Make STATEDIR and CACHEDIR configurable through ./configure and loadparm.c
authorSteven Danneman <steven.danneman@isilon.com>
Thu, 8 Jan 2009 19:18:13 +0000 (11:18 -0800)
committerMichael Adam <obnox@samba.org>
Mon, 12 Jan 2009 11:16:03 +0000 (12:16 +0100)
If they are not explicitely set in either place both will default to LOCKDIR.

Signed-off-by: Michael Adam <obnox@samba.org>
source3/Makefile.in
source3/dynconfig.c
source3/include/dynconfig.h
source3/include/proto.h
source3/lib/popt_common.c
source3/lib/util.c
source3/m4/check_path.m4
source3/param/loadparm.c
source3/script/mkbuildoptions.awk
source3/script/tests/selftest.sh
source3/utils/testparm.c

index a4b9bda564222ad083f70ecf15fc67ea58a4792f..08ba0ad32adf00b8e3116bc97e078e5beaf33b3a 100644 (file)
@@ -147,7 +147,7 @@ LOCALEDIR= @localedir@
 # the directory where lock files go
 LOCKDIR = @lockdir@
 
-# FHS directories; equal to LOCKDIR if not using --with-fhs
+# FHS directories; equal to LOCKDIR if not using --with-fhs, but also settable
 CACHEDIR = @cachedir@
 STATEDIR = @statedir@
 
@@ -2641,7 +2641,10 @@ install-everything:: install installmodules
 # is not used
 
 installdirs::
-       @$(SHELL) $(srcdir)/script/installdirs.sh $(INSTALLPERMS_BIN) $(DESTDIR) $(prefix) $(BINDIR) $(SBINDIR) $(LIBDIR) $(VARDIR) $(PRIVATEDIR) $(PIDDIR) $(LOCKDIR) $(MANDIR) $(CODEPAGEDIR) $(MODULESDIR) $(LOCALEDIR)
+       @$(SHELL) $(srcdir)/script/installdirs.sh $(INSTALLPERMS_BIN) \
+               $(DESTDIR) $(prefix) $(BINDIR) $(SBINDIR) $(LIBDIR) \
+               $(VARDIR) $(PRIVATEDIR) $(PIDDIR) $(LOCKDIR) $(STATEDIR) \
+               $(CACHEDIR) $(MANDIR) $(CODEPAGEDIR) $(MODULESDIR) $(LOCALEDIR)
 
 installservers:: all installdirs
        @$(SHELL) script/installbin.sh $(INSTALLPERMS_BIN) $(DESTDIR) $(prefix) $(SBINDIR) $(SBIN_PROGS)
@@ -2724,6 +2727,8 @@ showlayout::
        @echo "  privatedir:  $(PRIVATE_DIR)"
        @echo "  configdir:   $(CONFIGDIR)"
        @echo "  lockdir:     $(LOCKDIR)"
+       @echo "  statedir:    $(STATEDIR)"
+       @echo "  cachedir:    $(CACHEDIR)"
        @echo "  piddir:      $(PIDDIR)"
        @echo "  swatdir:     $(SWATDIR)"
        @echo "  codepagedir: $(CODEPAGEDIR)"
index 6125f9944cab01fb760598a8897ac909542a0a73..dfec0c3baa8a3562c52be1aabfc51e7b33f488c8 100644 (file)
@@ -76,30 +76,9 @@ DEFINE_DYN_CONFIG_PARAM(LIBDIR)
 DEFINE_DYN_CONFIG_PARAM(MODULESDIR)
 DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
 DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
+DEFINE_DYN_CONFIG_PARAM(STATEDIR) /** Persistent state files. Default LOCKDIR */
+DEFINE_DYN_CONFIG_PARAM(CACHEDIR) /** Temporary cache files. Default LOCKDIR */
 DEFINE_DYN_CONFIG_PARAM(PIDDIR)
 DEFINE_DYN_CONFIG_PARAM(NCALRPCDIR)
 DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
 DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
-
-/* 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.
- */
-
-const char *get_dyn_STATEDIR(void)
-{
-#ifdef FHS_COMPATIBLE
-       return STATEDIR;
-#else
-       return lp_lockdir();
-#endif
-}
-
-const char *get_dyn_CACHEDIR(void)
-{
-#ifdef FHS_COMPATIBLE
-       return CACHEDIR;
-#else
-       return lp_lockdir();
-#endif
-}
index 8267064f23ee5d232cadf76420ed56ce235cc6f8..86c77138e7c92fc50dd8baf2223d888283962bcf 100644 (file)
@@ -67,6 +67,14 @@ const char *get_dyn_LOCKDIR(void);
 const char *set_dyn_LOCKDIR(const char *newpath);
 bool is_default_dyn_LOCKDIR(void);
 
