From: Andrew Bartlett Date: Mon, 6 Jun 2011 04:37:06 +0000 (+1000) Subject: lib/util use modules_path(), data_path() and shlib_ext() from source3 X-Git-Tag: samba-4.0.0alpha16^2~399 X-Git-Url: http://git.samba.org/samba.git/?p=sfrench%2Fsamba-autobuild%2F.git;a=commitdiff_plain;h=de46ad9084aff4384f33660acf91da3b81554a88 lib/util use modules_path(), data_path() and shlib_ext() from source3 This brings these helpful utility functions in common, as they are not based on either loadparm system. (The 'modules dir' parameter from Samba4 will shortly be removed, so there is no loss in functionality) Andrew Bartlett --- diff --git a/lib/util/util.h b/lib/util/util.h index d1c5e82bdd7..e89c4ac9977 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -891,4 +891,30 @@ int samba_runcmd_recv(struct tevent_req *req, int *perrno); void samba_start_debugger(void); #endif +/** + * @brief Returns an absolute path to a file in the Samba modules directory. + * + * @param name File to find, relative to MODULESDIR. + * + * @retval Pointer to a string containing the full path. + **/ +char *modules_path(TALLOC_CTX *mem_ctx, const char *name); + +/** + * @brief Returns an absolute path to a file in the Samba data directory. + * + * @param name File to find, relative to CODEPAGEDIR. + * + * @retval Pointer to a talloc'ed string containing the full path. + **/ +char *data_path(TALLOC_CTX *mem_ctx, const char *name); + +/** + * @brief Returns the platform specific shared library extension. + * + * @retval Pointer to a const char * containing the extension. + **/ +const char *shlib_ext(void); + + #endif /* _SAMBA_UTIL_H_ */ diff --git a/lib/util/util_paths.c b/lib/util/util_paths.c new file mode 100644 index 00000000000..0baa6801c54 --- /dev/null +++ b/lib/util/util_paths.c @@ -0,0 +1,63 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 2001-2007 + Copyright (C) Simo Sorce 2001 + Copyright (C) Jim McDonough 2003 + Copyright (C) James Peach 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "dynconfig/dynconfig.h" + +/** + * @brief Returns an absolute path to a file in the Samba modules directory. + * + * @param name File to find, relative to MODULESDIR. + * + * @retval Pointer to a string containing the full path. + **/ + +char *modules_path(TALLOC_CTX *mem_ctx, const char *name) +{ + return talloc_asprintf(mem_ctx, "%s/%s", get_dyn_MODULESDIR(), name); +} + +/** + * @brief Returns an absolute path to a file in the Samba data directory. + * + * @param name File to find, relative to CODEPAGEDIR. + * + * @retval Pointer to a talloc'ed string containing the full path. + **/ + +char *data_path(TALLOC_CTX *mem_ctx, const char *name) +{ + return talloc_asprintf(mem_ctx, "%s/%s", get_dyn_CODEPAGEDIR(), name); +} + +/** + * @brief Returns the platform specific shared library extension. + * + * @retval Pointer to a const char * containing the extension. + **/ + +const char *shlib_ext(void) +{ + return get_dyn_SHLIBEXT(); +} + diff --git a/lib/util/wscript_build b/lib/util/wscript_build index 3092b6ccbba..8ce30eb6891 100755 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -4,7 +4,7 @@ common_util_sources = '''talloc_stack.c smb_threads.c xfile.c data_blob.c util_file.c time.c rbtree.c rfc1738.c select.c genrand.c fsusage.c blocking.c become_daemon.c signal.c system.c params.c util.c util_id.c util_net.c - util_strlist.c idtree.c debug.c fault.c base64.c + util_strlist.c util_paths.c idtree.c debug.c fault.c base64.c util_str.c util_str_common.c substitute.c ms_fnmatch.c''' common_util_headers = 'debug.h' diff --git a/libgpo/gpext/gpext.c b/libgpo/gpext/gpext.c index f38d87358ab..ac6c181e34c 100644 --- a/libgpo/gpext/gpext.c +++ b/libgpo/gpext/gpext.c @@ -492,7 +492,8 @@ static NTSTATUS gp_glob_ext_list(TALLOC_CTX *mem_ctx, SMB_STRUCT_DIR *dir = NULL; SMB_STRUCT_DIRENT *dirent = NULL; - dir = sys_opendir(modules_path(SAMBA_SUBSYSTEM_GPEXT)); + dir = sys_opendir(modules_path(talloc_tos(), + SAMBA_SUBSYSTEM_GPEXT)); if (!dir) { return map_nt_error_from_unix(errno); } diff --git a/source3/Makefile.in b/source3/Makefile.in index f7458d353a0..d4b59b95b96 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -421,7 +421,7 @@ LIBSAMBAUTIL_OBJ = \ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \ ../lib/util/xfile.o ../lib/util/util_strlist.o \ ../lib/util/util_file.o ../lib/util/data_blob.o \ - ../lib/util/util.o ../lib/util/fsusage.o \ + ../lib/util/util.o ../lib/util/util_paths.o ../lib/util/fsusage.o \ ../lib/util/params.o ../lib/util/talloc_stack.o \ ../lib/util/genrand.o ../lib/util/util_net.o \ ../lib/util/become_daemon.o ../lib/util/system.o \ diff --git a/source3/include/proto.h b/source3/include/proto.h index 1cdc0c9081a..10a84f90509 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -570,11 +570,8 @@ void *smb_xmalloc_array(size_t size, unsigned int count); char *myhostname(void); char *lock_path(const char *name); char *pid_path(const char *name); -char *modules_path(const char *name); -char *data_path(const char *name); char *state_path(const char *name); char *cache_path(const char *name); -const char *shlib_ext(void); bool parent_dirname(TALLOC_CTX *mem_ctx, const char *dir, char **parent, const char **name); bool ms_has_wild(const char *s); diff --git a/source3/intl/lang_tdb.c b/source3/intl/lang_tdb.c index c6206c16e47..6070e29e5ad 100644 --- a/source3/intl/lang_tdb.c +++ b/source3/intl/lang_tdb.c @@ -131,7 +131,7 @@ bool lang_tdb_init(const char *lang) return True; if (asprintf(&msg_path, "%s.msg", - data_path((const char *)lang)) == -1) { + data_path(talloc_tos(), (const char *)lang)) == -1) { DEBUG(0, ("asprintf failed\n")); goto done; } diff --git a/source3/lib/module.c b/source3/lib/module.c index de136680092..bec4fddefdc 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -117,10 +117,10 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) } full_path = talloc_asprintf(ctx, - "%s/%s.%s", - modules_path(subsystem), - module, - shlib_ext()); + "%s/%s.%s", + modules_path(ctx, subsystem), + module, + shlib_ext()); if (!full_path) { TALLOC_FREE(ctx); return NT_STATUS_NO_MEMORY; diff --git a/source3/lib/util.c b/source3/lib/util.c index dc91fa06a15..a596385bfb3 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1513,32 +1513,6 @@ char *pid_path(const char *name) return xx_path(name, lp_piddir()); } -/** - * @brief Returns an absolute path to a file in the Samba modules directory. - * - * @param name File to find, relative to MODULESDIR. - * - * @retval Pointer to a string containing the full path. - **/ - -char *modules_path(const char *name) -{ - return talloc_asprintf(talloc_tos(), "%s/%s", get_dyn_MODULESDIR(), name); -} - -/** - * @brief Returns an absolute path to a file in the Samba data directory. - * - * @param name File to find, relative to CODEPAGEDIR. - * - * @retval Pointer to a talloc'ed string containing the full path. - **/ - -char *data_path(const char *name) -{ - return talloc_asprintf(talloc_tos(), "%s/%s", get_dyn_CODEPAGEDIR(), name); -} - /** * @brief Returns an absolute path to a file in the Samba state directory. * @@ -1565,17 +1539,6 @@ char *cache_path(const char *name) return xx_path(name, lp_cachedir()); } -/** - * @brief Returns the platform specific shared library extension. - * - * @retval Pointer to a const char * containing the extension. - **/ - -const char *shlib_ext(void) -{ - return get_dyn_SHLIBEXT(); -} - /******************************************************************* Given a filename - get its directory name ********************************************************************/ diff --git a/source3/smbd/mangle_hash.c b/source3/smbd/mangle_hash.c index 575c35e458b..988251e8787 100644 --- a/source3/smbd/mangle_hash.c +++ b/source3/smbd/mangle_hash.c @@ -87,7 +87,7 @@ static void init_valid_table(void) return; } - valid_table = (uint8 *)map_file(data_path("valid.dat"), 0x10000); + valid_table = (uint8 *)map_file(data_path(talloc_tos(), "valid.dat"), 0x10000); if (!valid_table) { smb_panic("Could not load valid.dat file required for mangle method=hash"); return; diff --git a/source4/lib/ldb-samba/ldb_wrap.c b/source4/lib/ldb-samba/ldb_wrap.c index f7d562377a3..d713dfffbf2 100644 --- a/source4/lib/ldb-samba/ldb_wrap.c +++ b/source4/lib/ldb-samba/ldb_wrap.c @@ -126,10 +126,7 @@ char *wrap_casefold(void *context, void *mem_ctx, const char *s, size_t n) return NULL; } - ldb_set_modules_dir(ldb, - talloc_asprintf(ldb, - "%s/ldb", - lpcfg_modulesdir(lp_ctx))); + ldb_set_modules_dir(ldb, modules_path(ldb, "ldb")); ldb_set_debug(ldb, ldb_wrap_debug, NULL); diff --git a/source4/param/util.c b/source4/param/util.c index f8fc15a152b..bcb5be19747 100644 --- a/source4/param/util.c +++ b/source4/param/util.c @@ -266,14 +266,6 @@ bool run_init_functions(init_module_fn *fns) return ret; } -static char *modules_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx, - const char *name) -{ - return talloc_asprintf(mem_ctx, "%s/%s", - lpcfg_modulesdir(lp_ctx), - name); -} - /** * Load the initialization functions from DSO files for a specific subsystem. * @@ -282,7 +274,7 @@ static char *modules_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx, init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *subsystem) { - char *path = modules_path(mem_ctx, lp_ctx, subsystem); + char *path = modules_path(mem_ctx, subsystem); init_module_fn *ret; ret = load_modules(mem_ctx, path); diff --git a/source4/torture/drs/rpc/dssync.c b/source4/torture/drs/rpc/dssync.c index 733e55ded50..8279e736b19 100644 --- a/source4/torture/drs/rpc/dssync.c +++ b/source4/torture/drs/rpc/dssync.c @@ -271,10 +271,7 @@ static bool test_LDAPBind(struct torture_context *tctx, struct DsSyncTest *ctx, return NULL; } - ldb_set_modules_dir(ldb, - talloc_asprintf(ldb, - "%s/ldb", - lpcfg_modulesdir(tctx->lp_ctx))); + ldb_set_modules_dir(ldb, modules_path(ldb, "ldb")); if (ldb_set_opaque(ldb, "credentials", credentials)) { talloc_free(ldb); diff --git a/source4/torture/drs/rpc/msds_intid.c b/source4/torture/drs/rpc/msds_intid.c index 53f4992ba29..14c6454abe1 100644 --- a/source4/torture/drs/rpc/msds_intid.c +++ b/source4/torture/drs/rpc/msds_intid.c @@ -283,10 +283,7 @@ static bool _test_LDAPBind(struct torture_context *tctx, return NULL; } - ldb_set_modules_dir(ldb, - talloc_asprintf(ldb, - "%s/ldb", - lpcfg_modulesdir(tctx->lp_ctx))); + ldb_set_modules_dir(ldb, modules_path(ldb, "ldb")); if (ldb_set_opaque(ldb, "credentials", credentials) != LDB_SUCCESS) { talloc_free(ldb); diff --git a/source4/torture/rpc/dsgetinfo.c b/source4/torture/rpc/dsgetinfo.c index 6122ff06037..a0360e84041 100644 --- a/source4/torture/rpc/dsgetinfo.c +++ b/source4/torture/rpc/dsgetinfo.c @@ -88,7 +88,7 @@ static const char *torture_get_ldap_base_dn(struct torture_context *tctx, struct } ldb_set_modules_dir(ldb, - talloc_asprintf(ldb, "%s/ldb", lpcfg_modulesdir(tctx->lp_ctx))); + modules_path(ldb, "ldb")); ret = ldb_connect(ldb, ldap_url, 0, NULL); if (ret != LDB_SUCCESS) {