python samdb.newuser(): use user DN not samaccountname to set password
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 1 Feb 2018 21:35:25 +0000 (10:35 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 9 Feb 2018 06:59:20 +0000 (07:59 +0100)
This is noticably faster in cases (e.g. tests) where the same user
is added and deleted many times.

The rreason is samaccountname is retained for deleted objects, so the
search finds multiple objects that need to be filtered out internally.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/samdb.py

index d1048a74e14f459d944ebec1a92a1d62f031a267..7f52a5e56f8d003974be69e95c1ba35eab3b5161 100644 (file)
@@ -459,7 +459,9 @@ member: %s
 
             # Sets the password for it
             if setpassword:
-                self.setpassword("(samAccountName=%s)" % ldb.binary_encode(username), password,
+                self.setpassword(("(distinguishedName=%s)" %
+                                  ldb.binary_encode(user_dn)),
+                                 password,
                                  force_password_change_at_next_login_req)
         except:
             self.transaction_cancel()