[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-579-g52dc5ea

Jeremy Allison jra at samba.org
Mon Dec 10 19:31:07 GMT 2007


The branch, v3-2-test has been updated
       via  52dc5eaef2106015b3a8b659e818bdb15ad94b05 (commit)
      from  e81629339589e2e7f464b3dca55730ff2d0877e4 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 52dc5eaef2106015b3a8b659e818bdb15ad94b05
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Dec 10 11:30:37 2007 -0800

    Remove the char[1024] strings from dynconfig. Replace
    them with malloc'ing accessor functions. Should save a
    lot of static space :-).
    Jeremy.

-----------------------------------------------------------------------

Summary of changes:
 source/client/client.c              |    4 +-
 source/client/smbmount.c            |    8 +-
 source/client/smbspool.c            |    4 +-
 source/dynconfig.c                  |  251 ++++++++++++++++++++++++++++++++---
 source/include/dynconfig.h          |   51 +++++++-
 source/lib/fault.c                  |    2 +-
 source/lib/ldb/common/ldb_modules.c |    2 +-
 source/lib/pidfile.c                |    8 +-
 source/lib/popt_common.c            |   26 ++--
 source/lib/util.c                   |   10 +-
 source/libsmb/libsmbclient.c        |    6 +-
 source/libsmb/namequery.c           |    2 +-
 source/nmbd/nmbd.c                  |   17 ++-
 source/nmbd/nmbd_winsserver.c       |    2 +-
 source/nsswitch/wbinfo.c            |    4 +-
 source/nsswitch/wins.c              |    2 +-
 source/pam_smbpass/support.c        |    4 +-
 source/param/loadparm.c             |   10 +-
 source/passdb/pdb_tdb.c             |    2 +-
 source/rpc_client/cli_pipe.c        |    2 +-
 source/rpc_server/srv_srvsvc_nt.c   |    6 +-
 source/rpcclient/rpcclient.c        |    4 +-
 source/services/services_db.c       |    6 +-
 source/services/svc_rcinit.c        |    6 +-
 source/smbd/lanman.c                |    2 +-
 source/smbd/server.c                |    6 +-
 source/torture/locktest.c           |    2 +-
 source/torture/locktest2.c          |    2 +-
 source/torture/masktest.c           |    2 +-
 source/torture/msgtest.c            |    2 +-
 source/torture/pdbtest.c            |    2 +-
 source/torture/torture.c            |    2 +-
 source/torture/vfstest.c            |    6 +-
 source/utils/eventlogadm.c          |    2 +-
 source/utils/net.c                  |    2 +-
 source/utils/net_ads.c              |    8 +-
 source/utils/nmblookup.c            |    4 +-
 source/utils/ntlm_auth.c            |    4 +-
 source/utils/pdbedit.c              |    4 +-
 source/utils/sharesec.c             |    2 +-
 source/utils/smbcacls.c             |    2 +-
 source/utils/smbcontrol.c           |    2 +-
 source/utils/smbcquotas.c           |    2 +-
 source/utils/smbfilter.c            |    2 +-
 source/utils/smbpasswd.c            |    2 +-
 source/utils/smbtree.c              |    2 +-
 source/utils/smbw_sample.c          |    4 +-
 source/utils/status.c               |    6 +-
 source/utils/testparm.c             |    2 +-
 source/web/startstop.c              |    6 +-
 source/web/swat.c                   |   18 ++--
 source/winbindd/idmap.c             |    2 +-
 source/winbindd/winbindd.c          |    8 +-
 source/winbindd/winbindd_cm.c       |    2 +-
 source/winbindd/winbindd_dual.c     |    4 +-
 55 files changed, 406 insertions(+), 149 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/client/client.c b/source/client/client.c
index 80e906d..d59af9e 100644
--- a/source/client/client.c
+++ b/source/client/client.c
@@ -4705,9 +4705,9 @@ static int do_message_op(void)
 	if ( override_logfile )
 		setup_logging( lp_logfile(), false );
 
-	if (!lp_load(dyn_CONFIGFILE,true,false,false,true)) {
+	if (!lp_load(get_dyn_CONFIGFILE(),true,false,false,true)) {
 		fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
-			argv[0], dyn_CONFIGFILE);
+			argv[0], get_dyn_CONFIGFILE());
 	}
 
 	load_interfaces();
