s4:samldb LDB module - permit "userAccountControl" modifications without acct. type
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Wed, 29 May 2013 20:17:35 +0000 (22:17 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 5 Jun 2013 01:26:25 +0000 (03:26 +0200)
Obviously this defaults to UF_NORMAL_ACCOUNT. Some background can be found in
MS-SAMR section 3.1.1.8.10.

Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Wed Jun  5 03:26:25 CEST 2013 on sn-devel-104

source4/dsdb/samdb/ldb_modules/samldb.c
source4/dsdb/tests/python/sam.py

index cd13900bf5a9c0cdd89e07e475bdcc4420e3711b..5bb0b61d61a4eedba77f8c4f62a180c611a39928 100644 (file)
@@ -1517,8 +1517,32 @@ static int samldb_user_account_control_change(struct samldb_ctx *ac)
 
        account_type = ds_uf2atype(user_account_control);
        if (account_type == 0) {
-               ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
-               return LDB_ERR_UNWILLING_TO_PERFORM;
+               char *tempstr;
+
+               /*
+                * When there is no account type embedded in "userAccountControl"
+                * fall back to default "UF_NORMAL_ACCOUNT".
+                */
+               if (user_account_control == 0) {
+                       ldb_set_errstring(ldb,
+                                         "samldb: Invalid user account control value!");
+                       return LDB_ERR_UNWILLING_TO_PERFORM;
+               }
+
+               user_account_control |= UF_NORMAL_ACCOUNT;
+
+               tempstr = talloc_asprintf(ac->msg, "%d", user_account_control);
+               if (tempstr == NULL) {
+                       return ldb_module_oom(ac->module);
+               }
+
+               /* Overwrite "userAccountControl" with "UF_NORMAL_ACCOUNT" added */
+               el = dsdb_get_single_valued_attr(ac->msg, "userAccountControl",
+                                                ac->req->operation);
+               el->values[0].data = (uint8_t *) tempstr;
+               el->values[0].length = strlen(tempstr);
+
+               account_type = ATYPE_NORMAL_ACCOUNT;
        }
        ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg, "sAMAccountType",
                                 account_type);
index df1915a899fc1f6bdd03eacfe7a2715a109359bd..361a10898d36131887c75dac93d03df2df7a37d4 100755 (executable)
@@ -1571,6 +1571,22 @@ class SamTests(samba.tests.TestCase):
           ATYPE_NORMAL_ACCOUNT)
         self.assertTrue(int(res1[0]["userAccountControl"][0]) & UF_ACCOUNTDISABLE == 0)
 
+        m = Message()
+        m.dn = Dn(ldb, "cn=ldaptestuser,cn=users," + self.base_dn)
+        m["userAccountControl"] = MessageElement(
+          str(UF_ACCOUNTDISABLE),
+          FLAG_MOD_REPLACE, "userAccountControl")
+        ldb.modify(m)
+
+        res1 = ldb.search("cn=ldaptestuser,cn=users," + self.base_dn,
+                          scope=SCOPE_BASE,
+                          attrs=["sAMAccountType", "userAccountControl"])
+        self.assertTrue(len(res1) == 1)
+        self.assertEquals(int(res1[0]["sAMAccountType"][0]),
+          ATYPE_NORMAL_ACCOUNT)
+        self.assertTrue(int(res1[0]["userAccountControl"][0]) & UF_NORMAL_ACCOUNT != 0)
+        self.assertTrue(int(res1[0]["userAccountControl"][0]) & UF_ACCOUNTDISABLE != 0)
+
         try:
             m = Message()
             m.dn = Dn(ldb, "cn=ldaptestuser,cn=users," + self.base_dn)
@@ -1791,6 +1807,22 @@ class SamTests(samba.tests.TestCase):
           ATYPE_NORMAL_ACCOUNT)
         self.assertTrue(int(res1[0]["userAccountControl"][0]) & UF_ACCOUNTDISABLE == 0)
 
+        m = Message()
+        m.dn = Dn(ldb, "cn=ldaptestcomputer,cn=computers," + self.base_dn)
+        m["userAccountControl"] = MessageElement(
+          str(UF_ACCOUNTDISABLE),
+          FLAG_MOD_REPLACE, "userAccountControl")
+        ldb.modify(m)
+
+        res1 = ldb.search("cn=ldaptestcomputer,cn=computers," + self.base_dn,
+                          scope=SCOPE_BASE,
+                          attrs=["sAMAccountType", "userAccountControl"])
+        self.assertTrue(len(res1) == 1)
+        self.assertEquals(int(res1[0]["sAMAccountType"][0]),
+          ATYPE_NORMAL_ACCOUNT)
+        self.assertTrue(int(res1[0]["userAccountControl"][0]) & UF_NORMAL_ACCOUNT != 0)
+        self.assertTrue(int(res1[0]["userAccountControl"][0]) & UF_ACCOUNTDISABLE != 0)
+
         try:
             m = Message()
             m.dn = Dn(ldb, "cn=ldaptestcomputer,cn=computers," + self.base_dn)