+const char *get_dyn_STATEDIR(void);
+const char *set_dyn_STATEDIR(const char *newpath);
+bool is_default_dyn_STATEDIR(void);
+
+const char *get_dyn_CACHEDIR(void);
+const char *set_dyn_CACHEDIR(const char *newpath);
+bool is_default_dyn_CACHEDIR(void);
+
 const char *get_dyn_PIDDIR(void);
 const char *set_dyn_PIDDIR(const char *newpath);
 bool is_default_dyn_PIDDIR(void);
@@ -82,12 +90,3 @@ bool is_default_dyn_SMB_PASSWD_FILE(void);
 const char *get_dyn_PRIVATE_DIR(void);
 const char *set_dyn_PRIVATE_DIR(const char *newpath);
 bool is_default_dyn_PRIVATE_DIR(void);
-
-/*
- * For STATEDIR and CACHEDIR, there are only getter functions.
- * In non-FHS-mode, these are configurable via LOCKDIR.
- * In FHS-mode, these are their own fixed directories.
- */
-const char *get_dyn_STATEDIR(void);
-
-const char *get_dyn_CACHEDIR(void);
index 9a0ba9a4015ad13958cbe650d1e6fa4081bca7ac..9d990207a060ce8bc1324cdfc19c96d86d9ef28a 100644 (file)
@@ -1190,6 +1190,7 @@ char *lib_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);
@@ -3872,6 +3873,8 @@ char *lp_addprinter_cmd(void);
 char *lp_deleteprinter_cmd(void);
 char *lp_os2_driver_map(void);
 char *lp_lockdir(void);
+char *lp_statedir(void);
+char *lp_cachedir(void);
 char *lp_piddir(void);
 char *lp_mangling_method(void);
 int lp_mangle_prefix(void);
