idmap-autorid: Use talloc_tos() in idmap_autorid_id_to_sid
[samba.git] / source3 / winbindd / idmap_autorid.c
index 786bdfc5f1003f3624153f98e32bb3a297bf37e1..e814d0da1ff46f605370859e4ef4423b88b46126 100644 (file)
@@ -130,8 +130,7 @@ static NTSTATUS idmap_autorid_get_domainrange(struct db_context *db,
 
 }
 
-static NTSTATUS idmap_autorid_id_to_sid(TALLOC_CTX * memctx,
-                                       struct autorid_global_config *cfg,
+static NTSTATUS idmap_autorid_id_to_sid(struct autorid_global_config *cfg,
                                        struct id_map *map)
 {
        uint32_t range;
@@ -157,30 +156,33 @@ static NTSTATUS idmap_autorid_id_to_sid(TALLOC_CTX * memctx,
        /* determine the range of this uid */
        range = ((map->xid.id - cfg->minvalue) / cfg->rangesize);
 
-       keystr = talloc_asprintf(memctx, "%u", range);
+       keystr = talloc_asprintf(talloc_tos(), "%u", range);
        if (!keystr) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       data = dbwrap_fetch_bystring(autorid_db, memctx, keystr);
+       data = dbwrap_fetch_bystring(autorid_db, talloc_tos(), keystr);
+       TALLOC_FREE(keystr);
 
        if (!data.dptr) {
                DEBUG(4, ("id %d belongs to range %d which does not have "
                          "domain mapping, ignoring mapping request\n",
                          map->xid.id, range));
-       } else {
-               string_to_sid(&sid, (const char *)data.dptr);
+               return NT_STATUS_OK;
+       }
 
-               sid_compose(map->sid, &sid,
-                           (map->xid.id - cfg->minvalue -
-                            range * cfg->rangesize));
+       string_to_sid(&sid, (const char *)data.dptr);
+       TALLOC_FREE(data.dptr);
 
-               /* We **really** should have some way of validating
-                  the SID exists and is the correct type here.  But
-                  that is a deficiency in the idmap_rid design. */
+       sid_compose(map->sid, &sid,
+                   (map->xid.id - cfg->minvalue -
+                    range * cfg->rangesize));
 
-               map->status = ID_MAPPED;
-       }
+       /* We **really** should have some way of validating
+          the SID exists and is the correct type here.  But
+          that is a deficiency in the idmap_rid design. */
+
+       map->status = ID_MAPPED;
        return NT_STATUS_OK;
 }
 
@@ -243,7 +245,7 @@ static NTSTATUS idmap_autorid_unixids_to_sids(struct idmap_domain *dom,
 
        for (i = 0; ids[i]; i++) {
 
-               ret = idmap_autorid_id_to_sid(ctx, globalcfg, ids[i]);
+               ret = idmap_autorid_id_to_sid(globalcfg, ids[i]);
 
                if ((!NT_STATUS_IS_OK(ret)) &&
                    (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
@@ -271,17 +273,9 @@ static NTSTATUS idmap_autorid_sids_to_unixids(struct idmap_domain *dom,
                                              struct id_map **ids)
 {
        struct autorid_global_config *global;
-       TALLOC_CTX *ctx;
        NTSTATUS ret;
        int i;
 
-       ctx = talloc_new(dom);
-       if (!ctx) {
-               DEBUG(0, ("Out of memory!\n"));
-               ret = NT_STATUS_NO_MEMORY;
-               goto failure;
-       }
-
        /* initialize the status to avoid surprise */
        for (i = 0; ids[i]; i++) {
                ids[i]->status = ID_UNKNOWN;
@@ -339,12 +333,9 @@ static NTSTATUS idmap_autorid_sids_to_unixids(struct idmap_domain *dom,
                        goto failure;
                }
        }
-
-       talloc_free(ctx);
        return NT_STATUS_OK;
 
       failure:
-       talloc_free(ctx);
        return ret;
 
 }