[252] | 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 | #if 0
|
---|
| 44 | static char const *dyn_SBINDIR = SBINDIR;
|
---|
| 45 | static char const *dyn_BINDIR = BINDIR;
|
---|
| 46 | static char const *dyn_SWATDIR = SWATDIR;
|
---|
| 47 | #endif
|
---|
| 48 |
|
---|
| 49 | #define DEFINE_DYN_CONFIG_PARAM(name) \
|
---|
| 50 | static char *dyn_##name; \
|
---|
| 51 | \
|
---|
| 52 | const char *get_dyn_##name(void) \
|
---|
| 53 | {\
|
---|
| 54 | if (dyn_##name == NULL) {\
|
---|
| 55 | return name;\
|
---|
| 56 | }\
|
---|
| 57 | return dyn_##name;\
|
---|
| 58 | }\
|
---|
| 59 | \
|
---|
| 60 | const char *set_dyn_##name(const char *newpath) \
|
---|
| 61 | {\
|
---|
| 62 | if (dyn_##name) {\
|
---|
| 63 | SAFE_FREE(dyn_##name);\
|
---|
| 64 | }\
|
---|
| 65 | dyn_##name = SMB_STRDUP(newpath);\
|
---|
| 66 | return dyn_##name;\
|
---|
| 67 | }\
|
---|
| 68 | \
|
---|
| 69 | bool is_default_dyn_##name(void) \
|
---|
| 70 | {\
|
---|
| 71 | return (dyn_##name == NULL);\
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | DEFINE_DYN_CONFIG_PARAM(SBINDIR)
|
---|
| 75 | DEFINE_DYN_CONFIG_PARAM(BINDIR)
|
---|
| 76 | DEFINE_DYN_CONFIG_PARAM(SWATDIR)
|
---|
| 77 | #ifndef __OS2__
|
---|
| 78 | DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
|
---|
| 79 | DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
|
---|
| 80 | DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
|
---|
| 81 | #endif
|
---|
| 82 | DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
|
---|
| 83 | DEFINE_DYN_CONFIG_PARAM(LIBDIR)
|
---|
| 84 | DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
|
---|
| 85 | #ifndef __OS2__
|
---|
| 86 | DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
|
---|
| 87 | DEFINE_DYN_CONFIG_PARAM(PIDDIR)
|
---|
| 88 | DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
|
---|
| 89 | DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
|
---|
| 90 | #endif
|
---|
| 91 |
|
---|
| 92 | #ifdef __OS2__
|
---|
| 93 | static char *dyn_CONFIGFILE; /**< Location of smb.conf file. **/
|
---|
| 94 |
|
---|
| 95 | const char *get_dyn_CONFIGFILE(void)
|
---|
| 96 | {
|
---|
| 97 | static char buffer[1024] = "";
|
---|
| 98 | if (!*buffer)
|
---|
| 99 | {
|
---|
| 100 | snprintf(buffer, 260, "%s/samba/smb.conf", getenv("ETC"));
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | /* Set UNIXROOT to x:\MPTN if UNIXROOT is undefined */
|
---|
| 104 | if (getenv("UNIXROOT") == NULL) {
|
---|
| 105 | static char unixroot[1024] = "";
|
---|
| 106 | strncpy(unixroot,getenv("ETC"),strlen(getenv("ETC"))-4);
|
---|
| 107 | setenv("UNIXROOT",unixroot,0);
|
---|
| 108 | }
|
---|
| 109 | /* Make sure TMPIR points to a proper value */
|
---|
| 110 | static char tmpdir[1024] = "";
|
---|
| 111 | if (getenv("TMPDIR") == NULL && getenv("TEMP") != NULL) {
|
---|
| 112 | strncpy(tmpdir,getenv("TEMP"),strlen(getenv("TEMP")));
|
---|
| 113 | setenv("TMPDIR",tmpdir,0);
|
---|
| 114 | }
|
---|
| 115 | if (getenv("TMPDIR") == NULL) {
|
---|
| 116 | strncpy(tmpdir,getenv("ETC"),2);
|
---|
| 117 | stpcpy(tmpdir,"/OS2/SYSTEM");
|
---|
| 118 | setenv("TMPDIR",tmpdir,0);
|
---|
| 119 | }
|
---|
| 120 | if (dyn_CONFIGFILE == NULL) {
|
---|
| 121 | return buffer;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | return dyn_CONFIGFILE;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | const char *set_dyn_CONFIGFILE(const char *newpath)
|
---|
| 128 | {
|
---|
| 129 | if (dyn_CONFIGFILE) {
|
---|
| 130 | SAFE_FREE(dyn_CONFIGFILE);
|
---|
| 131 | }
|
---|
| 132 | dyn_CONFIGFILE = SMB_STRDUP(newpath);
|
---|
| 133 | return dyn_CONFIGFILE;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | bool is_default_dyn_CONFIGFILE(void) \
|
---|
| 137 | {\
|
---|
| 138 | return (dyn_CONFIGFILE == NULL);\
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | /** Log file directory. **/
|
---|
| 142 | static char *dyn_LOGFILEBASE;
|
---|
| 143 |
|
---|
| 144 | const char *get_dyn_LOGFILEBASE(void)
|
---|
| 145 | {
|
---|
| 146 | static char buffer[1024] = "";
|
---|
| 147 | if (!*buffer)
|
---|
| 148 | {
|
---|
| 149 | snprintf(buffer, 260, "%s/samba/log", getenv("ETC"));
|
---|
| 150 | }
|
---|
| 151 | if (dyn_LOGFILEBASE == NULL) {
|
---|
| 152 | return buffer;
|
---|
| 153 | }
|
---|
| 154 | return dyn_LOGFILEBASE;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | const char *set_dyn_LOGFILEBASE(const char *newpath)
|
---|
| 158 | {
|
---|
| 159 | if (dyn_LOGFILEBASE) {
|
---|
| 160 | SAFE_FREE(dyn_LOGFILEBASE);
|
---|
| 161 | }
|
---|
| 162 | dyn_LOGFILEBASE = SMB_STRDUP(newpath);
|
---|
| 163 | return dyn_LOGFILEBASE;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | /** Statically configured LanMan hosts. **/
|
---|
| 167 | static char *dyn_LMHOSTSFILE;
|
---|
| 168 |
|
---|
| 169 | const char *get_dyn_LMHOSTSFILE(void)
|
---|
| 170 | {
|
---|
| 171 | static char buffer[1024] = "";
|
---|
| 172 | if (!*buffer)
|
---|
| 173 | {
|
---|
| 174 | snprintf(buffer, 260, "%s/samba/lmhosts", getenv("ETC"));
|
---|
| 175 | }
|
---|
| 176 | if (dyn_LMHOSTSFILE == NULL) {
|
---|
| 177 | return buffer;
|
---|
| 178 | }
|
---|
| 179 | return dyn_LMHOSTSFILE;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | const char *set_dyn_LMHOSTSFILE(const char *newpath)
|
---|
| 183 | {
|
---|
| 184 | if (dyn_LMHOSTSFILE) {
|
---|
| 185 | SAFE_FREE(dyn_LMHOSTSFILE);
|
---|
| 186 | }
|
---|
| 187 | dyn_LMHOSTSFILE = SMB_STRDUP(newpath);
|
---|
| 188 | return dyn_LMHOSTSFILE;
|
---|
| 189 | }
|
---|
| 190 | #endif /* __OS2__ */
|
---|
| 191 |
|
---|
| 192 | #if 0
|
---|
| 193 | /**
|
---|
| 194 | * @brief Samba data directory.
|
---|
| 195 | *
|
---|
| 196 | * @sa data_path() to get the path to a file inside the CODEPAGEDIR.
|
---|
| 197 | **/
|
---|
| 198 | static char *dyn_CODEPAGEDIR;
|
---|
| 199 |
|
---|
| 200 | const char *get_dyn_CODEPAGEDIR(void)
|
---|
| 201 | {
|
---|
| 202 | if (dyn_CODEPAGEDIR == NULL) {
|
---|
| 203 | return CODEPAGEDIR;
|
---|
| 204 | }
|
---|
| 205 | return dyn_CODEPAGEDIR;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | const char *set_dyn_CODEPAGEDIR(const char *newpath)
|
---|
| 209 | {
|
---|
| 210 | if (dyn_CODEPAGEDIR) {
|
---|
| 211 | SAFE_FREE(dyn_CODEPAGEDIR);
|
---|
| 212 | }
|
---|
| 213 | dyn_CODEPAGEDIR = SMB_STRDUP(newpath);
|
---|
| 214 | return dyn_CODEPAGEDIR;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | /**
|
---|
| 218 | * @brief Samba library directory.
|
---|
| 219 | *
|
---|
| 220 | * @sa lib_path() to get the path to a file inside the LIBDIR.
|
---|
| 221 | **/
|
---|
| 222 | static char *dyn_LIBDIR;
|
---|
| 223 |
|
---|
| 224 | const char *get_dyn_LIBDIR(void)
|
---|
| 225 | {
|
---|
| 226 | if (dyn_LIBDIR == NULL) {
|
---|
| 227 | return LIBDIR;
|
---|
| 228 | }
|
---|
| 229 | return dyn_CODEPAGEDIR;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | const char *set_dyn_LIBDIR(const char *newpath)
|
---|
| 233 | {
|
---|
| 234 | if (dyn_LIBDIR) {
|
---|
| 235 | SAFE_FREE(dyn_LIBDIR);
|
---|
| 236 | }
|
---|
| 237 | dyn_LIBDIR = SMB_STRDUP(newpath);
|
---|
| 238 | return dyn_LIBDIR;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | static char *dyn_SHLIBEXT;
|
---|
| 242 |
|
---|
| 243 | const char *get_dyn_SHLIBEXT(void)
|
---|
| 244 | {
|
---|
| 245 | if (dyn_SHLIBEXT == NULL) {
|
---|
| 246 | return SHLIBEXT;
|
---|
| 247 | }
|
---|
| 248 | return dyn_SHLIBEXT;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | const char *set_dyn_SHLIBEXT(const char *newpath)
|
---|
| 252 | {
|
---|
| 253 | if (dyn_SHLIBEXT) {
|
---|
| 254 | SAFE_FREE(dyn_SHLIBEXT);
|
---|
| 255 | }
|
---|
| 256 | dyn_SHLIBEXT = SMB_STRDUP(newpath);
|
---|
| 257 | return dyn_SHLIBEXT;
|
---|
| 258 | }
|
---|
| 259 | #endif /* #if 0 */
|
---|
| 260 | #ifdef __OS2__
|
---|
| 261 | /**
|
---|
| 262 | * @brief Directory holding lock files.
|
---|
| 263 | *
|
---|
| 264 | * Not writable, but used to set a default in the parameter table.
|
---|
| 265 | **/
|
---|
| 266 |
|
---|
| 267 | static char *dyn_LOCKDIR;
|
---|
| 268 |
|
---|
| 269 | const char *get_dyn_LOCKDIR(void)
|
---|
| 270 | {
|
---|
| 271 | static char buffer[1024] = "";
|
---|
| 272 | if (!*buffer)
|
---|
| 273 | {
|
---|
| 274 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
---|
| 275 | }
|
---|
| 276 | if (dyn_LOCKDIR == NULL) {
|
---|
| 277 | return buffer;
|
---|
| 278 | }
|
---|
| 279 | return dyn_LOCKDIR;
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | const char *set_dyn_LOCKDIR(const char *newpath)
|
---|
| 283 | {
|
---|
| 284 | if (dyn_LOCKDIR) {
|
---|
| 285 | SAFE_FREE(dyn_LOCKDIR);
|
---|
| 286 | }
|
---|
| 287 | dyn_LOCKDIR = SMB_STRDUP(newpath);
|
---|
| 288 | return dyn_LOCKDIR;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | static char *dyn_PIDDIR;
|
---|
| 292 |
|
---|
| 293 | const char *get_dyn_PIDDIR(void)
|
---|
| 294 | {
|
---|
| 295 | static char buffer[1024] = "";
|
---|
| 296 | if (!*buffer)
|
---|
| 297 | {
|
---|
| 298 | snprintf(buffer, 260, "%s/samba/pid", getenv("ETC"));
|
---|
| 299 | }
|
---|
| 300 | if (dyn_PIDDIR == NULL) {
|
---|
| 301 | return buffer;
|
---|
| 302 | }
|
---|
| 303 | return dyn_PIDDIR;
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | const char *set_dyn_PIDDIR(const char *newpath)
|
---|
| 307 | {
|
---|
| 308 | if (dyn_PIDDIR) {
|
---|
| 309 | SAFE_FREE(dyn_PIDDIR);
|
---|
| 310 | }
|
---|
| 311 | dyn_PIDDIR = SMB_STRDUP(newpath);
|
---|
| 312 | return dyn_PIDDIR;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | static char *dyn_SMB_PASSWD_FILE;
|
---|
| 316 |
|
---|
| 317 | const char *get_dyn_SMB_PASSWD_FILE(void)
|
---|
| 318 | {
|
---|
| 319 | static char buffer[1024] = "";
|
---|
| 320 | if (!*buffer)
|
---|
| 321 | {
|
---|
| 322 | snprintf(buffer, 260, "%s/samba/private/smbpasswd", getenv("ETC"));
|
---|
| 323 | }
|
---|
| 324 | if (dyn_SMB_PASSWD_FILE == NULL) {
|
---|
| 325 | return buffer;
|
---|
| 326 | }
|
---|
| 327 | return dyn_SMB_PASSWD_FILE;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | const char *set_dyn_SMB_PASSWD_FILE(const char *newpath)
|
---|
| 331 | {
|
---|
| 332 | if (dyn_SMB_PASSWD_FILE) {
|
---|
| 333 | SAFE_FREE(dyn_SMB_PASSWD_FILE);
|
---|
| 334 | }
|
---|
| 335 | dyn_SMB_PASSWD_FILE = SMB_STRDUP(newpath);
|
---|
| 336 | return dyn_SMB_PASSWD_FILE;
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | static char *dyn_PRIVATE_DIR;
|
---|
| 340 |
|
---|
| 341 | const char *get_dyn_PRIVATE_DIR(void)
|
---|
| 342 | {
|
---|
| 343 | static char buffer[1024] = "";
|
---|
| 344 | if (!*buffer)
|
---|
| 345 | {
|
---|
| 346 | snprintf(buffer, 260, "%s/samba/private", getenv("ETC"));
|
---|
| 347 | }
|
---|
| 348 | if (dyn_PRIVATE_DIR == NULL) {
|
---|
| 349 | return buffer;
|
---|
| 350 | }
|
---|
| 351 | return dyn_PRIVATE_DIR;
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | const char *set_dyn_PRIVATE_DIR(const char *newpath)
|
---|
| 355 | {
|
---|
| 356 | if (dyn_PRIVATE_DIR) {
|
---|
| 357 | SAFE_FREE(dyn_PRIVATE_DIR);
|
---|
| 358 | }
|
---|
| 359 | dyn_PRIVATE_DIR = SMB_STRDUP(newpath);
|
---|
| 360 | return dyn_PRIVATE_DIR;
|
---|
| 361 | }
|
---|
| 362 | #endif
|
---|
| 363 |
|
---|
| 364 | /* In non-FHS mode, these should be configurable using 'lock dir =';
|
---|
| 365 | but in FHS mode, they are their own directory. Implement as wrapper
|
---|
| 366 | functions so that everything can still be kept in dynconfig.c.
|
---|
| 367 | */
|
---|
| 368 |
|
---|
| 369 | const char *get_dyn_STATEDIR(void)
|
---|
| 370 | {
|
---|
| 371 | #ifdef FHS_COMPATIBLE
|
---|
| 372 | return STATEDIR;
|
---|
| 373 | #else
|
---|
| 374 | return lp_lockdir();
|
---|
| 375 | #endif
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | const char *get_dyn_CACHEDIR(void)
|
---|
| 379 | {
|
---|
| 380 | #ifdef FHS_COMPATIBLE
|
---|
| 381 | return CACHEDIR;
|
---|
| 382 | #else
|
---|
| 383 | return lp_lockdir();
|
---|
| 384 | #endif
|
---|
| 385 | }
|
---|