xref: /freebsd/crypto/krb5/src/tests/t_kdb_locking.py (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert# This is a regression test for
2*7f2fe78bSCy Schubert# https://bugzilla.redhat.com/show_bug.cgi?id=586032 .
3*7f2fe78bSCy Schubert#
4*7f2fe78bSCy Schubert# We start a KDC, remove the kadm5 lock file, use the KDC, re-create the
5*7f2fe78bSCy Schubert# kadm5 lock file, and use kadmin.local.  The kinit should fail, and the
6*7f2fe78bSCy Schubert# kadmin.local should succeed.
7*7f2fe78bSCy Schubert
8*7f2fe78bSCy Schubert
9*7f2fe78bSCy Schubertimport os
10*7f2fe78bSCy Schubert
11*7f2fe78bSCy Schubertfrom k5test import *
12*7f2fe78bSCy Schubert
13*7f2fe78bSCy Schubertp = 'foo'
14*7f2fe78bSCy Schubertrealm = K5Realm(create_user=False, bdb_only=True)
15*7f2fe78bSCy Schubertrealm.addprinc(p, p)
16*7f2fe78bSCy Schubert
17*7f2fe78bSCy Schubertkadm5_lock = os.path.join(realm.testdir, 'db.kadm5.lock')
18*7f2fe78bSCy Schubertif not os.path.exists(kadm5_lock):
19*7f2fe78bSCy Schubert    fail('kadm5 lock file not created: ' + kadm5_lock)
20*7f2fe78bSCy Schubertos.unlink(kadm5_lock)
21*7f2fe78bSCy Schubert
22*7f2fe78bSCy Schubertrealm.kinit(p, p, [], expected_code=1,
23*7f2fe78bSCy Schubert            expected_msg='A service is not available')
24*7f2fe78bSCy Schubert
25*7f2fe78bSCy Schubertf = open(kadm5_lock, 'w')
26*7f2fe78bSCy Schubertf.close()
27*7f2fe78bSCy Schubert
28*7f2fe78bSCy Schubertoutput = realm.run([kadminl, 'modprinc', '-allow_tix', p])
29*7f2fe78bSCy Schubertif 'Cannot lock database' in output:
30*7f2fe78bSCy Schubert    fail('krb5kdc still holds a lock on the principal db')
31*7f2fe78bSCy Schubert
32*7f2fe78bSCy Schubertsuccess('KDB locking tests')
33