2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
69 #include "source4/dns_server/dns_update.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved = false;
76 #define LOADPARM_EXTRA_GLOBALS \
77 struct parmlist_entry *param_opt; \
91 #include "lib/param/param_global.h"
93 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
96 /* prototypes for the special type handlers */
97 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
98 const char *pszParmValue, char **ptr);
99 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
100 const char *pszParmValue, char **ptr);
101 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
102 const char *pszParmValue, char **ptr);
103 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
104 const char *pszParmValue, char **ptr);
105 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
106 const char *pszParmValue, char **ptr);
108 #include "lib/param/param_enums.c"
110 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
111 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
113 static struct parm_struct parm_table[] = {
115 .label = "server role",
118 .offset = GLOBAL_VAR(server_role),
120 .enum_list = enum_server_role
123 .label = "domain logons",
126 .offset = GLOBAL_VAR(domain_logons),
128 .enum_list = enum_bool_auto
131 .label = "domain master",
134 .offset = GLOBAL_VAR(domain_master),
136 .enum_list = enum_bool_auto
139 .label = "dos charset",
142 .offset = GLOBAL_VAR(dos_charset),
147 .label = "unix charset",
150 .offset = GLOBAL_VAR(unix_charset),
155 .label = "ncalrpc dir",
158 .offset = GLOBAL_VAR(ncalrpc_dir),
166 .offset = LOCAL_VAR(comment),
169 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
175 .offset = LOCAL_VAR(szPath),
178 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
181 .label = "directory",
184 .offset = LOCAL_VAR(szPath),
190 .label = "workgroup",
193 .offset = GLOBAL_VAR(szWorkgroup),
196 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
202 .offset = GLOBAL_VAR(szRealm),
203 .special = handle_realm,
205 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
208 .label = "netbios name",
211 .offset = GLOBAL_VAR(szNetbiosName),
214 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
217 .label = "netbios aliases",
220 .offset = GLOBAL_VAR(szNetbiosAliases),
225 .label = "netbios scope",
228 .offset = GLOBAL_VAR(szNetbiosScope),
231 .flags = FLAG_ADVANCED,
234 .label = "server string",
237 .offset = GLOBAL_VAR(szServerString),
240 .flags = FLAG_BASIC | FLAG_ADVANCED,
243 .label = "interfaces",
246 .offset = GLOBAL_VAR(szInterfaces),
249 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
252 .label = "bind interfaces only",
255 .offset = GLOBAL_VAR(bBindInterfacesOnly),
258 .flags = FLAG_ADVANCED | FLAG_WIZARD,
261 .label = "ntvfs handler",
264 .offset = LOCAL_VAR(ntvfs_handler),
269 .label = "passdb backend",
272 .offset = GLOBAL_VAR(passdb_backend),
277 .label = "dcerpc endpoint servers",
280 .offset = GLOBAL_VAR(dcerpc_ep_servers),
285 .label = "server services",
288 .offset = GLOBAL_VAR(server_services),
297 .offset = GLOBAL_VAR(security),
299 .enum_list = enum_security
302 .label = "encrypt passwords",
305 .offset = GLOBAL_VAR(bEncryptPasswords),
310 .label = "null passwords",
313 .offset = GLOBAL_VAR(bNullPasswords),
316 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
319 .label = "obey pam restrictions",
322 .offset = GLOBAL_VAR(bObeyPamRestrictions),
325 .flags = FLAG_ADVANCED,
328 .label = "password server",
331 .offset = GLOBAL_VAR(szPasswordServer),
336 .label = "private dir",
339 .offset = GLOBAL_VAR(szPrivateDir),
344 .label = "passwd chat",
347 .offset = GLOBAL_VAR(szPasswdChat),
352 .label = "password level",
355 .offset = GLOBAL_VAR(pwordlevel),
360 .label = "lanman auth",
363 .offset = GLOBAL_VAR(bLanmanAuth),
366 .flags = FLAG_ADVANCED,
369 .label = "ntlm auth",
372 .offset = GLOBAL_VAR(bNTLMAuth),
375 .flags = FLAG_ADVANCED,
378 .label = "client NTLMv2 auth",
381 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
384 .flags = FLAG_ADVANCED,
387 .label = "client lanman auth",
390 .offset = GLOBAL_VAR(bClientLanManAuth),
393 .flags = FLAG_ADVANCED,
396 .label = "client plaintext auth",
399 .offset = GLOBAL_VAR(bClientPlaintextAuth),
402 .flags = FLAG_ADVANCED,
405 .label = "client use spnego principal",
408 .offset = GLOBAL_VAR(client_use_spnego_principal),
414 .label = "read only",
417 .offset = LOCAL_VAR(bRead_only),
423 .label = "create mask",
426 .offset = LOCAL_VAR(iCreate_mask),
431 .label = "force create mode",
434 .offset = LOCAL_VAR(iCreate_force_mode),
439 .label = "directory mask",
442 .offset = LOCAL_VAR(iDir_mask),
447 .label = "force directory mode",
450 .offset = LOCAL_VAR(iDir_force_mode),
456 .label = "hosts allow",
459 .offset = LOCAL_VAR(szHostsallow),
464 .label = "hosts deny",
467 .offset = LOCAL_VAR(szHostsdeny),
473 .label = "log level",
476 .offset = GLOBAL_VAR(loglevel),
477 .special = handle_debuglevel,
481 .label = "debuglevel",
484 .offset = GLOBAL_VAR(loglevel),
485 .special = handle_debuglevel,
492 .offset = GLOBAL_VAR(logfile),
493 .special = handle_logfile,
495 .flags = FLAG_ADVANCED,
499 .label = "smb ports",
502 .offset = GLOBAL_VAR(smb_ports),
510 .offset = GLOBAL_VAR(nbt_port),
515 .label = "dgram port",
518 .offset = GLOBAL_VAR(dgram_port),
523 .label = "cldap port",
526 .offset = GLOBAL_VAR(cldap_port),
531 .label = "krb5 port",
534 .offset = GLOBAL_VAR(krb5_port),
539 .label = "kpasswd port",
542 .offset = GLOBAL_VAR(kpasswd_port),
550 .offset = GLOBAL_VAR(web_port),
555 .label = "tls enabled",
558 .offset = GLOBAL_VAR(tls_enabled),
563 .label = "tls keyfile",
566 .offset = GLOBAL_VAR(tls_keyfile),
571 .label = "tls certfile",
574 .offset = GLOBAL_VAR(tls_certfile),
579 .label = "tls cafile",
582 .offset = GLOBAL_VAR(tls_cafile),
587 .label = "tls crlfile",
590 .offset = GLOBAL_VAR(tls_crlfile),
595 .label = "tls dh params file",
598 .offset = GLOBAL_VAR(tls_dhpfile),
603 .label = "large readwrite",
606 .offset = GLOBAL_VAR(bLargeReadwrite),
609 .flags = FLAG_ADVANCED,
612 .label = "server max protocol",
615 .offset = GLOBAL_VAR(srv_maxprotocol),
617 .enum_list = enum_protocol,
618 .flags = FLAG_ADVANCED,
621 .label = "max protocol",
624 .offset = GLOBAL_VAR(srv_maxprotocol),
626 .enum_list = enum_protocol,
627 .flags = FLAG_ADVANCED,
633 .offset = GLOBAL_VAR(srv_maxprotocol),
635 .enum_list = enum_protocol,
636 .flags = FLAG_ADVANCED,
639 .label = "server min protocol",
642 .offset = GLOBAL_VAR(srv_minprotocol),
644 .enum_list = enum_protocol,
645 .flags = FLAG_ADVANCED,
648 .label = "min protocol",
651 .offset = GLOBAL_VAR(srv_minprotocol),
653 .enum_list = enum_protocol,
654 .flags = FLAG_ADVANCED,
657 .label = "client max protocol",
660 .offset = GLOBAL_VAR(cli_maxprotocol),
662 .enum_list = enum_protocol
665 .label = "client min protocol",
668 .offset = GLOBAL_VAR(cli_minprotocol),
670 .enum_list = enum_protocol
676 .offset = GLOBAL_VAR(bUnicode),
684 .offset = GLOBAL_VAR(bReadRaw),
689 .label = "write raw",
692 .offset = GLOBAL_VAR(bWriteRaw),
697 .label = "disable netbios",
700 .offset = GLOBAL_VAR(bDisableNetbios),
706 .label = "nt status support",
709 .offset = GLOBAL_VAR(bNTStatusSupport),
718 .offset = GLOBAL_VAR(max_mux),
721 .flags = FLAG_ADVANCED,
727 .offset = GLOBAL_VAR(max_xmit),
730 .flags = FLAG_ADVANCED,
734 .label = "name resolve order",
737 .offset = GLOBAL_VAR(szNameResolveOrder),
742 .label = "max wins ttl",
745 .offset = GLOBAL_VAR(max_wins_ttl),
748 .flags = FLAG_ADVANCED,
751 .label = "min wins ttl",
754 .offset = GLOBAL_VAR(min_wins_ttl),
757 .flags = FLAG_ADVANCED,
760 .label = "time server",
763 .offset = GLOBAL_VAR(bTimeServer),
766 .flags = FLAG_ADVANCED,
769 .label = "unix extensions",
772 .offset = GLOBAL_VAR(bUnixExtensions),
775 .flags = FLAG_ADVANCED,
778 .label = "use spnego",
781 .offset = GLOBAL_VAR(bUseSpnego),
786 .label = "server signing",
789 .offset = GLOBAL_VAR(server_signing),
791 .enum_list = enum_smb_signing_vals,
792 .flags = FLAG_ADVANCED,
795 .label = "client signing",
798 .offset = GLOBAL_VAR(client_signing),
800 .enum_list = enum_smb_signing_vals
803 .label = "rpc big endian",
806 .offset = GLOBAL_VAR(bRpcBigEndian),
812 .label = "max connections",
815 .offset = LOCAL_VAR(iMaxConnections),
818 .flags = FLAG_ADVANCED | FLAG_SHARE,
821 .label = "paranoid server security",
824 .offset = GLOBAL_VAR(paranoid_server_security),
829 .label = "socket options",
832 .offset = GLOBAL_VAR(socket_options),
838 .label = "strict sync",
841 .offset = LOCAL_VAR(bStrictSync),
849 .offset = GLOBAL_VAR(bUseMmap),
852 .flags = FLAG_ADVANCED,
855 .label = "case insensitive filesystem",
858 .offset = LOCAL_VAR(bCIFileSystem),
864 .label = "max print jobs",
867 .offset = LOCAL_VAR(iMaxPrintJobs),
872 .label = "printable",
875 .offset = LOCAL_VAR(bPrint_ok),
883 .offset = LOCAL_VAR(bPrint_ok),
889 .label = "printer name",
892 .offset = LOCAL_VAR(szPrintername),
895 .flags = FLAG_ADVANCED | FLAG_PRINT,
901 .offset = LOCAL_VAR(szPrintername),
908 .label = "map system",
911 .offset = LOCAL_VAR(bMap_system),
916 .label = "map hidden",
919 .offset = LOCAL_VAR(bMap_hidden),
924 .label = "map archive",
927 .offset = LOCAL_VAR(bMap_archive),
933 .label = "preferred master",
936 .offset = GLOBAL_VAR(bPreferredMaster),
938 .enum_list = enum_bool_auto,
939 .flags = FLAG_BASIC | FLAG_ADVANCED,
942 .label = "prefered master",
945 .offset = GLOBAL_VAR(bPreferredMaster),
947 .enum_list = enum_bool_auto,
951 .label = "local master",
954 .offset = GLOBAL_VAR(bLocalMaster),
959 .label = "browseable",
962 .offset = LOCAL_VAR(bBrowseable),
965 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
968 .label = "browsable",
971 .offset = LOCAL_VAR(bBrowseable),
977 .label = "dns proxy",
980 .offset = GLOBAL_VAR(bWINSdnsProxy),
985 .label = "wins server",
988 .offset = GLOBAL_VAR(szWINSservers),
991 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
994 .label = "wins support",
997 .offset = GLOBAL_VAR(bWINSsupport),
1000 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
1003 .label = "wins hook",
1005 .p_class = P_GLOBAL,
1006 .offset = GLOBAL_VAR(szWINSHook),
1009 .flags = FLAG_ADVANCED,
1013 .label = "csc policy",
1016 .offset = LOCAL_VAR(iCSCPolicy),
1018 .enum_list = enum_csc_policy,
1019 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1023 .label = "strict locking",
1026 .offset = LOCAL_VAR(iStrictLocking),
1034 .offset = LOCAL_VAR(bOpLocks),
1040 .label = "share backend",
1042 .p_class = P_GLOBAL,
1043 .offset = GLOBAL_VAR(szShareBackend),
1050 .p_class = P_GLOBAL,
1051 .offset = GLOBAL_VAR(szAutoServices),
1054 .flags = FLAG_ADVANCED,
1057 .label = "auto services",
1059 .p_class = P_GLOBAL,
1060 .offset = GLOBAL_VAR(szAutoServices),
1063 .flags = FLAG_ADVANCED,
1066 .label = "lock directory",
1068 .p_class = P_GLOBAL,
1069 .offset = GLOBAL_VAR(szLockDir),
1072 .flags = FLAG_ADVANCED,
1075 .label = "lock dir",
1077 .p_class = P_GLOBAL,
1078 .offset = GLOBAL_VAR(szLockDir),
1084 .label = "state directory",
1086 .p_class = P_GLOBAL,
1087 .offset = GLOBAL_VAR(szStateDir),
1090 .flags = FLAG_ADVANCED,
1093 .label = "cache directory",
1095 .p_class = P_GLOBAL,
1096 .offset = GLOBAL_VAR(szCacheDir),
1099 .flags = FLAG_ADVANCED,
1102 .label = "pid directory",
1104 .p_class = P_GLOBAL,
1105 .offset = GLOBAL_VAR(szPidDir),
1111 .label = "socket address",
1113 .p_class = P_GLOBAL,
1114 .offset = GLOBAL_VAR(szSocketAddress),
1122 .offset = LOCAL_VAR(szCopy),
1123 .special = handle_copy,
1131 .offset = LOCAL_VAR(szInclude),
1132 .special = handle_include,
1137 .label = "available",
1140 .offset = LOCAL_VAR(bAvailable),
1148 .offset = LOCAL_VAR(volume),
1151 .flags = FLAG_ADVANCED | FLAG_SHARE,
1157 .offset = LOCAL_VAR(fstype),
1163 .label = "panic action",
1165 .p_class = P_GLOBAL,
1166 .offset = GLOBAL_VAR(panic_action),
1172 .label = "msdfs root",
1175 .offset = LOCAL_VAR(bMSDfsRoot),
1180 .label = "host msdfs",
1182 .p_class = P_GLOBAL,
1183 .offset = GLOBAL_VAR(bHostMSDfs),
1186 .flags = FLAG_ADVANCED,
1189 .label = "winbind separator",
1191 .p_class = P_GLOBAL,
1192 .offset = GLOBAL_VAR(szWinbindSeparator),
1197 .label = "winbindd socket directory",
1199 .p_class = P_GLOBAL,
1200 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1203 .flags = FLAG_ADVANCED,
1206 .label = "winbindd privileged socket directory",
1208 .p_class = P_GLOBAL,
1209 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1212 .flags = FLAG_ADVANCED,
1215 .label = "winbind sealed pipes",
1217 .p_class = P_GLOBAL,
1218 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1221 .flags = FLAG_ADVANCED,
1224 .label = "template shell",
1226 .p_class = P_GLOBAL,
1227 .offset = GLOBAL_VAR(szTemplateShell),
1230 .flags = FLAG_ADVANCED,
1233 .label = "template homedir",
1235 .p_class = P_GLOBAL,
1236 .offset = GLOBAL_VAR(szTemplateHomedir),
1239 .flags = FLAG_ADVANCED,
1242 .label = "ntp signd socket directory",
1244 .p_class = P_GLOBAL,
1245 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1248 .flags = FLAG_ADVANCED,
1251 .label = "rndc command",
1253 .p_class = P_GLOBAL,
1254 .offset = GLOBAL_VAR(szRNDCCommand),
1257 .flags = FLAG_ADVANCED,
1260 .label = "dns update command",
1262 .p_class = P_GLOBAL,
1263 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1266 .flags = FLAG_ADVANCED,
1269 .label = "spn update command",
1271 .p_class = P_GLOBAL,
1272 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1275 .flags = FLAG_ADVANCED,
1278 .label = "samba kcc command",
1280 .p_class = P_GLOBAL,
1281 .offset = GLOBAL_VAR(szSambaKCCCommand),
1284 .flags = FLAG_ADVANCED,
1287 .label = "nsupdate command",
1289 .p_class = P_GLOBAL,
1290 .offset = GLOBAL_VAR(szNSUpdateCommand),
1293 .flags = FLAG_ADVANCED,
1296 .label = "allow dns updates",
1298 .p_class = P_GLOBAL,
1299 .offset = GLOBAL_VAR(allow_dns_updates),
1301 .enum_list = enum_dns_update_settings,
1302 .flags = FLAG_ADVANCED,
1305 .label = "dns forwarder",
1307 .p_class = P_GLOBAL,
1308 .offset = GLOBAL_VAR(dns_forwarder),
1311 .flags = FLAG_ADVANCED,
1314 .label = "dns recursive queries",
1316 .p_class = P_GLOBAL,
1317 .offset = GLOBAL_VAR(dns_recursive_queries),
1322 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1326 /* local variables */
1327 struct loadparm_context {
1328 const char *szConfigFile;
1329 struct loadparm_global *globals;
1330 struct loadparm_service **services;
1331 struct loadparm_service *sDefault;
1332 struct smb_iconv_handle *iconv_handle;
1334 struct loadparm_service *currentService;
1335 bool bInGlobalSection;
1337 struct file_lists *next;
1342 unsigned int flags[NUMPARAMETERS];
1345 bool global; /* Is this the global context, which may set
1346 * global variables such as debug level etc? */
1347 const struct loadparm_s3_helpers *s3_fns;
1351 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1353 if (lp_ctx->s3_fns) {
1354 return lp_ctx->s3_fns->get_default_loadparm_service();
1356 return lp_ctx->sDefault;
1360 * Convenience routine to grab string parameters into temporary memory
1361 * and run standard_sub_basic on them.
1363 * The buffers can be written to by
1364 * callers without affecting the source string.
1367 static const char *lp_string(const char *s)
1369 #if 0 /* until REWRITE done to make thread-safe */
1370 size_t len = s ? strlen(s) : 0;
1374 /* The follow debug is useful for tracking down memory problems
1375 especially if you have an inner loop that is calling a lp_*()
1376 function that returns a string. Perhaps this debug should be
1377 present all the time? */
1380 DEBUG(10, ("lp_string(%s)\n", s));
1383 #if 0 /* until REWRITE done to make thread-safe */
1385 lp_talloc = talloc_init("lp_talloc");
1387 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1395 strlcpy(ret, s, len);
1397 if (trim_string(ret, "\"", "\"")) {
1398 if (strchr(ret,'"') != NULL)
1399 strlcpy(ret, s, len);
1402 standard_sub_basic(ret,len+100);
1409 In this section all the functions that are used to access the
1410 parameters from the rest of the program are defined
1414 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1415 * for code compatibility between existing Samba4 and Samba3 code.
1418 /* this global context supports the lp_*() function varients */
1419 static struct loadparm_context *global_loadparm_context;
1421 #define lpcfg_default_service global_loadparm_context->sDefault
1422 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1424 #define FN_GLOBAL_STRING(fn_name,var_name) \
1425 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1426 if (lp_ctx == NULL) return NULL; \
1427 if (lp_ctx->s3_fns) { \
1428 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1429 return lp_ctx->s3_fns->fn_name(); \
1431 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1434 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1435 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1436 if (lp_ctx == NULL) return NULL; \
1437 if (lp_ctx->s3_fns) { \
1438 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1439 return lp_ctx->s3_fns->fn_name(); \
1441 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1444 #define FN_GLOBAL_LIST(fn_name,var_name) \
1445 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1446 if (lp_ctx == NULL) return NULL; \
1447 if (lp_ctx->s3_fns) { \
1448 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1449 return lp_ctx->s3_fns->fn_name(); \
1451 return lp_ctx->globals->var_name; \
1454 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1455 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1456 if (lp_ctx == NULL) return false; \
1457 if (lp_ctx->s3_fns) { \
1458 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1459 return lp_ctx->s3_fns->fn_name(); \
1461 return lp_ctx->globals->var_name; \
1464 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1465 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1466 if (lp_ctx->s3_fns) { \
1467 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1468 return lp_ctx->s3_fns->fn_name(); \
1470 return lp_ctx->globals->var_name; \
1473 /* Local parameters don't need the ->s3_fns because the struct
1474 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1476 #define FN_LOCAL_STRING(fn_name,val) \
1477 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1478 struct loadparm_service *sDefault) { \
1479 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1482 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1484 #define FN_LOCAL_LIST(fn_name,val) \
1485 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1486 struct loadparm_service *sDefault) {\
1487 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1490 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1492 #define FN_LOCAL_BOOL(fn_name,val) \
1493 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1494 struct loadparm_service *sDefault) { \
1495 return((service != NULL)? service->val : sDefault->val); \
1498 #define FN_LOCAL_INTEGER(fn_name,val) \
1499 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1500 struct loadparm_service *sDefault) { \
1501 return((service != NULL)? service->val : sDefault->val); \
1504 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1506 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1508 #define FN_LOCAL_CHAR(fn_name,val) \
1509 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1510 struct loadparm_service *sDefault) { \
1511 return((service != NULL)? service->val : sDefault->val); \
1514 #include "lib/param/param_functions.c"
1516 /* These functions remain only in lib/param for now */
1517 FN_GLOBAL_BOOL(readraw, bReadRaw)
1518 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1519 FN_GLOBAL_STRING(cachedir, szCacheDir)
1520 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1521 FN_GLOBAL_STRING(statedir, szStateDir)
1523 /* local prototypes */
1524 static int map_parameter(const char *pszParmName);
1525 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1526 const char *pszServiceName);
1527 static void copy_service(struct loadparm_service *pserviceDest,
1528 struct loadparm_service *pserviceSource,
1529 struct bitmap *pcopymapDest);
1530 static bool lpcfg_service_ok(struct loadparm_service *service);
1531 static bool do_section(const char *pszSectionName, void *);
1532 static void init_copymap(struct loadparm_service *pservice);
1534 /* This is a helper function for parametrical options support. */
1535 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1536 /* Actual parametrical functions are quite simple */
1537 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1538 struct loadparm_service *service,
1539 const char *type, const char *option)
1541 char *vfskey_tmp = NULL;
1542 char *vfskey = NULL;
1543 struct parmlist_entry *data;
1548 if (lp_ctx->s3_fns) {
1549 return lp_ctx->s3_fns->get_parametric(service, type, option);
1552 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1554 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1555 if (vfskey_tmp == NULL) return NULL;
1556 vfskey = strlower_talloc(NULL, vfskey_tmp);
1557 talloc_free(vfskey_tmp);
1560 if (strcmp(data->key, vfskey) == 0) {
1561 talloc_free(vfskey);
1567 if (service != NULL) {
1568 /* Try to fetch the same option but from globals */
1569 /* but only if we are not already working with globals */
1570 for (data = lp_ctx->globals->param_opt; data;
1571 data = data->next) {
1572 if (strcmp(data->key, vfskey) == 0) {
1573 talloc_free(vfskey);
1579 talloc_free(vfskey);
1586 * convenience routine to return int parameters.
1588 static int lp_int(const char *s)
1592 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1596 return strtol(s, NULL, 0);
1600 * convenience routine to return unsigned long parameters.
1602 static unsigned long lp_ulong(const char *s)
1606 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
1610 return strtoul(s, NULL, 0);
1614 * convenience routine to return unsigned long parameters.
1616 static long lp_long(const char *s)
1620 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
1624 return strtol(s, NULL, 0);
1628 * convenience routine to return unsigned long parameters.
1630 static double lp_double(const char *s)
1634 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1638 return strtod(s, NULL);
1642 * convenience routine to return boolean parameters.
1644 static bool lp_bool(const char *s)
1649 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1653 if (!set_boolean(s, &ret)) {
1654 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1663 * Return parametric option from a given service. Type is a part of option before ':'
1664 * Parametric option has following syntax: 'Type: option = value'
1665 * Returned value is allocated in 'lp_talloc' context
1668 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1669 struct loadparm_service *service, const char *type,
1672 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1675 return lp_string(value);
1681 * Return parametric option from a given service. Type is a part of option before ':'
1682 * Parametric option has following syntax: 'Type: option = value'
1683 * Returned value is allocated in 'lp_talloc' context
1686 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1687 struct loadparm_context *lp_ctx,
1688 struct loadparm_service *service,
1690 const char *option, const char *separator)
1692 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1695 return (const char **)str_list_make(mem_ctx, value, separator);
1701 * Return parametric option from a given service. Type is a part of option before ':'
1702 * Parametric option has following syntax: 'Type: option = value'
1705 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1706 struct loadparm_service *service, const char *type,
1707 const char *option, int default_v)
1709 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1712 return lp_int(value);
1718 * Return parametric option from a given service. Type is a part of
1719 * option before ':'.
1720 * Parametric option has following syntax: 'Type: option = value'.
1723 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1724 struct loadparm_service *service, const char *type,
1725 const char *option, int default_v)
1729 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1731 if (value && conv_str_size_error(value, &bval)) {
1732 if (bval <= INT_MAX) {
1741 * Return parametric option from a given service.
1742 * Type is a part of option before ':'
1743 * Parametric option has following syntax: 'Type: option = value'
1745 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1746 struct loadparm_service *service, const char *type,
1747 const char *option, unsigned long default_v)
1749 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1752 return lp_ulong(value);
1757 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
1758 struct loadparm_service *service, const char *type,
1759 const char *option, long default_v)
1761 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1764 return lp_long(value);
1769 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1770 struct loadparm_service *service, const char *type,
1771 const char *option, double default_v)
1773 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1776 return lp_double(value);
1782 * Return parametric option from a given service. Type is a part of option before ':'
1783 * Parametric option has following syntax: 'Type: option = value'
1786 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1787 struct loadparm_service *service, const char *type,
1788 const char *option, bool default_v)
1790 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1793 return lp_bool(value);
1800 * Initialise a service to the defaults.
1803 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1805 struct loadparm_service *pservice =
1806 talloc_zero(mem_ctx, struct loadparm_service);
1807 copy_service(pservice, sDefault, NULL);
1812 * Set a string value, deallocating any existing space, and allocing the space
1815 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1822 *dest = talloc_strdup(mem_ctx, src);
1823 if ((*dest) == NULL) {
1824 DEBUG(0,("Out of memory in string_set\n"));
1832 * Set a string value, deallocating any existing space, and allocing the space
1835 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1842 *dest = strupper_talloc(mem_ctx, src);
1843 if ((*dest) == NULL) {
1844 DEBUG(0,("Out of memory in string_set_upper\n"));
1854 * Add a new service to the services array initialising it with the given
1858 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1859 const struct loadparm_service *pservice,
1863 struct loadparm_service tservice;
1864 int num_to_alloc = lp_ctx->iNumServices + 1;
1865 struct parmlist_entry *data, *pdata;
1867 if (pservice == NULL) {
1868 pservice = lp_ctx->sDefault;
1871 tservice = *pservice;
1873 /* it might already exist */
1875 struct loadparm_service *service = getservicebyname(lp_ctx,
1877 if (service != NULL) {
1878 /* Clean all parametric options for service */
1879 /* They will be added during parsing again */
1880 data = service->param_opt;
1886 service->param_opt = NULL;
1891 /* find an invalid one */
1892 for (i = 0; i < lp_ctx->iNumServices; i++)
1893 if (lp_ctx->services[i] == NULL)
1896 /* if not, then create one */
1897 if (i == lp_ctx->iNumServices) {
1898 struct loadparm_service **tsp;
1900 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1903 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1906 lp_ctx->services = tsp;
1907 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1910 lp_ctx->iNumServices++;
1913 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1914 if (lp_ctx->services[i] == NULL) {
1915 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1918 copy_service(lp_ctx->services[i], &tservice, NULL);
1920 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1921 return lp_ctx->services[i];
1925 * Add a new home service, with the specified home directory, defaults coming
1926 * from service ifrom.
1929 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1930 const char *pszHomename,
1931 struct loadparm_service *default_service,
1932 const char *user, const char *pszHomedir)
1934 struct loadparm_service *service;
1936 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1938 if (service == NULL)
1941 if (!(*(default_service->szPath))
1942 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1943 service->szPath = talloc_strdup(service, pszHomedir);
1945 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1948 if (!(*(service->comment))) {
1949 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1951 service->bAvailable = default_service->bAvailable;
1952 service->bBrowseable = default_service->bBrowseable;
1954 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1955 pszHomename, user, service->szPath));
1961 * Add a new printer service, with defaults coming from service iFrom.
1964 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1965 const char *pszPrintername,
1966 struct loadparm_service *default_service)
1968 const char *comment = "From Printcap";
1969 struct loadparm_service *service;
1970 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1972 if (service == NULL)
1975 /* note that we do NOT default the availability flag to True - */
1976 /* we take it from the default service passed. This allows all */
1977 /* dynamic printers to be disabled by disabling the [printers] */
1978 /* entry (if/when the 'available' keyword is implemented!). */
1980 /* the printer name is set to the service name. */
1981 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
1982 lpcfg_string_set(service, &service->comment, comment);
1983 service->bBrowseable = default_service->bBrowseable;
1984 /* Printers cannot be read_only. */
1985 service->bRead_only = false;
1986 /* Printer services must be printable. */
1987 service->bPrint_ok = true;
1989 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1995 * Map a parameter's string representation to something we can use.
1996 * Returns False if the parameter string is not recognised, else TRUE.
1999 static int map_parameter(const char *pszParmName)
2003 if (*pszParmName == '-')
2006 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2007 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2010 /* Warn only if it isn't parametric option */
2011 if (strchr(pszParmName, ':') == NULL)
2012 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2013 /* We do return 'fail' for parametric options as well because they are
2014 stored in different storage
2021 return the parameter structure for a parameter
2023 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2027 if (lp_ctx->s3_fns) {
2028 return lp_ctx->s3_fns->get_parm_struct(name);
2031 parmnum = map_parameter(name);
2032 if (parmnum == -1) return NULL;
2033 return &parm_table[parmnum];
2037 return the parameter pointer for a parameter
2039 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2040 struct loadparm_service *service, struct parm_struct *parm)
2042 if (lp_ctx->s3_fns) {
2043 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2046 if (service == NULL) {
2047 if (parm->p_class == P_LOCAL)
2048 return ((char *)lp_ctx->sDefault)+parm->offset;
2049 else if (parm->p_class == P_GLOBAL)
2050 return ((char *)lp_ctx->globals)+parm->offset;
2053 return ((char *)service) + parm->offset;
2058 return the parameter pointer for a parameter
2060 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2064 if (lp_ctx->s3_fns) {
2065 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2067 return parm->flags & FLAG_CMDLINE;
2072 parmnum = map_parameter(name);
2073 if (parmnum == -1) return false;
2075 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2079 * Find a service by name. Otherwise works like get_service.
2082 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2083 const char *pszServiceName)
2087 if (lp_ctx->s3_fns) {
2088 return lp_ctx->s3_fns->get_service(pszServiceName);
2091 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2092 if (lp_ctx->services[iService] != NULL &&
2093 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2094 return lp_ctx->services[iService];
2101 * Copy a service structure to another.
2102 * If pcopymapDest is NULL then copy all fields
2105 static void copy_service(struct loadparm_service *pserviceDest,
2106 struct loadparm_service *pserviceSource,
2107 struct bitmap *pcopymapDest)
2110 bool bcopyall = (pcopymapDest == NULL);
2111 struct parmlist_entry *data, *pdata, *paramo;
2114 for (i = 0; parm_table[i].label; i++)
2115 if (parm_table[i].p_class == P_LOCAL &&
2116 (bcopyall || bitmap_query(pcopymapDest, i))) {
2118 ((char *)pserviceSource) + parm_table[i].offset;
2120 ((char *)pserviceDest) + parm_table[i].offset;
2122 switch (parm_table[i].type) {
2124 *(bool *)dest_ptr = *(bool *)src_ptr;
2131 *(int *)dest_ptr = *(int *)src_ptr;
2135 lpcfg_string_set(pserviceDest,
2141 lpcfg_string_set_upper(pserviceDest,
2146 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2147 *(const char ***)src_ptr);
2155 init_copymap(pserviceDest);
2156 if (pserviceSource->copymap)
2157 bitmap_copy(pserviceDest->copymap,
2158 pserviceSource->copymap);
2161 data = pserviceSource->param_opt;
2164 pdata = pserviceDest->param_opt;
2165 /* Traverse destination */
2167 /* If we already have same option, override it */
2168 if (strcmp(pdata->key, data->key) == 0) {
2169 talloc_free(pdata->value);
2170 pdata->value = talloc_strdup(pdata,
2175 pdata = pdata->next;
2178 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2181 paramo->key = talloc_strdup(paramo, data->key);
2182 paramo->value = talloc_strdup(paramo, data->value);
2183 DLIST_ADD(pserviceDest->param_opt, paramo);
2190 * Check a service for consistency. Return False if the service is in any way
2191 * incomplete or faulty, else True.
2193 static bool lpcfg_service_ok(struct loadparm_service *service)
2198 if (service->szService[0] == '\0') {
2199 DEBUG(0, ("The following message indicates an internal error:\n"));
2200 DEBUG(0, ("No service name in service entry.\n"));
2204 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2205 /* I can't see why you'd want a non-printable printer service... */
2206 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2207 if (!service->bPrint_ok) {
2208 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2209 service->szService));
2210 service->bPrint_ok = true;
2212 /* [printers] service must also be non-browsable. */
2213 if (service->bBrowseable)
2214 service->bBrowseable = false;
2217 /* If a service is flagged unavailable, log the fact at level 0. */
2218 if (!service->bAvailable)
2219 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2220 service->szService));
2226 /*******************************************************************
2227 Keep a linked list of all config files so we know when one has changed
2228 it's date and needs to be reloaded.
2229 ********************************************************************/
2231 static void add_to_file_list(struct loadparm_context *lp_ctx,
2232 const char *fname, const char *subfname)
2234 struct file_lists *f = lp_ctx->file_lists;
2237 if (f->name && !strcmp(f->name, fname))
2243 f = talloc(lp_ctx, struct file_lists);
2246 f->next = lp_ctx->file_lists;
2247 f->name = talloc_strdup(f, fname);
2252 f->subfname = talloc_strdup(f, subfname);
2257 lp_ctx->file_lists = f;
2258 f->modtime = file_modtime(subfname);
2260 time_t t = file_modtime(subfname);
2266 /*******************************************************************
2267 Check if a config file has changed date.
2268 ********************************************************************/
2269 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2271 struct file_lists *f;
2272 DEBUG(6, ("lp_file_list_changed()\n"));
2274 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2278 n2 = standard_sub_basic(lp_ctx, f->name);
2280 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2281 f->name, n2, ctime(&f->modtime)));
2283 mod_time = file_modtime(n2);
2285 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2286 DEBUGADD(6, ("file %s modified: %s\n", n2,
2288 f->modtime = mod_time;
2289 talloc_free(f->subfname);
2290 f->subfname = talloc_strdup(f, n2);
2297 /***************************************************************************
2298 Handle the "realm" parameter
2299 ***************************************************************************/
2301 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2302 const char *pszParmValue, char **ptr)
2304 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2306 talloc_free(lp_ctx->globals->szRealm_upper);
2307 talloc_free(lp_ctx->globals->szRealm_lower);
2309 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2310 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2315 /***************************************************************************
2316 Handle the include operation.
2317 ***************************************************************************/
2319 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2320 const char *pszParmValue, char **ptr)
2322 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2324 add_to_file_list(lp_ctx, pszParmValue, fname);
2326 lpcfg_string_set(lp_ctx, ptr, fname);
2328 if (file_exist(fname))
2329 return pm_process(fname, do_section, do_parameter, lp_ctx);
2331 DEBUG(2, ("Can't find include file %s\n", fname));
2336 /***************************************************************************
2337 Handle the interpretation of the copy parameter.
2338 ***************************************************************************/
2340 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2341 const char *pszParmValue, char **ptr)
2344 struct loadparm_service *serviceTemp;
2346 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2350 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2352 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2353 if (serviceTemp == lp_ctx->currentService) {
2354 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2356 copy_service(lp_ctx->currentService,
2358 lp_ctx->currentService->copymap);
2362 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2370 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2371 const char *pszParmValue, char **ptr)
2374 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2375 if (lp_ctx->global) {
2376 return debug_parse_levels(pszParmValue);
2381 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2382 const char *pszParmValue, char **ptr)
2384 debug_set_logfile(pszParmValue);
2385 if (lp_ctx->global) {
2386 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2391 /***************************************************************************
2392 Initialise a copymap.
2393 ***************************************************************************/
2395 static void init_copymap(struct loadparm_service *pservice)
2399 TALLOC_FREE(pservice->copymap);
2401 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2402 if (!pservice->copymap)
2404 ("Couldn't allocate copymap!! (size %d)\n",
2405 (int)NUMPARAMETERS));
2407 for (i = 0; i < NUMPARAMETERS; i++)
2408 bitmap_set(pservice->copymap, i);
2412 * Process a parametric option
2414 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2415 struct loadparm_service *service,
2416 const char *pszParmName,
2417 const char *pszParmValue, int flags)
2419 struct parmlist_entry *paramo, *data;
2421 TALLOC_CTX *mem_ctx;
2423 while (isspace((unsigned char)*pszParmName)) {
2427 name = strlower_talloc(lp_ctx, pszParmName);
2428 if (!name) return false;
2430 if (service == NULL) {
2431 data = lp_ctx->globals->param_opt;
2432 mem_ctx = lp_ctx->globals;
2434 data = service->param_opt;
2438 /* Traverse destination */
2439 for (paramo=data; paramo; paramo=paramo->next) {
2440 /* If we already have the option set, override it unless
2441 it was a command line option and the new one isn't */
2442 if (strcmp(paramo->key, name) == 0) {
2443 if ((paramo->priority & FLAG_CMDLINE) &&
2444 !(flags & FLAG_CMDLINE)) {
2449 talloc_free(paramo->value);
2450 paramo->value = talloc_strdup(paramo, pszParmValue);
2451 paramo->priority = flags;
2457 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2460 paramo->key = talloc_strdup(paramo, name);
2461 paramo->value = talloc_strdup(paramo, pszParmValue);
2462 paramo->priority = flags;
2463 if (service == NULL) {
2464 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2466 DLIST_ADD(service->param_opt, paramo);
2474 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2475 const char *pszParmName, const char *pszParmValue,
2476 struct loadparm_context *lp_ctx, bool on_globals)
2479 /* if it is a special case then go ahead */
2480 if (parm_table[parmnum].special) {
2482 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2487 goto mark_non_default;
2490 /* now switch on the type of variable it is */
2491 switch (parm_table[parmnum].type)
2495 if (!set_boolean(pszParmValue, &b)) {
2496 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2499 *(bool *)parm_ptr = b;
2505 if (!set_boolean(pszParmValue, &b)) {
2506 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2509 *(bool *)parm_ptr = !b;
2514 *(int *)parm_ptr = atoi(pszParmValue);
2518 *(char *)parm_ptr = *pszParmValue;
2522 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2528 if (conv_str_size_error(pszParmValue, &val)) {
2529 if (val <= INT_MAX) {
2530 *(int *)parm_ptr = (int)val;
2535 DEBUG(0,("lp_do_parameter(%s): value is not "
2536 "a valid size specifier!\n", pszParmValue));
2541 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2542 pszParmValue, NULL);
2546 char **new_list = str_list_make(mem_ctx,
2547 pszParmValue, NULL);
2548 for (i=0; new_list[i]; i++) {
2549 if (new_list[i][0] == '+' && new_list[i][1]) {
2550 if (!str_list_check(*(const char ***)parm_ptr,
2552 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2555 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2556 str_list_remove(*(const char ***)parm_ptr,
2560 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2561 pszParmName, pszParmValue));
2564 *(const char ***)parm_ptr = (const char **) new_list;
2571 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2575 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2579 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2582 parm_table[parmnum].enum_list[i].name)) {
2584 parm_table[parmnum].
2589 if (!parm_table[parmnum].enum_list[i].name) {
2590 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2591 pszParmValue, pszParmName));
2601 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2602 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2603 /* we have to also unset FLAG_DEFAULT on aliases */
2604 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2605 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2607 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2608 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2615 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2616 const char *pszParmName, const char *pszParmValue)
2618 int parmnum = map_parameter(pszParmName);
2622 if (strchr(pszParmName, ':')) {
2623 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2625 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2629 /* if the flag has been set on the command line, then don't allow override,
2630 but don't report an error */
2631 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2635 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2637 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2638 pszParmName, pszParmValue, lp_ctx, true);
2641 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2642 struct loadparm_service *service,
2643 const char *pszParmName, const char *pszParmValue)
2647 int parmnum = map_parameter(pszParmName);
2650 if (strchr(pszParmName, ':')) {
2651 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2653 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2657 /* if the flag has been set on the command line, then don't allow override,
2658 but don't report an error */
2659 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2663 if (parm_table[parmnum].p_class == P_GLOBAL) {
2665 ("Global parameter %s found in service section!\n",
2669 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2671 if (!service->copymap)
2672 init_copymap(service);
2674 /* this handles the aliases - set the copymap for other
2675 * entries with the same data pointer */
2676 for (i = 0; parm_table[i].label; i++)
2677 if (parm_table[i].offset == parm_table[parmnum].offset &&
2678 parm_table[i].p_class == parm_table[parmnum].p_class)
2679 bitmap_clear(service->copymap, i);
2681 return set_variable(service, parmnum, parm_ptr, pszParmName,
2682 pszParmValue, lp_ctx, false);
2686 * Process a parameter.
2689 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2692 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2694 if (lp_ctx->bInGlobalSection)
2695 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2698 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2699 pszParmName, pszParmValue);
2703 variable argument do parameter
2705 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2706 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2707 const char *pszParmName, const char *fmt, ...)
2714 s = talloc_vasprintf(NULL, fmt, ap);
2716 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2723 set a parameter from the commandline - this is called from command line parameter
2724 parsing code. It sets the parameter then marks the parameter as unable to be modified
2725 by smb.conf processing
2727 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2728 const char *pszParmValue)
2733 if (lp_ctx->s3_fns) {
2734 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2737 parmnum = map_parameter(pszParmName);
2739 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2742 if (parmnum < 0 && strchr(pszParmName, ':')) {
2743 /* set a parametric option */
2744 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2745 pszParmValue, FLAG_CMDLINE);
2749 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2753 /* reset the CMDLINE flag in case this has been called before */
2754 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2756 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2760 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2762 /* we have to also set FLAG_CMDLINE on aliases */
2763 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2764 lp_ctx->flags[i] |= FLAG_CMDLINE;
2766 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2767 lp_ctx->flags[i] |= FLAG_CMDLINE;
2774 set a option from the commandline in 'a=b' format. Use to support --option
2776 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2781 s = talloc_strdup(NULL, option);
2794 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2800 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2803 * Print a parameter of the specified type.
2806 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2808 /* For the seperation of lists values that we print below */
2809 const char *list_sep = ", ";
2814 for (i = 0; p->enum_list[i].name; i++) {
2815 if (*(int *)ptr == p->enum_list[i].value) {
2817 p->enum_list[i].name);
2824 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2828 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2833 fprintf(f, "%d", *(int *)ptr);
2837 fprintf(f, "%c", *(char *)ptr);
2841 int val = *(int *)ptr;
2845 fprintf(f, "0%o", val);
2854 if ((char ***)ptr && *(char ***)ptr) {
2855 char **list = *(char ***)ptr;
2856 for (; *list; list++) {
2857 /* surround strings with whitespace in double quotes */
2858 if (*(list+1) == NULL) {
2859 /* last item, no extra separator */
2862 if ( strchr_m( *list, ' ' ) ) {
2863 fprintf(f, "\"%s\"%s", *list, list_sep);
2865 fprintf(f, "%s%s", *list, list_sep);
2873 if (*(char **)ptr) {
2874 fprintf(f, "%s", *(char **)ptr);
2883 * Check if two parameters are equal.
2886 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2891 return (*((bool *)ptr1) == *((bool *)ptr2));
2897 return (*((int *)ptr1) == *((int *)ptr2));
2900 return (*((char *)ptr1) == *((char *)ptr2));
2904 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2909 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2914 return (p1 == p2 || strequal(p1, p2));
2923 * Process a new section (service).
2925 * At this stage all sections are services.
2926 * Later we'll have special sections that permit server parameters to be set.
2927 * Returns True on success, False on failure.
2930 static bool do_section(const char *pszSectionName, void *userdata)
2932 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2934 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2935 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2938 /* if we've just struck a global section, note the fact. */
2939 lp_ctx->bInGlobalSection = isglobal;
2941 /* check for multiple global sections */
2942 if (lp_ctx->bInGlobalSection) {
2943 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2947 /* if we have a current service, tidy it up before moving on */
2950 if (lp_ctx->currentService != NULL)
2951 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2953 /* if all is still well, move to the next record in the services array */
2955 /* We put this here to avoid an odd message order if messages are */
2956 /* issued by the post-processing of a previous section. */
2957 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2959 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2962 DEBUG(0, ("Failed to add a new service\n"));
2972 * Determine if a particular base parameter is currently set to the default value.
2975 static bool is_default(struct loadparm_service *sDefault, int i)
2977 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2978 if (!defaults_saved)
2980 switch (parm_table[i].type) {
2983 return str_list_equal((const char **)parm_table[i].def.lvalue,
2984 (const char **)def_ptr);
2987 return strequal(parm_table[i].def.svalue,
2991 return parm_table[i].def.bvalue ==
2998 return parm_table[i].def.ivalue ==
3007 *Display the contents of the global structure.
3010 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3014 struct parmlist_entry *data;
3016 fprintf(f, "# Global parameters\n[global]\n");
3018 for (i = 0; parm_table[i].label; i++)
3019 if (parm_table[i].p_class == P_GLOBAL &&
3020 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3021 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3023 fprintf(f, "\t%s = ", parm_table[i].label);
3024 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3027 if (lp_ctx->globals->param_opt != NULL) {
3028 for (data = lp_ctx->globals->param_opt; data;
3029 data = data->next) {
3030 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3033 fprintf(f, "\t%s = %s\n", data->key, data->value);
3040 * Display the contents of a single services record.
3043 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3044 unsigned int *flags)
3047 struct parmlist_entry *data;
3049 if (pService != sDefault)
3050 fprintf(f, "\n[%s]\n", pService->szService);
3052 for (i = 0; parm_table[i].label; i++) {
3053 if (parm_table[i].p_class == P_LOCAL &&
3054 (*parm_table[i].label != '-') &&
3055 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3057 if (pService == sDefault) {
3058 if (flags && (flags[i] & FLAG_DEFAULT)) {
3061 if (defaults_saved) {
3062 if (is_default(sDefault, i)) {
3067 if (equal_parameter(parm_table[i].type,
3068 ((char *)pService) +
3069 parm_table[i].offset,
3070 ((char *)sDefault) +
3071 parm_table[i].offset))
3075 fprintf(f, "\t%s = ", parm_table[i].label);
3076 print_parameter(&parm_table[i],
3077 ((char *)pService) + parm_table[i].offset, f);
3081 if (pService->param_opt != NULL) {
3082 for (data = pService->param_opt; data; data = data->next) {
3083 fprintf(f, "\t%s = %s\n", data->key, data->value);
3088 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3089 struct loadparm_service *service,
3090 const char *parm_name, FILE * f)
3092 struct parm_struct *parm;
3095 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3100 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3102 print_parameter(parm, ptr, f);
3108 * Return info about the next parameter in a service.
3109 * snum==-1 gives the globals.
3110 * Return NULL when out of parameters.
3114 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3118 /* do the globals */
3119 for (; parm_table[*i].label; (*i)++) {
3120 if ((*parm_table[*i].label == '-'))
3124 && (parm_table[*i].offset ==
3125 parm_table[(*i) - 1].offset)
3126 && (parm_table[*i].p_class ==
3127 parm_table[(*i) - 1].p_class))
3130 return &parm_table[(*i)++];
3133 struct loadparm_service *pService = lp_ctx->services[snum];
3135 for (; parm_table[*i].label; (*i)++) {
3136 if (parm_table[*i].p_class == P_LOCAL &&
3137 (*parm_table[*i].label != '-') &&
3139 (parm_table[*i].offset !=
3140 parm_table[(*i) - 1].offset)))
3142 if (allparameters ||
3143 !equal_parameter(parm_table[*i].type,
3144 ((char *)pService) +
3145 parm_table[*i].offset,
3146 ((char *)lp_ctx->sDefault) +
3147 parm_table[*i].offset))
3149 return &parm_table[(*i)++];
3160 * Auto-load some home services.
3162 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3170 * Unload unused services.
3173 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3174 struct smbsrv_connection *smb,
3175 bool (*snumused) (struct smbsrv_connection *, int))
3178 for (i = 0; i < lp_ctx->iNumServices; i++) {
3179 if (lp_ctx->services[i] == NULL)
3182 if (!snumused || !snumused(smb, i)) {
3183 talloc_free(lp_ctx->services[i]);
3184 lp_ctx->services[i] = NULL;
3190 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3192 struct parmlist_entry *data;
3194 if (lp_ctx->refuse_free) {
3195 /* someone is trying to free the
3196 global_loadparm_context.
3197 We can't allow that. */
3201 if (lp_ctx->globals->param_opt != NULL) {
3202 struct parmlist_entry *next;
3203 for (data = lp_ctx->globals->param_opt; data; data=next) {
3205 if (data->priority & FLAG_CMDLINE) continue;
3206 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3215 * Initialise the global parameter structure.
3217 * Note that most callers should use loadparm_init_global() instead
3219 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3223 struct loadparm_context *lp_ctx;
3224 struct parmlist_entry *parm;
3227 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3231 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3232 lp_ctx->bInGlobalSection = true;
3233 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3234 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3236 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3237 lp_ctx->sDefault->bAvailable = true;
3238 lp_ctx->sDefault->bBrowseable = true;
3239 lp_ctx->sDefault->bRead_only = true;
3240 lp_ctx->sDefault->bMap_archive = true;
3241 lp_ctx->sDefault->iStrictLocking = true;
3242 lp_ctx->sDefault->bOpLocks = true;
3243 lp_ctx->sDefault->iCreate_mask = 0744;
3244 lp_ctx->sDefault->iCreate_force_mode = 0000;
3245 lp_ctx->sDefault->iDir_mask = 0755;
3246 lp_ctx->sDefault->iDir_force_mode = 0000;
3248 DEBUG(3, ("Initialising global parameters\n"));
3250 for (i = 0; parm_table[i].label; i++) {
3251 if ((parm_table[i].type == P_STRING ||
3252 parm_table[i].type == P_USTRING) &&
3253 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3255 if (parm_table[i].p_class == P_LOCAL) {
3256 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3258 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3260 *r = talloc_strdup(lp_ctx, "");
3264 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3265 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3266 talloc_free(logfile);
3268 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3270 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3272 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3273 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3274 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3276 /* options that can be set on the command line must be initialised via
3277 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3279 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3281 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3282 myname = get_myname(lp_ctx);
3283 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3284 talloc_free(myname);
3285 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3287 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3289 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3290 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3292 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
3293 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3294 /* the winbind method for domain controllers is for both RODC
3295 auth forwarding and for trusted domains */
3296 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3297 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3299 /* This hive should be dynamically generated by Samba using
3300 data from the sam, but for the moment leave it in a tdb to
3301 keep regedt32 from popping up an annoying dialog. */
3302 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3304 /* using UTF8 by default allows us to support all chars */
3305 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3307 /* Use codepage 850 as a default for the dos character set */
3308 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3311 * Allow the default PASSWD_CHAT to be overridden in local.h.
3313 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3315 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3316 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3317 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3318 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3319 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3321 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3322 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3323 "Samba %s", SAMBA_VERSION_STRING);
3325 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3327 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3328 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3329 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3331 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3332 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3333 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3334 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3335 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3336 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3337 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3338 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3339 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3340 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3341 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3342 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3343 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3345 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3346 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3347 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3348 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3349 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3350 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3351 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3352 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3354 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3356 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3357 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3359 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3360 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3362 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3363 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3364 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3365 #if _SAMBA_BUILD_ >= 4
3366 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3367 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3368 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3369 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3370 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3371 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3373 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3374 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3376 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3377 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3379 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3381 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3383 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3384 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3385 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3386 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3387 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3388 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3389 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3391 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3393 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3394 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3396 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3397 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3398 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3399 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3400 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3402 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3403 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3405 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3406 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3407 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3409 for (i = 0; parm_table[i].label; i++) {
3410 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3411 lp_ctx->flags[i] |= FLAG_DEFAULT;
3415 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3416 if (!(parm->priority & FLAG_CMDLINE)) {
3417 parm->priority |= FLAG_DEFAULT;
3425 * Initialise the global parameter structure.
3427 struct loadparm_context *loadparm_init_global(bool load_default)
3429 if (global_loadparm_context == NULL) {
3430 global_loadparm_context = loadparm_init(NULL);
3432 if (global_loadparm_context == NULL) {
3435 global_loadparm_context->global = true;
3436 if (load_default && !global_loadparm_context->loaded) {
3437 lpcfg_load_default(global_loadparm_context);
3439 global_loadparm_context->refuse_free = true;
3440 return global_loadparm_context;
3444 * Initialise the global parameter structure.
3446 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3447 const struct loadparm_s3_helpers *s3_fns)
3449 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3450 if (!loadparm_context) {
3453 loadparm_context->s3_fns = s3_fns;
3454 return loadparm_context;
3457 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3459 return lp_ctx->szConfigFile;
3462 const char *lp_default_path(void)
3464 if (getenv("SMB_CONF_PATH"))
3465 return getenv("SMB_CONF_PATH");
3467 return dyn_CONFIGFILE;
3471 * Update the internal state of a loadparm context after settings
3474 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3476 struct debug_settings settings;
3477 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3479 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3480 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3483 if (!lp_ctx->global) {
3487 panic_action = lp_ctx->globals->panic_action;
3489 reload_charcnv(lp_ctx);
3491 ZERO_STRUCT(settings);
3492 /* Add any more debug-related smb.conf parameters created in
3494 settings.timestamp_logs = true;
3495 debug_set_settings(&settings);
3497 /* FIXME: This is a bit of a hack, but we can't use a global, since
3498 * not everything that uses lp also uses the socket library */
3499 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3500 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3502 unsetenv("SOCKET_TESTNONBLOCK");
3508 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3512 path = lp_default_path();
3514 if (!file_exist(path)) {
3515 /* We allow the default smb.conf file to not exist,
3516 * basically the equivalent of an empty file. */
3517 return lpcfg_update(lp_ctx);
3520 return lpcfg_load(lp_ctx, path);
3524 * Load the services array from the services file.
3526 * Return True on success, False on failure.
3528 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3533 filename = talloc_strdup(lp_ctx, filename);
3535 lp_ctx->szConfigFile = filename;
3537 if (lp_ctx->s3_fns) {
3538 return lp_ctx->s3_fns->load(filename);
3541 lp_ctx->bInGlobalSection = true;
3542 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3543 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3545 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3547 /* We get sections first, so have to start 'behind' to make up */
3548 lp_ctx->currentService = NULL;
3549 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3551 /* finish up the last section */
3552 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3554 if (lp_ctx->currentService != NULL)
3555 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3557 bRetval = bRetval && lpcfg_update(lp_ctx);
3559 /* we do this unconditionally, so that it happens even
3560 for a missing smb.conf */
3561 reload_charcnv(lp_ctx);
3563 if (bRetval == true) {
3564 /* set this up so that any child python tasks will
3565 find the right smb.conf */
3566 setenv("SMB_CONF_PATH", filename, 1);
3568 /* set the context used by the lp_*() function
3570 global_loadparm_context = lp_ctx;
3571 lp_ctx->loaded = true;
3578 * Return the max number of services.
3581 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3583 if (lp_ctx->s3_fns) {
3584 return lp_ctx->s3_fns->get_numservices();
3587 return lp_ctx->iNumServices;
3591 * Display the contents of the services array in human-readable form.
3594 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3599 if (lp_ctx->s3_fns) {
3600 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3604 defaults_saved = !show_defaults;
3606 dump_globals(lp_ctx, f, show_defaults);
3608 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3610 for (iService = 0; iService < maxtoprint; iService++)
3611 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3615 * Display the contents of one service in human-readable form.
3617 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3619 if (service != NULL) {
3620 if (service->szService[0] == '\0')
3622 dump_a_service(service, sDefault, f, NULL);
3626 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3629 if (lp_ctx->s3_fns) {
3630 return lp_ctx->s3_fns->get_servicebynum(snum);
3633 return lp_ctx->services[snum];
3636 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3637 const char *service_name)
3642 if (lp_ctx->s3_fns) {
3643 return lp_ctx->s3_fns->get_service(service_name);
3646 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3647 if (lp_ctx->services[iService] &&
3648 lp_ctx->services[iService]->szService) {
3650 * The substitution here is used to support %U is
3653 serviceName = standard_sub_basic(
3654 lp_ctx->services[iService],
3655 lp_ctx->services[iService]->szService);
3656 if (strequal(serviceName, service_name)) {
3657 talloc_free(serviceName);
3658 return lp_ctx->services[iService];
3660 talloc_free(serviceName);
3664 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3668 const char *lpcfg_servicename(const struct loadparm_service *service)
3670 return lp_string((const char *)service->szService);
3674 * A useful volume label function.
3676 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3679 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3680 service->volume : sDefault->volume));
3682 return lpcfg_servicename(service);
3687 * If we are PDC then prefer us as DMB
3689 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3692 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3693 service->szPrintername : sDefault->szPrintername));
3694 if (ret == NULL || (ret != NULL && *ret == '\0'))
3695 ret = lpcfg_servicename(service);
3702 * Return the max print jobs per queue.
3704 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3706 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3707 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3708 maxjobs = PRINT_MAX_JOBID - 1;
3713 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3715 if (lp_ctx == NULL) {
3716 return get_iconv_handle();
3718 return lp_ctx->iconv_handle;
3721 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3723 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3724 if (!lp_ctx->global) {
3728 if (old_ic == NULL) {
3729 old_ic = global_iconv_handle;
3731 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3732 global_iconv_handle = lp_ctx->iconv_handle;
3735 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3737 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3740 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3742 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3745 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3747 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3750 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3752 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3755 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3757 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3760 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3762 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3763 if (settings == NULL)
3765 SMB_ASSERT(lp_ctx != NULL);
3766 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3767 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3771 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3773 if (lp_ctx->s3_fns) {
3774 return lp_ctx->s3_fns->server_role();
3777 return lp_find_server_role(lp_ctx->globals->server_role,
3778 lp_ctx->globals->security,
3779 lp_ctx->globals->domain_logons,
3780 (lp_ctx->globals->domain_master == true) ||
3781 (lp_ctx->globals->domain_master == Auto));
3784 int lpcfg_security(struct loadparm_context *lp_ctx)
3786 if (lp_ctx->s3_fns) {
3787 return lp_ctx->s3_fns->security();
3790 return lp_find_security(lp_ctx->globals->server_role,
3791 lp_ctx->globals->security);