index cad14ec493092ebd18b4fd1a4c48795681e0f9f9..115133089c73911c6a1fcfaeed3db0cba4f080d3 100644 (file)
@@ -187,6 +187,8 @@ struct poptOption popt_common_debuglevel[] = {
  *             --modulesdir
  *             --shlibext
  *             --lockdir
+ *             --statedir
+ *             --cachedir
  *             --piddir
  *             --smb-passwd-file
  *             --private-dir
@@ -201,6 +203,8 @@ enum dyn_item{
        DYN_MODULESDIR,
        DYN_SHLIBEXT,
        DYN_LOCKDIR,
+       DYN_STATEDIR,
+       DYN_CACHEDIR,
        DYN_PIDDIR,
        DYN_SMB_PASSWD_FILE,
        DYN_PRIVATE_DIR,
@@ -262,6 +266,18 @@ static void popt_dynconfig_callback(poptContext con,
                }
                break;
 
+       case DYN_STATEDIR:
+               if (arg) {
+                       set_dyn_STATEDIR(arg);
+               }
+               break;
+
+       case DYN_CACHEDIR:
+               if (arg) {
+                       set_dyn_CACHEDIR(arg);
+               }
+               break;
+
        case DYN_PIDDIR:
                if (arg) {
                        set_dyn_PIDDIR(arg);
@@ -303,6 +319,10 @@ const struct poptOption popt_common_dynconfig[] = {
            "Shared library extension", "SHLIBEXT" },
        { "lockdir", '\0' , POPT_ARG_STRING, NULL, DYN_LOCKDIR,
            "Path to lock file directory", "LOCKDIR" },
+       { "statedir", '\0' , POPT_ARG_STRING, NULL, DYN_STATEDIR,
+           "Path to persistent state file directory", "STATEDIR" },
+       { "cachedir", '\0' , POPT_ARG_STRING, NULL, DYN_CACHEDIR,
+           "Path to temporary cache file directory", "CACHEDIR" },
        { "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,
index 08ea5add7a559a0bf83c02fae6ea99c5c7d7397e..1e6ee562302219176fdfbec2dcd5298506897729 100644 (file)
@@ -2232,9 +2232,14 @@ char *myhostname(void)
        return ret;
 }
 
-/*****************************************************************
- A useful function for returning a path in the Samba pid directory.
-*****************************************************************/
+/**
+ * @brief Returns an absolute path to a file concatenating the provided
+ * @a rootpath and @a basename
+ *
+ * @param name Filename, relative to @a rootpath
+ *
+ * @retval Pointer to a string containing the full path.
+ **/
 
 static char *xx_path(const char *name, const char *rootpath)
 {
@@ -2247,7 +2252,9 @@ static char *xx_path(const char *name, const char *rootpath)
        trim_string(fname,"","/");
 
        if (!directory_exist(fname)) {
-               mkdir(fname,0755);
+               if (!mkdir(fname,0755))
+                       DEBUG(1, ("Unable to create directory %s for file %s. "
+                             "Error was %s\n", fname, name, strerror(errno)));
        }
 
        return talloc_asprintf(talloc_tos(),
@@ -2256,18 +2263,26 @@ static char *xx_path(const char *name, const char *rootpath)
                                name);
 }
 
-/*****************************************************************
- A useful function for returning a path in the Samba lock directory.
-*****************************************************************/
+/**
+ * @brief Returns an absolute path to a file in the Samba lock directory.
+ *
+ * @param name File to find, relative to LOCKDIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
 
 char *lock_path(const char *name)
 {
        return xx_path(name, lp_lockdir());
 }
 
-/*****************************************************************
- A useful function for returning a path in the Samba pid directory.
-*****************************************************************/
+/**
+ * @brief Returns an absolute path to a file in the Samba pid directory.
+ *
+ * @param name File to find, relative to PIDDIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
 
 char *pid_path(const char *name)
 {
@@ -2313,13 +2328,30 @@ char *data_path(const char *name)
        return talloc_asprintf(talloc_tos(), "%s/%s", get_dyn_CODEPAGEDIR(), name);
 }
 
-/*****************************************************************
-a useful function for returning a path in the Samba state directory
- *****************************************************************/
+/**
+ * @brief Returns an absolute path to a file in the Samba state directory.
+ *
+ * @param name File to find, relative to STATEDIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
 
 char *state_path(const char *name)
 {
-       return xx_path(name, get_dyn_STATEDIR());
+       return xx_path(name, lp_statedir());
+}
+
+/**
+ * @brief Returns an absolute path to a file in the Samba cache directory.
+ *
+ * @param name File to find, relative to CACHEDIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
+
+char *cache_path(const char *name)
+{
+       return xx_path(name, lp_cachedir());
 }
 
 /**
index da6c9222338a1d9368ee678121166586aba83b2a..444ea1c401054ae494e8917eaccf9a5027414d5e 100644 (file)
@@ -101,6 +101,38 @@ AC_ARG_WITH(lockdir,
     ;;
   esac])
 
+#################################################
+# set state directory location
+AC_ARG_WITH(statedir,
+[AS_HELP_STRING([--with-statedir=DIR], [Where to put persistent state files ($ac_default_prefix/var/locks)])],
+[ case "$withval" in
+  yes|no)
+  #
+  # Just in case anybody calls it without argument
+  #
+    AC_MSG_WARN([--with-statedir called without argument - will use default])
+  ;;
+  * )
+    statedir="$withval"
+    ;;
+  esac])
+
+#################################################
+# set cache directory location
+AC_ARG_WITH(cachedir,
+[AS_HELP_STRING([--with-cachedir=DIR], [Where to put temporary cache files ($ac_default_prefix/var/locks)])],
+[ case "$withval" in
+  yes|no)
+  #
+  # Just in case anybody calls it without argument
+  #
+    AC_MSG_WARN([--with-cachedir called without argument - will use default])
+  ;;
+  * )
+    cachedir="$withval"
+    ;;
+  esac])
+
 #################################################
 # set pid directory location
 AC_ARG_WITH(piddir,
index cb0ba47572e3cc7609ff4adf1af8cda7400c35ad..6c0936a4bc1405e8e90510c4d2fe513849f9cc7f 100644 (file)
@@ -119,6 +119,8 @@ struct global {
        char *szDeletePrinterCommand;
        char *szOs2DriverMap;
        char *szLockDir;
+       char *szStateDir;
+       char *szCacheDir;
        char *szPidDir;
        char *szRootdir;
        char *szDefaultService;
@@ -3727,6 +3729,24 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_HIDE,
        },
+       {
+               .label          = "state directory",
+               .type           = P_STRING,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.szStateDir,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
+       {
+               .label          = "cache directory",
+               .type           = P_STRING,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.szCacheDir,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
        {
                .label          = "pid directory",
                .type           = P_STRING,
@@ -4747,8 +4767,10 @@ static void init_globals(bool first_time_only)
        string_set(&Globals.szWorkgroup, lp_workgroup());
 
        string_set(&Globals.szPasswdProgram, "");
-       string_set(&Globals.szPidDir, get_dyn_PIDDIR());
        string_set(&Globals.szLockDir, get_dyn_LOCKDIR());
+       string_set(&Globals.szStateDir, get_dyn_STATEDIR());
+       string_set(&Globals.szCacheDir, get_dyn_CACHEDIR());
+       string_set(&Globals.szPidDir, get_dyn_PIDDIR());
        string_set(&Globals.szSocketAddress, "0.0.0.0");
 
        if (asprintf(&s, "Samba %s", SAMBA_VERSION_STRING) < 0) {
@@ -5027,8 +5049,8 @@ static char *lp_string(const char *s)
 }
 
 /*
-   In this section all the functions that are used to access the 
-   parameters from the rest of the program are defined 
+   In this section all the functions that are used to access the
+   parameters from the rest of the program are defined
 */
 
 #define FN_GLOBAL_STRING(fn_name,ptr) \
@@ -5080,6 +5102,27 @@ FN_GLOBAL_STRING(lp_addprinter_cmd, &Globals.szAddPrinterCommand)
 FN_GLOBAL_STRING(lp_deleteprinter_cmd, &Globals.szDeletePrinterCommand)
 FN_GLOBAL_STRING(lp_os2_driver_map, &Globals.szOs2DriverMap)
 FN_GLOBAL_STRING(lp_lockdir, &Globals.szLockDir)
+/* If lp_statedir() and lp_cachedir() are explicitely set during the
+ * build process or in smb.conf, we use that value.  Otherwise they
+ * default to the value of lp_lockdir(). */
+char *lp_statedir(void) {
+       if ((strcmp(get_dyn_STATEDIR(), get_dyn_LOCKDIR()) != 0) ||
+           (strcmp(get_dyn_STATEDIR(), Globals.szStateDir) != 0))
+               return(lp_string(*(char **)(&Globals.szStateDir) ?
+                   *(char **)(&Globals.szStateDir) : ""));
+       else
+               return(lp_string(*(char **)(&Globals.szLockDir) ?
+                   *(char **)(&Globals.szLockDir) : ""));
+}
+char *lp_cachedir(void) {
+       if ((strcmp(get_dyn_CACHEDIR(), get_dyn_LOCKDIR()) != 0) ||
+           (strcmp(get_dyn_CACHEDIR(), Globals.szCacheDir) != 0))
+               return(lp_string(*(char **)(&Globals.szCacheDir) ?
+                   *(char **)(&Globals.szCacheDir) : ""));
+       else
+               return(lp_string(*(char **)(&Globals.szLockDir) ?
+                   *(char **)(&Globals.szLockDir) : ""));
+}
 FN_GLOBAL_STRING(lp_piddir, &Globals.szPidDir)
 FN_GLOBAL_STRING(lp_mangling_method, &Globals.szManglingMethod)
 FN_GLOBAL_INTEGER(lp_mangle_prefix, &Globals.mangle_prefix)
index a1e5d8506198e60c98709e3945175d219ead28a7..1955a80b46cc377df3ed9da13a4b0863eb1c8f33 100644 (file)
@@ -90,6 +90,8 @@ BEGIN {
        print "       output(screen,\"   SHLIBEXT: %s\\n\",get_dyn_SHLIBEXT());";
 
        print "       output(screen,\"   LOCKDIR: %s\\n\",get_dyn_LOCKDIR());";
+       print "       output(screen,\"   STATEDIR: %s\\n\",get_dyn_STATEDIR());";
+       print "       output(screen,\"   CACHEDIR: %s\\n\",get_dyn_CACHEDIR());";
        print "       output(screen,\"   PIDDIR: %s\\n\", get_dyn_PIDDIR());";
 
        print "       output(screen,\"   SMB_PASSWD_FILE: %s\\n\",get_dyn_SMB_PASSWD_FILE());";
index 4786a78d31b082792bc8c34fc1c6296840357c23..94fd791b51c2e6c564f27b292b60fe78658846cf 100755 (executable)
@@ -140,6 +140,8 @@ cat >$COMMONCONFFILE<<EOF
        private dir = $PRIVATEDIR
        pid directory = $PIDDIR
        lock directory = $LOCKDIR
+       state directory = $LOCKDIR
+       cache directory = $LOCKDIR
        log file = $LOGDIR/log.%m
        log level = 0
 
index da129cf7c04c9368e57731530e9096ce383479c3..e8458fda1b6c7b74d3d51593f00c72552a6b9850 100644 (file)
@@ -66,6 +66,26 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
                ret = 1;
        }
 
+       if (!directory_exist_stat(lp_statedir(), &st)) {
+               fprintf(stderr, "ERROR: state directory %s does not exist\n",
+                      lp_statedir());
+               ret = 1;
+       } else if ((st.st_mode & 0777) != 0755) {
+               fprintf(stderr, "WARNING: state directory %s should have permissions 0755 for browsing to work\n",
+                      lp_statedir());
+               ret = 1;
+       }
+
+       if (!directory_exist_stat(lp_cachedir(), &st)) {
+               fprintf(stderr, "ERROR: cache directory %s does not exist\n",
+                      lp_cachedir());
+               ret = 1;
+       } else if ((st.st_mode & 0777) != 0755) {
+               fprintf(stderr, "WARNING: cache directory %s should have permissions 0755 for browsing to work\n",
+                      lp_cachedir());
+               ret = 1;
+       }
+
        if (!directory_exist_stat(lp_piddir(), &st)) {
                fprintf(stderr, "ERROR: pid directory %s does not exist\n",
                       lp_piddir());