1
##############################################################################
2
# ldapbase.py Version 0.1.2
3
# (c) by Michael Stroeder, michael.stroeder@propack-data.de
4
##############################################################################
8
dn_pattern = r'([\w;.]+[\s]*=[^,]+)(,[ ]*[\w;.]+[\s]*=[^,]+)*'
9
dn_regex = re.compile(dn_pattern)
11
# returns 1 if s is a LDAP DN
13
rm = dn_regex.match(s)
14
return rm!=None and rm.group(0)==s
17
result = string.split(dn,',')
18
result = map(string.strip,result)
19
return string.join(result,',')
21
# returns parent-DN of dn
23
return string.join(string.split(dn,',')[1:],',')
25
# returns a list of parent-DNs of dn
28
DNComponentList = string.split(dn,',')
29
for i in range(1,len(DNComponentList)):
30
result.append(string.join(DNComponentList[i:],','))
33
# parse a LDAP URL and return (host,dn,attributes,scope,filter)
35
# dn distinguished name
36
# attributes list with attributes
37
# scope search scope string
38
# filter LDAP search filter
39
def parse_ldap_url(ldap_url):
40
dummy,rest = string.split(ldap_url,'://',1)
42
host,rest = string.split(rest,'/',1)
45
paramlist=string.split(rest,'?')
48
attributes = string.split(paramlist[1],',')
59
return (host,dn,attributes,scope,filter)
67
def put(self,name,oid='',syntax='',alias=[],notes=''):
73
def parse(self,attr_schemastr):
82
def put(self,name,oid='',syntax='',sup='',must=[],may=[],notes=''):
85
self.abstract=abstract
92
def parse(self,oc_schemastr):
98
def __init__(self,host):
105
def AddObjectClass(self,name,oid='',sup='',must=['objectClass'],may=[],syntax='',notes=''):
106
if not name in self.oc_list:
107
self.oc_list.append(name)
108
self.oc_def['name']=ObjectClass()
109
self.oc_def['name'].put(name,oid,sup,must,may,syntax,notes)
111
def AddAttribute(self,name,oid='',syntax='',alias=[],notes=''):
112
if not name in self.attr_list:
113
self.attr_list.append(name)
114
self.attr_def['name']=Attribute()
115
self.attr_def['name'].put(name,oid,syntax,alias,notes)
117
def v3SchemaQuery(self,ldapconn,basedn='cn=schema',searchfilter='objectclass=subschema'):
118
schema = ldapconn.search_s()
120
def ReadOpenLDAPConf(self,slapdconf):
121
f = open(slapdconf,'r')