r14575: Move some path-related functions to libsamba-config so libsamba-util
authorJelmer Vernooij <jelmer@samba.org>
Mon, 20 Mar 2006 00:28:12 +0000 (00:28 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:58:52 +0000 (13:58 -0500)
doesn't have to depend on the lp_* functions.

13 files changed:
source/auth/auth.c
source/auth/gensec/gensec.c
source/build/smb_build/makefile.pm
source/lib/tls/config.mk
source/lib/util/config.mk
source/lib/util/debug.c
source/lib/util/fault.c
source/lib/util/util.c
source/lib/util/util.h
source/param/config.mk
source/param/loadparm.c
source/param/util.c [new file with mode: 0644]
source/passdb/secrets.c

index 8ca7c3ea5cab067c790a42dfd63706021ee3802c..b4a473a6904718da175e706bbfd24ecccce33f81 100644 (file)
@@ -282,7 +282,7 @@ NTSTATUS auth_register(const void *_ops)
 
        backends = realloc_p(backends, struct auth_backend, num_backends+1);
        if (!backends) {
-               smb_panic("out of memory in auth_register");
+               return NT_STATUS_NO_MEMORY;
        }
 
        new_ops = smb_xmemdup(ops, sizeof(*ops));
index 0328d0dfea37ca20ae2d503096dbaa276340926f..8dbf9fe2db36d6716aac8bed58751b93acf5350c 100644 (file)
@@ -1088,7 +1088,7 @@ NTSTATUS gensec_register(const struct gensec_security_ops *ops)
                                              struct gensec_security_ops *, 
                                              gensec_num_backends+2);
        if (!generic_security_ops) {
-               smb_panic("out of memory (or failed to realloc referenced memory) in gensec_register");
+               return NT_STATUS_NO_MEMORY;
        }
 
        generic_security_ops[gensec_num_backends] = discard_const(ops);
index 03c172c38da5e76e27dc4dcdb91481e1b25b65ef..46345283cbf5ef3d97250a792a4433b9bb6e90c9 100644 (file)
@@ -424,10 +424,7 @@ sub PkgConfig($$)
        $link_name =~ s/^LIB//g;
        $link_name = lc($link_name);
 
-       if (not defined($ctx->{DESCRIPTION})) {
-               warn("$ctx->{NAME} has not DESCRIPTION set, not generating .pc file");
-               return;
-       }
+       return if (not defined($ctx->{DESCRIPTION}));
 
        my $path = "$ctx->{BASEDIR}/$link_name.pc";
 
index 8e59bb33e5d4e36caff4c65dc104acdb5fb66cf6..810dc17d2ded1e1c856e81153551a408fc9110e7 100644 (file)
@@ -5,7 +5,7 @@ OBJ_FILES = \
                tls.o \
                tlscert.o
 REQUIRED_SUBSYSTEMS = \
-               LIBTALLOC EXT_LIB_GNUTLS
+               LIBTALLOC EXT_LIB_GNUTLS LIBSAMBA-CONFIG
 #
 # End SUBSYSTEM LIBTLS
 ################################################
index 5aac2911523fe1fbe83f726e8d4b2541fb7eb824..c598d703c5c8947925ccbc090fda394b487c6eae 100644 (file)
@@ -33,7 +33,7 @@ OBJ_FILES = xfile.o \
                module.o
 REQUIRED_SUBSYSTEMS = \
                CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \
-               SOCKET_WRAPPER LIBSAMBA-CONFIG \
+               SOCKET_WRAPPER \
 # for the base64 functions
                ldb 
 
index 2c40064b7553735562df5d720450df570681cc55..fa781c823a6a5f7e5a06d63e50b828257dddff3a 100644 (file)
@@ -117,12 +117,13 @@ _PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2)
        free(s);
 }
 
+_PUBLIC_ const char *logfile = NULL;
+
 /**
   reopen the log file (usually called because the log file name might have changed)
 */
 _PUBLIC_ void reopen_logs(void)
 {
-       const char *logfile = lp_logfile();
        char *fname = NULL;
        int old_fd = state.fd;
 
index ff44b8a2921df99da5c0ca21ceb21a9178043cd5..8b447851dc0d8cf97d60aa3e802794f15eaf80d9 100644 (file)
@@ -109,18 +109,19 @@ _PUBLIC_ void call_backtrace(void)
 #endif
 }
 