diff --git a/source/client/smbmount.c b/source/client/smbmount.c
index 2e8d554..98c61a3 100644
--- a/source/client/smbmount.c
+++ b/source/client/smbmount.c
@@ -535,7 +535,7 @@ static void init_mount(void)
 	if (sys_fork() == 0) {
 		char *smbmnt_path;
 
-		asprintf(&smbmnt_path, "%s/smbmnt", dyn_BINDIR);
+		asprintf(&smbmnt_path, "%s/smbmnt", get_dyn_BINDIR());
 
 		if (file_exist(smbmnt_path, NULL)) {
 			execv(smbmnt_path, (char * const *)args);
@@ -586,7 +586,7 @@ static void get_password_file(void)
 	int fd = -1;
 	char *p;
 	bool close_it = False;
-	char *spec;
+	char *spec = NULL;
 	TALLOC_CTX *ctx = talloc_tos();
 	char pass[128];
 
@@ -1012,9 +1012,9 @@ static void parse_mount_smb(int argc, char **argv)
 		}
 	}
 
-	if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) {
+	if (!lp_load(get_dyn_CONFIGFILE(),True,False,False,True)) {
 		fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
-			dyn_CONFIGFILE);
+			get_dyn_CONFIGFILE());
 	}
 
 	parse_mount_smb(argc, argv);
diff --git a/source/client/smbspool.c b/source/client/smbspool.c
index 0ba4d57..4270eb4 100644
--- a/source/client/smbspool.c
+++ b/source/client/smbspool.c
@@ -230,9 +230,9 @@ static char *		uri_unescape_alloc(const char *);
 
   load_case_tables();
 
