afs: Use talloc_stackframe() instead of talloc_init()
[samba.git] / source3 / 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 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)
82
83 #if 0
84 static char *dyn_CONFIGFILE; /**< Location of smb.conf file. **/
85
86 const char *get_dyn_CONFIGFILE(void)
87 {
88         if (dyn_CONFIGFILE == NULL) {
89                 return CONFIGFILE;
90         }
91         return dyn_CONFIGFILE;
92 }
93
94 const char *set_dyn_CONFIGFILE(const char *newpath)
95 {
96         if (dyn_CONFIGFILE) {
97                 SAFE_FREE(dyn_CONFIGFILE);
98         }
99         dyn_CONFIGFILE = SMB_STRDUP(newpath);
100         return dyn_CONFIGFILE;
101 }
102
103 /** Log file directory. **/
104 static char *dyn_LOGFILEBASE;
105
106 const char *get_dyn_LOGFILEBASE(void)
107 {
108         if (dyn_LOGFILEBASE == NULL) {
109                 return LOGFILEBASE;
110         }
111         return dyn_LOGFILEBASE;
112 }
113
114 const char *set_dyn_LOGFILEBASE(const char *newpath)
115 {
116         if (dyn_LOGFILEBASE) {
117                 SAFE_FREE(dyn_LOGFILEBASE);
118         }
119         dyn_LOGFILEBASE = SMB_STRDUP(newpath);
120         return dyn_LOGFILEBASE;
121 }
122
123 /** Statically configured LanMan hosts. **/
124 static char *dyn_LMHOSTSFILE;
125
126 const char *get_dyn_LMHOSTSFILE(void)
127 {
128         if (dyn_LMHOSTSFILE == NULL) {
129                 return LMHOSTSFILE;
130         }
131         return dyn_LMHOSTSFILE;
132 }
133
134 const char *set_dyn_LMHOSTSFILE(const char *newpath)
135 {
136         if (dyn_LMHOSTSFILE) {
137                 SAFE_FREE(dyn_LMHOSTSFILE);
138         }
139         dyn_LMHOSTSFILE = SMB_STRDUP(newpath);
140         return dyn_LMHOSTSFILE;
141 }
142
143 /**
144  * @brief Samba data directory.
145  *
146  * @sa data_path() to get the path to a file inside the CODEPAGEDIR.
147  **/
148 static char *dyn_CODEPAGEDIR;
149
150 const char *get_dyn_CODEPAGEDIR(void)
151 {
152         if (dyn_CODEPAGEDIR == NULL) {
153                 return CODEPAGEDIR;
154         }
155         return dyn_CODEPAGEDIR;
156 }
157
158 const char *set_dyn_CODEPAGEDIR(const char *newpath)
159 {
160         if (dyn_CODEPAGEDIR) {
161                 SAFE_FREE(dyn_CODEPAGEDIR);
162         }
163         dyn_CODEPAGEDIR = SMB_STRDUP(newpath);
164         return dyn_CODEPAGEDIR;
165 }
166
167 /**
168  * @brief Samba library directory.
169  *
170  * @sa lib_path() to get the path to a file inside the LIBDIR.
171  **/
172 static char *dyn_LIBDIR;
173
174 const char *get_dyn_LIBDIR(void)
175 {
176         if (dyn_LIBDIR == NULL) {
177                 return LIBDIR;
178         }
179         return dyn_CODEPAGEDIR;
180 }
181
182 const char *set_dyn_LIBDIR(const char *newpath)
183 {
184         if (dyn_LIBDIR) {
185                 SAFE_FREE(dyn_LIBDIR);
186         }
187         dyn_LIBDIR = SMB_STRDUP(newpath);
188         return dyn_LIBDIR;
189 }
190
191 static char *dyn_SHLIBEXT;
192
193 const char *get_dyn_SHLIBEXT(void)
194 {
195         if (dyn_SHLIBEXT == NULL) {
196                 return SHLIBEXT;
197         }
198         return dyn_SHLIBEXT;
199 }
200
201 const char *set_dyn_SHLIBEXT(const char *newpath)
202 {
203         if (dyn_SHLIBEXT) {
204                 SAFE_FREE(dyn_SHLIBEXT);
205         }
206         dyn_SHLIBEXT = SMB_STRDUP(newpath);
207         return dyn_SHLIBEXT;
208 }
209
210 /**
211  * @brief Directory holding lock files.
212  *
213  * Not writable, but used to set a default in the parameter table.
214  **/
215
216 static char *dyn_LOCKDIR;
217
218 const char *get_dyn_LOCKDIR(void)
219 {
220         if (dyn_LOCKDIR == NULL) {
221                 return LOCKDIR;
222         }
223         return dyn_LOCKDIR;
224 }
225
226 const char *set_dyn_LOCKDIR(const char *newpath)
227 {
228         if (dyn_LOCKDIR) {
229                 SAFE_FREE(dyn_LOCKDIR);
230         }
231         dyn_LOCKDIR = SMB_STRDUP(newpath);
232         return dyn_LOCKDIR;
233 }
234
235 static char *dyn_PIDDIR;
236
237 const char *get_dyn_PIDDIR(void)
238 {
239         if (dyn_PIDDIR == NULL) {
240                 return PIDDIR;
241         }
242         return dyn_PIDDIR;
243 }
244
245 const char *set_dyn_PIDDIR(const char *newpath)
246 {
247         if (dyn_PIDDIR) {
248                 SAFE_FREE(dyn_PIDDIR);
249         }
250         dyn_PIDDIR = SMB_STRDUP(newpath);
251         return dyn_PIDDIR;
252 }
253
254 static char *dyn_SMB_PASSWD_FILE;
255
256 const char *get_dyn_SMB_PASSWD_FILE(void)
257 {
258         if (dyn_SMB_PASSWD_FILE == NULL) {
259                 return SMB_PASSWD_FILE;
260         }
261         return dyn_SMB_PASSWD_FILE;
262 }
263
264 const char *set_dyn_SMB_PASSWD_FILE(const char *newpath)
265 {
266         if (dyn_SMB_PASSWD_FILE) {
267                 SAFE_FREE(dyn_SMB_PASSWD_FILE);
268         }
269         dyn_SMB_PASSWD_FILE = SMB_STRDUP(newpath);
270         return dyn_SMB_PASSWD_FILE;
271 }
272
273 static char *dyn_PRIVATE_DIR;
274
275 const char *get_dyn_PRIVATE_DIR(void)
276 {
277         if (dyn_PRIVATE_DIR == NULL) {
278                 return PRIVATE_DIR;
279         }
280         return dyn_PRIVATE_DIR;
281 }
282
283 const char *set_dyn_PRIVATE_DIR(const char *newpath)
284 {
285         if (dyn_PRIVATE_DIR) {
286                 SAFE_FREE(dyn_PRIVATE_DIR);
287         }
288         dyn_PRIVATE_DIR = SMB_STRDUP(newpath);
289         return dyn_PRIVATE_DIR;
290 }
291 #endif
292
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.
296  */
297
298 const char *get_dyn_STATEDIR(void)
299 {
300 #ifdef FHS_COMPATIBLE
301         return STATEDIR;
302 #else
303         return lp_lockdir();
304 #endif
305 }
306
307 const char *get_dyn_CACHEDIR(void)
308 {
309 #ifdef FHS_COMPATIBLE
310         return CACHEDIR;
311 #else
312         return lp_lockdir();
313 #endif
314 }