r15848: Introduce commandline options to set the remainder of the parameters in
authorJames Peach <jpeach@samba.org>
Wed, 24 May 2006 04:02:14 +0000 (04:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:17:11 +0000 (11:17 -0500)
dynconfig.c. This is mainly useful for test harness scripts, hence the
lack of short options.
(This used to be commit bf3b71c84595608d71e0f15a6158adacb295518e)

source3/dynconfig.c
source3/include/dynconfig.h
source3/include/popt_common.h
source3/lib/popt_common.c
source3/smbd/server.c

index 34c716926ccf9a803e72dfd98cae4085b4050607..3104a12f7cf5d35298c210b3e54c9e054e4b9737 100644 (file)
@@ -58,15 +58,15 @@ pstring dyn_LMHOSTSFILE = LMHOSTSFILE;
  * @sa lib_path() to get the path to a file inside the LIBDIR.
  **/
 pstring dyn_LIBDIR = LIBDIR;
-const fstring dyn_SHLIBEXT = SHLIBEXT;
+fstring dyn_SHLIBEXT = SHLIBEXT;
 
 /**
  * @brief Directory holding lock files.
  *
  * Not writable, but used to set a default in the parameter table.
  **/
-const pstring dyn_LOCKDIR = LOCKDIR;
-const pstring dyn_PIDDIR  = PIDDIR;
+pstring dyn_LOCKDIR = LOCKDIR;
+pstring dyn_PIDDIR  = PIDDIR;
 
-const pstring dyn_SMB_PASSWD_FILE = SMB_PASSWD_FILE;
-const pstring dyn_PRIVATE_DIR = PRIVATE_DIR;
+pstring dyn_SMB_PASSWD_FILE = SMB_PASSWD_FILE;
+pstring dyn_PRIVATE_DIR = PRIVATE_DIR;
index a74d77e41f72e62f15dc45028158e6987174f487..aebc9c941ef0e8a25fdb77e6851eeaaf63d378c7 100644 (file)
@@ -31,8 +31,8 @@ extern char const *dyn_SBINDIR,
 extern pstring dyn_CONFIGFILE;
 extern pstring dyn_LOGFILEBASE, dyn_LMHOSTSFILE;
 extern pstring dyn_LIBDIR;
-extern const fstring dyn_SHLIBEXT;
-extern const pstring dyn_LOCKDIR; 
-extern const pstring dyn_PIDDIR;
-extern const pstring dyn_SMB_PASSWD_FILE;
-extern const pstring dyn_PRIVATE_DIR;
+extern fstring dyn_SHLIBEXT;
+extern pstring dyn_LOCKDIR;
+extern pstring dyn_PIDDIR;
+extern pstring dyn_SMB_PASSWD_FILE;
+extern pstring dyn_PRIVATE_DIR;
index 7c0a86836dca7066d05393f3f624c0182b0219c9..4c3facb48f9cff9addb0683c78d0b54c79e53bce 100644 (file)
@@ -28,6 +28,7 @@ extern struct poptOption popt_common_samba[];
 extern struct poptOption popt_common_connection[];
 extern struct poptOption popt_common_version[];
 extern struct poptOption popt_common_credentials[];
+extern const struct poptOption popt_common_dynconfig[];
 
 #ifndef POPT_TABLEEND
 #define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL }
@@ -37,6 +38,9 @@ extern struct poptOption popt_common_credentials[];
 #define POPT_COMMON_CONNECTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_connection, 0, "Connection options:", NULL },
 #define POPT_COMMON_VERSION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version, 0, "Common samba options:", NULL },
 #define POPT_COMMON_CREDENTIALS { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_credentials, 0, "Authentication options:", NULL },
+#define POPT_COMMON_DYNCONFIG { NULL, 0, POPT_ARG_INCLUDE_TABLE, \
+    CONST_DISCARD(poptOption *, popt_common_dynconfig), 0, \
+    "Build-time configuration overrides:", NULL },
 
 struct user_auth_info {
        pstring username;
index 6c35213d43ae90e1fe6b3165b3fbf447a805d7a0..f842ae80111282d6c6519d71272dff6306e308c2 100644 (file)
@@ -4,6 +4,7 @@
 
    Copyright (C) Tim Potter 2001,2002
    Copyright (C) Jelmer Vernooij 2002,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
@@ -39,11 +40,9 @@ extern BOOL override_logfile;
 
 struct user_auth_info cmdline_auth_info;
 
-static void popt_common_callback(poptContext con, 
-                          enum poptCallbackReason reason,
-                          const struct poptOption *opt,
-                          const char *arg, const void *data)
+static void set_logfile(poptContext con, const char * arg)
 {
+
        pstring logfile;
        const char *pname;
        
@@ -55,9 +54,19 @@ static void popt_common_callback(poptContext con,
        else 
                pname++;
 
+       pstr_sprintf(logfile, "%s/log.%s", arg, pname);
+       lp_set_logfile(logfile);
+       override_logfile = True;
+}
+
+static void popt_common_callback(poptContext con,
+                          enum poptCallbackReason reason,
+                          const struct poptOption *opt,
+                          const char *arg, const void *data)
+{
+
        if (reason == POPT_CALLBACK_REASON_PRE) {
-               pstr_sprintf(logfile, "%s/log.%s", dyn_LOGFILEBASE, pname);
-               lp_set_logfile(logfile);
+               set_logfile(con, dyn_LOGFILEBASE);
                return;
        }
 
@@ -94,9 +103,8 @@ static void popt_common_callback(poptContext con,
 
        case 'l':
                if (arg) {
-                       pstr_sprintf(logfile, "%s/log.%s", arg, pname);
-                       lp_set_logfile(logfile);
-                       override_logfile = True;
+                       set_logfile(con, arg);
+                       pstr_sprintf(dyn_LOGFILEBASE, "%s", arg);
                }
                break;
 
@@ -128,8 +136,8 @@ struct poptOption popt_common_connection[] = {
 struct poptOption popt_common_samba[] = {
        { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback },
        { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" },
-       { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" },
-       { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files", "LOGFILEBASE" },
+       { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternate configuration file", "CONFIGFILE" },
+       { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Base name for log files", "LOGFILEBASE" },
        { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
        POPT_TABLEEND
 };
@@ -141,6 +149,130 @@ struct poptOption popt_common_version[] = {
 };
 
 
+/* Handle command line options:
+ *             --sbindir
+ *             --bindir
+ *             --swatdir
+ *             --lmhostsfile
+ *             --libdir
+ *             --shlibext
+ *             --lockdir
+ *             --piddir
+ *             --smb-passwd-file
+ *             --private-dir
+ */
+
+enum dyn_item{
+       DYN_SBINDIR = 1,
+       DYN_BINDIR,
+       DYN_SWATDIR,
+       DYN_LMHOSTSFILE,
+       DYN_LIBDIR,
+       DYN_SHLIBEXT,
+       DYN_LOCKDIR,
+       DYN_PIDDIR,
+       DYN_SMB_PASSWD_FILE,
+       DYN_PRIVATE_DIR,
+};
+
+
+static void popt_dynconfig_callback(poptContext con,
+                          enum poptCallbackReason reason,
+                          const struct poptOption *opt,
+                          const char *arg, const void *data)
+{
+
+       switch (opt->val) {
+       case DYN_SBINDIR:
+               if (arg) {
+                       dyn_SBINDIR = SMB_STRDUP(arg);
+               }
+               break;
+
+       case DYN_BINDIR:
+               if (arg) {
+                       dyn_BINDIR = SMB_STRDUP(arg);
+               }
+               break;
+
+       case DYN_SWATDIR:
+               if (arg) {
+                       dyn_SWATDIR = SMB_STRDUP(arg);
+               }
+               break;
+
+       case DYN_LMHOSTSFILE:
+               if (arg) {
+                       pstrcpy(dyn_LMHOSTSFILE, arg);
+               }
+               break;
+
+       case DYN_LIBDIR:
+               if (arg) {
+                       pstrcpy(dyn_LIBDIR, arg);
+               }
+               break;
+
+       case DYN_SHLIBEXT:
+               if (arg) {
+                       fstrcpy(dyn_SHLIBEXT, arg);
+               }
+               break;
+
+       case DYN_LOCKDIR:
+               if (arg) {
+                       pstrcpy(dyn_LOCKDIR, arg);
+               }
+               break;
+
+       case DYN_PIDDIR:
+               if (arg) {
+                       pstrcpy(dyn_PIDDIR, arg);
+               }
+               break;
+
+       case DYN_SMB_PASSWD_FILE:
+               if (arg) {
+                       pstrcpy(dyn_SMB_PASSWD_FILE, arg);
+               }
+               break;
+
+       case DYN_PRIVATE_DIR:
+               if (arg) {
+                       pstrcpy(dyn_PRIVATE_DIR, arg);
+               }
+               break;
+
+       }
+}
+
+const struct poptOption popt_common_dynconfig[] = {
+
+       { NULL, '\0', POPT_ARG_CALLBACK, popt_dynconfig_callback },
+
+       { "sbindir", '\0' , POPT_ARG_STRING, NULL, DYN_SBINDIR,
+           "Path to sbin directory", "SBINDIR" },
+       { "bindir", '\0' , POPT_ARG_STRING, NULL, DYN_BINDIR,
+           "Path to bin directory", "BINDIR" },
+       { "swatdir", '\0' , POPT_ARG_STRING, NULL, DYN_SWATDIR,
+           "Path to SWAT installation directory", "SWATDIR" },
+       { "lmhostsfile", '\0' , POPT_ARG_STRING, NULL, DYN_LMHOSTSFILE,
+           "Path to lmhosts file", "LMHOSTSFILE" },
+       { "libdir", '\0' , POPT_ARG_STRING, NULL, DYN_LIBDIR,
+           "Path to shared library directory", "LIBDIR" },
+       { "shlibext", '\0' , POPT_ARG_STRING, NULL, DYN_SHLIBEXT,
+           "Shared library extension", "SHLIBEXT" },
+       { "lockdir", '\0' , POPT_ARG_STRING, NULL, DYN_LOCKDIR,
+           "Path to lock file directory", "LOCKDIR" },
+       { "piddir", '\0' , POPT_ARG_STRING, NULL, DYN_PIDDIR,
+           "Path to PID file directory", "PIDDIR" },
+       { "smb-passwd-file", '\0' , POPT_ARG_STRING, NULL, DYN_SMB_PASSWD_FILE,
+           "Path to smbpasswd file", "SMB_PASSWD_FILE" },
+       { "private-dir", '\0' , POPT_ARG_STRING, NULL, DYN_PRIVATE_DIR,
+           "Path to private data directory", "PRIVATE_DIR" },
+
+       POPT_TABLEEND
+};
 
 /****************************************************************************
  * get a password from a a file or file descriptor
index d16579f24a8d7a124798c7a56d4ac7dfeaf377ec..2bfeae9f5412579c98a48d3cd3a74be972601c14 100644 (file)
@@ -744,16 +744,17 @@ void build_options(BOOL screen);
        poptContext pc;
 
        struct poptOption long_options[] = {
-               POPT_AUTOHELP
+       POPT_AUTOHELP
        {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
        {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"},
-       {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" },
-       {"no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
+       {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc.)" },
+       {"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
        {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
        {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
        {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
        POPT_COMMON_SAMBA
-       { NULL }
+       POPT_COMMON_DYNCONFIG
+       POPT_TABLEEND
        };
 
        load_case_tables();