time.sleep(20) print "check entries in DS - see if they have title and enabled state correct" for ii in xrange(1,11): filt = "(uid=testuser%d)" % ii ents = ds.search_s(usersubtree + "," + suffix, ldap.SCOPE_SUBTREE, filt, dsattrs) if not ents or len(ents) == 0 or not ents[0]: raise Exception("error: " + filt + " not found in DS") dsent = ents[0] adent = adents[ii-1] if not entriesAreEqual(dsent, adent): print "entries are not equal", dsent.dn, adent.dn print "delete all entries in AD - at the same time, modify an entry in DS . . ." for ent in adents: ad.delete_s(ent.dn) ad.delete_s(adusersubtree + "," + suffix) time.sleep(1) mod = [(ldap.MOD_REPLACE, 'userPassword', 'Ornette1')] ds.modify_s(dsents[0].dn, mod) print "delete all entries in DS" for ent in dsents: try: ds.delete_s(ent.dn) except ldap.NO_SUCH_OBJECT: print ent.dn, "already deleted" print "add back the deleted container" ent = Entry(windows_subtree) rdn = ldap.explode_dn(windows_subtree)[0].split('=') ent.setValues('objectclass', ['top', 'container']) ent.setValues(rdn[0], rdn[1])
srv.add_s(ent) except ldap.ALREADY_EXISTS: pass def genpwd(pwd, salt): sha = hashlib.sha1(pwd) sha.update(salt) return "{SSHA}" + base64.b64encode(sha.digest() + salt) pwd = "averylongpassword" for ii in xrange(0, 100): dn = "cn=user%d,ou=people,%s" % (ii, basedn) try: srv.delete_s(dn) except ldap.NO_SUCH_OBJECT: pass ent = Entry(dn) ent.setValues("objectclass", "person") ent.setValues("sn", "User" + str(ii)) if ii > 0: salt = "a" * ii pwdstr = genpwd(pwd, salt) else: pwdstr = pwd ent.setValues("userPassword", pwdstr) srv.add_s(ent) for ii in xrange(0, 100): dn = "cn=user%d,ou=people,%s" % (ii, basedn)
srv.add_s(ent) except ldap.ALREADY_EXISTS: pass def genpwd(pwd, salt): sha = hashlib.sha1(pwd) sha.update(salt) return '{SSHA}' + base64.b64encode(sha.digest() + salt) pwd = 'averylongpassword' for ii in xrange(0, 100): dn = 'cn=user%d,ou=people,%s' % (ii, basedn) try: srv.delete_s(dn) except ldap.NO_SUCH_OBJECT: pass ent = Entry(dn) ent.setValues('objectclass', 'person') ent.setValues('sn', 'User' + str(ii)) if ii > 0: salt = 'a' * ii pwdstr = genpwd(pwd, salt) else: pwdstr = pwd ent.setValues('userPassword', pwdstr) srv.add_s(ent) for ii in xrange(0, 100): dn = 'cn=user%d,ou=people,%s' % (ii, basedn)