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_OFF, "No"},
146 {SMB_SIGNING_OFF, "False"},
147 {SMB_SIGNING_OFF, "0"},
148 {SMB_SIGNING_OFF, "Off"},
149 {SMB_SIGNING_OFF, "disabled"},
150 {SMB_SIGNING_SUPPORTED, "Yes"},
151 {SMB_SIGNING_SUPPORTED, "True"},
152 {SMB_SIGNING_SUPPORTED, "1"},
153 {SMB_SIGNING_SUPPORTED, "On"},
154 {SMB_SIGNING_SUPPORTED, "enabled"},
155 {SMB_SIGNING_REQUIRED, "required"},
156 {SMB_SIGNING_REQUIRED, "mandatory"},
157 {SMB_SIGNING_REQUIRED, "force"},
158 {SMB_SIGNING_REQUIRED, "forced"},
159 {SMB_SIGNING_REQUIRED, "enforced"},
160 {SMB_SIGNING_AUTO, "auto"},
164 static const struct enum_list enum_server_role[] = {
165 {ROLE_STANDALONE, "standalone"},
166 {ROLE_DOMAIN_MEMBER, "member server"},
167 {ROLE_DOMAIN_MEMBER, "member"},
168 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
169 {ROLE_DOMAIN_CONTROLLER, "dc"},
173 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
174 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
176 static struct parm_struct parm_table[] = {
178 .label = "server role",
181 .offset = GLOBAL_VAR(server_role),
183 .enum_list = enum_server_role
186 .label = "dos charset",
189 .offset = GLOBAL_VAR(dos_charset),
194 .label = "unix charset",
197 .offset = GLOBAL_VAR(unix_charset),
202 .label = "ncalrpc dir",
205 .offset = GLOBAL_VAR(ncalrpc_dir),
213 .offset = LOCAL_VAR(comment),
221 .offset = LOCAL_VAR(szPath),
226 .label = "directory",
229 .offset = LOCAL_VAR(szPath),
234 .label = "workgroup",
237 .offset = GLOBAL_VAR(szWorkgroup),
245 .offset = GLOBAL_VAR(szRealm),
246 .special = handle_realm,
250 .label = "netbios name",
253 .offset = GLOBAL_VAR(szNetbiosName),
258 .label = "netbios aliases",
261 .offset = GLOBAL_VAR(szNetbiosAliases),
266 .label = "netbios scope",
269 .offset = GLOBAL_VAR(szNetbiosScope),
274 .label = "server string",
277 .offset = GLOBAL_VAR(szServerString),
282 .label = "interfaces",
285 .offset = GLOBAL_VAR(szInterfaces),
290 .label = "bind interfaces only",
293 .offset = GLOBAL_VAR(bBindInterfacesOnly),
298 .label = "ntvfs handler",
301 .offset = LOCAL_VAR(ntvfs_handler),
306 .label = "ntptr providor",
309 .offset = GLOBAL_VAR(ntptr_providor),
314 .label = "passdb backend",
317 .offset = GLOBAL_VAR(passdb_backend),
322 .label = "dcerpc endpoint servers",
325 .offset = GLOBAL_VAR(dcerpc_ep_servers),
330 .label = "server services",
333 .offset = GLOBAL_VAR(server_services),
342 .offset = GLOBAL_VAR(security),
344 .enum_list = enum_security
347 .label = "encrypt passwords",
350 .offset = GLOBAL_VAR(bEncryptPasswords),
355 .label = "null passwords",
358 .offset = GLOBAL_VAR(bNullPasswords),
363 .label = "obey pam restrictions",
366 .offset = GLOBAL_VAR(bObeyPamRestrictions),
371 .label = "password server",
374 .offset = GLOBAL_VAR(szPasswordServers),
379 .label = "private dir",
382 .offset = GLOBAL_VAR(szPrivateDir),
387 .label = "passwd chat",
390 .offset = GLOBAL_VAR(szPasswdChat),
395 .label = "password level",
398 .offset = GLOBAL_VAR(pwordlevel),
403 .label = "lanman auth",
406 .offset = GLOBAL_VAR(bLanmanAuth),
411 .label = "ntlm auth",
414 .offset = GLOBAL_VAR(bNTLMAuth),
419 .label = "client NTLMv2 auth",
422 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
427 .label = "client lanman auth",
430 .offset = GLOBAL_VAR(bClientLanManAuth),
435 .label = "client plaintext auth",
438 .offset = GLOBAL_VAR(bClientPlaintextAuth),
443 .label = "client use spnego principal",
446 .offset = GLOBAL_VAR(client_use_spnego_principal),
452 .label = "read only",
455 .offset = LOCAL_VAR(bRead_only),
461 .label = "create mask",
464 .offset = LOCAL_VAR(iCreate_mask),
469 .label = "force create mode",
472 .offset = LOCAL_VAR(iCreate_force_mode),
477 .label = "directory mask",
480 .offset = LOCAL_VAR(iDir_mask),
485 .label = "force directory mode",
488 .offset = LOCAL_VAR(iDir_force_mode),
494 .label = "hosts allow",
497 .offset = LOCAL_VAR(szHostsallow),
502 .label = "hosts deny",
505 .offset = LOCAL_VAR(szHostsdeny),
511 .label = "log level",
514 .offset = GLOBAL_VAR(loglevel),
515 .special = handle_debuglevel,
519 .label = "debuglevel",
522 .offset = GLOBAL_VAR(loglevel),
523 .special = handle_debuglevel,
530 .offset = GLOBAL_VAR(logfile),
531 .special = handle_logfile,
536 .label = "smb ports",
539 .offset = GLOBAL_VAR(smb_ports),
547 .offset = GLOBAL_VAR(nbt_port),
552 .label = "dgram port",
555 .offset = GLOBAL_VAR(dgram_port),
560 .label = "cldap port",
563 .offset = GLOBAL_VAR(cldap_port),
568 .label = "krb5 port",
571 .offset = GLOBAL_VAR(krb5_port),
576 .label = "kpasswd port",
579 .offset = GLOBAL_VAR(kpasswd_port),
587 .offset = GLOBAL_VAR(web_port),
592 .label = "tls enabled",
595 .offset = GLOBAL_VAR(tls_enabled),
600 .label = "tls keyfile",
603 .offset = GLOBAL_VAR(tls_keyfile),
608 .label = "tls certfile",
611 .offset = GLOBAL_VAR(tls_certfile),
616 .label = "tls cafile",
619 .offset = GLOBAL_VAR(tls_cafile),
624 .label = "tls crlfile",
627 .offset = GLOBAL_VAR(tls_crlfile),
632 .label = "tls dh params file",
635 .offset = GLOBAL_VAR(tls_dhpfile),
640 .label = "large readwrite",
643 .offset = GLOBAL_VAR(bLargeReadwrite),
648 .label = "server max protocol",
651 .offset = GLOBAL_VAR(srv_maxprotocol),
653 .enum_list = enum_protocol
656 .label = "server min protocol",
659 .offset = GLOBAL_VAR(srv_minprotocol),
661 .enum_list = enum_protocol
664 .label = "client max protocol",
667 .offset = GLOBAL_VAR(cli_maxprotocol),
669 .enum_list = enum_protocol
672 .label = "client min protocol",
675 .offset = GLOBAL_VAR(cli_minprotocol),
677 .enum_list = enum_protocol
683 .offset = GLOBAL_VAR(bUnicode),
691 .offset = GLOBAL_VAR(bReadRaw),
696 .label = "write raw",
699 .offset = GLOBAL_VAR(bWriteRaw),
704 .label = "disable netbios",
707 .offset = GLOBAL_VAR(bDisableNetbios),
713 .label = "nt status support",
716 .offset = GLOBAL_VAR(bNTStatusSupport),
725 .offset = GLOBAL_VAR(max_mux),
733 .offset = GLOBAL_VAR(max_xmit),
739 .label = "name resolve order",
742 .offset = GLOBAL_VAR(szNameResolveOrder),
747 .label = "max wins ttl",
750 .offset = GLOBAL_VAR(max_wins_ttl),
755 .label = "min wins ttl",
758 .offset = GLOBAL_VAR(min_wins_ttl),
763 .label = "time server",
766 .offset = GLOBAL_VAR(bTimeServer),
771 .label = "unix extensions",
774 .offset = GLOBAL_VAR(bUnixExtensions),
779 .label = "use spnego",
782 .offset = GLOBAL_VAR(bUseSpnego),
787 .label = "server signing",
790 .offset = GLOBAL_VAR(server_signing),
792 .enum_list = enum_smb_signing_vals
795 .label = "client signing",
798 .offset = GLOBAL_VAR(client_signing),
800 .enum_list = enum_smb_signing_vals
803 .label = "rpc big endian",
806 .offset = GLOBAL_VAR(bRpcBigEndian),
812 .label = "max connections",
815 .offset = LOCAL_VAR(iMaxConnections),
820 .label = "paranoid server security",
823 .offset = GLOBAL_VAR(paranoid_server_security),
828 .label = "socket options",
831 .offset = GLOBAL_VAR(socket_options),
837 .label = "strict sync",
840 .offset = LOCAL_VAR(bStrictSync),
848 .offset = GLOBAL_VAR(bUseMmap),
851 .flags = FLAG_ADVANCED,
854 .label = "case insensitive filesystem",
857 .offset = LOCAL_VAR(bCIFileSystem),
863 .label = "max print jobs",
866 .offset = LOCAL_VAR(iMaxPrintJobs),
871 .label = "printable",
874 .offset = LOCAL_VAR(bPrint_ok),
882 .offset = LOCAL_VAR(bPrint_ok),
888 .label = "printer name",
891 .offset = LOCAL_VAR(szPrintername),
899 .offset = LOCAL_VAR(szPrintername),
905 .label = "map system",
908 .offset = LOCAL_VAR(bMap_system),
913 .label = "map hidden",
916 .offset = LOCAL_VAR(bMap_hidden),
921 .label = "map archive",
924 .offset = LOCAL_VAR(bMap_archive),
930 .label = "preferred master",
933 .offset = GLOBAL_VAR(bPreferredMaster),
935 .enum_list = enum_bool_auto
938 .label = "prefered master",
941 .offset = GLOBAL_VAR(bPreferredMaster),
943 .enum_list = enum_bool_auto
946 .label = "local master",
949 .offset = GLOBAL_VAR(bLocalMaster),
954 .label = "browseable",
957 .offset = LOCAL_VAR(bBrowseable),
962 .label = "browsable",
965 .offset = LOCAL_VAR(bBrowseable),
971 .label = "wins server",
974 .offset = GLOBAL_VAR(szWINSservers),
979 .label = "wins support",
982 .offset = GLOBAL_VAR(bWINSsupport),
987 .label = "dns proxy",
990 .offset = GLOBAL_VAR(bWINSdnsProxy),
995 .label = "wins hook",
998 .offset = GLOBAL_VAR(szWINSHook),
1004 .label = "csc policy",
1007 .offset = LOCAL_VAR(iCSCPolicy),
1009 .enum_list = enum_csc_policy
1013 .label = "strict locking",
1016 .offset = LOCAL_VAR(iStrictLocking),
1024 .offset = LOCAL_VAR(bOpLocks),
1030 .label = "share backend",
1032 .p_class = P_GLOBAL,
1033 .offset = GLOBAL_VAR(szShareBackend),
1040 .p_class = P_GLOBAL,
1041 .offset = GLOBAL_VAR(szAutoServices),
1046 .label = "auto services",
1048 .p_class = P_GLOBAL,
1049 .offset = GLOBAL_VAR(szAutoServices),
1054 .label = "lock dir",
1056 .p_class = P_GLOBAL,
1057 .offset = GLOBAL_VAR(szLockDir),
1062 .label = "lock directory",
1064 .p_class = P_GLOBAL,
1065 .offset = GLOBAL_VAR(szLockDir),
1070 .label = "state directory",
1072 .p_class = P_GLOBAL,
1073 .offset = GLOBAL_VAR(szStateDir),
1078 .label = "cache directory",
1080 .p_class = P_GLOBAL,
1081 .offset = GLOBAL_VAR(szCacheDir),
1086 .label = "pid directory",
1088 .p_class = P_GLOBAL,
1089 .offset = GLOBAL_VAR(szPidDir),
1095 .label = "socket address",
1097 .p_class = P_GLOBAL,
1098 .offset = GLOBAL_VAR(szSocketAddress),
1106 .offset = LOCAL_VAR(szCopy),
1107 .special = handle_copy,
1114 .offset = LOCAL_VAR(szInclude),
1115 .special = handle_include,
1120 .label = "available",
1123 .offset = LOCAL_VAR(bAvailable),
1131 .offset = LOCAL_VAR(volume),
1139 .offset = LOCAL_VAR(fstype),
1145 .label = "panic action",
1147 .p_class = P_GLOBAL,
1148 .offset = GLOBAL_VAR(panic_action),
1154 .label = "msdfs root",
1157 .offset = LOCAL_VAR(bMSDfsRoot),
1162 .label = "host msdfs",
1164 .p_class = P_GLOBAL,
1165 .offset = GLOBAL_VAR(bHostMSDfs),
1170 .label = "winbind separator",
1172 .p_class = P_GLOBAL,
1173 .offset = GLOBAL_VAR(szWinbindSeparator),
1178 .label = "winbindd socket directory",
1180 .p_class = P_GLOBAL,
1181 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1186 .label = "winbindd privileged socket directory",
1188 .p_class = P_GLOBAL,
1189 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1194 .label = "winbind sealed pipes",
1196 .p_class = P_GLOBAL,
1197 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1202 .label = "template shell",
1204 .p_class = P_GLOBAL,
1205 .offset = GLOBAL_VAR(szTemplateShell),
1210 .label = "template homedir",
1212 .p_class = P_GLOBAL,
1213 .offset = GLOBAL_VAR(szTemplateHomedir),
1218 .label = "idmap trusted only",
1220 .p_class = P_GLOBAL,
1221 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1227 .label = "ntp signd socket directory",
1229 .p_class = P_GLOBAL,
1230 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1235 .label = "rndc command",
1237 .p_class = P_GLOBAL,
1238 .offset = GLOBAL_VAR(szRNDCCommand),
1243 .label = "dns update command",
1245 .p_class = P_GLOBAL,
1246 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1251 .label = "spn update command",
1253 .p_class = P_GLOBAL,
1254 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1259 .label = "nsupdate command",
1261 .p_class = P_GLOBAL,
1262 .offset = GLOBAL_VAR(szNSUpdateCommand),
1267 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1271 /* local variables */
1272 struct loadparm_context {
1273 const char *szConfigFile;
1274 struct loadparm_global *globals;
1275 struct loadparm_service **services;
1276 struct loadparm_service *sDefault;
1277 struct smb_iconv_handle *iconv_handle;
1279 struct loadparm_service *currentService;
1280 bool bInGlobalSection;
1282 struct file_lists *next;
1287 unsigned int flags[NUMPARAMETERS];
1290 bool global; /* Is this the global context, which may set
1291 * global variables such as debug level etc? */
1292 const struct loadparm_s3_context *s3_fns;
1296 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1298 if (lp_ctx->s3_fns) {
1299 return lp_ctx->s3_fns->get_default_loadparm_service();
1301 return lp_ctx->sDefault;
1305 * Convenience routine to grab string parameters into temporary memory
1306 * and run standard_sub_basic on them.
1308 * The buffers can be written to by
1309 * callers without affecting the source string.
1312 static const char *lp_string(const char *s)
1314 #if 0 /* until REWRITE done to make thread-safe */
1315 size_t len = s ? strlen(s) : 0;
1319 /* The follow debug is useful for tracking down memory problems
1320 especially if you have an inner loop that is calling a lp_*()
1321 function that returns a string. Perhaps this debug should be
1322 present all the time? */
1325 DEBUG(10, ("lp_string(%s)\n", s));
1328 #if 0 /* until REWRITE done to make thread-safe */
1330 lp_talloc = talloc_init("lp_talloc");
1332 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1340 strlcpy(ret, s, len);
1342 if (trim_string(ret, "\"", "\"")) {
1343 if (strchr(ret,'"') != NULL)
1344 strlcpy(ret, s, len);
1347 standard_sub_basic(ret,len+100);
1354 In this section all the functions that are used to access the
1355 parameters from the rest of the program are defined
1359 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1360 * for code compatibility between existing Samba4 and Samba3 code.
1363 /* this global context supports the lp_*() function varients */
1364 static struct loadparm_context *global_loadparm_context;
1366 #define lpcfg_default_service global_loadparm_context->sDefault
1367 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1369 #define FN_GLOBAL_STRING(fn_name,var_name) \
1370 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1371 if (lp_ctx == NULL) return NULL; \
1372 if (lp_ctx->s3_fns) { \
1373 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1374 return lp_ctx->s3_fns->fn_name(); \
1376 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1379 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1380 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1381 if (lp_ctx == NULL) return NULL; \
1382 if (lp_ctx->s3_fns) { \
1383 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1384 return lp_ctx->s3_fns->fn_name(); \
1386 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1389 #define FN_GLOBAL_LIST(fn_name,var_name) \
1390 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1391 if (lp_ctx == NULL) return NULL; \
1392 if (lp_ctx->s3_fns) { \
1393 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1394 return lp_ctx->s3_fns->fn_name(); \
1396 return lp_ctx->globals->var_name; \
1399 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1400 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1401 if (lp_ctx == NULL) return false; \
1402 if (lp_ctx->s3_fns) { \
1403 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1404 return lp_ctx->s3_fns->fn_name(); \
1406 return lp_ctx->globals->var_name; \
1409 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1410 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1411 if (lp_ctx->s3_fns) { \
1412 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1413 return lp_ctx->s3_fns->fn_name(); \
1415 return lp_ctx->globals->var_name; \
1418 /* Local parameters don't need the ->s3_fns because the struct
1419 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1421 #define FN_LOCAL_STRING(fn_name,val) \
1422 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1423 struct loadparm_service *sDefault) { \
1424 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1427 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1429 #define FN_LOCAL_LIST(fn_name,val) \
1430 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1431 struct loadparm_service *sDefault) {\
1432 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1435 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1437 #define FN_LOCAL_BOOL(fn_name,val) \
1438 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1439 struct loadparm_service *sDefault) { \
1440 return((service != NULL)? service->val : sDefault->val); \
1443 #define FN_LOCAL_INTEGER(fn_name,val) \
1444 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1445 struct loadparm_service *sDefault) { \
1446 return((service != NULL)? service->val : sDefault->val); \
1449 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1451 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1453 #define FN_LOCAL_CHAR(fn_name,val) \
1454 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1455 struct loadparm_service *sDefault) { \
1456 return((service != NULL)? service->val : sDefault->val); \
1459 #include "lib/param/param_functions.c"
1461 FN_GLOBAL_INTEGER(server_role, server_role)
1462 FN_GLOBAL_LIST(smb_ports, smb_ports)
1463 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1464 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1465 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1466 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1467 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1468 FN_GLOBAL_INTEGER(web_port, web_port)
1469 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1470 FN_GLOBAL_STRING(logfile, logfile)
1471 FN_GLOBAL_STRING(share_backend, szShareBackend)
1472 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1473 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1474 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1475 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1476 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1477 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1478 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1479 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1480 FN_GLOBAL_STRING(serverstring, szServerString)
1481 FN_GLOBAL_STRING(lockdir, szLockDir)
1482 FN_GLOBAL_STRING(statedir, szStateDir)
1483 FN_GLOBAL_STRING(cachedir, szCacheDir)
1484 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1485 FN_GLOBAL_STRING(dos_charset, dos_charset)
1486 FN_GLOBAL_STRING(unix_charset, unix_charset)
1487 FN_GLOBAL_STRING(piddir, szPidDir)
1488 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1489 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1490 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1491 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1492 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1493 FN_GLOBAL_LIST(server_services, server_services)
1494 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1495 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1496 FN_GLOBAL_STRING(auto_services, szAutoServices)
1497 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1498 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1499 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1500 FN_GLOBAL_STRING(realm, szRealm_upper)
1501 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1502 FN_GLOBAL_STRING(socket_options, socket_options)
1503 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1504 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1505 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1506 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1507 FN_GLOBAL_LIST(interfaces, szInterfaces)
1508 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1509 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1510 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1511 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1512 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1513 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1514 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1515 FN_GLOBAL_BOOL(readraw, bReadRaw)
1516 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1517 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1518 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1519 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1520 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1521 FN_GLOBAL_BOOL(time_server, bTimeServer)
1522 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1523 FN_GLOBAL_BOOL(unicode, bUnicode)
1524 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1525 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1526 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1527 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1528 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1529 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1530 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1531 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1532 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1533 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1534 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1535 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1536 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1537 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1538 FN_GLOBAL_INTEGER(maxmux, max_mux)
1539 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1540 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1541 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1542 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1543 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1544 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1545 FN_GLOBAL_INTEGER(security, security)
1546 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1548 FN_GLOBAL_INTEGER(server_signing, server_signing)
1549 FN_GLOBAL_INTEGER(client_signing, client_signing)
1551 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1553 /* local prototypes */
1554 static int map_parameter(const char *pszParmName);
1555 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1556 const char *pszServiceName);
1557 static void copy_service(struct loadparm_service *pserviceDest,
1558 struct loadparm_service *pserviceSource,
1559 struct bitmap *pcopymapDest);
1560 static bool lpcfg_service_ok(struct loadparm_service *service);
1561 static bool do_section(const char *pszSectionName, void *);
1562 static void init_copymap(struct loadparm_service *pservice);
1564 /* This is a helper function for parametrical options support. */
1565 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1566 /* Actual parametrical functions are quite simple */
1567 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1568 struct loadparm_service *service,
1569 const char *type, const char *option)
1571 char *vfskey_tmp = NULL;
1572 char *vfskey = NULL;
1573 struct parmlist_entry *data;
1578 if (lp_ctx->s3_fns) {
1579 return lp_ctx->s3_fns->get_parametric(service, type, option);
1582 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1584 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1585 if (vfskey_tmp == NULL) return NULL;
1586 vfskey = strlower_talloc(NULL, vfskey_tmp);
1587 talloc_free(vfskey_tmp);
1590 if (strcmp(data->key, vfskey) == 0) {
1591 talloc_free(vfskey);
1597 if (service != NULL) {
1598 /* Try to fetch the same option but from globals */
1599 /* but only if we are not already working with globals */
1600 for (data = lp_ctx->globals->param_opt; data;
1601 data = data->next) {
1602 if (strcmp(data->key, vfskey) == 0) {
1603 talloc_free(vfskey);
1609 talloc_free(vfskey);
1616 * convenience routine to return int parameters.
1618 static int lp_int(const char *s)
1622 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1626 return strtol(s, NULL, 0);
1630 * convenience routine to return unsigned long parameters.
1632 static int lp_ulong(const char *s)
1636 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1640 return strtoul(s, NULL, 0);
1644 * convenience routine to return unsigned long parameters.
1646 static double lp_double(const char *s)
1650 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1654 return strtod(s, NULL);
1658 * convenience routine to return boolean parameters.
1660 static bool lp_bool(const char *s)
1665 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1669 if (!set_boolean(s, &ret)) {
1670 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1679 * Return parametric option from a given service. Type is a part of option before ':'
1680 * Parametric option has following syntax: 'Type: option = value'
1681 * Returned value is allocated in 'lp_talloc' context
1684 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1685 struct loadparm_service *service, const char *type,
1688 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1691 return lp_string(value);
1697 * Return parametric option from a given service. Type is a part of option before ':'
1698 * Parametric option has following syntax: 'Type: option = value'
1699 * Returned value is allocated in 'lp_talloc' context
1702 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1703 struct loadparm_context *lp_ctx,
1704 struct loadparm_service *service,
1706 const char *option, const char *separator)
1708 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1711 return (const char **)str_list_make(mem_ctx, value, separator);
1717 * Return parametric option from a given service. Type is a part of option before ':'
1718 * Parametric option has following syntax: 'Type: option = value'
1721 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1722 struct loadparm_service *service, const char *type,
1723 const char *option, int default_v)
1725 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1728 return lp_int(value);
1734 * Return parametric option from a given service. Type is a part of
1735 * option before ':'.
1736 * Parametric option has following syntax: 'Type: option = value'.
1739 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1740 struct loadparm_service *service, const char *type,
1741 const char *option, int default_v)
1745 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1747 if (value && conv_str_size_error(value, &bval)) {
1748 if (bval <= INT_MAX) {
1757 * Return parametric option from a given service.
1758 * Type is a part of option before ':'
1759 * Parametric option has following syntax: 'Type: option = value'
1761 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1762 struct loadparm_service *service, const char *type,
1763 const char *option, unsigned long default_v)
1765 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1768 return lp_ulong(value);
1774 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1775 struct loadparm_service *service, const char *type,
1776 const char *option, double default_v)
1778 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1781 return lp_double(value);
1787 * Return parametric option from a given service. Type is a part of option before ':'
1788 * Parametric option has following syntax: 'Type: option = value'
1791 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1792 struct loadparm_service *service, const char *type,
1793 const char *option, bool default_v)
1795 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1798 return lp_bool(value);
1805 * Initialise a service to the defaults.
1808 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1810 struct loadparm_service *pservice =
1811 talloc_zero(mem_ctx, struct loadparm_service);
1812 copy_service(pservice, sDefault, NULL);
1817 * Set a string value, deallocating any existing space, and allocing the space
1820 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1827 *dest = talloc_strdup(mem_ctx, src);
1828 if ((*dest) == NULL) {
1829 DEBUG(0,("Out of memory in string_set\n"));
1837 * Set a string value, deallocating any existing space, and allocing the space
1840 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1847 *dest = strupper_talloc(mem_ctx, src);
1848 if ((*dest) == NULL) {
1849 DEBUG(0,("Out of memory in string_set_upper\n"));
1859 * Add a new service to the services array initialising it with the given
1863 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1864 const struct loadparm_service *pservice,
1868 struct loadparm_service tservice;
1869 int num_to_alloc = lp_ctx->iNumServices + 1;
1870 struct parmlist_entry *data, *pdata;
1872 if (pservice == NULL) {
1873 pservice = lp_ctx->sDefault;
1876 tservice = *pservice;
1878 /* it might already exist */
1880 struct loadparm_service *service = getservicebyname(lp_ctx,
1882 if (service != NULL) {
1883 /* Clean all parametric options for service */
1884 /* They will be added during parsing again */
1885 data = service->param_opt;
1891 service->param_opt = NULL;
1896 /* find an invalid one */
1897 for (i = 0; i < lp_ctx->iNumServices; i++)
1898 if (lp_ctx->services[i] == NULL)
1901 /* if not, then create one */
1902 if (i == lp_ctx->iNumServices) {
1903 struct loadparm_service **tsp;
1905 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1908 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1911 lp_ctx->services = tsp;
1912 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1915 lp_ctx->iNumServices++;
1918 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1919 if (lp_ctx->services[i] == NULL) {
1920 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1923 copy_service(lp_ctx->services[i], &tservice, NULL);
1925 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1926 return lp_ctx->services[i];
1930 * Add a new home service, with the specified home directory, defaults coming
1931 * from service ifrom.
1934 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1935 const char *pszHomename,
1936 struct loadparm_service *default_service,
1937 const char *user, const char *pszHomedir)
1939 struct loadparm_service *service;
1941 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1943 if (service == NULL)
1946 if (!(*(default_service->szPath))
1947 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1948 service->szPath = talloc_strdup(service, pszHomedir);
1950 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1953 if (!(*(service->comment))) {
1954 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1956 service->bAvailable = default_service->bAvailable;
1957 service->bBrowseable = default_service->bBrowseable;
1959 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1960 pszHomename, user, service->szPath));
1966 * Add a new printer service, with defaults coming from service iFrom.
1969 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1970 const char *pszPrintername,
1971 struct loadparm_service *default_service)
1973 const char *comment = "From Printcap";
1974 struct loadparm_service *service;
1975 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1977 if (service == NULL)
1980 /* note that we do NOT default the availability flag to True - */
1981 /* we take it from the default service passed. This allows all */
1982 /* dynamic printers to be disabled by disabling the [printers] */
1983 /* entry (if/when the 'available' keyword is implemented!). */
1985 /* the printer name is set to the service name. */
1986 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
1987 lpcfg_string_set(service, &service->comment, comment);
1988 service->bBrowseable = default_service->bBrowseable;
1989 /* Printers cannot be read_only. */
1990 service->bRead_only = false;
1991 /* Printer services must be printable. */
1992 service->bPrint_ok = true;
1994 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2000 * Map a parameter's string representation to something we can use.
2001 * Returns False if the parameter string is not recognised, else TRUE.
2004 static int map_parameter(const char *pszParmName)
2008 if (*pszParmName == '-')
2011 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2012 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2015 /* Warn only if it isn't parametric option */
2016 if (strchr(pszParmName, ':') == NULL)
2017 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2018 /* We do return 'fail' for parametric options as well because they are
2019 stored in different storage
2026 return the parameter structure for a parameter
2028 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2032 if (lp_ctx->s3_fns) {
2033 return lp_ctx->s3_fns->get_parm_struct(name);
2036 parmnum = map_parameter(name);
2037 if (parmnum == -1) return NULL;
2038 return &parm_table[parmnum];
2042 return the parameter pointer for a parameter
2044 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2045 struct loadparm_service *service, struct parm_struct *parm)
2047 if (lp_ctx->s3_fns) {
2048 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2051 if (service == NULL) {
2052 if (parm->p_class == P_LOCAL)
2053 return ((char *)lp_ctx->sDefault)+parm->offset;
2054 else if (parm->p_class == P_GLOBAL)
2055 return ((char *)lp_ctx->globals)+parm->offset;
2058 return ((char *)service) + parm->offset;
2063 return the parameter pointer for a parameter
2065 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2069 if (lp_ctx->s3_fns) {
2070 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2072 return parm->flags & FLAG_CMDLINE;
2077 parmnum = map_parameter(name);
2078 if (parmnum == -1) return false;
2080 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2084 * Find a service by name. Otherwise works like get_service.
2087 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2088 const char *pszServiceName)
2092 if (lp_ctx->s3_fns) {
2093 return lp_ctx->s3_fns->get_service(pszServiceName);
2096 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2097 if (lp_ctx->services[iService] != NULL &&
2098 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2099 return lp_ctx->services[iService];
2106 * Copy a service structure to another.
2107 * If pcopymapDest is NULL then copy all fields
2110 static void copy_service(struct loadparm_service *pserviceDest,
2111 struct loadparm_service *pserviceSource,
2112 struct bitmap *pcopymapDest)
2115 bool bcopyall = (pcopymapDest == NULL);
2116 struct parmlist_entry *data, *pdata, *paramo;
2119 for (i = 0; parm_table[i].label; i++)
2120 if (parm_table[i].p_class == P_LOCAL &&
2121 (bcopyall || bitmap_query(pcopymapDest, i))) {
2123 ((char *)pserviceSource) + parm_table[i].offset;
2125 ((char *)pserviceDest) + parm_table[i].offset;
2127 switch (parm_table[i].type) {
2129 *(bool *)dest_ptr = *(bool *)src_ptr;
2135 *(int *)dest_ptr = *(int *)src_ptr;
2139 lpcfg_string_set(pserviceDest,
2145 lpcfg_string_set_upper(pserviceDest,
2150 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2151 *(const char ***)src_ptr);
2159 init_copymap(pserviceDest);
2160 if (pserviceSource->copymap)
2161 bitmap_copy(pserviceDest->copymap,
2162 pserviceSource->copymap);
2165 data = pserviceSource->param_opt;
2168 pdata = pserviceDest->param_opt;
2169 /* Traverse destination */
2171 /* If we already have same option, override it */
2172 if (strcmp(pdata->key, data->key) == 0) {
2173 talloc_free(pdata->value);
2174 pdata->value = talloc_reference(pdata,
2179 pdata = pdata->next;
2182 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2185 paramo->key = talloc_reference(paramo, data->key);
2186 paramo->value = talloc_reference(paramo, data->value);
2187 DLIST_ADD(pserviceDest->param_opt, paramo);
2194 * Check a service for consistency. Return False if the service is in any way
2195 * incomplete or faulty, else True.
2197 static bool lpcfg_service_ok(struct loadparm_service *service)
2202 if (service->szService[0] == '\0') {
2203 DEBUG(0, ("The following message indicates an internal error:\n"));
2204 DEBUG(0, ("No service name in service entry.\n"));
2208 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2209 /* I can't see why you'd want a non-printable printer service... */
2210 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2211 if (!service->bPrint_ok) {
2212 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2213 service->szService));
2214 service->bPrint_ok = true;
2216 /* [printers] service must also be non-browsable. */
2217 if (service->bBrowseable)
2218 service->bBrowseable = false;
2221 /* If a service is flagged unavailable, log the fact at level 0. */
2222 if (!service->bAvailable)
2223 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2224 service->szService));
2230 /*******************************************************************
2231 Keep a linked list of all config files so we know when one has changed
2232 it's date and needs to be reloaded.
2233 ********************************************************************/
2235 static void add_to_file_list(struct loadparm_context *lp_ctx,
2236 const char *fname, const char *subfname)
2238 struct file_lists *f = lp_ctx->file_lists;
2241 if (f->name && !strcmp(f->name, fname))
2247 f = talloc(lp_ctx, struct file_lists);
2250 f->next = lp_ctx->file_lists;
2251 f->name = talloc_strdup(f, fname);
2256 f->subfname = talloc_strdup(f, subfname);
2261 lp_ctx->file_lists = f;
2262 f->modtime = file_modtime(subfname);
2264 time_t t = file_modtime(subfname);
2270 /*******************************************************************
2271 Check if a config file has changed date.
2272 ********************************************************************/
2273 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2275 struct file_lists *f;
2276 DEBUG(6, ("lp_file_list_changed()\n"));
2278 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2282 n2 = standard_sub_basic(lp_ctx, f->name);
2284 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2285 f->name, n2, ctime(&f->modtime)));
2287 mod_time = file_modtime(n2);
2289 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2290 DEBUGADD(6, ("file %s modified: %s\n", n2,
2292 f->modtime = mod_time;
2293 talloc_free(f->subfname);
2294 f->subfname = talloc_strdup(f, n2);
2301 /***************************************************************************
2302 Handle the "realm" parameter
2303 ***************************************************************************/
2305 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2306 const char *pszParmValue, char **ptr)
2308 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2310 talloc_free(lp_ctx->globals->szRealm_upper);
2311 talloc_free(lp_ctx->globals->szRealm_lower);
2313 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2314 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2319 /***************************************************************************
2320 Handle the include operation.
2321 ***************************************************************************/
2323 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2324 const char *pszParmValue, char **ptr)
2326 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2328 add_to_file_list(lp_ctx, pszParmValue, fname);
2330 lpcfg_string_set(lp_ctx, ptr, fname);
2332 if (file_exist(fname))
2333 return pm_process(fname, do_section, do_parameter, lp_ctx);
2335 DEBUG(2, ("Can't find include file %s\n", fname));
2340 /***************************************************************************
2341 Handle the interpretation of the copy parameter.
2342 ***************************************************************************/
2344 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2345 const char *pszParmValue, char **ptr)
2348 struct loadparm_service *serviceTemp;
2350 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2354 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2356 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2357 if (serviceTemp == lp_ctx->currentService) {
2358 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2360 copy_service(lp_ctx->currentService,
2362 lp_ctx->currentService->copymap);
2366 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2374 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2375 const char *pszParmValue, char **ptr)
2378 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2379 if (lp_ctx->global) {
2380 return debug_parse_levels(pszParmValue);
2385 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2386 const char *pszParmValue, char **ptr)
2388 debug_set_logfile(pszParmValue);
2389 if (lp_ctx->global) {
2390 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2395 /***************************************************************************
2396 Initialise a copymap.
2397 ***************************************************************************/
2399 static void init_copymap(struct loadparm_service *pservice)
2403 TALLOC_FREE(pservice->copymap);
2405 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2406 if (!pservice->copymap)
2408 ("Couldn't allocate copymap!! (size %d)\n",
2409 (int)NUMPARAMETERS));
2411 for (i = 0; i < NUMPARAMETERS; i++)
2412 bitmap_set(pservice->copymap, i);
2416 * Process a parametric option
2418 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2419 struct loadparm_service *service,
2420 const char *pszParmName,
2421 const char *pszParmValue, int flags)
2423 struct parmlist_entry *paramo, *data;
2425 TALLOC_CTX *mem_ctx;
2427 while (isspace((unsigned char)*pszParmName)) {
2431 name = strlower_talloc(lp_ctx, pszParmName);
2432 if (!name) return false;
2434 if (service == NULL) {
2435 data = lp_ctx->globals->param_opt;
2436 mem_ctx = lp_ctx->globals;
2438 data = service->param_opt;
2442 /* Traverse destination */
2443 for (paramo=data; paramo; paramo=paramo->next) {
2444 /* If we already have the option set, override it unless
2445 it was a command line option and the new one isn't */
2446 if (strcmp(paramo->key, name) == 0) {
2447 if ((paramo->priority & FLAG_CMDLINE) &&
2448 !(flags & FLAG_CMDLINE)) {
2453 talloc_free(paramo->value);
2454 paramo->value = talloc_strdup(paramo, pszParmValue);
2455 paramo->priority = flags;
2461 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2464 paramo->key = talloc_strdup(paramo, name);
2465 paramo->value = talloc_strdup(paramo, pszParmValue);
2466 paramo->priority = flags;
2467 if (service == NULL) {
2468 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2470 DLIST_ADD(service->param_opt, paramo);
2478 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2479 const char *pszParmName, const char *pszParmValue,
2480 struct loadparm_context *lp_ctx, bool on_globals)
2483 /* if it is a special case then go ahead */
2484 if (parm_table[parmnum].special) {
2486 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2491 goto mark_non_default;
2494 /* now switch on the type of variable it is */
2495 switch (parm_table[parmnum].type)
2499 if (!set_boolean(pszParmValue, &b)) {
2500 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2503 *(bool *)parm_ptr = b;
2509 if (!set_boolean(pszParmValue, &b)) {
2510 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2513 *(bool *)parm_ptr = !b;
2518 *(int *)parm_ptr = atoi(pszParmValue);
2522 *(char *)parm_ptr = *pszParmValue;
2526 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2532 if (conv_str_size_error(pszParmValue, &val)) {
2533 if (val <= INT_MAX) {
2534 *(int *)parm_ptr = (int)val;
2539 DEBUG(0,("lp_do_parameter(%s): value is not "
2540 "a valid size specifier!\n", pszParmValue));
2545 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2546 pszParmValue, NULL);
2550 char **new_list = str_list_make(mem_ctx,
2551 pszParmValue, NULL);
2552 for (i=0; new_list[i]; i++) {
2553 if (new_list[i][0] == '+' && new_list[i][1] &&
2554 (!str_list_check(*(const char ***)parm_ptr,
2555 &new_list[i][1]))) {
2556 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2558 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2559 #if 0 /* This is commented out because we sometimes parse the list
2560 * twice, and so we can't assert on this */
2561 if (!str_list_check(*(const char ***)parm_ptr,
2563 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2564 pszParmName, pszParmValue, new_list[i],
2565 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2570 str_list_remove(*(const char ***)parm_ptr,
2574 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2575 pszParmName, pszParmValue));
2578 *(const char ***)parm_ptr = (const char **) new_list;
2585 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2589 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2593 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2596 parm_table[parmnum].enum_list[i].name)) {
2598 parm_table[parmnum].
2603 if (!parm_table[parmnum].enum_list[i].name) {
2604 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2605 pszParmValue, pszParmName));
2612 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2613 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2614 /* we have to also unset FLAG_DEFAULT on aliases */
2615 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2616 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2618 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2619 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2626 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2627 const char *pszParmName, const char *pszParmValue)
2629 int parmnum = map_parameter(pszParmName);
2633 if (strchr(pszParmName, ':')) {
2634 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2636 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2640 /* if the flag has been set on the command line, then don't allow override,
2641 but don't report an error */
2642 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2646 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2648 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2649 pszParmName, pszParmValue, lp_ctx, true);
2652 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2653 struct loadparm_service *service,
2654 const char *pszParmName, const char *pszParmValue)
2658 int parmnum = map_parameter(pszParmName);
2661 if (strchr(pszParmName, ':')) {
2662 return lp_do_parameter_parametric(lp_ctx, service, 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 if (parm_table[parmnum].p_class == P_GLOBAL) {
2676 ("Global parameter %s found in service section!\n",
2680 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2682 if (!service->copymap)
2683 init_copymap(service);
2685 /* this handles the aliases - set the copymap for other
2686 * entries with the same data pointer */
2687 for (i = 0; parm_table[i].label; i++)
2688 if (parm_table[i].offset == parm_table[parmnum].offset &&
2689 parm_table[i].p_class == parm_table[parmnum].p_class)
2690 bitmap_clear(service->copymap, i);
2692 return set_variable(service, parmnum, parm_ptr, pszParmName,
2693 pszParmValue, lp_ctx, false);
2697 * Process a parameter.
2700 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2703 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2705 if (lp_ctx->bInGlobalSection)
2706 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2709 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2710 pszParmName, pszParmValue);
2714 variable argument do parameter
2716 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2717 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2718 const char *pszParmName, const char *fmt, ...)
2725 s = talloc_vasprintf(NULL, fmt, ap);
2727 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2734 set a parameter from the commandline - this is called from command line parameter
2735 parsing code. It sets the parameter then marks the parameter as unable to be modified
2736 by smb.conf processing
2738 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2739 const char *pszParmValue)
2744 if (lp_ctx->s3_fns) {
2745 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2748 parmnum = map_parameter(pszParmName);
2750 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2753 if (parmnum < 0 && strchr(pszParmName, ':')) {
2754 /* set a parametric option */
2755 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2756 pszParmValue, FLAG_CMDLINE);
2760 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2764 /* reset the CMDLINE flag in case this has been called before */
2765 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2767 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2771 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2773 /* we have to also set FLAG_CMDLINE on aliases */
2774 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2775 lp_ctx->flags[i] |= FLAG_CMDLINE;
2777 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2778 lp_ctx->flags[i] |= FLAG_CMDLINE;
2785 set a option from the commandline in 'a=b' format. Use to support --option
2787 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2792 s = talloc_strdup(NULL, option);
2805 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2811 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2814 * Print a parameter of the specified type.
2817 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2819 /* For the seperation of lists values that we print below */
2820 const char *list_sep = ", ";
2825 for (i = 0; p->enum_list[i].name; i++) {
2826 if (*(int *)ptr == p->enum_list[i].value) {
2828 p->enum_list[i].name);
2835 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2839 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2844 fprintf(f, "%d", *(int *)ptr);
2848 fprintf(f, "%c", *(char *)ptr);
2852 int val = *(int *)ptr;
2856 fprintf(f, "0%o", val);
2865 if ((char ***)ptr && *(char ***)ptr) {
2866 char **list = *(char ***)ptr;
2867 for (; *list; list++) {
2868 /* surround strings with whitespace in double quotes */
2869 if (*(list+1) == NULL) {
2870 /* last item, no extra separator */
2873 if ( strchr_m( *list, ' ' ) ) {
2874 fprintf(f, "\"%s\"%s", *list, list_sep);
2876 fprintf(f, "%s%s", *list, list_sep);
2884 if (*(char **)ptr) {
2885 fprintf(f, "%s", *(char **)ptr);
2894 * Check if two parameters are equal.
2897 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2902 return (*((bool *)ptr1) == *((bool *)ptr2));
2908 return (*((int *)ptr1) == *((int *)ptr2));
2911 return (*((char *)ptr1) == *((char *)ptr2));
2915 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2920 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2925 return (p1 == p2 || strequal(p1, p2));
2934 * Process a new section (service).
2936 * At this stage all sections are services.
2937 * Later we'll have special sections that permit server parameters to be set.
2938 * Returns True on success, False on failure.
2941 static bool do_section(const char *pszSectionName, void *userdata)
2943 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2945 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2946 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2949 /* if we've just struck a global section, note the fact. */
2950 lp_ctx->bInGlobalSection = isglobal;
2952 /* check for multiple global sections */
2953 if (lp_ctx->bInGlobalSection) {
2954 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2958 /* if we have a current service, tidy it up before moving on */
2961 if (lp_ctx->currentService != NULL)
2962 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2964 /* if all is still well, move to the next record in the services array */
2966 /* We put this here to avoid an odd message order if messages are */
2967 /* issued by the post-processing of a previous section. */
2968 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2970 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2973 DEBUG(0, ("Failed to add a new service\n"));
2983 * Determine if a particular base parameter is currently set to the default value.
2986 static bool is_default(struct loadparm_service *sDefault, int i)
2988 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2989 if (!defaults_saved)
2991 switch (parm_table[i].type) {
2994 return str_list_equal((const char **)parm_table[i].def.lvalue,
2995 (const char **)def_ptr);
2998 return strequal(parm_table[i].def.svalue,
3002 return parm_table[i].def.bvalue ==
3009 return parm_table[i].def.ivalue ==
3016 *Display the contents of the global structure.
3019 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3023 struct parmlist_entry *data;
3025 fprintf(f, "# Global parameters\n[global]\n");
3027 for (i = 0; parm_table[i].label; i++)
3028 if (parm_table[i].p_class == P_GLOBAL &&
3029 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3030 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3032 fprintf(f, "\t%s = ", parm_table[i].label);
3033 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3036 if (lp_ctx->globals->param_opt != NULL) {
3037 for (data = lp_ctx->globals->param_opt; data;
3038 data = data->next) {
3039 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3042 fprintf(f, "\t%s = %s\n", data->key, data->value);
3049 * Display the contents of a single services record.
3052 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3053 unsigned int *flags)
3056 struct parmlist_entry *data;
3058 if (pService != sDefault)
3059 fprintf(f, "\n[%s]\n", pService->szService);
3061 for (i = 0; parm_table[i].label; i++) {
3062 if (parm_table[i].p_class == P_LOCAL &&
3063 (*parm_table[i].label != '-') &&
3064 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3066 if (pService == sDefault) {
3067 if (flags && (flags[i] & FLAG_DEFAULT)) {
3070 if (defaults_saved) {
3071 if (is_default(sDefault, i)) {
3076 if (equal_parameter(parm_table[i].type,
3077 ((char *)pService) +
3078 parm_table[i].offset,
3079 ((char *)sDefault) +
3080 parm_table[i].offset))
3084 fprintf(f, "\t%s = ", parm_table[i].label);
3085 print_parameter(&parm_table[i],
3086 ((char *)pService) + parm_table[i].offset, f);
3090 if (pService->param_opt != NULL) {
3091 for (data = pService->param_opt; data; data = data->next) {
3092 fprintf(f, "\t%s = %s\n", data->key, data->value);
3097 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3098 struct loadparm_service *service,
3099 const char *parm_name, FILE * f)
3101 struct parm_struct *parm;
3104 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3109 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3111 print_parameter(parm, ptr, f);
3117 * Return info about the next parameter in a service.
3118 * snum==-1 gives the globals.
3119 * Return NULL when out of parameters.
3123 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3127 /* do the globals */
3128 for (; parm_table[*i].label; (*i)++) {
3129 if ((*parm_table[*i].label == '-'))
3133 && (parm_table[*i].offset ==
3134 parm_table[(*i) - 1].offset)
3135 && (parm_table[*i].p_class ==
3136 parm_table[(*i) - 1].p_class))
3139 return &parm_table[(*i)++];
3142 struct loadparm_service *pService = lp_ctx->services[snum];
3144 for (; parm_table[*i].label; (*i)++) {
3145 if (parm_table[*i].p_class == P_LOCAL &&
3146 (*parm_table[*i].label != '-') &&
3148 (parm_table[*i].offset !=
3149 parm_table[(*i) - 1].offset)))
3151 if (allparameters ||
3152 !equal_parameter(parm_table[*i].type,
3153 ((char *)pService) +
3154 parm_table[*i].offset,
3155 ((char *)lp_ctx->sDefault) +
3156 parm_table[*i].offset))
3158 return &parm_table[(*i)++];
3169 * Auto-load some home services.
3171 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3179 * Unload unused services.
3182 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3183 struct smbsrv_connection *smb,
3184 bool (*snumused) (struct smbsrv_connection *, int))
3187 for (i = 0; i < lp_ctx->iNumServices; i++) {
3188 if (lp_ctx->services[i] == NULL)
3191 if (!snumused || !snumused(smb, i)) {
3192 talloc_free(lp_ctx->services[i]);
3193 lp_ctx->services[i] = NULL;
3199 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3201 struct parmlist_entry *data;
3203 if (lp_ctx->refuse_free) {
3204 /* someone is trying to free the
3205 global_loadparm_context.
3206 We can't allow that. */
3210 if (lp_ctx->globals->param_opt != NULL) {
3211 struct parmlist_entry *next;
3212 for (data = lp_ctx->globals->param_opt; data; data=next) {
3214 if (data->priority & FLAG_CMDLINE) continue;
3215 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3224 * Initialise the global parameter structure.
3226 * Note that most callers should use loadparm_init_global() instead
3228 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3232 struct loadparm_context *lp_ctx;
3233 struct parmlist_entry *parm;
3236 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3240 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3241 lp_ctx->bInGlobalSection = true;
3242 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3243 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3245 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3246 lp_ctx->sDefault->bAvailable = true;
3247 lp_ctx->sDefault->bBrowseable = true;
3248 lp_ctx->sDefault->bRead_only = true;
3249 lp_ctx->sDefault->bMap_archive = true;
3250 lp_ctx->sDefault->iStrictLocking = true;
3251 lp_ctx->sDefault->bOpLocks = true;
3252 lp_ctx->sDefault->iCreate_mask = 0744;
3253 lp_ctx->sDefault->iCreate_force_mode = 0000;
3254 lp_ctx->sDefault->iDir_mask = 0755;
3255 lp_ctx->sDefault->iDir_force_mode = 0000;
3257 DEBUG(3, ("Initialising global parameters\n"));
3259 for (i = 0; parm_table[i].label; i++) {
3260 if ((parm_table[i].type == P_STRING ||
3261 parm_table[i].type == P_USTRING) &&
3262 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3264 if (parm_table[i].p_class == P_LOCAL) {
3265 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3267 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3269 *r = talloc_strdup(lp_ctx, "");
3273 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3274 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3275 talloc_free(logfile);
3277 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3279 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3281 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3283 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
3285 /* options that can be set on the command line must be initialised via
3286 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3288 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3290 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3291 myname = get_myname(lp_ctx);
3292 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3293 talloc_free(myname);
3294 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3296 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3298 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3299 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3301 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3302 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3303 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3304 /* the winbind method for domain controllers is for both RODC
3305 auth forwarding and for trusted domains */
3306 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3307 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3309 /* This hive should be dynamically generated by Samba using
3310 data from the sam, but for the moment leave it in a tdb to
3311 keep regedt32 from popping up an annoying dialog. */
3312 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3314 /* using UTF8 by default allows us to support all chars */
3315 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3317 /* Use codepage 850 as a default for the dos character set */
3318 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3321 * Allow the default PASSWD_CHAT to be overridden in local.h.
3323 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3325 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3326 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3327 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3328 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3329 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3331 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3332 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3333 "Samba %s", SAMBA_VERSION_STRING);
3335 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3337 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3338 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3339 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3340 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3341 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3342 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3343 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3344 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3345 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
3346 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3347 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3348 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3349 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3350 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3351 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3353 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3354 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3355 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3356 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3357 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3358 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3359 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3360 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3362 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3364 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3365 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3367 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3368 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3370 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3371 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3372 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3373 #if _SAMBA_BUILD_ >= 4
3374 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3375 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3376 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3377 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3379 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3380 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3381 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3383 lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
3384 lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
3386 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3388 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3390 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3391 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3392 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3393 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3394 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3395 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3396 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3398 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3400 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3401 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3403 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3404 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3405 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3406 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3407 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3409 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3410 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3412 for (i = 0; parm_table[i].label; i++) {
3413 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3414 lp_ctx->flags[i] |= FLAG_DEFAULT;
3418 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3419 if (!(parm->priority & FLAG_CMDLINE)) {
3420 parm->priority |= FLAG_DEFAULT;
3428 * Initialise the global parameter structure.
3430 struct loadparm_context *loadparm_init_global(bool load_default)
3432 if (global_loadparm_context == NULL) {
3433 global_loadparm_context = loadparm_init(NULL);
3435 if (global_loadparm_context == NULL) {
3438 global_loadparm_context->global = true;
3439 if (load_default && !global_loadparm_context->loaded) {
3440 lpcfg_load_default(global_loadparm_context);
3442 global_loadparm_context->refuse_free = true;
3443 return global_loadparm_context;
3447 * Initialise the global parameter structure.
3449 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3450 const struct loadparm_s3_context *s3_fns)
3452 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3453 if (!loadparm_context) {
3456 loadparm_context->s3_fns = s3_fns;
3457 return loadparm_context;
3460 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3462 return lp_ctx->szConfigFile;
3465 const char *lp_default_path(void)
3467 if (getenv("SMB_CONF_PATH"))
3468 return getenv("SMB_CONF_PATH");
3470 return dyn_CONFIGFILE;
3474 * Update the internal state of a loadparm context after settings
3477 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3479 struct debug_settings settings;
3480 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3482 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3483 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3486 if (!lp_ctx->global) {
3490 panic_action = lp_ctx->globals->panic_action;
3492 reload_charcnv(lp_ctx);
3494 ZERO_STRUCT(settings);
3495 /* Add any more debug-related smb.conf parameters created in
3497 settings.timestamp_logs = true;
3498 debug_set_settings(&settings);
3500 /* FIXME: This is a bit of a hack, but we can't use a global, since
3501 * not everything that uses lp also uses the socket library */
3502 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3503 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3505 unsetenv("SOCKET_TESTNONBLOCK");
3511 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3515 path = lp_default_path();
3517 if (!file_exist(path)) {
3518 /* We allow the default smb.conf file to not exist,
3519 * basically the equivalent of an empty file. */
3520 return lpcfg_update(lp_ctx);
3523 return lpcfg_load(lp_ctx, path);
3527 * Load the services array from the services file.
3529 * Return True on success, False on failure.
3531 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3536 filename = talloc_strdup(lp_ctx, filename);
3538 lp_ctx->szConfigFile = filename;
3540 if (lp_ctx->s3_fns) {
3541 return lp_ctx->s3_fns->load(filename);
3544 lp_ctx->bInGlobalSection = true;
3545 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3546 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3548 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3550 /* We get sections first, so have to start 'behind' to make up */
3551 lp_ctx->currentService = NULL;
3552 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3554 /* finish up the last section */
3555 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3557 if (lp_ctx->currentService != NULL)
3558 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3560 bRetval = bRetval && lpcfg_update(lp_ctx);
3562 /* we do this unconditionally, so that it happens even
3563 for a missing smb.conf */
3564 reload_charcnv(lp_ctx);
3566 if (bRetval == true) {
3567 /* set this up so that any child python tasks will
3568 find the right smb.conf */
3569 setenv("SMB_CONF_PATH", filename, 1);
3571 /* set the context used by the lp_*() function
3573 global_loadparm_context = lp_ctx;
3574 lp_ctx->loaded = true;
3581 * Return the max number of services.
3584 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3586 if (lp_ctx->s3_fns) {
3587 return lp_ctx->s3_fns->get_numservices();
3590 return lp_ctx->iNumServices;
3594 * Display the contents of the services array in human-readable form.
3597 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3602 if (lp_ctx->s3_fns) {
3603 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3607 defaults_saved = !show_defaults;
3609 dump_globals(lp_ctx, f, show_defaults);
3611 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3613 for (iService = 0; iService < maxtoprint; iService++)
3614 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3618 * Display the contents of one service in human-readable form.
3620 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3622 if (service != NULL) {
3623 if (service->szService[0] == '\0')
3625 dump_a_service(service, sDefault, f, NULL);
3629 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3632 if (lp_ctx->s3_fns) {
3633 return lp_ctx->s3_fns->get_servicebynum(snum);
3636 return lp_ctx->services[snum];
3639 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3640 const char *service_name)
3645 if (lp_ctx->s3_fns) {
3646 return lp_ctx->s3_fns->get_service(service_name);
3649 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3650 if (lp_ctx->services[iService] &&
3651 lp_ctx->services[iService]->szService) {
3653 * The substitution here is used to support %U is
3656 serviceName = standard_sub_basic(
3657 lp_ctx->services[iService],
3658 lp_ctx->services[iService]->szService);
3659 if (strequal(serviceName, service_name)) {
3660 talloc_free(serviceName);
3661 return lp_ctx->services[iService];
3663 talloc_free(serviceName);
3667 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3671 const char *lpcfg_servicename(const struct loadparm_service *service)
3673 return lp_string((const char *)service->szService);
3677 * A useful volume label function.
3679 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3682 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3683 service->volume : sDefault->volume));
3685 return lpcfg_servicename(service);
3690 * If we are PDC then prefer us as DMB
3692 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3695 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3696 service->szPrintername : sDefault->szPrintername));
3697 if (ret == NULL || (ret != NULL && *ret == '\0'))
3698 ret = lpcfg_servicename(service);
3705 * Return the max print jobs per queue.
3707 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3709 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3710 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3711 maxjobs = PRINT_MAX_JOBID - 1;
3716 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3718 if (lp_ctx == NULL) {
3719 return get_iconv_handle();
3721 return lp_ctx->iconv_handle;
3724 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3726 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3727 if (!lp_ctx->global) {
3731 if (old_ic == NULL) {
3732 old_ic = global_iconv_handle;
3734 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3735 global_iconv_handle = lp_ctx->iconv_handle;
3738 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3740 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3743 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3745 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3748 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3750 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3753 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3755 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3758 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3760 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3763 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3765 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3766 if (settings == NULL)
3768 SMB_ASSERT(lp_ctx != NULL);
3769 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3770 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");