-
Notifications
You must be signed in to change notification settings - Fork 27
/
ipacostest.py
84 lines (71 loc) · 2.25 KB
/
ipacostest.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import sys
import time
import ldap
import pprint
from dsadmin import DSAdmin, Entry
host1 = "localhost"
cfgport = 1100
port1 = cfgport + 30
basedn = 'dc=example,dc=com'
newinst = 'ipa'
#os.environ['USE_GDB'] = "1"
srv = DSAdmin.createInstance({
'newrootpw': 'password',
'newhost': host1,
'newport': port1,
'newinst': newinst,
'newsuffix': basedn,
'no_admin': True
})
accountdn = "cn=accounts," + basedn
# add schema
srv.addAttr("( NAME 'posixName' DESC 'posixName' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )")
srv.addAttr("( NAME 'ipaUserDN' DESC 'ipaUserDN' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE )")
srv.addObjClass("( NAME 'ipaPosixName' SUP top AUXILIARY MUST posixName MAY ipaUserDN )")
# # enable attr uniqueness for posixName
# dn = "cn=attribute uniqueness,cn=plugins,cn=config"
# mod = [(ldap.MOD_REPLACE, 'pluginarg0', ['posixName']),
# (ldap.MOD_REPLACE, 'nsslapd-pluginarg1', [accountdn])]
# srv.modify_s(dn, mod)
# # stop start for plugin changes to take effect
# srv.stop()
# srv.start()
# add containers
ent = Entry(accountdn)
ent.setValues('objectclass', 'nsContainer')
srv.add_s(ent)
userdn = "cn=users," + accountdn
ent = Entry(userdn)
ent.setValues('objectclass', 'nsContainer')
srv.add_s(ent)
groupdn = "cn=groups," + accountdn
ent = Entry(groupdn)
ent.setValues('objectclass', 'nsContainer')
srv.add_s(ent)
# add CoS
dn = "cn=generatePosixName," + groupdn
ent = Entry(dn)
ent.setValues('description', 'generate posixName for group entries')
ent.setValues('objectClass', ['top', 'ldapsubentry', 'cossuperdefinition', 'cosIndirectDefinition'])
ent.setValues('cosAttribute', 'posixName override')
ent.setValues('cosIndirectSpecifier', 'ipaUserDN')
srv.add_s(ent)
# add user entry
dn = "cn=foo," + userdn
ent = Entry(dn)
ent.setValues('objectclass', ['person', 'ipaPosixName'])
ent.setValues('sn', 'Foo')
ent.setValues('posixName', 'foo')
srv.add_s(ent)
# add group entry
dn = "cn=foo," + groupdn
ent = Entry(dn)
ent.setValues('objectclass', ['nsContainer', 'ipaPosixName'])
ent.setValues('posixName', 'foo')
ent.setValues('ipaUserDN', "cn=foo," + userdn)
ent.setValues('posixName', 'dummyforschemachecking')
srv.add_s(ent)
# search for group entry
ents = srv.search_s(dn, ldap.SCOPE_BASE, "(objectclass=*)")
pprint.pprint(ents)