+_PUBLIC_ const char *panic_action = NULL;
+
 /**
  Something really nasty happened - panic !
 **/
 _PUBLIC_ void smb_panic(const char *why)
 {
-       const char *cmd = lp_panic_action();
        int result;
 
-       if (cmd && *cmd) {
+       if (panic_action && *panic_action) {
                char pidstr[20];
                char cmdstring[200];
-               safe_strcpy(cmdstring, cmd, sizeof(cmdstring));
+               safe_strcpy(cmdstring, panic_action, sizeof(cmdstring));
                snprintf(pidstr, sizeof(pidstr), "%u", getpid());
                all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring));
                if (progname) {
index a0890d5ba973869a7b2b7fda9e296ea966a11a5e..b7293c00923e96d5bf968df3894919aec5332d9b 100644 (file)
@@ -23,7 +23,6 @@
 */
 
 #include "includes.h"
-#include "dynconfig.h"
 #include "system/network.h"
 #include "system/iconv.h"
 #include "system/filesys.h"
@@ -267,30 +266,6 @@ _PUBLIC_ void safe_free(void *p)
 }
 
 
-/**
-  see if a string matches either our primary or one of our secondary 
-  netbios aliases. do a case insensitive match
-*/
-_PUBLIC_ BOOL is_myname(const char *name)
-{
-       const char **aliases;
-       int i;
-
-       if (strcasecmp(name, lp_netbios_name()) == 0) {
-               return True;
-       }
-
-       aliases = lp_netbios_aliases();
-       for (i=0; aliases && aliases[i]; i++) {
-               if (strcasecmp(name, aliases[i]) == 0) {
-                       return True;
-               }
-       }
-
-       return False;
-}
-
-
 /**
  Get my own name, return in malloc'ed storage.
 **/
@@ -584,139 +559,6 @@ _PUBLIC_ void *memdup(const void *p, size_t size)
        return p2;
 }
 
