source: branches/samba-3.3.x/source/dynconfig.c@ 472

Last change on this file since 472 was 372, checked in by Silvan Scherrer, 16 years ago

remove hardcoded path, remove some files

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