-  if (!lp_load(dyn_CONFIGFILE, True, False, False, True))
+  if (!lp_load(get_dyn_CONFIGFILE(), True, False, False, True))
   {
-    fprintf(stderr, "ERROR: Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
+    fprintf(stderr, "ERROR: Can't load %s - run testparm to debug it\n", get_dyn_CONFIGFILE());
     goto done;
   }
 
diff --git a/source/dynconfig.c b/source/dynconfig.c
index c9dcea5..ab0dd48 100644
--- a/source/dynconfig.c
+++ b/source/dynconfig.c
@@ -1,18 +1,19 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    Copyright (C) 2001 by Martin Pool <mbp at samba.org>
    Copyright (C) 2003 by Jim McDonough <jmcd at us.ibm.com>
-   
+   Copyright (C) 2007 by Jeremy Allison <jra at samba.org>
+
    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 <http://www.gnu.org/licenses/>.
 */
@@ -39,52 +40,262 @@
  * table?  There's kind of a chicken-and-egg situation there...
  **/
 
-char const *dyn_SBINDIR = SBINDIR,
-	*dyn_BINDIR = BINDIR,
-	*dyn_SWATDIR = SWATDIR;
+#if 0
+static char const *dyn_SBINDIR = SBINDIR;
+static char const *dyn_BINDIR = BINDIR;
+static char const *dyn_SWATDIR = SWATDIR;
+#endif
+
+#define DEFINE_DYN_CONFIG_PARAM(name) \
+static char *dyn_##name; \
+\
+ const char *get_dyn_##name(void) \
+{\
+	if (dyn_##name == NULL) {\
+		return name;\
+	}\
+	return dyn_##name;\
+}\
+\
+ const char *set_dyn_##name(const char *newpath) \
+{\
+	if (dyn_##name) {\
+		SAFE_FREE(dyn_##name);\
+	}\
+	dyn_##name = SMB_STRDUP(newpath);\
+	return dyn_##name;\
+}
+
+DEFINE_DYN_CONFIG_PARAM(SBINDIR)
+DEFINE_DYN_CONFIG_PARAM(BINDIR)
+DEFINE_DYN_CONFIG_PARAM(SWATDIR)
+DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
+DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
+DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
+DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
+DEFINE_DYN_CONFIG_PARAM(LIBDIR)
+DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
+DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
+DEFINE_DYN_CONFIG_PARAM(PIDDIR)
+DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
+DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
+
+#if 0
+static char *dyn_CONFIGFILE; /**< Location of smb.conf file. **/
+
+const char *get_dyn_CONFIGFILE(void)
+{
+	if (dyn_CONFIGFILE == NULL) {
+		return CONFIGFILE;
+	}
+	return dyn_CONFIGFILE;
+}
 
-/* JRA - FIXME - these should be dynamic char * */
-char dyn_CONFIGFILE[1024] = CONFIGFILE; /**< Location of smb.conf file. **/
+const char *set_dyn_CONFIGFILE(const char *newpath)
+{
+	if (dyn_CONFIGFILE) {
+		SAFE_FREE(dyn_CONFIGFILE);
+	}
+	dyn_CONFIGFILE = SMB_STRDUP(newpath);
+	return dyn_CONFIGFILE;
+}
 
 /** Log file directory. **/
-char dyn_LOGFILEBASE[1024] = LOGFILEBASE;
+static char *dyn_LOGFILEBASE;
+
+const char *get_dyn_LOGFILEBASE(void)
+{
+	if (dyn_LOGFILEBASE == NULL) {
+		return LOGFILEBASE;
+	}
+	return dyn_LOGFILEBASE;
+}
+
+const char *set_dyn_LOGFILEBASE(const char *newpath)
+{
+	if (dyn_LOGFILEBASE) {
+		SAFE_FREE(dyn_LOGFILEBASE);
+	}
+	dyn_LOGFILEBASE = SMB_STRDUP(newpath);
+	return dyn_LOGFILEBASE;
+}
 
 /** Statically configured LanMan hosts. **/
-char dyn_LMHOSTSFILE[1024] = LMHOSTSFILE;
+static char *dyn_LMHOSTSFILE;
+
+const char *get_dyn_LMHOSTSFILE(void)
+{
+	if (dyn_LMHOSTSFILE == NULL) {
+		return LMHOSTSFILE;
+	}
+	return dyn_LMHOSTSFILE;
+}
+
+const char *set_dyn_LMHOSTSFILE(const char *newpath)
+{
+	if (dyn_LMHOSTSFILE) {
+		SAFE_FREE(dyn_LMHOSTSFILE);
+	}
+	dyn_LMHOSTSFILE = SMB_STRDUP(newpath);
+	return dyn_LMHOSTSFILE;
+}
 
 /**
  * @brief Samba data directory.
  *
  * @sa data_path() to get the path to a file inside the CODEPAGEDIR.
  **/
-char dyn_CODEPAGEDIR[1024] = CODEPAGEDIR;
+static char *dyn_CODEPAGEDIR;
+
+const char *get_dyn_CODEPAGEDIR(void)
+{
+	if (dyn_CODEPAGEDIR == NULL) {
+		return CODEPAGEDIR;
+	}
+	return dyn_CODEPAGEDIR;
+}
+
+const char *set_dyn_CODEPAGEDIR(const char *newpath)
+{
+	if (dyn_CODEPAGEDIR) {
+		SAFE_FREE(dyn_CODEPAGEDIR);
+	}
+	dyn_CODEPAGEDIR = SMB_STRDUP(newpath);
+	return dyn_CODEPAGEDIR;
+}
 
 /**
  * @brief Samba library directory.
  *
  * @sa lib_path() to get the path to a file inside the LIBDIR.
  **/
-char dyn_LIBDIR[1024] = LIBDIR;
-fstring dyn_SHLIBEXT = SHLIBEXT;
+static char *dyn_LIBDIR;
+
+const char *get_dyn_LIBDIR(void)
+{
+	if (dyn_LIBDIR == NULL) {
+		return LIBDIR;
+	}
+	return dyn_CODEPAGEDIR;
+}
+
+const char *set_dyn_LIBDIR(const char *newpath)
+{
+	if (dyn_LIBDIR) {
+		SAFE_FREE(dyn_LIBDIR);
+	}
+	dyn_LIBDIR = SMB_STRDUP(newpath);
+	return dyn_LIBDIR;
+}
+
+static char *dyn_SHLIBEXT;
+
+const char *get_dyn_SHLIBEXT(void)
+{
+	if (dyn_SHLIBEXT == NULL) {
+		return SHLIBEXT;
+	}
+	return dyn_SHLIBEXT;
+}
+
+const char *set_dyn_SHLIBEXT(const char *newpath)
+{
+	if (dyn_SHLIBEXT) {
+		SAFE_FREE(dyn_SHLIBEXT);
+	}
+	dyn_SHLIBEXT = SMB_STRDUP(newpath);
+	return dyn_SHLIBEXT;
+}
 
 /**
  * @brief Directory holding lock files.
  *
  * Not writable, but used to set a default in the parameter table.
  **/
-char dyn_LOCKDIR[1024] = LOCKDIR;
-char dyn_PIDDIR[1024]  = PIDDIR;
 
-char dyn_SMB_PASSWD_FILE[1024] = SMB_PASSWD_FILE;
-char dyn_PRIVATE_DIR[1024] = PRIVATE_DIR;
+static char *dyn_LOCKDIR;
+
+const char *get_dyn_LOCKDIR(void)
+{
+	if (dyn_LOCKDIR == NULL) {
+		return LOCKDIR;
+	}
+	return dyn_LOCKDIR;
+}
+
+const char *set_dyn_LOCKDIR(const char *newpath)
+{
+	if (dyn_LOCKDIR) {
+		SAFE_FREE(dyn_LOCKDIR);
+	}
+	dyn_LOCKDIR = SMB_STRDUP(newpath);
+	return dyn_LOCKDIR;
+}
+
+static char *dyn_PIDDIR;
+
+const char *get_dyn_PIDDIR(void)
+{
+	if (dyn_PIDDIR == NULL) {
+		return PIDDIR;
+	}
+	return dyn_PIDDIR;
+}
 
+const char *set_dyn_PIDDIR(const char *newpath)
+{
+	if (dyn_PIDDIR) {
+		SAFE_FREE(dyn_PIDDIR);
+	}
+	dyn_PIDDIR = SMB_STRDUP(newpath);
+	return dyn_PIDDIR;
+}
+
+static char *dyn_SMB_PASSWD_FILE;
+
+const char *get_dyn_SMB_PASSWD_FILE(void)
+{
+	if (dyn_SMB_PASSWD_FILE == NULL) {
+		return SMB_PASSWD_FILE;
+	}
+	return dyn_SMB_PASSWD_FILE;
+}
+
+const char *set_dyn_SMB_PASSWD_FILE(const char *newpath)
+{
+	if (dyn_SMB_PASSWD_FILE) {
+		SAFE_FREE(dyn_SMB_PASSWD_FILE);
+	}
+	dyn_SMB_PASSWD_FILE = SMB_STRDUP(newpath);
+	return dyn_SMB_PASSWD_FILE;
+}
+
+static char *dyn_PRIVATE_DIR;
+
+const char *get_dyn_PRIVATE_DIR(void)
+{
+	if (dyn_PRIVATE_DIR == NULL) {
+		return PRIVATE_DIR;
+	}
+	return dyn_PRIVATE_DIR;
+}
+
+const char *set_dyn_PRIVATE_DIR(const char *newpath)
+{
+	if (dyn_PRIVATE_DIR) {
+		SAFE_FREE(dyn_PRIVATE_DIR);
+	}
+	dyn_PRIVATE_DIR = SMB_STRDUP(newpath);
+	return dyn_PRIVATE_DIR;
+}
+#endif
 
 /* In non-FHS mode, these should be configurable using 'lock dir =';
    but in FHS mode, they are their own directory.  Implement as wrapper
    functions so that everything can still be kept in dynconfig.c.
  */
 
-char *dyn_STATEDIR(void)
+const char *get_dyn_STATEDIR(void)
 {
 #ifdef FHS_COMPATIBLE
 	return STATEDIR;
@@ -93,7 +304,7 @@ char *dyn_STATEDIR(void)
 #endif
 }
 
-char *dyn_CACHEDIR(void)
+const char *get_dyn_CACHEDIR(void)
 {
 #ifdef FHS_COMPATIBLE
 	return CACHEDIR;
diff --git a/source/include/dynconfig.h b/source/include/dynconfig.h
index a26f840..bb7e2c2 100644
--- a/source/include/dynconfig.h
+++ b/source/include/dynconfig.h
@@ -23,9 +23,10 @@
  * @brief Exported global configurations.
  **/
 
-extern char const *dyn_SBINDIR,
-	*dyn_BINDIR,
-	*dyn_SWATDIR;
+#if 0
+const char *get_dyn_SBINDIR(void);
+const char *get_dyn_BINDIR(void);
+const char *get_dyn_SWATDIR(void);
 
 extern char dyn_CONFIGFILE[1024];
 extern char dyn_LOGFILEBASE[1024], dyn_LMHOSTSFILE[1024];
@@ -36,6 +37,46 @@ extern char dyn_LOCKDIR[1024];
 extern char dyn_PIDDIR[1024];
 extern char dyn_SMB_PASSWD_FILE[1024];
 extern char dyn_PRIVATE_DIR[1024];
+#endif
 
-char *dyn_STATEDIR(void);
-char *dyn_CACHEDIR(void);
+const char *get_dyn_SBINDIR(void);
+const char *set_dyn_SBINDIR(const char *newpath);
+
+const char *get_dyn_BINDIR(void);
+const char *set_dyn_BINDIR(const char *newpath);
+
+const char *get_dyn_SWATDIR(void);
+const char *set_dyn_SWATDIR(const char *newpath);
+
+const char *get_dyn_CONFIGFILE(void);
+const char *set_dyn_CONFIGFILE(const char *newpath);
+
+const char *get_dyn_dyn_LOGFILEBASE(void);
+const char *set_dyn_dyn_LOGFILEBASE(const char *newpath);
+
+const char *get_dyn_LMHOSTSFILE(void);
+const char *set_dyn_LMHOSTSFILE(const char *newpath);
+
+const char *get_dyn_CODEPAGEDIR(void);
+const char *set_dyn_CODEPAGEDIR(const char *newpath);
+
+const char *get_dyn_LIBDIR(void);
+const char *set_dyn_LIBDIR(const char *newpath);
+
+const char *get_dyn_SHLIBEXT(void);
+const char *set_dyn_SHLIBEXT(const char *newpath);
+
+const char *get_dyn_LOCKDIR(void);
+const char *set_dyn_LOCKDIR(const char *newpath);
+
+const char *get_dyn_PIDDIR(void);
+const char *set_dyn_PIDDIR(const char *newpath);
+
+const char *get_dyn_SMB_PASSWD_FILE(void);
+const char *set_dyn_SMB_PASSWD_FILE(const char *newpath);
+
+const char *get_dyn_PRIVATE_DIR(void);
+const char *set_dyn_PRIVATE_DIR(const char *newpath);
+
+const char *get_dyn_STATEDIR(void);
+const char *get_dyn_CACHEDIR(void);
diff --git a/source/lib/fault.c b/source/lib/fault.c
index b5d290a..33e1401 100644
--- a/source/lib/fault.c
+++ b/source/lib/fault.c
@@ -108,7 +108,7 @@ void dump_core_setup(const char *progname)
 		 * line by the -l option but the "log file" option is not set
 		 * in smb.conf.
 		 */
-		if (asprintf(&logbase, "%s", dyn_LOGFILEBASE) < 0) {
+		if (asprintf(&logbase, "%s", get_dyn_LOGFILEBASE()) < 0) {
 			return;
 		}
 	}
diff --git a/source/lib/ldb/common/ldb_modules.c b/source/lib/ldb/common/ldb_modules.c
index c2fec2a..68c4535 100644
--- a/source/lib/ldb/common/ldb_modules.c
+++ b/source/lib/ldb/common/ldb_modules.c
@@ -212,7 +212,7 @@ int ldb_try_load_dso(struct ldb_context *ldb, const char *name)
 		modulesdir = talloc_strdup(ldb, getenv("LD_LDB_MODULE_PATH"));
 	} else {
 #ifdef _SAMBA_BUILD_
-		modulesdir = talloc_asprintf(ldb, "%s/ldb", dyn_MODULESDIR);
+		modulesdir = talloc_asprintf(ldb, "%s/ldb", get_dyn_LIBDIR());
 #else
 		modulesdir = talloc_strdup(ldb, MODULESDIR);
 #endif
diff --git a/source/lib/pidfile.c b/source/lib/pidfile.c
index b6a8e02..f49f8af 100644
--- a/source/lib/pidfile.c
+++ b/source/lib/pidfile.c
@@ -86,20 +86,20 @@ void pidfile_create(const char *program_name)
 {
 	int     fd;
 	char    buf[20];
-	char    *short_configfile;
+	const char    *short_configfile;
 	char *name;
 	char *pidFile;
 	pid_t pid;
 
 	/* Add a suffix to the program name if this is a process with a
 	 * none default configuration file name. */
-	if (strcmp( CONFIGFILE, dyn_CONFIGFILE) == 0) {
+	if (strcmp( CONFIGFILE, get_dyn_CONFIGFILE()) == 0) {
 		name = SMB_STRDUP(program_name);
 	} else {
-		short_configfile = strrchr( dyn_CONFIGFILE, '/');
+		short_configfile = strrchr( get_dyn_CONFIGFILE(), '/');
 		if (short_configfile == NULL) {
 			/* conf file in current directory */
-			short_configfile = dyn_CONFIGFILE;
+			short_configfile = get_dyn_CONFIGFILE();


-- 
Samba Shared Repository


More information about the samba-cvs mailing list