Simplify idmap_cache_build_[s]idkey a bit
authorVolker Lendecke <vl@samba.org>
Thu, 3 Jul 2008 02:57:30 +0000 (04:57 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 3 Jul 2008 19:19:09 +0000 (21:19 +0200)
(This used to be commit 80932c0266ef73b8d0462c078a053444fff47f32)

source3/winbindd/idmap_cache.c

index b724ba0c592725d25eea02ef88b153e59ca01a36..0b3c22eb20de8e12ed0436bb659a691d24e0845f 100644 (file)
@@ -70,33 +70,19 @@ struct idmap_cache_ctx *idmap_cache_init(TALLOC_CTX *memctx)
        return cache;
 }
 
-static NTSTATUS idmap_cache_build_sidkey(TALLOC_CTX *ctx, char **sidkey,
-                                        const struct id_map *id)
+static char *idmap_cache_sidkey(TALLOC_CTX *ctx, const DOM_SID *sid)
 {
        fstring sidstr;
 
-       *sidkey = talloc_asprintf(ctx, "IDMAP/SID/%s",
-                                 sid_to_fstring(sidstr, id->sid));
-       if ( ! *sidkey) {
-               DEBUG(1, ("failed to build sidkey, OOM?\n"));
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       return NT_STATUS_OK;
+       return talloc_asprintf(ctx, "IDMAP/SID/%s",
+                              sid_to_fstring(sidstr, sid));
 }
 
-static NTSTATUS idmap_cache_build_idkey(TALLOC_CTX *ctx, char **idkey,
-                                       const struct id_map *id)
+static char *idmap_cache_idkey(TALLOC_CTX *ctx, const struct id_map *id)
 {
-       *idkey = talloc_asprintf(ctx, "IDMAP/%s/%lu",
-                               (id->xid.type==ID_TYPE_UID)?"UID":"GID",
-                               (unsigned long)id->xid.id);
-       if ( ! *idkey) {
-               DEBUG(1, ("failed to build idkey, OOM?\n"));
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       return NT_STATUS_OK;
+       return talloc_asprintf(ctx, "IDMAP/%s/%lu",
+                              (id->xid.type==ID_TYPE_UID)?"UID":"GID",
+                              (unsigned long)id->xid.id);
 }
 
 NTSTATUS idmap_cache_set(struct idmap_cache_ctx *cache, const struct id_map *id)
@@ -120,12 +106,15 @@ NTSTATUS idmap_cache_set(struct idmap_cache_ctx *cache, const struct id_map *id)
                return NT_STATUS_OK;
        }
 
-       ret = idmap_cache_build_sidkey(cache, &sidkey, id);
-       if (!NT_STATUS_IS_OK(ret)) return ret;
+       sidkey = idmap_cache_sidkey(cache, id->sid);
+       if (sidkey == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        /* use sidkey as the local memory ctx */
-       ret = idmap_cache_build_idkey(sidkey, &idkey, id);
-       if (!NT_STATUS_IS_OK(ret)) {
+       idkey = idmap_cache_idkey(sidkey, id);
+       if (idkey == NULL) {
+               ret = NT_STATUS_NO_MEMORY;
                goto done;
        }
 
@@ -182,14 +171,16 @@ done:
 
 NTSTATUS idmap_cache_set_negative_sid(struct idmap_cache_ctx *cache, const struct id_map *id)
 {
-       NTSTATUS ret;
+       NTSTATUS ret = NT_STATUS_OK;
        time_t timeout = time(NULL) + lp_idmap_negative_cache_time();
        TDB_DATA databuf;
        char *sidkey;
        char *valstr;
 
-       ret = idmap_cache_build_sidkey(cache, &sidkey, id);
-       if (!NT_STATUS_IS_OK(ret)) return ret;
+       sidkey = idmap_cache_sidkey(cache, id->sid);
+       if (sidkey == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        /* use sidkey as the local memory ctx */
        valstr = talloc_asprintf(sidkey, IDMAP_CACHE_DATA_FMT, (int)timeout, "IDMAP/NEGATIVE");
@@ -218,14 +209,16 @@ done:
 
 NTSTATUS idmap_cache_set_negative_id(struct idmap_cache_ctx *cache, const struct id_map *id)
 {
-       NTSTATUS ret;
+       NTSTATUS ret = NT_STATUS_OK;
        time_t timeout = time(NULL) + lp_idmap_negative_cache_time();
        TDB_DATA databuf;
        char *idkey;
        char *valstr;
 
-       ret = idmap_cache_build_idkey(cache, &idkey, id);
-       if (!NT_STATUS_IS_OK(ret)) return ret;
+       idkey = idmap_cache_idkey(cache, id);
+       if (idkey == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        /* use idkey as the local memory ctx */
        valstr = talloc_asprintf(idkey, IDMAP_CACHE_DATA_FMT, (int)timeout, "IDMAP/NEGATIVE");
@@ -317,7 +310,7 @@ failed:
 
 NTSTATUS idmap_cache_map_sid(struct idmap_cache_ctx *cache, struct id_map *id)
 {
-       NTSTATUS ret;
+       NTSTATUS ret = NT_STATUS_OK;
        TDB_DATA databuf;
        time_t t;
        char *sidkey;
@@ -328,8 +321,10 @@ NTSTATUS idmap_cache_map_sid(struct idmap_cache_ctx *cache, struct id_map *id)
        /* make sure it is marked as not mapped by default */
        id->status = ID_UNKNOWN;
 
-       ret = idmap_cache_build_sidkey(cache, &sidkey, id);
-       if (!NT_STATUS_IS_OK(ret)) return ret;
+       sidkey = idmap_cache_sidkey(cache, id->sid);
+       if (sidkey == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        databuf = tdb_fetch_bystring(cache->tdb, sidkey);
 
@@ -438,8 +433,10 @@ NTSTATUS idmap_cache_map_id(struct idmap_cache_ctx *cache, struct id_map *id)
        /* make sure it is marked as unknown by default */
        id->status = ID_UNKNOWN;
 
-       ret = idmap_cache_build_idkey(cache, &idkey, id);
-       if (!NT_STATUS_IS_OK(ret)) return ret;
+       idkey = idmap_cache_idkey(cache, id);
+       if (idkey == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        databuf = tdb_fetch_bystring(cache->tdb, idkey);