| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | Copyright (C) 2001 by Martin Pool <[email protected]>
|
|---|
| 4 | Copyright (C) 2003 by Jim McDonough <[email protected]>
|
|---|
| 5 | Copyright (C) 2007 by Jeremy Allison <[email protected]>
|
|---|
| 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 | {
|
|---|
|
|---|