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
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * This module provides suitable callback functions for the params
33 * module. It builds the internal table of service details which is
34 * then used by the rest of the server.
38 * 1) add it to the global or service structure definition
39 * 2) add it to the parm_table
40 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
41 * 4) If it's a global then initialise it in init_globals. If a local
42 * (ie. service) parameter then initialise it in the sDefault structure
46 * The configuration file is processed sequentially for speed. It is NOT
47 * accessed randomly as happens in 'real' Windows. For this reason, there
48 * is a fair bit of sequence-dependent code here - ie., code which assumes
49 * that certain things happen before others. In particular, the code which
50 * happens at the boundary between sections is delicately poised, so be
57 #include "dynconfig/dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "../lib/util/dlinklist.h"
62 #include "lib/param/param.h"
63 #include "lib/param/loadparm.h"
64 #include "auth/gensec/gensec.h"
66 #include "lib/util/bitmap.h"
67 #include "libcli/smb/smb_constants.h"
69 #define standard_sub_basic talloc_strdup
71 static bool do_parameter(const char *, const char *, void *);
72 static bool defaults_saved = false;
74 #define LOADPARM_EXTRA_GLOBALS \
75 struct parmlist_entry *param_opt; \
86 #include "param_global.h"
88 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
91 /* prototypes for the special type handlers */
92 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
93 const char *pszParmValue, char **ptr);
94 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
95 const char *pszParmValue, char **ptr);
96 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
97 const char *pszParmValue, char **ptr);
98 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
99 const char *pszParmValue, char **ptr);
100 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
101 const char *pszParmValue, char **ptr);
103 static const struct enum_list enum_protocol[] = {
104 {PROTOCOL_SMB2_02, "SMB2"},
105 {PROTOCOL_SMB2_02, "SMB2_02"},
106 {PROTOCOL_NT1, "NT1"},
107 {PROTOCOL_LANMAN2, "LANMAN2"},
108 {PROTOCOL_LANMAN1, "LANMAN1"},
109 {PROTOCOL_CORE, "CORE"},
110 {PROTOCOL_COREPLUS, "COREPLUS"},
111 {PROTOCOL_COREPLUS, "CORE+"},
115 static const struct enum_list enum_security[] = {
116 {SEC_SHARE, "SHARE"},
122 static const struct enum_list enum_bool_auto[] = {
133 /* Client-side offline caching policy types */
135 static const struct enum_list enum_csc_policy[] = {
136 {CSC_POLICY_MANUAL, "manual"},
137 {CSC_POLICY_DOCUMENTS, "documents"},
138 {CSC_POLICY_PROGRAMS, "programs"},
139 {CSC_POLICY_DISABLE, "disable"},
143 /* SMB signing types. */
144 static const struct enum_list enum_smb_signing_vals[] = {
145 {SMB_SIGNING_DEFAULT, "default"},
146 {SMB_SIGNING_OFF, "No"},
147 {SMB_SIGNING_OFF, "False"},
148 {SMB_SIGNING_OFF, "0"},
149 {SMB_SIGNING_OFF, "Off"},
150 {SMB_SIGNING_OFF, "disabled"},
151 {SMB_SIGNING_IF_REQUIRED, "if_required"},
152 {SMB_SIGNING_IF_REQUIRED, "Yes"},
153 {SMB_SIGNING_IF_REQUIRED, "True"},
154 {SMB_SIGNING_IF_REQUIRED, "1"},
155 {SMB_SIGNING_IF_REQUIRED, "On"},
156 {SMB_SIGNING_IF_REQUIRED, "enabled"},
157 {SMB_SIGNING_IF_REQUIRED, "auto"},
158 {SMB_SIGNING_REQUIRED, "required"},
159 {SMB_SIGNING_REQUIRED, "mandatory"},
160 {SMB_SIGNING_REQUIRED, "force"},
161 {SMB_SIGNING_REQUIRED, "forced"},
162 {SMB_SIGNING_REQUIRED, "enforced"},
166 /* Server role options */
167 static const struct enum_list enum_server_role[] = {
169 {ROLE_STANDALONE, "standalone"},
170 {ROLE_DOMAIN_MEMBER, "member server"},
171 {ROLE_DOMAIN_MEMBER, "member"},
172 /* note that currently
173 ROLE_DOMAIN_CONTROLLER == ROLE_DOMAIN_BDC */
174 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
175 {ROLE_DOMAIN_BDC, "backup domain controller"},
176 {ROLE_DOMAIN_BDC, "bdc"},
177 {ROLE_DOMAIN_BDC, "dc"},
178 {ROLE_DOMAIN_PDC, "primary domain controller"},
179 {ROLE_DOMAIN_PDC, "pdc"},
183 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
184 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
186 static struct parm_struct parm_table[] = {
188 .label = "server role",
191 .offset = GLOBAL_VAR(server_role),
193 .enum_list = enum_server_role
196 .label = "domain logons",
199 .offset = GLOBAL_VAR(domain_logons),
201 .enum_list = enum_bool_auto
204 .label = "domain master",
207 .offset = GLOBAL_VAR(domain_master),
209 .enum_list = enum_bool_auto
212 .label = "dos charset",
215 .offset = GLOBAL_VAR(dos_charset),
220 .label = "unix charset",
223 .offset = GLOBAL_VAR(unix_charset),
228 .label = "ncalrpc dir",
231 .offset = GLOBAL_VAR(ncalrpc_dir),
239 .offset = LOCAL_VAR(comment),
247 .offset = LOCAL_VAR(szPath),
252 .label = "directory",
255 .offset = LOCAL_VAR(szPath),
260 .label = "workgroup",
263 .offset = GLOBAL_VAR(szWorkgroup),
271 .offset = GLOBAL_VAR(szRealm),
272 .special = handle_realm,
276 .label = "netbios name",
279 .offset = GLOBAL_VAR(szNetbiosName),
284 .label = "netbios aliases",
287 .offset = GLOBAL_VAR(szNetbiosAliases),
292 .label = "netbios scope",
295 .offset = GLOBAL_VAR(szNetbiosScope),
300 .label = "server string",
303 .offset = GLOBAL_VAR(szServerString),
308 .label = "interfaces",
311 .offset = GLOBAL_VAR(szInterfaces),
316 .label = "bind interfaces only",
319 .offset = GLOBAL_VAR(bBindInterfacesOnly),
324 .label = "ntvfs handler",
327 .offset = LOCAL_VAR(ntvfs_handler),
332 .label = "ntptr providor",
335 .offset = GLOBAL_VAR(ntptr_providor),
340 .label = "passdb backend",
343 .offset = GLOBAL_VAR(passdb_backend),
348 .label = "dcerpc endpoint servers",
351 .offset = GLOBAL_VAR(dcerpc_ep_servers),
356 .label = "server services",
359 .offset = GLOBAL_VAR(server_services),
368 .offset = GLOBAL_VAR(security),
370 .enum_list = enum_security
373 .label = "encrypt passwords",
376 .offset = GLOBAL_VAR(bEncryptPasswords),
381 .label = "null passwords",
384 .offset = GLOBAL_VAR(bNullPasswords),
389 .label = "obey pam restrictions",
392 .offset = GLOBAL_VAR(bObeyPamRestrictions),
397 .label = "password server",
400 .offset = GLOBAL_VAR(szPasswordServers),
405 .label = "private dir",
408 .offset = GLOBAL_VAR(szPrivateDir),
413 .label = "passwd chat",
416 .offset = GLOBAL_VAR(szPasswdChat),
421 .label = "password level",
424 .offset = GLOBAL_VAR(pwordlevel),
429 .label = "lanman auth",
432 .offset = GLOBAL_VAR(bLanmanAuth),
437 .label = "ntlm auth",
440 .offset = GLOBAL_VAR(bNTLMAuth),
445 .label = "client NTLMv2 auth",
448 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
453 .label = "client lanman auth",
456 .offset = GLOBAL_VAR(bClientLanManAuth),
461 .label = "client plaintext auth",
464 .offset = GLOBAL_VAR(bClientPlaintextAuth),
469 .label = "client use spnego principal",
472 .offset = GLOBAL_VAR(client_use_spnego_principal),
478 .label = "read only",
481 .offset = LOCAL_VAR(bRead_only),
487 .label = "create mask",
490 .offset = LOCAL_VAR(iCreate_mask),
495 .label = "force create mode",
498 .offset = LOCAL_VAR(iCreate_force_mode),
503 .label = "directory mask",
506 .offset = LOCAL_VAR(iDir_mask),
511 .label = "force directory mode",
514 .offset = LOCAL_VAR(iDir_force_mode),
520 .label = "hosts allow",
523 .offset = LOCAL_VAR(szHostsallow),
528 .label = "hosts deny",
531 .offset = LOCAL_VAR(szHostsdeny),
537 .label = "log level",
540 .offset = GLOBAL_VAR(loglevel),
541 .special = handle_debuglevel,
545 .label = "debuglevel",
548 .offset = GLOBAL_VAR(loglevel),
549 .special = handle_debuglevel,
556 .offset = GLOBAL_VAR(logfile),
557 .special = handle_logfile,
562 .label = "smb ports",
565 .offset = GLOBAL_VAR(smb_ports),
573 .offset = GLOBAL_VAR(nbt_port),
578 .label = "dgram port",
581 .offset = GLOBAL_VAR(dgram_port),
586 .label = "cldap port",
589 .offset = GLOBAL_VAR(cldap_port),
594 .label = "krb5 port",
597 .offset = GLOBAL_VAR(krb5_port),
602 .label = "kpasswd port",
605 .offset = GLOBAL_VAR(kpasswd_port),
613 .offset = GLOBAL_VAR(web_port),
618 .label = "tls enabled",
621 .offset = GLOBAL_VAR(tls_enabled),
626 .label = "tls keyfile",
629 .offset = GLOBAL_VAR(tls_keyfile),
634 .label = "tls certfile",
637 .offset = GLOBAL_VAR(tls_certfile),
642 .label = "tls cafile",
645 .offset = GLOBAL_VAR(tls_cafile),
650 .label = "tls crlfile",
653 .offset = GLOBAL_VAR(tls_crlfile),
658 .label = "tls dh params file",
661 .offset = GLOBAL_VAR(tls_dhpfile),
666 .label = "large readwrite",
669 .offset = GLOBAL_VAR(bLargeReadwrite),
674 .label = "server max protocol",
677 .offset = GLOBAL_VAR(srv_maxprotocol),
679 .enum_list = enum_protocol
682 .label = "server min protocol",
685 .offset = GLOBAL_VAR(srv_minprotocol),
687 .enum_list = enum_protocol
690 .label = "client max protocol",
693 .offset = GLOBAL_VAR(cli_maxprotocol),
695 .enum_list = enum_protocol
698 .label = "client min protocol",
701 .offset = GLOBAL_VAR(cli_minprotocol),
703 .enum_list = enum_protocol
709 .offset = GLOBAL_VAR(bUnicode),
717 .offset = GLOBAL_VAR(bReadRaw),
722 .label = "write raw",
725 .offset = GLOBAL_VAR(bWriteRaw),
730 .label = "disable netbios",
733 .offset = GLOBAL_VAR(bDisableNetbios),
739 .label = "nt status support",
742 .offset = GLOBAL_VAR(bNTStatusSupport),
751 .offset = GLOBAL_VAR(max_mux),
759 .offset = GLOBAL_VAR(max_xmit),
765 .label = "name resolve order",
768 .offset = GLOBAL_VAR(szNameResolveOrder),
773 .label = "max wins ttl",
776 .offset = GLOBAL_VAR(max_wins_ttl),
781 .label = "min wins ttl",
784 .offset = GLOBAL_VAR(min_wins_ttl),
789 .label = "time server",
792 .offset = GLOBAL_VAR(bTimeServer),
797 .label = "unix extensions",
800 .offset = GLOBAL_VAR(bUnixExtensions),
805 .label = "use spnego",
808 .offset = GLOBAL_VAR(bUseSpnego),
813 .label = "server signing",
816 .offset = GLOBAL_VAR(server_signing),
818 .enum_list = enum_smb_signing_vals
821 .label = "client signing",
824 .offset = GLOBAL_VAR(client_signing),
826 .enum_list = enum_smb_signing_vals
829 .label = "rpc big endian",
832 .offset = GLOBAL_VAR(bRpcBigEndian),
838 .label = "max connections",
841 .offset = LOCAL_VAR(iMaxConnections),
846 .label = "paranoid server security",
849 .offset = GLOBAL_VAR(paranoid_server_security),
854 .label = "socket options",
857 .offset = GLOBAL_VAR(socket_options),
863 .label = "strict sync",
866 .offset = LOCAL_VAR(bStrictSync),
874 .offset = GLOBAL_VAR(bUseMmap),
877 .flags = FLAG_ADVANCED,
880 .label = "case insensitive filesystem",
883 .offset = LOCAL_VAR(bCIFileSystem),
889 .label = "max print jobs",
892 .offset = LOCAL_VAR(iMaxPrintJobs),
897 .label = "printable",
900 .offset = LOCAL_VAR(bPrint_ok),
908 .offset = LOCAL_VAR(bPrint_ok),
914 .label = "printer name",
917 .offset = LOCAL_VAR(szPrintername),
925 .offset = LOCAL_VAR(szPrintername),
931 .label = "map system",
934 .offset = LOCAL_VAR(bMap_system),
939 .label = "map hidden",
942 .offset = LOCAL_VAR(bMap_hidden),
947 .label = "map archive",
950 .offset = LOCAL_VAR(bMap_archive),
956 .label = "preferred master",
959 .offset = GLOBAL_VAR(bPreferredMaster),
961 .enum_list = enum_bool_auto
964 .label = "prefered master",
967 .offset = GLOBAL_VAR(bPreferredMaster),
969 .enum_list = enum_bool_auto
972 .label = "local master",
975 .offset = GLOBAL_VAR(bLocalMaster),
980 .label = "browseable",
983 .offset = LOCAL_VAR(bBrowseable),
988 .label = "browsable",
991 .offset = LOCAL_VAR(bBrowseable),
997 .label = "wins server",
1000 .offset = GLOBAL_VAR(szWINSservers),
1005 .label = "wins support",
1007 .p_class = P_GLOBAL,
1008 .offset = GLOBAL_VAR(bWINSsupport),
1013 .label = "dns proxy",
1015 .p_class = P_GLOBAL,
1016 .offset = GLOBAL_VAR(bWINSdnsProxy),
1021 .label = "wins hook",
1023 .p_class = P_GLOBAL,
1024 .offset = GLOBAL_VAR(szWINSHook),
1030 .label = "csc policy",
1033 .offset = LOCAL_VAR(iCSCPolicy),
1035 .enum_list = enum_csc_policy
1039 .label = "strict locking",
1042 .offset = LOCAL_VAR(iStrictLocking),
1050 .offset = LOCAL_VAR(bOpLocks),
1056 .label = "share backend",
1058 .p_class = P_GLOBAL,
1059 .offset = GLOBAL_VAR(szShareBackend),
1066 .p_class = P_GLOBAL,
1067 .offset = GLOBAL_VAR(szAutoServices),
1072 .label = "auto services",
1074 .p_class = P_GLOBAL,
1075 .offset = GLOBAL_VAR(szAutoServices),
1080 .label = "lock dir",
1082 .p_class = P_GLOBAL,
1083 .offset = GLOBAL_VAR(szLockDir),
1088 .label = "lock directory",
1090 .p_class = P_GLOBAL,
1091 .offset = GLOBAL_VAR(szLockDir),
1096 .label = "state directory",
1098 .p_class = P_GLOBAL,
1099 .offset = GLOBAL_VAR(szStateDir),
1104 .label = "cache directory",
1106 .p_class = P_GLOBAL,
1107 .offset = GLOBAL_VAR(szCacheDir),
1112 .label = "pid directory",
1114 .p_class = P_GLOBAL,
1115 .offset = GLOBAL_VAR(szPidDir),
1121 .label = "socket address",
1123 .p_class = P_GLOBAL,
1124 .offset = GLOBAL_VAR(szSocketAddress),
1132 .offset = LOCAL_VAR(szCopy),
1133 .special = handle_copy,
1140 .offset = LOCAL_VAR(szInclude),
1141 .special = handle_include,
1146 .label = "available",
1149 .offset = LOCAL_VAR(bAvailable),
1157 .offset = LOCAL_VAR(volume),
1165 .offset = LOCAL_VAR(fstype),
1171 .label = "panic action",
1173 .p_class = P_GLOBAL,
1174 .offset = GLOBAL_VAR(panic_action),
1180 .label = "msdfs root",
1183 .offset = LOCAL_VAR(bMSDfsRoot),
1188 .label = "host msdfs",
1190 .p_class = P_GLOBAL,
1191 .offset = GLOBAL_VAR(bHostMSDfs),
1196 .label = "winbind separator",
1198 .p_class = P_GLOBAL,
1199 .offset = GLOBAL_VAR(szWinbindSeparator),
1204 .label = "winbindd socket directory",
1206 .p_class = P_GLOBAL,
1207 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1212 .label = "winbindd privileged socket directory",
1214 .p_class = P_GLOBAL,
1215 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1220 .label = "winbind sealed pipes",
1222 .p_class = P_GLOBAL,
1223 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1228 .label = "template shell",
1230 .p_class = P_GLOBAL,
1231 .offset = GLOBAL_VAR(szTemplateShell),
1236 .label = "template homedir",
1238 .p_class = P_GLOBAL,
1239 .offset = GLOBAL_VAR(szTemplateHomedir),
1244 .label = "idmap trusted only",
1246 .p_class = P_GLOBAL,
1247 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1253 .label = "ntp signd socket directory",
1255 .p_class = P_GLOBAL,
1256 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1261 .label = "rndc command",
1263 .p_class = P_GLOBAL,
1264 .offset = GLOBAL_VAR(szRNDCCommand),
1269 .label = "dns update command",
1271 .p_class = P_GLOBAL,
1272 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1277 .label = "spn update command",
1279 .p_class = P_GLOBAL,
1280 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1285 .label = "nsupdate command",
1287 .p_class = P_GLOBAL,
1288 .offset = GLOBAL_VAR(szNSUpdateCommand),
1293 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1297 /* local variables */
1298 struct loadparm_context {
1299 const char *szConfigFile;
1300 struct loadparm_global *globals;
1301 struct loadparm_service **services;
1302 struct loadparm_service *sDefault;
1303 struct smb_iconv_handle *iconv_handle;
1305 struct loadparm_service *currentService;
1306 bool bInGlobalSection;
1308 struct file_lists *next;
1313 unsigned int flags[NUMPARAMETERS];
1316 bool global; /* Is this the global context, which may set
1317 * global variables such as debug level etc? */
1318 const struct loadparm_s3_context *s3_fns;
1322 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1324 if (lp_ctx->s3_fns) {
1325 return lp_ctx->s3_fns->get_default_loadparm_service();
1327 return lp_ctx->sDefault;
1331 * Convenience routine to grab string parameters into temporary memory
1332 * and run standard_sub_basic on them.
1334 * The buffers can be written to by
1335 * callers without affecting the source string.
1338 static const char *lp_string(const char *s)
1340 #if 0 /* until REWRITE done to make thread-safe */
1341 size_t len = s ? strlen(s) : 0;
1345 /* The follow debug is useful for tracking down memory problems
1346 especially if you have an inner loop that is calling a lp_*()
1347 function that returns a string. Perhaps this debug should be
1348 present all the time? */
1351 DEBUG(10, ("lp_string(%s)\n", s));
1354 #if 0 /* until REWRITE done to make thread-safe */
1356 lp_talloc = talloc_init("lp_talloc");
1358 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1366 strlcpy(ret, s, len);
1368 if (trim_string(ret, "\"", "\"")) {
1369 if (strchr(ret,'"') != NULL)
1370 strlcpy(ret, s, len);
1373 standard_sub_basic(ret,len+100);
1380 In this section all the functions that are used to access the
1381 parameters from the rest of the program are defined
1385 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1386 * for code compatibility between existing Samba4 and Samba3 code.
1389 /* this global context supports the lp_*() function varients */
1390 static struct loadparm_context *global_loadparm_context;
1392 #define lpcfg_default_service global_loadparm_context->sDefault
1393 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1395 #define FN_GLOBAL_STRING(fn_name,var_name) \
1396 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1397 if (lp_ctx == NULL) return NULL; \
1398 if (lp_ctx->s3_fns) { \
1399 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1400 return lp_ctx->s3_fns->fn_name(); \
1402 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1405 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1406 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1407 if (lp_ctx == NULL) return NULL; \
1408 if (lp_ctx->s3_fns) { \
1409 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1410 return lp_ctx->s3_fns->fn_name(); \
1412 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1415 #define FN_GLOBAL_LIST(fn_name,var_name) \
1416 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1417 if (lp_ctx == NULL) return NULL; \
1418 if (lp_ctx->s3_fns) { \
1419 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1420 return lp_ctx->s3_fns->fn_name(); \
1422 return lp_ctx->globals->var_name; \
1425 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1426 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1427 if (lp_ctx == NULL) return false; \
1428 if (lp_ctx->s3_fns) { \
1429 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1430 return lp_ctx->s3_fns->fn_name(); \
1432 return lp_ctx->globals->var_name; \
1435 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1436 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
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; \
1444 /* Local parameters don't need the ->s3_fns because the struct
1445 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1447 #define FN_LOCAL_STRING(fn_name,val) \
1448 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1449 struct loadparm_service *sDefault) { \
1450 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1453 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1455 #define FN_LOCAL_LIST(fn_name,val) \
1456 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1457 struct loadparm_service *sDefault) {\
1458 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1461 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1463 #define FN_LOCAL_BOOL(fn_name,val) \
1464 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1465 struct loadparm_service *sDefault) { \
1466 return((service != NULL)? service->val : sDefault->val); \
1469 #define FN_LOCAL_INTEGER(fn_name,val) \
1470 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1471 struct loadparm_service *sDefault) { \
1472 return((service != NULL)? service->val : sDefault->val); \
1475 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1477 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1479 #define FN_LOCAL_CHAR(fn_name,val) \
1480 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1481 struct loadparm_service *sDefault) { \
1482 return((service != NULL)? service->val : sDefault->val); \
1485 #include "lib/param/param_functions.c"
1487 FN_GLOBAL_INTEGER(server_role, server_role)
1488 static FN_GLOBAL_BOOL(domain_logons, domain_logons)
1489 FN_GLOBAL_INTEGER(domain_master, domain_master)
1490 FN_GLOBAL_LIST(smb_ports, smb_ports)
1491 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1492 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1493 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1494 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1495 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1496 FN_GLOBAL_INTEGER(web_port, web_port)
1497 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1498 FN_GLOBAL_STRING(logfile, logfile)
1499 FN_GLOBAL_STRING(share_backend, szShareBackend)
1500 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1501 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1502 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1503 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1504 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1505 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1506 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1507 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1508 FN_GLOBAL_STRING(serverstring, szServerString)
1509 FN_GLOBAL_STRING(lockdir, szLockDir)
1510 FN_GLOBAL_STRING(statedir, szStateDir)
1511 FN_GLOBAL_STRING(cachedir, szCacheDir)
1512 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1513 FN_GLOBAL_STRING(dos_charset, dos_charset)
1514 FN_GLOBAL_STRING(unix_charset, unix_charset)
1515 FN_GLOBAL_STRING(piddir, szPidDir)
1516 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1517 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1518 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1519 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1520 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1521 FN_GLOBAL_LIST(server_services, server_services)
1522 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1523 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1524 FN_GLOBAL_STRING(auto_services, szAutoServices)
1525 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1526 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1527 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1528 FN_GLOBAL_STRING(realm, szRealm_upper)
1529 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1530 FN_GLOBAL_STRING(socket_options, socket_options)
1531 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1532 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1533 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1534 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1535 FN_GLOBAL_LIST(interfaces, szInterfaces)
1536 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1537 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1538 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1539 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1540 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1541 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1542 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1543 FN_GLOBAL_BOOL(readraw, bReadRaw)
1544 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1545 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1546 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1547 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1548 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1549 FN_GLOBAL_BOOL(time_server, bTimeServer)
1550 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1551 FN_GLOBAL_BOOL(unicode, bUnicode)
1552 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1553 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1554 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1555 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1556 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1557 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1558 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1559 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1560 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1561 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1562 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1563 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1564 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1565 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1566 FN_GLOBAL_INTEGER(maxmux, max_mux)
1567 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1568 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1569 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1570 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1571 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1572 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1573 FN_GLOBAL_INTEGER(security, security)
1574 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1576 FN_GLOBAL_INTEGER(server_signing, server_signing)
1577 FN_GLOBAL_INTEGER(client_signing, client_signing)
1579 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1581 /* local prototypes */
1582 static int map_parameter(const char *pszParmName);
1583 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1584 const char *pszServiceName);
1585 static void copy_service(struct loadparm_service *pserviceDest,
1586 struct loadparm_service *pserviceSource,
1587 struct bitmap *pcopymapDest);
1588 static bool lpcfg_service_ok(struct loadparm_service *service);
1589 static bool do_section(const char *pszSectionName, void *);
1590 static void init_copymap(struct loadparm_service *pservice);
1592 /* This is a helper function for parametrical options support. */
1593 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1594 /* Actual parametrical functions are quite simple */
1595 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1596 struct loadparm_service *service,
1597 const char *type, const char *option)
1599 char *vfskey_tmp = NULL;
1600 char *vfskey = NULL;
1601 struct parmlist_entry *data;
1606 if (lp_ctx->s3_fns) {
1607 return lp_ctx->s3_fns->get_parametric(service, type, option);
1610 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1612 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1613 if (vfskey_tmp == NULL) return NULL;
1614 vfskey = strlower_talloc(NULL, vfskey_tmp);
1615 talloc_free(vfskey_tmp);
1618 if (strcmp(data->key, vfskey) == 0) {
1619 talloc_free(vfskey);
1625 if (service != NULL) {
1626 /* Try to fetch the same option but from globals */
1627 /* but only if we are not already working with globals */
1628 for (data = lp_ctx->globals->param_opt; data;
1629 data = data->next) {
1630 if (strcmp(data->key, vfskey) == 0) {
1631 talloc_free(vfskey);
1637 talloc_free(vfskey);
1644 * convenience routine to return int parameters.
1646 static int lp_int(const char *s)
1650 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1654 return strtol(s, NULL, 0);
1658 * convenience routine to return unsigned long parameters.
1660 static int lp_ulong(const char *s)
1664 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1668 return strtoul(s, NULL, 0);
1672 * convenience routine to return unsigned long parameters.
1674 static double lp_double(const char *s)
1678 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1682 return strtod(s, NULL);
1686 * convenience routine to return boolean parameters.
1688 static bool lp_bool(const char *s)
1693 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1697 if (!set_boolean(s, &ret)) {
1698 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1707 * Return parametric option from a given service. Type is a part of option before ':'
1708 * Parametric option has following syntax: 'Type: option = value'
1709 * Returned value is allocated in 'lp_talloc' context
1712 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1713 struct loadparm_service *service, const char *type,
1716 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1719 return lp_string(value);
1725 * Return parametric option from a given service. Type is a part of option before ':'
1726 * Parametric option has following syntax: 'Type: option = value'
1727 * Returned value is allocated in 'lp_talloc' context
1730 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1731 struct loadparm_context *lp_ctx,
1732 struct loadparm_service *service,
1734 const char *option, const char *separator)
1736 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1739 return (const char **)str_list_make(mem_ctx, value, separator);
1745 * Return parametric option from a given service. Type is a part of option before ':'
1746 * Parametric option has following syntax: 'Type: option = value'
1749 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1750 struct loadparm_service *service, const char *type,
1751 const char *option, int default_v)
1753 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1756 return lp_int(value);
1762 * Return parametric option from a given service. Type is a part of
1763 * option before ':'.
1764 * Parametric option has following syntax: 'Type: option = value'.
1767 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1768 struct loadparm_service *service, const char *type,
1769 const char *option, int default_v)
1773 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1775 if (value && conv_str_size_error(value, &bval)) {
1776 if (bval <= INT_MAX) {
1785 * Return parametric option from a given service.
1786 * Type is a part of option before ':'
1787 * Parametric option has following syntax: 'Type: option = value'
1789 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1790 struct loadparm_service *service, const char *type,
1791 const char *option, unsigned long default_v)
1793 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1796 return lp_ulong(value);
1802 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1803 struct loadparm_service *service, const char *type,
1804 const char *option, double default_v)
1806 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1809 return lp_double(value);
1815 * Return parametric option from a given service. Type is a part of option before ':'
1816 * Parametric option has following syntax: 'Type: option = value'
1819 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1820 struct loadparm_service *service, const char *type,
1821 const char *option, bool default_v)
1823 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1826 return lp_bool(value);
1833 * Initialise a service to the defaults.
1836 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1838 struct loadparm_service *pservice =
1839 talloc_zero(mem_ctx, struct loadparm_service);
1840 copy_service(pservice, sDefault, NULL);
1845 * Set a string value, deallocating any existing space, and allocing the space
1848 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1855 *dest = talloc_strdup(mem_ctx, src);
1856 if ((*dest) == NULL) {
1857 DEBUG(0,("Out of memory in string_set\n"));
1865 * Set a string value, deallocating any existing space, and allocing the space
1868 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1875 *dest = strupper_talloc(mem_ctx, src);
1876 if ((*dest) == NULL) {
1877 DEBUG(0,("Out of memory in string_set_upper\n"));
1887 * Add a new service to the services array initialising it with the given
1891 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1892 const struct loadparm_service *pservice,
1896 struct loadparm_service tservice;
1897 int num_to_alloc = lp_ctx->iNumServices + 1;
1898 struct parmlist_entry *data, *pdata;
1900 if (pservice == NULL) {
1901 pservice = lp_ctx->sDefault;
1904 tservice = *pservice;
1906 /* it might already exist */
1908 struct loadparm_service *service = getservicebyname(lp_ctx,
1910 if (service != NULL) {
1911 /* Clean all parametric options for service */
1912 /* They will be added during parsing again */
1913 data = service->param_opt;
1919 service->param_opt = NULL;
1924 /* find an invalid one */
1925 for (i = 0; i < lp_ctx->iNumServices; i++)
1926 if (lp_ctx->services[i] == NULL)
1929 /* if not, then create one */
1930 if (i == lp_ctx->iNumServices) {
1931 struct loadparm_service **tsp;
1933 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1936 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1939 lp_ctx->services = tsp;
1940 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1943 lp_ctx->iNumServices++;
1946 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1947 if (lp_ctx->services[i] == NULL) {
1948 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1951 copy_service(lp_ctx->services[i], &tservice, NULL);
1953 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1954 return lp_ctx->services[i];
1958 * Add a new home service, with the specified home directory, defaults coming
1959 * from service ifrom.
1962 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1963 const char *pszHomename,
1964 struct loadparm_service *default_service,
1965 const char *user, const char *pszHomedir)
1967 struct loadparm_service *service;
1969 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1971 if (service == NULL)
1974 if (!(*(default_service->szPath))
1975 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1976 service->szPath = talloc_strdup(service, pszHomedir);
1978 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1981 if (!(*(service->comment))) {
1982 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1984 service->bAvailable = default_service->bAvailable;
1985 service->bBrowseable = default_service->bBrowseable;
1987 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1988 pszHomename, user, service->szPath));
1994 * Add a new printer service, with defaults coming from service iFrom.
1997 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1998 const char *pszPrintername,
1999 struct loadparm_service *default_service)
2001 const char *comment = "From Printcap";
2002 struct loadparm_service *service;
2003 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2005 if (service == NULL)
2008 /* note that we do NOT default the availability flag to True - */
2009 /* we take it from the default service passed. This allows all */
2010 /* dynamic printers to be disabled by disabling the [printers] */
2011 /* entry (if/when the 'available' keyword is implemented!). */
2013 /* the printer name is set to the service name. */
2014 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
2015 lpcfg_string_set(service, &service->comment, comment);
2016 service->bBrowseable = default_service->bBrowseable;
2017 /* Printers cannot be read_only. */
2018 service->bRead_only = false;
2019 /* Printer services must be printable. */
2020 service->bPrint_ok = true;
2022 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2028 * Map a parameter's string representation to something we can use.
2029 * Returns False if the parameter string is not recognised, else TRUE.
2032 static int map_parameter(const char *pszParmName)
2036 if (*pszParmName == '-')
2039 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2040 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2043 /* Warn only if it isn't parametric option */
2044 if (strchr(pszParmName, ':') == NULL)
2045 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2046 /* We do return 'fail' for parametric options as well because they are
2047 stored in different storage
2054 return the parameter structure for a parameter
2056 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2060 if (lp_ctx->s3_fns) {
2061 return lp_ctx->s3_fns->get_parm_struct(name);
2064 parmnum = map_parameter(name);
2065 if (parmnum == -1) return NULL;
2066 return &parm_table[parmnum];
2070 return the parameter pointer for a parameter
2072 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2073 struct loadparm_service *service, struct parm_struct *parm)
2075 if (lp_ctx->s3_fns) {
2076 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2079 if (service == NULL) {
2080 if (parm->p_class == P_LOCAL)
2081 return ((char *)lp_ctx->sDefault)+parm->offset;
2082 else if (parm->p_class == P_GLOBAL)
2083 return ((char *)lp_ctx->globals)+parm->offset;
2086 return ((char *)service) + parm->offset;
2091 return the parameter pointer for a parameter
2093 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2097 if (lp_ctx->s3_fns) {
2098 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2100 return parm->flags & FLAG_CMDLINE;
2105 parmnum = map_parameter(name);
2106 if (parmnum == -1) return false;
2108 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2112 * Find a service by name. Otherwise works like get_service.
2115 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2116 const char *pszServiceName)
2120 if (lp_ctx->s3_fns) {
2121 return lp_ctx->s3_fns->get_service(pszServiceName);
2124 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2125 if (lp_ctx->services[iService] != NULL &&
2126 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2127 return lp_ctx->services[iService];
2134 * Copy a service structure to another.
2135 * If pcopymapDest is NULL then copy all fields
2138 static void copy_service(struct loadparm_service *pserviceDest,
2139 struct loadparm_service *pserviceSource,
2140 struct bitmap *pcopymapDest)
2143 bool bcopyall = (pcopymapDest == NULL);
2144 struct parmlist_entry *data, *pdata, *paramo;
2147 for (i = 0; parm_table[i].label; i++)
2148 if (parm_table[i].p_class == P_LOCAL &&
2149 (bcopyall || bitmap_query(pcopymapDest, i))) {
2151 ((char *)pserviceSource) + parm_table[i].offset;
2153 ((char *)pserviceDest) + parm_table[i].offset;
2155 switch (parm_table[i].type) {
2157 *(bool *)dest_ptr = *(bool *)src_ptr;
2163 *(int *)dest_ptr = *(int *)src_ptr;
2167 lpcfg_string_set(pserviceDest,
2173 lpcfg_string_set_upper(pserviceDest,
2178 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2179 *(const char ***)src_ptr);
2187 init_copymap(pserviceDest);
2188 if (pserviceSource->copymap)
2189 bitmap_copy(pserviceDest->copymap,
2190 pserviceSource->copymap);
2193 data = pserviceSource->param_opt;
2196 pdata = pserviceDest->param_opt;
2197 /* Traverse destination */
2199 /* If we already have same option, override it */
2200 if (strcmp(pdata->key, data->key) == 0) {
2201 talloc_free(pdata->value);
2202 pdata->value = talloc_reference(pdata,
2207 pdata = pdata->next;
2210 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2213 paramo->key = talloc_reference(paramo, data->key);
2214 paramo->value = talloc_reference(paramo, data->value);
2215 DLIST_ADD(pserviceDest->param_opt, paramo);
2222 * Check a service for consistency. Return False if the service is in any way
2223 * incomplete or faulty, else True.
2225 static bool lpcfg_service_ok(struct loadparm_service *service)
2230 if (service->szService[0] == '\0') {
2231 DEBUG(0, ("The following message indicates an internal error:\n"));
2232 DEBUG(0, ("No service name in service entry.\n"));
2236 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2237 /* I can't see why you'd want a non-printable printer service... */
2238 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2239 if (!service->bPrint_ok) {
2240 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2241 service->szService));
2242 service->bPrint_ok = true;
2244 /* [printers] service must also be non-browsable. */
2245 if (service->bBrowseable)
2246 service->bBrowseable = false;
2249 /* If a service is flagged unavailable, log the fact at level 0. */
2250 if (!service->bAvailable)
2251 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2252 service->szService));
2258 /*******************************************************************
2259 Keep a linked list of all config files so we know when one has changed
2260 it's date and needs to be reloaded.
2261 ********************************************************************/
2263 static void add_to_file_list(struct loadparm_context *lp_ctx,
2264 const char *fname, const char *subfname)
2266 struct file_lists *f = lp_ctx->file_lists;
2269 if (f->name && !strcmp(f->name, fname))
2275 f = talloc(lp_ctx, struct file_lists);
2278 f->next = lp_ctx->file_lists;
2279 f->name = talloc_strdup(f, fname);
2284 f->subfname = talloc_strdup(f, subfname);
2289 lp_ctx->file_lists = f;
2290 f->modtime = file_modtime(subfname);
2292 time_t t = file_modtime(subfname);
2298 /*******************************************************************
2299 Check if a config file has changed date.
2300 ********************************************************************/
2301 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2303 struct file_lists *f;
2304 DEBUG(6, ("lp_file_list_changed()\n"));
2306 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2310 n2 = standard_sub_basic(lp_ctx, f->name);
2312 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2313 f->name, n2, ctime(&f->modtime)));
2315 mod_time = file_modtime(n2);
2317 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2318 DEBUGADD(6, ("file %s modified: %s\n", n2,
2320 f->modtime = mod_time;
2321 talloc_free(f->subfname);
2322 f->subfname = talloc_strdup(f, n2);
2329 /***************************************************************************
2330 Handle the "realm" parameter
2331 ***************************************************************************/
2333 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2334 const char *pszParmValue, char **ptr)
2336 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2338 talloc_free(lp_ctx->globals->szRealm_upper);
2339 talloc_free(lp_ctx->globals->szRealm_lower);
2341 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2342 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2347 /***************************************************************************
2348 Handle the include operation.
2349 ***************************************************************************/
2351 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2352 const char *pszParmValue, char **ptr)
2354 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2356 add_to_file_list(lp_ctx, pszParmValue, fname);
2358 lpcfg_string_set(lp_ctx, ptr, fname);
2360 if (file_exist(fname))
2361 return pm_process(fname, do_section, do_parameter, lp_ctx);
2363 DEBUG(2, ("Can't find include file %s\n", fname));
2368 /***************************************************************************
2369 Handle the interpretation of the copy parameter.
2370 ***************************************************************************/
2372 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2373 const char *pszParmValue, char **ptr)
2376 struct loadparm_service *serviceTemp;
2378 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2382 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2384 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2385 if (serviceTemp == lp_ctx->currentService) {
2386 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2388 copy_service(lp_ctx->currentService,
2390 lp_ctx->currentService->copymap);
2394 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2402 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2403 const char *pszParmValue, char **ptr)
2406 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2407 if (lp_ctx->global) {
2408 return debug_parse_levels(pszParmValue);
2413 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2414 const char *pszParmValue, char **ptr)
2416 debug_set_logfile(pszParmValue);
2417 if (lp_ctx->global) {
2418 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2423 /***************************************************************************
2424 Initialise a copymap.
2425 ***************************************************************************/
2427 static void init_copymap(struct loadparm_service *pservice)
2431 TALLOC_FREE(pservice->copymap);
2433 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2434 if (!pservice->copymap)
2436 ("Couldn't allocate copymap!! (size %d)\n",
2437 (int)NUMPARAMETERS));
2439 for (i = 0; i < NUMPARAMETERS; i++)
2440 bitmap_set(pservice->copymap, i);
2444 * Process a parametric option
2446 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2447 struct loadparm_service *service,
2448 const char *pszParmName,
2449 const char *pszParmValue, int flags)
2451 struct parmlist_entry *paramo, *data;
2453 TALLOC_CTX *mem_ctx;
2455 while (isspace((unsigned char)*pszParmName)) {
2459 name = strlower_talloc(lp_ctx, pszParmName);
2460 if (!name) return false;
2462 if (service == NULL) {
2463 data = lp_ctx->globals->param_opt;
2464 mem_ctx = lp_ctx->globals;
2466 data = service->param_opt;
2470 /* Traverse destination */
2471 for (paramo=data; paramo; paramo=paramo->next) {
2472 /* If we already have the option set, override it unless
2473 it was a command line option and the new one isn't */
2474 if (strcmp(paramo->key, name) == 0) {
2475 if ((paramo->priority & FLAG_CMDLINE) &&
2476 !(flags & FLAG_CMDLINE)) {
2481 talloc_free(paramo->value);
2482 paramo->value = talloc_strdup(paramo, pszParmValue);
2483 paramo->priority = flags;
2489 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2492 paramo->key = talloc_strdup(paramo, name);
2493 paramo->value = talloc_strdup(paramo, pszParmValue);
2494 paramo->priority = flags;
2495 if (service == NULL) {
2496 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2498 DLIST_ADD(service->param_opt, paramo);
2506 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2507 const char *pszParmName, const char *pszParmValue,
2508 struct loadparm_context *lp_ctx, bool on_globals)
2511 /* if it is a special case then go ahead */
2512 if (parm_table[parmnum].special) {
2514 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2519 goto mark_non_default;
2522 /* now switch on the type of variable it is */
2523 switch (parm_table[parmnum].type)
2527 if (!set_boolean(pszParmValue, &b)) {
2528 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2531 *(bool *)parm_ptr = b;
2537 if (!set_boolean(pszParmValue, &b)) {
2538 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2541 *(bool *)parm_ptr = !b;
2546 *(int *)parm_ptr = atoi(pszParmValue);
2550 *(char *)parm_ptr = *pszParmValue;
2554 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2560 if (conv_str_size_error(pszParmValue, &val)) {
2561 if (val <= INT_MAX) {
2562 *(int *)parm_ptr = (int)val;
2567 DEBUG(0,("lp_do_parameter(%s): value is not "
2568 "a valid size specifier!\n", pszParmValue));
2573 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2574 pszParmValue, NULL);
2578 char **new_list = str_list_make(mem_ctx,
2579 pszParmValue, NULL);
2580 for (i=0; new_list[i]; i++) {
2581 if (new_list[i][0] == '+' && new_list[i][1] &&
2582 (!str_list_check(*(const char ***)parm_ptr,
2583 &new_list[i][1]))) {
2584 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2586 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2587 #if 0 /* This is commented out because we sometimes parse the list
2588 * twice, and so we can't assert on this */
2589 if (!str_list_check(*(const char ***)parm_ptr,
2591 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2592 pszParmName, pszParmValue, new_list[i],
2593 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2598 str_list_remove(*(const char ***)parm_ptr,
2602 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2603 pszParmName, pszParmValue));
2606 *(const char ***)parm_ptr = (const char **) new_list;
2613 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2617 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2621 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2624 parm_table[parmnum].enum_list[i].name)) {
2626 parm_table[parmnum].
2631 if (!parm_table[parmnum].enum_list[i].name) {
2632 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2633 pszParmValue, pszParmName));
2640 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2641 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2642 /* we have to also unset FLAG_DEFAULT on aliases */
2643 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2644 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2646 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2647 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2654 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2655 const char *pszParmName, const char *pszParmValue)
2657 int parmnum = map_parameter(pszParmName);
2661 if (strchr(pszParmName, ':')) {
2662 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2664 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2668 /* if the flag has been set on the command line, then don't allow override,
2669 but don't report an error */
2670 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2674 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2676 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2677 pszParmName, pszParmValue, lp_ctx, true);
2680 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2681 struct loadparm_service *service,
2682 const char *pszParmName, const char *pszParmValue)
2686 int parmnum = map_parameter(pszParmName);
2689 if (strchr(pszParmName, ':')) {
2690 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2692 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2696 /* if the flag has been set on the command line, then don't allow override,
2697 but don't report an error */
2698 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2702 if (parm_table[parmnum].p_class == P_GLOBAL) {
2704 ("Global parameter %s found in service section!\n",
2708 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2710 if (!service->copymap)
2711 init_copymap(service);
2713 /* this handles the aliases - set the copymap for other
2714 * entries with the same data pointer */
2715 for (i = 0; parm_table[i].label; i++)
2716 if (parm_table[i].offset == parm_table[parmnum].offset &&
2717 parm_table[i].p_class == parm_table[parmnum].p_class)
2718 bitmap_clear(service->copymap, i);
2720 return set_variable(service, parmnum, parm_ptr, pszParmName,
2721 pszParmValue, lp_ctx, false);
2725 * Process a parameter.
2728 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2731 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2733 if (lp_ctx->bInGlobalSection)
2734 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2737 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2738 pszParmName, pszParmValue);
2742 variable argument do parameter
2744 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2745 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2746 const char *pszParmName, const char *fmt, ...)
2753 s = talloc_vasprintf(NULL, fmt, ap);
2755 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2762 set a parameter from the commandline - this is called from command line parameter
2763 parsing code. It sets the parameter then marks the parameter as unable to be modified
2764 by smb.conf processing
2766 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2767 const char *pszParmValue)
2772 if (lp_ctx->s3_fns) {
2773 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2776 parmnum = map_parameter(pszParmName);
2778 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2781 if (parmnum < 0 && strchr(pszParmName, ':')) {
2782 /* set a parametric option */
2783 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2784 pszParmValue, FLAG_CMDLINE);
2788 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2792 /* reset the CMDLINE flag in case this has been called before */
2793 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2795 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2799 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2801 /* we have to also set FLAG_CMDLINE on aliases */
2802 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2803 lp_ctx->flags[i] |= FLAG_CMDLINE;
2805 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2806 lp_ctx->flags[i] |= FLAG_CMDLINE;
2813 set a option from the commandline in 'a=b' format. Use to support --option
2815 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2820 s = talloc_strdup(NULL, option);
2833 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2839 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2842 * Print a parameter of the specified type.
2845 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2847 /* For the seperation of lists values that we print below */
2848 const char *list_sep = ", ";
2853 for (i = 0; p->enum_list[i].name; i++) {
2854 if (*(int *)ptr == p->enum_list[i].value) {
2856 p->enum_list[i].name);
2863 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2867 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2872 fprintf(f, "%d", *(int *)ptr);
2876 fprintf(f, "%c", *(char *)ptr);
2880 int val = *(int *)ptr;
2884 fprintf(f, "0%o", val);
2893 if ((char ***)ptr && *(char ***)ptr) {
2894 char **list = *(char ***)ptr;
2895 for (; *list; list++) {
2896 /* surround strings with whitespace in double quotes */
2897 if (*(list+1) == NULL) {
2898 /* last item, no extra separator */
2901 if ( strchr_m( *list, ' ' ) ) {
2902 fprintf(f, "\"%s\"%s", *list, list_sep);
2904 fprintf(f, "%s%s", *list, list_sep);
2912 if (*(char **)ptr) {
2913 fprintf(f, "%s", *(char **)ptr);
2922 * Check if two parameters are equal.
2925 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2930 return (*((bool *)ptr1) == *((bool *)ptr2));
2936 return (*((int *)ptr1) == *((int *)ptr2));
2939 return (*((char *)ptr1) == *((char *)ptr2));
2943 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2948 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2953 return (p1 == p2 || strequal(p1, p2));
2962 * Process a new section (service).
2964 * At this stage all sections are services.
2965 * Later we'll have special sections that permit server parameters to be set.
2966 * Returns True on success, False on failure.
2969 static bool do_section(const char *pszSectionName, void *userdata)
2971 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2973 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2974 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2977 /* if we've just struck a global section, note the fact. */
2978 lp_ctx->bInGlobalSection = isglobal;
2980 /* check for multiple global sections */
2981 if (lp_ctx->bInGlobalSection) {
2982 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2986 /* if we have a current service, tidy it up before moving on */
2989 if (lp_ctx->currentService != NULL)
2990 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2992 /* if all is still well, move to the next record in the services array */
2994 /* We put this here to avoid an odd message order if messages are */
2995 /* issued by the post-processing of a previous section. */
2996 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2998 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
3001 DEBUG(0, ("Failed to add a new service\n"));
3011 * Determine if a particular base parameter is currently set to the default value.
3014 static bool is_default(struct loadparm_service *sDefault, int i)
3016 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
3017 if (!defaults_saved)
3019 switch (parm_table[i].type) {
3022 return str_list_equal((const char **)parm_table[i].def.lvalue,
3023 (const char **)def_ptr);
3026 return strequal(parm_table[i].def.svalue,
3030 return parm_table[i].def.bvalue ==
3037 return parm_table[i].def.ivalue ==
3044 *Display the contents of the global structure.
3047 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3051 struct parmlist_entry *data;
3053 fprintf(f, "# Global parameters\n[global]\n");
3055 for (i = 0; parm_table[i].label; i++)
3056 if (parm_table[i].p_class == P_GLOBAL &&
3057 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3058 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3060 fprintf(f, "\t%s = ", parm_table[i].label);
3061 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3064 if (lp_ctx->globals->param_opt != NULL) {
3065 for (data = lp_ctx->globals->param_opt; data;
3066 data = data->next) {
3067 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3070 fprintf(f, "\t%s = %s\n", data->key, data->value);
3077 * Display the contents of a single services record.
3080 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3081 unsigned int *flags)
3084 struct parmlist_entry *data;
3086 if (pService != sDefault)
3087 fprintf(f, "\n[%s]\n", pService->szService);
3089 for (i = 0; parm_table[i].label; i++) {
3090 if (parm_table[i].p_class == P_LOCAL &&
3091 (*parm_table[i].label != '-') &&
3092 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3094 if (pService == sDefault) {
3095 if (flags && (flags[i] & FLAG_DEFAULT)) {
3098 if (defaults_saved) {
3099 if (is_default(sDefault, i)) {
3104 if (equal_parameter(parm_table[i].type,
3105 ((char *)pService) +
3106 parm_table[i].offset,
3107 ((char *)sDefault) +
3108 parm_table[i].offset))
3112 fprintf(f, "\t%s = ", parm_table[i].label);
3113 print_parameter(&parm_table[i],
3114 ((char *)pService) + parm_table[i].offset, f);
3118 if (pService->param_opt != NULL) {
3119 for (data = pService->param_opt; data; data = data->next) {
3120 fprintf(f, "\t%s = %s\n", data->key, data->value);
3125 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3126 struct loadparm_service *service,
3127 const char *parm_name, FILE * f)
3129 struct parm_struct *parm;
3132 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3137 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3139 print_parameter(parm, ptr, f);
3145 * Return info about the next parameter in a service.
3146 * snum==-1 gives the globals.
3147 * Return NULL when out of parameters.
3151 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3155 /* do the globals */
3156 for (; parm_table[*i].label; (*i)++) {
3157 if ((*parm_table[*i].label == '-'))
3161 && (parm_table[*i].offset ==
3162 parm_table[(*i) - 1].offset)
3163 && (parm_table[*i].p_class ==
3164 parm_table[(*i) - 1].p_class))
3167 return &parm_table[(*i)++];
3170 struct loadparm_service *pService = lp_ctx->services[snum];
3172 for (; parm_table[*i].label; (*i)++) {
3173 if (parm_table[*i].p_class == P_LOCAL &&
3174 (*parm_table[*i].label != '-') &&
3176 (parm_table[*i].offset !=
3177 parm_table[(*i) - 1].offset)))
3179 if (allparameters ||
3180 !equal_parameter(parm_table[*i].type,
3181 ((char *)pService) +
3182 parm_table[*i].offset,
3183 ((char *)lp_ctx->sDefault) +
3184 parm_table[*i].offset))
3186 return &parm_table[(*i)++];
3197 * Auto-load some home services.
3199 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3207 * Unload unused services.
3210 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3211 struct smbsrv_connection *smb,
3212 bool (*snumused) (struct smbsrv_connection *, int))
3215 for (i = 0; i < lp_ctx->iNumServices; i++) {
3216 if (lp_ctx->services[i] == NULL)
3219 if (!snumused || !snumused(smb, i)) {
3220 talloc_free(lp_ctx->services[i]);
3221 lp_ctx->services[i] = NULL;
3227 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3229 struct parmlist_entry *data;
3231 if (lp_ctx->refuse_free) {
3232 /* someone is trying to free the
3233 global_loadparm_context.
3234 We can't allow that. */
3238 if (lp_ctx->globals->param_opt != NULL) {
3239 struct parmlist_entry *next;
3240 for (data = lp_ctx->globals->param_opt; data; data=next) {
3242 if (data->priority & FLAG_CMDLINE) continue;
3243 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3252 * Initialise the global parameter structure.
3254 * Note that most callers should use loadparm_init_global() instead
3256 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3260 struct loadparm_context *lp_ctx;
3261 struct parmlist_entry *parm;
3264 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3268 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3269 lp_ctx->bInGlobalSection = true;
3270 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3271 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3273 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3274 lp_ctx->sDefault->bAvailable = true;
3275 lp_ctx->sDefault->bBrowseable = true;
3276 lp_ctx->sDefault->bRead_only = true;
3277 lp_ctx->sDefault->bMap_archive = true;
3278 lp_ctx->sDefault->iStrictLocking = true;
3279 lp_ctx->sDefault->bOpLocks = true;
3280 lp_ctx->sDefault->iCreate_mask = 0744;
3281 lp_ctx->sDefault->iCreate_force_mode = 0000;
3282 lp_ctx->sDefault->iDir_mask = 0755;
3283 lp_ctx->sDefault->iDir_force_mode = 0000;
3285 DEBUG(3, ("Initialising global parameters\n"));
3287 for (i = 0; parm_table[i].label; i++) {
3288 if ((parm_table[i].type == P_STRING ||
3289 parm_table[i].type == P_USTRING) &&
3290 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3292 if (parm_table[i].p_class == P_LOCAL) {
3293 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3295 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3297 *r = talloc_strdup(lp_ctx, "");
3301 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3302 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3303 talloc_free(logfile);
3305 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3307 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3309 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
3310 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3311 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3313 /* options that can be set on the command line must be initialised via
3314 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3316 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3318 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3319 myname = get_myname(lp_ctx);
3320 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3321 talloc_free(myname);
3322 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3324 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3326 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3327 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3329 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey dnsserver");
3330 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3331 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3332 /* the winbind method for domain controllers is for both RODC
3333 auth forwarding and for trusted domains */
3334 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3335 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3337 /* This hive should be dynamically generated by Samba using
3338 data from the sam, but for the moment leave it in a tdb to
3339 keep regedt32 from popping up an annoying dialog. */
3340 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3342 /* using UTF8 by default allows us to support all chars */
3343 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3345 /* Use codepage 850 as a default for the dos character set */
3346 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3349 * Allow the default PASSWD_CHAT to be overridden in local.h.
3351 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3353 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3354 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3355 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3356 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3357 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3359 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3360 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3361 "Samba %s", SAMBA_VERSION_STRING);
3363 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3365 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3366 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3367 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3368 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3369 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3370 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3371 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3372 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3373 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
3374 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3375 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3376 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3377 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3378 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3379 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3381 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3382 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3383 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3384 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3385 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3386 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3387 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3388 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3390 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3392 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3393 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3395 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3396 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3398 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3399 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3400 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3401 #if _SAMBA_BUILD_ >= 4
3402 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3403 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3404 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3405 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3407 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3408 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3409 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3411 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3412 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3414 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3416 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3418 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3419 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3420 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3421 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3422 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3423 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3424 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3426 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3428 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3429 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3431 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3432 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3433 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3434 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3435 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3437 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3438 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3440 for (i = 0; parm_table[i].label; i++) {
3441 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3442 lp_ctx->flags[i] |= FLAG_DEFAULT;
3446 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3447 if (!(parm->priority & FLAG_CMDLINE)) {
3448 parm->priority |= FLAG_DEFAULT;
3456 * Initialise the global parameter structure.
3458 struct loadparm_context *loadparm_init_global(bool load_default)
3460 if (global_loadparm_context == NULL) {
3461 global_loadparm_context = loadparm_init(NULL);
3463 if (global_loadparm_context == NULL) {
3466 global_loadparm_context->global = true;
3467 if (load_default && !global_loadparm_context->loaded) {
3468 lpcfg_load_default(global_loadparm_context);
3470 global_loadparm_context->refuse_free = true;
3471 return global_loadparm_context;
3475 * Initialise the global parameter structure.
3477 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3478 const struct loadparm_s3_context *s3_fns)
3480 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3481 if (!loadparm_context) {
3484 loadparm_context->s3_fns = s3_fns;
3485 return loadparm_context;
3488 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3490 return lp_ctx->szConfigFile;
3493 const char *lp_default_path(void)
3495 if (getenv("SMB_CONF_PATH"))
3496 return getenv("SMB_CONF_PATH");
3498 return dyn_CONFIGFILE;
3502 * Update the internal state of a loadparm context after settings
3505 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3507 struct debug_settings settings;
3508 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3510 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3511 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3514 if (!lp_ctx->global) {
3518 panic_action = lp_ctx->globals->panic_action;
3520 reload_charcnv(lp_ctx);
3522 ZERO_STRUCT(settings);
3523 /* Add any more debug-related smb.conf parameters created in
3525 settings.timestamp_logs = true;
3526 debug_set_settings(&settings);
3528 /* FIXME: This is a bit of a hack, but we can't use a global, since
3529 * not everything that uses lp also uses the socket library */
3530 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3531 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3533 unsetenv("SOCKET_TESTNONBLOCK");
3539 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3543 path = lp_default_path();
3545 if (!file_exist(path)) {
3546 /* We allow the default smb.conf file to not exist,
3547 * basically the equivalent of an empty file. */
3548 return lpcfg_update(lp_ctx);
3551 return lpcfg_load(lp_ctx, path);
3555 * Load the services array from the services file.
3557 * Return True on success, False on failure.
3559 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3564 filename = talloc_strdup(lp_ctx, filename);
3566 lp_ctx->szConfigFile = filename;
3568 if (lp_ctx->s3_fns) {
3569 return lp_ctx->s3_fns->load(filename);
3572 lp_ctx->bInGlobalSection = true;
3573 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3574 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3576 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3578 /* We get sections first, so have to start 'behind' to make up */
3579 lp_ctx->currentService = NULL;
3580 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3582 /* finish up the last section */
3583 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3585 if (lp_ctx->currentService != NULL)
3586 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3588 bRetval = bRetval && lpcfg_update(lp_ctx);
3590 /* we do this unconditionally, so that it happens even
3591 for a missing smb.conf */
3592 reload_charcnv(lp_ctx);
3594 if (bRetval == true) {
3595 /* set this up so that any child python tasks will
3596 find the right smb.conf */
3597 setenv("SMB_CONF_PATH", filename, 1);
3599 /* set the context used by the lp_*() function
3601 global_loadparm_context = lp_ctx;
3602 lp_ctx->loaded = true;
3609 * Return the max number of services.
3612 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3614 if (lp_ctx->s3_fns) {
3615 return lp_ctx->s3_fns->get_numservices();
3618 return lp_ctx->iNumServices;
3622 * Display the contents of the services array in human-readable form.
3625 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3630 if (lp_ctx->s3_fns) {
3631 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3635 defaults_saved = !show_defaults;
3637 dump_globals(lp_ctx, f, show_defaults);
3639 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3641 for (iService = 0; iService < maxtoprint; iService++)
3642 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3646 * Display the contents of one service in human-readable form.
3648 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3650 if (service != NULL) {
3651 if (service->szService[0] == '\0')
3653 dump_a_service(service, sDefault, f, NULL);
3657 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3660 if (lp_ctx->s3_fns) {
3661 return lp_ctx->s3_fns->get_servicebynum(snum);
3664 return lp_ctx->services[snum];
3667 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3668 const char *service_name)
3673 if (lp_ctx->s3_fns) {
3674 return lp_ctx->s3_fns->get_service(service_name);
3677 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3678 if (lp_ctx->services[iService] &&
3679 lp_ctx->services[iService]->szService) {
3681 * The substitution here is used to support %U is
3684 serviceName = standard_sub_basic(
3685 lp_ctx->services[iService],
3686 lp_ctx->services[iService]->szService);
3687 if (strequal(serviceName, service_name)) {
3688 talloc_free(serviceName);
3689 return lp_ctx->services[iService];
3691 talloc_free(serviceName);
3695 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3699 const char *lpcfg_servicename(const struct loadparm_service *service)
3701 return lp_string((const char *)service->szService);
3705 * A useful volume label function.
3707 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3710 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3711 service->volume : sDefault->volume));
3713 return lpcfg_servicename(service);
3718 * If we are PDC then prefer us as DMB
3720 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3723 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3724 service->szPrintername : sDefault->szPrintername));
3725 if (ret == NULL || (ret != NULL && *ret == '\0'))
3726 ret = lpcfg_servicename(service);
3733 * Return the max print jobs per queue.
3735 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3737 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3738 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3739 maxjobs = PRINT_MAX_JOBID - 1;
3744 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3746 if (lp_ctx == NULL) {
3747 return get_iconv_handle();
3749 return lp_ctx->iconv_handle;
3752 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3754 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3755 if (!lp_ctx->global) {
3759 if (old_ic == NULL) {
3760 old_ic = global_iconv_handle;
3762 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3763 global_iconv_handle = lp_ctx->iconv_handle;
3766 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3768 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3771 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3773 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3776 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3778 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3781 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3783 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3786 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3788 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3791 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3793 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3794 if (settings == NULL)
3796 SMB_ASSERT(lp_ctx != NULL);
3797 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3798 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");