-
Notifications
You must be signed in to change notification settings - Fork 272
/
tut4.py
56 lines (54 loc) · 1.58 KB
/
tut4.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
from ldap3 import Server, Connection, ObjectDef, AttrDef, Reader, Writer, ALL
server = Server('ipa.demo1.freeipa.org', get_info=ALL)
conn = Connection(server, 'uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org', 'Secret123', auto_bind=True)
obj_person = ObjectDef('person', conn)
print(obj_person)
print(obj_person.sn)
obj_inetorgperson = ObjectDef('inetOrgPerson', conn)
r = Reader(conn, obj_inetorgperson, 'ou=ldap3-tutorial,dc=demo1,dc=freeipa,dc=org')
print(r)
r.search()
print(r)
print(r[0])
print(r[0].entry_dn)
print(r[0].entry_attributes)
print(r[0].entry_attributes_as_dict)
print(r[0].entry_mandatory_attributes)
print(r[0].entry_to_ldif())
print(r[0].entry_to_json(include_empty=False))
print(obj_person)
obj_person += 'uid'
print(obj_person)
r = Reader(conn, obj_person, 'cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org', 'uid:=admin')
print(r)
r.search()
print(r[0])
obj_person = ObjectDef(['person', 'posixaccount', 'krbprincipalaux'], conn)
print(obj_person)
r = Reader(conn, obj_person, 'dc=demo1,dc=freeipa,dc=org', 'uid:=admin')
r.search()
print(r[0])
print(r[0].krblastpwdchange.raw_values)
print(r[0].krbloginfailedcount.value)
print(r[0].krbloginfailedcount.raw_values)
r.search_level()
print(r)
print(len(r))
r.search_subtree()
print(len(r))
r = Reader(conn, obj_inetorgperson, 'ou=ldap3-tutorial,dc=demo1,dc=freeipa,dc=org')
r.search()
w = Writer.from_cursor(r)
print(w)
print(w[0])
w[0].sn += 'Smyth'
w[0].sn += 'Johnson'
w[0].sn -= 'Young'
print(w[0].entry_changes)
print(w[0])
w[0].sn.discard()
w[0].sn += ['Smith', 'Johnson']
w[0].sn -= 'Young'
print(w[0])
w.commit()
print(w[0])