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