Imported Upstream version 1.10.2
[platform/upstream/krb5.git] / src / tests / dejagnu / krb-standalone / iprop.exp
1 # Password-changing Kerberos test.
2 # This is a DejaGnu test script.
3
4 proc setup_slave {} {
5     global tmppwd hostname REALMNAME KDB5_UTIL
6     file delete $tmppwd/slave-stash $tmppwd/slave-acl
7     file copy -force $tmppwd/acl $tmppwd/slave-acl
8     if ![file exists $tmppwd/kpropdacl] {
9         set aclfile [open $tmppwd/kpropd-acl w]
10         puts $aclfile "host/$hostname@$REALMNAME"
11         close $aclfile
12     }
13     setup_slave_db
14     # copy database - must be used after master db set up
15     envstack_push
16     setup_kerberos_env kdc
17     set dumpfile $tmppwd/dump-file
18     file delete $dumpfile $dumpfile.dump_ok
19     if [catch {exec $KDB5_UTIL dump -i $dumpfile} msg] {
20         error "master dump failed: $msg"
21     }
22     setup_kerberos_env slave
23     foreach suffix { .kadm5.lock .ok } {
24         file copy -force $tmppwd/kdc-db$suffix $tmppwd/slave-db$suffix
25     }
26     if [catch {exec $KDB5_UTIL load -i $dumpfile} msg] {
27         send_user "slave load failed: $msg"
28         error "slave load failed: $msg"
29     }
30 }
31
32 # We are about to start up a couple of daemon processes.  We do all
33 # the rest of the tests inside a proc, so that we can easily kill the
34 # processes when the procedure ends.
35
36 proc doit { } {
37     global REALMNAME KEY
38     global KLIST KDESTROY KADMIN_LOCAL KTUTIL KPROPLOG KPROPD KDB5_UTIL
39     global hostname tmppwd spawn_id kpropd_spawn_id kpropd_pid
40     global supported_enctypes KRBIV portbase mode
41     global ulog des3_krbtgt
42
43     # Delete any db, ulog files
44     delete_db
45
46     # Update config file
47     set ulog 1
48     reset_kerberos_files
49
50     # Initialize the Kerberos database.  The argument tells
51     # setup_kerberos_db that it is being called from here.
52     if ![setup_kerberos_db 0] {
53         return
54     }
55     if ![start_kerberos_daemons 0] {
56         return
57     }
58
59     # Check that ulog file does exist
60     if [file exists $tmppwd/db.ulog] {
61         pass "create update log"
62     } else {
63         fail "create update log"
64     }
65
66     setup_slave
67
68     # Use kadmin to add a key.
69     if ![add_kerberos_key wakawaka 0] {
70         return
71     }
72     set c chocolate-flavored-school-bus
73     # Long enough to make realloc likely, but not enough to grow
74     # basic ulog entry size.
75     set longname $c/$c/$c/$c/$c/$c/$c/$c/$c/$c/$c/$c/$c
76     if ![add_kerberos_key $longname 0] {
77         return
78     }
79     if ![add_kerberos_key w 0] {
80         return
81     }
82     if ![modify_principal w -allow_tix] {
83         return
84     }
85     if ![modify_principal w +allow_tix] {
86         return
87     }
88     # Should test rename_principal once we have that.
89
90     # Run kproplog, look at output.
91     setup_kerberos_env kdc
92     spawn $KPROPLOG
93     expect_after {
94         timeout {
95             fail "kproplog output"
96             break
97         }
98         eof {
99             fail "kproplog output"
100             break
101         }
102     }
103     catch {
104         expect -re "Kerberos update log"
105         expect -re "Update log dump"
106         expect -re "First serial \# : 1"
107         if $des3_krbtgt {
108             expect -re "Last serial \# : 9"
109             expect -re "Update Entry"
110             expect -re "Update serial \# : 1"
111             expect -re "Attributes changed : 12"
112             expect -re "Update Entry"
113             expect -re "Update serial \# : 3"
114             expect -re "Attributes changed : 6"
115             expect -re "Update Entry"
116             expect -re "Update serial \# : 5"
117             expect -re "Attributes changed : 12"
118             expect -re "Update Entry"
119             expect -re "Update serial \# : 5"
120         } else {
121             expect -re "Last serial \# : 8"
122             expect -re "Update Entry"
123             expect -re "Update serial \# : 1"
124             expect -re "Attributes changed : 12"
125             expect -re "Update Entry"
126             expect -re "Update serial \# : 3"
127             expect -re "Attributes changed : 12"
128             expect -re "Update Entry"
129             expect -re "Update serial \# : 4"
130         }
131         expect -re "Update operation : Add"
132         expect -re "Update principal : wakawaka@KRBTEST.COM"
133         expect_after {
134             timeout {
135                 fail "kproplog output"
136                 break
137             }
138         }
139         expect -re "Attributes changed : 12"
140         expect eof
141         pass "kproplog output"
142     } foo
143     catch expect_after
144     if [check_exit_status kproplog] {
145         pass "kproplog"
146     }
147     add_random_key host/$hostname 0
148     add_random_key kiprop/$hostname 0
149
150     # Already have kadmind running.
151
152     # Get a keytab file.
153     setup_srvtab 0
154
155     # Sleep 11s for built-in delay.
156     verbose "Delaying to bypass contention-avoidance code in kadmind/iprop"
157     sleep 11
158
159     # Launch slave kpropd.
160     start_kpropd
161 #    setup_kerberos_env slave
162 #    send_user [list $KPROPD -S -d -P [expr 10 + $portbase] -s $tmppwd/srvtab -f $tmppwd/incoming-slave-datatrans -p $KDB5_UTIL -a $tmppwd/kpropd-acl]\n
163 #    spawn_shell
164     expect {
165         -i $kpropd_spawn_id
166         "Update transfer from master was OK" {
167             exec kill $kpropd_pid
168             wait -i $kpropd_spawn_id
169             unset kpropd_spawn_id kpropd_pid
170         }
171         -re ..* { exp_continue }
172         timeout {
173             catch { exec kill $kpropd_pid }
174             exp_continue
175         }
176         eof {
177             wait -i $kpropd_spawn_id
178             unset kpropd_spawn_id kpropd_pid
179         }
180     }
181
182     # Wait briefly?
183     # Check slave db for new principal.
184     setup_kerberos_env slave
185     spawn $KADMIN_LOCAL -r $REALMNAME -q listprincs
186     expect {
187         wakawaka@ {
188             expect eof
189         }
190         eof {
191             fail "kprop (updated slave data)"
192             return
193         }
194         timeout {
195             fail "kprop (examining new db)"
196             return
197         }
198     }
199     pass "iprop"
200
201     # What about testing for full propagation?  (Small number of
202     # entries in update log, change one principal's record a lot of
203     # times, then fire up incremental kpropd...)  Do later.
204 }
205
206 run_once iprop {
207     catch "unset kpropd_pid"
208     catch "unset kpropd_spawn_id"
209
210     # Set up the Kerberos files and environment.
211     if {![get_hostname] || ![setup_kerberos_files] || ![setup_kerberos_env]} {
212         return
213     }
214
215     set status [catch doit msg]
216
217     stop_kerberos_daemons
218
219     # if kpropd is running, kill it
220     if [info exists kpropd_pid] {
221         catch {
222             exec kill $kpropd_pid
223             expect -i $kpropd_spawn_id eof
224             wait -i $kpropd_spawn_id
225             unset kpropd_pid kpropd_spawn_id
226         }
227     }
228
229     set ulog 0
230     reset_kerberos_files
231     delete_db
232
233     if { $status != 0 } {
234         send_error "ERROR: error in iprop.exp\n"
235         send_error "$msg\n"
236         exit 1
237     }
238 }