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"
72 #include "../lib/util/bitmap.h"
74 #define standard_sub_basic talloc_strdup
76 static bool do_parameter(const char *, const char *, void *);
77 static bool defaults_saved = false;
79 #define LOADPARM_EXTRA_GLOBALS \
80 struct parmlist_entry *param_opt; \
91 #define LOADPARM_EXTRA_LOCALS \
92 struct parmlist_entry *param_opt; \
96 char *szPrintername; \
100 struct bitmap *copymap; \
101 char dummy[3]; /* for alignment */
103 #include "param_global.h"
104 #include "param_local.h"
106 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
109 /* prototypes for the special type handlers */
110 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
111 const char *pszParmValue, char **ptr);
112 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
113 const char *pszParmValue, char **ptr);
114 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
115 const char *pszParmValue, char **ptr);
116 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
117 const char *pszParmValue, char **ptr);
118 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
119 const char *pszParmValue, char **ptr);
121 static const struct enum_list enum_protocol[] = {
122 {PROTOCOL_SMB2, "SMB2"},
123 {PROTOCOL_NT1, "NT1"},
124 {PROTOCOL_LANMAN2, "LANMAN2"},
125 {PROTOCOL_LANMAN1, "LANMAN1"},
126 {PROTOCOL_CORE, "CORE"},
127 {PROTOCOL_COREPLUS, "COREPLUS"},
128 {PROTOCOL_COREPLUS, "CORE+"},
132 static const struct enum_list enum_security[] = {
133 {SEC_SHARE, "SHARE"},
139 static const struct enum_list enum_bool_auto[] = {
150 /* Client-side offline caching policy types */
153 CSC_POLICY_DOCUMENTS=1,
154 CSC_POLICY_PROGRAMS=2,
158 static const struct enum_list enum_csc_policy[] = {
159 {CSC_POLICY_MANUAL, "manual"},
160 {CSC_POLICY_DOCUMENTS, "documents"},
161 {CSC_POLICY_PROGRAMS, "programs"},
162 {CSC_POLICY_DISABLE, "disable"},
166 /* SMB signing types. */
167 static const struct enum_list enum_smb_signing_vals[] = {
168 {SMB_SIGNING_OFF, "No"},
169 {SMB_SIGNING_OFF, "False"},
170 {SMB_SIGNING_OFF, "0"},
171 {SMB_SIGNING_OFF, "Off"},
172 {SMB_SIGNING_OFF, "disabled"},
173 {SMB_SIGNING_SUPPORTED, "Yes"},
174 {SMB_SIGNING_SUPPORTED, "True"},
175 {SMB_SIGNING_SUPPORTED, "1"},
176 {SMB_SIGNING_SUPPORTED, "On"},
177 {SMB_SIGNING_SUPPORTED, "enabled"},
178 {SMB_SIGNING_REQUIRED, "required"},
179 {SMB_SIGNING_REQUIRED, "mandatory"},
180 {SMB_SIGNING_REQUIRED, "force"},
181 {SMB_SIGNING_REQUIRED, "forced"},
182 {SMB_SIGNING_REQUIRED, "enforced"},
183 {SMB_SIGNING_AUTO, "auto"},
187 static const struct enum_list enum_server_role[] = {
188 {ROLE_STANDALONE, "standalone"},
189 {ROLE_DOMAIN_MEMBER, "member server"},
190 {ROLE_DOMAIN_MEMBER, "member"},
191 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
192 {ROLE_DOMAIN_CONTROLLER, "dc"},
196 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
197 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
199 static struct parm_struct parm_table[] = {
201 .label = "server role",
204 .offset = GLOBAL_VAR(server_role),
206 .enum_list = enum_server_role
209 .label = "dos charset",
212 .offset = GLOBAL_VAR(dos_charset),
217 .label = "unix charset",
220 .offset = GLOBAL_VAR(unix_charset),
225 .label = "ncalrpc dir",
228 .offset = GLOBAL_VAR(ncalrpc_dir),
236 .offset = LOCAL_VAR(comment),
244 .offset = LOCAL_VAR(szPath),
249 .label = "directory",
252 .offset = LOCAL_VAR(szPath),
257 .label = "workgroup",
260 .offset = GLOBAL_VAR(szWorkgroup),
268 .offset = GLOBAL_VAR(szRealm),
269 .special = handle_realm,
273 .label = "netbios name",
276 .offset = GLOBAL_VAR(szNetbiosName),
281 .label = "netbios aliases",
284 .offset = GLOBAL_VAR(szNetbiosAliases),
289 .label = "netbios scope",
292 .offset = GLOBAL_VAR(szNetbiosScope),
297 .label = "server string",
300 .offset = GLOBAL_VAR(szServerString),
305 .label = "interfaces",
308 .offset = GLOBAL_VAR(szInterfaces),
313 .label = "bind interfaces only",
316 .offset = GLOBAL_VAR(bBindInterfacesOnly),
321 .label = "ntvfs handler",
324 .offset = LOCAL_VAR(ntvfs_handler),
329 .label = "ntptr providor",
332 .offset = GLOBAL_VAR(ntptr_providor),
337 .label = "dcerpc endpoint servers",
340 .offset = GLOBAL_VAR(dcerpc_ep_servers),
345 .label = "server services",
348 .offset = GLOBAL_VAR(server_services),
357 .offset = GLOBAL_VAR(security),
359 .enum_list = enum_security
362 .label = "encrypt passwords",
365 .offset = GLOBAL_VAR(bEncryptPasswords),
370 .label = "null passwords",
373 .offset = GLOBAL_VAR(bNullPasswords),
378 .label = "obey pam restrictions",
381 .offset = GLOBAL_VAR(bObeyPamRestrictions),
386 .label = "password server",
389 .offset = GLOBAL_VAR(szPasswordServers),
394 .label = "spoolss database",
397 .offset = GLOBAL_VAR(szSPOOLSS_URL),
402 .label = "wins config database",
405 .offset = GLOBAL_VAR(szWINS_CONFIG_URL),
410 .label = "wins database",
413 .offset = GLOBAL_VAR(szWINS_URL),
418 .label = "private dir",
421 .offset = GLOBAL_VAR(szPrivateDir),
426 .label = "passwd chat",
429 .offset = GLOBAL_VAR(szPasswdChat),
434 .label = "password level",
437 .offset = GLOBAL_VAR(pwordlevel),
442 .label = "lanman auth",
445 .offset = GLOBAL_VAR(bLanmanAuth),
450 .label = "ntlm auth",
453 .offset = GLOBAL_VAR(bNTLMAuth),
458 .label = "client NTLMv2 auth",
461 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
466 .label = "client lanman auth",
469 .offset = GLOBAL_VAR(bClientLanManAuth),
474 .label = "client plaintext auth",
477 .offset = GLOBAL_VAR(bClientPlaintextAuth),
482 .label = "client use spnego principal",
485 .offset = GLOBAL_VAR(client_use_spnego_principal),
491 .label = "read only",
494 .offset = LOCAL_VAR(bRead_only),
500 .label = "create mask",
503 .offset = LOCAL_VAR(iCreate_mask),
508 .label = "force create mode",
511 .offset = LOCAL_VAR(iCreate_force_mode),
516 .label = "directory mask",
519 .offset = LOCAL_VAR(iDir_mask),
524 .label = "force directory mode",
527 .offset = LOCAL_VAR(iDir_force_mode),
533 .label = "hosts allow",
536 .offset = LOCAL_VAR(szHostsallow),
541 .label = "hosts deny",
544 .offset = LOCAL_VAR(szHostsdeny),
550 .label = "log level",
553 .offset = GLOBAL_VAR(loglevel),
554 .special = handle_debuglevel,
558 .label = "debuglevel",
561 .offset = GLOBAL_VAR(loglevel),
562 .special = handle_debuglevel,
569 .offset = GLOBAL_VAR(logfile),
570 .special = handle_logfile,
575 .label = "smb ports",
578 .offset = GLOBAL_VAR(smb_ports),
586 .offset = GLOBAL_VAR(nbt_port),
591 .label = "dgram port",
594 .offset = GLOBAL_VAR(dgram_port),
599 .label = "cldap port",
602 .offset = GLOBAL_VAR(cldap_port),
607 .label = "krb5 port",
610 .offset = GLOBAL_VAR(krb5_port),
615 .label = "kpasswd port",
618 .offset = GLOBAL_VAR(kpasswd_port),
626 .offset = GLOBAL_VAR(web_port),
631 .label = "tls enabled",
634 .offset = GLOBAL_VAR(tls_enabled),
639 .label = "tls keyfile",
642 .offset = GLOBAL_VAR(tls_keyfile),
647 .label = "tls certfile",
650 .offset = GLOBAL_VAR(tls_certfile),
655 .label = "tls cafile",
658 .offset = GLOBAL_VAR(tls_cafile),
663 .label = "tls crlfile",
666 .offset = GLOBAL_VAR(tls_crlfile),
671 .label = "tls dh params file",
674 .offset = GLOBAL_VAR(tls_dhpfile),
679 .label = "large readwrite",
682 .offset = GLOBAL_VAR(bLargeReadwrite),
687 .label = "server max protocol",
690 .offset = GLOBAL_VAR(srv_maxprotocol),
692 .enum_list = enum_protocol
695 .label = "server min protocol",
698 .offset = GLOBAL_VAR(srv_minprotocol),
700 .enum_list = enum_protocol
703 .label = "client max protocol",
706 .offset = GLOBAL_VAR(cli_maxprotocol),
708 .enum_list = enum_protocol
711 .label = "client min protocol",
714 .offset = GLOBAL_VAR(cli_minprotocol),
716 .enum_list = enum_protocol
722 .offset = GLOBAL_VAR(bUnicode),
730 .offset = GLOBAL_VAR(bReadRaw),
735 .label = "write raw",
738 .offset = GLOBAL_VAR(bWriteRaw),
743 .label = "disable netbios",
746 .offset = GLOBAL_VAR(bDisableNetbios),
752 .label = "nt status support",
755 .offset = GLOBAL_VAR(bNTStatusSupport),
764 .offset = GLOBAL_VAR(max_mux),
772 .offset = GLOBAL_VAR(max_xmit),
778 .label = "name resolve order",
781 .offset = GLOBAL_VAR(szNameResolveOrder),
786 .label = "max wins ttl",
789 .offset = GLOBAL_VAR(max_wins_ttl),
794 .label = "min wins ttl",
797 .offset = GLOBAL_VAR(min_wins_ttl),
802 .label = "time server",
805 .offset = GLOBAL_VAR(bTimeServer),
810 .label = "unix extensions",
813 .offset = GLOBAL_VAR(bUnixExtensions),
818 .label = "use spnego",
821 .offset = GLOBAL_VAR(bUseSpnego),
826 .label = "server signing",
829 .offset = GLOBAL_VAR(server_signing),
831 .enum_list = enum_smb_signing_vals
834 .label = "client signing",
837 .offset = GLOBAL_VAR(client_signing),
839 .enum_list = enum_smb_signing_vals
842 .label = "rpc big endian",
845 .offset = GLOBAL_VAR(bRpcBigEndian),
851 .label = "max connections",
854 .offset = LOCAL_VAR(iMaxConnections),
859 .label = "paranoid server security",
862 .offset = GLOBAL_VAR(paranoid_server_security),
867 .label = "socket options",
870 .offset = GLOBAL_VAR(socket_options),
876 .label = "strict sync",
879 .offset = LOCAL_VAR(bStrictSync),
884 .label = "case insensitive filesystem",
887 .offset = LOCAL_VAR(bCIFileSystem),
893 .label = "max print jobs",
896 .offset = LOCAL_VAR(iMaxPrintJobs),
901 .label = "printable",
904 .offset = LOCAL_VAR(bPrint_ok),
912 .offset = LOCAL_VAR(bPrint_ok),
918 .label = "printer name",
921 .offset = LOCAL_VAR(szPrintername),
929 .offset = LOCAL_VAR(szPrintername),
935 .label = "map system",
938 .offset = LOCAL_VAR(bMap_system),
943 .label = "map hidden",
946 .offset = LOCAL_VAR(bMap_hidden),
951 .label = "map archive",
954 .offset = LOCAL_VAR(bMap_archive),
960 .label = "preferred master",
963 .offset = GLOBAL_VAR(bPreferredMaster),
965 .enum_list = enum_bool_auto
968 .label = "prefered master",
971 .offset = GLOBAL_VAR(bPreferredMaster),
973 .enum_list = enum_bool_auto
976 .label = "local master",
979 .offset = GLOBAL_VAR(bLocalMaster),
984 .label = "browseable",
987 .offset = LOCAL_VAR(bBrowseable),
992 .label = "browsable",
995 .offset = LOCAL_VAR(bBrowseable),
1001 .label = "wins server",
1003 .p_class = P_GLOBAL,
1004 .offset = GLOBAL_VAR(szWINSservers),
1009 .label = "wins support",
1011 .p_class = P_GLOBAL,
1012 .offset = GLOBAL_VAR(bWINSsupport),
1017 .label = "dns proxy",
1019 .p_class = P_GLOBAL,
1020 .offset = GLOBAL_VAR(bWINSdnsProxy),
1025 .label = "wins hook",
1027 .p_class = P_GLOBAL,
1028 .offset = GLOBAL_VAR(szWINSHook),
1034 .label = "csc policy",
1037 .offset = LOCAL_VAR(iCSCPolicy),
1039 .enum_list = enum_csc_policy
1043 .label = "strict locking",
1046 .offset = LOCAL_VAR(bStrictLocking),
1054 .offset = LOCAL_VAR(bOplocks),
1060 .label = "share backend",
1062 .p_class = P_GLOBAL,
1063 .offset = GLOBAL_VAR(szShareBackend),
1070 .p_class = P_GLOBAL,
1071 .offset = GLOBAL_VAR(szAutoServices),
1076 .label = "auto services",
1078 .p_class = P_GLOBAL,
1079 .offset = GLOBAL_VAR(szAutoServices),
1084 .label = "lock dir",
1086 .p_class = P_GLOBAL,
1087 .offset = GLOBAL_VAR(szLockDir),
1092 .label = "lock directory",
1094 .p_class = P_GLOBAL,
1095 .offset = GLOBAL_VAR(szLockDir),
1100 .label = "pid directory",
1102 .p_class = P_GLOBAL,
1103 .offset = GLOBAL_VAR(szPidDir),
1109 .label = "socket address",
1111 .p_class = P_GLOBAL,
1112 .offset = GLOBAL_VAR(szSocketAddress),
1120 .offset = LOCAL_VAR(szCopy),
1121 .special = handle_copy,
1128 .offset = LOCAL_VAR(szInclude),
1129 .special = handle_include,
1134 .label = "available",
1137 .offset = LOCAL_VAR(bAvailable),
1145 .offset = LOCAL_VAR(volume),
1153 .offset = LOCAL_VAR(fstype),
1159 .label = "panic action",
1161 .p_class = P_GLOBAL,
1162 .offset = GLOBAL_VAR(panic_action),
1168 .label = "msdfs root",
1171 .offset = LOCAL_VAR(bMSDfsRoot),
1176 .label = "host msdfs",
1178 .p_class = P_GLOBAL,
1179 .offset = GLOBAL_VAR(bHostMSDfs),
1184 .label = "winbind separator",
1186 .p_class = P_GLOBAL,
1187 .offset = GLOBAL_VAR(szWinbindSeparator),
1192 .label = "winbindd socket directory",
1194 .p_class = P_GLOBAL,
1195 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1200 .label = "winbindd privileged socket directory",
1202 .p_class = P_GLOBAL,
1203 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1208 .label = "winbind sealed pipes",
1210 .p_class = P_GLOBAL,
1211 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1216 .label = "template shell",
1218 .p_class = P_GLOBAL,
1219 .offset = GLOBAL_VAR(szTemplateShell),
1224 .label = "template homedir",
1226 .p_class = P_GLOBAL,
1227 .offset = GLOBAL_VAR(szTemplateHomedir),
1232 .label = "idmap trusted only",
1234 .p_class = P_GLOBAL,
1235 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1241 .label = "ntp signd socket directory",
1243 .p_class = P_GLOBAL,
1244 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1249 .label = "rndc command",
1251 .p_class = P_GLOBAL,
1252 .offset = GLOBAL_VAR(szRNDCCommand),
1257 .label = "dns update command",
1259 .p_class = P_GLOBAL,
1260 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1265 .label = "spn update command",
1267 .p_class = P_GLOBAL,
1268 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1273 .label = "nsupdate command",
1275 .p_class = P_GLOBAL,
1276 .offset = GLOBAL_VAR(szNSUpdateCommand),
1281 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1285 /* local variables */
1286 struct loadparm_context {
1287 const char *szConfigFile;
1288 struct loadparm_global *globals;
1289 struct loadparm_service **services;
1290 struct loadparm_service *sDefault;
1291 struct smb_iconv_handle *iconv_handle;
1293 struct loadparm_service *currentService;
1294 bool bInGlobalSection;
1296 struct file_lists *next;
1301 unsigned int flags[NUMPARAMETERS];
1304 bool global; /* Is this the global context, which may set
1305 * global variables such as debug level etc? */
1306 const struct loadparm_s3_context *s3_fns;
1310 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1312 return lp_ctx->sDefault;
1316 * Convenience routine to grab string parameters into temporary memory
1317 * and run standard_sub_basic on them.
1319 * The buffers can be written to by
1320 * callers without affecting the source string.
1323 static const char *lp_string(const char *s)
1325 #if 0 /* until REWRITE done to make thread-safe */
1326 size_t len = s ? strlen(s) : 0;
1330 /* The follow debug is useful for tracking down memory problems
1331 especially if you have an inner loop that is calling a lp_*()
1332 function that returns a string. Perhaps this debug should be
1333 present all the time? */
1336 DEBUG(10, ("lp_string(%s)\n", s));
1339 #if 0 /* until REWRITE done to make thread-safe */
1341 lp_talloc = talloc_init("lp_talloc");
1343 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1351 strlcpy(ret, s, len);
1353 if (trim_string(ret, "\"", "\"")) {
1354 if (strchr(ret,'"') != NULL)
1355 strlcpy(ret, s, len);
1358 standard_sub_basic(ret,len+100);
1365 In this section all the functions that are used to access the
1366 parameters from the rest of the program are defined
1370 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1371 * for code compatibility between existing Samba4 and Samba3 code.
1374 /* this global context supports the lp_*() function varients */
1375 static struct loadparm_context *global_loadparm_context;
1377 #define lpcfg_default_service global_loadparm_context->sDefault
1378 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1380 #define FN_GLOBAL_STRING(fn_name,var_name) \
1381 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1382 if (lp_ctx == NULL) return NULL; \
1383 if (lp_ctx->s3_fns) { \
1384 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1385 return lp_ctx->s3_fns->fn_name(); \
1387 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1390 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1391 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1392 if (lp_ctx == NULL) return NULL; \
1393 if (lp_ctx->s3_fns) { \
1394 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1395 return lp_ctx->s3_fns->fn_name(); \
1397 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1400 #define FN_GLOBAL_LIST(fn_name,var_name) \
1401 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1402 if (lp_ctx == NULL) return NULL; \
1403 if (lp_ctx->s3_fns) { \
1404 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1405 return lp_ctx->s3_fns->fn_name(); \
1407 return lp_ctx->globals->var_name; \
1410 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1411 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1412 if (lp_ctx == NULL) return false; \
1413 if (lp_ctx->s3_fns) { \
1414 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1415 return lp_ctx->s3_fns->fn_name(); \
1417 return lp_ctx->globals->var_name; \
1420 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1421 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1422 if (lp_ctx->s3_fns) { \
1423 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1424 return lp_ctx->s3_fns->fn_name(); \
1426 return lp_ctx->globals->var_name; \
1429 #define FN_LOCAL_STRING(fn_name,val) \
1430 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1431 struct loadparm_service *sDefault) { \
1432 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1435 #define FN_LOCAL_LIST(fn_name,val) \
1436 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1437 struct loadparm_service *sDefault) {\
1438 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1441 #define FN_LOCAL_BOOL(fn_name,val) \
1442 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1443 struct loadparm_service *sDefault) { \
1444 return((service != NULL)? service->val : sDefault->val); \
1447 #define FN_LOCAL_INTEGER(fn_name,val) \
1448 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1449 struct loadparm_service *sDefault) { \
1450 return((service != NULL)? service->val : sDefault->val); \
1453 FN_GLOBAL_INTEGER(server_role, server_role)
1454 FN_GLOBAL_LIST(smb_ports, smb_ports)
1455 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1456 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1457 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1458 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1459 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1460 FN_GLOBAL_INTEGER(web_port, web_port)
1461 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1462 FN_GLOBAL_STRING(logfile, logfile)
1463 FN_GLOBAL_STRING(share_backend, szShareBackend)
1464 FN_GLOBAL_STRING(spoolss_url, szSPOOLSS_URL)
1465 FN_GLOBAL_STRING(wins_config_url, szWINS_CONFIG_URL)
1466 FN_GLOBAL_STRING(wins_url, szWINS_URL)
1467 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1468 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1469 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1470 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1471 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1472 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1473 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1474 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1475 FN_GLOBAL_STRING(serverstring, szServerString)
1476 FN_GLOBAL_STRING(lockdir, szLockDir)
1477 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1478 FN_GLOBAL_STRING(dos_charset, dos_charset)
1479 FN_GLOBAL_STRING(unix_charset, unix_charset)
1480 FN_GLOBAL_STRING(piddir, szPidDir)
1481 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1482 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1483 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1484 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1485 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1486 FN_GLOBAL_LIST(server_services, server_services)
1487 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1488 FN_GLOBAL_STRING(auto_services, szAutoServices)
1489 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1490 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1491 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1492 FN_GLOBAL_STRING(realm, szRealm_upper)
1493 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1494 FN_GLOBAL_STRING(socket_options, socket_options)
1495 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1496 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1497 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1498 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1499 FN_GLOBAL_LIST(interfaces, szInterfaces)
1500 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1501 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1502 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1503 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1504 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1505 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1506 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1507 FN_GLOBAL_BOOL(readraw, bReadRaw)
1508 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1509 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1510 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1511 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1512 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1513 FN_GLOBAL_BOOL(time_server, bTimeServer)
1514 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1515 FN_GLOBAL_BOOL(unicode, bUnicode)
1516 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1517 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1518 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1519 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1520 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1521 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1522 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1523 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1524 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1525 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1526 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1527 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1528 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1529 FN_GLOBAL_INTEGER(maxmux, max_mux)
1530 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1531 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1532 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1533 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1534 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1535 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1536 FN_GLOBAL_INTEGER(security, security)
1537 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1539 FN_LOCAL_STRING(pathname, szPath)
1540 FN_LOCAL_LIST(hostsallow, szHostsallow)
1541 FN_LOCAL_LIST(hostsdeny, szHostsdeny)
1542 FN_LOCAL_STRING(comment, comment)
1543 FN_LOCAL_STRING(fstype, fstype)
1544 FN_LOCAL_LIST(ntvfs_handler, ntvfs_handler)
1545 FN_LOCAL_BOOL(msdfs_root, bMSDfsRoot)
1546 FN_LOCAL_BOOL(browseable, bBrowseable)
1547 FN_LOCAL_BOOL(readonly, bRead_only)
1548 FN_LOCAL_BOOL(print_ok, bPrint_ok)
1549 FN_LOCAL_BOOL(map_hidden, bMap_hidden)
1550 FN_LOCAL_BOOL(map_archive, bMap_archive)
1551 FN_LOCAL_BOOL(strict_locking, bStrictLocking)
1552 FN_LOCAL_BOOL(oplocks, bOplocks)
1553 FN_LOCAL_BOOL(strict_sync, bStrictSync)
1554 FN_LOCAL_BOOL(ci_filesystem, bCIFileSystem)
1555 FN_LOCAL_BOOL(map_system, bMap_system)
1556 FN_LOCAL_INTEGER(max_connections, iMaxConnections)
1557 FN_LOCAL_INTEGER(csc_policy, iCSCPolicy)
1558 FN_LOCAL_INTEGER(create_mask, iCreate_mask)
1559 FN_LOCAL_INTEGER(force_create_mode, iCreate_force_mode)
1560 FN_LOCAL_INTEGER(dir_mask, iDir_mask)
1561 FN_LOCAL_INTEGER(force_dir_mode, iDir_force_mode)
1562 FN_GLOBAL_INTEGER(server_signing, server_signing)
1563 FN_GLOBAL_INTEGER(client_signing, client_signing)
1565 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1567 /* local prototypes */
1568 static int map_parameter(const char *pszParmName);
1569 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1570 const char *pszServiceName);
1571 static void copy_service(struct loadparm_service *pserviceDest,
1572 struct loadparm_service *pserviceSource,
1573 struct bitmap *pcopymapDest);
1574 static bool service_ok(struct loadparm_service *service);
1575 static bool do_section(const char *pszSectionName, void *);
1576 static void init_copymap(struct loadparm_service *pservice);
1578 /* This is a helper function for parametrical options support. */
1579 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1580 /* Actual parametrical functions are quite simple */
1581 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1582 struct loadparm_service *service,
1583 const char *type, const char *option)
1585 char *vfskey_tmp = NULL;
1586 char *vfskey = NULL;
1587 struct parmlist_entry *data;
1592 if (lp_ctx->s3_fns) {
1593 return lp_ctx->s3_fns->get_parametric(service, type, option);
1596 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1598 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1599 if (vfskey_tmp == NULL) return NULL;
1600 vfskey = strlower_talloc(NULL, vfskey_tmp);
1601 talloc_free(vfskey_tmp);
1604 if (strcmp(data->key, vfskey) == 0) {
1605 talloc_free(vfskey);
1611 if (service != NULL) {
1612 /* Try to fetch the same option but from globals */
1613 /* but only if we are not already working with globals */
1614 for (data = lp_ctx->globals->param_opt; data;
1615 data = data->next) {
1616 if (strcmp(data->key, vfskey) == 0) {
1617 talloc_free(vfskey);
1623 talloc_free(vfskey);
1630 * convenience routine to return int parameters.
1632 static int lp_int(const char *s)
1636 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1640 return strtol(s, NULL, 0);
1644 * convenience routine to return unsigned long parameters.
1646 static int lp_ulong(const char *s)
1650 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1654 return strtoul(s, NULL, 0);
1658 * convenience routine to return unsigned long parameters.
1660 static double lp_double(const char *s)
1664 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1668 return strtod(s, NULL);
1672 * convenience routine to return boolean parameters.
1674 static bool lp_bool(const char *s)
1679 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1683 if (!set_boolean(s, &ret)) {
1684 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1693 * Return parametric option from a given service. Type is a part of option before ':'
1694 * Parametric option has following syntax: 'Type: option = value'
1695 * Returned value is allocated in 'lp_talloc' context
1698 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1699 struct loadparm_service *service, const char *type,
1702 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1705 return lp_string(value);
1711 * Return parametric option from a given service. Type is a part of option before ':'
1712 * Parametric option has following syntax: 'Type: option = value'
1713 * Returned value is allocated in 'lp_talloc' context
1716 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1717 struct loadparm_context *lp_ctx,
1718 struct loadparm_service *service,
1720 const char *option, const char *separator)
1722 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1725 return (const char **)str_list_make(mem_ctx, value, separator);
1731 * Return parametric option from a given service. Type is a part of option before ':'
1732 * Parametric option has following syntax: 'Type: option = value'
1735 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1736 struct loadparm_service *service, const char *type,
1737 const char *option, int default_v)
1739 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1742 return lp_int(value);
1748 * Return parametric option from a given service. Type is a part of
1749 * option before ':'.
1750 * Parametric option has following syntax: 'Type: option = value'.
1753 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1754 struct loadparm_service *service, const char *type,
1755 const char *option, int default_v)
1759 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1761 if (value && conv_str_size_error(value, &bval)) {
1762 if (bval <= INT_MAX) {
1771 * Return parametric option from a given service.
1772 * Type is a part of option before ':'
1773 * Parametric option has following syntax: 'Type: option = value'
1775 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1776 struct loadparm_service *service, const char *type,
1777 const char *option, unsigned long default_v)
1779 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1782 return lp_ulong(value);
1788 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1789 struct loadparm_service *service, const char *type,
1790 const char *option, double default_v)
1792 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1795 return lp_double(value);
1801 * Return parametric option from a given service. Type is a part of option before ':'
1802 * Parametric option has following syntax: 'Type: option = value'
1805 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1806 struct loadparm_service *service, const char *type,
1807 const char *option, bool default_v)
1809 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1812 return lp_bool(value);
1819 * Initialise a service to the defaults.
1822 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1824 struct loadparm_service *pservice =
1825 talloc_zero(mem_ctx, struct loadparm_service);
1826 copy_service(pservice, sDefault, NULL);
1831 * Set a string value, deallocating any existing space, and allocing the space
1834 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1841 *dest = talloc_strdup(mem_ctx, src);
1842 if ((*dest) == NULL) {
1843 DEBUG(0,("Out of memory in string_set\n"));
1851 * Set a string value, deallocating any existing space, and allocing the space
1854 static bool string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1861 *dest = strupper_talloc(mem_ctx, src);
1862 if ((*dest) == NULL) {
1863 DEBUG(0,("Out of memory in string_set_upper\n"));
1873 * Add a new service to the services array initialising it with the given
1877 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1878 const struct loadparm_service *pservice,
1882 struct loadparm_service tservice;
1883 int num_to_alloc = lp_ctx->iNumServices + 1;
1884 struct parmlist_entry *data, *pdata;
1886 if (pservice == NULL) {
1887 pservice = lp_ctx->sDefault;
1890 tservice = *pservice;
1892 /* it might already exist */
1894 struct loadparm_service *service = getservicebyname(lp_ctx,
1896 if (service != NULL) {
1897 /* Clean all parametric options for service */
1898 /* They will be added during parsing again */
1899 data = service->param_opt;
1905 service->param_opt = NULL;
1910 /* find an invalid one */
1911 for (i = 0; i < lp_ctx->iNumServices; i++)
1912 if (lp_ctx->services[i] == NULL)
1915 /* if not, then create one */
1916 if (i == lp_ctx->iNumServices) {
1917 struct loadparm_service **tsp;
1919 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1922 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1925 lp_ctx->services = tsp;
1926 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1929 lp_ctx->iNumServices++;
1932 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1933 if (lp_ctx->services[i] == NULL) {
1934 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1937 copy_service(lp_ctx->services[i], &tservice, NULL);
1939 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1940 return lp_ctx->services[i];
1944 * Add a new home service, with the specified home directory, defaults coming
1945 * from service ifrom.
1948 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1949 const char *pszHomename,
1950 struct loadparm_service *default_service,
1951 const char *user, const char *pszHomedir)
1953 struct loadparm_service *service;
1955 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1957 if (service == NULL)
1960 if (!(*(default_service->szPath))
1961 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1962 service->szPath = talloc_strdup(service, pszHomedir);
1964 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1967 if (!(*(service->comment))) {
1968 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1970 service->bAvailable = default_service->bAvailable;
1971 service->bBrowseable = default_service->bBrowseable;
1973 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1974 pszHomename, user, service->szPath));
1980 * Add a new printer service, with defaults coming from service iFrom.
1983 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1984 const char *pszPrintername,
1985 struct loadparm_service *default_service)
1987 const char *comment = "From Printcap";
1988 struct loadparm_service *service;
1989 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1991 if (service == NULL)
1994 /* note that we do NOT default the availability flag to True - */
1995 /* we take it from the default service passed. This allows all */
1996 /* dynamic printers to be disabled by disabling the [printers] */
1997 /* entry (if/when the 'available' keyword is implemented!). */
1999 /* the printer name is set to the service name. */
2000 string_set(service, &service->szPrintername, pszPrintername);
2001 string_set(service, &service->comment, comment);
2002 service->bBrowseable = default_service->bBrowseable;
2003 /* Printers cannot be read_only. */
2004 service->bRead_only = false;
2005 /* Printer services must be printable. */
2006 service->bPrint_ok = true;
2008 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2014 * Map a parameter's string representation to something we can use.
2015 * Returns False if the parameter string is not recognised, else TRUE.
2018 static int map_parameter(const char *pszParmName)
2022 if (*pszParmName == '-')
2025 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2026 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2029 /* Warn only if it isn't parametric option */
2030 if (strchr(pszParmName, ':') == NULL)
2031 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2032 /* We do return 'fail' for parametric options as well because they are
2033 stored in different storage
2040 return the parameter structure for a parameter
2042 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2046 if (lp_ctx->s3_fns) {
2047 return lp_ctx->s3_fns->get_parm_struct(name);
2050 parmnum = map_parameter(name);
2051 if (parmnum == -1) return NULL;
2052 return &parm_table[parmnum];
2056 return the parameter pointer for a parameter
2058 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2059 struct loadparm_service *service, struct parm_struct *parm)
2061 if (lp_ctx->s3_fns) {
2062 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2065 if (service == NULL) {
2066 if (parm->p_class == P_LOCAL)
2067 return ((char *)lp_ctx->sDefault)+parm->offset;
2068 else if (parm->p_class == P_GLOBAL)
2069 return ((char *)lp_ctx->globals)+parm->offset;
2072 return ((char *)service) + parm->offset;
2077 * Find a service by name. Otherwise works like get_service.
2080 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2081 const char *pszServiceName)
2085 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2086 if (lp_ctx->services[iService] != NULL &&
2087 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2088 return lp_ctx->services[iService];
2095 * Copy a service structure to another.
2096 * If pcopymapDest is NULL then copy all fields
2099 static void copy_service(struct loadparm_service *pserviceDest,
2100 struct loadparm_service *pserviceSource,
2101 struct bitmap *pcopymapDest)
2104 bool bcopyall = (pcopymapDest == NULL);
2105 struct parmlist_entry *data, *pdata, *paramo;
2108 for (i = 0; parm_table[i].label; i++)
2109 if (parm_table[i].p_class == P_LOCAL &&
2110 (bcopyall || bitmap_query(pcopymapDest, i))) {
2112 ((char *)pserviceSource) + parm_table[i].offset;
2114 ((char *)pserviceDest) + parm_table[i].offset;
2116 switch (parm_table[i].type) {
2118 *(int *)dest_ptr = *(int *)src_ptr;
2124 *(int *)dest_ptr = *(int *)src_ptr;
2128 string_set(pserviceDest,
2134 string_set_upper(pserviceDest,
2139 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2140 *(const char ***)src_ptr);
2148 init_copymap(pserviceDest);
2149 if (pserviceSource->copymap)
2150 bitmap_copy(pserviceDest->copymap,
2151 pserviceSource->copymap);
2154 data = pserviceSource->param_opt;
2157 pdata = pserviceDest->param_opt;
2158 /* Traverse destination */
2160 /* If we already have same option, override it */
2161 if (strcmp(pdata->key, data->key) == 0) {
2162 talloc_free(pdata->value);
2163 pdata->value = talloc_reference(pdata,
2168 pdata = pdata->next;
2171 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2174 paramo->key = talloc_reference(paramo, data->key);
2175 paramo->value = talloc_reference(paramo, data->value);
2176 DLIST_ADD(pserviceDest->param_opt, paramo);
2183 * Check a service for consistency. Return False if the service is in any way
2184 * incomplete or faulty, else True.
2186 static bool service_ok(struct loadparm_service *service)
2191 if (service->szService[0] == '\0') {
2192 DEBUG(0, ("The following message indicates an internal error:\n"));
2193 DEBUG(0, ("No service name in service entry.\n"));
2197 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2198 /* I can't see why you'd want a non-printable printer service... */
2199 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2200 if (!service->bPrint_ok) {
2201 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2202 service->szService));
2203 service->bPrint_ok = true;
2205 /* [printers] service must also be non-browsable. */
2206 if (service->bBrowseable)
2207 service->bBrowseable = false;
2210 /* If a service is flagged unavailable, log the fact at level 0. */
2211 if (!service->bAvailable)
2212 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2213 service->szService));
2219 /*******************************************************************
2220 Keep a linked list of all config files so we know when one has changed
2221 it's date and needs to be reloaded.
2222 ********************************************************************/
2224 static void add_to_file_list(struct loadparm_context *lp_ctx,
2225 const char *fname, const char *subfname)
2227 struct file_lists *f = lp_ctx->file_lists;
2230 if (f->name && !strcmp(f->name, fname))
2236 f = talloc(lp_ctx, struct file_lists);
2239 f->next = lp_ctx->file_lists;
2240 f->name = talloc_strdup(f, fname);
2245 f->subfname = talloc_strdup(f, subfname);
2250 lp_ctx->file_lists = f;
2251 f->modtime = file_modtime(subfname);
2253 time_t t = file_modtime(subfname);
2259 /*******************************************************************
2260 Check if a config file has changed date.
2261 ********************************************************************/
2262 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2264 struct file_lists *f;
2265 DEBUG(6, ("lp_file_list_changed()\n"));
2267 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2271 n2 = standard_sub_basic(lp_ctx, f->name);
2273 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2274 f->name, n2, ctime(&f->modtime)));
2276 mod_time = file_modtime(n2);
2278 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2279 DEBUGADD(6, ("file %s modified: %s\n", n2,
2281 f->modtime = mod_time;
2282 talloc_free(f->subfname);
2283 f->subfname = talloc_strdup(f, n2);
2290 /***************************************************************************
2291 Handle the "realm" parameter
2292 ***************************************************************************/
2294 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2295 const char *pszParmValue, char **ptr)
2297 string_set(lp_ctx, ptr, pszParmValue);
2299 talloc_free(lp_ctx->globals->szRealm_upper);
2300 talloc_free(lp_ctx->globals->szRealm_lower);
2302 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2303 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2308 /***************************************************************************
2309 Handle the include operation.
2310 ***************************************************************************/
2312 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2313 const char *pszParmValue, char **ptr)
2315 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2317 add_to_file_list(lp_ctx, pszParmValue, fname);
2319 string_set(lp_ctx, ptr, fname);
2321 if (file_exist(fname))
2322 return pm_process(fname, do_section, do_parameter, lp_ctx);
2324 DEBUG(2, ("Can't find include file %s\n", fname));
2329 /***************************************************************************
2330 Handle the interpretation of the copy parameter.
2331 ***************************************************************************/
2333 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2334 const char *pszParmValue, char **ptr)
2337 struct loadparm_service *serviceTemp;
2339 string_set(lp_ctx, ptr, pszParmValue);
2343 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2345 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2346 if (serviceTemp == lp_ctx->currentService) {
2347 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2349 copy_service(lp_ctx->currentService,
2351 lp_ctx->currentService->copymap);
2355 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2363 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2364 const char *pszParmValue, char **ptr)
2367 string_set(lp_ctx, ptr, pszParmValue);
2368 if (lp_ctx->global) {
2369 return debug_parse_levels(pszParmValue);
2374 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2375 const char *pszParmValue, char **ptr)
2377 debug_set_logfile(pszParmValue);
2378 if (lp_ctx->global) {
2379 string_set(lp_ctx, ptr, pszParmValue);
2384 /***************************************************************************
2385 Initialise a copymap.
2386 ***************************************************************************/
2388 static void init_copymap(struct loadparm_service *pservice)
2392 TALLOC_FREE(pservice->copymap);
2394 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2395 if (!pservice->copymap)
2397 ("Couldn't allocate copymap!! (size %d)\n",
2398 (int)NUMPARAMETERS));
2400 for (i = 0; i < NUMPARAMETERS; i++)
2401 bitmap_set(pservice->copymap, i);
2405 * Process a parametric option
2407 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2408 struct loadparm_service *service,
2409 const char *pszParmName,
2410 const char *pszParmValue, int flags)
2412 struct parmlist_entry *paramo, *data;
2414 TALLOC_CTX *mem_ctx;
2416 while (isspace((unsigned char)*pszParmName)) {
2420 name = strlower_talloc(lp_ctx, pszParmName);
2421 if (!name) return false;
2423 if (service == NULL) {
2424 data = lp_ctx->globals->param_opt;
2425 mem_ctx = lp_ctx->globals;
2427 data = service->param_opt;
2431 /* Traverse destination */
2432 for (paramo=data; paramo; paramo=paramo->next) {
2433 /* If we already have the option set, override it unless
2434 it was a command line option and the new one isn't */
2435 if (strcmp(paramo->key, name) == 0) {
2436 if ((paramo->priority & FLAG_CMDLINE) &&
2437 !(flags & FLAG_CMDLINE)) {
2442 talloc_free(paramo->value);
2443 paramo->value = talloc_strdup(paramo, pszParmValue);
2444 paramo->priority = flags;
2450 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2453 paramo->key = talloc_strdup(paramo, name);
2454 paramo->value = talloc_strdup(paramo, pszParmValue);
2455 paramo->priority = flags;
2456 if (service == NULL) {
2457 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2459 DLIST_ADD(service->param_opt, paramo);
2467 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2468 const char *pszParmName, const char *pszParmValue,
2469 struct loadparm_context *lp_ctx, bool on_globals)
2472 /* if it is a special case then go ahead */
2473 if (parm_table[parmnum].special) {
2475 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2480 goto mark_non_default;
2483 /* now switch on the type of variable it is */
2484 switch (parm_table[parmnum].type)
2488 if (!set_boolean(pszParmValue, &b)) {
2489 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2492 *(int *)parm_ptr = b;
2498 if (!set_boolean(pszParmValue, &b)) {
2499 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2502 *(int *)parm_ptr = !b;
2507 *(int *)parm_ptr = atoi(pszParmValue);
2511 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2517 if (conv_str_size_error(pszParmValue, &val)) {
2518 if (val <= INT_MAX) {
2519 *(int *)parm_ptr = (int)val;
2524 DEBUG(0,("lp_do_parameter(%s): value is not "
2525 "a valid size specifier!\n", pszParmValue));
2530 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2531 pszParmValue, NULL);
2535 char **new_list = str_list_make(mem_ctx,
2536 pszParmValue, NULL);
2537 for (i=0; new_list[i]; i++) {
2538 if (new_list[i][0] == '+' && new_list[i][1] &&
2539 (!str_list_check(*(const char ***)parm_ptr,
2540 &new_list[i][1]))) {
2541 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2543 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2544 #if 0 /* This is commented out because we sometimes parse the list
2545 * twice, and so we can't assert on this */
2546 if (!str_list_check(*(const char ***)parm_ptr,
2548 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2549 pszParmName, pszParmValue, new_list[i],
2550 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2555 str_list_remove(*(const char ***)parm_ptr,
2559 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2560 pszParmName, pszParmValue));
2563 *(const char ***)parm_ptr = (const char **) new_list;
2570 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2574 string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2578 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2581 parm_table[parmnum].enum_list[i].name)) {
2583 parm_table[parmnum].
2588 if (!parm_table[parmnum].enum_list[i].name) {
2589 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2590 pszParmValue, pszParmName));
2597 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2598 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2599 /* we have to also unset FLAG_DEFAULT on aliases */
2600 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2601 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2603 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2604 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2611 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2612 const char *pszParmName, const char *pszParmValue)
2614 int parmnum = map_parameter(pszParmName);
2618 if (strchr(pszParmName, ':')) {
2619 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2621 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2625 /* if the flag has been set on the command line, then don't allow override,
2626 but don't report an error */
2627 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2631 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2633 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2634 pszParmName, pszParmValue, lp_ctx, true);
2637 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2638 struct loadparm_service *service,
2639 const char *pszParmName, const char *pszParmValue)
2643 int parmnum = map_parameter(pszParmName);
2646 if (strchr(pszParmName, ':')) {
2647 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2649 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2653 /* if the flag has been set on the command line, then don't allow override,
2654 but don't report an error */
2655 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2659 if (parm_table[parmnum].p_class == P_GLOBAL) {
2661 ("Global parameter %s found in service section!\n",
2665 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2667 if (!service->copymap)
2668 init_copymap(service);
2670 /* this handles the aliases - set the copymap for other
2671 * entries with the same data pointer */
2672 for (i = 0; parm_table[i].label; i++)
2673 if (parm_table[i].offset == parm_table[parmnum].offset &&
2674 parm_table[i].p_class == parm_table[parmnum].p_class)
2675 bitmap_clear(service->copymap, i);
2677 return set_variable(service, parmnum, parm_ptr, pszParmName,
2678 pszParmValue, lp_ctx, false);
2682 * Process a parameter.
2685 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2688 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2690 if (lp_ctx->bInGlobalSection)
2691 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2694 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2695 pszParmName, pszParmValue);
2699 variable argument do parameter
2701 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2702 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2703 const char *pszParmName, const char *fmt, ...)
2710 s = talloc_vasprintf(NULL, fmt, ap);
2712 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2719 set a parameter from the commandline - this is called from command line parameter
2720 parsing code. It sets the parameter then marks the parameter as unable to be modified
2721 by smb.conf processing
2723 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2724 const char *pszParmValue)
2726 int parmnum = map_parameter(pszParmName);
2729 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2732 if (parmnum < 0 && strchr(pszParmName, ':')) {
2733 /* set a parametric option */
2734 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2735 pszParmValue, FLAG_CMDLINE);
2739 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2743 /* reset the CMDLINE flag in case this has been called before */
2744 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2746 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2750 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2752 /* we have to also set FLAG_CMDLINE on aliases */
2753 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2754 lp_ctx->flags[i] |= FLAG_CMDLINE;
2756 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2757 lp_ctx->flags[i] |= FLAG_CMDLINE;
2764 set a option from the commandline in 'a=b' format. Use to support --option
2766 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2784 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2790 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2793 * Print a parameter of the specified type.
2796 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2799 const char *list_sep = ", "; /* For the seperation of lists values that we print below */
2803 for (i = 0; p->enum_list[i].name; i++) {
2804 if (*(int *)ptr == p->enum_list[i].value) {
2806 p->enum_list[i].name);
2813 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
2817 fprintf(f, "%s", BOOLSTR(!(bool)*(int *)ptr));
2822 fprintf(f, "%d", *(int *)ptr);
2826 fprintf(f, "0%o", *(int *)ptr);
2833 if ((char ***)ptr && *(char ***)ptr) {
2834 char **list = *(char ***)ptr;
2836 for (; *list; list++) {
2837 if (*(list+1) == NULL) {
2838 /* last item, print no extra seperator after */
2841 fprintf(f, "%s%s", *list, list_sep);
2848 if (*(char **)ptr) {
2849 fprintf(f, "%s", *(char **)ptr);
2856 * Check if two parameters are equal.
2859 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2864 return (*((int *)ptr1) == *((int *)ptr2));
2870 return (*((int *)ptr1) == *((int *)ptr2));
2874 return str_list_equal((const char **)(*(char ***)ptr1),
2875 (const char **)(*(char ***)ptr2));
2880 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2885 return (p1 == p2 || strequal(p1, p2));
2892 * Process a new section (service).
2894 * At this stage all sections are services.
2895 * Later we'll have special sections that permit server parameters to be set.
2896 * Returns True on success, False on failure.
2899 static bool do_section(const char *pszSectionName, void *userdata)
2901 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2903 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2904 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2907 /* if we've just struck a global section, note the fact. */
2908 lp_ctx->bInGlobalSection = isglobal;
2910 /* check for multiple global sections */
2911 if (lp_ctx->bInGlobalSection) {
2912 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2916 /* if we have a current service, tidy it up before moving on */
2919 if (lp_ctx->currentService != NULL)
2920 bRetval = service_ok(lp_ctx->currentService);
2922 /* if all is still well, move to the next record in the services array */
2924 /* We put this here to avoid an odd message order if messages are */
2925 /* issued by the post-processing of a previous section. */
2926 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2928 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2931 DEBUG(0, ("Failed to add a new service\n"));
2941 * Determine if a particular base parameter is currently set to the default value.
2944 static bool is_default(struct loadparm_service *sDefault, int i)
2946 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2947 if (!defaults_saved)
2949 switch (parm_table[i].type) {
2952 return str_list_equal((const char **)parm_table[i].def.lvalue,
2953 (const char **)def_ptr);
2956 return strequal(parm_table[i].def.svalue,
2960 return parm_table[i].def.bvalue ==
2966 return parm_table[i].def.ivalue ==
2973 *Display the contents of the global structure.
2976 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2980 struct parmlist_entry *data;
2982 fprintf(f, "# Global parameters\n[global]\n");
2984 for (i = 0; parm_table[i].label; i++)
2985 if (parm_table[i].p_class == P_GLOBAL &&
2986 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2987 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2989 fprintf(f, "\t%s = ", parm_table[i].label);
2990 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2993 if (lp_ctx->globals->param_opt != NULL) {
2994 for (data = lp_ctx->globals->param_opt; data;
2995 data = data->next) {
2996 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2999 fprintf(f, "\t%s = %s\n", data->key, data->value);
3006 * Display the contents of a single services record.
3009 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3010 unsigned int *flags)
3013 struct parmlist_entry *data;
3015 if (pService != sDefault)
3016 fprintf(f, "\n[%s]\n", pService->szService);
3018 for (i = 0; parm_table[i].label; i++) {
3019 if (parm_table[i].p_class == P_LOCAL &&
3020 (*parm_table[i].label != '-') &&
3021 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3023 if (pService == sDefault) {
3024 if (flags && (flags[i] & FLAG_DEFAULT)) {
3027 if (defaults_saved) {
3028 if (is_default(sDefault, i)) {
3033 if (equal_parameter(parm_table[i].type,
3034 ((char *)pService) +
3035 parm_table[i].offset,
3036 ((char *)sDefault) +
3037 parm_table[i].offset))
3041 fprintf(f, "\t%s = ", parm_table[i].label);
3042 print_parameter(&parm_table[i],
3043 ((char *)pService) + parm_table[i].offset, f);
3047 if (pService->param_opt != NULL) {
3048 for (data = pService->param_opt; data; data = data->next) {
3049 fprintf(f, "\t%s = %s\n", data->key, data->value);
3054 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3055 struct loadparm_service *service,
3056 const char *parm_name, FILE * f)
3058 struct parm_struct *parm;
3061 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3066 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3068 print_parameter(parm, ptr, f);
3074 * Return info about the next parameter in a service.
3075 * snum==-1 gives the globals.
3076 * Return NULL when out of parameters.
3080 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3084 /* do the globals */
3085 for (; parm_table[*i].label; (*i)++) {
3086 if ((*parm_table[*i].label == '-'))
3090 && (parm_table[*i].offset ==
3091 parm_table[(*i) - 1].offset)
3092 && (parm_table[*i].p_class ==
3093 parm_table[(*i) - 1].p_class))
3096 return &parm_table[(*i)++];
3099 struct loadparm_service *pService = lp_ctx->services[snum];
3101 for (; parm_table[*i].label; (*i)++) {
3102 if (parm_table[*i].p_class == P_LOCAL &&
3103 (*parm_table[*i].label != '-') &&
3105 (parm_table[*i].offset !=
3106 parm_table[(*i) - 1].offset)))
3108 if (allparameters ||
3109 !equal_parameter(parm_table[*i].type,
3110 ((char *)pService) +
3111 parm_table[*i].offset,
3112 ((char *)lp_ctx->sDefault) +
3113 parm_table[*i].offset))
3115 return &parm_table[(*i)++];
3126 * Auto-load some home services.
3128 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3136 * Unload unused services.
3139 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3140 struct smbsrv_connection *smb,
3141 bool (*snumused) (struct smbsrv_connection *, int))
3144 for (i = 0; i < lp_ctx->iNumServices; i++) {
3145 if (lp_ctx->services[i] == NULL)
3148 if (!snumused || !snumused(smb, i)) {
3149 talloc_free(lp_ctx->services[i]);
3150 lp_ctx->services[i] = NULL;
3156 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3158 struct parmlist_entry *data;
3160 if (lp_ctx->refuse_free) {
3161 /* someone is trying to free the
3162 global_loadparm_context.
3163 We can't allow that. */
3167 if (lp_ctx->globals->param_opt != NULL) {
3168 struct parmlist_entry *next;
3169 for (data = lp_ctx->globals->param_opt; data; data=next) {
3171 if (data->priority & FLAG_CMDLINE) continue;
3172 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3181 * Initialise the global parameter structure.
3183 * Note that most callers should use loadparm_init_global() instead
3185 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3189 struct loadparm_context *lp_ctx;
3190 struct parmlist_entry *parm;
3193 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3197 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3198 lp_ctx->bInGlobalSection = true;
3199 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3200 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3202 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3203 lp_ctx->sDefault->bAvailable = true;
3204 lp_ctx->sDefault->bBrowseable = true;
3205 lp_ctx->sDefault->bRead_only = true;
3206 lp_ctx->sDefault->bMap_archive = true;
3207 lp_ctx->sDefault->bStrictLocking = true;
3208 lp_ctx->sDefault->bOplocks = true;
3209 lp_ctx->sDefault->iCreate_mask = 0744;
3210 lp_ctx->sDefault->iCreate_force_mode = 0000;
3211 lp_ctx->sDefault->iDir_mask = 0755;
3212 lp_ctx->sDefault->iDir_force_mode = 0000;
3214 DEBUG(3, ("Initialising global parameters\n"));
3216 for (i = 0; parm_table[i].label; i++) {
3217 if ((parm_table[i].type == P_STRING ||
3218 parm_table[i].type == P_USTRING) &&
3219 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3221 if (parm_table[i].p_class == P_LOCAL) {
3222 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3224 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3226 *r = talloc_strdup(lp_ctx, "");
3230 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3231 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3232 talloc_free(logfile);
3234 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3236 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3238 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3240 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
3242 /* options that can be set on the command line must be initialised via
3243 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3245 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3247 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3248 myname = get_myname(lp_ctx);
3249 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3250 talloc_free(myname);
3251 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3253 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3255 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3256 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3258 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3259 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate web");
3260 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3261 /* the winbind method for domain controllers is for both RODC
3262 auth forwarding and for trusted domains */
3263 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3264 lpcfg_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
3265 lpcfg_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
3266 lpcfg_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
3267 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3269 /* This hive should be dynamically generated by Samba using
3270 data from the sam, but for the moment leave it in a tdb to
3271 keep regedt32 from popping up an annoying dialog. */
3272 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3274 /* using UTF8 by default allows us to support all chars */
3275 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3277 /* Use codepage 850 as a default for the dos character set */
3278 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3281 * Allow the default PASSWD_CHAT to be overridden in local.h.
3283 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3285 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3286 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3287 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3289 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3290 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3291 "Samba %s", SAMBA_VERSION_STRING);
3293 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3295 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3296 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3297 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3298 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3299 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3300 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3301 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3302 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3303 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
3304 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3305 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3306 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3307 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3308 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3309 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3311 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3312 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3313 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3314 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3315 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3316 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3317 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3318 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3320 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3322 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3323 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3325 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3326 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3328 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3329 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3330 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3331 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3332 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3333 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3334 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3336 lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
3337 lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
3339 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3341 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3342 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3343 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3344 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3345 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3346 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3347 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3349 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3351 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3352 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3354 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3355 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3356 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3357 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3358 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3360 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3361 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3362 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3363 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3364 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3366 for (i = 0; parm_table[i].label; i++) {
3367 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3368 lp_ctx->flags[i] |= FLAG_DEFAULT;
3372 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3373 if (!(parm->priority & FLAG_CMDLINE)) {
3374 parm->priority |= FLAG_DEFAULT;
3382 * Initialise the global parameter structure.
3384 struct loadparm_context *loadparm_init_global(bool load_default)
3386 if (global_loadparm_context == NULL) {
3387 global_loadparm_context = loadparm_init(NULL);
3389 if (global_loadparm_context == NULL) {
3392 global_loadparm_context->global = true;
3393 if (load_default && !global_loadparm_context->loaded) {
3394 lpcfg_load_default(global_loadparm_context);
3396 global_loadparm_context->refuse_free = true;
3397 return global_loadparm_context;
3401 * Initialise the global parameter structure.
3403 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3404 const struct loadparm_s3_context *s3_fns)
3406 struct loadparm_context *loadparm_context = loadparm_init(mem_ctx);
3407 if (!loadparm_context) {
3410 loadparm_context->s3_fns = s3_fns;
3411 return loadparm_context;
3414 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3416 return lp_ctx->szConfigFile;
3419 const char *lp_default_path(void)
3421 if (getenv("SMB_CONF_PATH"))
3422 return getenv("SMB_CONF_PATH");
3424 return dyn_CONFIGFILE;
3428 * Update the internal state of a loadparm context after settings
3431 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3433 struct debug_settings settings;
3434 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3436 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3437 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3440 if (!lp_ctx->global) {
3444 panic_action = lp_ctx->globals->panic_action;
3446 reload_charcnv(lp_ctx);
3448 ZERO_STRUCT(settings);
3449 /* Add any more debug-related smb.conf parameters created in
3451 settings.timestamp_logs = true;
3452 debug_set_settings(&settings);
3454 /* FIXME: This is a bit of a hack, but we can't use a global, since
3455 * not everything that uses lp also uses the socket library */
3456 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3457 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3459 unsetenv("SOCKET_TESTNONBLOCK");
3465 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3469 path = lp_default_path();
3471 if (!file_exist(path)) {
3472 /* We allow the default smb.conf file to not exist,
3473 * basically the equivalent of an empty file. */
3474 return lpcfg_update(lp_ctx);
3477 return lpcfg_load(lp_ctx, path);
3481 * Load the services array from the services file.
3483 * Return True on success, False on failure.
3485 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3490 filename = talloc_strdup(lp_ctx, filename);
3492 lp_ctx->szConfigFile = filename;
3494 lp_ctx->bInGlobalSection = true;
3495 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3496 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3498 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3500 /* We get sections first, so have to start 'behind' to make up */
3501 lp_ctx->currentService = NULL;
3502 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3504 /* finish up the last section */
3505 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3507 if (lp_ctx->currentService != NULL)
3508 bRetval = service_ok(lp_ctx->currentService);
3510 bRetval = bRetval && lpcfg_update(lp_ctx);
3512 /* we do this unconditionally, so that it happens even
3513 for a missing smb.conf */
3514 reload_charcnv(lp_ctx);
3516 if (bRetval == true) {
3517 /* set this up so that any child python tasks will
3518 find the right smb.conf */
3519 setenv("SMB_CONF_PATH", filename, 1);
3521 /* set the context used by the lp_*() function
3523 global_loadparm_context = lp_ctx;
3524 lp_ctx->loaded = true;
3531 * Return the max number of services.
3534 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3536 return lp_ctx->iNumServices;
3540 * Display the contents of the services array in human-readable form.
3543 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3548 defaults_saved = !show_defaults;
3550 dump_globals(lp_ctx, f, show_defaults);
3552 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3554 for (iService = 0; iService < maxtoprint; iService++)
3555 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3559 * Display the contents of one service in human-readable form.
3561 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3563 if (service != NULL) {
3564 if (service->szService[0] == '\0')
3566 dump_a_service(service, sDefault, f, NULL);
3570 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3573 return lp_ctx->services[snum];
3576 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3577 const char *service_name)
3582 if (lp_ctx->s3_fns) {
3583 return lp_ctx->s3_fns->get_service(service_name);
3586 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3587 if (lp_ctx->services[iService] &&
3588 lp_ctx->services[iService]->szService) {
3590 * The substitution here is used to support %U is
3593 serviceName = standard_sub_basic(
3594 lp_ctx->services[iService],
3595 lp_ctx->services[iService]->szService);
3596 if (strequal(serviceName, service_name)) {
3597 talloc_free(serviceName);
3598 return lp_ctx->services[iService];
3600 talloc_free(serviceName);
3604 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3608 const char *lpcfg_servicename(const struct loadparm_service *service)
3610 return lp_string((const char *)service->szService);
3614 * A useful volume label function.
3616 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3619 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3620 service->volume : sDefault->volume));
3622 return lpcfg_servicename(service);
3627 * If we are PDC then prefer us as DMB
3629 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3632 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3633 service->szPrintername : sDefault->szPrintername));
3634 if (ret == NULL || (ret != NULL && *ret == '\0'))
3635 ret = lpcfg_servicename(service);
3642 * Return the max print jobs per queue.
3644 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3646 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3647 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3648 maxjobs = PRINT_MAX_JOBID - 1;
3653 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3655 if (lp_ctx == NULL) {
3656 return get_iconv_handle();
3658 return lp_ctx->iconv_handle;
3661 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3663 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3664 if (!lp_ctx->global) {
3668 if (old_ic == NULL) {
3669 old_ic = global_iconv_handle;
3671 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3672 global_iconv_handle = lp_ctx->iconv_handle;
3675 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
3676 struct smbcli_options *options)
3678 options->max_xmit = lpcfg_max_xmit(lp_ctx);
3679 options->max_mux = lpcfg_maxmux(lp_ctx);
3680 options->use_spnego = lpcfg_nt_status_support(lp_ctx) && lpcfg_use_spnego(lp_ctx);
3681 options->signing = lpcfg_client_signing(lp_ctx);
3682 options->request_timeout = SMB_REQUEST_TIMEOUT;
3683 options->ntstatus_support = lpcfg_nt_status_support(lp_ctx);
3684 options->max_protocol = lpcfg_cli_maxprotocol(lp_ctx);
3685 options->unicode = lpcfg_unicode(lp_ctx);
3686 options->use_oplocks = true;
3687 options->use_level2_oplocks = true;
3690 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
3691 struct smbcli_session_options *options)
3693 options->lanman_auth = lpcfg_client_lanman_auth(lp_ctx);
3694 options->ntlmv2_auth = lpcfg_client_ntlmv2_auth(lp_ctx);
3695 options->plaintext_auth = lpcfg_client_plaintext_auth(lp_ctx);
3698 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3700 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3703 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3705 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3708 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3710 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3713 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3715 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3718 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3720 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3723 _PUBLIC_ struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3725 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
3727 ret->domain_name = talloc_reference(mem_ctx, lpcfg_workgroup(lp_ctx));
3728 ret->version_major = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
3729 ret->version_minor = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
3730 ret->version_build = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
3735 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3737 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3738 if (settings == NULL)
3740 SMB_ASSERT(lp_ctx != NULL);
3741 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3742 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");