lib: Pass mem_ctx to cache_path()
authorVolker Lendecke <vl@samba.org>
Thu, 16 Aug 2018 08:51:44 +0000 (10:51 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 17 Aug 2018 12:28:51 +0000 (14:28 +0200)
Fix a confusing API: Many places TALLOC_FREE the path where it's not
clear you have to do it.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Fri Aug 17 14:28:51 CEST 2018 on sn-devel-144

15 files changed:
libgpo/pygpo.c
source3/lib/gencache.c
source3/lib/util_path.c
source3/lib/util_path.h
source3/libgpo/gpext/registry.c
source3/libgpo/gpext/scripts.c
source3/libgpo/gpext/security.c
source3/libsmb/samlogon_cache.c
source3/nmbd/nmbd_serverlistdb.c
source3/passdb/login_cache.c
source3/printing/printing.c
source3/printing/printing_db.c
source3/profile/profile.c
source3/smbd/lanman.c
source3/utils/net_ads_gpo.c

index 8848642..cd10731 100644 (file)
@@ -93,7 +93,7 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args,
        }
 
        if (!cache_dir) {
-               cache_dir = cache_path(GPO_CACHE_DIR);
+               cache_dir = cache_path(talloc_tos(), GPO_CACHE_DIR);
                if (!cache_dir) {
                        PyErr_SetString(PyExc_MemoryError,
                                        "Failed to determine gpo cache dir");
index 158554b..b4d374b 100644 (file)
@@ -64,7 +64,7 @@ static bool gencache_init(void)
 
        hash_size = lp_parm_int(-1, "gencache", "hash_size", 10000);
 
-       cache_fname = cache_path("gencache.tdb");
+       cache_fname = cache_path(talloc_tos(), "gencache.tdb");
        if (cache_fname == NULL) {
                return false;
        }
index efe3e60..d9fed29 100644 (file)
@@ -91,9 +91,9 @@ char *state_path(TALLOC_CTX *mem_ctx, const char *name)
  * @retval Pointer to a talloc'ed string containing the full path.
  **/
 
-char *cache_path(const char *name)
+char *cache_path(TALLOC_CTX *mem_ctx, const char *name)
 {
-       return xx_path(talloc_tos(), name, lp_cache_directory());
+       return xx_path(mem_ctx, name, lp_cache_directory());
 }
 
 /**
index b189b3e..3e7d04d 100644 (file)
@@ -29,7 +29,7 @@
 
 char *lock_path(TALLOC_CTX *mem_ctx, const char *name);
 char *state_path(TALLOC_CTX *mem_ctx, const char *name);
-char *cache_path(const char *name);
+char *cache_path(TALLOC_CTX *mem_ctx, const char *name);
 char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path);
 
 #endif
index 5d51bdf..525493f 100644 (file)
@@ -291,7 +291,7 @@ static NTSTATUS registry_process_group_policy(TALLOC_CTX *mem_ctx,
        size_t num_entries = 0;
        char *unix_path = NULL;
        const struct GROUP_POLICY_OBJECT *gpo;
-       char *gpo_cache_path = cache_path(GPO_CACHE_DIR);
+       char *gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
        if (gpo_cache_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index de66413..dfa9958 100644 (file)
@@ -364,7 +364,7 @@ static NTSTATUS scripts_process_group_policy(TALLOC_CTX *mem_ctx,
                GP_SCRIPTS_INI_LOGOFF
        };
        const struct GROUP_POLICY_OBJECT *gpo;
-       char *gpo_cache_path = cache_path(GPO_CACHE_DIR);
+       char *gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
        if (gpo_cache_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index b6b7ca0..a915eec 100644 (file)
@@ -154,7 +154,7 @@ static NTSTATUS security_process_group_policy(TALLOC_CTX *mem_ctx,
        char *unix_path = NULL;
        struct gp_inifile_context *ini_ctx = NULL;
        const struct GROUP_POLICY_OBJECT *gpo;
-       char *gpo_cache_path = cache_path(GPO_CACHE_DIR);
+       char *gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
        if (gpo_cache_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index ae77610..74e89d7 100644 (file)
@@ -51,7 +51,7 @@ bool netsamlogon_cache_init(void)
                return true;
        }
 
-       path = cache_path(NETSAMLOGON_TDB);
+       path = cache_path(talloc_tos(), NETSAMLOGON_TDB);
        if (path == NULL) {
                return false;
        }
index 05dcb6c..ad25183 100644 (file)
@@ -300,7 +300,7 @@ void write_browse_list(time_t t, bool force_write)
 
        updatecount++;
 
-       fname = cache_path(SERVER_LIST);
+       fname = cache_path(talloc_tos(), SERVER_LIST);
        if (!fname) {
                return;
        }
index eebb50a..6b636b3 100644 (file)
@@ -38,7 +38,7 @@ bool login_cache_init(void)
        /* skip file open if it's already opened */
        if (cache) return True;
 
-       cache_fname = cache_path(LOGIN_CACHE_FILE);
+       cache_fname = cache_path(talloc_tos(), LOGIN_CACHE_FILE);
        if (cache_fname == NULL) {
                DEBUG(0, ("Filename allocation failed.\n"));
                return False;
index 0acbb7e..efdd687 100644 (file)
@@ -204,7 +204,7 @@ bool print_backend_init(struct messaging_context *msg_ctx)
                return false;
        }
 
-       print_cache_path = cache_path("printing");
+       print_cache_path = cache_path(talloc_tos(), "printing");
        if (print_cache_path == NULL) {
                return false;
        }
@@ -214,7 +214,7 @@ bool print_backend_init(struct messaging_context *msg_ctx)
                return false;
        }
 
-       print_cache_path = cache_path("printing.tdb");
+       print_cache_path = cache_path(talloc_tos(), "printing.tdb");
        if (print_cache_path == NULL) {
                return false;
        }
index 7465195..3fa8557 100644 (file)
@@ -95,7 +95,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
                DLIST_ADD(print_db_head, p);
        }
 
-       print_cache_path = cache_path("printing/");
+       print_cache_path = cache_path(talloc_tos(), "printing/");
        if (print_cache_path == NULL) {
                DLIST_REMOVE(print_db_head, p);
                SAFE_FREE(p);
index 833c9c4..5deef81 100644 (file)
@@ -129,7 +129,7 @@ bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
                return true;
        }
 
-       db_name = cache_path("smbprofile.tdb");
+       db_name = cache_path(talloc_tos(), "smbprofile.tdb");
        if (db_name == NULL) {
                return false;
        }
index 90906a2..dcc7f91 100644 (file)
@@ -1228,7 +1228,7 @@ static int get_session_info(uint32_t servertype,
        char **lines;
        bool local_list_only;
        int i;
-       char *slist_cache_path = cache_path(SERVER_LIST);
+       char *slist_cache_path = cache_path(talloc_tos(), SERVER_LIST);
        if (slist_cache_path == NULL) {
                return 0;
        }
index f2f65c8..791e836 100644 (file)
@@ -100,7 +100,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
        d_printf(_("finished\n"));
 
        d_printf(_("* Refreshing Group Policy Data "));
-       gpo_cache_path = cache_path(GPO_CACHE_DIR);
+       gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
        if (gpo_cache_path == NULL) {
                d_printf(_("failed: %s\n"), nt_errstr(NT_STATUS_NO_MEMORY));
                goto out;