| 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) != 0)
|
|---|
| 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) != 0)
|
|---|
| 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) != 0)
|
|---|
| 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) != 0)
|
|---|
| 238 | {
|
|---|
| 239 | snprintf(buffer, 260, "%s", CODEPAGEDIR);
|
|---|
| 240 | } else {
|
|---|
| 241 | snprintf(buffer, 260, "%s/%s", exedir, "codepages");
|
|---|
| 242 | }
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | if (dyn_CODEPAGEDIR == NULL) {
|
|---|
| 246 | return buffer;
|
|---|
| 247 | }
|
|---|
| 248 | return dyn_CODEPAGEDIR;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | /* Directory holding the libs */
|
|---|
| 252 | const char *get_dyn_LIBDIR(void)
|
|---|
| 253 | {
|
|---|
| 254 | static char buffer[1024] = "";
|
|---|
| 255 | if (!*buffer)
|
|---|
| 256 | {
|
|---|
| 257 | char exedir[1024] = "";
|
|---|
| 258 | if (os2_GetExePath(exedir) != 0)
|
|---|
| 259 | {
|
|---|
| 260 | snprintf(buffer, 260, "%s", LIBDIR);
|
|---|
| 261 | } else {
|
|---|
| 262 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
|---|
| 263 | }
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | if (dyn_LIBDIR == NULL) {
|
|---|
| 267 | return buffer;
|
|---|
| 268 | }
|
|---|
| 269 | return dyn_LIBDIR;
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | /* Directory holding the modules */
|
|---|
| 273 | const char *get_dyn_MODULESDIR(void)
|
|---|
| 274 | {
|
|---|
| 275 | static char buffer[1024] = "";
|
|---|
| 276 | if (!*buffer)
|
|---|
| 277 | {
|
|---|
| 278 | char exedir[1024] = "";
|
|---|
| 279 | if (os2_GetExePath(exedir) != 0)
|
|---|
| 280 | {
|
|---|
| 281 | snprintf(buffer, 260, "%s", MODULESDIR);
|
|---|
| 282 | } else {
|
|---|
| 283 | snprintf(buffer, 260, "%s/%s", exedir, "modules");
|
|---|
| 284 | }
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | if (dyn_MODULESDIR == NULL) {
|
|---|
| 288 | return buffer;
|
|---|
| 289 | }
|
|---|
| 290 | return dyn_MODULESDIR;
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | /* Directory holding lock files */
|
|---|
| 294 | const char *get_dyn_LOCKDIR(void)
|
|---|
| 295 | {
|
|---|
| 296 | static char buffer[1024] = "";
|
|---|
| 297 | if (!*buffer)
|
|---|
| 298 | {
|
|---|
| 299 | if (os2_isClient())
|
|---|
| 300 | {
|
|---|
| 301 | snprintf(buffer, 260, "%s/samba/lock/client", getenv("ETC"));
|
|---|
| 302 | } else {
|
|---|
| 303 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
|---|
| 304 | }
|
|---|
| 305 | }
|
|---|
| 306 | if (dyn_LOCKDIR == NULL) {
|
|---|
| 307 | return buffer;
|
|---|
| 308 | }
|
|---|
| 309 | return dyn_LOCKDIR;
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | /* Directory holding the pid files */
|
|---|
| 313 | const char *get_dyn_PIDDIR(void)
|
|---|
| 314 | {
|
|---|
| 315 | static char buffer[1024] = "";
|
|---|
| 316 | if (!*buffer)
|
|---|
| 317 | {
|
|---|
| 318 | snprintf(buffer, 260, "%s/samba/pid", getenv("ETC"));
|
|---|
| 319 | }
|
|---|
| 320 | if (dyn_PIDDIR == NULL) {
|
|---|
| 321 | return buffer;
|
|---|
| 322 | }
|
|---|
| 323 | return dyn_PIDDIR;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | /* Location of smbpasswd */
|
|---|
| 327 | const char *get_dyn_SMB_PASSWD_FILE(void)
|
|---|
| 328 | {
|
|---|
| 329 | static char buffer[1024] = "";
|
|---|
| 330 | if (!*buffer)
|
|---|
| 331 | {
|
|---|
| 332 | snprintf(buffer, 260, "%s/samba/private/smbpasswd", getenv("ETC"));
|
|---|
| 333 | }
|
|---|
| 334 | if (dyn_SMB_PASSWD_FILE == NULL) {
|
|---|
| 335 | return buffer;
|
|---|
| 336 | }
|
|---|
| 337 | return dyn_SMB_PASSWD_FILE;
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | /* Directory holding the private files */
|
|---|
| 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 | /* Directory holding the shared libs (same as libdir) */
|
|---|
| 355 | const char *get_dyn_SHLIBEXT(void)
|
|---|
| 356 | {
|
|---|
| 357 | static char buffer[1024] = "";
|
|---|
| 358 | if (!*buffer)
|
|---|
| 359 | {
|
|---|
| 360 | char exedir[1024] = "";
|
|---|
| 361 | if (os2_GetExePath(exedir) != 0)
|
|---|
| 362 | {
|
|---|
| 363 | snprintf(buffer, 260, "%s", LIBDIR);
|
|---|
| 364 | } else {
|
|---|
| 365 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
|---|
| 366 | }
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | if (dyn_SHLIBEXT == NULL) {
|
|---|
| 370 | return buffer;
|
|---|
| 371 | }
|
|---|
| 372 | return dyn_SHLIBEXT;
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | /* Directory holding the NCALRPCDIR (whatever that is) */
|
|---|
| 376 | const char *get_dyn_NCALRPCDIR(void)
|
|---|
| 377 | {
|
|---|
| 378 | static char buffer[1024] = "";
|
|---|
| 379 | if (!*buffer)
|
|---|
| 380 | {
|
|---|
| 381 | char exedir[1024] = "";
|
|---|
| 382 | if (os2_GetExePath(exedir) != 0)
|
|---|
| 383 | {
|
|---|
| 384 | snprintf(buffer, 260, "%s", NCALRPCDIR);
|
|---|
| 385 | } else {
|
|---|
| 386 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
|---|
| 387 | }
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | if (dyn_NCALRPCDIR == NULL) {
|
|---|
| 391 | return buffer;
|
|---|
| 392 | }
|
|---|
| 393 | return dyn_NCALRPCDIR;
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | #endif /* __OS2__ */
|
|---|
| 397 |
|
|---|
| 398 | /* In non-FHS mode, these should be configurable using 'lock dir =';
|
|---|
| 399 | but in FHS mode, they are their own directory. Implement as wrapper
|
|---|
| 400 | functions so that everything can still be kept in dynconfig.c.
|
|---|
| 401 | */
|
|---|
| 402 |
|
|---|
| 403 | const char *get_dyn_STATEDIR(void)
|
|---|
| 404 | {
|
|---|
| 405 | #ifdef FHS_COMPATIBLE
|
|---|
| 406 | return STATEDIR;
|
|---|
| 407 | #else
|
|---|
| 408 | return lp_lockdir();
|
|---|
| 409 | #endif
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | const char *get_dyn_CACHEDIR(void)
|
|---|
| 413 | {
|
|---|
| 414 | #ifdef FHS_COMPATIBLE
|
|---|
| 415 | return CACHEDIR;
|
|---|
| 416 | #else
|
|---|
| 417 | return lp_lockdir();
|
|---|
| 418 | #endif
|
|---|
| 419 | }
|
|---|