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(NCALRPCDIR)
|
---|
102 | DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
|
---|
103 | DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
|
---|
104 |
|
---|
105 | #ifdef __OS2__
|
---|
106 |
|
---|
107 | /* Directory the binary was called from, same as getbindir() */
|
---|
108 | const char *get_dyn_SBINDIR(void)
|
---|
109 | {
|
---|
110 | static char buffer[1024] = "";
|
---|
111 | if (!*buffer)
|
---|
112 | {
|
---|
113 | char exedir[1024] = "";
|
---|
114 | if (!os2_GetExePath(exedir))
|
---|
115 | {
|
---|
116 | snprintf(buffer, 260, "%s", SBINDIR);
|
---|
117 | } else {
|
---|
118 | snprintf(buffer, 260, "%s", exedir);
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | if (dyn_SBINDIR == NULL) {
|
---|
123 | return buffer;
|
---|
124 | }
|
---|
125 | return dyn_SBINDIR;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /* Directory the binary was called from, same as getsbindir() */
|
---|
129 | const char *get_dyn_BINDIR(void)
|
---|
130 | {
|
---|
131 | static char buffer[1024] = "";
|
---|
132 | if (!*buffer)
|
---|
133 | {
|
---|
134 | char exedir[1024] = "";
|
---|
135 | if (!os2_GetExePath(exedir))
|
---|
136 | {
|
---|
137 | snprintf(buffer, 260, "%s", BINDIR);
|
---|
138 | } else {
|
---|
139 | snprintf(buffer, 260, "%s", exedir);
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (dyn_BINDIR == NULL) {
|
---|
144 | return buffer;
|
---|
145 | }
|
---|
146 | return dyn_BINDIR;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /* Directory holding the SWAT files */
|
---|
150 | const char *get_dyn_SWATDIR(void)
|
---|
151 | {
|
---|
152 | static char buffer[1024] = "";
|
---|
153 | if (!*buffer)
|
---|
154 | {
|
---|
155 | char exedir[1024] = "";
|
---|
156 | if (!os2_GetExePath(exedir))
|
---|
157 | {
|
---|
158 | snprintf(buffer, 260, "%s", SWATDIR);
|
---|
159 | } else {
|
---|
160 | snprintf(buffer, 260, "%s/%s", exedir,"swat");
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | if (dyn_SWATDIR == NULL) {
|
---|
165 | return buffer;
|
---|
166 | }
|
---|
167 | return dyn_SWATDIR;
|
---|
168 | }
|
---|
169 |
|
---|
170 | /* Location of smb.conf file. */
|
---|
171 | const char *get_dyn_CONFIGFILE(void)
|
---|
172 | {
|
---|
173 | static char buffer[1024] = "";
|
---|
174 | if (!*buffer)
|
---|
175 | {
|
---|
176 | snprintf(buffer, 260, "%s/samba/smb.conf", getenv("ETC"));
|
---|
177 | }
|
---|
178 | /* Set UNIXROOT to x:\MPTN if UNIXROOT is undefined */
|
---|
179 | if (getenv("UNIXROOT") == NULL) {
|
---|
180 | static char unixroot[1024] = "";
|
---|
181 | strncpy(unixroot,getenv("ETC"),strlen(getenv("ETC"))-4);
|
---|
182 | setenv("UNIXROOT",unixroot,0);
|
---|
183 | }
|
---|
184 | /* Make sure TMPIR points to a proper value */
|
---|
185 | static char tmpdir[1024] = "";
|
---|
186 | if (getenv("TMPDIR") == NULL && getenv("TEMP") != NULL) {
|
---|
187 | strncpy(tmpdir,getenv("TEMP"),strlen(getenv("TEMP")));
|
---|
188 | setenv("TMPDIR",tmpdir,0);
|
---|
189 | }
|
---|
190 | if (getenv("TMPDIR") == NULL) {
|
---|
191 | strncpy(tmpdir,getenv("ETC"),2);
|
---|
192 | stpcpy(tmpdir,"/OS2/SYSTEM");
|
---|
193 | setenv("TMPDIR",tmpdir,0);
|
---|
194 | }
|
---|
195 |
|
---|
196 | if (dyn_CONFIGFILE == NULL) {
|
---|
197 | return buffer;
|
---|
198 | }
|
---|
199 | return dyn_CONFIGFILE;
|
---|
200 | }
|
---|
201 |
|
---|
202 | /** Log file directory. **/
|
---|
203 | const char *get_dyn_LOGFILEBASE(void)
|
---|
204 | {
|
---|
205 | static char buffer[1024] = "";
|
---|
206 | if (!*buffer)
|
---|
207 | {
|
---|
208 | snprintf(buffer, 260, "%s/samba/log", getenv("ETC"));
|
---|
209 | }
|
---|
210 | if (dyn_LOGFILEBASE == NULL) {
|
---|
211 | return buffer;
|
---|
212 | }
|
---|
213 | return dyn_LOGFILEBASE;
|
---|
214 | }
|
---|
215 |
|
---|
216 | /** Statically configured LanMan hosts. **/
|
---|
217 | const char *get_dyn_LMHOSTSFILE(void)
|
---|
218 | {
|
---|
219 | static char buffer[1024] = "";
|
---|
220 | if (!*buffer)
|
---|
221 | {
|
---|
222 | snprintf(buffer, 260, "%s/samba/lmhosts", getenv("ETC"));
|
---|
223 | }
|
---|
224 | if (dyn_LMHOSTSFILE == NULL) {
|
---|
225 | return buffer;
|
---|
226 | }
|
---|
227 | return dyn_LMHOSTSFILE;
|
---|
228 | }
|
---|
229 |
|
---|
230 | /* Directory holding the codepages */
|
---|
231 | const char *get_dyn_CODEPAGEDIR(void)
|
---|
232 | {
|
---|
233 | static char buffer[1024] = "";
|
---|
234 | if (!*buffer)
|
---|
235 | {
|
---|
236 | char exedir[1024] = "";
|
---|
237 | if (!os2_GetExePath(exedir))
|
---|
238 | {
|
---|
239 | snprintf(buffer, 260, "%s", CODEPAGEDIR);
|
---|
240 | } else {
|
---|
241 | if (!lp_is_in_client()) {
|
---|
242 | snprintf(buffer, 260, "%s/%s", exedir, "codepages");
|
---|
243 | } else {
|
---|
244 | snprintf(buffer, 260, "%s/%s", getenv("SMB_EXE"), "codepages");
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | if (dyn_CODEPAGEDIR == NULL) {
|
---|
250 | return buffer;
|
---|
251 | }
|
---|
252 | return dyn_CODEPAGEDIR;
|
---|
253 | }
|
---|
254 |
|
---|
255 | /* Directory holding the libs */
|
---|
256 | const char *get_dyn_LIBDIR(void)
|
---|
257 | {
|
---|
258 | static char buffer[1024] = "";
|
---|
259 | if (!*buffer)
|
---|
260 | {
|
---|
261 | char exedir[1024] = "";
|
---|
262 | if (!os2_GetExePath(exedir))
|
---|
263 | {
|
---|
264 | snprintf(buffer, 260, "%s", LIBDIR);
|
---|
265 | } else {
|
---|
266 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | if (dyn_LIBDIR == NULL) {
|
---|
271 | return buffer;
|
---|
272 | }
|
---|
273 | return dyn_LIBDIR;
|
---|
274 | }
|
---|
275 |
|
---|
276 | /* Directory holding the modules */
|
---|
277 | const char *get_dyn_MODULESDIR(void)
|
---|
278 | {
|
---|
279 | static char buffer[1024] = "";
|
---|
280 | if (!*buffer)
|
---|
281 | {
|
---|
282 | char exedir[1024] = "";
|
---|
283 | if (!os2_GetExePath(exedir))
|
---|
284 | {
|
---|
285 | snprintf(buffer, 260, "%s", MODULESDIR);
|
---|
286 | } else {
|
---|
287 | snprintf(buffer, 260, "%s/%s", exedir, "modules");
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | if (dyn_MODULESDIR == NULL) {
|
---|
292 | return buffer;
|
---|
293 | }
|
---|
294 | return dyn_MODULESDIR;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /* Directory holding lock files */
|
---|
298 | const char *get_dyn_LOCKDIR(void)
|
---|
299 | {
|
---|
300 | static char buffer[1024] = "";
|
---|
301 | if (!*buffer)
|
---|
302 | {
|
---|
303 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
---|
304 | }
|
---|
305 | if (dyn_LOCKDIR == NULL) {
|
---|
306 | return buffer;
|
---|
307 | }
|
---|
308 | return dyn_LOCKDIR;
|
---|
309 | }
|
---|
310 |
|
---|
311 | /* Directory holding the pid files */
|
---|
312 | const char *get_dyn_PIDDIR(void)
|
---|
313 | {
|
---|
314 | static char buffer[1024] = "";
|
---|
315 | if (!*buffer)
|
---|
316 | {
|
---|
317 | snprintf(buffer, 260, "%s/samba/pid", getenv("ETC"));
|
---|
318 | }
|
---|
319 | if (dyn_PIDDIR == NULL) {
|
---|
320 | return buffer;
|
---|
321 | }
|
---|
322 | return dyn_PIDDIR;
|
---|
323 | }
|
---|
324 |
|
---|
325 | /* Location of smbpasswd */
|
---|
326 | const char *get_dyn_SMB_PASSWD_FILE(void)
|
---|
327 | {
|
---|
328 | static char buffer[1024] = "";
|
---|
329 | if (!*buffer)
|
---|
330 | {
|
---|
331 | snprintf(buffer, 260, "%s/samba/private/smbpasswd", getenv("ETC"));
|
---|
332 | }
|
---|
333 | if (dyn_SMB_PASSWD_FILE == NULL) {
|
---|
334 | return buffer;
|
---|
335 | }
|
---|
336 | return dyn_SMB_PASSWD_FILE;
|
---|
337 | }
|
---|
338 |
|
---|
339 | /* Directory holding the private files */
|
---|
340 | const char *get_dyn_PRIVATE_DIR(void)
|
---|
341 | {
|
---|
342 | static char buffer[1024] = "";
|
---|
343 | if (!*buffer)
|
---|
344 | {
|
---|
345 | snprintf(buffer, 260, "%s/samba/private", getenv("ETC"));
|
---|
346 | }
|
---|
347 | if (dyn_PRIVATE_DIR == NULL) {
|
---|
348 | return buffer;
|
---|
349 | }
|
---|
350 | return dyn_PRIVATE_DIR;
|
---|
351 | }
|
---|
352 |
|
---|
353 | /* Directory holding the shared libs (same as libdir) */
|
---|
354 | const char *get_dyn_SHLIBEXT(void)
|
---|
355 | {
|
---|
356 | static char buffer[1024] = "";
|
---|
357 | if (!*buffer)
|
---|
358 | {
|
---|
359 | char exedir[1024] = "";
|
---|
360 | if (!os2_GetExePath(exedir))
|
---|
361 | {
|
---|
362 | snprintf(buffer, 260, "%s", LIBDIR);
|
---|
363 | } else {
|
---|
364 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
365 | }
|
---|
366 | }
|
---|
367 |
|
---|
368 | if (dyn_SHLIBEXT == NULL) {
|
---|
369 | return buffer;
|
---|
370 | }
|
---|
371 | return dyn_SHLIBEXT;
|
---|
372 | }
|
---|
373 |
|
---|
374 | /* Directory holding the NCALRPCDIR (whatever that is) */
|
---|
375 | const char *get_dyn_NCALRPCDIR(void)
|
---|
376 | {
|
---|
377 | static char buffer[1024] = "";
|
---|
378 | if (!*buffer)
|
---|
379 | {
|
---|
380 | char exedir[1024] = "";
|
---|
381 | if (!os2_GetExePath(exedir))
|
---|
382 | {
|
---|
383 | snprintf(buffer, 260, "%s", NCALRPCDIR);
|
---|
384 | } else {
|
---|
385 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | if (dyn_NCALRPCDIR == NULL) {
|
---|
390 | return buffer;
|
---|
391 | }
|
---|
392 | return dyn_NCALRPCDIR;
|
---|
393 | }
|
---|
394 |
|
---|
395 | #endif /* __OS2__ */
|
---|
396 |
|
---|
397 | /* In non-FHS mode, these should be configurable using 'lock dir =';
|
---|
398 | but in FHS mode, they are their own directory. Implement as wrapper
|
---|
399 | functions so that everything can still be kept in dynconfig.c.
|
---|
400 | */
|
---|
401 |
|
---|
402 | const char *get_dyn_STATEDIR(void)
|
---|
403 | {
|
---|
404 | #ifdef FHS_COMPATIBLE
|
---|
405 | return STATEDIR;
|
---|
406 | #else
|
---|
407 | return lp_lockdir();
|
---|
408 | #endif
|
---|
409 | }
|
---|
410 |
|
---|
411 | const char *get_dyn_CACHEDIR(void)
|
---|
412 | {
|
---|
413 | #ifdef FHS_COMPATIBLE
|
---|
414 | return CACHEDIR;
|
---|
415 | #else
|
---|
416 | return lp_lockdir();
|
---|
417 | #endif
|
---|
418 | }
|
---|