1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-21 18:04:06 +03:00

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>
This commit is contained in:
Steven Danneman 2009-01-08 11:18:13 -08:00 committed by Michael Adam
parent ffb53c3574
commit 19a05bf2f4
11 changed files with 188 additions and 51 deletions

View 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)"

View 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
}

View 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);

View 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);

View 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,

View 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());
}
/**

View 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,

View 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)

View 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());";

View File

@ -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

View 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());