lib: Pass mem_ctx to state_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 09:30:11 +0000 (11:30 +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>
22 files changed:
source3/groupdb/mapping_tdb.c
source3/lib/eventlog/eventlog.c
source3/lib/sharesec.c
source3/lib/util_path.c
source3/lib/util_path.h
source3/modules/vfs_acl_tdb.c
source3/modules/vfs_xattr_tdb.c
source3/nmbd/nmbd_winsserver.c
source3/passdb/account_pol.c
source3/passdb/pdb_tdb.c
source3/printing/nt_printing.c
source3/printing/nt_printing_migrate_internal.c
source3/printing/nt_printing_tdb.c
source3/registry/reg_backend_db.c
source3/registry/reg_perfcount.c
source3/utils/net_idmap.c
source3/utils/net_registry.c
source3/utils/smbcontrol.c
source3/winbindd/idmap_autorid.c
source3/winbindd/idmap_tdb.c
source3/winbindd/winbindd.c
source3/winbindd/winbindd_cache.c

index adc7d0b..3561057 100644 (file)
@@ -53,7 +53,7 @@ static bool init_group_mapping(void)
                return true;
        }
 
-       tdb_path = state_path("group_mapping.tdb");
+       tdb_path = state_path(talloc_tos(), "group_mapping.tdb");
        if (tdb_path == NULL) {
                return false;
        }
@@ -67,7 +67,7 @@ static bool init_group_mapping(void)
                return false;
        }
 
-       ldb_path = state_path("group_mapping.ldb");
+       ldb_path = state_path(talloc_tos(), "group_mapping.ldb");
        if (ldb_path == NULL) {
                talloc_free(tdb_path);
                return false;
@@ -1084,7 +1084,7 @@ static bool mapping_switch(const char *ldb_path)
        }
 
        /* now rename the old db out of the way */
-       new_path = state_path("group_mapping.ldb.replaced");
+       new_path = state_path(talloc_tos(), "group_mapping.ldb.replaced");
        if (!new_path) {
                goto failed;
        }
index 9053fdd..4b63118 100644 (file)
@@ -73,7 +73,7 @@ char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
        char *file;
        char *tdbname;
 
-       path = state_path("eventlog");
+       path = state_path(talloc_tos(), "eventlog");
        if (!path) {
                return NULL;
        }
@@ -373,7 +373,7 @@ ELOG_TDB *elog_open_tdb( const char *logname, bool force_clear, bool read_only )
 
        /* make sure that the eventlog dir exists */
 
-       eventlogdir = state_path("eventlog");
+       eventlogdir = state_path(talloc_tos(), "eventlog");
        if (eventlogdir == NULL) {
                return NULL;
        }
index d790b08..58a2dee 100644 (file)
@@ -148,7 +148,7 @@ bool share_info_db_init(void)
                return True;
        }
 
-       db_path = state_path("share_info.tdb");
+       db_path = state_path(talloc_tos(), "share_info.tdb");
        if (db_path == NULL) {
                return false;
        }
index b8ce304..efe3e60 100644 (file)
@@ -78,9 +78,9 @@ char *lock_path(TALLOC_CTX *mem_ctx, const char *name)
  * @retval Pointer to a talloc'ed string containing the full path.
  **/
 
-char *state_path(const char *name)
+char *state_path(TALLOC_CTX *mem_ctx, const char *name)
 {
-       return xx_path(talloc_tos(), name, lp_state_directory());
+       return xx_path(mem_ctx, name, lp_state_directory());
 }
 
 /**
index 6df67fb..b189b3e 100644 (file)
@@ -28,7 +28,7 @@
 #include <talloc.h>
 
 char *lock_path(TALLOC_CTX *mem_ctx, const char *name);
-char *state_path(const char *name);
+char *state_path(TALLOC_CTX *mem_ctx, const char *name);
 char *cache_path(const char *name);
 char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path);
 
index bb69170..7506e4e 100644 (file)
@@ -50,7 +50,7 @@ static bool acl_tdb_init(void)
                return true;
        }
 
-       dbname = state_path("file_ntacls.tdb");
+       dbname = state_path(talloc_tos(), "file_ntacls.tdb");
 
        if (dbname == NULL) {
                errno = ENOSYS;
index f67a86f..32968ae 100644 (file)
@@ -458,7 +458,7 @@ static bool xattr_tdb_init(int snum, TALLOC_CTX *mem_ctx, struct db_context **p_
        const char *dbname;
        char *def_dbname;
 
-       def_dbname = state_path("xattr.tdb");
+       def_dbname = state_path(talloc_tos(), "xattr.tdb");
        if (def_dbname == NULL) {
                errno = ENOSYS;
                return false;
index cd7d3b7..c34bfae 100644 (file)
@@ -601,7 +601,7 @@ bool initialise_wins(void)
                return True;
        }
 
-       db_path = state_path("wins.tdb");
+       db_path = state_path(talloc_tos(), "wins.tdb");
        if (db_path == NULL) {
                return false;
        }
@@ -620,7 +620,7 @@ bool initialise_wins(void)
 
        add_samba_names_to_subnet(wins_server_subnet);
 
-       list_path = state_path(WINS_LIST);
+       list_path = state_path(talloc_tos(), WINS_LIST);
        if (list_path == NULL) {
                tdb_close(wins_tdb);
                return false;
@@ -2493,7 +2493,7 @@ void wins_write_database(time_t t, bool background)
                }
        }
 
-       if (!(fname = state_path(WINS_LIST))) {
+       if (!(fname = state_path(talloc_tos(), WINS_LIST))) {
                goto err_exit;
        }
        /* This is safe as the 0 length means "don't expand". */
