[680] | 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 | This program is free software; you can redistribute it and/or modify
|
---|
| 7 | it under the terms of the GNU General Public License as published by
|
---|
| 8 | the Free Software Foundation; either version 3 of the License, or
|
---|
| 9 | (at your option) any later version.
|
---|
| 10 | This program is distributed in the hope that it will be useful,
|
---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | GNU General Public License for more details.
|
---|
| 14 | You should have received a copy of the GNU General Public License
|
---|
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 16 | */
|
---|
| 17 | #include "includes.h"
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * @file dynconfig.c
|
---|
| 21 | *
|
---|
| 22 | * @brief Global configurations, initialized to configured defaults.
|
---|
| 23 | *
|
---|
| 24 | * This file should be the only file that depends on path
|
---|
| 25 | * configuration (--prefix, etc), so that if ./configure is re-run,
|
---|
| 26 | * all programs will be appropriately updated. Everything else in
|
---|
| 27 | * Samba should import extern variables from here, rather than relying
|
---|
| 28 | * on preprocessor macros.
|
---|
| 29 | *
|
---|
| 30 | * Eventually some of these may become even more variable, so that
|
---|
| 31 | * they can for example consistently be set across the whole of Samba
|
---|
| 32 | * by command-line parameters, config file entries, or environment
|
---|
| 33 | * variables.
|
---|
| 34 | *
|
---|
| 35 | * @todo Perhaps eventually these should be merged into the parameter
|
---|
| 36 | * table? There's kind of a chicken-and-egg situation there...
|
---|
| 37 | **/
|
---|
| 38 | #ifndef __OS2__
|
---|
| 39 | #define DEFINE_DYN_CONFIG_PARAM(name) \
|
---|
| 40 | static char *dyn_##name; \
|
---|
| 41 | \
|
---|
| 42 | const char *get_dyn_##name(void) \
|
---|
| 43 | {\
|
---|
| 44 | if (dyn_##name == NULL) {\
|
---|
| 45 | return name;\
|
---|
| 46 | }\
|
---|
| 47 | return dyn_##name;\
|
---|
| 48 | }\
|
---|
| 49 | \
|
---|
| 50 | const char *set_dyn_##name(const char *newpath) \
|
---|
| 51 | {\
|
---|
| 52 | if (dyn_##name) {\
|
---|
| 53 | SAFE_FREE(dyn_##name);\
|
---|
| 54 | }\
|
---|
| 55 | dyn_##name = SMB_STRDUP(newpath);\
|
---|
| 56 | return dyn_##name;\
|
---|
| 57 | }\
|
---|
| 58 | \
|
---|
| 59 | bool is_default_dyn_##name(void) \
|
---|
| 60 | {\
|
---|
| 61 | return (dyn_##name == NULL);\
|
---|
| 62 | }
|
---|
| 63 | #else
|
---|
| 64 | #define DEFINE_DYN_CONFIG_PARAM(name) \
|
---|
| 65 | static char *dyn_##name; \
|
---|
| 66 | \
|
---|
| 67 | const char *set_dyn_##name(const char *newpath) \
|
---|
| 68 | {\
|
---|
| 69 | if (dyn_##name) {\
|
---|
| 70 | SAFE_FREE(dyn_##name);\
|
---|
| 71 | }\
|
---|
| 72 | dyn_##name = SMB_STRDUP(newpath);\
|
---|
| 73 | return dyn_##name;\
|
---|
| 74 | }\
|
---|
| 75 | \
|
---|
| 76 | bool is_default_dyn_##name(void) \
|
---|
| 77 | {\
|
---|
| 78 | return (dyn_##name == NULL);\
|
---|
| 79 | }
|
---|
| 80 | #endif
|
---|
| 81 | DEFINE_DYN_CONFIG_PARAM(SBINDIR)
|
---|
| 82 | DEFINE_DYN_CONFIG_PARAM(BINDIR)
|
---|
| 83 | DEFINE_DYN_CONFIG_PARAM(SWATDIR)
|
---|
| 84 | DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
|
---|
| 85 | DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
|
---|
| 86 | DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
|
---|
| 87 | DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
|
---|
| 88 | DEFINE_DYN_CONFIG_PARAM(LIBDIR)
|
---|
| 89 | DEFINE_DYN_CONFIG_PARAM(MODULESDIR)
|
---|
| 90 | DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
|
---|
| 91 | DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
|
---|
| 92 | DEFINE_DYN_CONFIG_PARAM(PIDDIR)
|
---|
| 93 | DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
|
---|
| 94 | DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
|
---|
| 95 |
|
---|
| 96 | #ifdef __OS2__
|
---|
| 97 | /* Directory the binary was called from, same as getbindir() */
|
---|
| 98 | const char *get_dyn_SBINDIR(void)
|
---|
| 99 | {
|
---|
| 100 | static char buffer[1024] = "";
|
---|
| 101 | if (!*buffer)
|
---|
| 102 | {
|
---|
| 103 | char exedir[1024] = "";
|
---|
| 104 | if (!os2_GetExePath(exedir))
|
---|
| 105 | {
|
---|
| 106 | snprintf(buffer, 260, "%s", SBINDIR);
|
---|
| 107 | } else {
|
---|
| 108 | snprintf(buffer, 260, "%s", exedir);
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | if (dyn_SBINDIR == NULL) {
|
---|
| 112 | return buffer;
|
---|
| 113 | }
|
---|
| 114 | return dyn_SBINDIR;
|
---|
| 115 | }
|
---|
| 116 | /* Directory the binary was called from, same as getsbindir() */
|
---|
| 117 | const char *get_dyn_BINDIR(void)
|
---|
| 118 | {
|
---|
| 119 | static char buffer[1024] = "";
|
---|
| 120 | if (!*buffer)
|
---|
| 121 | {
|
---|
| 122 | char exedir[1024] = "";
|
---|
| 123 | if (!os2_GetExePath(exedir))
|
---|
| 124 | {
|
---|
| 125 | snprintf(buffer, 260, "%s", BINDIR);
|
---|
| 126 | } else {
|
---|
| 127 | snprintf(buffer, 260, "%s", exedir);
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | if (dyn_BINDIR == NULL) {
|
---|
| 131 | return buffer;
|
---|
| 132 | }
|
---|
| 133 | return dyn_BINDIR;
|
---|
| 134 | }
|
---|
| 135 | /* Directory holding the SWAT files */
|
---|
| 136 | const char *get_dyn_SWATDIR(void)
|
---|
| 137 | {
|
---|
| 138 | static char buffer[1024] = "";
|
---|
| 139 | if (!*buffer)
|
---|
| 140 | {
|
---|
| 141 | char exedir[1024] = "";
|
---|
| 142 | if (!os2_GetExePath(exedir))
|
---|
| 143 | {
|
---|
| 144 | snprintf(buffer, 260, "%s", SWATDIR);
|
---|
| 145 | } else {
|
---|
| 146 | snprintf(buffer, 260, "%s/%s", exedir,"swat");
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 | if (dyn_SWATDIR == NULL) {
|
---|
| 150 | return buffer;
|
---|
| 151 | }
|
---|
| 152 | return dyn_SWATDIR;
|
---|
| 153 | }
|
---|
| 154 | /* Location of smb.conf file. */
|
---|
| 155 | const char *get_dyn_CONFIGFILE(void)
|
---|
| 156 | {
|
---|
| 157 | static char buffer[1024] = "";
|
---|
| 158 | if (!*buffer)
|
---|
| 159 | {
|
---|
| 160 | snprintf(buffer, 260, "%s/samba/smb.conf", getenv("ETC"));
|
---|
| 161 | }
|
---|
| 162 | /* Set UNIXROOT to x:\MPTN if UNIXROOT is undefined */
|
---|
| 163 | if (getenv("UNIXROOT") == NULL) {
|
---|
| 164 | static char unixroot[1024] = "";
|
---|
| 165 | strncpy(unixroot,getenv("ETC"),strlen(getenv("ETC"))-4);
|
---|
| 166 | setenv("UNIXROOT",unixroot,0);
|
---|
| 167 | }
|
---|
| 168 | /* Make sure TMPIR points to a proper value */
|
---|
| 169 | static char tmpdir[1024] = "";
|
---|
| 170 | if (getenv("TMPDIR") == NULL && getenv("TEMP") != NULL) {
|
---|
| 171 | strncpy(tmpdir,getenv("TEMP"),strlen(getenv("TEMP")));
|
---|
| 172 | setenv("TMPDIR",tmpdir,0);
|
---|
| 173 | }
|
---|
| 174 | if (getenv("TMPDIR") == NULL) {
|
---|
| 175 | strncpy(tmpdir,getenv("ETC"),2);
|
---|
| 176 | stpcpy(tmpdir,"/OS2/SYSTEM");
|
---|
| 177 | setenv("TMPDIR",tmpdir,0);
|
---|
| 178 | }
|
---|
| 179 | if (dyn_CONFIGFILE == NULL) {
|
---|
| 180 | return buffer;
|
---|
| 181 | }
|
---|
| 182 | return dyn_CONFIGFILE;
|
---|
| 183 | }
|
---|
| 184 | /** Log file directory. **/
|
---|
| 185 | const char *get_dyn_LOGFILEBASE(void)
|
---|
| 186 | {
|
---|
| 187 | static char buffer[1024] = "";
|
---|
| 188 | if (!*buffer)
|
---|
| 189 | {
|
---|
| 190 | snprintf(buffer, 260, "%s/samba/log", getenv("ETC"));
|
---|
| 191 | }
|
---|
| 192 | if (dyn_LOGFILEBASE == NULL) {
|
---|
| 193 | return buffer;
|
---|
| 194 | }
|
---|
| 195 | return dyn_LOGFILEBASE;
|
---|
| 196 | }
|
---|
| 197 | /** Statically configured LanMan hosts. **/
|
---|
| 198 | const char *get_dyn_LMHOSTSFILE(void)
|
---|
| 199 | {
|
---|
| 200 | static char buffer[1024] = "";
|
---|
| 201 | if (!*buffer)
|
---|
| 202 | {
|
---|
| 203 | snprintf(buffer, 260, "%s/samba/lmhosts", getenv("ETC"));
|
---|
| 204 | }
|
---|
| 205 | if (dyn_LMHOSTSFILE == NULL) {
|
---|
| 206 | return buffer;
|
---|
| 207 | }
|
---|
| 208 | return dyn_LMHOSTSFILE;
|
---|
| 209 | }
|
---|
| 210 | /* Directory holding the codepages */
|
---|
| 211 | const char *get_dyn_CODEPAGEDIR(void)
|
---|
| 212 | {
|
---|
| 213 | static char buffer[1024] = "";
|
---|
| 214 | if (!*buffer)
|
---|
| 215 | {
|
---|
| 216 | char exedir[1024] = "";
|
---|
| 217 | if (!os2_GetExePath(exedir))
|
---|
| 218 | {
|
---|
| 219 | snprintf(buffer, 260, "%s", CODEPAGEDIR);
|
---|
| 220 | } else {
|
---|
| 221 | if (!lp_is_in_client()) {
|
---|
| 222 | snprintf(buffer, 260, "%s/%s", exedir, "codepages");
|
---|
| 223 | } else {
|
---|
| 224 | snprintf(buffer, 260, "%s/%s", getenv("SMB_EXE"), "codepages");
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 | if (dyn_CODEPAGEDIR == NULL) {
|
---|
| 229 | return buffer;
|
---|
| 230 | }
|
---|
| 231 | return dyn_CODEPAGEDIR;
|
---|
| 232 | }
|
---|
| 233 | /* Directory holding the libs */
|
---|
| 234 | const char *get_dyn_LIBDIR(void)
|
---|
| 235 | {
|
---|
| 236 | static char buffer[1024] = "";
|
---|
| 237 | if (!*buffer)
|
---|
| 238 | {
|
---|
| 239 | char exedir[1024] = "";
|
---|
| 240 | if (!os2_GetExePath(exedir))
|
---|
| 241 | {
|
---|
| 242 | snprintf(buffer, 260, "%s", LIBDIR);
|
---|
| 243 | } else {
|
---|
| 244 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | if (dyn_LIBDIR == NULL) {
|
---|
| 248 | return buffer;
|
---|
| 249 | }
|
---|
| 250 | return dyn_LIBDIR;
|
---|
| 251 | }
|
---|
| 252 | /* Directory holding the modules */
|
---|
| 253 | const char *get_dyn_MODULESDIR(void)
|
---|
| 254 | {
|
---|
| 255 | static char buffer[1024] = "";
|
---|
| 256 | if (!*buffer)
|
---|
| 257 | {
|
---|
| 258 | char exedir[1024] = "";
|
---|
| 259 | if (!os2_GetExePath(exedir))
|
---|
| 260 | {
|
---|
| 261 | snprintf(buffer, 260, "%s", MODULESDIR);
|
---|
| 262 | } else {
|
---|
| 263 | snprintf(buffer, 260, "%s/%s", exedir, "modules");
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 | if (dyn_MODULESDIR == NULL) {
|
---|
| 267 | return buffer;
|
---|
| 268 | }
|
---|
| 269 | return dyn_MODULESDIR;
|
---|
| 270 | }
|
---|
| 271 | /* Directory holding lock files */
|
---|
| 272 | const char *get_dyn_LOCKDIR(void)
|
---|
| 273 | {
|
---|
| 274 | static char buffer[1024] = "";
|
---|
| 275 | if (!*buffer)
|
---|
| 276 | {
|
---|
[689] | 277 | snprintf(buffer, 260, "%s/samba/lock", getenv("ETC"));
|
---|
[680] | 278 | }
|
---|
| 279 | if (dyn_LOCKDIR == NULL) {
|
---|
| 280 | return buffer;
|
---|
| 281 | }
|
---|
| 282 | return dyn_LOCKDIR;
|
---|
| 283 | }
|
---|
| 284 | /* Directory holding the pid files */
|
---|
| 285 | const char *get_dyn_PIDDIR(void)
|
---|
| 286 | {
|
---|
| 287 | static char buffer[1024] = "";
|
---|
| 288 | if (!*buffer)
|
---|
| 289 | {
|
---|
| 290 | snprintf(buffer, 260, "%s/samba/pid", getenv("ETC"));
|
---|
| 291 | }
|
---|
| 292 | if (dyn_PIDDIR == NULL) {
|
---|
| 293 | return buffer;
|
---|
| 294 | }
|
---|
| 295 | return dyn_PIDDIR;
|
---|
| 296 | }
|
---|
| 297 | /* Location of smbpasswd */
|
---|
| 298 | const char *get_dyn_SMB_PASSWD_FILE(void)
|
---|
| 299 | {
|
---|
| 300 | static char buffer[1024] = "";
|
---|
| 301 | if (!*buffer)
|
---|
| 302 | {
|
---|
| 303 | snprintf(buffer, 260, "%s/samba/private/smbpasswd", getenv("ETC"));
|
---|
| 304 | }
|
---|
| 305 | if (dyn_SMB_PASSWD_FILE == NULL) {
|
---|
| 306 | return buffer;
|
---|
| 307 | }
|
---|
| 308 | return dyn_SMB_PASSWD_FILE;
|
---|
| 309 | }
|
---|
| 310 | /* Directory holding the private files */
|
---|
| 311 | const char *get_dyn_PRIVATE_DIR(void)
|
---|
| 312 | {
|
---|
| 313 | static char buffer[1024] = "";
|
---|
| 314 | if (!*buffer)
|
---|
| 315 | {
|
---|
| 316 | snprintf(buffer, 260, "%s/samba/private", getenv("ETC"));
|
---|
| 317 | }
|
---|
| 318 | if (dyn_PRIVATE_DIR == NULL) {
|
---|
| 319 | return buffer;
|
---|
| 320 | }
|
---|
| 321 | return dyn_PRIVATE_DIR;
|
---|
| 322 | }
|
---|
| 323 | /* Directory holding the shared libs (same as libdir) */
|
---|
| 324 | const char *get_dyn_SHLIBEXT(void)
|
---|
| 325 | {
|
---|
| 326 | static char buffer[1024] = "";
|
---|
| 327 | if (!*buffer)
|
---|
| 328 | {
|
---|
| 329 | char exedir[1024] = "";
|
---|
| 330 | if (!os2_GetExePath(exedir))
|
---|
| 331 | {
|
---|
| 332 | snprintf(buffer, 260, "%s", LIBDIR);
|
---|
| 333 | } else {
|
---|
| 334 | snprintf(buffer, 260, "%s/%s", exedir, "lib");
|
---|
| 335 | }
|
---|
| 336 | }
|
---|
| 337 | if (dyn_SHLIBEXT == NULL) {
|
---|
| 338 | return buffer;
|
---|
| 339 | }
|
---|
| 340 | return dyn_SHLIBEXT;
|
---|
| 341 | }
|
---|
| 342 | #endif /* __OS2__ */
|
---|
| 343 | /* In non-FHS mode, these should be configurable using 'lock dir =';
|
---|
| 344 | but in FHS mode, they are their own directory. Implement as wrapper
|
---|
| 345 | functions so that everything can still be kept in dynconfig.c.
|
---|
| 346 | */
|
---|
| 347 | const char *get_dyn_STATEDIR(void)
|
---|
| 348 | {
|
---|
| 349 | #ifdef FHS_COMPATIBLE
|
---|
| 350 | return STATEDIR;
|
---|
| 351 | #else
|
---|
| 352 | return lp_lockdir();
|
---|
| 353 | #endif
|
---|
| 354 | }
|
---|
| 355 | const char *get_dyn_CACHEDIR(void)
|
---|
| 356 | {
|
---|
| 357 | #ifdef FHS_COMPATIBLE
|
---|
| 358 | return CACHEDIR;
|
---|
| 359 | #else
|
---|
| 360 | return lp_lockdir();
|
---|
| 361 | #endif
|
---|
| 362 | }
|
---|