If they are not explicitely set in either place both will default to LOCKDIR.
Signed-off-by: Michael Adam <obnox@samba.org>
# 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@
# 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)
@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)"
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
-}
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);
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);
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);
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);
* --modulesdir
* --shlibext
* --lockdir
+ * --statedir
+ * --cachedir
* --piddir
* --smb-passwd-file
* --private-dir
DYN_MODULESDIR,
DYN_SHLIBEXT,
DYN_LOCKDIR,
+ DYN_STATEDIR,
+ DYN_CACHEDIR,
DYN_PIDDIR,
DYN_SMB_PASSWD_FILE,
DYN_PRIVATE_DIR,
}
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);
"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,
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)
{
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(),
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)
{
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());
}
/**
;;
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,
char *szDeletePrinterCommand;
char *szOs2DriverMap;
char *szLockDir;
+ char *szStateDir;
+ char *szCacheDir;
char *szPidDir;
char *szRootdir;
char *szDefaultService;
.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,
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) {
}
/*
- 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) \
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)
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());";
private dir = $PRIVATEDIR
pid directory = $PIDDIR
lock directory = $LOCKDIR
+ state directory = $LOCKDIR
+ cache directory = $LOCKDIR
log file = $LOGDIR/log.%m
log level = 0
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());