index 421a054..4d94dfe 100644 (file)
@@ -220,7 +220,7 @@ bool init_account_policy(void)
                return True;
        }
 
-       db_path = state_path("account_policy.tdb");
+       db_path = state_path(talloc_tos(), "account_policy.tdb");
        if (db_path == NULL) {
                return false;
        }
index 6f3dda6..91735ff 100644 (file)
@@ -336,7 +336,7 @@ static bool tdbsam_upgrade_next_rid(struct db_context *db)
                return true;
        }
 
-       db_path = state_path("winbindd_idmap.tdb");
+       db_path = state_path(talloc_tos(), "winbindd_idmap.tdb");
        if (db_path == NULL) {
                return false;
        }
index 633e350..9c4c488 100644 (file)
@@ -152,7 +152,7 @@ static bool print_driver_directories_init(void)
                }
        }
 
-       driver_path = state_path("DriverStore");
+       driver_path = state_path(talloc_tos(), "DriverStore");
        if (driver_path == NULL) {
                talloc_free(mem_ctx);
                return false;
@@ -165,7 +165,7 @@ static bool print_driver_directories_init(void)
                return false;
        }
 
-       driver_path = state_path("DriverStore/FileRepository");
+       driver_path = state_path(talloc_tos(), "DriverStore/FileRepository");
        if (driver_path == NULL) {
                talloc_free(mem_ctx);
                return false;
@@ -178,7 +178,7 @@ static bool print_driver_directories_init(void)
                return false;
        }
 
-       driver_path = state_path("DriverStore/Temp");
+       driver_path = state_path(talloc_tos(), "DriverStore/Temp");
        if (driver_path == NULL) {
                talloc_free(mem_ctx);
                return false;
index dd78e69..8bcc2d4 100644 (file)
@@ -198,9 +198,9 @@ bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
        NTSTATUS status;
 
        /* paths talloced on new stackframe */
-       drivers_path = state_path("ntdrivers.tdb");
-       printers_path = state_path("ntprinters.tdb");
-       forms_path = state_path("ntforms.tdb");
+       drivers_path = state_path(talloc_tos(), "ntdrivers.tdb");
+       printers_path = state_path(talloc_tos(), "ntprinters.tdb");
+       forms_path = state_path(talloc_tos(), "ntforms.tdb");
        if ((drivers_path == NULL) || (printers_path == NULL)
                                                || (forms_path == NULL)) {
                talloc_free(tmp_ctx);
index ea1e87e..0193b17 100644 (file)
@@ -349,17 +349,17 @@ bool nt_printing_tdb_upgrade(void)
        int32_t vers_id;
        bool ret;
 
-       drivers_path = state_path("ntdrivers.tdb");
+       drivers_path = state_path(talloc_tos(), "ntdrivers.tdb");
        if (drivers_path == NULL) {
                ret = false;
                goto err_out;
        }
-       printers_path = state_path("ntprinters.tdb");
+       printers_path = state_path(talloc_tos(), "ntprinters.tdb");
        if (printers_path == NULL) {
                ret = false;
                goto err_drvdb_free;
        }
-       forms_path = state_path("ntforms.tdb");
+       forms_path = state_path(talloc_tos(), "ntforms.tdb");
        if (forms_path == NULL) {
                ret = false;
                goto err_prdb_free;
index 928572e..aa97d60 100644 (file)
@@ -733,7 +733,7 @@ WERROR regdb_init(void)
                return WERR_OK;
        }
 
-       db_path = state_path("registry.tdb");
+       db_path = state_path(talloc_tos(), "registry.tdb");
        if (db_path == NULL) {
                return WERR_NOT_ENOUGH_MEMORY;
        }
@@ -861,7 +861,7 @@ WERROR regdb_open( void )
                return WERR_OK;
        }
 
-       db_path = state_path("registry.tdb");
+       db_path = state_path(talloc_tos(), "registry.tdb");
        if (db_path == NULL) {
                return WERR_NOT_ENOUGH_MEMORY;
        }
index e31f899..6fa96f3 100644 (file)
@@ -48,7 +48,7 @@ static char *counters_directory(const char *dbname)
        char *db_subpath = NULL;
        char *ret = NULL;
 
-       dir_path = state_path(PERFCOUNTDIR);
+       dir_path = state_path(talloc_tos(), PERFCOUNTDIR);
        if (dir_path == NULL) {
                return NULL;
        }
@@ -64,7 +64,7 @@ static char *counters_directory(const char *dbname)
                return NULL;
        }
 
