lib: Use "mem_ctx" arg in gencache_get
authorVolker Lendecke <vl@samba.org>
Wed, 4 Sep 2013 06:57:59 +0000 (08:57 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 5 Sep 2013 18:09:21 +0000 (20:09 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Signed-off-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Sep  5 20:09:21 CEST 2013 on sn-devel-104

source3/auth/user_util.c
source3/lib/gencache.c
source3/lib/idmap_cache.c
source3/libsmb/conncache.c
source3/libsmb/namecache.c
source3/libsmb/trustdom_cache.c
source3/passdb/account_pol.c
source3/rpc_server/spoolss/srv_spoolss_nt.c
source3/torture/torture.c
source3/winbindd/winbindd_cm.c

index b52f1dd5bcbde0ee8e7555b1c6a0ae961d472c5f..70ab5ade654bb1710bd25a908349859b72083bee 100644 (file)
@@ -96,14 +96,13 @@ static bool fetch_map_from_gencache(TALLOC_CTX *ctx,
        if (key == NULL) {
                return false;
        }
-       found = gencache_get(key, NULL, &value, NULL);
+       found = gencache_get(key, ctx, &value, NULL);
        TALLOC_FREE(key);
        if (!found) {
                return false;
        }
        TALLOC_FREE(*p_user_out);
-       *p_user_out = talloc_strdup(ctx, value);
-       SAFE_FREE(value);
+       *p_user_out = value;
        if (!*p_user_out) {
                return false;
        }
index 1ecaad5be53c887c0f15e2524ae70de34131a9b7..2c5e9ab4245635cff14a153a66a98decd6aae81d 100644 (file)
@@ -711,7 +711,7 @@ bool gencache_get(const char *keystr, TALLOC_CTX *mem_ctx, char **value,
        DATA_BLOB blob;
        bool ret = False;
 
-       ret = gencache_get_data_blob(keystr, NULL, &blob, ptimeout, NULL);
+       ret = gencache_get_data_blob(keystr, mem_ctx, &blob, ptimeout, NULL);
        if (!ret) {
                return false;
        }
@@ -725,11 +725,7 @@ bool gencache_get(const char *keystr, TALLOC_CTX *mem_ctx, char **value,
                return false;
        }
        if (value) {
-               *value = SMB_STRDUP((char *)blob.data);
-               data_blob_free(&blob);
-               if (*value == NULL) {
-                       return false;
-               }
+               *value = talloc_move(mem_ctx, (char **)&blob.data);
                return true;
        }
        data_blob_free(&blob);
@@ -783,8 +779,11 @@ static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key,
                keystr = (char *)key.dptr;
        } else {
                /* ensure 0-termination */
-               keystr = SMB_STRNDUP((char *)key.dptr, key.dsize);
+               keystr = talloc_strndup(talloc_tos(), (char *)key.dptr, key.dsize);
                free_key = keystr;
+               if (keystr == NULL) {
+                       goto done;
+               }
        }
 
        if (!gencache_pull_timeout((char *)data.dptr, &timeout, &endptr)) {
@@ -806,7 +805,7 @@ static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key,
                  timeout, state->private_data);
 
  done:
-       SAFE_FREE(free_key);
+       TALLOC_FREE(free_key);
        return 0;
 }
 
@@ -862,8 +861,11 @@ static void gencache_iterate_fn(const char *key, DATA_BLOB value,
                valstr = (char *)value.data;
        } else {
                /* ensure 0-termination */
-               valstr = SMB_STRNDUP((char *)value.data, value.length);
+               valstr = talloc_strndup(talloc_tos(), (char *)value.data, value.length);
                free_val = valstr;
+               if (valstr == NULL) {
+                       goto done;
+               }
        }
 
        DEBUG(10, ("Calling function with arguments "
@@ -872,7 +874,9 @@ static void gencache_iterate_fn(const char *key, DATA_BLOB value,
 
        state->fn(key, valstr, timeout, state->private_data);
 
-       SAFE_FREE(free_val);
+  done:
+
+       TALLOC_FREE(free_val);
 }
 
 void gencache_iterate(void (*fn)(const char *key, const char *value,
index 627ced30b3504d7ff862073686a3d078738709a2..ffd3c1955cdc723f80bc464cdf915983664ed9f5 100644 (file)
@@ -48,7 +48,7 @@ bool idmap_cache_find_sid2unixid(const struct dom_sid *sid, struct unixid *id,
        if (key == NULL) {
                return false;
        }
-       ret = gencache_get(key, NULL, &value, &timeout);
+       ret = gencache_get(key, talloc_tos(), &value, &timeout);
        if (!ret) {
                goto done;
        }
@@ -128,7 +128,7 @@ bool idmap_cache_find_sid2unixid(const struct dom_sid *sid, struct unixid *id,
 
 done:
        TALLOC_FREE(key);
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
        return ret;
 }
 
@@ -209,7 +209,7 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired)
        if (key == NULL) {
                return false;
        }
-       ret = gencache_get(key, NULL, &value, &timeout);
+       ret = gencache_get(key, talloc_tos(), &value, &timeout);
        TALLOC_FREE(key);
        if (!ret) {
                return false;
@@ -218,7 +218,7 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired)
        if (value[0] != '-') {
                ret = string_to_sid(sid, value);
        }
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
        if (ret) {
                *expired = (timeout <= time(NULL));
        }
@@ -246,7 +246,7 @@ bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired)
        if (key == NULL) {
                return false;
        }
-       ret = gencache_get(key, NULL, &value, &timeout);
+       ret = gencache_get(key, talloc_tos(), &value, &timeout);
        TALLOC_FREE(key);
        if (!ret) {
                return false;
@@ -255,7 +255,7 @@ bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired)
        if (value[0] != '-') {
                ret = string_to_sid(sid, value);
        }
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
        if (ret) {
                *expired = (timeout <= time(NULL));
        }
@@ -431,7 +431,7 @@ static bool idmap_cache_del_xid(char t, int xid)
        time_t timeout;
        bool ret = true;
 
-       if (!gencache_get(key, NULL, &sid_str, &timeout)) {
+       if (!gencache_get(key, mem_ctx, &sid_str, &timeout)) {
                DEBUG(3, ("no entry: %s\n", key));
                ret = false;
                goto done;
index dfc2f471acb34354df148ca349d09d5101828206..9bf4c56a339f699720e7ec763568bfd82068b46d 100644 (file)
@@ -143,13 +143,13 @@ NTSTATUS check_negative_conn_cache( const char *domain, const char *server)
        if (key == NULL)
                goto done;
 
-       if (gencache_get(key, NULL, &value, NULL))
+       if (gencache_get(key, talloc_tos(), &value, NULL))
                result = negative_conn_cache_valuedecode(value);
  done:
        DEBUG(9,("check_negative_conn_cache returning result %d for domain %s "
                  "server %s\n", NT_STATUS_V(result), domain, server));
        TALLOC_FREE(key);
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
        return result;
 }
 
index ebd51fd919a50a5482519a4399303f4c39fc1e43..1e6158444dcfbbaa6fa488b0383badfadfe3ad69 100644 (file)
@@ -156,7 +156,7 @@ bool namecache_fetch(const char *name,
                return False;
        }
 
-       if (!gencache_get(key, NULL, &value, &timeout)) {
+       if (!gencache_get(key, talloc_tos(), &value, &timeout)) {
                DEBUG(5, ("no entry for %s#%02X found.\n", name, name_type));
                SAFE_FREE(key);
                return False;
@@ -170,7 +170,7 @@ bool namecache_fetch(const char *name,
        *num_names = ipstr_list_parse(value, ip_list);
 
        SAFE_FREE(key);
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
 
        return *num_names > 0; /* true only if some ip has been fetched */
 }
@@ -294,7 +294,7 @@ bool namecache_status_fetch(const char *keyname,
        if (!key)
                return False;
 
-       if (!gencache_get(key, NULL, &value, &timeout)) {
+       if (!gencache_get(key, talloc_tos(), &value, &timeout)) {
                DEBUG(5, ("namecache_status_fetch: no entry for %s found.\n",
                                        key));
                SAFE_FREE(key);
@@ -306,6 +306,6 @@ bool namecache_status_fetch(const char *keyname,
 
        strlcpy(srvname_out, value, 16);
        SAFE_FREE(key);
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
        return True;
 }
index 81b366a4ccea56ce9c38ef0d9f50be94cf27c56a..81d8bf9c7a55b8df6d83c1a4f9aeff6bac55215a 100644 (file)
@@ -160,7 +160,7 @@ bool trustdom_cache_fetch(const char* name, struct dom_sid* sid)
        if (!key)
                return False;
 
-       if (!gencache_get(key, NULL, &value, &timeout)) {
+       if (!gencache_get(key, talloc_tos(), &value, &timeout)) {
                DEBUG(5, ("no entry for trusted domain %s found.\n", name));
                SAFE_FREE(key);
                return False;
@@ -172,11 +172,11 @@ bool trustdom_cache_fetch(const char* name, struct dom_sid* sid)
        /* convert sid string representation into struct dom_sid structure */
        if(! string_to_sid(sid, value)) {
                sid = NULL;
-               SAFE_FREE(value);
+               TALLOC_FREE(value);
                return False;
        }
 
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
        return True;
 }
 
@@ -191,7 +191,7 @@ uint32 trustdom_cache_fetch_timestamp( void )
        time_t timeout;
        uint32 timestamp;
 
-       if (!gencache_get(TDOMTSKEY, NULL, &value, &timeout)) {
+       if (!gencache_get(TDOMTSKEY, talloc_tos(), &value, &timeout)) {
                DEBUG(5, ("no timestamp for trusted domain cache located.\n"));
                SAFE_FREE(value);
                return 0;
@@ -199,7 +199,7 @@ uint32 trustdom_cache_fetch_timestamp( void )
 
        timestamp = atoi(value);
 
-       SAFE_FREE(value);
+       TALLOC_FREE(value);
        return timestamp;
 }
 
index 14ff946b5103ed6ba46122705c7d5eeb683dad34..06925e8af666bdd90d254e66d69219fd0a123a3c 100644 (file)
@@ -446,7 +446,7 @@ bool cache_account_policy_get(enum pdb_policy_type type, uint32_t *value)
                goto done;
        }
 
-       if (gencache_get(cache_key, NULL, &cache_value, NULL)) {
+       if (gencache_get(cache_key, talloc_tos(), &cache_value, NULL)) {
                uint32 tmp = strtoul(cache_value, NULL, 10);
                *value = tmp;
                ret = True;
@@ -454,7 +454,7 @@ bool cache_account_policy_get(enum pdb_policy_type type, uint32_t *value)
 
  done:
        SAFE_FREE(cache_key);
-       SAFE_FREE(cache_value);
+       TALLOC_FREE(cache_value);
        return ret;
 }
 
index 37f11c78ee10bab99fe75f80217fa2acfef4f62a..89938e4b9f400ae180507c3e521d1d5f68550ac8 100644 (file)
@@ -631,16 +631,16 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
        cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
                                    aprinter);
        if ((cache_key != NULL) &&
-           gencache_get(cache_key, NULL, &tmp, NULL)) {
+           gencache_get(cache_key, talloc_tos(), &tmp, NULL)) {
 
                found = (strcmp(tmp, printer_not_found) != 0);
                if (!found) {
                        DEBUG(4, ("Printer %s not found\n", aprinter));
-                       SAFE_FREE(tmp);
+                       TALLOC_FREE(tmp);
                        return WERR_INVALID_PRINTER_NAME;
                }
                fstrcpy(sname, tmp);
-               SAFE_FREE(tmp);
+               TALLOC_FREE(tmp);
        }
 
        /* Search all sharenames first as this is easier than pulling
index f2446d1e34f9b85b86cda41ba50fdea1edd103af..8313cf141bf35cdefd0bdf0d51176057b38778f6 100644 (file)
@@ -8135,7 +8135,7 @@ static bool run_local_gencache(int dummy)
                return False;
        }
 
-       if (!gencache_get("foo", NULL, &val, &tm)) {
+       if (!gencache_get("foo", talloc_tos(), &val, &tm)) {
                d_printf("%s: gencache_get() failed\n", __location__);
                return False;
        }
@@ -8143,11 +8143,11 @@ static bool run_local_gencache(int dummy)
        if (strcmp(val, "bar") != 0) {
                d_printf("%s: gencache_get() returned %s, expected %s\n",
                         __location__, val, "bar");
-               SAFE_FREE(val);
+               TALLOC_FREE(val);
                return False;
        }
 
-       SAFE_FREE(val);
+       TALLOC_FREE(val);
 
        if (!gencache_del("foo")) {
                d_printf("%s: gencache_del() failed\n", __location__);
@@ -8159,7 +8159,7 @@ static bool run_local_gencache(int dummy)
                return False;
        }
 
-       if (gencache_get("foo", NULL, &val, &tm)) {
+       if (gencache_get("foo", talloc_tos(), &val, &tm)) {
                d_printf("%s: gencache_get() on deleted entry "
                         "succeeded\n", __location__);
                return False;
@@ -8173,7 +8173,7 @@ static bool run_local_gencache(int dummy)
                return False;
        }
 
-       if (!gencache_get_data_blob("foo", NULL, &blob, NULL, NULL)) {
+       if (!gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
                d_printf("%s: gencache_get_data_blob() failed\n", __location__);
                return False;
        }
@@ -8197,7 +8197,7 @@ static bool run_local_gencache(int dummy)
                return False;
        }
 
-       if (gencache_get_data_blob("foo", NULL, &blob, NULL, NULL)) {
+       if (gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
                d_printf("%s: gencache_get_data_blob() on deleted entry "
                         "succeeded\n", __location__);
                return False;
@@ -8212,7 +8212,7 @@ static bool run_local_gencache(int dummy)
                         __location__);
                return false;
        }
-       if (gencache_get("blob", NULL, &val, &tm)) {
+       if (gencache_get("blob", talloc_tos(), &val, &tm)) {
                d_printf("%s: gencache_get succeeded\n", __location__);
                return false;
        }
index 17ede8c5cf2295b2e59b143c4d5baae02d639ba7..3906d3d1ff91133ebbe64ab4065b3433596e089f 100644 (file)
@@ -1512,7 +1512,7 @@ bool fetch_current_dc_from_gencache(TALLOC_CTX *mem_ctx,
        if (key == NULL) {
                goto done;
        }
-       if (!gencache_get(key, NULL, &value, NULL)) {
+       if (!gencache_get(key, mem_ctx, &value, NULL)) {
                goto done;
        }
        p = strchr(value, ' ');
@@ -1541,6 +1541,7 @@ done:
        TALLOC_FREE(dc_name);
        TALLOC_FREE(dc_ip);
        TALLOC_FREE(key);
+       TALLOC_FREE(value);
        return ret;
 }