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 "smb_server/smb_server.h"
62 #include "libcli/raw/signing.h"
63 #include "../lib/util/dlinklist.h"
64 #include "../lib/util/parmlist.h"
65 #include "param/param.h"
66 #include "param/loadparm.h"
67 #include "libcli/raw/libcliraw.h"
68 #include "rpc_server/common/common.h"
69 #include "lib/socket/socket.h"
70 #include "auth/gensec/gensec.h"
73 #define standard_sub_basic talloc_strdup
75 static bool do_parameter(const char *, const char *, void *);
76 static bool defaults_saved = false;
78 #define LOADPARM_EXTRA_GLOBALS \
79 struct parmlist_entry *param_opt; \
88 int bPreferredMaster; \
89 char *szAnnounceVersion; /* This is initialised in init_globals */
90 #define LOADPARM_EXTRA_LOCALS \
91 struct parmlist_entry *param_opt; \
95 char *szPrintername; \
100 char dummy[3]; /* for alignment */
102 #include "param_global.h"
103 #include "param_local.h"
105 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
108 /* prototypes for the special type handlers */
109 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
110 const char *pszParmValue, char **ptr);
111 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
112 const char *pszParmValue, char **ptr);
113 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
114 const char *pszParmValue, char **ptr);
115 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
116 const char *pszParmValue, char **ptr);
117 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
118 const char *pszParmValue, char **ptr);
120 static const struct enum_list enum_protocol[] = {
121 {PROTOCOL_SMB2, "SMB2"},
122 {PROTOCOL_NT1, "NT1"},
123 {PROTOCOL_LANMAN2, "LANMAN2"},
124 {PROTOCOL_LANMAN1, "LANMAN1"},
125 {PROTOCOL_CORE, "CORE"},
126 {PROTOCOL_COREPLUS, "COREPLUS"},
127 {PROTOCOL_COREPLUS, "CORE+"},
131 static const struct enum_list enum_security[] = {
132 {SEC_SHARE, "SHARE"},
138 static const struct enum_list enum_bool_auto[] = {
149 /* Client-side offline caching policy types */
152 CSC_POLICY_DOCUMENTS=1,
153 CSC_POLICY_PROGRAMS=2,
157 static const struct enum_list enum_csc_policy[] = {
158 {CSC_POLICY_MANUAL, "manual"},
159 {CSC_POLICY_DOCUMENTS, "documents"},
160 {CSC_POLICY_PROGRAMS, "programs"},
161 {CSC_POLICY_DISABLE, "disable"},
165 /* SMB signing types. */
166 static const struct enum_list enum_smb_signing_vals[] = {
167 {SMB_SIGNING_OFF, "No"},
168 {SMB_SIGNING_OFF, "False"},
169 {SMB_SIGNING_OFF, "0"},
170 {SMB_SIGNING_OFF, "Off"},
171 {SMB_SIGNING_OFF, "disabled"},
172 {SMB_SIGNING_SUPPORTED, "Yes"},
173 {SMB_SIGNING_SUPPORTED, "True"},
174 {SMB_SIGNING_SUPPORTED, "1"},
175 {SMB_SIGNING_SUPPORTED, "On"},
176 {SMB_SIGNING_SUPPORTED, "enabled"},
177 {SMB_SIGNING_REQUIRED, "required"},
178 {SMB_SIGNING_REQUIRED, "mandatory"},
179 {SMB_SIGNING_REQUIRED, "force"},
180 {SMB_SIGNING_REQUIRED, "forced"},
181 {SMB_SIGNING_REQUIRED, "enforced"},
182 {SMB_SIGNING_AUTO, "auto"},
186 static const struct enum_list enum_server_role[] = {
187 {ROLE_STANDALONE, "standalone"},
188 {ROLE_DOMAIN_MEMBER, "member server"},
189 {ROLE_DOMAIN_MEMBER, "member"},
190 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
191 {ROLE_DOMAIN_CONTROLLER, "dc"},
195 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
196 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
198 static struct parm_struct parm_table[] = {
200 .label = "server role",
203 .offset = GLOBAL_VAR(server_role),
205 .enum_list = enum_server_role
208 .label = "dos charset",
211 .offset = GLOBAL_VAR(dos_charset),
216 .label = "unix charset",
219 .offset = GLOBAL_VAR(unix_charset),
224 .label = "ncalrpc dir",
227 .offset = GLOBAL_VAR(ncalrpc_dir),
235 .offset = LOCAL_VAR(comment),
243 .offset = LOCAL_VAR(szPath),
248 .label = "directory",
251 .offset = LOCAL_VAR(szPath),
256 .label = "workgroup",
259 .offset = GLOBAL_VAR(szWorkgroup),
267 .offset = GLOBAL_VAR(szRealm),
268 .special = handle_realm,
272 .label = "netbios name",
275 .offset = GLOBAL_VAR(szNetbiosName),
280 .label = "netbios aliases",
283 .offset = GLOBAL_VAR(szNetbiosAliases),
288 .label = "netbios scope",
291 .offset = GLOBAL_VAR(szNetbiosScope),
296 .label = "server string",
299 .offset = GLOBAL_VAR(szServerString),
304 .label = "interfaces",
307 .offset = GLOBAL_VAR(szInterfaces),
312 .label = "bind interfaces only",
315 .offset = GLOBAL_VAR(bBindInterfacesOnly),
320 .label = "ntvfs handler",
323 .offset = LOCAL_VAR(ntvfs_handler),
328 .label = "ntptr providor",
331 .offset = GLOBAL_VAR(ntptr_providor),
336 .label = "dcerpc endpoint servers",
339 .offset = GLOBAL_VAR(dcerpc_ep_servers),
344 .label = "server services",
347 .offset = GLOBAL_VAR(server_services),
356 .offset = GLOBAL_VAR(security),
358 .enum_list = enum_security
361 .label = "encrypt passwords",
364 .offset = GLOBAL_VAR(bEncryptPasswords),
369 .label = "null passwords",
372 .offset = GLOBAL_VAR(bNullPasswords),
377 .label = "obey pam restrictions",
380 .offset = GLOBAL_VAR(bObeyPamRestrictions),
385 .label = "password server",
388 .offset = GLOBAL_VAR(szPasswordServers),
393 .label = "spoolss database",
396 .offset = GLOBAL_VAR(szSPOOLSS_URL),
401 .label = "wins config database",
404 .offset = GLOBAL_VAR(szWINS_CONFIG_URL),
409 .label = "wins database",
412 .offset = GLOBAL_VAR(szWINS_URL),
417 .label = "private dir",
420 .offset = GLOBAL_VAR(szPrivateDir),
425 .label = "passwd chat",
428 .offset = GLOBAL_VAR(szPasswdChat),
433 .label = "password level",
436 .offset = GLOBAL_VAR(pwordlevel),
441 .label = "lanman auth",
444 .offset = GLOBAL_VAR(bLanmanAuth),
449 .label = "ntlm auth",
452 .offset = GLOBAL_VAR(bNTLMAuth),
457 .label = "client NTLMv2 auth",
460 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
465 .label = "client lanman auth",
468 .offset = GLOBAL_VAR(bClientLanManAuth),
473 .label = "client plaintext auth",
476 .offset = GLOBAL_VAR(bClientPlaintextAuth),
481 .label = "client use spnego principal",
484 .offset = GLOBAL_VAR(client_use_spnego_principal),
490 .label = "read only",
493 .offset = LOCAL_VAR(bRead_only),
499 .label = "create mask",
502 .offset = LOCAL_VAR(iCreate_mask),
507 .label = "force create mode",
510 .offset = LOCAL_VAR(iCreate_force_mode),
515 .label = "directory mask",
518 .offset = LOCAL_VAR(iDir_mask),
523 .label = "force directory mode",
526 .offset = LOCAL_VAR(iDir_force_mode),
532 .label = "hosts allow",
535 .offset = LOCAL_VAR(szHostsallow),
540 .label = "hosts deny",
543 .offset = LOCAL_VAR(szHostsdeny),
549 .label = "log level",
552 .offset = GLOBAL_VAR(loglevel),
553 .special = handle_debuglevel,
557 .label = "debuglevel",
560 .offset = GLOBAL_VAR(loglevel),
561 .special = handle_debuglevel,
568 .offset = GLOBAL_VAR(logfile),
569 .special = handle_logfile,
574 .label = "smb ports",
577 .offset = GLOBAL_VAR(smb_ports),
585 .offset = GLOBAL_VAR(nbt_port),
590 .label = "dgram port",
593 .offset = GLOBAL_VAR(dgram_port),
598 .label = "cldap port",
601 .offset = GLOBAL_VAR(cldap_port),
606 .label = "krb5 port",
609 .offset = GLOBAL_VAR(krb5_port),
614 .label = "kpasswd port",
617 .offset = GLOBAL_VAR(kpasswd_port),
625 .offset = GLOBAL_VAR(web_port),
630 .label = "tls enabled",
633 .offset = GLOBAL_VAR(tls_enabled),
638 .label = "tls keyfile",
641 .offset = GLOBAL_VAR(tls_keyfile),
646 .label = "tls certfile",
649 .offset = GLOBAL_VAR(tls_certfile),
654 .label = "tls cafile",
657 .offset = GLOBAL_VAR(tls_cafile),
662 .label = "tls crlfile",
665 .offset = GLOBAL_VAR(tls_crlfile),
670 .label = "tls dh params file",
673 .offset = GLOBAL_VAR(tls_dhpfile),
678 .label = "large readwrite",
681 .offset = GLOBAL_VAR(bLargeReadwrite),
686 .label = "server max protocol",
689 .offset = GLOBAL_VAR(srv_maxprotocol),
691 .enum_list = enum_protocol
694 .label = "server min protocol",
697 .offset = GLOBAL_VAR(srv_minprotocol),
699 .enum_list = enum_protocol
702 .label = "client max protocol",
705 .offset = GLOBAL_VAR(cli_maxprotocol),
707 .enum_list = enum_protocol
710 .label = "client min protocol",
713 .offset = GLOBAL_VAR(cli_minprotocol),
715 .enum_list = enum_protocol
721 .offset = GLOBAL_VAR(bUnicode),
729 .offset = GLOBAL_VAR(bReadRaw),
734 .label = "write raw",
737 .offset = GLOBAL_VAR(bWriteRaw),
742 .label = "disable netbios",
745 .offset = GLOBAL_VAR(bDisableNetbios),
751 .label = "nt status support",
754 .offset = GLOBAL_VAR(bNTStatusSupport),
760 .label = "announce version",
763 .offset = GLOBAL_VAR(szAnnounceVersion),
771 .offset = GLOBAL_VAR(max_mux),
779 .offset = GLOBAL_VAR(max_xmit),
785 .label = "name resolve order",
788 .offset = GLOBAL_VAR(szNameResolveOrder),
793 .label = "max wins ttl",
796 .offset = GLOBAL_VAR(max_wins_ttl),
801 .label = "min wins ttl",
804 .offset = GLOBAL_VAR(min_wins_ttl),
809 .label = "time server",
812 .offset = GLOBAL_VAR(bTimeServer),
817 .label = "unix extensions",
820 .offset = GLOBAL_VAR(bUnixExtensions),
825 .label = "use spnego",
828 .offset = GLOBAL_VAR(bUseSpnego),
833 .label = "server signing",
836 .offset = GLOBAL_VAR(server_signing),
838 .enum_list = enum_smb_signing_vals
841 .label = "client signing",
844 .offset = GLOBAL_VAR(client_signing),
846 .enum_list = enum_smb_signing_vals
849 .label = "rpc big endian",
852 .offset = GLOBAL_VAR(bRpcBigEndian),
858 .label = "max connections",
861 .offset = LOCAL_VAR(iMaxConnections),
866 .label = "paranoid server security",
869 .offset = GLOBAL_VAR(paranoid_server_security),
874 .label = "socket options",
877 .offset = GLOBAL_VAR(socket_options),
883 .label = "strict sync",
886 .offset = LOCAL_VAR(bStrictSync),
891 .label = "case insensitive filesystem",
894 .offset = LOCAL_VAR(bCIFileSystem),
900 .label = "max print jobs",
903 .offset = LOCAL_VAR(iMaxPrintJobs),
908 .label = "printable",
911 .offset = LOCAL_VAR(bPrint_ok),
919 .offset = LOCAL_VAR(bPrint_ok),
925 .label = "printer name",
928 .offset = LOCAL_VAR(szPrintername),
936 .offset = LOCAL_VAR(szPrintername),
942 .label = "map system",
945 .offset = LOCAL_VAR(bMap_system),
950 .label = "map hidden",
953 .offset = LOCAL_VAR(bMap_hidden),
958 .label = "map archive",
961 .offset = LOCAL_VAR(bMap_archive),
967 .label = "preferred master",
970 .offset = GLOBAL_VAR(bPreferredMaster),
972 .enum_list = enum_bool_auto
975 .label = "prefered master",
978 .offset = GLOBAL_VAR(bPreferredMaster),
980 .enum_list = enum_bool_auto
983 .label = "local master",
986 .offset = GLOBAL_VAR(bLocalMaster),
991 .label = "browseable",
994 .offset = LOCAL_VAR(bBrowseable),
999 .label = "browsable",
1002 .offset = LOCAL_VAR(bBrowseable),
1008 .label = "wins server",
1010 .p_class = P_GLOBAL,
1011 .offset = GLOBAL_VAR(szWINSservers),
1016 .label = "wins support",
1018 .p_class = P_GLOBAL,
1019 .offset = GLOBAL_VAR(bWINSsupport),
1024 .label = "dns proxy",
1026 .p_class = P_GLOBAL,
1027 .offset = GLOBAL_VAR(bWINSdnsProxy),
1032 .label = "wins hook",
1034 .p_class = P_GLOBAL,
1035 .offset = GLOBAL_VAR(szWINSHook),
1041 .label = "csc policy",
1044 .offset = LOCAL_VAR(iCSCPolicy),
1046 .enum_list = enum_csc_policy
1050 .label = "strict locking",
1053 .offset = LOCAL_VAR(bStrictLocking),
1061 .offset = LOCAL_VAR(bOplocks),
1067 .label = "share backend",
1069 .p_class = P_GLOBAL,
1070 .offset = GLOBAL_VAR(szShareBackend),
1077 .p_class = P_GLOBAL,
1078 .offset = GLOBAL_VAR(szAutoServices),
1083 .label = "auto services",
1085 .p_class = P_GLOBAL,
1086 .offset = GLOBAL_VAR(szAutoServices),
1091 .label = "lock dir",
1093 .p_class = P_GLOBAL,
1094 .offset = GLOBAL_VAR(szLockDir),
1099 .label = "lock directory",
1101 .p_class = P_GLOBAL,
1102 .offset = GLOBAL_VAR(szLockDir),
1107 .label = "pid directory",
1109 .p_class = P_GLOBAL,
1110 .offset = GLOBAL_VAR(szPidDir),
1116 .label = "socket address",
1118 .p_class = P_GLOBAL,
1119 .offset = GLOBAL_VAR(szSocketAddress),
1127 .offset = LOCAL_VAR(szCopy),
1128 .special = handle_copy,
1135 .offset = LOCAL_VAR(szInclude),
1136 .special = handle_include,
1141 .label = "available",
1144 .offset = LOCAL_VAR(bAvailable),
1152 .offset = LOCAL_VAR(volume),
1160 .offset = LOCAL_VAR(fstype),
1166 .label = "panic action",
1168 .p_class = P_GLOBAL,
1169 .offset = GLOBAL_VAR(panic_action),
1175 .label = "msdfs root",
1178 .offset = LOCAL_VAR(bMSDfsRoot),
1183 .label = "host msdfs",
1185 .p_class = P_GLOBAL,
1186 .offset = GLOBAL_VAR(bHostMSDfs),
1191 .label = "winbind separator",
1193 .p_class = P_GLOBAL,
1194 .offset = GLOBAL_VAR(szWinbindSeparator),
1199 .label = "winbindd socket directory",
1201 .p_class = P_GLOBAL,
1202 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1207 .label = "winbindd privileged socket directory",
1209 .p_class = P_GLOBAL,
1210 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1215 .label = "winbind sealed pipes",
1217 .p_class = P_GLOBAL,
1218 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1223 .label = "template shell",
1225 .p_class = P_GLOBAL,
1226 .offset = GLOBAL_VAR(szTemplateShell),
1231 .label = "template homedir",
1233 .p_class = P_GLOBAL,
1234 .offset = GLOBAL_VAR(szTemplateHomedir),
1239 .label = "idmap trusted only",
1241 .p_class = P_GLOBAL,
1242 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1248 .label = "ntp signd socket directory",
1250 .p_class = P_GLOBAL,
1251 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1256 .label = "rndc command",
1258 .p_class = P_GLOBAL,
1259 .offset = GLOBAL_VAR(szRNDCCommand),
1264 .label = "dns update command",
1266 .p_class = P_GLOBAL,
1267 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1272 .label = "spn update command",
1274 .p_class = P_GLOBAL,
1275 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1280 .label = "nsupdate command",
1282 .p_class = P_GLOBAL,
1283 .offset = GLOBAL_VAR(szNSUpdateCommand),
1288 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1292 /* local variables */
1293 struct loadparm_context {
1294 const char *szConfigFile;
1295 struct loadparm_global *globals;
1296 struct loadparm_service **services;
1297 struct loadparm_service *sDefault;
1298 struct smb_iconv_handle *iconv_handle;
1300 struct loadparm_service *currentService;
1301 bool bInGlobalSection;
1303 struct file_lists *next;
1308 unsigned int flags[NUMPARAMETERS];
1311 bool global; /* Is this the global context, which may set
1312 * global variables such as debug level etc? */
1313 const struct loadparm_s3_context *s3_fns;
1317 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1319 return lp_ctx->sDefault;
1323 return the parameter table
1325 struct parm_struct *lpcfg_parm_table(void)
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 #define FN_LOCAL_STRING(fn_name,val) \
1445 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1446 struct loadparm_service *sDefault) { \
1447 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1450 #define FN_LOCAL_LIST(fn_name,val) \
1451 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1452 struct loadparm_service *sDefault) {\
1453 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1456 #define FN_LOCAL_BOOL(fn_name,val) \
1457 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1458 struct loadparm_service *sDefault) { \
1459 return((service != NULL)? service->val : sDefault->val); \
1462 #define FN_LOCAL_INTEGER(fn_name,val) \
1463 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1464 struct loadparm_service *sDefault) { \
1465 return((service != NULL)? service->val : sDefault->val); \
1468 FN_GLOBAL_INTEGER(server_role, server_role)
1469 FN_GLOBAL_LIST(smb_ports, smb_ports)
1470 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1471 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1472 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1473 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1474 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1475 FN_GLOBAL_INTEGER(web_port, web_port)
1476 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1477 FN_GLOBAL_STRING(logfile, logfile)
1478 FN_GLOBAL_STRING(share_backend, szShareBackend)
1479 FN_GLOBAL_STRING(spoolss_url, szSPOOLSS_URL)
1480 FN_GLOBAL_STRING(wins_config_url, szWINS_CONFIG_URL)
1481 FN_GLOBAL_STRING(wins_url, szWINS_URL)
1482 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1483 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1484 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1485 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1486 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1487 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1488 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1489 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1490 FN_GLOBAL_STRING(serverstring, szServerString)
1491 FN_GLOBAL_STRING(lockdir, szLockDir)
1492 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1493 FN_GLOBAL_STRING(dos_charset, dos_charset)
1494 FN_GLOBAL_STRING(unix_charset, unix_charset)
1495 FN_GLOBAL_STRING(piddir, szPidDir)
1496 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1497 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1498 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1499 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1500 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1501 FN_GLOBAL_LIST(server_services, server_services)
1502 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1503 FN_GLOBAL_STRING(auto_services, szAutoServices)
1504 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1505 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1506 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1507 FN_GLOBAL_STRING(realm, szRealm_upper)
1508 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1509 FN_GLOBAL_STRING(socket_options, socket_options)
1510 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1511 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1512 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1513 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1514 FN_GLOBAL_LIST(interfaces, szInterfaces)
1515 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1516 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1517 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1518 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1519 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1520 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1521 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1522 FN_GLOBAL_BOOL(readraw, bReadRaw)
1523 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1524 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1525 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1526 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1527 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1528 FN_GLOBAL_BOOL(time_server, bTimeServer)
1529 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1530 FN_GLOBAL_BOOL(unicode, bUnicode)
1531 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1532 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1533 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1534 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1535 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1536 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1537 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1538 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1539 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1540 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1541 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1542 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1543 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1544 FN_GLOBAL_INTEGER(maxmux, max_mux)
1545 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1546 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1547 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1548 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1549 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1550 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1551 FN_GLOBAL_INTEGER(security, security)
1552 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1554 FN_LOCAL_STRING(pathname, szPath)
1555 FN_LOCAL_LIST(hostsallow, szHostsallow)
1556 FN_LOCAL_LIST(hostsdeny, szHostsdeny)
1557 FN_LOCAL_STRING(comment, comment)
1558 FN_LOCAL_STRING(fstype, fstype)
1559 FN_LOCAL_LIST(ntvfs_handler, ntvfs_handler)
1560 FN_LOCAL_BOOL(msdfs_root, bMSDfsRoot)
1561 FN_LOCAL_BOOL(browseable, bBrowseable)
1562 FN_LOCAL_BOOL(readonly, bRead_only)
1563 FN_LOCAL_BOOL(print_ok, bPrint_ok)
1564 FN_LOCAL_BOOL(map_hidden, bMap_hidden)
1565 FN_LOCAL_BOOL(map_archive, bMap_archive)
1566 FN_LOCAL_BOOL(strict_locking, bStrictLocking)
1567 FN_LOCAL_BOOL(oplocks, bOplocks)
1568 FN_LOCAL_BOOL(strict_sync, bStrictSync)
1569 FN_LOCAL_BOOL(ci_filesystem, bCIFileSystem)
1570 FN_LOCAL_BOOL(map_system, bMap_system)
1571 FN_LOCAL_INTEGER(max_connections, iMaxConnections)
1572 FN_LOCAL_INTEGER(csc_policy, iCSCPolicy)
1573 FN_LOCAL_INTEGER(create_mask, iCreate_mask)
1574 FN_LOCAL_INTEGER(force_create_mode, iCreate_force_mode)
1575 FN_LOCAL_INTEGER(dir_mask, iDir_mask)
1576 FN_LOCAL_INTEGER(force_dir_mode, iDir_force_mode)
1577 FN_GLOBAL_INTEGER(server_signing, server_signing)
1578 FN_GLOBAL_INTEGER(client_signing, client_signing)
1580 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1582 /* local prototypes */
1583 static int map_parameter(const char *pszParmName);
1584 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1585 const char *pszServiceName);
1586 static void copy_service(struct loadparm_service *pserviceDest,
1587 struct loadparm_service *pserviceSource,
1589 static bool service_ok(struct loadparm_service *service);
1590 static bool do_section(const char *pszSectionName, void *);
1591 static void init_copymap(struct loadparm_service *pservice);
1593 /* This is a helper function for parametrical options support. */
1594 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1595 /* Actual parametrical functions are quite simple */
1596 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1597 struct loadparm_service *service,
1598 const char *type, const char *option)
1600 char *vfskey_tmp = NULL;
1601 char *vfskey = NULL;
1602 struct parmlist_entry *data;
1607 if (lp_ctx->s3_fns) {
1608 SMB_ASSERT(service == NULL);
1609 return lp_ctx->s3_fns->get_parametric(type, option);
1612 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1614 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1615 if (vfskey_tmp == NULL) return NULL;
1616 vfskey = strlower_talloc(NULL, vfskey_tmp);
1617 talloc_free(vfskey_tmp);
1620 if (strcmp(data->key, vfskey) == 0) {
1621 talloc_free(vfskey);
1627 if (service != NULL) {
1628 /* Try to fetch the same option but from globals */
1629 /* but only if we are not already working with globals */
1630 for (data = lp_ctx->globals->param_opt; data;
1631 data = data->next) {
1632 if (strcmp(data->key, vfskey) == 0) {
1633 talloc_free(vfskey);
1639 talloc_free(vfskey);
1646 * convenience routine to return int parameters.
1648 static int lp_int(const char *s)
1652 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1656 return strtol(s, NULL, 0);
1660 * convenience routine to return unsigned long parameters.
1662 static int lp_ulong(const char *s)
1666 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1670 return strtoul(s, NULL, 0);
1674 * convenience routine to return unsigned long parameters.
1676 static double lp_double(const char *s)
1680 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1684 return strtod(s, NULL);
1688 * convenience routine to return boolean parameters.
1690 static bool lp_bool(const char *s)
1695 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1699 if (!set_boolean(s, &ret)) {
1700 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1709 * Return parametric option from a given service. Type is a part of option before ':'
1710 * Parametric option has following syntax: 'Type: option = value'
1711 * Returned value is allocated in 'lp_talloc' context
1714 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1715 struct loadparm_service *service, const char *type,
1718 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1721 return lp_string(value);
1727 * Return parametric option from a given service. Type is a part of option before ':'
1728 * Parametric option has following syntax: 'Type: option = value'
1729 * Returned value is allocated in 'lp_talloc' context
1732 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1733 struct loadparm_context *lp_ctx,
1734 struct loadparm_service *service,
1736 const char *option, const char *separator)
1738 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1741 return (const char **)str_list_make(mem_ctx, value, separator);
1747 * Return parametric option from a given service. Type is a part of option before ':'
1748 * Parametric option has following syntax: 'Type: option = value'
1751 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1752 struct loadparm_service *service, const char *type,
1753 const char *option, int default_v)
1755 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1758 return lp_int(value);
1764 * Return parametric option from a given service. Type is a part of
1765 * option before ':'.
1766 * Parametric option has following syntax: 'Type: option = value'.
1769 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1770 struct loadparm_service *service, const char *type,
1771 const char *option, int default_v)
1775 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1777 if (value && conv_str_size_error(value, &bval)) {
1778 if (bval <= INT_MAX) {
1787 * Return parametric option from a given service.
1788 * Type is a part of option before ':'
1789 * Parametric option has following syntax: 'Type: option = value'
1791 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1792 struct loadparm_service *service, const char *type,
1793 const char *option, unsigned long default_v)
1795 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1798 return lp_ulong(value);
1804 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1805 struct loadparm_service *service, const char *type,
1806 const char *option, double default_v)
1808 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1811 return lp_double(value);
1817 * Return parametric option from a given service. Type is a part of option before ':'
1818 * Parametric option has following syntax: 'Type: option = value'
1821 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1822 struct loadparm_service *service, const char *type,
1823 const char *option, bool default_v)
1825 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1828 return lp_bool(value);
1835 * Initialise a service to the defaults.
1838 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1840 struct loadparm_service *pservice =
1841 talloc_zero(mem_ctx, struct loadparm_service);
1842 copy_service(pservice, sDefault, NULL);
1847 * Set a string value, deallocating any existing space, and allocing the space
1850 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1857 *dest = talloc_strdup(mem_ctx, src);
1858 if ((*dest) == NULL) {
1859 DEBUG(0,("Out of memory in string_set\n"));
1867 * Set a string value, deallocating any existing space, and allocing the space
1870 static bool string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1877 *dest = strupper_talloc(mem_ctx, src);
1878 if ((*dest) == NULL) {
1879 DEBUG(0,("Out of memory in string_set_upper\n"));
1889 * Add a new service to the services array initialising it with the given
1893 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1894 const struct loadparm_service *pservice,
1898 struct loadparm_service tservice;
1899 int num_to_alloc = lp_ctx->iNumServices + 1;
1900 struct parmlist_entry *data, *pdata;
1902 if (pservice == NULL) {
1903 pservice = lp_ctx->sDefault;
1906 tservice = *pservice;
1908 /* it might already exist */
1910 struct loadparm_service *service = getservicebyname(lp_ctx,
1912 if (service != NULL) {
1913 /* Clean all parametric options for service */
1914 /* They will be added during parsing again */
1915 data = service->param_opt;
1921 service->param_opt = NULL;
1926 /* find an invalid one */
1927 for (i = 0; i < lp_ctx->iNumServices; i++)
1928 if (lp_ctx->services[i] == NULL)
1931 /* if not, then create one */
1932 if (i == lp_ctx->iNumServices) {
1933 struct loadparm_service **tsp;
1935 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1938 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1941 lp_ctx->services = tsp;
1942 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1945 lp_ctx->iNumServices++;
1948 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1949 if (lp_ctx->services[i] == NULL) {
1950 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1953 copy_service(lp_ctx->services[i], &tservice, NULL);
1955 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1956 return lp_ctx->services[i];
1960 * Add a new home service, with the specified home directory, defaults coming
1961 * from service ifrom.
1964 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1965 const char *pszHomename,
1966 struct loadparm_service *default_service,
1967 const char *user, const char *pszHomedir)
1969 struct loadparm_service *service;
1971 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1973 if (service == NULL)
1976 if (!(*(default_service->szPath))
1977 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1978 service->szPath = talloc_strdup(service, pszHomedir);
1980 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1983 if (!(*(service->comment))) {
1984 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1986 service->bAvailable = default_service->bAvailable;
1987 service->bBrowseable = default_service->bBrowseable;
1989 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1990 pszHomename, user, service->szPath));
1996 * Add a new printer service, with defaults coming from service iFrom.
1999 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
2000 const char *pszPrintername,
2001 struct loadparm_service *default_service)
2003 const char *comment = "From Printcap";
2004 struct loadparm_service *service;
2005 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2007 if (service == NULL)
2010 /* note that we do NOT default the availability flag to True - */
2011 /* we take it from the default service passed. This allows all */
2012 /* dynamic printers to be disabled by disabling the [printers] */
2013 /* entry (if/when the 'available' keyword is implemented!). */
2015 /* the printer name is set to the service name. */
2016 string_set(service, &service->szPrintername, pszPrintername);
2017 string_set(service, &service->comment, comment);
2018 service->bBrowseable = default_service->bBrowseable;
2019 /* Printers cannot be read_only. */
2020 service->bRead_only = false;
2021 /* Printer services must be printable. */
2022 service->bPrint_ok = true;
2024 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2030 * Map a parameter's string representation to something we can use.
2031 * Returns False if the parameter string is not recognised, else TRUE.
2034 static int map_parameter(const char *pszParmName)
2038 if (*pszParmName == '-')
2041 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2042 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2045 /* Warn only if it isn't parametric option */
2046 if (strchr(pszParmName, ':') == NULL)
2047 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2048 /* We do return 'fail' for parametric options as well because they are
2049 stored in different storage
2056 return the parameter structure for a parameter
2058 struct parm_struct *lpcfg_parm_struct(const char *name)
2060 int parmnum = map_parameter(name);
2061 if (parmnum == -1) return NULL;
2062 return &parm_table[parmnum];
2066 return the parameter pointer for a parameter
2068 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2069 struct loadparm_service *service, struct parm_struct *parm)
2071 if (service == NULL) {
2072 if (parm->p_class == P_LOCAL)
2073 return ((char *)lp_ctx->sDefault)+parm->offset;
2074 else if (parm->p_class == P_GLOBAL)
2075 return ((char *)lp_ctx->globals)+parm->offset;
2078 return ((char *)service) + parm->offset;
2083 * Find a service by name. Otherwise works like get_service.
2086 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2087 const char *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,
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].offset != -1 && parm_table[i].p_class == P_LOCAL &&
2116 (bcopyall || pcopymapDest[i])) {
2118 ((char *)pserviceSource) + parm_table[i].offset;
2120 ((char *)pserviceDest) + parm_table[i].offset;
2122 switch (parm_table[i].type) {
2124 *(int *)dest_ptr = *(int *)src_ptr;
2130 *(int *)dest_ptr = *(int *)src_ptr;
2134 string_set(pserviceDest,
2140 string_set_upper(pserviceDest,
2145 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2146 *(const char ***)src_ptr);
2154 init_copymap(pserviceDest);
2155 if (pserviceSource->copymap)
2156 memcpy((void *)pserviceDest->copymap,
2157 (void *)pserviceSource->copymap,
2158 sizeof(int) * NUMPARAMETERS);
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_reference(pdata,
2175 pdata = pdata->next;
2178 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2181 paramo->key = talloc_reference(paramo, data->key);
2182 paramo->value = talloc_reference(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 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 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 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 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 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 string_set(lp_ctx, ptr, pszParmValue);
2391 /***************************************************************************
2392 Initialise a copymap.
2393 ***************************************************************************/
2395 static void init_copymap(struct loadparm_service *pservice)
2398 talloc_free(pservice->copymap);
2399 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
2400 if (pservice->copymap == NULL) {
2402 ("Couldn't allocate copymap!! (size %d)\n",
2403 (int)NUMPARAMETERS));
2406 for (i = 0; i < NUMPARAMETERS; i++)
2407 pservice->copymap[i] = true;
2411 * Process a parametric option
2413 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2414 struct loadparm_service *service,
2415 const char *pszParmName,
2416 const char *pszParmValue, int flags)
2418 struct parmlist_entry *paramo, *data;
2420 TALLOC_CTX *mem_ctx;
2422 while (isspace((unsigned char)*pszParmName)) {
2426 name = strlower_talloc(lp_ctx, pszParmName);
2427 if (!name) return false;
2429 if (service == NULL) {
2430 data = lp_ctx->globals->param_opt;
2431 mem_ctx = lp_ctx->globals;
2433 data = service->param_opt;
2437 /* Traverse destination */
2438 for (paramo=data; paramo; paramo=paramo->next) {
2439 /* If we already have the option set, override it unless
2440 it was a command line option and the new one isn't */
2441 if (strcmp(paramo->key, name) == 0) {
2442 if ((paramo->priority & FLAG_CMDLINE) &&
2443 !(flags & FLAG_CMDLINE)) {
2448 talloc_free(paramo->value);
2449 paramo->value = talloc_strdup(paramo, pszParmValue);
2450 paramo->priority = flags;
2456 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2459 paramo->key = talloc_strdup(paramo, name);
2460 paramo->value = talloc_strdup(paramo, pszParmValue);
2461 paramo->priority = flags;
2462 if (service == NULL) {
2463 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2465 DLIST_ADD(service->param_opt, paramo);
2473 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2474 const char *pszParmName, const char *pszParmValue,
2475 struct loadparm_context *lp_ctx, bool on_globals)
2478 /* if it is a special case then go ahead */
2479 if (parm_table[parmnum].special) {
2481 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2486 goto mark_non_default;
2489 /* now switch on the type of variable it is */
2490 switch (parm_table[parmnum].type)
2494 if (!set_boolean(pszParmValue, &b)) {
2495 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2498 *(int *)parm_ptr = b;
2504 if (!set_boolean(pszParmValue, &b)) {
2505 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2508 *(int *)parm_ptr = !b;
2513 *(int *)parm_ptr = atoi(pszParmValue);
2517 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2523 if (conv_str_size_error(pszParmValue, &val)) {
2524 if (val <= INT_MAX) {
2525 *(int *)parm_ptr = (int)val;
2530 DEBUG(0,("lp_do_parameter(%s): value is not "
2531 "a valid size specifier!\n", pszParmValue));
2536 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2537 pszParmValue, NULL);
2541 char **new_list = str_list_make(mem_ctx,
2542 pszParmValue, NULL);
2543 for (i=0; new_list[i]; i++) {
2544 if (new_list[i][0] == '+' && new_list[i][1] &&
2545 (!str_list_check(*(const char ***)parm_ptr,
2546 &new_list[i][1]))) {
2547 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2549 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2550 #if 0 /* This is commented out because we sometimes parse the list
2551 * twice, and so we can't assert on this */
2552 if (!str_list_check(*(const char ***)parm_ptr,
2554 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2555 pszParmName, pszParmValue, new_list[i],
2556 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2561 str_list_remove(*(const char ***)parm_ptr,
2565 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2566 pszParmName, pszParmValue));
2569 *(const char ***)parm_ptr = (const char **) new_list;
2576 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2580 string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2584 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2587 parm_table[parmnum].enum_list[i].name)) {
2589 parm_table[parmnum].
2594 if (!parm_table[parmnum].enum_list[i].name) {
2595 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2596 pszParmValue, pszParmName));
2603 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2604 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2605 /* we have to also unset FLAG_DEFAULT on aliases */
2606 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2607 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2609 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2610 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2617 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2618 const char *pszParmName, const char *pszParmValue)
2620 int parmnum = map_parameter(pszParmName);
2624 if (strchr(pszParmName, ':')) {
2625 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2627 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2631 /* if the flag has been set on the command line, then don't allow override,
2632 but don't report an error */
2633 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2637 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2639 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2640 pszParmName, pszParmValue, lp_ctx, true);
2643 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2644 struct loadparm_service *service,
2645 const char *pszParmName, const char *pszParmValue)
2649 int parmnum = map_parameter(pszParmName);
2652 if (strchr(pszParmName, ':')) {
2653 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2655 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2659 /* if the flag has been set on the command line, then don't allow override,
2660 but don't report an error */
2661 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2665 if (parm_table[parmnum].p_class == P_GLOBAL) {
2667 ("Global parameter %s found in service section!\n",
2671 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2673 if (!service->copymap)
2674 init_copymap(service);
2676 /* this handles the aliases - set the copymap for other
2677 * entries with the same data pointer */
2678 for (i = 0; parm_table[i].label; i++)
2679 if (parm_table[i].offset == parm_table[parmnum].offset &&
2680 parm_table[i].p_class == parm_table[parmnum].p_class)
2681 service->copymap[i] = false;
2683 return set_variable(service, parmnum, parm_ptr, pszParmName,
2684 pszParmValue, lp_ctx, false);
2688 * Process a parameter.
2691 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2694 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2696 if (lp_ctx->bInGlobalSection)
2697 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2700 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2701 pszParmName, pszParmValue);
2705 variable argument do parameter
2707 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2708 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2709 const char *pszParmName, const char *fmt, ...)
2716 s = talloc_vasprintf(NULL, fmt, ap);
2718 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2725 set a parameter from the commandline - this is called from command line parameter
2726 parsing code. It sets the parameter then marks the parameter as unable to be modified
2727 by smb.conf processing
2729 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2730 const char *pszParmValue)
2732 int parmnum = map_parameter(pszParmName);
2735 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2738 if (parmnum < 0 && strchr(pszParmName, ':')) {
2739 /* set a parametric option */
2740 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2741 pszParmValue, FLAG_CMDLINE);
2745 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2749 /* reset the CMDLINE flag in case this has been called before */
2750 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2752 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2756 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2758 /* we have to also set FLAG_CMDLINE on aliases */
2759 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2760 lp_ctx->flags[i] |= FLAG_CMDLINE;
2762 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2763 lp_ctx->flags[i] |= FLAG_CMDLINE;
2770 set a option from the commandline in 'a=b' format. Use to support --option
2772 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2790 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2796 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2799 * Print a parameter of the specified type.
2802 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2805 const char *list_sep = ", "; /* For the seperation of lists values that we print below */
2809 for (i = 0; p->enum_list[i].name; i++) {
2810 if (*(int *)ptr == p->enum_list[i].value) {
2812 p->enum_list[i].name);
2819 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
2823 fprintf(f, "%s", BOOLSTR(!(bool)*(int *)ptr));
2828 fprintf(f, "%d", *(int *)ptr);
2832 fprintf(f, "0%o", *(int *)ptr);
2839 if ((char ***)ptr && *(char ***)ptr) {
2840 char **list = *(char ***)ptr;
2842 for (; *list; list++) {
2843 if (*(list+1) == NULL) {
2844 /* last item, print no extra seperator after */
2847 fprintf(f, "%s%s", *list, list_sep);
2854 if (*(char **)ptr) {
2855 fprintf(f, "%s", *(char **)ptr);
2862 * Check if two parameters are equal.
2865 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2870 return (*((int *)ptr1) == *((int *)ptr2));
2876 return (*((int *)ptr1) == *((int *)ptr2));
2880 return str_list_equal((const char **)(*(char ***)ptr1),
2881 (const char **)(*(char ***)ptr2));
2886 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2891 return (p1 == p2 || strequal(p1, p2));
2898 * Process a new section (service).
2900 * At this stage all sections are services.
2901 * Later we'll have special sections that permit server parameters to be set.
2902 * Returns True on success, False on failure.
2905 static bool do_section(const char *pszSectionName, void *userdata)
2907 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2909 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2910 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2913 /* if we've just struck a global section, note the fact. */
2914 lp_ctx->bInGlobalSection = isglobal;
2916 /* check for multiple global sections */
2917 if (lp_ctx->bInGlobalSection) {
2918 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2922 /* if we have a current service, tidy it up before moving on */
2925 if (lp_ctx->currentService != NULL)
2926 bRetval = service_ok(lp_ctx->currentService);
2928 /* if all is still well, move to the next record in the services array */
2930 /* We put this here to avoid an odd message order if messages are */
2931 /* issued by the post-processing of a previous section. */
2932 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2934 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2937 DEBUG(0, ("Failed to add a new service\n"));
2947 * Determine if a particular base parameter is currently set to the default value.
2950 static bool is_default(struct loadparm_service *sDefault, int i)
2952 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2953 if (!defaults_saved)
2955 switch (parm_table[i].type) {
2958 return str_list_equal((const char **)parm_table[i].def.lvalue,
2959 (const char **)def_ptr);
2962 return strequal(parm_table[i].def.svalue,
2966 return parm_table[i].def.bvalue ==
2972 return parm_table[i].def.ivalue ==
2979 *Display the contents of the global structure.
2982 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2986 struct parmlist_entry *data;
2988 fprintf(f, "# Global parameters\n[global]\n");
2990 for (i = 0; parm_table[i].label; i++)
2991 if (parm_table[i].p_class == P_GLOBAL &&
2992 parm_table[i].offset != -1 &&
2993 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2994 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2996 fprintf(f, "\t%s = ", parm_table[i].label);
2997 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3000 if (lp_ctx->globals->param_opt != NULL) {
3001 for (data = lp_ctx->globals->param_opt; data;
3002 data = data->next) {
3003 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3006 fprintf(f, "\t%s = %s\n", data->key, data->value);
3013 * Display the contents of a single services record.
3016 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3017 unsigned int *flags)
3020 struct parmlist_entry *data;
3022 if (pService != sDefault)
3023 fprintf(f, "\n[%s]\n", pService->szService);
3025 for (i = 0; parm_table[i].label; i++) {
3026 if (parm_table[i].p_class == P_LOCAL &&
3027 parm_table[i].offset != -1 &&
3028 (*parm_table[i].label != '-') &&
3029 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3031 if (pService == sDefault) {
3032 if (flags && (flags[i] & FLAG_DEFAULT)) {
3035 if (defaults_saved) {
3036 if (is_default(sDefault, i)) {
3041 if (equal_parameter(parm_table[i].type,
3042 ((char *)pService) +
3043 parm_table[i].offset,
3044 ((char *)sDefault) +
3045 parm_table[i].offset))
3049 fprintf(f, "\t%s = ", parm_table[i].label);
3050 print_parameter(&parm_table[i],
3051 ((char *)pService) + parm_table[i].offset, f);
3055 if (pService->param_opt != NULL) {
3056 for (data = pService->param_opt; data; data = data->next) {
3057 fprintf(f, "\t%s = %s\n", data->key, data->value);
3062 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3063 struct loadparm_service *service,
3064 const char *parm_name, FILE * f)
3066 struct parm_struct *parm;
3069 parm = lpcfg_parm_struct(parm_name);
3074 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3076 print_parameter(parm, ptr, f);
3082 * Return info about the next parameter in a service.
3083 * snum==-1 gives the globals.
3084 * Return NULL when out of parameters.
3088 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3092 /* do the globals */
3093 for (; parm_table[*i].label; (*i)++) {
3094 if (parm_table[*i].offset == -1
3095 || (*parm_table[*i].label == '-'))
3099 && (parm_table[*i].offset ==
3100 parm_table[(*i) - 1].offset))
3103 return &parm_table[(*i)++];
3106 struct loadparm_service *pService = lp_ctx->services[snum];
3108 for (; parm_table[*i].label; (*i)++) {
3109 if (parm_table[*i].p_class == P_LOCAL &&
3110 parm_table[*i].offset != -1 &&
3111 (*parm_table[*i].label != '-') &&
3113 (parm_table[*i].offset !=
3114 parm_table[(*i) - 1].offset)))
3116 if (allparameters ||
3117 !equal_parameter(parm_table[*i].type,
3118 ((char *)pService) +
3119 parm_table[*i].offset,
3120 ((char *)lp_ctx->sDefault) +
3121 parm_table[*i].offset))
3123 return &parm_table[(*i)++];
3134 * Auto-load some home services.
3136 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3144 * Unload unused services.
3147 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3148 struct smbsrv_connection *smb,
3149 bool (*snumused) (struct smbsrv_connection *, int))
3152 for (i = 0; i < lp_ctx->iNumServices; i++) {
3153 if (lp_ctx->services[i] == NULL)
3156 if (!snumused || !snumused(smb, i)) {
3157 talloc_free(lp_ctx->services[i]);
3158 lp_ctx->services[i] = NULL;
3164 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3166 struct parmlist_entry *data;
3168 if (lp_ctx->refuse_free) {
3169 /* someone is trying to free the
3170 global_loadparm_context.
3171 We can't allow that. */
3175 if (lp_ctx->globals->param_opt != NULL) {
3176 struct parmlist_entry *next;
3177 for (data = lp_ctx->globals->param_opt; data; data=next) {
3179 if (data->priority & FLAG_CMDLINE) continue;
3180 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3189 * Initialise the global parameter structure.
3191 * Note that most callers should use loadparm_init_global() instead
3193 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3197 struct loadparm_context *lp_ctx;
3198 struct parmlist_entry *parm;
3201 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3205 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3206 lp_ctx->bInGlobalSection = true;
3207 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3208 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3210 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3211 lp_ctx->sDefault->bAvailable = true;
3212 lp_ctx->sDefault->bBrowseable = true;
3213 lp_ctx->sDefault->bRead_only = true;
3214 lp_ctx->sDefault->bMap_archive = true;
3215 lp_ctx->sDefault->bStrictLocking = true;
3216 lp_ctx->sDefault->bOplocks = true;
3217 lp_ctx->sDefault->iCreate_mask = 0744;
3218 lp_ctx->sDefault->iCreate_force_mode = 0000;
3219 lp_ctx->sDefault->iDir_mask = 0755;
3220 lp_ctx->sDefault->iDir_force_mode = 0000;
3222 DEBUG(3, ("Initialising global parameters\n"));
3224 for (i = 0; parm_table[i].label; i++) {
3225 if ((parm_table[i].type == P_STRING ||
3226 parm_table[i].type == P_USTRING) &&
3227 parm_table[i].offset != -1 &&
3228 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3230 if (parm_table[i].p_class == P_LOCAL) {
3231 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3233 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3235 *r = talloc_strdup(lp_ctx, "");
3239 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3240 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3241 talloc_free(logfile);
3243 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3245 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3247 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3249 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
3251 /* options that can be set on the command line must be initialised via
3252 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3254 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3256 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3257 myname = get_myname(lp_ctx);
3258 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3259 talloc_free(myname);
3260 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3262 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3264 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3265 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3267 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3268 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate web");
3269 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3270 /* the winbind method for domain controllers is for both RODC
3271 auth forwarding and for trusted domains */
3272 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3273 lpcfg_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
3274 lpcfg_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
3275 lpcfg_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
3276 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3278 /* This hive should be dynamically generated by Samba using
3279 data from the sam, but for the moment leave it in a tdb to
3280 keep regedt32 from popping up an annoying dialog. */
3281 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3283 /* using UTF8 by default allows us to support all chars */
3284 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3286 /* Use codepage 850 as a default for the dos character set */
3287 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3290 * Allow the default PASSWD_CHAT to be overridden in local.h.
3292 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3294 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3295 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3296 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3298 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3299 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3300 "Samba %s", SAMBA_VERSION_STRING);
3302 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3304 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3305 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3306 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3307 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3308 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3309 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3310 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3311 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3312 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
3313 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3314 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3315 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3316 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3317 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3318 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3320 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3321 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3322 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3323 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3324 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3325 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3326 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3327 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3329 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3331 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3332 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3334 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3335 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3337 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3338 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3339 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3340 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3341 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3342 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3343 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3345 lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
3346 lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
3348 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3350 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3351 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3352 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3353 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3354 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3355 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3356 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3358 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3360 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3361 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3363 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3364 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3365 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3366 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3367 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3369 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3370 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3371 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3372 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3373 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3375 for (i = 0; parm_table[i].label; i++) {
3376 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3377 lp_ctx->flags[i] |= FLAG_DEFAULT;
3381 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3382 if (!(parm->priority & FLAG_CMDLINE)) {
3383 parm->priority |= FLAG_DEFAULT;
3391 * Initialise the global parameter structure.
3393 struct loadparm_context *loadparm_init_global(bool load_default)
3395 if (global_loadparm_context == NULL) {
3396 global_loadparm_context = loadparm_init(NULL);
3398 if (global_loadparm_context == NULL) {
3401 global_loadparm_context->global = true;
3402 if (load_default && !global_loadparm_context->loaded) {
3403 lpcfg_load_default(global_loadparm_context);
3405 global_loadparm_context->refuse_free = true;
3406 return global_loadparm_context;
3410 * Initialise the global parameter structure.
3412 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3413 const struct loadparm_s3_context *s3_fns)
3415 struct loadparm_context *loadparm_context = loadparm_init(mem_ctx);
3416 if (!loadparm_context) {
3419 loadparm_context->s3_fns = s3_fns;
3420 return loadparm_context;
3423 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3425 return lp_ctx->szConfigFile;
3428 const char *lp_default_path(void)
3430 if (getenv("SMB_CONF_PATH"))
3431 return getenv("SMB_CONF_PATH");
3433 return dyn_CONFIGFILE;
3437 * Update the internal state of a loadparm context after settings
3440 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3442 struct debug_settings settings;
3443 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3445 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3446 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3449 if (!lp_ctx->global) {
3453 panic_action = lp_ctx->globals->panic_action;
3455 reload_charcnv(lp_ctx);
3457 ZERO_STRUCT(settings);
3458 /* Add any more debug-related smb.conf parameters created in
3460 settings.timestamp_logs = true;
3461 debug_set_settings(&settings);
3463 /* FIXME: This is a bit of a hack, but we can't use a global, since
3464 * not everything that uses lp also uses the socket library */
3465 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3466 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3468 unsetenv("SOCKET_TESTNONBLOCK");
3474 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3478 path = lp_default_path();
3480 if (!file_exist(path)) {
3481 /* We allow the default smb.conf file to not exist,
3482 * basically the equivalent of an empty file. */
3483 return lpcfg_update(lp_ctx);
3486 return lpcfg_load(lp_ctx, path);
3490 * Load the services array from the services file.
3492 * Return True on success, False on failure.
3494 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3499 filename = talloc_strdup(lp_ctx, filename);
3501 lp_ctx->szConfigFile = filename;
3503 lp_ctx->bInGlobalSection = true;
3504 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3505 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3507 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3509 /* We get sections first, so have to start 'behind' to make up */
3510 lp_ctx->currentService = NULL;
3511 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3513 /* finish up the last section */
3514 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3516 if (lp_ctx->currentService != NULL)
3517 bRetval = service_ok(lp_ctx->currentService);
3519 bRetval = bRetval && lpcfg_update(lp_ctx);
3521 /* we do this unconditionally, so that it happens even
3522 for a missing smb.conf */
3523 reload_charcnv(lp_ctx);
3525 if (bRetval == true) {
3526 /* set this up so that any child python tasks will
3527 find the right smb.conf */
3528 setenv("SMB_CONF_PATH", filename, 1);
3530 /* set the context used by the lp_*() function
3532 global_loadparm_context = lp_ctx;
3533 lp_ctx->loaded = true;
3540 * Return the max number of services.
3543 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3545 return lp_ctx->iNumServices;
3549 * Display the contents of the services array in human-readable form.
3552 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3557 defaults_saved = !show_defaults;
3559 dump_globals(lp_ctx, f, show_defaults);
3561 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3563 for (iService = 0; iService < maxtoprint; iService++)
3564 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3568 * Display the contents of one service in human-readable form.
3570 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3572 if (service != NULL) {
3573 if (service->szService[0] == '\0')
3575 dump_a_service(service, sDefault, f, NULL);
3579 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3582 return lp_ctx->services[snum];
3585 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3586 const char *service_name)
3591 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3592 if (lp_ctx->services[iService] &&
3593 lp_ctx->services[iService]->szService) {
3595 * The substitution here is used to support %U is
3598 serviceName = standard_sub_basic(
3599 lp_ctx->services[iService],
3600 lp_ctx->services[iService]->szService);
3601 if (strequal(serviceName, service_name)) {
3602 talloc_free(serviceName);
3603 return lp_ctx->services[iService];
3605 talloc_free(serviceName);
3609 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3613 const char *lpcfg_servicename(const struct loadparm_service *service)
3615 return lp_string((const char *)service->szService);
3619 * A useful volume label function.
3621 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3624 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3625 service->volume : sDefault->volume));
3627 return lpcfg_servicename(service);
3632 * If we are PDC then prefer us as DMB
3634 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3637 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3638 service->szPrintername : sDefault->szPrintername));
3639 if (ret == NULL || (ret != NULL && *ret == '\0'))
3640 ret = lpcfg_servicename(service);
3647 * Return the max print jobs per queue.
3649 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3651 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3652 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3653 maxjobs = PRINT_MAX_JOBID - 1;
3658 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3660 if (lp_ctx == NULL) {
3661 return get_iconv_handle();
3663 return lp_ctx->iconv_handle;
3666 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3668 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3669 if (!lp_ctx->global) {
3673 if (old_ic == NULL) {
3674 old_ic = global_iconv_handle;
3676 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3677 global_iconv_handle = lp_ctx->iconv_handle;
3680 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
3681 struct smbcli_options *options)
3683 options->max_xmit = lpcfg_max_xmit(lp_ctx);
3684 options->max_mux = lpcfg_maxmux(lp_ctx);
3685 options->use_spnego = lpcfg_nt_status_support(lp_ctx) && lpcfg_use_spnego(lp_ctx);
3686 options->signing = lpcfg_client_signing(lp_ctx);
3687 options->request_timeout = SMB_REQUEST_TIMEOUT;
3688 options->ntstatus_support = lpcfg_nt_status_support(lp_ctx);
3689 options->max_protocol = lpcfg_cli_maxprotocol(lp_ctx);
3690 options->unicode = lpcfg_unicode(lp_ctx);
3691 options->use_oplocks = true;
3692 options->use_level2_oplocks = true;
3695 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
3696 struct smbcli_session_options *options)
3698 options->lanman_auth = lpcfg_client_lanman_auth(lp_ctx);
3699 options->ntlmv2_auth = lpcfg_client_ntlmv2_auth(lp_ctx);
3700 options->plaintext_auth = lpcfg_client_plaintext_auth(lp_ctx);
3703 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3705 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3708 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3710 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3713 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3715 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3718 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3720 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3723 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3725 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3728 _PUBLIC_ struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3730 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
3732 ret->domain_name = talloc_reference(mem_ctx, lpcfg_workgroup(lp_ctx));
3733 ret->version_major = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
3734 ret->version_minor = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
3735 ret->version_build = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
3740 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3742 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3743 if (settings == NULL)
3745 SMB_ASSERT(lp_ctx != NULL);
3746 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3747 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");