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

Last change on this file since 338 was 309, checked in by Herwig Bauernfeind, 16 years ago

Update 3.3 to 3.3.7

File size: 6.9 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
68DEFINE_DYN_CONFIG_PARAM(SBINDIR)
69DEFINE_DYN_CONFIG_PARAM(BINDIR)
70DEFINE_DYN_CONFIG_PARAM(SWATDIR)
71#ifndef __OS2__
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. **/
75#endif
76DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
77DEFINE_DYN_CONFIG_PARAM(LIBDIR)
78DEFINE_DYN_CONFIG_PARAM(MODULESDIR)
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__
88static char *dyn_CONFIGFILE; /**< Location of smb.conf file. **/
89
90const char *get_dyn_CONFIGFILE(void)
91{
92 static char buffer[1024] = "";
93 if (!*buffer)
94 {
95 snprintf(buffer, 260, "%s/samba/smb.conf", getenv("ETC"));
96 }
97 /* Set UNIXROOT to x:\MPTN if UNIXROOT is undefined */
98 if (getenv("UNIXROOT") == NULL) {
99 static char unixroot[1024] = "";
100 strncpy(unixroot,getenv("ETC"),strlen(getenv("ETC"))-4);
101 setenv("UNIXROOT",unixroot,0);
102 }
103 /* Make sure TMPIR points to a proper value */
104 static char tmpdir[1024] = "";
105 if (getenv("TMPDIR") == NULL && getenv("TEMP") != NULL) {
106 strncpy(tmpdir,getenv("TEMP"),strlen(getenv("TEMP")));
107 setenv("TMPDIR",tmpdir,0);
108 }
109 if (getenv("TMPDIR") == NULL) {
110 strncpy(tmpdir,getenv("ETC"),2);
111 stpcpy(tmpdir,"/OS2/SYSTEM");
112 setenv("TMPDIR",tmpdir,0);
113 }
114
115 if (dyn_CONFIGFILE == NULL) {
116 return buffer;
117 }
118 return dyn_CONFIGFILE;
119}
120
121const char *set_dyn_CONFIGFILE(const char *newpath)
122{
123 if (dyn_CONFIGFILE) {
124 SAFE_FREE(dyn_CONFIGFILE);
125 }
126 dyn_CONFIGFILE = SMB_STRDUP(newpath);
127 return dyn_CONFIGFILE;
128}
129
130 bool is_default_dyn_CONFIGFILE(void) \
131{\
132 return (dyn_CONFIGFILE == NULL);\
133}
134
135/** Log file directory. **/
136static char *dyn_LOGFILEBASE;
137
138const char *get_dyn_LOGFILEBASE(void)
139{
140 static char buffer[1024] = "";
141 if (!*buffer)
142 {
143 snprintf(buffer, 260, "%s/samba/log", getenv("ETC"));
144 }
145 if (dyn_LOGFILEBASE == NULL) {
146 return buffer;
147 }
148 return dyn_LOGFILEBASE;
149}
150
151const char *set_dyn_LOGFILEBASE(const char *newpath)
152{
153 if (dyn_LOGFILEBASE) {
154 SAFE_FREE(dyn_LOGFILEBASE);
155 }
156 dyn_LOGFILEBASE = SMB_STRDUP(newpath);
157 return dyn_LOGFILEBASE;
158}
159
160/** Statically configured LanMan hosts. **/
161static char *dyn_LMHOSTSFILE;
162
163const char *get_dyn_LMHOSTSFILE(void)
164{
165 static char buffer[1024] = "";
166 if (!*buffer)
167 {
168 snprintf(buffer, 260, "%s/samba/lmhosts", getenv("ETC"));
169 }
170 if (dyn_LMHOSTSFILE == NULL) {
171 return buffer;
172 }
173 return dyn_LMHOSTSFILE;
174}
175
176const char *set_dyn_LMHOSTSFILE(const char *newpath)
177{
178 if (dyn_LMHOSTSFILE) {
179 SAFE_FREE(dyn_LMHOSTSFILE);
180 }
181 dyn_LMHOSTSFILE = SMB_STRDUP(newpath);
182 return dyn_LMHOSTSFILE;
183}
184
185/**
186 * @brief Directory holding lock files.
187 *
188 * Not writable, but used to set a default in the parameter table.
189 **/
190
191static char *dyn_LOCKDIR;
192
193const char *get_dyn_LOCKDIR(void)
194{
195 static char buffer[1024] = "";
196 if (!*buffer)
197 {
198 snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
199 }
200 if (dyn_LOCKDIR == NULL) {
201 return buffer;
202 }
203 return dyn_LOCKDIR;
204}
205
206const char *set_dyn_LOCKDIR(const char *newpath)
207{
208 if (dyn_LOCKDIR) {
209 SAFE_FREE(dyn_LOCKDIR);
210 }
211 dyn_LOCKDIR = SMB_STRDUP(newpath);
212 return dyn_LOCKDIR;
213}
214
215static char *dyn_PIDDIR;
216
217const char *get_dyn_PIDDIR(void)
218{
219 static char buffer[1024] = "";
220 if (!*buffer)
221 {
222 snprintf(buffer, 260, "%s/samba/pid", getenv("ETC"));
223 }
224 if (dyn_PIDDIR == NULL) {
225 return buffer;
226 }
227 return dyn_PIDDIR;
228}
229
230const char *set_dyn_PIDDIR(const char *newpath)
231{
232 if (dyn_PIDDIR) {
233 SAFE_FREE(dyn_PIDDIR);
234 }
235 dyn_PIDDIR = SMB_STRDUP(newpath);
236 return dyn_PIDDIR;
237}
238
239static char *dyn_SMB_PASSWD_FILE;
240
241const char *get_dyn_SMB_PASSWD_FILE(void)
242{
243 static char buffer[1024] = "";
244 if (!*buffer)
245 {
246 snprintf(buffer, 260, "%s/samba/private/smbpasswd", getenv("ETC"));
247 }
248 if (dyn_SMB_PASSWD_FILE == NULL) {
249 return buffer;
250 }
251 return dyn_SMB_PASSWD_FILE;
252}
253
254const char *set_dyn_SMB_PASSWD_FILE(const char *newpath)
255{
256 if (dyn_SMB_PASSWD_FILE) {
257 SAFE_FREE(dyn_SMB_PASSWD_FILE);
258 }
259 dyn_SMB_PASSWD_FILE = SMB_STRDUP(newpath);
260 return dyn_SMB_PASSWD_FILE;
261}
262
263static char *dyn_PRIVATE_DIR;
264
265const char *get_dyn_PRIVATE_DIR(void)
266{
267 static char buffer[1024] = "";
268 if (!*buffer)
269 {
270 snprintf(buffer, 260, "%s/samba/private", getenv("ETC"));
271 }
272 if (dyn_PRIVATE_DIR == NULL) {
273 return buffer;
274 }
275 return dyn_PRIVATE_DIR;
276}
277
278const char *set_dyn_PRIVATE_DIR(const char *newpath)
279{
280 if (dyn_PRIVATE_DIR) {
281 SAFE_FREE(dyn_PRIVATE_DIR);
282 }
283 dyn_PRIVATE_DIR = SMB_STRDUP(newpath);
284 return dyn_PRIVATE_DIR;
285}
286#endif /* __OS2__ */
287
288/* In non-FHS mode, these should be configurable using 'lock dir =';
289 but in FHS mode, they are their own directory. Implement as wrapper
290 functions so that everything can still be kept in dynconfig.c.
291 */
292
293const char *get_dyn_STATEDIR(void)
294{
295#ifdef FHS_COMPATIBLE
296 return STATEDIR;
297#else
298 return lp_lockdir();
299#endif
300}
301
302const char *get_dyn_CACHEDIR(void)
303{
304#ifdef FHS_COMPATIBLE
305 return CACHEDIR;
306#else
307 return lp_lockdir();
308#endif
309}
Note: See TracBrowser for help on using the repository browser.