-/**
- A useful function for returning a path in the Samba lock directory.
-**/
-_PUBLIC_ char *lock_path(TALLOC_CTX* mem_ctx, const char *name)
-{
-       char *fname, *dname;
-       if (name == NULL) {
-               return NULL;
-       }
-       if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) {
-               return talloc_strdup(mem_ctx, name);
-       }
-
-       dname = talloc_strdup(mem_ctx, lp_lockdir());
-       trim_string(dname,"","/");
-       
-       if (!directory_exist(dname)) {
-               mkdir(dname,0755);
-       }
-       
-       fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
-
-       talloc_free(dname);
-
-       return fname;
-}
-
-
-/**
- A useful function for returning a path in the Samba piddir directory.
-**/
-static char *pid_path(TALLOC_CTX* mem_ctx, const char *name)
-{
-       char *fname, *dname;
-
-       dname = talloc_strdup(mem_ctx, lp_piddir());
-       trim_string(dname,"","/");
-       
-       if (!directory_exist(dname)) {
-               mkdir(dname,0755);
-       }
-       
-       fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
-
-       talloc_free(dname);
-
-       return fname;
-}
-
-
-/**
- * @brief Returns an absolute path to a file in the Samba lib directory.
- *
- * @param name File to find, relative to DATADIR.
- *
- * @retval Pointer to a talloc'ed string containing the full path.
- **/
-
-_PUBLIC_ char *data_path(TALLOC_CTX* mem_ctx, const char *name)
-{
-       char *fname;
-       fname = talloc_asprintf(mem_ctx, "%s/%s", dyn_DATADIR, name);
-       return fname;
-}
-
-/**
- * @brief Returns an absolute path to a file in the Samba private directory.
- *
- * @param name File to find, relative to PRIVATEDIR.
- * if name is not relative, then use it as-is
- *
- * @retval Pointer to a talloc'ed string containing the full path.
- **/
-_PUBLIC_ char *private_path(TALLOC_CTX* mem_ctx, const char *name)
-{
-       char *fname;
-       if (name == NULL) {
-               return NULL;
-       }
-       if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) {
-               return talloc_strdup(mem_ctx, name);
-       }
-       fname = talloc_asprintf(mem_ctx, "%s/%s", lp_private_dir(), name);
-       return fname;
-}
-
-/**
-  return a path in the smbd.tmp directory, where all temporary file
-  for smbd go. If NULL is passed for name then return the directory 
-  path itself
-*/
-_PUBLIC_ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name)
-{
-       char *fname, *dname;
-
-       dname = pid_path(mem_ctx, "smbd.tmp");
-       if (!directory_exist(dname)) {
-               mkdir(dname,0755);
-       }
-
-       if (name == NULL) {
-               return dname;
-       }
-
-       fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
-       talloc_free(dname);
-
-       return fname;
-}
-
-static char *modules_path(TALLOC_CTX* mem_ctx, const char *name)
-{
-       return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name);
-}
-
-/**
- * Load the initialization functions from DSO files for a specific subsystem.
- *
- * Will return an array of function pointers to initialization functions
- */
-
-_PUBLIC_ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem)
-{
-       char *path = modules_path(mem_ctx, subsystem);
-       init_module_fn *ret;
-
-       ret = load_modules(mem_ctx, path);
-
-       talloc_free(path);
-
-       return ret;
-}
-
 /**
  * Write a password to the log file.
  *
index 73fb675e2817fdb9f105379a95a8fab65a492781..1b48bafc94273a9b4f417f848fb243226a59bcfe 100644 (file)
@@ -36,6 +36,9 @@ struct substitute_context;
 struct asn1_data;
 struct smbsrv_tcon;
 
+extern const char *logfile;
+extern const char *panic_action;
+
 #include "util/xfile.h"
 #include "util/debug.h"
 #include "util/mutex.h"
index 4ef685a35be5ac16cf154f3f263bf3115ce87a3e..b04dbd3e123ac0f814d72da042067c87ab765b5c 100644 (file)
@@ -5,6 +5,7 @@ SO_VERSION = 0
 OBJ_FILES = loadparm.o \
                        params.o \
                        generic.o \
+                       util.o \
                        ../lib/version.o
 REQUIRED_SUBSYSTEMS = LIBSAMBA-UTIL DYNCONFIG
 PUBLIC_PROTO_HEADER = proto.h
index 931eed626fd65c979f0d6757cd7df65874e0c681..21d1e0d57db8604b5fae1ccf9a4d88c73eeb2567 100644 (file)
@@ -103,7 +103,6 @@ typedef struct
        char *szServerString;
        char *szAutoServices;
        char *szPasswdChat;
-       char *szLogFile;
        char *szConfigFile;
        char *szSAM_URL;
        char *szSPOOLSS_URL;
@@ -124,7 +123,6 @@ typedef struct
        char *szNetbiosScope;
        char *szDomainOtherSIDs;
        char **szNameResolveOrder;
-       char *szPanicAction;
        char **dcerpc_ep_servers;
        char **server_services;
        char *ntptr_providor;
@@ -431,7 +429,7 @@ static struct parm_struct parm_table[] = {
 
        {"log level", P_INTEGER, P_GLOBAL, &DEBUGLEVEL, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"debuglevel", P_INTEGER, P_GLOBAL, &DEBUGLEVEL, NULL, NULL, FLAG_HIDE},
-       {"log file", P_STRING, P_GLOBAL, &Globals.szLogFile, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+       {"log file", P_STRING, P_GLOBAL, &logfile, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        
        {"Protocol Options", P_SEP, P_SEPARATOR},
        
@@ -544,7 +542,7 @@ static struct parm_struct parm_table[] = {
        {"volume", P_STRING, P_LOCAL, &sDefault.volume, NULL, NULL, FLAG_SHARE },
        {"fstype", P_STRING, P_LOCAL, &sDefault.fstype, NULL, NULL, FLAG_SHARE},
 
-       {"panic action", P_STRING, P_GLOBAL, &Globals.szPanicAction, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+       {"panic action", P_STRING, P_GLOBAL, &panic_action, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
 
        {"msdfs root", P_BOOL, P_LOCAL, &sDefault.bMSDfsRoot, NULL, NULL, FLAG_SHARE},
        {"host msdfs", P_BOOL, P_GLOBAL, &Globals.bHostMSDfs, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
@@ -819,7 +817,6 @@ _PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, &Globals.tls_cafile)
 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, &Globals.tls_crlfile)
 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, &Globals.unix_charset)
 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, &Globals.display_charset)
-_PUBLIC_ FN_GLOBAL_STRING(lp_logfile, &Globals.szLogFile)
 _PUBLIC_ FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile)
 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, &Globals.szSAM_URL)
 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, &Globals.szSPOOLSS_URL)
@@ -850,7 +847,6 @@ _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, &Globals.szWINSservers)
 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, &Globals.szInterfaces)
 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, &Globals.szSocketAddress)
 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, &Globals.szNetbiosAliases)
-_PUBLIC_ FN_GLOBAL_STRING(lp_panic_action, &Globals.szPanicAction)
 
 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, &Globals.bDisableNetbios)
 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, &Globals.bWINSsupport)
diff --git a/source/param/util.c b/source/param/util.c
new file mode 100644 (file)
index 0000000..85a0587
--- /dev/null
@@ -0,0 +1,194 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Jeremy Allison 2001-2002
+   Copyright (C) Simo Sorce 2001
+   Copyright (C) Jim McDonough (jmcd@us.ibm.com)  2003.
+   Copyright (C) James J Myers 2003
+   
+   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 2 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, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "dynconfig.h"
+#include "system/network.h"
+#include "system/iconv.h"
+#include "system/filesys.h"
+
+/**
+ * @file
+ * @brief Misc utility functions
+ */
+
+
+/**
+  see if a string matches either our primary or one of our secondary 
+  netbios aliases. do a case insensitive match
+*/
+_PUBLIC_ BOOL is_myname(const char *name)
+{
+       const char **aliases;
+       int i;
+
+       if (strcasecmp(name, lp_netbios_name()) == 0) {
+               return True;
+       }
+
+       aliases = lp_netbios_aliases();
+       for (i=0; aliases && aliases[i]; i++) {
+               if (strcasecmp(name, aliases[i]) == 0) {
+                       return True;
+               }
+       }
+
+       return False;
+}
+
+
+/**
+ A useful function for returning a path in the Samba lock directory.
+**/
+_PUBLIC_ char *lock_path(TALLOC_CTX* mem_ctx, const char *name)
+{
+       char *fname, *dname;
+       if (name == NULL) {
+               return NULL;
+       }
+       if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) {
+               return talloc_strdup(mem_ctx, name);
+       }
+
+       dname = talloc_strdup(mem_ctx, lp_lockdir());
+       trim_string(dname,"","/");
+       
+       if (!directory_exist(dname)) {
+               mkdir(dname,0755);
+       }
+       
+       fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
+
+       talloc_free(dname);
+
+       return fname;
+}
+
+
+/**
+ A useful function for returning a path in the Samba piddir directory.
+**/
+static char *pid_path(TALLOC_CTX* mem_ctx, const char *name)
+{
+       char *fname, *dname;
+
+       dname = talloc_strdup(mem_ctx, lp_piddir());
+       trim_string(dname,"","/");
+       
+       if (!directory_exist(dname)) {
+               mkdir(dname,0755);
+       }
+       
+       fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
+
+       talloc_free(dname);
+
+       return fname;
+}
+
+
+/**
+ * @brief Returns an absolute path to a file in the Samba lib directory.
+ *
+ * @param name File to find, relative to DATADIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
+
+_PUBLIC_ char *data_path(TALLOC_CTX* mem_ctx, const char *name)
+{
+       char *fname;
+       fname = talloc_asprintf(mem_ctx, "%s/%s", dyn_DATADIR, name);
+       return fname;
+}
+
+/**
+ * @brief Returns an absolute path to a file in the Samba private directory.
+ *
+ * @param name File to find, relative to PRIVATEDIR.
+ * if name is not relative, then use it as-is
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
+_PUBLIC_ char *private_path(TALLOC_CTX* mem_ctx, const char *name)
+{
+       char *fname;
+       if (name == NULL) {
+               return NULL;
+       }
+       if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) {
+               return talloc_strdup(mem_ctx, name);
+       }
+       fname = talloc_asprintf(mem_ctx, "%s/%s", lp_private_dir(), name);
+       return fname;
+}
+
+/**
+  return a path in the smbd.tmp directory, where all temporary file
+  for smbd go. If NULL is passed for name then return the directory 
+  path itself
+*/
+_PUBLIC_ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name)
+{
+       char *fname, *dname;
+
+       dname = pid_path(mem_ctx, "smbd.tmp");
+       if (!directory_exist(dname)) {
+               mkdir(dname,0755);
+       }
+
+       if (name == NULL) {
+               return dname;
+       }
+
+       fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
+       talloc_free(dname);
+
+       return fname;
+}
+
+static char *modules_path(TALLOC_CTX* mem_ctx, const char *name)
+{
+       return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name);
+}
+
+/**
+ * Load the initialization functions from DSO files for a specific subsystem.
+ *
+ * Will return an array of function pointers to initialization functions
+ */
+
+_PUBLIC_ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem)
+{
+       char *path = modules_path(mem_ctx, subsystem);
+       init_module_fn *ret;
+
+       ret = load_modules(mem_ctx, path);
+
+       talloc_free(path);
+
+       return ret;
+}
+
+
index 13f71e269e0a2c6b876f66ea7308e7af28f8c444..cbf94c0c3e8eabd18ec42e80a1336823b3a9758b 100644 (file)
@@ -25,6 +25,7 @@
 #include "includes.h"
 #include "lib/tdb/include/tdbutil.h"
 #include "secrets.h"
+#include "param/param.h"
 #include "system/filesys.h"
 #include "db_wrap.h"
 #include "lib/ldb/include/ldb.h"