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 | #ifndef __OS2__
|
---|
78 | DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
|
---|
79 | DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
|
---|
80 | DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
|
---|
81 | #endif
|
---|
82 | DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
|
---|
83 | DEFINE_DYN_CONFIG_PARAM(LIBDIR)
|
---|
84 | DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
|
---|
85 | #ifndef __OS2__
|
---|
86 | DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
|
---|
87 | DEFINE_DYN_CONFIG_PARAM(PIDDIR)
|
---|
88 | DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
|
---|
89 | DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | #ifdef __OS2__
|
---|
93 | static char *dyn_CONFIGFILE; /**< Location of smb.conf file. **/
|
---|
94 |
|
---|
95 | const char *get_dyn_CONFIGFILE(void)
|
---|
96 | {
|
---|
97 | static char buffer[1024] = "";
|
---|
98 | if (!*buffer)
|
---|
99 | {
|
---|
100 | snprintf(buffer, 260, "%s/samba/smb.conf", getenv("ETC"));
|
---|
101 | }
|
---|
102 | if (dyn_CONFIGFILE == NULL) {
|
---|
103 |
|
---|
104 | return buffer;
|
---|
105 | }
|
---|
106 | return dyn_CONFIGFILE;
|
---|
107 | }
|
---|
108 |
|
---|
109 | const char *set_dyn_CONFIGFILE(const char *newpath)
|
---|
110 | {
|
---|
111 | if (dyn_CONFIGFILE) {
|
---|
112 | SAFE_FREE(dyn_CONFIGFILE);
|
---|
113 | }
|
---|
114 | dyn_CONFIGFILE = SMB_STRDUP(newpath);
|
---|
115 | return dyn_CONFIGFILE;
|
---|
116 | }
|
---|
117 |
|
---|
118 | bool is_default_dyn_CONFIGFILE(void) \
|
---|
119 | {\
|
---|
120 | return (dyn_CONFIGFILE == NULL);\
|
---|
121 | }
|
---|
122 |
|
---|
123 | /** Log file directory. **/
|
---|
124 | static char *dyn_LOGFILEBASE;
|
---|
125 |
|
---|
126 | const char *get_dyn_LOGFILEBASE(void)
|
---|
127 | {
|
---|
128 | static char buffer[1024] = "";
|
---|
129 | if (!*buffer)
|
---|
130 | {
|
---|
131 | snprintf(buffer, 260, "%s/samba/log", getenv("ETC"));
|
---|
132 | }
|
---|
133 | if (dyn_LOGFILEBASE == NULL) {
|
---|
134 | return buffer;
|
---|
135 | }
|
---|
136 | return dyn_LOGFILEBASE;
|
---|
137 | }
|
---|
138 |
|
---|
139 | const char *set_dyn_LOGFILEBASE(const char *newpath)
|
---|
140 | {
|
---|
141 | if (dyn_LOGFILEBASE) {
|
---|
142 | SAFE_FREE(dyn_LOGFILEBASE);
|
---|
143 | }
|
---|
144 | dyn_LOGFILEBASE = SMB_STRDUP(newpath);
|
---|
145 | return dyn_LOGFILEBASE;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /** Statically configured LanMan hosts. **/
|
---|
149 | static char *dyn_LMHOSTSFILE;
|
---|
150 |
|
---|
151 | const char *get_dyn_LMHOSTSFILE(void)
|
---|
152 | {
|
---|
153 | static char buffer[1024] = "";
|
---|
154 | if (!*buffer)
|
---|
155 | {
|
---|
156 | snprintf(buffer, 260, "%s/samba/lmhosts", getenv("ETC"));
|
---|
157 | }
|
---|
158 | if (dyn_LMHOSTSFILE == NULL) {
|
---|
159 | return buffer;
|
---|
160 | }
|
---|
161 | return dyn_LMHOSTSFILE;
|
---|
162 | }
|
---|
163 |
|
---|
164 | const char *set_dyn_LMHOSTSFILE(const char *newpath)
|
---|
165 | {
|
---|
166 | if (dyn_LMHOSTSFILE) {
|
---|
167 | SAFE_FREE(dyn_LMHOSTSFILE);
|
---|
168 | }
|
---|
169 | dyn_LMHOSTSFILE = SMB_STRDUP(newpath);
|
---|
170 | return dyn_LMHOSTSFILE;
|
---|
171 | }
|
---|
172 | #endif /* __OS2__ */
|
---|
173 |
|
---|
174 | #if 0
|
---|
175 | /**
|
---|
176 | * @brief Samba data directory.
|
---|
177 | *
|
---|
178 | * @sa data_path() to get the path to a file inside the CODEPAGEDIR.
|
---|
179 | **/
|
---|
180 | static char *dyn_CODEPAGEDIR;
|
---|
181 |
|
---|
182 | const char *get_dyn_CODEPAGEDIR(void)
|
---|
183 | {
|
---|
184 | if (dyn_CODEPAGEDIR == NULL) {
|
---|
185 | return CODEPAGEDIR;
|
---|
186 | }
|
---|
187 | return dyn_CODEPAGEDIR;
|
---|
188 | }
|
---|
189 |
|
---|
190 | const char *set_dyn_CODEPAGEDIR(const char *newpath)
|
---|
191 | {
|
---|
192 | if (dyn_CODEPAGEDIR) {
|
---|
193 | SAFE_FREE(dyn_CODEPAGEDIR);
|
---|
194 | }
|
---|
195 | dyn_CODEPAGEDIR = SMB_STRDUP(newpath);
|
---|
196 | return dyn_CODEPAGEDIR;
|
---|
197 | }
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * @brief Samba library directory.
|
---|
201 | *
|
---|
202 | * @sa lib_path() to get the path to a file inside the LIBDIR.
|
---|
203 | **/
|
---|
204 | static char *dyn_LIBDIR;
|
---|
205 |
|
---|
206 | const char *get_dyn_LIBDIR(void)
|
---|
207 | {
|
---|
208 | if (dyn_LIBDIR == NULL) {
|
---|
209 | return LIBDIR;
|
---|
210 | }
|
---|
211 | return dyn_CODEPAGEDIR;
|
---|
212 | }
|
---|
213 |
|
---|
214 | const char *set_dyn_LIBDIR(const char *newpath)
|
---|
215 | {
|
---|
216 | if (dyn_LIBDIR) {
|
---|
217 | SAFE_FREE(dyn_LIBDIR);
|
---|
218 | }
|
---|
219 | dyn_LIBDIR = SMB_STRDUP(newpath);
|
---|
220 | return dyn_LIBDIR;
|
---|
221 | }
|
---|
222 |
|
---|
223 | static char *dyn_SHLIBEXT;
|
---|
224 |
|
---|
225 | const char *get_dyn_SHLIBEXT(void)
|
---|
226 | {
|
---|
227 | if (dyn_SHLIBEXT == NULL) {
|
---|
228 | return SHLIBEXT;
|
---|
229 | }
|
---|
230 | return dyn_SHLIBEXT;
|
---|
231 | }
|
---|
232 |
|
---|
233 | const char *set_dyn_SHLIBEXT(const char *newpath)
|
---|
234 | {
|
---|
235 | if (dyn_SHLIBEXT) {
|
---|
236 | SAFE_FREE(dyn_SHLIBEXT);
|
---|
237 | }
|
---|
238 | dyn_SHLIBEXT = SMB_STRDUP(newpath);
|
---|
239 | return dyn_SHLIBEXT;
|
---|
240 | }
|
---|
241 | #endif /* #if 0 */
|
---|
242 | #ifdef __OS2__
|
---|
243 | /**
|
---|
244 | * @brief Directory holding lock files.
|
---|
245 | *
|
---|
246 | * Not writable, but used to set a default in the parameter table.
|
---|
247 | **/
|
---|
248 |
|
---|
249 | static char *dyn_LOCKDIR;
|
---|
250 |
|
---|
251 | const char *get_dyn_LOCKDIR(void)
|
---|
252 | {
|
---|
253 | static char buffer[1024] = "";
|
---|
254 | if (!*buffer)
|
---|
255 | {
|
---|
256 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
---|
257 | }
|
---|
258 | if (dyn_LOCKDIR == NULL) {
|
---|
259 | return buffer;
|
---|
260 | }
|
---|
261 | return dyn_LOCKDIR;
|
---|
262 | }
|
---|
263 |
|
---|
264 | const char *set_dyn_LOCKDIR(const char *newpath)
|
---|
265 | {
|
---|
266 | if (dyn_LOCKDIR) {
|
---|
267 | SAFE_FREE(dyn_LOCKDIR);
|
---|
268 | }
|
---|
269 | dyn_LOCKDIR = SMB_STRDUP(newpath);
|
---|
270 | return dyn_LOCKDIR;
|
---|
271 | }
|
---|
272 |
|
---|
273 | static char *dyn_PIDDIR;
|
---|
274 |
|
---|
275 | const char *get_dyn_PIDDIR(void)
|
---|
276 | {
|
---|
277 | static char buffer[1024] = "";
|
---|
278 | if (!*buffer)
|
---|
279 | {
|
---|
280 | snprintf(buffer, 260, "%s/samba/pid", getenv("ETC"));
|
---|
281 | }
|
---|
282 | if (dyn_PIDDIR == NULL) {
|
---|
283 | return buffer;
|
---|
284 | }
|
---|
285 | return dyn_PIDDIR;
|
---|
286 | }
|
---|
287 |
|
---|
288 | const char *set_dyn_PIDDIR(const char *newpath)
|
---|
289 | {
|
---|
290 | if (dyn_PIDDIR) {
|
---|
291 | SAFE_FREE(dyn_PIDDIR);
|
---|
292 | }
|
---|
293 | dyn_PIDDIR = SMB_STRDUP(newpath);
|
---|
294 | return dyn_PIDDIR;
|
---|
295 | }
|
---|
296 |
|
---|
297 | static char *dyn_SMB_PASSWD_FILE;
|
---|
298 |
|
---|
299 | const char *get_dyn_SMB_PASSWD_FILE(void)
|
---|
300 | {
|
---|
301 | static char buffer[1024] = "";
|
---|
302 | if (!*buffer)
|
---|
303 | {
|
---|
304 | snprintf(buffer, 260, "%s/samba/private/smbpasswd", getenv("ETC"));
|
---|
305 | }
|
---|
306 | if (dyn_SMB_PASSWD_FILE == NULL) {
|
---|
307 | return buffer;
|
---|
308 | }
|
---|
309 | return dyn_SMB_PASSWD_FILE;
|
---|
310 | }
|
---|
311 |
|
---|
312 | const char *set_dyn_SMB_PASSWD_FILE(const char *newpath)
|
---|
313 | {
|
---|
314 | if (dyn_SMB_PASSWD_FILE) {
|
---|
315 | SAFE_FREE(dyn_SMB_PASSWD_FILE);
|
---|
316 | }
|
---|
317 | dyn_SMB_PASSWD_FILE = SMB_STRDUP(newpath);
|
---|
318 | return dyn_SMB_PASSWD_FILE;
|
---|
319 | }
|
---|
320 |
|
---|
321 | static char *dyn_PRIVATE_DIR;
|
---|
322 |
|
---|
323 | const char *get_dyn_PRIVATE_DIR(void)
|
---|
324 | {
|
---|
325 | static char buffer[1024] = "";
|
---|
326 | if (!*buffer)
|
---|
327 | {
|
---|
328 | snprintf(buffer, 260, "%s/samba/private", getenv("ETC"));
|
---|
329 | }
|
---|
330 | if (dyn_PRIVATE_DIR == NULL) {
|
---|
331 | return buffer;
|
---|
332 | }
|
---|
333 | return dyn_PRIVATE_DIR;
|
---|
334 | }
|
---|
335 |
|
---|
336 | const char *set_dyn_PRIVATE_DIR(const char *newpath)
|
---|
337 | {
|
---|
338 | if (dyn_PRIVATE_DIR) {
|
---|
339 | SAFE_FREE(dyn_PRIVATE_DIR);
|
---|
340 | }
|
---|
341 | dyn_PRIVATE_DIR = SMB_STRDUP(newpath);
|
---|
342 | return dyn_PRIVATE_DIR;
|
---|
343 | }
|
---|
344 | #endif
|
---|
345 |
|
---|
346 | /* In non-FHS mode, these should be configurable using 'lock dir =';
|
---|
347 | but in FHS mode, they are their own directory. Implement as wrapper
|
---|
348 | functions so that everything can still be kept in dynconfig.c.
|
---|
349 | */
|
---|
350 |
|
---|
351 | const char *get_dyn_STATEDIR(void)
|
---|
352 | {
|
---|
353 | #ifdef FHS_COMPATIBLE
|
---|
354 | return STATEDIR;
|
---|
355 | #else
|
---|
356 | return lp_lockdir();
|
---|
357 | #endif
|
---|
358 | }
|
---|
359 |
|
---|
360 | const char *get_dyn_CACHEDIR(void)
|
---|
361 | {
|
---|
362 | #ifdef FHS_COMPATIBLE
|
---|
363 | return CACHEDIR;
|
---|
364 | #else
|
---|
365 | return lp_lockdir();
|
---|
366 | #endif
|
---|
367 | }
|
---|