Some more minor cleanup for "net rpc audit".
[Samba/gebeck_regimport.git] / source / dynconfig.c
blobab0dd48da7ccd1b3d46d9091fb14a0283ec9c22f
1 /*
2 Unix SMB/CIFS implementation.
3 Copyright (C) 2001 by Martin Pool <mbp@samba.org>
4 Copyright (C) 2003 by Jim McDonough <jmcd@us.ibm.com>
5 Copyright (C) 2007 by Jeremy Allison <jra@samba.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
23 /**
24 * @file dynconfig.c
26 * @brief Global configurations, initialized to configured defaults.
28 * This file should be the only file that depends on path
29 * configuration (--prefix, etc), so that if ./configure is re-run,
30 * all programs will be appropriately updated. Everything else in
31 * Samba should import extern variables from here, rather than relying
32 * on preprocessor macros.
34 * Eventually some of these may become even more variable, so that
35 * they can for example consistently be set across the whole of Samba
36 * by command-line parameters, config file entries, or environment
37 * variables.
39 * @todo Perhaps eventually these should be merged into the parameter
40 * table? There's kind of a chicken-and-egg situation there...
41 **/
43 #if 0
44 static char const *dyn_SBINDIR = SBINDIR;
45 static char const *dyn_BINDIR = BINDIR;
46 static char const *dyn_SWATDIR = SWATDIR;
47 #endif
49 #define DEFINE_DYN_CONFIG_PARAM(name) \
50 static char *dyn_##name; \
52 const char *get_dyn_##name(void) \
54 if (dyn_##name == NULL) {\
55 return name;\
57 return dyn_##name;\
60 const char *set_dyn_##name(const char *newpath) \
62 if (dyn_##name) {\
63 SAFE_FREE(dyn_##name);\
65 dyn_##name = SMB_STRDUP(newpath);\
66 return dyn_##name;\
69 DEFINE_DYN_CONFIG_PARAM(SBINDIR)
70 DEFINE_DYN_CONFIG_PARAM(BINDIR)
71 DEFINE_DYN_CONFIG_PARAM(SWATDIR)
72 DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
73 DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
74 DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
75 DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
76 DEFINE_DYN_CONFIG_PARAM(LIBDIR)
77 DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
78 DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
79 DEFINE_DYN_CONFIG_PARAM(PIDDIR)
80 DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
81 DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
83 #if 0
84 static char *dyn_CONFIGFILE; /**< Location of smb.conf file. **/
86 const char *get_dyn_CONFIGFILE(void)
88 if (dyn_CONFIGFILE == NULL) {
89 return CONFIGFILE;
91 return dyn_CONFIGFILE;
94 const char *set_dyn_CONFIGFILE(const char *newpath)
96 if (dyn_CONFIGFILE) {
97 SAFE_FREE(dyn_CONFIGFILE);
99 dyn_CONFIGFILE = SMB_STRDUP(newpath);
100 return dyn_CONFIGFILE;
103 /** Log file directory. **/
104 static char *dyn_LOGFILEBASE;
106 const char *get_dyn_LOGFILEBASE(void)
108 if (dyn_LOGFILEBASE == NULL) {
109 return LOGFILEBASE;
111 return dyn_LOGFILEBASE;
114 const char *set_dyn_LOGFILEBASE(const char *newpath)
116 if (dyn_LOGFILEBASE) {
117 SAFE_FREE(dyn_LOGFILEBASE);
119 dyn_LOGFILEBASE = SMB_STRDUP(newpath);
120 return dyn_LOGFILEBASE;
123 /** Statically configured LanMan hosts. **/
124 static char *dyn_LMHOSTSFILE;
126 const char *get_dyn_LMHOSTSFILE(void)
128 if (dyn_LMHOSTSFILE == NULL) {
129 return LMHOSTSFILE;
131 return dyn_LMHOSTSFILE;
134 const char *set_dyn_LMHOSTSFILE(const char *newpath)
136 if (dyn_LMHOSTSFILE) {
137 SAFE_FREE(dyn_LMHOSTSFILE);
139 dyn_LMHOSTSFILE = SMB_STRDUP(newpath);
140 return dyn_LMHOSTSFILE;
144 * @brief Samba data directory.
146 * @sa data_path() to get the path to a file inside the CODEPAGEDIR.
148 static char *dyn_CODEPAGEDIR;
150 const char *get_dyn_CODEPAGEDIR(void)
152 if (dyn_CODEPAGEDIR == NULL) {
153 return CODEPAGEDIR;
155 return dyn_CODEPAGEDIR;
158 const char *set_dyn_CODEPAGEDIR(const char *newpath)
160 if (dyn_CODEPAGEDIR) {
161 SAFE_FREE(dyn_CODEPAGEDIR);
163 dyn_CODEPAGEDIR = SMB_STRDUP(newpath);
164 return dyn_CODEPAGEDIR;
168 * @brief Samba library directory.
170 * @sa lib_path() to get the path to a file inside the LIBDIR.
172 static char *dyn_LIBDIR;
174 const char *get_dyn_LIBDIR(void)
176 if (dyn_LIBDIR == NULL) {
177 return LIBDIR;
179 return dyn_CODEPAGEDIR;
182 const char *set_dyn_LIBDIR(const char *newpath)
184 if (dyn_LIBDIR) {
185 SAFE_FREE(dyn_LIBDIR);
187 dyn_LIBDIR = SMB_STRDUP(newpath);
188 return dyn_LIBDIR;
191 static char *dyn_SHLIBEXT;
193 const char *get_dyn_SHLIBEXT(void)
195 if (dyn_SHLIBEXT == NULL) {
196 return SHLIBEXT;
198 return dyn_SHLIBEXT;
201 const char *set_dyn_SHLIBEXT(const char *newpath)
203 if (dyn_SHLIBEXT) {
204 SAFE_FREE(dyn_SHLIBEXT);
206 dyn_SHLIBEXT = SMB_STRDUP(newpath);
207 return dyn_SHLIBEXT;
211 * @brief Directory holding lock files.
213 * Not writable, but used to set a default in the parameter table.
216 static char *dyn_LOCKDIR;
218 const char *get_dyn_LOCKDIR(void)
220 if (dyn_LOCKDIR == NULL) {
221 return LOCKDIR;
223 return dyn_LOCKDIR;
226 const char *set_dyn_LOCKDIR(const char *newpath)
228 if (dyn_LOCKDIR) {
229 SAFE_FREE(dyn_LOCKDIR);
231 dyn_LOCKDIR = SMB_STRDUP(newpath);
232 return dyn_LOCKDIR;
235 static char *dyn_PIDDIR;
237 const char *get_dyn_PIDDIR(void)
239 if (dyn_PIDDIR == NULL) {
240 return PIDDIR;
242 return dyn_PIDDIR;
245 const char *set_dyn_PIDDIR(const char *newpath)
247 if (dyn_PIDDIR) {
248 SAFE_FREE(dyn_PIDDIR);
250 dyn_PIDDIR = SMB_STRDUP(newpath);
251 return dyn_PIDDIR;
254 static char *dyn_SMB_PASSWD_FILE;
256 const char *get_dyn_SMB_PASSWD_FILE(void)
258 if (dyn_SMB_PASSWD_FILE == NULL) {
259 return SMB_PASSWD_FILE;
261 return dyn_SMB_PASSWD_FILE;
264 const char *set_dyn_SMB_PASSWD_FILE(const char *newpath)
266 if (dyn_SMB_PASSWD_FILE) {
267 SAFE_FREE(dyn_SMB_PASSWD_FILE);
269 dyn_SMB_PASSWD_FILE = SMB_STRDUP(newpath);
270 return dyn_SMB_PASSWD_FILE;
273 static char *dyn_PRIVATE_DIR;
275 const char *get_dyn_PRIVATE_DIR(void)
277 if (dyn_PRIVATE_DIR == NULL) {
278 return PRIVATE_DIR;
280 return dyn_PRIVATE_DIR;
283 const char *set_dyn_PRIVATE_DIR(const char *newpath)
285 if (dyn_PRIVATE_DIR) {
286 SAFE_FREE(dyn_PRIVATE_DIR);
288 dyn_PRIVATE_DIR = SMB_STRDUP(newpath);
289 return dyn_PRIVATE_DIR;
291 #endif
293 /* In non-FHS mode, these should be configurable using 'lock dir =';
294 but in FHS mode, they are their own directory. Implement as wrapper
295 functions so that everything can still be kept in dynconfig.c.
298 const char *get_dyn_STATEDIR(void)
300 #ifdef FHS_COMPATIBLE
301 return STATEDIR;
302 #else
303 return lp_lockdir();
304 #endif
307 const char *get_dyn_CACHEDIR(void)
309 #ifdef FHS_COMPATIBLE
310 return CACHEDIR;
311 #else
312 return lp_lockdir();
313 #endif