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 "lib/socket/socket.h"
65 #include "auth/gensec/gensec.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
70 #define standard_sub_basic talloc_strdup
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved = false;
75 #define LOADPARM_EXTRA_GLOBALS \
76 struct parmlist_entry *param_opt; \
87 #include "param_global.h"
89 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
92 /* prototypes for the special type handlers */
93 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
94 const char *pszParmValue, char **ptr);
95 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
96 const char *pszParmValue, char **ptr);
97 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
98 const char *pszParmValue, char **ptr);
99 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
100 const char *pszParmValue, char **ptr);
101 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
102 const char *pszParmValue, char **ptr);
104 static const struct enum_list enum_protocol[] = {
105 {PROTOCOL_SMB2_02, "SMB2"},
106 {PROTOCOL_SMB2_02, "SMB2_02"},
107 {PROTOCOL_NT1, "NT1"},
108 {PROTOCOL_LANMAN2, "LANMAN2"},
109 {PROTOCOL_LANMAN1, "LANMAN1"},
110 {PROTOCOL_CORE, "CORE"},
111 {PROTOCOL_COREPLUS, "COREPLUS"},
112 {PROTOCOL_COREPLUS, "CORE+"},
116 static const struct enum_list enum_security[] = {
117 {SEC_SHARE, "SHARE"},
123 static const struct enum_list enum_bool_auto[] = {
134 /* Client-side offline caching policy types */
137 CSC_POLICY_DOCUMENTS=1,
138 CSC_POLICY_PROGRAMS=2,
142 static const struct enum_list enum_csc_policy[] = {
143 {CSC_POLICY_MANUAL, "manual"},
144 {CSC_POLICY_DOCUMENTS, "documents"},
145 {CSC_POLICY_PROGRAMS, "programs"},
146 {CSC_POLICY_DISABLE, "disable"},
150 /* SMB signing types. */
151 static const struct enum_list enum_smb_signing_vals[] = {
152 {SMB_SIGNING_OFF, "No"},
153 {SMB_SIGNING_OFF, "False"},
154 {SMB_SIGNING_OFF, "0"},
155 {SMB_SIGNING_OFF, "Off"},
156 {SMB_SIGNING_OFF, "disabled"},
157 {SMB_SIGNING_SUPPORTED, "Yes"},
158 {SMB_SIGNING_SUPPORTED, "True"},
159 {SMB_SIGNING_SUPPORTED, "1"},
160 {SMB_SIGNING_SUPPORTED, "On"},
161 {SMB_SIGNING_SUPPORTED, "enabled"},
162 {SMB_SIGNING_REQUIRED, "required"},
163 {SMB_SIGNING_REQUIRED, "mandatory"},
164 {SMB_SIGNING_REQUIRED, "force"},
165 {SMB_SIGNING_REQUIRED, "forced"},
166 {SMB_SIGNING_REQUIRED, "enforced"},
167 {SMB_SIGNING_AUTO, "auto"},
171 static const struct enum_list enum_server_role[] = {
172 {ROLE_STANDALONE, "standalone"},
173 {ROLE_DOMAIN_MEMBER, "member server"},
174 {ROLE_DOMAIN_MEMBER, "member"},
175 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
176 {ROLE_DOMAIN_CONTROLLER, "dc"},
180 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
181 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
183 static struct parm_struct parm_table[] = {
185 .label = "server role",
188 .offset = GLOBAL_VAR(server_role),
190 .enum_list = enum_server_role
193 .label = "dos charset",
196 .offset = GLOBAL_VAR(dos_charset),
201 .label = "unix charset",
204 .offset = GLOBAL_VAR(unix_charset),
209 .label = "ncalrpc dir",
212 .offset = GLOBAL_VAR(ncalrpc_dir),
220 .offset = LOCAL_VAR(comment),
228 .offset = LOCAL_VAR(szPath),
233 .label = "directory",
236 .offset = LOCAL_VAR(szPath),
241 .label = "workgroup",
244 .offset = GLOBAL_VAR(szWorkgroup),
252 .offset = GLOBAL_VAR(szRealm),
253 .special = handle_realm,
257 .label = "netbios name",
260 .offset = GLOBAL_VAR(szNetbiosName),
265 .label = "netbios aliases",
268 .offset = GLOBAL_VAR(szNetbiosAliases),
273 .label = "netbios scope",
276 .offset = GLOBAL_VAR(szNetbiosScope),
281 .label = "server string",
284 .offset = GLOBAL_VAR(szServerString),
289 .label = "interfaces",
292 .offset = GLOBAL_VAR(szInterfaces),
297 .label = "bind interfaces only",
300 .offset = GLOBAL_VAR(bBindInterfacesOnly),
305 .label = "ntvfs handler",
308 .offset = LOCAL_VAR(ntvfs_handler),
313 .label = "ntptr providor",
316 .offset = GLOBAL_VAR(ntptr_providor),
321 .label = "passdb backend",
324 .offset = GLOBAL_VAR(passdb_backend),
329 .label = "dcerpc endpoint servers",
332 .offset = GLOBAL_VAR(dcerpc_ep_servers),
337 .label = "server services",
340 .offset = GLOBAL_VAR(server_services),
349 .offset = GLOBAL_VAR(security),
351 .enum_list = enum_security
354 .label = "encrypt passwords",
357 .offset = GLOBAL_VAR(bEncryptPasswords),
362 .label = "null passwords",
365 .offset = GLOBAL_VAR(bNullPasswords),
370 .label = "obey pam restrictions",
373 .offset = GLOBAL_VAR(bObeyPamRestrictions),
378 .label = "password server",
381 .offset = GLOBAL_VAR(szPasswordServers),
386 .label = "spoolss database",
389 .offset = GLOBAL_VAR(szSPOOLSS_URL),
394 .label = "wins config database",
397 .offset = GLOBAL_VAR(szWINS_CONFIG_URL),
402 .label = "wins database",
405 .offset = GLOBAL_VAR(szWINS_URL),
410 .label = "private dir",
413 .offset = GLOBAL_VAR(szPrivateDir),
418 .label = "passwd chat",
421 .offset = GLOBAL_VAR(szPasswdChat),
426 .label = "password level",
429 .offset = GLOBAL_VAR(pwordlevel),
434 .label = "lanman auth",
437 .offset = GLOBAL_VAR(bLanmanAuth),
442 .label = "ntlm auth",
445 .offset = GLOBAL_VAR(bNTLMAuth),
450 .label = "client NTLMv2 auth",
453 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
458 .label = "client lanman auth",
461 .offset = GLOBAL_VAR(bClientLanManAuth),
466 .label = "client plaintext auth",
469 .offset = GLOBAL_VAR(bClientPlaintextAuth),
474 .label = "client use spnego principal",
477 .offset = GLOBAL_VAR(client_use_spnego_principal),
483 .label = "read only",
486 .offset = LOCAL_VAR(bRead_only),
492 .label = "create mask",
495 .offset = LOCAL_VAR(iCreate_mask),
500 .label = "force create mode",
503 .offset = LOCAL_VAR(iCreate_force_mode),
508 .label = "directory mask",
511 .offset = LOCAL_VAR(iDir_mask),
516 .label = "force directory mode",
519 .offset = LOCAL_VAR(iDir_force_mode),
525 .label = "hosts allow",
528 .offset = LOCAL_VAR(szHostsallow),
533 .label = "hosts deny",
536 .offset = LOCAL_VAR(szHostsdeny),
542 .label = "log level",
545 .offset = GLOBAL_VAR(loglevel),
546 .special = handle_debuglevel,
550 .label = "debuglevel",
553 .offset = GLOBAL_VAR(loglevel),
554 .special = handle_debuglevel,
561 .offset = GLOBAL_VAR(logfile),
562 .special = handle_logfile,
567 .label = "smb ports",
570 .offset = GLOBAL_VAR(smb_ports),
578 .offset = GLOBAL_VAR(nbt_port),
583 .label = "dgram port",
586 .offset = GLOBAL_VAR(dgram_port),
591 .label = "cldap port",
594 .offset = GLOBAL_VAR(cldap_port),
599 .label = "krb5 port",
602 .offset = GLOBAL_VAR(krb5_port),
607 .label = "kpasswd port",
610 .offset = GLOBAL_VAR(kpasswd_port),
618 .offset = GLOBAL_VAR(web_port),
623 .label = "tls enabled",
626 .offset = GLOBAL_VAR(tls_enabled),
631 .label = "tls keyfile",
634 .offset = GLOBAL_VAR(tls_keyfile),
639 .label = "tls certfile",
642 .offset = GLOBAL_VAR(tls_certfile),
647 .label = "tls cafile",
650 .offset = GLOBAL_VAR(tls_cafile),
655 .label = "tls crlfile",
658 .offset = GLOBAL_VAR(tls_crlfile),
663 .label = "tls dh params file",
666 .offset = GLOBAL_VAR(tls_dhpfile),
671 .label = "large readwrite",
674 .offset = GLOBAL_VAR(bLargeReadwrite),
679 .label = "server max protocol",
682 .offset = GLOBAL_VAR(srv_maxprotocol),
684 .enum_list = enum_protocol
687 .label = "server min protocol",
690 .offset = GLOBAL_VAR(srv_minprotocol),
692 .enum_list = enum_protocol
695 .label = "client max protocol",
698 .offset = GLOBAL_VAR(cli_maxprotocol),
700 .enum_list = enum_protocol
703 .label = "client min protocol",
706 .offset = GLOBAL_VAR(cli_minprotocol),
708 .enum_list = enum_protocol
714 .offset = GLOBAL_VAR(bUnicode),
722 .offset = GLOBAL_VAR(bReadRaw),
727 .label = "write raw",
730 .offset = GLOBAL_VAR(bWriteRaw),
735 .label = "disable netbios",
738 .offset = GLOBAL_VAR(bDisableNetbios),
744 .label = "nt status support",
747 .offset = GLOBAL_VAR(bNTStatusSupport),
756 .offset = GLOBAL_VAR(max_mux),
764 .offset = GLOBAL_VAR(max_xmit),
770 .label = "name resolve order",
773 .offset = GLOBAL_VAR(szNameResolveOrder),
778 .label = "max wins ttl",
781 .offset = GLOBAL_VAR(max_wins_ttl),
786 .label = "min wins ttl",
789 .offset = GLOBAL_VAR(min_wins_ttl),
794 .label = "time server",
797 .offset = GLOBAL_VAR(bTimeServer),
802 .label = "unix extensions",
805 .offset = GLOBAL_VAR(bUnixExtensions),
810 .label = "use spnego",
813 .offset = GLOBAL_VAR(bUseSpnego),
818 .label = "server signing",
821 .offset = GLOBAL_VAR(server_signing),
823 .enum_list = enum_smb_signing_vals
826 .label = "client signing",
829 .offset = GLOBAL_VAR(client_signing),
831 .enum_list = enum_smb_signing_vals
834 .label = "rpc big endian",
837 .offset = GLOBAL_VAR(bRpcBigEndian),
843 .label = "max connections",
846 .offset = LOCAL_VAR(iMaxConnections),
851 .label = "paranoid server security",
854 .offset = GLOBAL_VAR(paranoid_server_security),
859 .label = "socket options",
862 .offset = GLOBAL_VAR(socket_options),
868 .label = "strict sync",
871 .offset = LOCAL_VAR(bStrictSync),
876 .label = "case insensitive filesystem",
879 .offset = LOCAL_VAR(bCIFileSystem),
885 .label = "max print jobs",
888 .offset = LOCAL_VAR(iMaxPrintJobs),
893 .label = "printable",
896 .offset = LOCAL_VAR(bPrint_ok),
904 .offset = LOCAL_VAR(bPrint_ok),
910 .label = "printer name",
913 .offset = LOCAL_VAR(szPrintername),
921 .offset = LOCAL_VAR(szPrintername),
927 .label = "map system",
930 .offset = LOCAL_VAR(bMap_system),
935 .label = "map hidden",
938 .offset = LOCAL_VAR(bMap_hidden),
943 .label = "map archive",
946 .offset = LOCAL_VAR(bMap_archive),
952 .label = "preferred master",
955 .offset = GLOBAL_VAR(bPreferredMaster),
957 .enum_list = enum_bool_auto
960 .label = "prefered master",
963 .offset = GLOBAL_VAR(bPreferredMaster),
965 .enum_list = enum_bool_auto
968 .label = "local master",
971 .offset = GLOBAL_VAR(bLocalMaster),
976 .label = "browseable",
979 .offset = LOCAL_VAR(bBrowseable),
984 .label = "browsable",
987 .offset = LOCAL_VAR(bBrowseable),
993 .label = "wins server",
996 .offset = GLOBAL_VAR(szWINSservers),
1001 .label = "wins support",
1003 .p_class = P_GLOBAL,
1004 .offset = GLOBAL_VAR(bWINSsupport),
1009 .label = "dns proxy",
1011 .p_class = P_GLOBAL,
1012 .offset = GLOBAL_VAR(bWINSdnsProxy),
1017 .label = "wins hook",
1019 .p_class = P_GLOBAL,
1020 .offset = GLOBAL_VAR(szWINSHook),
1026 .label = "csc policy",
1029 .offset = LOCAL_VAR(iCSCPolicy),
1031 .enum_list = enum_csc_policy
1035 .label = "strict locking",
1038 .offset = LOCAL_VAR(iStrictLocking),
1046 .offset = LOCAL_VAR(bOpLocks),
1052 .label = "share backend",
1054 .p_class = P_GLOBAL,
1055 .offset = GLOBAL_VAR(szShareBackend),
1062 .p_class = P_GLOBAL,
1063 .offset = GLOBAL_VAR(szAutoServices),
1068 .label = "auto services",
1070 .p_class = P_GLOBAL,
1071 .offset = GLOBAL_VAR(szAutoServices),
1076 .label = "lock dir",
1078 .p_class = P_GLOBAL,
1079 .offset = GLOBAL_VAR(szLockDir),
1084 .label = "lock directory",
1086 .p_class = P_GLOBAL,
1087 .offset = GLOBAL_VAR(szLockDir),
1092 .label = "state directory",
1094 .p_class = P_GLOBAL,
1095 .offset = GLOBAL_VAR(szStateDir),
1100 .label = "cache directory",
1102 .p_class = P_GLOBAL,
1103 .offset = GLOBAL_VAR(szCacheDir),
1108 .label = "pid directory",
1110 .p_class = P_GLOBAL,
1111 .offset = GLOBAL_VAR(szPidDir),
1117 .label = "socket address",
1119 .p_class = P_GLOBAL,
1120 .offset = GLOBAL_VAR(szSocketAddress),
1128 .offset = LOCAL_VAR(szCopy),
1129 .special = handle_copy,
1136 .offset = LOCAL_VAR(szInclude),
1137 .special = handle_include,
1142 .label = "available",
1145 .offset = LOCAL_VAR(bAvailable),
1153 .offset = LOCAL_VAR(volume),
1161 .offset = LOCAL_VAR(fstype),
1167 .label = "panic action",
1169 .p_class = P_GLOBAL,
1170 .offset = GLOBAL_VAR(panic_action),
1176 .label = "msdfs root",
1179 .offset = LOCAL_VAR(bMSDfsRoot),
1184 .label = "host msdfs",
1186 .p_class = P_GLOBAL,
1187 .offset = GLOBAL_VAR(bHostMSDfs),
1192 .label = "winbind separator",
1194 .p_class = P_GLOBAL,
1195 .offset = GLOBAL_VAR(szWinbindSeparator),
1200 .label = "winbindd socket directory",
1202 .p_class = P_GLOBAL,
1203 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1208 .label = "winbindd privileged socket directory",
1210 .p_class = P_GLOBAL,
1211 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1216 .label = "winbind sealed pipes",
1218 .p_class = P_GLOBAL,
1219 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1224 .label = "template shell",
1226 .p_class = P_GLOBAL,
1227 .offset = GLOBAL_VAR(szTemplateShell),
1232 .label = "template homedir",
1234 .p_class = P_GLOBAL,
1235 .offset = GLOBAL_VAR(szTemplateHomedir),
1240 .label = "idmap trusted only",
1242 .p_class = P_GLOBAL,
1243 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1249 .label = "ntp signd socket directory",
1251 .p_class = P_GLOBAL,
1252 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1257 .label = "rndc command",
1259 .p_class = P_GLOBAL,
1260 .offset = GLOBAL_VAR(szRNDCCommand),
1265 .label = "dns update command",
1267 .p_class = P_GLOBAL,
1268 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1273 .label = "spn update command",
1275 .p_class = P_GLOBAL,
1276 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1281 .label = "nsupdate command",
1283 .p_class = P_GLOBAL,
1284 .offset = GLOBAL_VAR(szNSUpdateCommand),
1289 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1293 /* local variables */
1294 struct loadparm_context {
1295 const char *szConfigFile;
1296 struct loadparm_global *globals;
1297 struct loadparm_service **services;
1298 struct loadparm_service *sDefault;
1299 struct smb_iconv_handle *iconv_handle;
1301 struct loadparm_service *currentService;
1302 bool bInGlobalSection;
1304 struct file_lists *next;
1309 unsigned int flags[NUMPARAMETERS];
1312 bool global; /* Is this the global context, which may set
1313 * global variables such as debug level etc? */
1314 const struct loadparm_s3_context *s3_fns;
1318 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1320 if (lp_ctx->s3_fns) {
1321 return lp_ctx->s3_fns->get_default_loadparm_service();
1323 return lp_ctx->sDefault;
1327 * Convenience routine to grab string parameters into temporary memory
1328 * and run standard_sub_basic on them.
1330 * The buffers can be written to by
1331 * callers without affecting the source string.
1334 static const char *lp_string(const char *s)
1336 #if 0 /* until REWRITE done to make thread-safe */
1337 size_t len = s ? strlen(s) : 0;
1341 /* The follow debug is useful for tracking down memory problems
1342 especially if you have an inner loop that is calling a lp_*()
1343 function that returns a string. Perhaps this debug should be
1344 present all the time? */
1347 DEBUG(10, ("lp_string(%s)\n", s));
1350 #if 0 /* until REWRITE done to make thread-safe */
1352 lp_talloc = talloc_init("lp_talloc");
1354 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1362 strlcpy(ret, s, len);
1364 if (trim_string(ret, "\"", "\"")) {
1365 if (strchr(ret,'"') != NULL)
1366 strlcpy(ret, s, len);
1369 standard_sub_basic(ret,len+100);
1376 In this section all the functions that are used to access the
1377 parameters from the rest of the program are defined
1381 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1382 * for code compatibility between existing Samba4 and Samba3 code.
1385 /* this global context supports the lp_*() function varients */
1386 static struct loadparm_context *global_loadparm_context;
1388 #define lpcfg_default_service global_loadparm_context->sDefault
1389 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1391 #define FN_GLOBAL_STRING(fn_name,var_name) \
1392 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1393 if (lp_ctx == NULL) return NULL; \
1394 if (lp_ctx->s3_fns) { \
1395 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1396 return lp_ctx->s3_fns->fn_name(); \
1398 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1401 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1402 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1403 if (lp_ctx == NULL) return NULL; \
1404 if (lp_ctx->s3_fns) { \
1405 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1406 return lp_ctx->s3_fns->fn_name(); \
1408 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1411 #define FN_GLOBAL_LIST(fn_name,var_name) \
1412 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1413 if (lp_ctx == NULL) return NULL; \
1414 if (lp_ctx->s3_fns) { \
1415 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1416 return lp_ctx->s3_fns->fn_name(); \
1418 return lp_ctx->globals->var_name; \
1421 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1422 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1423 if (lp_ctx == NULL) return false; \
1424 if (lp_ctx->s3_fns) { \
1425 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1426 return lp_ctx->s3_fns->fn_name(); \
1428 return lp_ctx->globals->var_name; \
1431 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1432 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1433 if (lp_ctx->s3_fns) { \
1434 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1435 return lp_ctx->s3_fns->fn_name(); \
1437 return lp_ctx->globals->var_name; \
1440 /* Local parameters don't need the ->s3_fns because the struct
1441 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1443 #define FN_LOCAL_STRING(fn_name,val) \
1444 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1445 struct loadparm_service *sDefault) { \
1446 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1449 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1451 #define FN_LOCAL_LIST(fn_name,val) \
1452 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1453 struct loadparm_service *sDefault) {\
1454 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1457 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1459 #define FN_LOCAL_BOOL(fn_name,val) \
1460 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1461 struct loadparm_service *sDefault) { \
1462 return((service != NULL)? service->val : sDefault->val); \
1465 #define FN_LOCAL_INTEGER(fn_name,val) \
1466 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1467 struct loadparm_service *sDefault) { \
1468 return((service != NULL)? service->val : sDefault->val); \
1471 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1473 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1475 #define FN_LOCAL_CHAR(fn_name,val) \
1476 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1477 struct loadparm_service *sDefault) { \
1478 return((service != NULL)? service->val : sDefault->val); \
1481 #include "lib/param/param_functions.c"
1483 FN_GLOBAL_INTEGER(server_role, server_role)
1484 FN_GLOBAL_LIST(smb_ports, smb_ports)
1485 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1486 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1487 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1488 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1489 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1490 FN_GLOBAL_INTEGER(web_port, web_port)
1491 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1492 FN_GLOBAL_STRING(logfile, logfile)
1493 FN_GLOBAL_STRING(share_backend, szShareBackend)
1494 FN_GLOBAL_STRING(spoolss_url, szSPOOLSS_URL)
1495 FN_GLOBAL_STRING(wins_config_url, szWINS_CONFIG_URL)
1496 FN_GLOBAL_STRING(wins_url, szWINS_URL)
1497 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1498 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1499 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1500 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1501 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1502 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1503 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1504 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1505 FN_GLOBAL_STRING(serverstring, szServerString)
1506 FN_GLOBAL_STRING(lockdir, szLockDir)
1507 FN_GLOBAL_STRING(statedir, szStateDir)
1508 FN_GLOBAL_STRING(cachedir, szCacheDir)
1509 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1510 FN_GLOBAL_STRING(dos_charset, dos_charset)
1511 FN_GLOBAL_STRING(unix_charset, unix_charset)
1512 FN_GLOBAL_STRING(piddir, szPidDir)
1513 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1514 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1515 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1516 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1517 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1518 FN_GLOBAL_LIST(server_services, server_services)
1519 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1520 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1521 FN_GLOBAL_STRING(auto_services, szAutoServices)
1522 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1523 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1524 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1525 FN_GLOBAL_STRING(realm, szRealm_upper)
1526 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1527 FN_GLOBAL_STRING(socket_options, socket_options)
1528 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1529 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1530 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1531 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1532 FN_GLOBAL_LIST(interfaces, szInterfaces)
1533 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1534 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1535 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1536 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1537 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1538 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1539 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1540 FN_GLOBAL_BOOL(readraw, bReadRaw)
1541 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1542 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1543 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1544 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1545 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1546 FN_GLOBAL_BOOL(time_server, bTimeServer)
1547 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1548 FN_GLOBAL_BOOL(unicode, bUnicode)
1549 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1550 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1551 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1552 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1553 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1554 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1555 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1556 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1557 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1558 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1559 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1560 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1561 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1562 FN_GLOBAL_INTEGER(maxmux, max_mux)
1563 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1564 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1565 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1566 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1567 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1568 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1569 FN_GLOBAL_INTEGER(security, security)
1570 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1572 FN_GLOBAL_INTEGER(server_signing, server_signing)
1573 FN_GLOBAL_INTEGER(client_signing, client_signing)
1575 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1577 /* local prototypes */
1578 static int map_parameter(const char *pszParmName);
1579 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1580 const char *pszServiceName);
1581 static void copy_service(struct loadparm_service *pserviceDest,
1582 struct loadparm_service *pserviceSource,
1583 struct bitmap *pcopymapDest);
1584 static bool service_ok(struct loadparm_service *service);
1585 static bool do_section(const char *pszSectionName, void *);
1586 static void init_copymap(struct loadparm_service *pservice);
1588 /* This is a helper function for parametrical options support. */
1589 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1590 /* Actual parametrical functions are quite simple */
1591 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1592 struct loadparm_service *service,
1593 const char *type, const char *option)
1595 char *vfskey_tmp = NULL;
1596 char *vfskey = NULL;
1597 struct parmlist_entry *data;
1602 if (lp_ctx->s3_fns) {
1603 return lp_ctx->s3_fns->get_parametric(service, type, option);
1606 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1608 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1609 if (vfskey_tmp == NULL) return NULL;
1610 vfskey = strlower_talloc(NULL, vfskey_tmp);
1611 talloc_free(vfskey_tmp);
1614 if (strcmp(data->key, vfskey) == 0) {
1615 talloc_free(vfskey);
1621 if (service != NULL) {
1622 /* Try to fetch the same option but from globals */
1623 /* but only if we are not already working with globals */
1624 for (data = lp_ctx->globals->param_opt; data;
1625 data = data->next) {
1626 if (strcmp(data->key, vfskey) == 0) {
1627 talloc_free(vfskey);
1633 talloc_free(vfskey);
1640 * convenience routine to return int parameters.
1642 static int lp_int(const char *s)
1646 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1650 return strtol(s, NULL, 0);
1654 * convenience routine to return unsigned long parameters.
1656 static int lp_ulong(const char *s)
1660 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1664 return strtoul(s, NULL, 0);
1668 * convenience routine to return unsigned long parameters.
1670 static double lp_double(const char *s)
1674 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1678 return strtod(s, NULL);
1682 * convenience routine to return boolean parameters.
1684 static bool lp_bool(const char *s)
1689 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1693 if (!set_boolean(s, &ret)) {
1694 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1703 * Return parametric option from a given service. Type is a part of option before ':'
1704 * Parametric option has following syntax: 'Type: option = value'
1705 * Returned value is allocated in 'lp_talloc' context
1708 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1709 struct loadparm_service *service, const char *type,
1712 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1715 return lp_string(value);
1721 * Return parametric option from a given service. Type is a part of option before ':'
1722 * Parametric option has following syntax: 'Type: option = value'
1723 * Returned value is allocated in 'lp_talloc' context
1726 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1727 struct loadparm_context *lp_ctx,
1728 struct loadparm_service *service,
1730 const char *option, const char *separator)
1732 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1735 return (const char **)str_list_make(mem_ctx, value, separator);
1741 * Return parametric option from a given service. Type is a part of option before ':'
1742 * Parametric option has following syntax: 'Type: option = value'
1745 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1746 struct loadparm_service *service, const char *type,
1747 const char *option, int default_v)
1749 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1752 return lp_int(value);
1758 * Return parametric option from a given service. Type is a part of
1759 * option before ':'.
1760 * Parametric option has following syntax: 'Type: option = value'.
1763 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1764 struct loadparm_service *service, const char *type,
1765 const char *option, int default_v)
1769 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1771 if (value && conv_str_size_error(value, &bval)) {
1772 if (bval <= INT_MAX) {
1781 * Return parametric option from a given service.
1782 * Type is a part of option before ':'
1783 * Parametric option has following syntax: 'Type: option = value'
1785 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1786 struct loadparm_service *service, const char *type,
1787 const char *option, unsigned long default_v)
1789 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1792 return lp_ulong(value);
1798 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1799 struct loadparm_service *service, const char *type,
1800 const char *option, double default_v)
1802 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1805 return lp_double(value);
1811 * Return parametric option from a given service. Type is a part of option before ':'
1812 * Parametric option has following syntax: 'Type: option = value'
1815 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1816 struct loadparm_service *service, const char *type,
1817 const char *option, bool default_v)
1819 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1822 return lp_bool(value);
1829 * Initialise a service to the defaults.
1832 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1834 struct loadparm_service *pservice =
1835 talloc_zero(mem_ctx, struct loadparm_service);
1836 copy_service(pservice, sDefault, NULL);
1841 * Set a string value, deallocating any existing space, and allocing the space
1844 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1851 *dest = talloc_strdup(mem_ctx, src);
1852 if ((*dest) == NULL) {
1853 DEBUG(0,("Out of memory in string_set\n"));
1861 * Set a string value, deallocating any existing space, and allocing the space
1864 static bool string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1871 *dest = strupper_talloc(mem_ctx, src);
1872 if ((*dest) == NULL) {
1873 DEBUG(0,("Out of memory in string_set_upper\n"));
1883 * Add a new service to the services array initialising it with the given
1887 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1888 const struct loadparm_service *pservice,
1892 struct loadparm_service tservice;
1893 int num_to_alloc = lp_ctx->iNumServices + 1;
1894 struct parmlist_entry *data, *pdata;
1896 if (pservice == NULL) {
1897 pservice = lp_ctx->sDefault;
1900 tservice = *pservice;
1902 /* it might already exist */
1904 struct loadparm_service *service = getservicebyname(lp_ctx,
1906 if (service != NULL) {
1907 /* Clean all parametric options for service */
1908 /* They will be added during parsing again */
1909 data = service->param_opt;
1915 service->param_opt = NULL;
1920 /* find an invalid one */
1921 for (i = 0; i < lp_ctx->iNumServices; i++)
1922 if (lp_ctx->services[i] == NULL)
1925 /* if not, then create one */
1926 if (i == lp_ctx->iNumServices) {
1927 struct loadparm_service **tsp;
1929 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1932 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1935 lp_ctx->services = tsp;
1936 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1939 lp_ctx->iNumServices++;
1942 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1943 if (lp_ctx->services[i] == NULL) {
1944 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1947 copy_service(lp_ctx->services[i], &tservice, NULL);
1949 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1950 return lp_ctx->services[i];
1954 * Add a new home service, with the specified home directory, defaults coming
1955 * from service ifrom.
1958 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1959 const char *pszHomename,
1960 struct loadparm_service *default_service,
1961 const char *user, const char *pszHomedir)
1963 struct loadparm_service *service;
1965 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1967 if (service == NULL)
1970 if (!(*(default_service->szPath))
1971 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1972 service->szPath = talloc_strdup(service, pszHomedir);
1974 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1977 if (!(*(service->comment))) {
1978 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1980 service->bAvailable = default_service->bAvailable;
1981 service->bBrowseable = default_service->bBrowseable;
1983 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1984 pszHomename, user, service->szPath));
1990 * Add a new printer service, with defaults coming from service iFrom.
1993 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1994 const char *pszPrintername,
1995 struct loadparm_service *default_service)
1997 const char *comment = "From Printcap";
1998 struct loadparm_service *service;
1999 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2001 if (service == NULL)
2004 /* note that we do NOT default the availability flag to True - */
2005 /* we take it from the default service passed. This allows all */
2006 /* dynamic printers to be disabled by disabling the [printers] */
2007 /* entry (if/when the 'available' keyword is implemented!). */
2009 /* the printer name is set to the service name. */
2010 string_set(service, &service->szPrintername, pszPrintername);
2011 string_set(service, &service->comment, comment);
2012 service->bBrowseable = default_service->bBrowseable;
2013 /* Printers cannot be read_only. */
2014 service->bRead_only = false;
2015 /* Printer services must be printable. */
2016 service->bPrint_ok = true;
2018 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2024 * Map a parameter's string representation to something we can use.
2025 * Returns False if the parameter string is not recognised, else TRUE.
2028 static int map_parameter(const char *pszParmName)
2032 if (*pszParmName == '-')
2035 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2036 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2039 /* Warn only if it isn't parametric option */
2040 if (strchr(pszParmName, ':') == NULL)
2041 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2042 /* We do return 'fail' for parametric options as well because they are
2043 stored in different storage
2050 return the parameter structure for a parameter
2052 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2056 if (lp_ctx->s3_fns) {
2057 return lp_ctx->s3_fns->get_parm_struct(name);
2060 parmnum = map_parameter(name);
2061 if (parmnum == -1) return NULL;
2062 return &parm_table[parmnum];
2066 return the parameter pointer for a parameter
2068 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2069 struct loadparm_service *service, struct parm_struct *parm)
2071 if (lp_ctx->s3_fns) {
2072 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2075 if (service == NULL) {
2076 if (parm->p_class == P_LOCAL)
2077 return ((char *)lp_ctx->sDefault)+parm->offset;
2078 else if (parm->p_class == P_GLOBAL)
2079 return ((char *)lp_ctx->globals)+parm->offset;
2082 return ((char *)service) + parm->offset;
2087 * Find a service by name. Otherwise works like get_service.
2090 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2091 const char *pszServiceName)
2095 if (lp_ctx->s3_fns) {
2096 return lp_ctx->s3_fns->get_service(pszServiceName);
2099 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2100 if (lp_ctx->services[iService] != NULL &&
2101 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2102 return lp_ctx->services[iService];
2109 * Copy a service structure to another.
2110 * If pcopymapDest is NULL then copy all fields
2113 static void copy_service(struct loadparm_service *pserviceDest,
2114 struct loadparm_service *pserviceSource,
2115 struct bitmap *pcopymapDest)
2118 bool bcopyall = (pcopymapDest == NULL);
2119 struct parmlist_entry *data, *pdata, *paramo;
2122 for (i = 0; parm_table[i].label; i++)
2123 if (parm_table[i].p_class == P_LOCAL &&
2124 (bcopyall || bitmap_query(pcopymapDest, i))) {
2126 ((char *)pserviceSource) + parm_table[i].offset;
2128 ((char *)pserviceDest) + parm_table[i].offset;
2130 switch (parm_table[i].type) {
2132 *(bool *)dest_ptr = *(bool *)src_ptr;
2138 *(int *)dest_ptr = *(int *)src_ptr;
2142 string_set(pserviceDest,
2148 string_set_upper(pserviceDest,
2153 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2154 *(const char ***)src_ptr);
2162 init_copymap(pserviceDest);
2163 if (pserviceSource->copymap)
2164 bitmap_copy(pserviceDest->copymap,
2165 pserviceSource->copymap);
2168 data = pserviceSource->param_opt;
2171 pdata = pserviceDest->param_opt;
2172 /* Traverse destination */
2174 /* If we already have same option, override it */
2175 if (strcmp(pdata->key, data->key) == 0) {
2176 talloc_free(pdata->value);
2177 pdata->value = talloc_reference(pdata,
2182 pdata = pdata->next;
2185 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2188 paramo->key = talloc_reference(paramo, data->key);
2189 paramo->value = talloc_reference(paramo, data->value);
2190 DLIST_ADD(pserviceDest->param_opt, paramo);
2197 * Check a service for consistency. Return False if the service is in any way
2198 * incomplete or faulty, else True.
2200 static bool service_ok(struct loadparm_service *service)
2205 if (service->szService[0] == '\0') {
2206 DEBUG(0, ("The following message indicates an internal error:\n"));
2207 DEBUG(0, ("No service name in service entry.\n"));
2211 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2212 /* I can't see why you'd want a non-printable printer service... */
2213 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2214 if (!service->bPrint_ok) {
2215 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2216 service->szService));
2217 service->bPrint_ok = true;
2219 /* [printers] service must also be non-browsable. */
2220 if (service->bBrowseable)
2221 service->bBrowseable = false;
2224 /* If a service is flagged unavailable, log the fact at level 0. */
2225 if (!service->bAvailable)
2226 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2227 service->szService));
2233 /*******************************************************************
2234 Keep a linked list of all config files so we know when one has changed
2235 it's date and needs to be reloaded.
2236 ********************************************************************/
2238 static void add_to_file_list(struct loadparm_context *lp_ctx,
2239 const char *fname, const char *subfname)
2241 struct file_lists *f = lp_ctx->file_lists;
2244 if (f->name && !strcmp(f->name, fname))
2250 f = talloc(lp_ctx, struct file_lists);
2253 f->next = lp_ctx->file_lists;
2254 f->name = talloc_strdup(f, fname);
2259 f->subfname = talloc_strdup(f, subfname);
2264 lp_ctx->file_lists = f;
2265 f->modtime = file_modtime(subfname);
2267 time_t t = file_modtime(subfname);
2273 /*******************************************************************
2274 Check if a config file has changed date.
2275 ********************************************************************/
2276 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2278 struct file_lists *f;
2279 DEBUG(6, ("lp_file_list_changed()\n"));
2281 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2285 n2 = standard_sub_basic(lp_ctx, f->name);
2287 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2288 f->name, n2, ctime(&f->modtime)));
2290 mod_time = file_modtime(n2);
2292 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2293 DEBUGADD(6, ("file %s modified: %s\n", n2,
2295 f->modtime = mod_time;
2296 talloc_free(f->subfname);
2297 f->subfname = talloc_strdup(f, n2);
2304 /***************************************************************************
2305 Handle the "realm" parameter
2306 ***************************************************************************/
2308 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2309 const char *pszParmValue, char **ptr)
2311 string_set(lp_ctx, ptr, pszParmValue);
2313 talloc_free(lp_ctx->globals->szRealm_upper);
2314 talloc_free(lp_ctx->globals->szRealm_lower);
2316 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2317 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2322 /***************************************************************************
2323 Handle the include operation.
2324 ***************************************************************************/
2326 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2327 const char *pszParmValue, char **ptr)
2329 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2331 add_to_file_list(lp_ctx, pszParmValue, fname);
2333 string_set(lp_ctx, ptr, fname);
2335 if (file_exist(fname))
2336 return pm_process(fname, do_section, do_parameter, lp_ctx);
2338 DEBUG(2, ("Can't find include file %s\n", fname));
2343 /***************************************************************************
2344 Handle the interpretation of the copy parameter.
2345 ***************************************************************************/
2347 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2348 const char *pszParmValue, char **ptr)
2351 struct loadparm_service *serviceTemp;
2353 string_set(lp_ctx, ptr, pszParmValue);
2357 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2359 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2360 if (serviceTemp == lp_ctx->currentService) {
2361 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2363 copy_service(lp_ctx->currentService,
2365 lp_ctx->currentService->copymap);
2369 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2377 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2378 const char *pszParmValue, char **ptr)
2381 string_set(lp_ctx, ptr, pszParmValue);
2382 if (lp_ctx->global) {
2383 return debug_parse_levels(pszParmValue);
2388 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2389 const char *pszParmValue, char **ptr)
2391 debug_set_logfile(pszParmValue);
2392 if (lp_ctx->global) {
2393 string_set(lp_ctx, ptr, pszParmValue);
2398 /***************************************************************************
2399 Initialise a copymap.
2400 ***************************************************************************/
2402 static void init_copymap(struct loadparm_service *pservice)
2406 TALLOC_FREE(pservice->copymap);
2408 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2409 if (!pservice->copymap)
2411 ("Couldn't allocate copymap!! (size %d)\n",
2412 (int)NUMPARAMETERS));
2414 for (i = 0; i < NUMPARAMETERS; i++)
2415 bitmap_set(pservice->copymap, i);
2419 * Process a parametric option
2421 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2422 struct loadparm_service *service,
2423 const char *pszParmName,
2424 const char *pszParmValue, int flags)
2426 struct parmlist_entry *paramo, *data;
2428 TALLOC_CTX *mem_ctx;
2430 while (isspace((unsigned char)*pszParmName)) {
2434 name = strlower_talloc(lp_ctx, pszParmName);
2435 if (!name) return false;
2437 if (service == NULL) {
2438 data = lp_ctx->globals->param_opt;
2439 mem_ctx = lp_ctx->globals;
2441 data = service->param_opt;
2445 /* Traverse destination */
2446 for (paramo=data; paramo; paramo=paramo->next) {
2447 /* If we already have the option set, override it unless
2448 it was a command line option and the new one isn't */
2449 if (strcmp(paramo->key, name) == 0) {
2450 if ((paramo->priority & FLAG_CMDLINE) &&
2451 !(flags & FLAG_CMDLINE)) {
2456 talloc_free(paramo->value);
2457 paramo->value = talloc_strdup(paramo, pszParmValue);
2458 paramo->priority = flags;
2464 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2467 paramo->key = talloc_strdup(paramo, name);
2468 paramo->value = talloc_strdup(paramo, pszParmValue);
2469 paramo->priority = flags;
2470 if (service == NULL) {
2471 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2473 DLIST_ADD(service->param_opt, paramo);
2481 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2482 const char *pszParmName, const char *pszParmValue,
2483 struct loadparm_context *lp_ctx, bool on_globals)
2486 /* if it is a special case then go ahead */
2487 if (parm_table[parmnum].special) {
2489 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2494 goto mark_non_default;
2497 /* now switch on the type of variable it is */
2498 switch (parm_table[parmnum].type)
2502 if (!set_boolean(pszParmValue, &b)) {
2503 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2506 *(bool *)parm_ptr = b;
2512 if (!set_boolean(pszParmValue, &b)) {
2513 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2516 *(bool *)parm_ptr = !b;
2521 *(int *)parm_ptr = atoi(pszParmValue);
2525 *(char *)parm_ptr = *pszParmValue;
2529 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2535 if (conv_str_size_error(pszParmValue, &val)) {
2536 if (val <= INT_MAX) {
2537 *(int *)parm_ptr = (int)val;
2542 DEBUG(0,("lp_do_parameter(%s): value is not "
2543 "a valid size specifier!\n", pszParmValue));
2548 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2549 pszParmValue, NULL);
2553 char **new_list = str_list_make(mem_ctx,
2554 pszParmValue, NULL);
2555 for (i=0; new_list[i]; i++) {
2556 if (new_list[i][0] == '+' && new_list[i][1] &&
2557 (!str_list_check(*(const char ***)parm_ptr,
2558 &new_list[i][1]))) {
2559 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2561 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2562 #if 0 /* This is commented out because we sometimes parse the list
2563 * twice, and so we can't assert on this */
2564 if (!str_list_check(*(const char ***)parm_ptr,
2566 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2567 pszParmName, pszParmValue, new_list[i],
2568 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2573 str_list_remove(*(const char ***)parm_ptr,
2577 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2578 pszParmName, pszParmValue));
2581 *(const char ***)parm_ptr = (const char **) new_list;
2588 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2592 string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2596 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2599 parm_table[parmnum].enum_list[i].name)) {
2601 parm_table[parmnum].
2606 if (!parm_table[parmnum].enum_list[i].name) {
2607 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2608 pszParmValue, pszParmName));
2615 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2616 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2617 /* we have to also unset FLAG_DEFAULT on aliases */
2618 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2619 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2621 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2622 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2629 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2630 const char *pszParmName, const char *pszParmValue)
2632 int parmnum = map_parameter(pszParmName);
2636 if (strchr(pszParmName, ':')) {
2637 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2639 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2643 /* if the flag has been set on the command line, then don't allow override,
2644 but don't report an error */
2645 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2649 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2651 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2652 pszParmName, pszParmValue, lp_ctx, true);
2655 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2656 struct loadparm_service *service,
2657 const char *pszParmName, const char *pszParmValue)
2661 int parmnum = map_parameter(pszParmName);
2664 if (strchr(pszParmName, ':')) {
2665 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2667 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2671 /* if the flag has been set on the command line, then don't allow override,
2672 but don't report an error */
2673 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2677 if (parm_table[parmnum].p_class == P_GLOBAL) {
2679 ("Global parameter %s found in service section!\n",
2683 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2685 if (!service->copymap)
2686 init_copymap(service);
2688 /* this handles the aliases - set the copymap for other
2689 * entries with the same data pointer */
2690 for (i = 0; parm_table[i].label; i++)
2691 if (parm_table[i].offset == parm_table[parmnum].offset &&
2692 parm_table[i].p_class == parm_table[parmnum].p_class)
2693 bitmap_clear(service->copymap, i);
2695 return set_variable(service, parmnum, parm_ptr, pszParmName,
2696 pszParmValue, lp_ctx, false);
2700 * Process a parameter.
2703 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2706 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2708 if (lp_ctx->bInGlobalSection)
2709 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2712 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2713 pszParmName, pszParmValue);
2717 variable argument do parameter
2719 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2720 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2721 const char *pszParmName, const char *fmt, ...)
2728 s = talloc_vasprintf(NULL, fmt, ap);
2730 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2737 set a parameter from the commandline - this is called from command line parameter
2738 parsing code. It sets the parameter then marks the parameter as unable to be modified
2739 by smb.conf processing
2741 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2742 const char *pszParmValue)
2747 if (lp_ctx->s3_fns) {
2748 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2751 parmnum = map_parameter(pszParmName);
2753 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2756 if (parmnum < 0 && strchr(pszParmName, ':')) {
2757 /* set a parametric option */
2758 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2759 pszParmValue, FLAG_CMDLINE);
2763 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2767 /* reset the CMDLINE flag in case this has been called before */
2768 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2770 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2774 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2776 /* we have to also set FLAG_CMDLINE on aliases */
2777 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2778 lp_ctx->flags[i] |= FLAG_CMDLINE;
2780 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2781 lp_ctx->flags[i] |= FLAG_CMDLINE;
2788 set a option from the commandline in 'a=b' format. Use to support --option
2790 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2808 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2814 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2817 * Print a parameter of the specified type.
2820 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2822 /* For the seperation of lists values that we print below */
2823 const char *list_sep = ", ";
2828 for (i = 0; p->enum_list[i].name; i++) {
2829 if (*(int *)ptr == p->enum_list[i].value) {
2831 p->enum_list[i].name);
2838 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2842 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2847 fprintf(f, "%d", *(int *)ptr);
2851 fprintf(f, "%c", *(char *)ptr);
2855 int val = *(int *)ptr;
2859 fprintf(f, "0%o", val);
2868 if ((char ***)ptr && *(char ***)ptr) {
2869 char **list = *(char ***)ptr;
2870 for (; *list; list++) {
2871 /* surround strings with whitespace in double quotes */
2872 if (*(list+1) == NULL) {
2873 /* last item, no extra separator */
2876 if ( strchr_m( *list, ' ' ) ) {
2877 fprintf(f, "\"%s\"%s", *list, list_sep);
2879 fprintf(f, "%s%s", *list, list_sep);
2887 if (*(char **)ptr) {
2888 fprintf(f, "%s", *(char **)ptr);
2897 * Check if two parameters are equal.
2900 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2905 return (*((bool *)ptr1) == *((bool *)ptr2));
2911 return (*((int *)ptr1) == *((int *)ptr2));
2914 return (*((char *)ptr1) == *((char *)ptr2));
2918 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2923 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2928 return (p1 == p2 || strequal(p1, p2));
2937 * Process a new section (service).
2939 * At this stage all sections are services.
2940 * Later we'll have special sections that permit server parameters to be set.
2941 * Returns True on success, False on failure.
2944 static bool do_section(const char *pszSectionName, void *userdata)
2946 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2948 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2949 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2952 /* if we've just struck a global section, note the fact. */
2953 lp_ctx->bInGlobalSection = isglobal;
2955 /* check for multiple global sections */
2956 if (lp_ctx->bInGlobalSection) {
2957 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2961 /* if we have a current service, tidy it up before moving on */
2964 if (lp_ctx->currentService != NULL)
2965 bRetval = service_ok(lp_ctx->currentService);
2967 /* if all is still well, move to the next record in the services array */
2969 /* We put this here to avoid an odd message order if messages are */
2970 /* issued by the post-processing of a previous section. */
2971 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2973 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2976 DEBUG(0, ("Failed to add a new service\n"));
2986 * Determine if a particular base parameter is currently set to the default value.
2989 static bool is_default(struct loadparm_service *sDefault, int i)
2991 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2992 if (!defaults_saved)
2994 switch (parm_table[i].type) {
2997 return str_list_equal((const char **)parm_table[i].def.lvalue,
2998 (const char **)def_ptr);
3001 return strequal(parm_table[i].def.svalue,
3005 return parm_table[i].def.bvalue ==
3012 return parm_table[i].def.ivalue ==
3019 *Display the contents of the global structure.
3022 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3026 struct parmlist_entry *data;
3028 fprintf(f, "# Global parameters\n[global]\n");
3030 for (i = 0; parm_table[i].label; i++)
3031 if (parm_table[i].p_class == P_GLOBAL &&
3032 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3033 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3035 fprintf(f, "\t%s = ", parm_table[i].label);
3036 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3039 if (lp_ctx->globals->param_opt != NULL) {
3040 for (data = lp_ctx->globals->param_opt; data;
3041 data = data->next) {
3042 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3045 fprintf(f, "\t%s = %s\n", data->key, data->value);
3052 * Display the contents of a single services record.
3055 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3056 unsigned int *flags)
3059 struct parmlist_entry *data;
3061 if (pService != sDefault)
3062 fprintf(f, "\n[%s]\n", pService->szService);
3064 for (i = 0; parm_table[i].label; i++) {
3065 if (parm_table[i].p_class == P_LOCAL &&
3066 (*parm_table[i].label != '-') &&
3067 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3069 if (pService == sDefault) {
3070 if (flags && (flags[i] & FLAG_DEFAULT)) {
3073 if (defaults_saved) {
3074 if (is_default(sDefault, i)) {
3079 if (equal_parameter(parm_table[i].type,
3080 ((char *)pService) +
3081 parm_table[i].offset,
3082 ((char *)sDefault) +
3083 parm_table[i].offset))
3087 fprintf(f, "\t%s = ", parm_table[i].label);
3088 print_parameter(&parm_table[i],
3089 ((char *)pService) + parm_table[i].offset, f);
3093 if (pService->param_opt != NULL) {
3094 for (data = pService->param_opt; data; data = data->next) {
3095 fprintf(f, "\t%s = %s\n", data->key, data->value);
3100 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3101 struct loadparm_service *service,
3102 const char *parm_name, FILE * f)
3104 struct parm_struct *parm;
3107 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3112 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3114 print_parameter(parm, ptr, f);
3120 * Return info about the next parameter in a service.
3121 * snum==-1 gives the globals.
3122 * Return NULL when out of parameters.
3126 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3130 /* do the globals */
3131 for (; parm_table[*i].label; (*i)++) {
3132 if ((*parm_table[*i].label == '-'))
3136 && (parm_table[*i].offset ==
3137 parm_table[(*i) - 1].offset)
3138 && (parm_table[*i].p_class ==
3139 parm_table[(*i) - 1].p_class))
3142 return &parm_table[(*i)++];
3145 struct loadparm_service *pService = lp_ctx->services[snum];
3147 for (; parm_table[*i].label; (*i)++) {
3148 if (parm_table[*i].p_class == P_LOCAL &&
3149 (*parm_table[*i].label != '-') &&
3151 (parm_table[*i].offset !=
3152 parm_table[(*i) - 1].offset)))
3154 if (allparameters ||
3155 !equal_parameter(parm_table[*i].type,
3156 ((char *)pService) +
3157 parm_table[*i].offset,
3158 ((char *)lp_ctx->sDefault) +
3159 parm_table[*i].offset))
3161 return &parm_table[(*i)++];
3172 * Auto-load some home services.
3174 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3182 * Unload unused services.
3185 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3186 struct smbsrv_connection *smb,
3187 bool (*snumused) (struct smbsrv_connection *, int))
3190 for (i = 0; i < lp_ctx->iNumServices; i++) {
3191 if (lp_ctx->services[i] == NULL)
3194 if (!snumused || !snumused(smb, i)) {
3195 talloc_free(lp_ctx->services[i]);
3196 lp_ctx->services[i] = NULL;
3202 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3204 struct parmlist_entry *data;
3206 if (lp_ctx->refuse_free) {
3207 /* someone is trying to free the
3208 global_loadparm_context.
3209 We can't allow that. */
3213 if (lp_ctx->globals->param_opt != NULL) {
3214 struct parmlist_entry *next;
3215 for (data = lp_ctx->globals->param_opt; data; data=next) {
3217 if (data->priority & FLAG_CMDLINE) continue;
3218 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3227 * Initialise the global parameter structure.
3229 * Note that most callers should use loadparm_init_global() instead
3231 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3235 struct loadparm_context *lp_ctx;
3236 struct parmlist_entry *parm;
3239 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3243 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3244 lp_ctx->bInGlobalSection = true;
3245 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3246 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3248 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3249 lp_ctx->sDefault->bAvailable = true;
3250 lp_ctx->sDefault->bBrowseable = true;
3251 lp_ctx->sDefault->bRead_only = true;
3252 lp_ctx->sDefault->bMap_archive = true;
3253 lp_ctx->sDefault->iStrictLocking = true;
3254 lp_ctx->sDefault->bOpLocks = true;
3255 lp_ctx->sDefault->iCreate_mask = 0744;
3256 lp_ctx->sDefault->iCreate_force_mode = 0000;
3257 lp_ctx->sDefault->iDir_mask = 0755;
3258 lp_ctx->sDefault->iDir_force_mode = 0000;
3260 DEBUG(3, ("Initialising global parameters\n"));
3262 for (i = 0; parm_table[i].label; i++) {
3263 if ((parm_table[i].type == P_STRING ||
3264 parm_table[i].type == P_USTRING) &&
3265 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3267 if (parm_table[i].p_class == P_LOCAL) {
3268 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3270 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3272 *r = talloc_strdup(lp_ctx, "");
3276 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3277 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3278 talloc_free(logfile);
3280 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3282 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3284 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3286 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
3288 /* options that can be set on the command line must be initialised via
3289 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3291 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3293 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3294 myname = get_myname(lp_ctx);
3295 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3296 talloc_free(myname);
3297 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3299 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3301 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3302 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3304 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3305 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3306 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3307 /* the winbind method for domain controllers is for both RODC
3308 auth forwarding and for trusted domains */
3309 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3310 lpcfg_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
3311 lpcfg_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
3312 lpcfg_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
3313 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3315 /* This hive should be dynamically generated by Samba using
3316 data from the sam, but for the moment leave it in a tdb to
3317 keep regedt32 from popping up an annoying dialog. */
3318 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3320 /* using UTF8 by default allows us to support all chars */
3321 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3323 /* Use codepage 850 as a default for the dos character set */
3324 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3327 * Allow the default PASSWD_CHAT to be overridden in local.h.
3329 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3331 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3332 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3333 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3334 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3335 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3337 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3338 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3339 "Samba %s", SAMBA_VERSION_STRING);
3341 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3343 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3344 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3345 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3346 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3347 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3348 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3349 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3350 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3351 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
3352 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3353 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3354 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3355 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3356 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3357 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3359 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3360 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3361 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3362 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3363 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3364 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3365 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3366 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3368 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3370 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3371 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3373 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3374 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3376 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3377 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3378 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3379 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3380 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3381 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3382 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3384 lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
3385 lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
3387 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3389 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3390 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3391 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3392 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3393 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3394 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3395 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3397 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3399 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3400 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3402 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3403 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3404 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3405 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3406 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3408 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3409 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3410 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3411 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3412 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3414 for (i = 0; parm_table[i].label; i++) {
3415 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3416 lp_ctx->flags[i] |= FLAG_DEFAULT;
3420 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3421 if (!(parm->priority & FLAG_CMDLINE)) {
3422 parm->priority |= FLAG_DEFAULT;
3430 * Initialise the global parameter structure.
3432 struct loadparm_context *loadparm_init_global(bool load_default)
3434 if (global_loadparm_context == NULL) {
3435 global_loadparm_context = loadparm_init(NULL);
3437 if (global_loadparm_context == NULL) {
3440 global_loadparm_context->global = true;
3441 if (load_default && !global_loadparm_context->loaded) {
3442 lpcfg_load_default(global_loadparm_context);
3444 global_loadparm_context->refuse_free = true;
3445 return global_loadparm_context;
3449 * Initialise the global parameter structure.
3451 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3452 const struct loadparm_s3_context *s3_fns)
3454 struct loadparm_context *loadparm_context = loadparm_init(mem_ctx);
3455 if (!loadparm_context) {
3458 loadparm_context->s3_fns = s3_fns;
3459 return loadparm_context;
3462 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3464 return lp_ctx->szConfigFile;
3467 const char *lp_default_path(void)
3469 if (getenv("SMB_CONF_PATH"))
3470 return getenv("SMB_CONF_PATH");
3472 return dyn_CONFIGFILE;
3476 * Update the internal state of a loadparm context after settings
3479 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3481 struct debug_settings settings;
3482 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3484 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3485 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3488 if (!lp_ctx->global) {
3492 panic_action = lp_ctx->globals->panic_action;
3494 reload_charcnv(lp_ctx);
3496 ZERO_STRUCT(settings);
3497 /* Add any more debug-related smb.conf parameters created in
3499 settings.timestamp_logs = true;
3500 debug_set_settings(&settings);
3502 /* FIXME: This is a bit of a hack, but we can't use a global, since
3503 * not everything that uses lp also uses the socket library */
3504 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3505 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3507 unsetenv("SOCKET_TESTNONBLOCK");
3513 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3517 path = lp_default_path();
3519 if (!file_exist(path)) {
3520 /* We allow the default smb.conf file to not exist,
3521 * basically the equivalent of an empty file. */
3522 return lpcfg_update(lp_ctx);
3525 return lpcfg_load(lp_ctx, path);
3529 * Load the services array from the services file.
3531 * Return True on success, False on failure.
3533 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3538 filename = talloc_strdup(lp_ctx, filename);
3540 lp_ctx->szConfigFile = filename;
3542 if (lp_ctx->s3_fns) {
3543 return lp_ctx->s3_fns->load(filename);
3546 lp_ctx->bInGlobalSection = true;
3547 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3548 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3550 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3552 /* We get sections first, so have to start 'behind' to make up */
3553 lp_ctx->currentService = NULL;
3554 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3556 /* finish up the last section */
3557 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3559 if (lp_ctx->currentService != NULL)
3560 bRetval = service_ok(lp_ctx->currentService);
3562 bRetval = bRetval && lpcfg_update(lp_ctx);
3564 /* we do this unconditionally, so that it happens even
3565 for a missing smb.conf */
3566 reload_charcnv(lp_ctx);
3568 if (bRetval == true) {
3569 /* set this up so that any child python tasks will
3570 find the right smb.conf */
3571 setenv("SMB_CONF_PATH", filename, 1);
3573 /* set the context used by the lp_*() function
3575 global_loadparm_context = lp_ctx;
3576 lp_ctx->loaded = true;
3583 * Return the max number of services.
3586 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3588 if (lp_ctx->s3_fns) {
3589 return lp_ctx->s3_fns->get_numservices();
3592 return lp_ctx->iNumServices;
3596 * Display the contents of the services array in human-readable form.
3599 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3604 if (lp_ctx->s3_fns) {
3605 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3609 defaults_saved = !show_defaults;
3611 dump_globals(lp_ctx, f, show_defaults);
3613 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3615 for (iService = 0; iService < maxtoprint; iService++)
3616 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3620 * Display the contents of one service in human-readable form.
3622 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3624 if (service != NULL) {
3625 if (service->szService[0] == '\0')
3627 dump_a_service(service, sDefault, f, NULL);
3631 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3634 if (lp_ctx->s3_fns) {
3635 return lp_ctx->s3_fns->get_servicebynum(snum);
3638 return lp_ctx->services[snum];
3641 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3642 const char *service_name)
3647 if (lp_ctx->s3_fns) {
3648 return lp_ctx->s3_fns->get_service(service_name);
3651 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3652 if (lp_ctx->services[iService] &&
3653 lp_ctx->services[iService]->szService) {
3655 * The substitution here is used to support %U is
3658 serviceName = standard_sub_basic(
3659 lp_ctx->services[iService],
3660 lp_ctx->services[iService]->szService);
3661 if (strequal(serviceName, service_name)) {
3662 talloc_free(serviceName);
3663 return lp_ctx->services[iService];
3665 talloc_free(serviceName);
3669 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3673 const char *lpcfg_servicename(const struct loadparm_service *service)
3675 return lp_string((const char *)service->szService);
3679 * A useful volume label function.
3681 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3684 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3685 service->volume : sDefault->volume));
3687 return lpcfg_servicename(service);
3692 * If we are PDC then prefer us as DMB
3694 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3697 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3698 service->szPrintername : sDefault->szPrintername));
3699 if (ret == NULL || (ret != NULL && *ret == '\0'))
3700 ret = lpcfg_servicename(service);
3707 * Return the max print jobs per queue.
3709 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3711 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3712 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3713 maxjobs = PRINT_MAX_JOBID - 1;
3718 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3720 if (lp_ctx == NULL) {
3721 return get_iconv_handle();
3723 return lp_ctx->iconv_handle;
3726 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3728 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3729 if (!lp_ctx->global) {
3733 if (old_ic == NULL) {
3734 old_ic = global_iconv_handle;
3736 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3737 global_iconv_handle = lp_ctx->iconv_handle;
3740 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3742 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3745 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3747 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3750 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3752 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3755 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3757 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3760 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3762 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3765 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3767 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3768 if (settings == NULL)
3770 SMB_ASSERT(lp_ctx != NULL);
3771 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3772 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");