diff options
author | Steven Danneman <steven.danneman@isilon.com> | 2009-01-08 11:18:13 -0800 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2009-01-12 12:16:03 +0100 |
commit | 19a05bf2f485023b11b41dfae3f6459847d55ef7 (patch) | |
tree | 74b17e9f203dd81926a09876dc78e7cae3e799f6 | |
parent | ffb53c35748154081c1587b5f167721e32ff10f2 (diff) | |
download | samba-19a05bf2f485023b11b41dfae3f6459847d55ef7.tar.gz samba-19a05bf2f485023b11b41dfae3f6459847d55ef7.tar.bz2 samba-19a05bf2f485023b11b41dfae3f6459847d55ef7.zip |
Make STATEDIR and CACHEDIR configurable through ./configure and loadparm.c
If they are not explicitely set in either place both will default to LOCKDIR.
Signed-off-by: Michael Adam <obnox@samba.org>
-rw-r--r-- | source3/Makefile.in | 9 | ||||
-rw-r--r-- | source3/dynconfig.c | 25 | ||||
-rw-r--r-- | source3/include/dynconfig.h | 17 | ||||
-rw-r--r-- | source3/include/proto.h | 3 | ||||
-rw-r--r-- | source3/lib/popt_common.c | 20 | ||||
-rw-r--r-- | source3/lib/util.c | 60 | ||||
-rw-r--r-- | source3/m4/check_path.m4 | 32 | ||||
-rw-r--r-- | source3/param/loadparm.c | 49 | ||||
-rw-r--r-- | source3/script/mkbuildoptions.awk | 2 | ||||
-rwxr-xr-x | source3/script/tests/selftest.sh | 2 | ||||
-rw-r--r-- | source3/utils/testparm.c | 20 |
11 files changed, 188 insertions, 51 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index a4b9bda564..08ba0ad32a 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -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)" diff --git a/source3/dynconfig.c b/source3/dynconfig.c index 6125f9944c..dfec0c3baa 100644 --- a/source3/dynconfig.c +++ b/source3/dynconfig.c @@ -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 -} diff --git a/source3/include/dynconfig.h b/source3/include/dynconfig.h index 8267064f23..86c77138e7 100644 --- a/source3/include/dynconfig.h +++ b/source3/include/dynconfig.h @@ -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); diff --git a/source3/include/proto.h b/source3/include/proto.h index 9a0ba9a401..9d990207a0 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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); diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index cad14ec493..115133089c 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -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, diff --git a/source3/lib/util.c b/source3/lib/util.c index 08ea5add7a..1e6ee56230 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -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()); } /** diff --git a/source3/m4/check_path.m4 b/source3/m4/check_path.m4 index da6c922233..444ea1c401 100644 --- a/source3/m4/check_path.m4 +++ b/source3/m4/check_path.m4 @@ -102,6 +102,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, [AS_HELP_STRING([--with-piddir=DIR], [Where to put pid files ($ac_default_prefix/var/locks)])], diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index cb0ba47572..6c0936a4bc 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -119,6 +119,8 @@ struct global { char *szDeletePrinterCommand; char *szOs2DriverMap; char *szLockDir; + char *szStateDir; + char *szCacheDir; char *szPidDir; char *szRootdir; char *szDefaultService; @@ -3728,6 +3730,24 @@ static struct parm_struct parm_table[] = { .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, .p_class = P_GLOBAL, @@ -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) diff --git a/source3/script/mkbuildoptions.awk b/source3/script/mkbuildoptions.awk index a1e5d85061..1955a80b46 100644 --- a/source3/script/mkbuildoptions.awk +++ b/source3/script/mkbuildoptions.awk @@ -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());"; diff --git a/source3/script/tests/selftest.sh b/source3/script/tests/selftest.sh index 4786a78d31..94fd791b51 100755 --- a/source3/script/tests/selftest.sh +++ b/source3/script/tests/selftest.sh @@ -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 diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index da129cf7c0..e8458fda1b 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -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()); |