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

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

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

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