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 adc7d0b9d475132a8e085d4f0843804324152f5c..3561057214cdf9ff3b06279aa6ba0768f6b4ac23 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 9053fdd9a24508fa8b00f67d27726bc987f8c791..4b6311808166e8af710a3c91930b16733035a7a1 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 d790b0832181b02146cfc2732c627a7dd6ad5373..58a2dee3bcf05d2b515cc92e580d93590d24addd 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 b8ce304c213002b8dad0ab789a5db2cae8b0f257..efe3e608d7da900de12653744a5d0f2f9df14d4d 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 6df67fb6feb2c602ccc312ea87408959fa240460..b189b3e33cb7f1e45dcfae1480886aed3cd5da94 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 bb69170c910adc980cc1ab0b04993b3264c82b15..7506e4e34fa12ade86af0219bc3def55f328c165 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 f67a86f80276803c83e0ade699708e3525dc10bf..32968ae083fa5de53284cbb2f2f0bc201d873b00 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 cd7d3b7fc753bc92eaf609221d94356747d20b61..c34bfaea3beda87cf601279827dd380d00501970 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 421a054f83b7d1a3c1061a221a3a41cc380822c9..4d94dfe817c065522d99b8f5abd7337aa0305f95 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 6f3dda6e2291965dda4c98f36660c1016e92c8db..91735ff7084a098eee2ac834c8ee955b920d6577 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 633e350ff35f3eb74853a6b2f77d9461e7df7d81..9c4c488040f273470ca0e84eadcf4cbb11575dbd 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 dd78e69989e739b67edd5f9e30ae38071d8b74e3..8bcc2d45a1162563d67f94cf4e80def89f8e3bfc 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 ea1e87e4a12bb969f21f2a628af411eb4c5054d0..0193b177aece5c21fd97ae04acee34477278d5f4 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 928572e8a5a1644e8e25581365058700b8bd05de..aa97d60abecffb845a6f4df229099ef7a7690534 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 e31f8991642f914376db7520d07c91875a10d4bc..6fa96f314fb0e10b92a28f63a83c3cef033f97ed 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 4f365662a71fd6782f435c5c0377c37c28ce9f0d..b49d5f43381ba8b016a4121c84a22c27b588772f 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 c67a148ddd0aa06836eec8325c4068e2da20a55b..01a36b20e7cd96b537298c669e30905ec8529711 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 bd89b9ebf0a4ce8272e12634d355a71615dd76cb..6e612e9dd8fa68d5337839d3224fa8100ed9a734 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 65b3d5af222d389b32aa17ab833abae91094c529..cb7dcba1a5f224d7e83ddea72c9a4c81691e1c48 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 24ef11836e1107865b3aca579aa45f37f6d69a60..b1f908e2d62a287d2ec99a94f5f31868b513aa0b 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 5e273762ff14d451d0d42aba40705fc31a80ac20..b63db3815405cb1bb30f6cb90b47796690546f44 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 af67aa3b0cfa20529de4d5109a45d9498f6597e3..2f3bac7587b12ea83f8a8b12458f6b472c7bf3f5 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)