s3: Add an explicit counter to tldap_add_mod_[blobs|str]
authorVolker Lendecke <vl@samba.org>
Sat, 12 Feb 2011 15:58:10 +0000 (16:58 +0100)
committerVolker Lendecke <vl@samba.org>
Sun, 13 Feb 2011 11:11:53 +0000 (12:11 +0100)
source3/include/tldap_util.h
source3/lib/tldap_util.c
source3/passdb/pdb_ads.c

index d0268fe1d626b95393ac54cc58b4f6cb17d9fd31..6a99a5f78a8ab21c7425714645469efd57ad3a26 100644 (file)
@@ -33,10 +33,12 @@ bool tldap_pull_binsid(struct tldap_message *msg, const char *attribute,
                       struct dom_sid *sid);
 bool tldap_pull_guid(struct tldap_message *msg, const char *attribute,
                     struct GUID *guid);
-bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
+bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx,
+                        struct tldap_mod **pmods, int *pnum_mods,
                         int mod_op, const char *attrib,
-                        DATA_BLOB *values, int num_values);
-bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
+                        DATA_BLOB *newvals, int num_newvals);
+bool tldap_add_mod_str(TALLOC_CTX *mem_ctx,
+                      struct tldap_mod **pmods, int *pnum_mods,
                       int mod_op, const char *attrib, const char *str);
 bool tldap_make_mod_blob(struct tldap_message *existing, TALLOC_CTX *mem_ctx,
                         struct tldap_mod **pmods, int *pnum_mods,
index 2646348aa1f4899893289bfdf5f7e240c8396d1d..e42188a2abb2c8126ab27391f3df1f73c7593c94 100644 (file)
@@ -132,7 +132,7 @@ static bool tldap_add_blob_vals(TALLOC_CTX *mem_ctx, struct tldap_mod *mod,
 }
 
 bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx,
-                        struct tldap_mod **pmods,
+                        struct tldap_mod **pmods, int *pnum_mods,
                         int mod_op, const char *attrib,
                         DATA_BLOB *newvals, int num_newvals)
 {
@@ -148,7 +148,7 @@ bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx,
                return false;
        }
 
-       num_mods = talloc_array_length(mods);
+       num_mods = *pnum_mods;
 
        for (i=0; i<num_mods; i++) {
                if ((mods[i].mod_op == mod_op)
@@ -174,7 +174,7 @@ bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx,
                return false;
        }
 
-       if (i == num_mods) {
+       if ((i == num_mods) && (talloc_array_length(mods) < num_mods + 1)) {
                mods = talloc_realloc(talloc_tos(), mods, struct tldap_mod,
                                      num_mods+1);
                if (mods == NULL) {
@@ -184,10 +184,12 @@ bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx,
        }
 
        *pmods = mods;
+       *pnum_mods += 1;
        return true;
 }
 
-bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
+bool tldap_add_mod_str(TALLOC_CTX *mem_ctx,
+                      struct tldap_mod **pmods, int *pnum_mods,
                       int mod_op, const char *attrib, const char *str)
 {
        DATA_BLOB utf8;
@@ -199,7 +201,8 @@ bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
                return false;
        }
 
-       ret = tldap_add_mod_blobs(mem_ctx, pmods, mod_op, attrib, &utf8, 1);
+       ret = tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods, mod_op, attrib,
+                                 &utf8, 1);
        TALLOC_FREE(utf8.data);
        return ret;
 }
@@ -248,7 +251,8 @@ static bool tldap_make_mod_blob_int(struct tldap_message *existing,
 
                DEBUG(10, ("smbldap_make_mod_blob: deleting attribute |%s|\n",
                           attrib));
-               if (!tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_DELETE,
+               if (!tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods,
+                                        TLDAP_MOD_DELETE,
                                         attrib, &oldval, 1)) {
                        return false;
                }
@@ -261,12 +265,12 @@ static bool tldap_make_mod_blob_int(struct tldap_message *existing,
        if (newval.data != NULL) {
                DEBUG(10, ("smbldap_make_mod: adding attribute |%s| value len "
                           "%d\n", attrib, (int)newval.length));
-               if (!tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_ADD,
+               if (!tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods,
+                                        TLDAP_MOD_ADD,
                                         attrib, &newval, 1)) {
                        return false;
                }
        }
-       *pnum_mods = talloc_array_length(*pmods);
        return true;
 }
 
index 99170aacc3cdc732e6278ac02570c7320b5ad730..8c5ea81145a8f900d640bdf158ab2632b0039929 100644 (file)
@@ -330,11 +330,9 @@ static bool pdb_ads_init_ads_from_sam(struct pdb_ads_state *state,
                }
                blob = data_blob_const(pw_utf16, pw_utf16_len);
 
-               ret &= tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_REPLACE,
+               ret &= tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods,
+                                          TLDAP_MOD_REPLACE,
                                           "unicodePwd", &blob, 1);
-               if (ret) {
-                       *pnum_mods = talloc_array_length(*pmods);
-               }
                TALLOC_FREE(pw_utf16);
                TALLOC_FREE(pw_quote);
        }
@@ -1084,6 +1082,7 @@ static NTSTATUS pdb_ads_mod_groupmem(struct pdb_methods *m,
        struct dom_sid groupsid, membersid;
        char *groupdn, *memberdn;
        struct tldap_mod *mods;
+       int num_mods;
        int rc;
        NTSTATUS status;
 
@@ -1107,14 +1106,15 @@ static NTSTATUS pdb_ads_mod_groupmem(struct pdb_methods *m,
        }
 
        mods = NULL;
+       num_mods = 0;
 
-       if (!tldap_add_mod_str(talloc_tos(), &mods, mod_op,
+       if (!tldap_add_mod_str(talloc_tos(), &mods, &num_mods, mod_op,
                               "member", memberdn)) {
                TALLOC_FREE(frame);
                return NT_STATUS_NO_MEMORY;
        }
 
-       rc = tldap_modify(ld, groupdn, mods, 1, NULL, 0, NULL, 0);
+       rc = tldap_modify(ld, groupdn, mods, num_mods, NULL, 0, NULL, 0);
        TALLOC_FREE(frame);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_modify failed: %s\n",
@@ -1414,6 +1414,7 @@ static NTSTATUS pdb_ads_mod_aliasmem(struct pdb_methods *m,
        struct tldap_context *ld;
        TALLOC_CTX *frame = talloc_stackframe();
        struct tldap_mod *mods;
+       int num_mods;
        int rc;
        char *aliasdn, *memberdn;
        NTSTATUS status;
@@ -1439,14 +1440,15 @@ static NTSTATUS pdb_ads_mod_aliasmem(struct pdb_methods *m,
        }
 
        mods = NULL;
+       num_mods = 0;
 
-       if (!tldap_add_mod_str(talloc_tos(), &mods, mod_op,
+       if (!tldap_add_mod_str(talloc_tos(), &mods, &num_mods, mod_op,
                               "member", memberdn)) {
                TALLOC_FREE(frame);
                return NT_STATUS_NO_MEMORY;
        }
 
-       rc = tldap_modify(ld, aliasdn, mods, 1, NULL, 0, NULL, 0);
+       rc = tldap_modify(ld, aliasdn, mods, num_mods, NULL, 0, NULL, 0);
        TALLOC_FREE(frame);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_modify failed: %s\n",