-
Notifications
You must be signed in to change notification settings - Fork 27
/
bug552421.py
58 lines (49 loc) · 1.28 KB
/
bug552421.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from bug_harness import DSAdminHarness as DSAdmin
from dsadmin import Entry
import os
import sys
import time
import ldap
import pprint
import base64, hashlib
host1 = "localhost.localdomain"
cfgport = 1100
port1 = cfgport + 30
basedn = 'dc=example,dc=com'
newinst = 'ds'
os.environ['USE_GDB'] = "1"
srv = DSAdmin.createInstance({
'newrootpw': 'password',
'newhost': host1,
'newport': port1,
'newinst': newinst,
'newsuffix': basedn,
'no_admin': True
})
userdn = "ou=people," + basedn
# make password
password = "password"
sha = hashlib.sha1(password)
hashedpw = "{SHA}" + base64.b64encode(sha.digest()) + '\n' # add extra bogus newline
# add user entry
dn = "cn=foo," + userdn
ent = Entry(dn)
ent.setValues('objectclass', 'person')
ent.setValues('sn', 'Foo')
ent.setValues('userPassword', hashedpw)
srv.add_s(ent)
# attempt to bind as user
user = ldap.ldapobject.SimpleLDAPObject('ldap://%s:%d' % (host1,port1))
user.simple_bind_s(dn, password)
user.unbind_s()
# add another user entry
dn = "cn=bar," + userdn
ent = Entry(dn)
ent.setValues('objectclass', 'person')
ent.setValues('sn', 'Foo')
ent.setValues('userPassword', password)
srv.add_s(ent)
# attempt to bind as user
user = ldap.ldapobject.SimpleLDAPObject('ldap://%s:%d' % (host1,port1))
user.simple_bind_s(dn, password)
user.unbind_s()