s4:python tools - try to fix some test problems
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 20 Sep 2009 21:49:05 +0000 (23:49 +0200)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 20 Sep 2009 21:49:05 +0000 (23:49 +0200)
source4/scripting/python/samba/samdb.py
source4/setup/newuser
source4/setup/setexpiry

index 28352f202f7bdff6bb1f1396be9b44136abafb2c..239dd6a6ea4f44397da2b4d70c078f97f3ce6036 100644 (file)
@@ -107,15 +107,16 @@ pwdLastSet: 0
 """ % (user_dn)
         self.modify_ldif(mod)
 
-    def newuser(self, username, unixname, password, force_password_change_at_next_login=False):
+    def newuser(self, username, unixname, password, force_password_change_at_next_login_req=False):
         """Adds a new user
 
         Note: This call adds also the ID mapping for winbind; therefore it works
         *only* on SAMBA 4.
         
-        :param username: Name of the new user.
-        :param unixname: Name of the unix user to map to.
+        :param username: Name of the new user
+        :param unixname: Name of the unix user to map to
         :param password: Password for the new user
+        :param force_password_change_at_next_login_req: Force password change
         """
         self.transaction_start()
         try:
@@ -129,7 +130,7 @@ pwdLastSet: 0
 
             # Sets the password for it
             self.setpassword("(dn=" + user_dn + ")", password,
-              force_password_change_at_next_login)
+              force_password_change_at_next_login_req)
 
             # Gets the user SID (for the account mapping setup)
             res = self.search(user_dn, scope=ldb.SCOPE_BASE,
@@ -153,7 +154,7 @@ pwdLastSet: 0
             raise
         self.transaction_commit()
 
-    def setpassword(self, filter, password, force_password_change_at_next_login=False):
+    def setpassword(self, filter, password, force_password_change_at_next_login_req=False):
         """Sets the password for a user
         
         Note: This call uses the "userPassword" attribute to set the password.
@@ -162,7 +163,7 @@ pwdLastSet: 0
 
         :param filter: LDAP filter to find the user (eg samccountname=name)
         :param password: Password for the user
-        :param force_password_change_at_next_login: Force password change
+        :param force_password_change_at_next_login_req: Force password change
         """
         self.transaction_start()
         try:
@@ -180,8 +181,9 @@ userPassword:: %s
 
             self.modify_ldif(setpw)
 
-            if force_password_change_at_next_login:
-                self.force_password_change_at_next_login(user_dn)
+            if force_password_change_at_next_login_req:
+                self.force_password_change_at_next_login(
+                  "(dn=" + str(user_dn) + ")")
 
             #  modify the userAccountControl to remove the disabled bit
             self.enable_account(filter)
@@ -190,24 +192,24 @@ userPassword:: %s
             raise
         self.transaction_commit()
 
-    def setexpiry(self, filter, expiry_seconds, noexpiry=False):
+    def setexpiry(self, filter, expiry_seconds, no_expiry_req=False):
         """Sets the account expiry for a user
         
         :param filter: LDAP filter to find the user (eg samccountname=name)
         :param expiry_seconds: expiry time from now in seconds
-        :param noexpiry: if set, then don't expire password
+        :param no_expiry_req: if set, then don't expire password
         """
         self.transaction_start()
         try:
             res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
                               expression=filter,
                               attrs=["userAccountControl", "accountExpires"])
-            assert len(res) == 1
+            assert(len(res) == 1)
             user_dn = res[0].dn
 
             userAccountControl = int(res[0]["userAccountControl"][0])
             accountExpires     = int(res[0]["accountExpires"][0])
-            if noexpiry:
+            if no_expiry_req:
                 userAccountControl = userAccountControl | 0x10000
                 accountExpires = 0
             else:
index 422677c301fb137a1f99abda1d5d4ddce020fcca..10af55a458afe973a3af2c4942d6777f8c96b9eb 100755 (executable)
@@ -60,4 +60,4 @@ creds = credopts.get_credentials(lp)
 
 samdb = SamDB(url=lp.get("sam database"), session_info=system_session(),
               credentials=creds, lp=lp)
-samdb.newuser(username, opts.unixname, password, force_password_change_at_next_login=opts.must_change_at_next_login)
+samdb.newuser(username, opts.unixname, password, force_password_change_at_next_login_req=opts.must_change_at_next_login)
index 6c6305ceaf6b9f219f388246b46c07e818e10e84..1572555b8cfab5de7f22202ca2e21f43648c2443 100755 (executable)
@@ -61,4 +61,4 @@ creds = credopts.get_credentials(lp)
 
 samdb = SamDB(url=lp.get("sam database"), session_info=system_session(),
               credentials=creds, lp=lp)
-samdb.setexpiry(filter, days*24*3600, noexpiry=opts.noexpiry)
+samdb.setexpiry(filter, days*24*3600, no_expiry_req=opts.noexpiry)