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 | #ifndef __OS2__
|
---|
44 | #define DEFINE_DYN_CONFIG_PARAM(name) \
|
---|
45 | static char *dyn_##name; \
|
---|
46 | \
|
---|
47 | const char *get_dyn_##name(void) \
|
---|
48 | {\
|
---|
49 | if (dyn_##name == NULL) {\
|
---|
50 | return name;\
|
---|
51 | }\
|
---|
52 | return dyn_##name;\
|
---|
53 | }\
|
---|
54 | \
|
---|
55 | const char *set_dyn_##name(const char *newpath) \
|
---|
56 | {\
|
---|
57 | if (dyn_##name) {\
|
---|
58 | SAFE_FREE(dyn_##name);\
|
---|
59 | }\
|
---|
60 | dyn_##name = SMB_STRDUP(newpath);\
|
---|
61 | return dyn_##name;\
|
---|
62 | }\
|
---|
63 | \
|
---|
64 | bool is_default_dyn_##name(void) \
|
---|
65 | {\
|
---|
66 | return (dyn_##name == NULL);\
|
---|
67 | }
|
---|
68 | #else
|
---|
69 | #define DEFINE_DYN_CONFIG_PARAM(name) \
|
---|
70 | static char *dyn_##name; \
|
---|
71 | \
|
---|
72 | const char *set_dyn_##name(const char *newpath) \
|
---|
73 | {\
|
---|
74 | if (dyn_##name) {\
|
---|
75 | SAFE_FREE(dyn_##name);\
|
---|
76 | }\
|
---|
77 | dyn_##name = SMB_STRDUP(newpath);\
|
---|
78 | return dyn_##name;\
|
---|
79 | }\
|
---|
80 | \
|
---|
81 | bool is_default_dyn_##name(void) \
|
---|
82 | {\
|
---|
83 | return (dyn_##name == NULL);\
|
---|
84 | }
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | DEFINE_DYN_CONFIG_PARAM(SBINDIR)
|
---|
88 | DEFINE_DYN_CONFIG_PARAM(BINDIR)
|
---|
89 | DEFINE_DYN_CONFIG_PARAM(SWATDIR)
|
---|
90 | DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
|
---|
91 | DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
|
---|
92 | DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
|
---|
93 | DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
|
---|
94 | DEFINE_DYN_CONFIG_PARAM(LIBDIR)
|
---|
95 | DEFINE_DYN_CONFIG_PARAM(MODULESDIR)
|
---|
96 | DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
|
---|
97 | DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
|
---|
98 | DEFINE_DYN_CONFIG_PARAM(STATEDIR) /** Persistent state files. Default LOCKDIR */
|
---|
99 | DEFINE_DYN_CONFIG_PARAM(CACHEDIR) /** Temporary cache files. Default LOCKDIR */
|
---|
100 | DEFINE_DYN_CONFIG_PARAM(PIDDIR)
|
---|
101 | DEFINE_DYN_CONFIG_PARAM(NMBDSOCKETDIR)
|
---|
102 | DEFINE_DYN_CONFIG_PARAM(NCALRPCDIR)
|
---|
103 | DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
|
---|
104 | DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
|
---|
105 | DEFINE_DYN_CONFIG_PARAM(LOCALEDIR)
|
---|
106 |
|
---|
107 | #ifdef __OS2__
|
---|
108 | // @todo change this file so it also works for rpm
|
---|
109 | // @todo see what NMBDSOCKETDIR & LOCALEDIR are used for
|
---|
110 |
|
---|
111 | /* Directory the binary was called from, same as getbindir() */
|
---|
112 | const char *get_dyn_SBINDIR(void)
|
---|
113 | {
|
---|
114 | static char buffer[1024] = "";
|
---|
115 | if (!*buffer)
|
---|
116 | {
|
---|
117 | char exedir[1024] = "";
|
---|
118 | if (!os2_GetExePath(exedir))
|
---|
119 | {
|
---|
120 | snprintf(buffer, 260, "%s", SBINDIR);
|
---|
121 | } else {
|
---|
122 | snprintf(buffer, 260, "%s", exedir);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (dyn_SBINDIR == NULL) {
|
---|
127 | return buffer;
|
---|
128 | }
|
---|
129 | return dyn_SBINDIR;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* Directory the binary was called from, same as getsbindir() */
|
---|
133 | const char *get_dyn_BINDIR(void)
|
---|
134 | {
|
---|
135 | static char buffer[1024] = "";
|
---|
136 | if (!*buffer)
|
---|
137 | {
|
---|
138 | char exedir[1024] = "";
|
---|
139 | if (!os2_GetExePath(exedir))
|
---|
140 | {
|
---|
141 | snprintf(buffer, 260, "%s", BINDIR);
|
---|
142 | } else {
|
---|
143 | snprintf(buffer, 260, "%s", exedir);
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | if (dyn_BINDIR == NULL) {
|
---|
148 | return buffer;
|
---|
149 | }
|
---|
150 | return dyn_BINDIR;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /* Directory holding the SWAT files */
|
---|
154 | const char *get_dyn_SWATDIR(void)
|
---|
155 | {
|
---|
156 | static char buffer[1024] = "";
|
---|
157 | if (!*buffer)
|
---|
158 | {
|
---|
159 | char exedir[1024] = "";
|
---|
160 | if (!os2_GetExePath(exedir))
|
---|
161 | {
|
---|
162 | snprintf(buffer, 260, "%s", SWATDIR);
|
---|
163 | } else {
|
---|
164 | snprintf(buffer, 260, "%s/%s", exedir,"swat");
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | if (dyn_SWATDIR == NULL) {
|
---|
169 | return buffer;
|
---|
170 | }
|
---|
171 | return dyn_SWATDIR;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /* Location of smb.conf file. */
|
---|
175 | const char *get_dyn_CONFIGFILE(void)
|
---|
176 | {
|
---|
177 | static char buffer[1024] = "";
|
---|
178 | if (!*buffer)
|
---|
179 | {
|
---|
180 | snprintf(buffer, 260, "%s/samba/smb.conf", getenv("ETC"));
|
---|
181 | }
|
---|
182 | /* Set UNIXROOT to x:\MPTN if UNIXROOT is undefined */
|
---|
183 | if (getenv("UNIXROOT") == NULL) {
|
---|
184 | static char unixroot[1024] = "";
|
---|
185 | strncpy(unixroot,getenv("ETC"),strlen(getenv("ETC"))-4);
|
---|
186 | setenv("UNIXROOT",unixroot,0);
|
---|
187 | }
|
---|
188 | /* Make sure TMPIR points to a proper value */
|
---|
189 | static char tmpdir[1024] = "";
|
---|
190 | if (getenv("TMPDIR") == NULL && getenv("TEMP") != NULL) {
|
---|
191 | strncpy(tmpdir,getenv("TEMP"),strlen(getenv("TEMP")));
|
---|
192 | setenv("TMPDIR",tmpdir,0);
|
---|
193 | }
|
---|
194 | if (getenv("TMPDIR") == NULL) {
|
---|
195 | strncpy(tmpdir,getenv("ETC"),2);
|
---|
196 | stpcpy(tmpdir,"/OS2/SYSTEM");
|
---|
197 | setenv("TMPDIR",tmpdir,0);
|
---|
198 | }
|
---|
199 |
|
---|
200 | if (dyn_CONFIGFILE == NULL) {
|
---|
201 | return buffer;
|
---|
202 | }
|
---|
203 | return dyn_CONFIGFILE;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /** Log file directory. **/
|
---|
207 | const char *get_dyn_LOGFILEBASE(void)
|
---|
208 | {
|
---|
209 | static char buffer[1024] = "";
|
---|
210 | if (!*buffer)
|
---|
211 | {
|
---|
212 | snprintf(buffer, 260, "%s/samba/log", getenv("ETC"));
|
---|
213 | }
|
---|
214 | if (dyn_LOGFILEBASE == NULL) {
|
---|
215 | return buffer;
|
---|
216 | }
|
---|
217 | return dyn_LOGFILEBASE;
|
---|
218 | }
|
---|
219 |
|
---|
220 | /** Statically configured LanMan hosts. **/
|
---|
221 | const char *get_dyn_LMHOSTSFILE(void)
|
---|
222 | {
|
---|
223 | static char buffer[1024] = "";
|
---|
224 | if (!*buffer)
|
---|
225 | {
|
---|
226 | snprintf(buffer, 260, "%s/samba/lmhosts", getenv("ETC"));
|
---|
227 | }
|
---|
228 | if (dyn_LMHOSTSFILE == NULL) {
|
---|
229 | return buffer;
|
---|
230 | }
|
---|
231 | return dyn_LMHOSTSFILE;
|
---|
232 | }
|
---|
233 |
|
---|
234 | /* Directory holding the codepages */
|
---|
235 | const char *get_dyn_CODEPAGEDIR(void)
|
---|
236 | {
|
---|
237 | static char buffer[1024] = "";
|
---|
238 | if (!*buffer)
|
---|
239 | {
|
---|
240 | char exedir[1024] = "";
|
---|
241 | if (!os2_GetExePath(exedir))
|
---|
242 | {
|
---|
243 | snprintf(buffer, 260, "%s", CODEPAGEDIR);
|
---|
244 | } else {
|
---|
245 | if (!lp_is_in_client()) {
|
---|
246 | snprintf(buffer, 260, "%s/%s", exedir, "codepages");
|
---|
247 | } else {
|
---|
248 | snprintf(buffer, 260, "%s/%s", getenv("SMB_EXE"), "codepages");
|
---|
249 | }
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | if (dyn_CODEPAGEDIR == NULL) {
|
---|
254 | return buffer;
|
---|
255 | }
|
---|
256 | return dyn_CODEPAGEDIR;
|
---|
257 | }
|
---|
258 |
|
---|
259 | /* Directory holding the libs */
|
---|
260 | const char *get_dyn_LIBDIR(void)
|
---|
261 | {
|
---|
262 | static char buffer[1024] = "";
|
---|
263 | if (!*buffer)
|
---|
264 | {
|
---|
265 | char exedir[1024] = "";
|
---|
266 | if (!os2_GetExePath(exedir))
|
---|
267 | {
|
---|
268 | snprintf(buffer, 260, "%s", LIBDIR);
|
---|
269 | } else {
|
---|
270 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | if (dyn_LIBDIR == NULL) {
|
---|
275 | return buffer;
|
---|
276 | }
|
---|
277 | return dyn_LIBDIR;
|
---|
278 | }
|
---|
279 |
|
---|
280 | /* Directory holding the modules */
|
---|
281 | const char *get_dyn_MODULESDIR(void)
|
---|
282 | {
|
---|
283 | static char buffer[1024] = "";
|
---|
284 | if (!*buffer)
|
---|
285 | {
|
---|
286 | char exedir[1024] = "";
|
---|
287 | if (!os2_GetExePath(exedir))
|
---|
288 | {
|
---|
289 | snprintf(buffer, 260, "%s", MODULESDIR);
|
---|
290 | } else {
|
---|
291 | snprintf(buffer, 260, "%s/%s", exedir, "modules");
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | if (dyn_MODULESDIR == NULL) {
|
---|
296 | return buffer;
|
---|
297 | }
|
---|
298 | return dyn_MODULESDIR;
|
---|
299 | }
|
---|
300 |
|
---|
301 | /* Directory holding the shared libs (same as libdir) */
|
---|
302 | const char *get_dyn_SHLIBEXT(void)
|
---|
303 | {
|
---|
304 | static char buffer[1024] = "";
|
---|
305 | if (!*buffer)
|
---|
306 | {
|
---|
307 | char exedir[1024] = "";
|
---|
308 | if (!os2_GetExePath(exedir))
|
---|
309 | {
|
---|
310 | snprintf(buffer, 260, "%s", LIBDIR);
|
---|
311 | } else {
|
---|
312 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | if (dyn_SHLIBEXT == NULL) {
|
---|
317 | return buffer;
|
---|
318 | }
|
---|
319 | return dyn_SHLIBEXT;
|
---|
320 | }
|
---|
321 |
|
---|
322 | /* Directory holding lock files */
|
---|
323 | const char *get_dyn_LOCKDIR(void)
|
---|
324 | {
|
---|
325 | static char buffer[1024] = "";
|
---|
326 | if (!*buffer)
|
---|
327 | {
|
---|
328 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
---|
329 | }
|
---|
330 | if (dyn_LOCKDIR == NULL) {
|
---|
331 | return buffer;
|
---|
332 | }
|
---|
333 | return dyn_LOCKDIR;
|
---|
334 | }
|
---|
335 |
|
---|
336 | /* Directory holding persistent state files */
|
---|
337 | const char *get_dyn_STATEDIR(void)
|
---|
338 | {
|
---|
339 | static char buffer[1024] = "";
|
---|
340 | if (!*buffer)
|
---|
341 | {
|
---|
342 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
---|
343 | }
|
---|
344 | if (dyn_STATEDIR == NULL) {
|
---|
345 | return buffer;
|
---|
346 | }
|
---|
347 | return dyn_STATEDIR;
|
---|
348 | }
|
---|
349 |
|
---|
350 | /* Temporary cache files. Default LOCKDIR */
|
---|
351 | const char *get_dyn_CACHEDIR(void)
|
---|
352 | {
|
---|
353 | static char buffer[1024] = "";
|
---|
354 | if (!*buffer)
|
---|
355 | {
|
---|
356 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
---|
357 | }
|
---|
358 | if (dyn_CACHEDIR == NULL) {
|
---|
359 | return buffer;
|
---|
360 | }
|
---|
361 | return dyn_CACHEDIR;
|
---|
362 | }
|
---|
363 |
|
---|
364 | /* Directory holding the pid files */
|
---|
365 | const char *get_dyn_PIDDIR(void)
|
---|
366 | {
|
---|
367 | static char buffer[1024] = "";
|
---|
368 | if (!*buffer)
|
---|
369 | {
|
---|
370 | snprintf(buffer, 260, "%s/samba/pid", getenv("ETC"));
|
---|
371 | }
|
---|
372 | if (dyn_PIDDIR == NULL) {
|
---|
373 | return buffer;
|
---|
374 | }
|
---|
375 | return dyn_PIDDIR;
|
---|
376 | }
|
---|
377 |
|
---|
378 | /* Directory holding the NMBDSOCKETDIR (whatever that is) */
|
---|
379 | const char *get_dyn_NMBDSOCKETDIR(void)
|
---|
380 | {
|
---|
381 | static char buffer[1024] = "";
|
---|
382 | if (!*buffer)
|
---|
383 | {
|
---|
384 | char exedir[1024] = "";
|
---|
385 | if (!os2_GetExePath(exedir))
|
---|
386 | {
|
---|
387 | snprintf(buffer, 260, "%s", NMBDSOCKETDIR);
|
---|
388 | } else {
|
---|
389 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
390 | }
|
---|
391 | }
|
---|
392 |
|
---|
393 | if (dyn_NMBDSOCKETDIR == NULL) {
|
---|
394 | return buffer;
|
---|
395 | }
|
---|
396 | return dyn_NMBDSOCKETDIR;
|
---|
397 | }
|
---|
398 |
|
---|
399 | /* Directory holding the LOCALEDIR (whatever that is) */
|
---|
400 | const char *get_dyn_LOCALEDIR(void)
|
---|
401 | {
|
---|
402 | static char buffer[1024] = "";
|
---|
403 | if (!*buffer)
|
---|
404 | {
|
---|
405 | char exedir[1024] = "";
|
---|
406 | if (!os2_GetExePath(exedir))
|
---|
407 | {
|
---|
408 | snprintf(buffer, 260, "%s", LOCALEDIR);
|
---|
409 | } else {
|
---|
410 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
411 | }
|
---|
412 | }
|
---|
413 |
|
---|
414 | if (dyn_LOCALEDIR == NULL) {
|
---|
415 | return buffer;
|
---|
416 | }
|
---|
417 | return dyn_LOCALEDIR;
|
---|
418 | }
|
---|
419 |
|
---|
420 | /* Directory holding the NCALRPCDIR (whatever that is) */
|
---|
421 | const char *get_dyn_NCALRPCDIR(void)
|
---|
422 | {
|
---|
423 | static char buffer[1024] = "";
|
---|
424 | if (!*buffer)
|
---|
425 | {
|
---|
426 | char exedir[1024] = "";
|
---|
427 | if (!os2_GetExePath(exedir))
|
---|
428 | {
|
---|
429 | snprintf(buffer, 260, "%s", NCALRPCDIR);
|
---|
430 | } else {
|
---|
431 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | if (dyn_NCALRPCDIR == NULL) {
|
---|
436 | return buffer;
|
---|
437 | }
|
---|
438 | return dyn_NCALRPCDIR;
|
---|
439 | }
|
---|
440 |
|
---|
441 | /* Location of smbpasswd */
|
---|
442 | const char *get_dyn_SMB_PASSWD_FILE(void)
|
---|
443 | {
|
---|
444 | static char buffer[1024] = "";
|
---|
445 | if (!*buffer)
|
---|
446 | {
|
---|
447 | snprintf(buffer, 260, "%s/samba/private/smbpasswd", getenv("ETC"));
|
---|
448 | }
|
---|
449 | if (dyn_SMB_PASSWD_FILE == NULL) {
|
---|
450 | return buffer;
|
---|
451 | }
|
---|
452 | return dyn_SMB_PASSWD_FILE;
|
---|
453 | }
|
---|
454 |
|
---|
455 | /* Directory holding the private files */
|
---|
456 | const char *get_dyn_PRIVATE_DIR(void)
|
---|
457 | {
|
---|
458 | static char buffer[1024] = "";
|
---|
459 | if (!*buffer)
|
---|
460 | {
|
---|
461 | snprintf(buffer, 260, "%s/samba/private", getenv("ETC"));
|
---|
462 | }
|
---|
463 | if (dyn_PRIVATE_DIR == NULL) {
|
---|
464 | return buffer;
|
---|
465 | }
|
---|
466 | return dyn_PRIVATE_DIR;
|
---|
467 | }
|
---|
468 |
|
---|
469 | #endif /* __OS2__ */
|
---|