-       ret = state_path(db_subpath);
+       ret = state_path(talloc_tos(), db_subpath);
        TALLOC_FREE(dir_path);
        return ret;
 }
index 4f36566..b49d5f4 100644 (file)
@@ -148,7 +148,7 @@ static char *net_idmap_dbfile(struct net_context *c,
                        d_fprintf(stderr, _("Out of memory!\n"));
                }
        } else if (strequal(backend, "tdb")) {
-               dbfile = state_path("winbindd_idmap.tdb");
+               dbfile = state_path(talloc_tos(), "winbindd_idmap.tdb");
                if (dbfile == NULL) {
                        d_fprintf(stderr, _("Out of memory!\n"));
                }
@@ -161,7 +161,7 @@ static char *net_idmap_dbfile(struct net_context *c,
                }
                ctx->backend = TDB;
        } else if (strequal(backend, "autorid")) {
-               dbfile = state_path("autorid.tdb");
+               dbfile = state_path(talloc_tos(), "autorid.tdb");
                if (dbfile == NULL) {
                        d_fprintf(stderr, _("Out of memory!\n"));
                }
index c67a148..01a36b2 100644 (file)
@@ -1512,7 +1512,7 @@ static int net_registry_check(struct net_context *c, int argc,
        } else if (argc > 0) {
                dbfile = talloc_strdup(talloc_tos(), argv[0]);
        } else {
-               dbfile = state_path("registry.tdb");
+               dbfile = state_path(talloc_tos(), "registry.tdb");
        }
        if (dbfile == NULL) {
                return -1;
index bd89b9e..6e612e9 100644 (file)
@@ -1061,7 +1061,7 @@ static bool do_winbind_online(struct tevent_context *ev_ctx,
                return False;
        }
 
-       db_path = state_path("winbindd_cache.tdb");
+       db_path = state_path(talloc_tos(), "winbindd_cache.tdb");
        if (db_path == NULL) {
                return false;
        }
@@ -1099,7 +1099,7 @@ static bool do_winbind_offline(struct tevent_context *ev_ctx,
                return False;
        }
 
-       db_path = state_path("winbindd_cache.tdb");
+       db_path = state_path(talloc_tos(), "winbindd_cache.tdb");
        if (db_path == NULL) {
                return false;
        }
index 65b3d5a..cb7dcba 100644 (file)
@@ -879,7 +879,7 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
        commonconfig->rw_ops->get_new_id = idmap_autorid_allocate_id;
        commonconfig->rw_ops->set_mapping = idmap_tdb_common_set_mapping;
 
-       db_path = state_path("autorid.tdb");
+       db_path = state_path(talloc_tos(), "autorid.tdb");
        if (db_path == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto error;
index 24ef118..b1f908e 100644 (file)
@@ -310,7 +310,7 @@ static NTSTATUS idmap_tdb_open_db(struct idmap_domain *dom)
        mem_ctx = talloc_stackframe();
 
        /* use the old database if present */
-       tdbfile = state_path("winbindd_idmap.tdb");
+       tdbfile = state_path(talloc_tos(), "winbindd_idmap.tdb");
        if (!tdbfile) {
                DEBUG(0, ("Out of memory!\n"));
                ret = NT_STATUS_NO_MEMORY;
index 5e27376..b63db38 100644 (file)
@@ -1256,7 +1256,7 @@ static void winbindd_listen_fde_handler(struct tevent_context *ev,
 
 char *get_winbind_priv_pipe_dir(void)
 {
-       return state_path(WINBINDD_PRIV_SOCKET_SUBDIR);
+       return state_path(talloc_tos(), WINBINDD_PRIV_SOCKET_SUBDIR);
 }
 
 static void winbindd_setup_max_fds(void)
index af67aa3..2f3bac7 100644 (file)
@@ -119,7 +119,7 @@ static char *wcache_path(void)
         * Data needs to be kept persistent in state directory for
         * running with "winbindd offline logon".
         */
-       return state_path("winbindd_cache.tdb");
+       return state_path(talloc_tos(), "winbindd_cache.tdb");
 }
 
 static void winbindd_domain_init_backend(struct winbindd_domain *domain)