s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git] / source3 / groupdb / mapping_tdb.c
index f608e2e51440554e654882146bc8883745cf0a95..cf8857cda541990cff878745933d5ea41b361999 100644 (file)
  */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "passdb.h"
 #include "groupdb/mapping.h"
+#include "dbwrap.h"
+#include "util_tdb.h"
+#include "../libcli/security/security.h"
 
 static struct db_context *db; /* used for driver files */
 
@@ -140,7 +145,7 @@ static bool add_mapping_entry(GROUP_MAP *map, int flag)
        len = tdb_pack(NULL, 0, "ddff",
                map->gid, map->sid_name_use, map->nt_name, map->comment);
 
-       buf = TALLOC_ARRAY(key, char, len);
+       buf = talloc_array(key, char, len);
        if (!buf) {
                TALLOC_FREE(key);
                return false;
@@ -339,7 +344,7 @@ static int collect_map(struct db_record *rec, void *private_data)
        }
 
        if ((state->domsid != NULL) &&
-           (sid_compare_domain(state->domsid, &map.sid) != 0)) {
+           (dom_sid_compare_domain(state->domsid, &map.sid) != 0)) {
                DEBUG(11,("enum_group_mapping: group %s is not in domain\n",
                          sid_string_dbg(&map.sid)));
                return 0;
@@ -408,14 +413,17 @@ static NTSTATUS one_alias_membership(const struct dom_sid *member,
 
        while (next_token_talloc(frame, &p, &string_sid, " ")) {
                struct dom_sid alias;
+               uint32_t num_sids;
 
                if (!string_to_sid(&alias, string_sid))
                        continue;
 
-               status= add_sid_to_array_unique(NULL, &alias, sids, num);
+               num_sids = *num;
+               status= add_sid_to_array_unique(NULL, &alias, sids, &num_sids);
                if (!NT_STATUS_IS_OK(status)) {
                        goto done;
                }
+               *num = num_sids;
        }
 
 done:
@@ -442,7 +450,8 @@ static NTSTATUS alias_memberships(const struct dom_sid *members, size_t num_memb
 static bool is_aliasmem(const struct dom_sid *alias, const struct dom_sid *member)
 {
        struct dom_sid *sids;
-       size_t i, num;
+       size_t i;
+       size_t num;
 
        /* This feels the wrong way round, but the on-disk data structure
         * dictates it this way. */
@@ -450,7 +459,7 @@ static bool is_aliasmem(const struct dom_sid *alias, const struct dom_sid *membe
                return False;
 
        for (i=0; i<num; i++) {
-               if (sid_compare(alias, &sids[i]) == 0) {
+               if (dom_sid_compare(alias, &sids[i]) == 0) {
                        TALLOC_FREE(sids);
                        return True;
                }
@@ -566,11 +575,12 @@ static int collect_aliasmem(struct db_record *rec, void *priv)
        while (next_token_talloc(frame, &p, &alias_string, " ")) {
                struct dom_sid alias, member;
                const char *member_string;
+               uint32_t num_sids;
 
                if (!string_to_sid(&alias, alias_string))
                        continue;
 
-               if (sid_compare(state->alias, &alias) != 0)
+               if (dom_sid_compare(state->alias, &alias) != 0)
                        continue;
 
                /* Ok, we found the alias we're looking for in the membership
@@ -588,13 +598,15 @@ static int collect_aliasmem(struct db_record *rec, void *priv)
                if (!string_to_sid(&member, member_string))
                        continue;
 
+               num_sids = *state->num;
                if (!NT_STATUS_IS_OK(add_sid_to_array(state->mem_ctx, &member,
                                                      state->sids,
-                                                     state->num)))
+                                                     &num_sids)))
                {
                        /* talloc fail. */
                        break;
                }
+               *state->num = num_sids;
        }
 
        TALLOC_FREE(frame);
@@ -648,7 +660,7 @@ static NTSTATUS del_aliasmem(const struct dom_sid *alias, const struct dom_sid *
        }
 
        for (i=0; i<num; i++) {
-               if (sid_compare(&sids[i], alias) == 0) {
+               if (dom_sid_compare(&sids[i], alias) == 0) {
                        found = True;
                        break;
                }
@@ -837,7 +849,7 @@ static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
                p += len + 1;
 
                num_vals = pull_uint32(p, 0);
-               if (StrCaseCmp(name, "member") == 0) {
+               if (strcasecmp_m(name, "member") == 0) {
                        num_mem = num_vals;
                        members = talloc_array(tmp_ctx, struct dom_sid, num_mem);
                        if (members == NULL) {
@@ -870,30 +882,30 @@ static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
 
                        /* we ignore unknown or uninteresting attributes
                         * (objectclass, etc.) */
-                       if (StrCaseCmp(name, "gidNumber") == 0) {
+                       if (strcasecmp_m(name, "gidNumber") == 0) {
                                map.gid = strtoul(val, &q, 10);
                                if (*q) {
                                        errno = EIO;
                                        goto failed;
                                }
-                       } else if (StrCaseCmp(name, "sid") == 0) {
+                       } else if (strcasecmp_m(name, "sid") == 0) {
                                if (!string_to_sid(&map.sid, val)) {
                                        errno = EIO;
                                        goto failed;
                                }
-                       } else if (StrCaseCmp(name, "sidNameUse") == 0) {
+                       } else if (strcasecmp_m(name, "sidNameUse") == 0) {
                                map.sid_name_use = strtoul(val, &q, 10);
                                if (*q) {
                                        errno = EIO;
                                        goto failed;
                                }
-                       } else if (StrCaseCmp(name, "ntname") == 0) {
+                       } else if (strcasecmp_m(name, "ntname") == 0) {
                                strlcpy(map.nt_name, val,
-                                       sizeof(map.nt_name) -1);
-                       } else if (StrCaseCmp(name, "comment") == 0) {
+                                       sizeof(map.nt_name));
+                       } else if (strcasecmp_m(name, "comment") == 0) {
                                strlcpy(map.comment, val,
-                                       sizeof(map.comment) -1);
-                       } else if (StrCaseCmp(name, "member") == 0) {
+                                       sizeof(map.comment));
+                       } else if (strcasecmp_m(name, "member") == 0) {
                                if (!string_to_sid(&members[j], val)) {
                                        errno = EIO;
                                        goto failed;