Re-run make idl.
[gd/samba/.git] / source / dynconfig.c
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>
6
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.
11
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.
16
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/>.
19 */
20
21 #include "includes.h"
22
23 /**
24  * @file dynconfig.c
25  *
26  * @brief Global configurations, initialized to configured defaults.
27  *
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.
33  *
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.
38  *
39  * @todo Perhaps eventually these should be merged into the parameter
40  * table?  There's kind of a chicken-and-egg situation there...
41  **/
42
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
48
49 #define DEFINE_DYN_CONFIG_PARAM(name) \
50 static char *dyn_##name; \
51 \
52  const char *get_dyn_##name(void) \
53 {\
54         if (dyn_##name == NULL) {\
55                 return name;\
56         }\
57         return dyn_##name;\
58 }\
59 \
60  const char *set_dyn_##name(const char *newpath) \
61 {\
62         if (dyn_##name) {\
63                 SAFE_FREE(dyn_##name);\
64         }\
65         dyn_##name = SMB_STRDUP(newpath);\
66         return dyn_##name;\
67 }\
68 \
69  bool is_default_dyn_##name(void) \
70 {\
71         return (dyn_##name == NULL);\
72 }
73
74 DEFINE_DYN_CONFIG_PARAM(SBINDIR)
75 DEFINE_DYN_CONFIG_PARAM(BINDIR)
76 DEFINE_DYN_CONFIG_PARAM(SWATDIR)
77 DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
78 DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
79 DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
80 DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
81 DEFINE_DYN_CONFIG_PARAM(LIBDIR)
82 DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
83 DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
84 DEFINE_DYN_CONFIG_PARAM(PIDDIR)
85 DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
86 DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
87
88 #if 0
89 static char *dyn_CONFIGFILE; /**< Location of smb.conf file. **/
90
91 const char *get_dyn_CONFIGFILE(void)
92 {
93         if (dyn_CONFIGFILE == NULL) {
94                 return CONFIGFILE;
95         }
96         return dyn_CONFIGFILE;
97 }
98
99 const char *set_dyn_CONFIGFILE(const char *newpath)
100 {
101         if (dyn_CONFIGFILE) {
102                 SAFE_FREE(dyn_CONFIGFILE);
103         }
104         dyn_CONFIGFILE = SMB_STRDUP(newpath);
105         return dyn_CONFIGFILE;
106 }
107
108 /** Log file directory. **/
109 static char *dyn_LOGFILEBASE;
110
111 const char *get_dyn_LOGFILEBASE(void)
112 {
113         if (dyn_LOGFILEBASE == NULL) {
114                 return LOGFILEBASE;
115         }
116         return dyn_LOGFILEBASE;
117 }
118
119 const char *set_dyn_LOGFILEBASE(const char *newpath)
120 {
121         if (dyn_LOGFILEBASE) {
122                 SAFE_FREE(dyn_LOGFILEBASE);
123         }
124         dyn_LOGFILEBASE = SMB_STRDUP(newpath);
125         return dyn_LOGFILEBASE;
126 }
127
128 /** Statically configured LanMan hosts. **/
129 static char *dyn_LMHOSTSFILE;
130
131 const char *get_dyn_LMHOSTSFILE(void)
132 {
133         if (dyn_LMHOSTSFILE == NULL) {
134                 return LMHOSTSFILE;
135         }
136         return dyn_LMHOSTSFILE;
137 }
138
139 const char *set_dyn_LMHOSTSFILE(const char *newpath)
140 {
141         if (dyn_LMHOSTSFILE) {
142                 SAFE_FREE(dyn_LMHOSTSFILE);
143         }
144         dyn_LMHOSTSFILE = SMB_STRDUP(newpath);
145         return dyn_LMHOSTSFILE;
146 }
147
148 /**
149  * @brief Samba data directory.
150  *
151  * @sa data_path() to get the path to a file inside the CODEPAGEDIR.
152  **/
153 static char *dyn_CODEPAGEDIR;
154
155 const char *get_dyn_CODEPAGEDIR(void)
156 {
157         if (dyn_CODEPAGEDIR == NULL) {
158                 return CODEPAGEDIR;
159         }
160         return dyn_CODEPAGEDIR;
161 }
162
163 const char *set_dyn_CODEPAGEDIR(const char *newpath)
164 {
165         if (dyn_CODEPAGEDIR) {
166                 SAFE_FREE(dyn_CODEPAGEDIR);
167         }
168         dyn_CODEPAGEDIR = SMB_STRDUP(newpath);
169         return dyn_CODEPAGEDIR;
170 }
171
172 /**
173  * @brief Samba library directory.
174  *
175  * @sa lib_path() to get the path to a file inside the LIBDIR.
176  **/
177 static char *dyn_LIBDIR;
178
179 const char *get_dyn_LIBDIR(void)
180 {
181         if (dyn_LIBDIR == NULL) {
182                 return LIBDIR;
183         }
184         return dyn_CODEPAGEDIR;
185 }
186
187 const char *set_dyn_LIBDIR(const char *newpath)
188 {
189         if (dyn_LIBDIR) {
190                 SAFE_FREE(dyn_LIBDIR);
191         }
192         dyn_LIBDIR = SMB_STRDUP(newpath);
193         return dyn_LIBDIR;
194 }
195
196 static char *dyn_SHLIBEXT;
197
198 const char *get_dyn_SHLIBEXT(void)
199 {
200         if (dyn_SHLIBEXT == NULL) {
201                 return SHLIBEXT;
202         }
203         return dyn_SHLIBEXT;
204 }
205
206 const char *set_dyn_SHLIBEXT(const char *newpath)
207 {
208         if (dyn_SHLIBEXT) {
209                 SAFE_FREE(dyn_SHLIBEXT);
210         }
211         dyn_SHLIBEXT = SMB_STRDUP(newpath);
212         return dyn_SHLIBEXT;
213 }
214
215 /**
216  * @brief Directory holding lock files.
217  *
218  * Not writable, but used to set a default in the parameter table.
219  **/
220
221 static char *dyn_LOCKDIR;
222
223 const char *get_dyn_LOCKDIR(void)
224 {
225         if (dyn_LOCKDIR == NULL) {
226                 return LOCKDIR;
227         }
228         return dyn_LOCKDIR;
229 }
230
231 const char *set_dyn_LOCKDIR(const char *newpath)
232 {
233         if (dyn_LOCKDIR) {
234                 SAFE_FREE(dyn_LOCKDIR);
235         }
236         dyn_LOCKDIR = SMB_STRDUP(newpath);
237         return dyn_LOCKDIR;
238 }
239
240 static char *dyn_PIDDIR;
241
242 const char *get_dyn_PIDDIR(void)
243 {
244         if (dyn_PIDDIR == NULL) {
245                 return PIDDIR;
246         }
247         return dyn_PIDDIR;
248 }
249
250 const char *set_dyn_PIDDIR(const char *newpath)
251 {
252         if (dyn_PIDDIR) {
253                 SAFE_FREE(dyn_PIDDIR);
254         }
255         dyn_PIDDIR = SMB_STRDUP(newpath);
256         return dyn_PIDDIR;
257 }
258
259 static char *dyn_SMB_PASSWD_FILE;
260
261 const char *get_dyn_SMB_PASSWD_FILE(void)
262 {
263         if (dyn_SMB_PASSWD_FILE == NULL) {
264                 return SMB_PASSWD_FILE;
265         }
266         return dyn_SMB_PASSWD_FILE;
267 }
268
269 const char *set_dyn_SMB_PASSWD_FILE(const char *newpath)
270 {
271         if (dyn_SMB_PASSWD_FILE) {
272                 SAFE_FREE(dyn_SMB_PASSWD_FILE);
273         }
274         dyn_SMB_PASSWD_FILE = SMB_STRDUP(newpath);
275         return dyn_SMB_PASSWD_FILE;
276 }
277
278 static char *dyn_PRIVATE_DIR;
279
280 const char *get_dyn_PRIVATE_DIR(void)
281 {
282         if (dyn_PRIVATE_DIR == NULL) {
283                 return PRIVATE_DIR;
284         }
285         return dyn_PRIVATE_DIR;
286 }
287
288 const char *set_dyn_PRIVATE_DIR(const char *newpath)
289 {
290         if (dyn_PRIVATE_DIR) {
291                 SAFE_FREE(dyn_PRIVATE_DIR);
292         }
293         dyn_PRIVATE_DIR = SMB_STRDUP(newpath);
294         return dyn_PRIVATE_DIR;
295 }
296 #endif
297
298 /* In non-FHS mode, these should be configurable using 'lock dir =';
299    but in FHS mode, they are their own directory.  Implement as wrapper
300    functions so that everything can still be kept in dynconfig.c.
301  */
302
303 const char *get_dyn_STATEDIR(void)
304 {
305 #ifdef FHS_COMPATIBLE
306         return STATEDIR;
307 #else
308         return lp_lockdir();
309 #endif
310 }
311
312 const char *get_dyn_CACHEDIR(void)
313 {
314 #ifdef FHS_COMPATIBLE
315         return CACHEDIR;
316 #else
317         return lp_lockdir();
318 #endif
319 }