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"
73 #include "../lib/param/param_structs.h"
75 #define standard_sub_basic talloc_strdup
77 static bool do_parameter(const char *, const char *, void *);
78 static bool defaults_saved = false;
80 #define LOADPARM_EXTRA_GLOBALS \
81 struct parmlist_entry *param_opt; \
92 #include "param_global.h"
94 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
97 /* prototypes for the special type handlers */
98 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
99 const char *pszParmValue, char **ptr);
100 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
101 const char *pszParmValue, char **ptr);
102 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
103 const char *pszParmValue, char **ptr);
104 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
105 const char *pszParmValue, char **ptr);
106 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
107 const char *pszParmValue, char **ptr);
109 static const struct enum_list enum_protocol[] = {
110 {PROTOCOL_SMB2, "SMB2"},
111 {PROTOCOL_NT1, "NT1"},
112 {PROTOCOL_LANMAN2, "LANMAN2"},
113 {PROTOCOL_LANMAN1, "LANMAN1"},
114 {PROTOCOL_CORE, "CORE"},
115 {PROTOCOL_COREPLUS, "COREPLUS"},
116 {PROTOCOL_COREPLUS, "CORE+"},
120 static const struct enum_list enum_security[] = {
121 {SEC_SHARE, "SHARE"},
127 static const struct enum_list enum_bool_auto[] = {
138 /* Client-side offline caching policy types */
141 CSC_POLICY_DOCUMENTS=1,
142 CSC_POLICY_PROGRAMS=2,
146 static const struct enum_list enum_csc_policy[] = {
147 {CSC_POLICY_MANUAL, "manual"},
148 {CSC_POLICY_DOCUMENTS, "documents"},
149 {CSC_POLICY_PROGRAMS, "programs"},
150 {CSC_POLICY_DISABLE, "disable"},
154 /* SMB signing types. */
155 static const struct enum_list enum_smb_signing_vals[] = {
156 {SMB_SIGNING_OFF, "No"},
157 {SMB_SIGNING_OFF, "False"},
158 {SMB_SIGNING_OFF, "0"},
159 {SMB_SIGNING_OFF, "Off"},
160 {SMB_SIGNING_OFF, "disabled"},
161 {SMB_SIGNING_SUPPORTED, "Yes"},
162 {SMB_SIGNING_SUPPORTED, "True"},
163 {SMB_SIGNING_SUPPORTED, "1"},
164 {SMB_SIGNING_SUPPORTED, "On"},
165 {SMB_SIGNING_SUPPORTED, "enabled"},
166 {SMB_SIGNING_REQUIRED, "required"},
167 {SMB_SIGNING_REQUIRED, "mandatory"},
168 {SMB_SIGNING_REQUIRED, "force"},
169 {SMB_SIGNING_REQUIRED, "forced"},
170 {SMB_SIGNING_REQUIRED, "enforced"},
171 {SMB_SIGNING_AUTO, "auto"},
175 static const struct enum_list enum_server_role[] = {
176 {ROLE_STANDALONE, "standalone"},
177 {ROLE_DOMAIN_MEMBER, "member server"},
178 {ROLE_DOMAIN_MEMBER, "member"},
179 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
180 {ROLE_DOMAIN_CONTROLLER, "dc"},
184 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
185 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
187 static struct parm_struct parm_table[] = {
189 .label = "server role",
192 .offset = GLOBAL_VAR(server_role),
194 .enum_list = enum_server_role
197 .label = "dos charset",
200 .offset = GLOBAL_VAR(dos_charset),
205 .label = "unix charset",
208 .offset = GLOBAL_VAR(unix_charset),
213 .label = "ncalrpc dir",
216 .offset = GLOBAL_VAR(ncalrpc_dir),
224 .offset = LOCAL_VAR(comment),
232 .offset = LOCAL_VAR(szPath),
237 .label = "directory",
240 .offset = LOCAL_VAR(szPath),
245 .label = "workgroup",
248 .offset = GLOBAL_VAR(szWorkgroup),
256 .offset = GLOBAL_VAR(szRealm),
257 .special = handle_realm,
261 .label = "netbios name",
264 .offset = GLOBAL_VAR(szNetbiosName),
269 .label = "netbios aliases",
272 .offset = GLOBAL_VAR(szNetbiosAliases),
277 .label = "netbios scope",
280 .offset = GLOBAL_VAR(szNetbiosScope),
285 .label = "server string",
288 .offset = GLOBAL_VAR(szServerString),
293 .label = "interfaces",
296 .offset = GLOBAL_VAR(szInterfaces),
301 .label = "bind interfaces only",
304 .offset = GLOBAL_VAR(bBindInterfacesOnly),
309 .label = "ntvfs handler",
312 .offset = LOCAL_VAR(ntvfs_handler),
317 .label = "ntptr providor",
320 .offset = GLOBAL_VAR(ntptr_providor),
325 .label = "dcerpc endpoint servers",
328 .offset = GLOBAL_VAR(dcerpc_ep_servers),
333 .label = "server services",
336 .offset = GLOBAL_VAR(server_services),
345 .offset = GLOBAL_VAR(security),
347 .enum_list = enum_security
350 .label = "encrypt passwords",
353 .offset = GLOBAL_VAR(bEncryptPasswords),
358 .label = "null passwords",
361 .offset = GLOBAL_VAR(bNullPasswords),
366 .label = "obey pam restrictions",
369 .offset = GLOBAL_VAR(bObeyPamRestrictions),
374 .label = "password server",
377 .offset = GLOBAL_VAR(szPasswordServers),
382 .label = "spoolss database",
385 .offset = GLOBAL_VAR(szSPOOLSS_URL),
390 .label = "wins config database",
393 .offset = GLOBAL_VAR(szWINS_CONFIG_URL),
398 .label = "wins database",
401 .offset = GLOBAL_VAR(szWINS_URL),
406 .label = "private dir",
409 .offset = GLOBAL_VAR(szPrivateDir),
414 .label = "passwd chat",
417 .offset = GLOBAL_VAR(szPasswdChat),
422 .label = "password level",
425 .offset = GLOBAL_VAR(pwordlevel),
430 .label = "lanman auth",
433 .offset = GLOBAL_VAR(bLanmanAuth),
438 .label = "ntlm auth",
441 .offset = GLOBAL_VAR(bNTLMAuth),
446 .label = "client NTLMv2 auth",
449 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
454 .label = "client lanman auth",
457 .offset = GLOBAL_VAR(bClientLanManAuth),
462 .label = "client plaintext auth",
465 .offset = GLOBAL_VAR(bClientPlaintextAuth),
470 .label = "client use spnego principal",
473 .offset = GLOBAL_VAR(client_use_spnego_principal),
479 .label = "read only",
482 .offset = LOCAL_VAR(bRead_only),
488 .label = "create mask",
491 .offset = LOCAL_VAR(iCreate_mask),
496 .label = "force create mode",
499 .offset = LOCAL_VAR(iCreate_force_mode),
504 .label = "directory mask",
507 .offset = LOCAL_VAR(iDir_mask),
512 .label = "force directory mode",
515 .offset = LOCAL_VAR(iDir_force_mode),
521 .label = "hosts allow",
524 .offset = LOCAL_VAR(szHostsallow),
529 .label = "hosts deny",
532 .offset = LOCAL_VAR(szHostsdeny),
538 .label = "log level",
541 .offset = GLOBAL_VAR(loglevel),
542 .special = handle_debuglevel,
546 .label = "debuglevel",
549 .offset = GLOBAL_VAR(loglevel),
550 .special = handle_debuglevel,
557 .offset = GLOBAL_VAR(logfile),
558 .special = handle_logfile,
563 .label = "smb ports",
566 .offset = GLOBAL_VAR(smb_ports),
574 .offset = GLOBAL_VAR(nbt_port),
579 .label = "dgram port",
582 .offset = GLOBAL_VAR(dgram_port),
587 .label = "cldap port",
590 .offset = GLOBAL_VAR(cldap_port),
595 .label = "krb5 port",
598 .offset = GLOBAL_VAR(krb5_port),
603 .label = "kpasswd port",
606 .offset = GLOBAL_VAR(kpasswd_port),
614 .offset = GLOBAL_VAR(web_port),
619 .label = "tls enabled",
622 .offset = GLOBAL_VAR(tls_enabled),
627 .label = "tls keyfile",
630 .offset = GLOBAL_VAR(tls_keyfile),
635 .label = "tls certfile",
638 .offset = GLOBAL_VAR(tls_certfile),
643 .label = "tls cafile",
646 .offset = GLOBAL_VAR(tls_cafile),
651 .label = "tls crlfile",
654 .offset = GLOBAL_VAR(tls_crlfile),
659 .label = "tls dh params file",
662 .offset = GLOBAL_VAR(tls_dhpfile),
667 .label = "large readwrite",
670 .offset = GLOBAL_VAR(bLargeReadwrite),
675 .label = "server max protocol",
678 .offset = GLOBAL_VAR(srv_maxprotocol),
680 .enum_list = enum_protocol
683 .label = "server min protocol",
686 .offset = GLOBAL_VAR(srv_minprotocol),
688 .enum_list = enum_protocol
691 .label = "client max protocol",
694 .offset = GLOBAL_VAR(cli_maxprotocol),
696 .enum_list = enum_protocol
699 .label = "client min protocol",
702 .offset = GLOBAL_VAR(cli_minprotocol),
704 .enum_list = enum_protocol
710 .offset = GLOBAL_VAR(bUnicode),
718 .offset = GLOBAL_VAR(bReadRaw),
723 .label = "write raw",
726 .offset = GLOBAL_VAR(bWriteRaw),
731 .label = "disable netbios",
734 .offset = GLOBAL_VAR(bDisableNetbios),
740 .label = "nt status support",
743 .offset = GLOBAL_VAR(bNTStatusSupport),
752 .offset = GLOBAL_VAR(max_mux),
760 .offset = GLOBAL_VAR(max_xmit),
766 .label = "name resolve order",
769 .offset = GLOBAL_VAR(szNameResolveOrder),
774 .label = "max wins ttl",
777 .offset = GLOBAL_VAR(max_wins_ttl),
782 .label = "min wins ttl",
785 .offset = GLOBAL_VAR(min_wins_ttl),
790 .label = "time server",
793 .offset = GLOBAL_VAR(bTimeServer),
798 .label = "unix extensions",
801 .offset = GLOBAL_VAR(bUnixExtensions),
806 .label = "use spnego",
809 .offset = GLOBAL_VAR(bUseSpnego),
814 .label = "server signing",
817 .offset = GLOBAL_VAR(server_signing),
819 .enum_list = enum_smb_signing_vals
822 .label = "client signing",
825 .offset = GLOBAL_VAR(client_signing),
827 .enum_list = enum_smb_signing_vals
830 .label = "rpc big endian",
833 .offset = GLOBAL_VAR(bRpcBigEndian),
839 .label = "max connections",
842 .offset = LOCAL_VAR(iMaxConnections),
847 .label = "paranoid server security",
850 .offset = GLOBAL_VAR(paranoid_server_security),
855 .label = "socket options",
858 .offset = GLOBAL_VAR(socket_options),
864 .label = "strict sync",
867 .offset = LOCAL_VAR(bStrictSync),
872 .label = "case insensitive filesystem",
875 .offset = LOCAL_VAR(bCIFileSystem),
881 .label = "max print jobs",
884 .offset = LOCAL_VAR(iMaxPrintJobs),
889 .label = "printable",
892 .offset = LOCAL_VAR(bPrint_ok),
900 .offset = LOCAL_VAR(bPrint_ok),
906 .label = "printer name",
909 .offset = LOCAL_VAR(szPrintername),
917 .offset = LOCAL_VAR(szPrintername),
923 .label = "map system",
926 .offset = LOCAL_VAR(bMap_system),
931 .label = "map hidden",
934 .offset = LOCAL_VAR(bMap_hidden),
939 .label = "map archive",
942 .offset = LOCAL_VAR(bMap_archive),
948 .label = "preferred master",
951 .offset = GLOBAL_VAR(bPreferredMaster),
953 .enum_list = enum_bool_auto
956 .label = "prefered master",
959 .offset = GLOBAL_VAR(bPreferredMaster),
961 .enum_list = enum_bool_auto
964 .label = "local master",
967 .offset = GLOBAL_VAR(bLocalMaster),
972 .label = "browseable",
975 .offset = LOCAL_VAR(bBrowseable),
980 .label = "browsable",
983 .offset = LOCAL_VAR(bBrowseable),
989 .label = "wins server",
992 .offset = GLOBAL_VAR(szWINSservers),
997 .label = "wins support",
1000 .offset = GLOBAL_VAR(bWINSsupport),
1005 .label = "dns proxy",
1007 .p_class = P_GLOBAL,
1008 .offset = GLOBAL_VAR(bWINSdnsProxy),
1013 .label = "wins hook",
1015 .p_class = P_GLOBAL,
1016 .offset = GLOBAL_VAR(szWINSHook),
1022 .label = "csc policy",
1025 .offset = LOCAL_VAR(iCSCPolicy),
1027 .enum_list = enum_csc_policy
1031 .label = "strict locking",
1034 .offset = LOCAL_VAR(bStrictLocking),
1042 .offset = LOCAL_VAR(bOplocks),
1048 .label = "share backend",
1050 .p_class = P_GLOBAL,
1051 .offset = GLOBAL_VAR(szShareBackend),
1058 .p_class = P_GLOBAL,
1059 .offset = GLOBAL_VAR(szAutoServices),
1064 .label = "auto services",
1066 .p_class = P_GLOBAL,
1067 .offset = GLOBAL_VAR(szAutoServices),
1072 .label = "lock dir",
1074 .p_class = P_GLOBAL,
1075 .offset = GLOBAL_VAR(szLockDir),
1080 .label = "lock directory",
1082 .p_class = P_GLOBAL,
1083 .offset = GLOBAL_VAR(szLockDir),
1088 .label = "pid directory",
1090 .p_class = P_GLOBAL,
1091 .offset = GLOBAL_VAR(szPidDir),
1097 .label = "socket address",
1099 .p_class = P_GLOBAL,
1100 .offset = GLOBAL_VAR(szSocketAddress),
1108 .offset = LOCAL_VAR(szCopy),
1109 .special = handle_copy,
1116 .offset = LOCAL_VAR(szInclude),
1117 .special = handle_include,
1122 .label = "available",
1125 .offset = LOCAL_VAR(bAvailable),
1133 .offset = LOCAL_VAR(volume),
1141 .offset = LOCAL_VAR(fstype),
1147 .label = "panic action",
1149 .p_class = P_GLOBAL,
1150 .offset = GLOBAL_VAR(panic_action),
1156 .label = "msdfs root",
1159 .offset = LOCAL_VAR(bMSDfsRoot),
1164 .label = "host msdfs",
1166 .p_class = P_GLOBAL,
1167 .offset = GLOBAL_VAR(bHostMSDfs),
1172 .label = "winbind separator",
1174 .p_class = P_GLOBAL,
1175 .offset = GLOBAL_VAR(szWinbindSeparator),
1180 .label = "winbindd socket directory",
1182 .p_class = P_GLOBAL,
1183 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1188 .label = "winbindd privileged socket directory",
1190 .p_class = P_GLOBAL,
1191 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1196 .label = "winbind sealed pipes",
1198 .p_class = P_GLOBAL,
1199 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1204 .label = "template shell",
1206 .p_class = P_GLOBAL,
1207 .offset = GLOBAL_VAR(szTemplateShell),
1212 .label = "template homedir",
1214 .p_class = P_GLOBAL,
1215 .offset = GLOBAL_VAR(szTemplateHomedir),
1220 .label = "idmap trusted only",
1222 .p_class = P_GLOBAL,
1223 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1229 .label = "ntp signd socket directory",
1231 .p_class = P_GLOBAL,
1232 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1237 .label = "rndc command",
1239 .p_class = P_GLOBAL,
1240 .offset = GLOBAL_VAR(szRNDCCommand),
1245 .label = "dns update command",
1247 .p_class = P_GLOBAL,
1248 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1253 .label = "spn update command",
1255 .p_class = P_GLOBAL,
1256 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1261 .label = "nsupdate command",
1263 .p_class = P_GLOBAL,
1264 .offset = GLOBAL_VAR(szNSUpdateCommand),
1269 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1273 /* local variables */
1274 struct loadparm_context {
1275 const char *szConfigFile;
1276 struct loadparm_global *globals;
1277 struct loadparm_service **services;
1278 struct loadparm_service *sDefault;
1279 struct smb_iconv_handle *iconv_handle;
1281 struct loadparm_service *currentService;
1282 bool bInGlobalSection;
1284 struct file_lists *next;
1289 unsigned int flags[NUMPARAMETERS];
1292 bool global; /* Is this the global context, which may set
1293 * global variables such as debug level etc? */
1294 const struct loadparm_s3_context *s3_fns;
1298 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1300 return lp_ctx->sDefault;
1304 * Convenience routine to grab string parameters into temporary memory
1305 * and run standard_sub_basic on them.
1307 * The buffers can be written to by
1308 * callers without affecting the source string.
1311 static const char *lp_string(const char *s)
1313 #if 0 /* until REWRITE done to make thread-safe */
1314 size_t len = s ? strlen(s) : 0;
1318 /* The follow debug is useful for tracking down memory problems
1319 especially if you have an inner loop that is calling a lp_*()
1320 function that returns a string. Perhaps this debug should be
1321 present all the time? */
1324 DEBUG(10, ("lp_string(%s)\n", s));
1327 #if 0 /* until REWRITE done to make thread-safe */
1329 lp_talloc = talloc_init("lp_talloc");
1331 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1339 strlcpy(ret, s, len);
1341 if (trim_string(ret, "\"", "\"")) {
1342 if (strchr(ret,'"') != NULL)
1343 strlcpy(ret, s, len);
1346 standard_sub_basic(ret,len+100);
1353 In this section all the functions that are used to access the
1354 parameters from the rest of the program are defined
1358 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1359 * for code compatibility between existing Samba4 and Samba3 code.
1362 /* this global context supports the lp_*() function varients */
1363 static struct loadparm_context *global_loadparm_context;
1365 #define lpcfg_default_service global_loadparm_context->sDefault
1366 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1368 #define FN_GLOBAL_STRING(fn_name,var_name) \
1369 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1370 if (lp_ctx == NULL) return NULL; \
1371 if (lp_ctx->s3_fns) { \
1372 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1373 return lp_ctx->s3_fns->fn_name(); \
1375 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1378 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1379 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1380 if (lp_ctx == NULL) return NULL; \
1381 if (lp_ctx->s3_fns) { \
1382 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1383 return lp_ctx->s3_fns->fn_name(); \
1385 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1388 #define FN_GLOBAL_LIST(fn_name,var_name) \
1389 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1390 if (lp_ctx == NULL) return NULL; \
1391 if (lp_ctx->s3_fns) { \
1392 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1393 return lp_ctx->s3_fns->fn_name(); \
1395 return lp_ctx->globals->var_name; \
1398 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1399 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1400 if (lp_ctx == NULL) return false; \
1401 if (lp_ctx->s3_fns) { \
1402 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1403 return lp_ctx->s3_fns->fn_name(); \
1405 return lp_ctx->globals->var_name; \
1408 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1409 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1410 if (lp_ctx->s3_fns) { \
1411 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1412 return lp_ctx->s3_fns->fn_name(); \
1414 return lp_ctx->globals->var_name; \
1417 #define FN_LOCAL_STRING(fn_name,val) \
1418 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1419 struct loadparm_service *sDefault) { \
1420 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1423 #define FN_LOCAL_LIST(fn_name,val) \
1424 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1425 struct loadparm_service *sDefault) {\
1426 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1429 #define FN_LOCAL_BOOL(fn_name,val) \
1430 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1431 struct loadparm_service *sDefault) { \
1432 return((service != NULL)? service->val : sDefault->val); \
1435 #define FN_LOCAL_INTEGER(fn_name,val) \
1436 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1437 struct loadparm_service *sDefault) { \
1438 return((service != NULL)? service->val : sDefault->val); \
1441 #include "lib/param/param_functions.c"
1443 FN_GLOBAL_INTEGER(server_role, server_role)
1444 FN_GLOBAL_LIST(smb_ports, smb_ports)
1445 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1446 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1447 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1448 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1449 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1450 FN_GLOBAL_INTEGER(web_port, web_port)
1451 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1452 FN_GLOBAL_STRING(logfile, logfile)
1453 FN_GLOBAL_STRING(share_backend, szShareBackend)
1454 FN_GLOBAL_STRING(spoolss_url, szSPOOLSS_URL)
1455 FN_GLOBAL_STRING(wins_config_url, szWINS_CONFIG_URL)
1456 FN_GLOBAL_STRING(wins_url, szWINS_URL)
1457 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1458 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1459 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1460 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1461 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1462 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1463 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1464 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1465 FN_GLOBAL_STRING(serverstring, szServerString)
1466 FN_GLOBAL_STRING(lockdir, szLockDir)
1467 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1468 FN_GLOBAL_STRING(dos_charset, dos_charset)
1469 FN_GLOBAL_STRING(unix_charset, unix_charset)
1470 FN_GLOBAL_STRING(piddir, szPidDir)
1471 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1472 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1473 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1474 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1475 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1476 FN_GLOBAL_LIST(server_services, server_services)
1477 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1478 FN_GLOBAL_STRING(auto_services, szAutoServices)
1479 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1480 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1481 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1482 FN_GLOBAL_STRING(realm, szRealm_upper)
1483 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1484 FN_GLOBAL_STRING(socket_options, socket_options)
1485 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1486 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1487 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1488 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1489 FN_GLOBAL_LIST(interfaces, szInterfaces)
1490 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1491 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1492 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1493 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1494 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1495 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1496 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1497 FN_GLOBAL_BOOL(readraw, bReadRaw)
1498 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1499 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1500 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1501 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1502 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1503 FN_GLOBAL_BOOL(time_server, bTimeServer)
1504 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1505 FN_GLOBAL_BOOL(unicode, bUnicode)
1506 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1507 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1508 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1509 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1510 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1511 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1512 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1513 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1514 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1515 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1516 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1517 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1518 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1519 FN_GLOBAL_INTEGER(maxmux, max_mux)
1520 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1521 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1522 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1523 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1524 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1525 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1526 FN_GLOBAL_INTEGER(security, security)
1527 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1529 FN_GLOBAL_INTEGER(server_signing, server_signing)
1530 FN_GLOBAL_INTEGER(client_signing, client_signing)
1532 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1534 /* local prototypes */
1535 static int map_parameter(const char *pszParmName);
1536 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1537 const char *pszServiceName);
1538 static void copy_service(struct loadparm_service *pserviceDest,
1539 struct loadparm_service *pserviceSource,
1540 struct bitmap *pcopymapDest);
1541 static bool service_ok(struct loadparm_service *service);
1542 static bool do_section(const char *pszSectionName, void *);
1543 static void init_copymap(struct loadparm_service *pservice);
1545 /* This is a helper function for parametrical options support. */
1546 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1547 /* Actual parametrical functions are quite simple */
1548 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1549 struct loadparm_service *service,
1550 const char *type, const char *option)
1552 char *vfskey_tmp = NULL;
1553 char *vfskey = NULL;
1554 struct parmlist_entry *data;
1559 if (lp_ctx->s3_fns) {
1560 return lp_ctx->s3_fns->get_parametric(service, type, option);
1563 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1565 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1566 if (vfskey_tmp == NULL) return NULL;
1567 vfskey = strlower_talloc(NULL, vfskey_tmp);
1568 talloc_free(vfskey_tmp);
1571 if (strcmp(data->key, vfskey) == 0) {
1572 talloc_free(vfskey);
1578 if (service != NULL) {
1579 /* Try to fetch the same option but from globals */
1580 /* but only if we are not already working with globals */
1581 for (data = lp_ctx->globals->param_opt; data;
1582 data = data->next) {
1583 if (strcmp(data->key, vfskey) == 0) {
1584 talloc_free(vfskey);
1590 talloc_free(vfskey);
1597 * convenience routine to return int parameters.
1599 static int lp_int(const char *s)
1603 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1607 return strtol(s, NULL, 0);
1611 * convenience routine to return unsigned long parameters.
1613 static int lp_ulong(const char *s)
1617 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1621 return strtoul(s, NULL, 0);
1625 * convenience routine to return unsigned long parameters.
1627 static double lp_double(const char *s)
1631 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1635 return strtod(s, NULL);
1639 * convenience routine to return boolean parameters.
1641 static bool lp_bool(const char *s)
1646 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1650 if (!set_boolean(s, &ret)) {
1651 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1660 * Return parametric option from a given service. Type is a part of option before ':'
1661 * Parametric option has following syntax: 'Type: option = value'
1662 * Returned value is allocated in 'lp_talloc' context
1665 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1666 struct loadparm_service *service, const char *type,
1669 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1672 return lp_string(value);
1678 * Return parametric option from a given service. Type is a part of option before ':'
1679 * Parametric option has following syntax: 'Type: option = value'
1680 * Returned value is allocated in 'lp_talloc' context
1683 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1684 struct loadparm_context *lp_ctx,
1685 struct loadparm_service *service,
1687 const char *option, const char *separator)
1689 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1692 return (const char **)str_list_make(mem_ctx, value, separator);
1698 * Return parametric option from a given service. Type is a part of option before ':'
1699 * Parametric option has following syntax: 'Type: option = value'
1702 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1703 struct loadparm_service *service, const char *type,
1704 const char *option, int default_v)
1706 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1709 return lp_int(value);
1715 * Return parametric option from a given service. Type is a part of
1716 * option before ':'.
1717 * Parametric option has following syntax: 'Type: option = value'.
1720 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1721 struct loadparm_service *service, const char *type,
1722 const char *option, int default_v)
1726 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1728 if (value && conv_str_size_error(value, &bval)) {
1729 if (bval <= INT_MAX) {
1738 * Return parametric option from a given service.
1739 * Type is a part of option before ':'
1740 * Parametric option has following syntax: 'Type: option = value'
1742 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1743 struct loadparm_service *service, const char *type,
1744 const char *option, unsigned long default_v)
1746 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1749 return lp_ulong(value);
1755 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1756 struct loadparm_service *service, const char *type,
1757 const char *option, double default_v)
1759 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1762 return lp_double(value);
1768 * Return parametric option from a given service. Type is a part of option before ':'
1769 * Parametric option has following syntax: 'Type: option = value'
1772 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1773 struct loadparm_service *service, const char *type,
1774 const char *option, bool default_v)
1776 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1779 return lp_bool(value);
1786 * Initialise a service to the defaults.
1789 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1791 struct loadparm_service *pservice =
1792 talloc_zero(mem_ctx, struct loadparm_service);
1793 copy_service(pservice, sDefault, NULL);
1798 * Set a string value, deallocating any existing space, and allocing the space
1801 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1808 *dest = talloc_strdup(mem_ctx, src);
1809 if ((*dest) == NULL) {
1810 DEBUG(0,("Out of memory in string_set\n"));
1818 * Set a string value, deallocating any existing space, and allocing the space
1821 static bool string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1828 *dest = strupper_talloc(mem_ctx, src);
1829 if ((*dest) == NULL) {
1830 DEBUG(0,("Out of memory in string_set_upper\n"));
1840 * Add a new service to the services array initialising it with the given
1844 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1845 const struct loadparm_service *pservice,
1849 struct loadparm_service tservice;
1850 int num_to_alloc = lp_ctx->iNumServices + 1;
1851 struct parmlist_entry *data, *pdata;
1853 if (pservice == NULL) {
1854 pservice = lp_ctx->sDefault;
1857 tservice = *pservice;
1859 /* it might already exist */
1861 struct loadparm_service *service = getservicebyname(lp_ctx,
1863 if (service != NULL) {
1864 /* Clean all parametric options for service */
1865 /* They will be added during parsing again */
1866 data = service->param_opt;
1872 service->param_opt = NULL;
1877 /* find an invalid one */
1878 for (i = 0; i < lp_ctx->iNumServices; i++)
1879 if (lp_ctx->services[i] == NULL)
1882 /* if not, then create one */
1883 if (i == lp_ctx->iNumServices) {
1884 struct loadparm_service **tsp;
1886 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1889 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1892 lp_ctx->services = tsp;
1893 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1896 lp_ctx->iNumServices++;
1899 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1900 if (lp_ctx->services[i] == NULL) {
1901 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1904 copy_service(lp_ctx->services[i], &tservice, NULL);
1906 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1907 return lp_ctx->services[i];
1911 * Add a new home service, with the specified home directory, defaults coming
1912 * from service ifrom.
1915 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1916 const char *pszHomename,
1917 struct loadparm_service *default_service,
1918 const char *user, const char *pszHomedir)
1920 struct loadparm_service *service;
1922 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1924 if (service == NULL)
1927 if (!(*(default_service->szPath))
1928 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1929 service->szPath = talloc_strdup(service, pszHomedir);
1931 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1934 if (!(*(service->comment))) {
1935 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1937 service->bAvailable = default_service->bAvailable;
1938 service->bBrowseable = default_service->bBrowseable;
1940 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1941 pszHomename, user, service->szPath));
1947 * Add a new printer service, with defaults coming from service iFrom.
1950 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1951 const char *pszPrintername,
1952 struct loadparm_service *default_service)
1954 const char *comment = "From Printcap";
1955 struct loadparm_service *service;
1956 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1958 if (service == NULL)
1961 /* note that we do NOT default the availability flag to True - */
1962 /* we take it from the default service passed. This allows all */
1963 /* dynamic printers to be disabled by disabling the [printers] */
1964 /* entry (if/when the 'available' keyword is implemented!). */
1966 /* the printer name is set to the service name. */
1967 string_set(service, &service->szPrintername, pszPrintername);
1968 string_set(service, &service->comment, comment);
1969 service->bBrowseable = default_service->bBrowseable;
1970 /* Printers cannot be read_only. */
1971 service->bRead_only = false;
1972 /* Printer services must be printable. */
1973 service->bPrint_ok = true;
1975 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1981 * Map a parameter's string representation to something we can use.
1982 * Returns False if the parameter string is not recognised, else TRUE.
1985 static int map_parameter(const char *pszParmName)
1989 if (*pszParmName == '-')
1992 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1993 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1996 /* Warn only if it isn't parametric option */
1997 if (strchr(pszParmName, ':') == NULL)
1998 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1999 /* We do return 'fail' for parametric options as well because they are
2000 stored in different storage
2007 return the parameter structure for a parameter
2009 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2013 if (lp_ctx->s3_fns) {
2014 return lp_ctx->s3_fns->get_parm_struct(name);
2017 parmnum = map_parameter(name);
2018 if (parmnum == -1) return NULL;
2019 return &parm_table[parmnum];
2023 return the parameter pointer for a parameter
2025 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2026 struct loadparm_service *service, struct parm_struct *parm)
2028 if (lp_ctx->s3_fns) {
2029 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2032 if (service == NULL) {
2033 if (parm->p_class == P_LOCAL)
2034 return ((char *)lp_ctx->sDefault)+parm->offset;
2035 else if (parm->p_class == P_GLOBAL)
2036 return ((char *)lp_ctx->globals)+parm->offset;
2039 return ((char *)service) + parm->offset;
2044 * Find a service by name. Otherwise works like get_service.
2047 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2048 const char *pszServiceName)
2052 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2053 if (lp_ctx->services[iService] != NULL &&
2054 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2055 return lp_ctx->services[iService];
2062 * Copy a service structure to another.
2063 * If pcopymapDest is NULL then copy all fields
2066 static void copy_service(struct loadparm_service *pserviceDest,
2067 struct loadparm_service *pserviceSource,
2068 struct bitmap *pcopymapDest)
2071 bool bcopyall = (pcopymapDest == NULL);
2072 struct parmlist_entry *data, *pdata, *paramo;
2075 for (i = 0; parm_table[i].label; i++)
2076 if (parm_table[i].p_class == P_LOCAL &&
2077 (bcopyall || bitmap_query(pcopymapDest, i))) {
2079 ((char *)pserviceSource) + parm_table[i].offset;
2081 ((char *)pserviceDest) + parm_table[i].offset;
2083 switch (parm_table[i].type) {
2085 *(int *)dest_ptr = *(int *)src_ptr;
2091 *(int *)dest_ptr = *(int *)src_ptr;
2095 string_set(pserviceDest,
2101 string_set_upper(pserviceDest,
2106 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2107 *(const char ***)src_ptr);
2115 init_copymap(pserviceDest);
2116 if (pserviceSource->copymap)
2117 bitmap_copy(pserviceDest->copymap,
2118 pserviceSource->copymap);
2121 data = pserviceSource->param_opt;
2124 pdata = pserviceDest->param_opt;
2125 /* Traverse destination */
2127 /* If we already have same option, override it */
2128 if (strcmp(pdata->key, data->key) == 0) {
2129 talloc_free(pdata->value);
2130 pdata->value = talloc_reference(pdata,
2135 pdata = pdata->next;
2138 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2141 paramo->key = talloc_reference(paramo, data->key);
2142 paramo->value = talloc_reference(paramo, data->value);
2143 DLIST_ADD(pserviceDest->param_opt, paramo);
2150 * Check a service for consistency. Return False if the service is in any way
2151 * incomplete or faulty, else True.
2153 static bool service_ok(struct loadparm_service *service)
2158 if (service->szService[0] == '\0') {
2159 DEBUG(0, ("The following message indicates an internal error:\n"));
2160 DEBUG(0, ("No service name in service entry.\n"));
2164 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2165 /* I can't see why you'd want a non-printable printer service... */
2166 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2167 if (!service->bPrint_ok) {
2168 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2169 service->szService));
2170 service->bPrint_ok = true;
2172 /* [printers] service must also be non-browsable. */
2173 if (service->bBrowseable)
2174 service->bBrowseable = false;
2177 /* If a service is flagged unavailable, log the fact at level 0. */
2178 if (!service->bAvailable)
2179 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2180 service->szService));
2186 /*******************************************************************
2187 Keep a linked list of all config files so we know when one has changed
2188 it's date and needs to be reloaded.
2189 ********************************************************************/
2191 static void add_to_file_list(struct loadparm_context *lp_ctx,
2192 const char *fname, const char *subfname)
2194 struct file_lists *f = lp_ctx->file_lists;
2197 if (f->name && !strcmp(f->name, fname))
2203 f = talloc(lp_ctx, struct file_lists);
2206 f->next = lp_ctx->file_lists;
2207 f->name = talloc_strdup(f, fname);
2212 f->subfname = talloc_strdup(f, subfname);
2217 lp_ctx->file_lists = f;
2218 f->modtime = file_modtime(subfname);
2220 time_t t = file_modtime(subfname);
2226 /*******************************************************************
2227 Check if a config file has changed date.
2228 ********************************************************************/
2229 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2231 struct file_lists *f;
2232 DEBUG(6, ("lp_file_list_changed()\n"));
2234 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2238 n2 = standard_sub_basic(lp_ctx, f->name);
2240 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2241 f->name, n2, ctime(&f->modtime)));
2243 mod_time = file_modtime(n2);
2245 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2246 DEBUGADD(6, ("file %s modified: %s\n", n2,
2248 f->modtime = mod_time;
2249 talloc_free(f->subfname);
2250 f->subfname = talloc_strdup(f, n2);
2257 /***************************************************************************
2258 Handle the "realm" parameter
2259 ***************************************************************************/
2261 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2262 const char *pszParmValue, char **ptr)
2264 string_set(lp_ctx, ptr, pszParmValue);
2266 talloc_free(lp_ctx->globals->szRealm_upper);
2267 talloc_free(lp_ctx->globals->szRealm_lower);
2269 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2270 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2275 /***************************************************************************
2276 Handle the include operation.
2277 ***************************************************************************/
2279 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2280 const char *pszParmValue, char **ptr)
2282 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2284 add_to_file_list(lp_ctx, pszParmValue, fname);
2286 string_set(lp_ctx, ptr, fname);
2288 if (file_exist(fname))
2289 return pm_process(fname, do_section, do_parameter, lp_ctx);
2291 DEBUG(2, ("Can't find include file %s\n", fname));
2296 /***************************************************************************
2297 Handle the interpretation of the copy parameter.
2298 ***************************************************************************/
2300 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2301 const char *pszParmValue, char **ptr)
2304 struct loadparm_service *serviceTemp;
2306 string_set(lp_ctx, ptr, pszParmValue);
2310 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2312 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2313 if (serviceTemp == lp_ctx->currentService) {
2314 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2316 copy_service(lp_ctx->currentService,
2318 lp_ctx->currentService->copymap);
2322 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2330 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2331 const char *pszParmValue, char **ptr)
2334 string_set(lp_ctx, ptr, pszParmValue);
2335 if (lp_ctx->global) {
2336 return debug_parse_levels(pszParmValue);
2341 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2342 const char *pszParmValue, char **ptr)
2344 debug_set_logfile(pszParmValue);
2345 if (lp_ctx->global) {
2346 string_set(lp_ctx, ptr, pszParmValue);
2351 /***************************************************************************
2352 Initialise a copymap.
2353 ***************************************************************************/
2355 static void init_copymap(struct loadparm_service *pservice)
2359 TALLOC_FREE(pservice->copymap);
2361 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2362 if (!pservice->copymap)
2364 ("Couldn't allocate copymap!! (size %d)\n",
2365 (int)NUMPARAMETERS));
2367 for (i = 0; i < NUMPARAMETERS; i++)
2368 bitmap_set(pservice->copymap, i);
2372 * Process a parametric option
2374 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2375 struct loadparm_service *service,
2376 const char *pszParmName,
2377 const char *pszParmValue, int flags)
2379 struct parmlist_entry *paramo, *data;
2381 TALLOC_CTX *mem_ctx;
2383 while (isspace((unsigned char)*pszParmName)) {
2387 name = strlower_talloc(lp_ctx, pszParmName);
2388 if (!name) return false;
2390 if (service == NULL) {
2391 data = lp_ctx->globals->param_opt;
2392 mem_ctx = lp_ctx->globals;
2394 data = service->param_opt;
2398 /* Traverse destination */
2399 for (paramo=data; paramo; paramo=paramo->next) {
2400 /* If we already have the option set, override it unless
2401 it was a command line option and the new one isn't */
2402 if (strcmp(paramo->key, name) == 0) {
2403 if ((paramo->priority & FLAG_CMDLINE) &&
2404 !(flags & FLAG_CMDLINE)) {
2409 talloc_free(paramo->value);
2410 paramo->value = talloc_strdup(paramo, pszParmValue);
2411 paramo->priority = flags;
2417 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2420 paramo->key = talloc_strdup(paramo, name);
2421 paramo->value = talloc_strdup(paramo, pszParmValue);
2422 paramo->priority = flags;
2423 if (service == NULL) {
2424 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2426 DLIST_ADD(service->param_opt, paramo);
2434 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2435 const char *pszParmName, const char *pszParmValue,
2436 struct loadparm_context *lp_ctx, bool on_globals)
2439 /* if it is a special case then go ahead */
2440 if (parm_table[parmnum].special) {
2442 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2447 goto mark_non_default;
2450 /* now switch on the type of variable it is */
2451 switch (parm_table[parmnum].type)
2455 if (!set_boolean(pszParmValue, &b)) {
2456 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2459 *(int *)parm_ptr = b;
2465 if (!set_boolean(pszParmValue, &b)) {
2466 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2469 *(int *)parm_ptr = !b;
2474 *(int *)parm_ptr = atoi(pszParmValue);
2478 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2484 if (conv_str_size_error(pszParmValue, &val)) {
2485 if (val <= INT_MAX) {
2486 *(int *)parm_ptr = (int)val;
2491 DEBUG(0,("lp_do_parameter(%s): value is not "
2492 "a valid size specifier!\n", pszParmValue));
2497 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2498 pszParmValue, NULL);
2502 char **new_list = str_list_make(mem_ctx,
2503 pszParmValue, NULL);
2504 for (i=0; new_list[i]; i++) {
2505 if (new_list[i][0] == '+' && new_list[i][1] &&
2506 (!str_list_check(*(const char ***)parm_ptr,
2507 &new_list[i][1]))) {
2508 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2510 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2511 #if 0 /* This is commented out because we sometimes parse the list
2512 * twice, and so we can't assert on this */
2513 if (!str_list_check(*(const char ***)parm_ptr,
2515 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2516 pszParmName, pszParmValue, new_list[i],
2517 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2522 str_list_remove(*(const char ***)parm_ptr,
2526 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2527 pszParmName, pszParmValue));
2530 *(const char ***)parm_ptr = (const char **) new_list;
2537 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2541 string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2545 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2548 parm_table[parmnum].enum_list[i].name)) {
2550 parm_table[parmnum].
2555 if (!parm_table[parmnum].enum_list[i].name) {
2556 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2557 pszParmValue, pszParmName));
2564 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2565 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2566 /* we have to also unset FLAG_DEFAULT on aliases */
2567 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2568 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2570 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2571 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2578 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2579 const char *pszParmName, const char *pszParmValue)
2581 int parmnum = map_parameter(pszParmName);
2585 if (strchr(pszParmName, ':')) {
2586 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2588 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2592 /* if the flag has been set on the command line, then don't allow override,
2593 but don't report an error */
2594 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2598 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2600 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2601 pszParmName, pszParmValue, lp_ctx, true);
2604 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2605 struct loadparm_service *service,
2606 const char *pszParmName, const char *pszParmValue)
2610 int parmnum = map_parameter(pszParmName);
2613 if (strchr(pszParmName, ':')) {
2614 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2616 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2620 /* if the flag has been set on the command line, then don't allow override,
2621 but don't report an error */
2622 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2626 if (parm_table[parmnum].p_class == P_GLOBAL) {
2628 ("Global parameter %s found in service section!\n",
2632 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2634 if (!service->copymap)
2635 init_copymap(service);
2637 /* this handles the aliases - set the copymap for other
2638 * entries with the same data pointer */
2639 for (i = 0; parm_table[i].label; i++)
2640 if (parm_table[i].offset == parm_table[parmnum].offset &&
2641 parm_table[i].p_class == parm_table[parmnum].p_class)
2642 bitmap_clear(service->copymap, i);
2644 return set_variable(service, parmnum, parm_ptr, pszParmName,
2645 pszParmValue, lp_ctx, false);
2649 * Process a parameter.
2652 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2655 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2657 if (lp_ctx->bInGlobalSection)
2658 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2661 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2662 pszParmName, pszParmValue);
2666 variable argument do parameter
2668 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2669 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2670 const char *pszParmName, const char *fmt, ...)
2677 s = talloc_vasprintf(NULL, fmt, ap);
2679 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2686 set a parameter from the commandline - this is called from command line parameter
2687 parsing code. It sets the parameter then marks the parameter as unable to be modified
2688 by smb.conf processing
2690 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2691 const char *pszParmValue)
2693 int parmnum = map_parameter(pszParmName);
2696 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2699 if (parmnum < 0 && strchr(pszParmName, ':')) {
2700 /* set a parametric option */
2701 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2702 pszParmValue, FLAG_CMDLINE);
2706 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2710 /* reset the CMDLINE flag in case this has been called before */
2711 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2713 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2717 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2719 /* we have to also set FLAG_CMDLINE on aliases */
2720 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2721 lp_ctx->flags[i] |= FLAG_CMDLINE;
2723 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2724 lp_ctx->flags[i] |= FLAG_CMDLINE;
2731 set a option from the commandline in 'a=b' format. Use to support --option
2733 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2751 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2757 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2760 * Print a parameter of the specified type.
2763 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2766 const char *list_sep = ", "; /* For the seperation of lists values that we print below */
2770 for (i = 0; p->enum_list[i].name; i++) {
2771 if (*(int *)ptr == p->enum_list[i].value) {
2773 p->enum_list[i].name);
2780 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
2784 fprintf(f, "%s", BOOLSTR(!(bool)*(int *)ptr));
2789 fprintf(f, "%d", *(int *)ptr);
2793 fprintf(f, "0%o", *(int *)ptr);
2800 if ((char ***)ptr && *(char ***)ptr) {
2801 char **list = *(char ***)ptr;
2803 for (; *list; list++) {
2804 if (*(list+1) == NULL) {
2805 /* last item, print no extra seperator after */
2808 fprintf(f, "%s%s", *list, list_sep);
2815 if (*(char **)ptr) {
2816 fprintf(f, "%s", *(char **)ptr);
2823 * Check if two parameters are equal.
2826 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2831 return (*((int *)ptr1) == *((int *)ptr2));
2837 return (*((int *)ptr1) == *((int *)ptr2));
2841 return str_list_equal((const char **)(*(char ***)ptr1),
2842 (const char **)(*(char ***)ptr2));
2847 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2852 return (p1 == p2 || strequal(p1, p2));
2859 * Process a new section (service).
2861 * At this stage all sections are services.
2862 * Later we'll have special sections that permit server parameters to be set.
2863 * Returns True on success, False on failure.
2866 static bool do_section(const char *pszSectionName, void *userdata)
2868 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2870 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2871 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2874 /* if we've just struck a global section, note the fact. */
2875 lp_ctx->bInGlobalSection = isglobal;
2877 /* check for multiple global sections */
2878 if (lp_ctx->bInGlobalSection) {
2879 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2883 /* if we have a current service, tidy it up before moving on */
2886 if (lp_ctx->currentService != NULL)
2887 bRetval = service_ok(lp_ctx->currentService);
2889 /* if all is still well, move to the next record in the services array */
2891 /* We put this here to avoid an odd message order if messages are */
2892 /* issued by the post-processing of a previous section. */
2893 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2895 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2898 DEBUG(0, ("Failed to add a new service\n"));
2908 * Determine if a particular base parameter is currently set to the default value.
2911 static bool is_default(struct loadparm_service *sDefault, int i)
2913 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2914 if (!defaults_saved)
2916 switch (parm_table[i].type) {
2919 return str_list_equal((const char **)parm_table[i].def.lvalue,
2920 (const char **)def_ptr);
2923 return strequal(parm_table[i].def.svalue,
2927 return parm_table[i].def.bvalue ==
2933 return parm_table[i].def.ivalue ==
2940 *Display the contents of the global structure.
2943 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2947 struct parmlist_entry *data;
2949 fprintf(f, "# Global parameters\n[global]\n");
2951 for (i = 0; parm_table[i].label; i++)
2952 if (parm_table[i].p_class == P_GLOBAL &&
2953 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2954 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2956 fprintf(f, "\t%s = ", parm_table[i].label);
2957 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2960 if (lp_ctx->globals->param_opt != NULL) {
2961 for (data = lp_ctx->globals->param_opt; data;
2962 data = data->next) {
2963 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2966 fprintf(f, "\t%s = %s\n", data->key, data->value);
2973 * Display the contents of a single services record.
2976 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2977 unsigned int *flags)
2980 struct parmlist_entry *data;
2982 if (pService != sDefault)
2983 fprintf(f, "\n[%s]\n", pService->szService);
2985 for (i = 0; parm_table[i].label; i++) {
2986 if (parm_table[i].p_class == P_LOCAL &&
2987 (*parm_table[i].label != '-') &&
2988 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
2990 if (pService == sDefault) {
2991 if (flags && (flags[i] & FLAG_DEFAULT)) {
2994 if (defaults_saved) {
2995 if (is_default(sDefault, i)) {
3000 if (equal_parameter(parm_table[i].type,
3001 ((char *)pService) +
3002 parm_table[i].offset,
3003 ((char *)sDefault) +
3004 parm_table[i].offset))
3008 fprintf(f, "\t%s = ", parm_table[i].label);
3009 print_parameter(&parm_table[i],
3010 ((char *)pService) + parm_table[i].offset, f);
3014 if (pService->param_opt != NULL) {
3015 for (data = pService->param_opt; data; data = data->next) {
3016 fprintf(f, "\t%s = %s\n", data->key, data->value);
3021 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3022 struct loadparm_service *service,
3023 const char *parm_name, FILE * f)
3025 struct parm_struct *parm;
3028 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3033 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3035 print_parameter(parm, ptr, f);
3041 * Return info about the next parameter in a service.
3042 * snum==-1 gives the globals.
3043 * Return NULL when out of parameters.
3047 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3051 /* do the globals */
3052 for (; parm_table[*i].label; (*i)++) {
3053 if ((*parm_table[*i].label == '-'))
3057 && (parm_table[*i].offset ==
3058 parm_table[(*i) - 1].offset)
3059 && (parm_table[*i].p_class ==
3060 parm_table[(*i) - 1].p_class))
3063 return &parm_table[(*i)++];
3066 struct loadparm_service *pService = lp_ctx->services[snum];
3068 for (; parm_table[*i].label; (*i)++) {
3069 if (parm_table[*i].p_class == P_LOCAL &&
3070 (*parm_table[*i].label != '-') &&
3072 (parm_table[*i].offset !=
3073 parm_table[(*i) - 1].offset)))
3075 if (allparameters ||
3076 !equal_parameter(parm_table[*i].type,
3077 ((char *)pService) +
3078 parm_table[*i].offset,
3079 ((char *)lp_ctx->sDefault) +
3080 parm_table[*i].offset))
3082 return &parm_table[(*i)++];
3093 * Auto-load some home services.
3095 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3103 * Unload unused services.
3106 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3107 struct smbsrv_connection *smb,
3108 bool (*snumused) (struct smbsrv_connection *, int))
3111 for (i = 0; i < lp_ctx->iNumServices; i++) {
3112 if (lp_ctx->services[i] == NULL)
3115 if (!snumused || !snumused(smb, i)) {
3116 talloc_free(lp_ctx->services[i]);
3117 lp_ctx->services[i] = NULL;
3123 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3125 struct parmlist_entry *data;
3127 if (lp_ctx->refuse_free) {
3128 /* someone is trying to free the
3129 global_loadparm_context.
3130 We can't allow that. */
3134 if (lp_ctx->globals->param_opt != NULL) {
3135 struct parmlist_entry *next;
3136 for (data = lp_ctx->globals->param_opt; data; data=next) {
3138 if (data->priority & FLAG_CMDLINE) continue;
3139 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3148 * Initialise the global parameter structure.
3150 * Note that most callers should use loadparm_init_global() instead
3152 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3156 struct loadparm_context *lp_ctx;
3157 struct parmlist_entry *parm;
3160 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3164 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3165 lp_ctx->bInGlobalSection = true;
3166 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3167 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3169 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3170 lp_ctx->sDefault->bAvailable = true;
3171 lp_ctx->sDefault->bBrowseable = true;
3172 lp_ctx->sDefault->bRead_only = true;
3173 lp_ctx->sDefault->bMap_archive = true;
3174 lp_ctx->sDefault->bStrictLocking = true;
3175 lp_ctx->sDefault->bOplocks = true;
3176 lp_ctx->sDefault->iCreate_mask = 0744;
3177 lp_ctx->sDefault->iCreate_force_mode = 0000;
3178 lp_ctx->sDefault->iDir_mask = 0755;
3179 lp_ctx->sDefault->iDir_force_mode = 0000;
3181 DEBUG(3, ("Initialising global parameters\n"));
3183 for (i = 0; parm_table[i].label; i++) {
3184 if ((parm_table[i].type == P_STRING ||
3185 parm_table[i].type == P_USTRING) &&
3186 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3188 if (parm_table[i].p_class == P_LOCAL) {
3189 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3191 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3193 *r = talloc_strdup(lp_ctx, "");
3197 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3198 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3199 talloc_free(logfile);
3201 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3203 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3205 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3207 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
3209 /* options that can be set on the command line must be initialised via
3210 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3212 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3214 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3215 myname = get_myname(lp_ctx);
3216 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3217 talloc_free(myname);
3218 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3220 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3222 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3223 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3225 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3226 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate web");
3227 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3228 /* the winbind method for domain controllers is for both RODC
3229 auth forwarding and for trusted domains */
3230 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3231 lpcfg_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
3232 lpcfg_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
3233 lpcfg_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
3234 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3236 /* This hive should be dynamically generated by Samba using
3237 data from the sam, but for the moment leave it in a tdb to
3238 keep regedt32 from popping up an annoying dialog. */
3239 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3241 /* using UTF8 by default allows us to support all chars */
3242 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3244 /* Use codepage 850 as a default for the dos character set */
3245 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3248 * Allow the default PASSWD_CHAT to be overridden in local.h.
3250 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3252 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3253 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3254 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3256 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3257 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3258 "Samba %s", SAMBA_VERSION_STRING);
3260 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3262 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3263 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3264 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3265 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3266 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3267 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3268 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3269 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3270 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
3271 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3272 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3273 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3274 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3275 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3276 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3278 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3279 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3280 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3281 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3282 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3283 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3284 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3285 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3287 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3289 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3290 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3292 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3293 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3295 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3296 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3297 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3298 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3299 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3300 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3301 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3303 lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
3304 lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
3306 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3308 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3309 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3310 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3311 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3312 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3313 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3314 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3316 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3318 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3319 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3321 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3322 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3323 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3324 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3325 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3327 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3328 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3329 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3330 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3331 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3333 for (i = 0; parm_table[i].label; i++) {
3334 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3335 lp_ctx->flags[i] |= FLAG_DEFAULT;
3339 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3340 if (!(parm->priority & FLAG_CMDLINE)) {
3341 parm->priority |= FLAG_DEFAULT;
3349 * Initialise the global parameter structure.
3351 struct loadparm_context *loadparm_init_global(bool load_default)
3353 if (global_loadparm_context == NULL) {
3354 global_loadparm_context = loadparm_init(NULL);
3356 if (global_loadparm_context == NULL) {
3359 global_loadparm_context->global = true;
3360 if (load_default && !global_loadparm_context->loaded) {
3361 lpcfg_load_default(global_loadparm_context);
3363 global_loadparm_context->refuse_free = true;
3364 return global_loadparm_context;
3368 * Initialise the global parameter structure.
3370 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3371 const struct loadparm_s3_context *s3_fns)
3373 struct loadparm_context *loadparm_context = loadparm_init(mem_ctx);
3374 if (!loadparm_context) {
3377 loadparm_context->s3_fns = s3_fns;
3378 return loadparm_context;
3381 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3383 return lp_ctx->szConfigFile;
3386 const char *lp_default_path(void)
3388 if (getenv("SMB_CONF_PATH"))
3389 return getenv("SMB_CONF_PATH");
3391 return dyn_CONFIGFILE;
3395 * Update the internal state of a loadparm context after settings
3398 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3400 struct debug_settings settings;
3401 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3403 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3404 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3407 if (!lp_ctx->global) {
3411 panic_action = lp_ctx->globals->panic_action;
3413 reload_charcnv(lp_ctx);
3415 ZERO_STRUCT(settings);
3416 /* Add any more debug-related smb.conf parameters created in
3418 settings.timestamp_logs = true;
3419 debug_set_settings(&settings);
3421 /* FIXME: This is a bit of a hack, but we can't use a global, since
3422 * not everything that uses lp also uses the socket library */
3423 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3424 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3426 unsetenv("SOCKET_TESTNONBLOCK");
3432 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3436 path = lp_default_path();
3438 if (!file_exist(path)) {
3439 /* We allow the default smb.conf file to not exist,
3440 * basically the equivalent of an empty file. */
3441 return lpcfg_update(lp_ctx);
3444 return lpcfg_load(lp_ctx, path);
3448 * Load the services array from the services file.
3450 * Return True on success, False on failure.
3452 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3457 filename = talloc_strdup(lp_ctx, filename);
3459 lp_ctx->szConfigFile = filename;
3461 lp_ctx->bInGlobalSection = true;
3462 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3463 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3465 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3467 /* We get sections first, so have to start 'behind' to make up */
3468 lp_ctx->currentService = NULL;
3469 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3471 /* finish up the last section */
3472 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3474 if (lp_ctx->currentService != NULL)
3475 bRetval = service_ok(lp_ctx->currentService);
3477 bRetval = bRetval && lpcfg_update(lp_ctx);
3479 /* we do this unconditionally, so that it happens even
3480 for a missing smb.conf */
3481 reload_charcnv(lp_ctx);
3483 if (bRetval == true) {
3484 /* set this up so that any child python tasks will
3485 find the right smb.conf */
3486 setenv("SMB_CONF_PATH", filename, 1);
3488 /* set the context used by the lp_*() function
3490 global_loadparm_context = lp_ctx;
3491 lp_ctx->loaded = true;
3498 * Return the max number of services.
3501 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3503 return lp_ctx->iNumServices;
3507 * Display the contents of the services array in human-readable form.
3510 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3515 defaults_saved = !show_defaults;
3517 dump_globals(lp_ctx, f, show_defaults);
3519 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3521 for (iService = 0; iService < maxtoprint; iService++)
3522 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3526 * Display the contents of one service in human-readable form.
3528 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3530 if (service != NULL) {
3531 if (service->szService[0] == '\0')
3533 dump_a_service(service, sDefault, f, NULL);
3537 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3540 return lp_ctx->services[snum];
3543 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3544 const char *service_name)
3549 if (lp_ctx->s3_fns) {
3550 return lp_ctx->s3_fns->get_service(service_name);
3553 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3554 if (lp_ctx->services[iService] &&
3555 lp_ctx->services[iService]->szService) {
3557 * The substitution here is used to support %U is
3560 serviceName = standard_sub_basic(
3561 lp_ctx->services[iService],
3562 lp_ctx->services[iService]->szService);
3563 if (strequal(serviceName, service_name)) {
3564 talloc_free(serviceName);
3565 return lp_ctx->services[iService];
3567 talloc_free(serviceName);
3571 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3575 const char *lpcfg_servicename(const struct loadparm_service *service)
3577 return lp_string((const char *)service->szService);
3581 * A useful volume label function.
3583 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3586 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3587 service->volume : sDefault->volume));
3589 return lpcfg_servicename(service);
3594 * If we are PDC then prefer us as DMB
3596 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3599 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3600 service->szPrintername : sDefault->szPrintername));
3601 if (ret == NULL || (ret != NULL && *ret == '\0'))
3602 ret = lpcfg_servicename(service);
3609 * Return the max print jobs per queue.
3611 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3613 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3614 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3615 maxjobs = PRINT_MAX_JOBID - 1;
3620 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3622 if (lp_ctx == NULL) {
3623 return get_iconv_handle();
3625 return lp_ctx->iconv_handle;
3628 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3630 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3631 if (!lp_ctx->global) {
3635 if (old_ic == NULL) {
3636 old_ic = global_iconv_handle;
3638 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3639 global_iconv_handle = lp_ctx->iconv_handle;
3642 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
3643 struct smbcli_options *options)
3645 options->max_xmit = lpcfg_max_xmit(lp_ctx);
3646 options->max_mux = lpcfg_maxmux(lp_ctx);
3647 options->use_spnego = lpcfg_nt_status_support(lp_ctx) && lpcfg_use_spnego(lp_ctx);
3648 options->signing = lpcfg_client_signing(lp_ctx);
3649 options->request_timeout = SMB_REQUEST_TIMEOUT;
3650 options->ntstatus_support = lpcfg_nt_status_support(lp_ctx);
3651 options->max_protocol = lpcfg_cli_maxprotocol(lp_ctx);
3652 options->unicode = lpcfg_unicode(lp_ctx);
3653 options->use_oplocks = true;
3654 options->use_level2_oplocks = true;
3657 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
3658 struct smbcli_session_options *options)
3660 options->lanman_auth = lpcfg_client_lanman_auth(lp_ctx);
3661 options->ntlmv2_auth = lpcfg_client_ntlmv2_auth(lp_ctx);
3662 options->plaintext_auth = lpcfg_client_plaintext_auth(lp_ctx);
3665 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3667 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3670 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3672 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3675 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3677 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3680 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3682 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3685 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3687 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3690 _PUBLIC_ struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3692 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
3694 ret->domain_name = talloc_reference(mem_ctx, lpcfg_workgroup(lp_ctx));
3695 ret->version_major = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
3696 ret->version_minor = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
3697 ret->version_build = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
3702 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3704 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3705 if (settings == NULL)
3707 SMB_ASSERT(lp_ctx != NULL);
3708 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3709 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");