def search_ext(self, base, scope, filterstr='(objectClass=*)', attrlist=None, attrsonly=0, serverctrls=None, clientctrls=None, timeout=-1, sizelimit=0, offset=None, length=None, ordering=None, context_id=None): assert not (offset and length) or ordering, 'if VLV is used ordering is mandatory' assert not ((offset is not None) ^ (length is not None)), 'offset and length must be set on unset at the same time' serverctrls = serverctrls or [] clientctrls = [] if ordering: serverctrls.append(SSSRequestControl(ordering, criticality=True)) if offset is not None: serverctrls.append(VLVRequestControl(offset=offset, after_count=length, content_count=0, criticality=True, context_id=context_id)) self.vlv = True result = LDAPObject.search_ext(self, base, scope, filterstr, attrlist, attrsonly, serverctrls, clientctrls, timeout, sizelimit) del self.vlv return result
def search_ext(self, base, scope, filterstr='(objectClass=*)', attrlist=None, attrsonly=0, serverctrls=None, clientctrls=None, timeout=-1, sizelimit=0, offset=None, length=None, ordering=None, context_id=None): assert not (offset and length) or ordering, 'if VLV is used ordering is mandatory' assert not ( (offset is not None) ^ (length is not None) ), 'offset and length must be set on unset at the same time' serverctrls = serverctrls or [] clientctrls = [] if ordering: serverctrls.append(SSSRequestControl(ordering, criticality=True)) if offset is not None: serverctrls.append( VLVRequestControl(offset=offset, after_count=length, content_count=0, criticality=True, context_id=context_id)) self.vlv = True result = LDAPObject.search_ext(self, base, scope, filterstr, attrlist, attrsonly, serverctrls, clientctrls, timeout, sizelimit) del self.vlv return result
def main(): adhost = 'w2k8x8664.testdomain.com' adport = 389 aduri = "ldap://%s:%d/" % (adhost, adport) suffix = "DC=testdomain,DC=com" name = sys.argv[1] pwd = sys.argv[2] # adroot = "cn=Dirsync User,cn=users," + suffix # adrootpw = "Secret123" adroot = "cn=%s,cn=users,%s" % (name, suffix) adrootpw = pwd verbose = False # ldap.set_option(ldap.OPT_DEBUG_LEVEL, 15) ad = LDAPObject(aduri) ad.simple_bind_s(adroot, adrootpw) # do initial dirsync search to get entries and the initial dirsync # cookie scope = ldap.SCOPE_SUBTREE filt = '(objectclass=*)' attrlist = None dirsyncctrl = DirSyncCtrl() page_size = 1000 lc = SimplePagedResultsControl( ldap.LDAP_CONTROL_PAGE_OID,True,(page_size,'') ) serverctrls = [dirsyncctrl, lc] msgid = ad.search_ext(suffix, scope, filt, attrlist, 0, serverctrls) initiallist = {} # the dirsync control is returned with the LDAP_RES_SEARCH_RESULT # def result3(self,msgid=_ldap.RES_ANY,all=1,timeout=None): while True: (rtype, rdata, rmsgid, decoded_serverctrls) = ad.result3(msgid) print "Search returned %d results" % len(rdata) for dn, ent in rdata: print "dn: ", dn if verbose: pprint.pprint(ent) if rtype == ldap.RES_SEARCH_RESULT: dirsyncctrl.update(decoded_serverctrls) break # now search again with the updated dirsync control # we should get back no results since nothing in AD # has changed msgid = ad.search_ext(suffix, scope, filt, attrlist, 0, serverctrls) while True: (rtype, rdata, rmsgid, decoded_serverctrls) = ad.result3(msgid) print "Search returned %d results" % len(rdata) if len(rdata) > 0: print "Nothing changed but something was returned????" pprint.pprint(rdata) if rtype == ldap.RES_SEARCH_RESULT: dirsyncctrl.update(decoded_serverctrls) break print "Change something on the AD side, and press Enter" sys.stdin.readline() print "Searching for changes . . ." msgid = ad.search_ext(suffix, scope, filt, attrlist, 0, serverctrls) while True: (rtype, rdata, rmsgid, decoded_serverctrls) = ad.result3(msgid) print "Search returned %d results" % len(rdata) for dn, ent in rdata: print "dn: ", dn pprint.pprint(ent) if rtype == ldap.RES_SEARCH_RESULT: dirsyncctrl.update(decoded_serverctrls) break
def main(): adhost = 'w2k8x8664.testdomain.com' adport = 389 aduri = "ldap://%s:%d/" % (adhost, adport) suffix = "DC=testdomain,DC=com" name = sys.argv[1] pwd = sys.argv[2] # adroot = "cn=Dirsync User,cn=users," + suffix # adrootpw = "Secret123" adroot = "cn=%s,cn=users,%s" % (name, suffix) adrootpw = pwd verbose = False # ldap.set_option(ldap.OPT_DEBUG_LEVEL, 15) ad = LDAPObject(aduri) ad.simple_bind_s(adroot, adrootpw) # do initial dirsync search to get entries and the initial dirsync # cookie scope = ldap.SCOPE_SUBTREE filt = '(objectclass=*)' attrlist = None dirsyncctrl = DirSyncCtrl() page_size = 1000 lc = SimplePagedResultsControl(ldap.LDAP_CONTROL_PAGE_OID, True, (page_size, '')) serverctrls = [dirsyncctrl, lc] msgid = ad.search_ext(suffix, scope, filt, attrlist, 0, serverctrls) initiallist = {} # the dirsync control is returned with the LDAP_RES_SEARCH_RESULT # def result3(self,msgid=_ldap.RES_ANY,all=1,timeout=None): while True: (rtype, rdata, rmsgid, decoded_serverctrls) = ad.result3(msgid) print "Search returned %d results" % len(rdata) for dn, ent in rdata: print "dn: ", dn if verbose: pprint.pprint(ent) if rtype == ldap.RES_SEARCH_RESULT: dirsyncctrl.update(decoded_serverctrls) break # now search again with the updated dirsync control # we should get back no results since nothing in AD # has changed msgid = ad.search_ext(suffix, scope, filt, attrlist, 0, serverctrls) while True: (rtype, rdata, rmsgid, decoded_serverctrls) = ad.result3(msgid) print "Search returned %d results" % len(rdata) if len(rdata) > 0: print "Nothing changed but something was returned????" pprint.pprint(rdata) if rtype == ldap.RES_SEARCH_RESULT: dirsyncctrl.update(decoded_serverctrls) break print "Change something on the AD side, and press Enter" sys.stdin.readline() print "Searching for changes . . ." msgid = ad.search_ext(suffix, scope, filt, attrlist, 0, serverctrls) while True: (rtype, rdata, rmsgid, decoded_serverctrls) = ad.result3(msgid) print "Search returned %d results" % len(rdata) for dn, ent in rdata: print "dn: ", dn pprint.pprint(ent) if rtype == ldap.RES_SEARCH_RESULT: dirsyncctrl.update(decoded_serverctrls) break