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
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
69 #include "source4/dns_server/dns_update.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved = false;
76 #define LOADPARM_EXTRA_GLOBALS \
77 struct parmlist_entry *param_opt; \
92 #include "lib/param/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 #include "lib/param/param_enums.c"
111 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
112 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
114 static struct parm_struct parm_table[] = {
116 .label = "server role",
119 .offset = GLOBAL_VAR(server_role),
121 .enum_list = enum_server_role
124 .label = "domain logons",
127 .offset = GLOBAL_VAR(domain_logons),
129 .enum_list = enum_bool_auto
132 .label = "domain master",
135 .offset = GLOBAL_VAR(domain_master),
137 .enum_list = enum_bool_auto
140 .label = "dos charset",
143 .offset = GLOBAL_VAR(dos_charset),
148 .label = "unix charset",
151 .offset = GLOBAL_VAR(unix_charset),
156 .label = "ncalrpc dir",
159 .offset = GLOBAL_VAR(ncalrpc_dir),
167 .offset = LOCAL_VAR(comment),
170 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
176 .offset = LOCAL_VAR(szPath),
179 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
182 .label = "directory",
185 .offset = LOCAL_VAR(szPath),
191 .label = "workgroup",
194 .offset = GLOBAL_VAR(szWorkgroup),
197 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
203 .offset = GLOBAL_VAR(szRealm),
204 .special = handle_realm,
206 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
209 .label = "netbios name",
212 .offset = GLOBAL_VAR(szNetbiosName),
215 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
218 .label = "netbios aliases",
221 .offset = GLOBAL_VAR(szNetbiosAliases),
226 .label = "netbios scope",
229 .offset = GLOBAL_VAR(szNetbiosScope),
232 .flags = FLAG_ADVANCED,
235 .label = "server string",
238 .offset = GLOBAL_VAR(szServerString),
241 .flags = FLAG_BASIC | FLAG_ADVANCED,
244 .label = "interfaces",
247 .offset = GLOBAL_VAR(szInterfaces),
250 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
253 .label = "bind interfaces only",
256 .offset = GLOBAL_VAR(bBindInterfacesOnly),
259 .flags = FLAG_ADVANCED | FLAG_WIZARD,
262 .label = "ntvfs handler",
265 .offset = LOCAL_VAR(ntvfs_handler),
270 .label = "ntptr providor",
273 .offset = GLOBAL_VAR(ntptr_providor),
278 .label = "passdb backend",
281 .offset = GLOBAL_VAR(passdb_backend),
286 .label = "dcerpc endpoint servers",
289 .offset = GLOBAL_VAR(dcerpc_ep_servers),
294 .label = "server services",
297 .offset = GLOBAL_VAR(server_services),
306 .offset = GLOBAL_VAR(security),
308 .enum_list = enum_security
311 .label = "encrypt passwords",
314 .offset = GLOBAL_VAR(bEncryptPasswords),
319 .label = "null passwords",
322 .offset = GLOBAL_VAR(bNullPasswords),
325 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
328 .label = "obey pam restrictions",
331 .offset = GLOBAL_VAR(bObeyPamRestrictions),
334 .flags = FLAG_ADVANCED,
337 .label = "password server",
340 .offset = GLOBAL_VAR(szPasswordServer),
345 .label = "private dir",
348 .offset = GLOBAL_VAR(szPrivateDir),
353 .label = "passwd chat",
356 .offset = GLOBAL_VAR(szPasswdChat),
361 .label = "password level",
364 .offset = GLOBAL_VAR(pwordlevel),
369 .label = "lanman auth",
372 .offset = GLOBAL_VAR(bLanmanAuth),
375 .flags = FLAG_ADVANCED,
378 .label = "ntlm auth",
381 .offset = GLOBAL_VAR(bNTLMAuth),
384 .flags = FLAG_ADVANCED,
387 .label = "client NTLMv2 auth",
390 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
393 .flags = FLAG_ADVANCED,
396 .label = "client lanman auth",
399 .offset = GLOBAL_VAR(bClientLanManAuth),
402 .flags = FLAG_ADVANCED,
405 .label = "client plaintext auth",
408 .offset = GLOBAL_VAR(bClientPlaintextAuth),
411 .flags = FLAG_ADVANCED,
414 .label = "client use spnego principal",
417 .offset = GLOBAL_VAR(client_use_spnego_principal),
423 .label = "read only",
426 .offset = LOCAL_VAR(bRead_only),
432 .label = "create mask",
435 .offset = LOCAL_VAR(iCreate_mask),
440 .label = "force create mode",
443 .offset = LOCAL_VAR(iCreate_force_mode),
448 .label = "directory mask",
451 .offset = LOCAL_VAR(iDir_mask),
456 .label = "force directory mode",
459 .offset = LOCAL_VAR(iDir_force_mode),
465 .label = "hosts allow",
468 .offset = LOCAL_VAR(szHostsallow),
473 .label = "hosts deny",
476 .offset = LOCAL_VAR(szHostsdeny),
482 .label = "log level",
485 .offset = GLOBAL_VAR(loglevel),
486 .special = handle_debuglevel,
490 .label = "debuglevel",
493 .offset = GLOBAL_VAR(loglevel),
494 .special = handle_debuglevel,
501 .offset = GLOBAL_VAR(logfile),
502 .special = handle_logfile,
504 .flags = FLAG_ADVANCED,
508 .label = "smb ports",
511 .offset = GLOBAL_VAR(smb_ports),
519 .offset = GLOBAL_VAR(nbt_port),
524 .label = "dgram port",
527 .offset = GLOBAL_VAR(dgram_port),
532 .label = "cldap port",
535 .offset = GLOBAL_VAR(cldap_port),
540 .label = "krb5 port",
543 .offset = GLOBAL_VAR(krb5_port),
548 .label = "kpasswd port",
551 .offset = GLOBAL_VAR(kpasswd_port),
559 .offset = GLOBAL_VAR(web_port),
564 .label = "tls enabled",
567 .offset = GLOBAL_VAR(tls_enabled),
572 .label = "tls keyfile",
575 .offset = GLOBAL_VAR(tls_keyfile),
580 .label = "tls certfile",
583 .offset = GLOBAL_VAR(tls_certfile),
588 .label = "tls cafile",
591 .offset = GLOBAL_VAR(tls_cafile),
596 .label = "tls crlfile",
599 .offset = GLOBAL_VAR(tls_crlfile),
604 .label = "tls dh params file",
607 .offset = GLOBAL_VAR(tls_dhpfile),
612 .label = "large readwrite",
615 .offset = GLOBAL_VAR(bLargeReadwrite),
618 .flags = FLAG_ADVANCED,
621 .label = "server max protocol",
624 .offset = GLOBAL_VAR(srv_maxprotocol),
626 .enum_list = enum_protocol,
627 .flags = FLAG_ADVANCED,
630 .label = "max protocol",
633 .offset = GLOBAL_VAR(srv_maxprotocol),
635 .enum_list = enum_protocol,
636 .flags = FLAG_ADVANCED,
642 .offset = GLOBAL_VAR(srv_maxprotocol),
644 .enum_list = enum_protocol,
645 .flags = FLAG_ADVANCED,
648 .label = "server min protocol",
651 .offset = GLOBAL_VAR(srv_minprotocol),
653 .enum_list = enum_protocol,
654 .flags = FLAG_ADVANCED,
657 .label = "min protocol",
660 .offset = GLOBAL_VAR(srv_minprotocol),
662 .enum_list = enum_protocol,
663 .flags = FLAG_ADVANCED,
666 .label = "client max protocol",
669 .offset = GLOBAL_VAR(cli_maxprotocol),
671 .enum_list = enum_protocol
674 .label = "client min protocol",
677 .offset = GLOBAL_VAR(cli_minprotocol),
679 .enum_list = enum_protocol
685 .offset = GLOBAL_VAR(bUnicode),
693 .offset = GLOBAL_VAR(bReadRaw),
698 .label = "write raw",
701 .offset = GLOBAL_VAR(bWriteRaw),
706 .label = "disable netbios",
709 .offset = GLOBAL_VAR(bDisableNetbios),
715 .label = "nt status support",
718 .offset = GLOBAL_VAR(bNTStatusSupport),
727 .offset = GLOBAL_VAR(max_mux),
730 .flags = FLAG_ADVANCED,
736 .offset = GLOBAL_VAR(max_xmit),
739 .flags = FLAG_ADVANCED,
743 .label = "name resolve order",
746 .offset = GLOBAL_VAR(szNameResolveOrder),
751 .label = "max wins ttl",
754 .offset = GLOBAL_VAR(max_wins_ttl),
757 .flags = FLAG_ADVANCED,
760 .label = "min wins ttl",
763 .offset = GLOBAL_VAR(min_wins_ttl),
766 .flags = FLAG_ADVANCED,
769 .label = "time server",
772 .offset = GLOBAL_VAR(bTimeServer),
775 .flags = FLAG_ADVANCED,
778 .label = "unix extensions",
781 .offset = GLOBAL_VAR(bUnixExtensions),
784 .flags = FLAG_ADVANCED,
787 .label = "use spnego",
790 .offset = GLOBAL_VAR(bUseSpnego),
795 .label = "server signing",
798 .offset = GLOBAL_VAR(server_signing),
800 .enum_list = enum_smb_signing_vals,
801 .flags = FLAG_ADVANCED,
804 .label = "client signing",
807 .offset = GLOBAL_VAR(client_signing),
809 .enum_list = enum_smb_signing_vals
812 .label = "rpc big endian",
815 .offset = GLOBAL_VAR(bRpcBigEndian),
821 .label = "max connections",
824 .offset = LOCAL_VAR(iMaxConnections),
827 .flags = FLAG_ADVANCED | FLAG_SHARE,
830 .label = "paranoid server security",
833 .offset = GLOBAL_VAR(paranoid_server_security),
838 .label = "socket options",
841 .offset = GLOBAL_VAR(socket_options),
847 .label = "strict sync",
850 .offset = LOCAL_VAR(bStrictSync),
858 .offset = GLOBAL_VAR(bUseMmap),
861 .flags = FLAG_ADVANCED,
864 .label = "case insensitive filesystem",
867 .offset = LOCAL_VAR(bCIFileSystem),
873 .label = "max print jobs",
876 .offset = LOCAL_VAR(iMaxPrintJobs),
881 .label = "printable",
884 .offset = LOCAL_VAR(bPrint_ok),
892 .offset = LOCAL_VAR(bPrint_ok),
898 .label = "printer name",
901 .offset = LOCAL_VAR(szPrintername),
904 .flags = FLAG_ADVANCED | FLAG_PRINT,
910 .offset = LOCAL_VAR(szPrintername),
917 .label = "map system",
920 .offset = LOCAL_VAR(bMap_system),
925 .label = "map hidden",
928 .offset = LOCAL_VAR(bMap_hidden),
933 .label = "map archive",
936 .offset = LOCAL_VAR(bMap_archive),
942 .label = "preferred master",
945 .offset = GLOBAL_VAR(bPreferredMaster),
947 .enum_list = enum_bool_auto,
948 .flags = FLAG_BASIC | FLAG_ADVANCED,
951 .label = "prefered master",
954 .offset = GLOBAL_VAR(bPreferredMaster),
956 .enum_list = enum_bool_auto,
960 .label = "local master",
963 .offset = GLOBAL_VAR(bLocalMaster),
968 .label = "browseable",
971 .offset = LOCAL_VAR(bBrowseable),
974 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
977 .label = "browsable",
980 .offset = LOCAL_VAR(bBrowseable),
986 .label = "dns proxy",
989 .offset = GLOBAL_VAR(bWINSdnsProxy),
994 .label = "wins server",
997 .offset = GLOBAL_VAR(szWINSservers),
1000 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
1003 .label = "wins support",
1005 .p_class = P_GLOBAL,
1006 .offset = GLOBAL_VAR(bWINSsupport),
1009 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
1012 .label = "wins hook",
1014 .p_class = P_GLOBAL,
1015 .offset = GLOBAL_VAR(szWINSHook),
1018 .flags = FLAG_ADVANCED,
1022 .label = "csc policy",
1025 .offset = LOCAL_VAR(iCSCPolicy),
1027 .enum_list = enum_csc_policy,
1028 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1032 .label = "strict locking",
1035 .offset = LOCAL_VAR(iStrictLocking),
1043 .offset = LOCAL_VAR(bOpLocks),
1049 .label = "share backend",
1051 .p_class = P_GLOBAL,
1052 .offset = GLOBAL_VAR(szShareBackend),
1059 .p_class = P_GLOBAL,
1060 .offset = GLOBAL_VAR(szAutoServices),
1063 .flags = FLAG_ADVANCED,
1066 .label = "auto services",
1068 .p_class = P_GLOBAL,
1069 .offset = GLOBAL_VAR(szAutoServices),
1072 .flags = FLAG_ADVANCED,
1075 .label = "lock directory",
1077 .p_class = P_GLOBAL,
1078 .offset = GLOBAL_VAR(szLockDir),
1081 .flags = FLAG_ADVANCED,
1084 .label = "lock dir",
1086 .p_class = P_GLOBAL,
1087 .offset = GLOBAL_VAR(szLockDir),
1093 .label = "state directory",
1095 .p_class = P_GLOBAL,
1096 .offset = GLOBAL_VAR(szStateDir),
1099 .flags = FLAG_ADVANCED,
1102 .label = "cache directory",
1104 .p_class = P_GLOBAL,
1105 .offset = GLOBAL_VAR(szCacheDir),
1108 .flags = FLAG_ADVANCED,
1111 .label = "pid directory",
1113 .p_class = P_GLOBAL,
1114 .offset = GLOBAL_VAR(szPidDir),
1120 .label = "socket address",
1122 .p_class = P_GLOBAL,
1123 .offset = GLOBAL_VAR(szSocketAddress),
1131 .offset = LOCAL_VAR(szCopy),
1132 .special = handle_copy,
1140 .offset = LOCAL_VAR(szInclude),
1141 .special = handle_include,
1146 .label = "available",
1149 .offset = LOCAL_VAR(bAvailable),
1157 .offset = LOCAL_VAR(volume),
1160 .flags = FLAG_ADVANCED | FLAG_SHARE,
1166 .offset = LOCAL_VAR(fstype),
1172 .label = "panic action",
1174 .p_class = P_GLOBAL,
1175 .offset = GLOBAL_VAR(panic_action),
1181 .label = "msdfs root",
1184 .offset = LOCAL_VAR(bMSDfsRoot),
1189 .label = "host msdfs",
1191 .p_class = P_GLOBAL,
1192 .offset = GLOBAL_VAR(bHostMSDfs),
1195 .flags = FLAG_ADVANCED,
1198 .label = "winbind separator",
1200 .p_class = P_GLOBAL,
1201 .offset = GLOBAL_VAR(szWinbindSeparator),
1206 .label = "winbindd socket directory",
1208 .p_class = P_GLOBAL,
1209 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1212 .flags = FLAG_ADVANCED,
1215 .label = "winbindd privileged socket directory",
1217 .p_class = P_GLOBAL,
1218 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1221 .flags = FLAG_ADVANCED,
1224 .label = "winbind sealed pipes",
1226 .p_class = P_GLOBAL,
1227 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1230 .flags = FLAG_ADVANCED,
1233 .label = "template shell",
1235 .p_class = P_GLOBAL,
1236 .offset = GLOBAL_VAR(szTemplateShell),
1239 .flags = FLAG_ADVANCED,
1242 .label = "template homedir",
1244 .p_class = P_GLOBAL,
1245 .offset = GLOBAL_VAR(szTemplateHomedir),
1248 .flags = FLAG_ADVANCED,
1251 .label = "ntp signd socket directory",
1253 .p_class = P_GLOBAL,
1254 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1257 .flags = FLAG_ADVANCED,
1260 .label = "rndc command",
1262 .p_class = P_GLOBAL,
1263 .offset = GLOBAL_VAR(szRNDCCommand),
1266 .flags = FLAG_ADVANCED,
1269 .label = "dns update command",
1271 .p_class = P_GLOBAL,
1272 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1275 .flags = FLAG_ADVANCED,
1278 .label = "spn update command",
1280 .p_class = P_GLOBAL,
1281 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1284 .flags = FLAG_ADVANCED,
1287 .label = "samba kcc command",
1289 .p_class = P_GLOBAL,
1290 .offset = GLOBAL_VAR(szSambaKCCCommand),
1293 .flags = FLAG_ADVANCED,
1296 .label = "nsupdate command",
1298 .p_class = P_GLOBAL,
1299 .offset = GLOBAL_VAR(szNSUpdateCommand),
1302 .flags = FLAG_ADVANCED,
1305 .label = "allow dns updates",
1307 .p_class = P_GLOBAL,
1308 .offset = GLOBAL_VAR(allow_dns_updates),
1310 .enum_list = enum_dns_update_settings,
1311 .flags = FLAG_ADVANCED,
1314 .label = "dns forwarder",
1316 .p_class = P_GLOBAL,
1317 .offset = GLOBAL_VAR(dns_forwarder),
1320 .flags = FLAG_ADVANCED,
1323 .label = "dns recursive queries",
1325 .p_class = P_GLOBAL,
1326 .offset = GLOBAL_VAR(dns_recursive_queries),
1331 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1335 /* local variables */
1336 struct loadparm_context {
1337 const char *szConfigFile;
1338 struct loadparm_global *globals;
1339 struct loadparm_service **services;
1340 struct loadparm_service *sDefault;
1341 struct smb_iconv_handle *iconv_handle;
1343 struct loadparm_service *currentService;
1344 bool bInGlobalSection;
1346 struct file_lists *next;
1351 unsigned int flags[NUMPARAMETERS];
1354 bool global; /* Is this the global context, which may set
1355 * global variables such as debug level etc? */
1356 const struct loadparm_s3_helpers *s3_fns;
1360 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1362 if (lp_ctx->s3_fns) {
1363 return lp_ctx->s3_fns->get_default_loadparm_service();
1365 return lp_ctx->sDefault;
1369 * Convenience routine to grab string parameters into temporary memory
1370 * and run standard_sub_basic on them.
1372 * The buffers can be written to by
1373 * callers without affecting the source string.
1376 static const char *lp_string(const char *s)
1378 #if 0 /* until REWRITE done to make thread-safe */
1379 size_t len = s ? strlen(s) : 0;
1383 /* The follow debug is useful for tracking down memory problems
1384 especially if you have an inner loop that is calling a lp_*()
1385 function that returns a string. Perhaps this debug should be
1386 present all the time? */
1389 DEBUG(10, ("lp_string(%s)\n", s));
1392 #if 0 /* until REWRITE done to make thread-safe */
1394 lp_talloc = talloc_init("lp_talloc");
1396 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1404 strlcpy(ret, s, len);
1406 if (trim_string(ret, "\"", "\"")) {
1407 if (strchr(ret,'"') != NULL)
1408 strlcpy(ret, s, len);
1411 standard_sub_basic(ret,len+100);
1418 In this section all the functions that are used to access the
1419 parameters from the rest of the program are defined
1423 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1424 * for code compatibility between existing Samba4 and Samba3 code.
1427 /* this global context supports the lp_*() function varients */
1428 static struct loadparm_context *global_loadparm_context;
1430 #define lpcfg_default_service global_loadparm_context->sDefault
1431 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1433 #define FN_GLOBAL_STRING(fn_name,var_name) \
1434 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1435 if (lp_ctx == NULL) return NULL; \
1436 if (lp_ctx->s3_fns) { \
1437 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1438 return lp_ctx->s3_fns->fn_name(); \
1440 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1443 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1444 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1445 if (lp_ctx == NULL) return NULL; \
1446 if (lp_ctx->s3_fns) { \
1447 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1448 return lp_ctx->s3_fns->fn_name(); \
1450 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1453 #define FN_GLOBAL_LIST(fn_name,var_name) \
1454 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1455 if (lp_ctx == NULL) return NULL; \
1456 if (lp_ctx->s3_fns) { \
1457 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1458 return lp_ctx->s3_fns->fn_name(); \
1460 return lp_ctx->globals->var_name; \
1463 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1464 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1465 if (lp_ctx == NULL) return false; \
1466 if (lp_ctx->s3_fns) { \
1467 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1468 return lp_ctx->s3_fns->fn_name(); \
1470 return lp_ctx->globals->var_name; \
1473 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1474 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1475 if (lp_ctx->s3_fns) { \
1476 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1477 return lp_ctx->s3_fns->fn_name(); \
1479 return lp_ctx->globals->var_name; \
1482 /* Local parameters don't need the ->s3_fns because the struct
1483 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1485 #define FN_LOCAL_STRING(fn_name,val) \
1486 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1487 struct loadparm_service *sDefault) { \
1488 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1491 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1493 #define FN_LOCAL_LIST(fn_name,val) \
1494 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1495 struct loadparm_service *sDefault) {\
1496 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1499 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1501 #define FN_LOCAL_BOOL(fn_name,val) \
1502 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1503 struct loadparm_service *sDefault) { \
1504 return((service != NULL)? service->val : sDefault->val); \
1507 #define FN_LOCAL_INTEGER(fn_name,val) \
1508 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1509 struct loadparm_service *sDefault) { \
1510 return((service != NULL)? service->val : sDefault->val); \
1513 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1515 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1517 #define FN_LOCAL_CHAR(fn_name,val) \
1518 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1519 struct loadparm_service *sDefault) { \
1520 return((service != NULL)? service->val : sDefault->val); \
1523 #include "lib/param/param_functions.c"
1525 /* These functions remain only in lib/param for now */
1526 FN_GLOBAL_BOOL(readraw, bReadRaw)
1527 FN_GLOBAL_BOOL(unicode, bUnicode)
1528 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1529 FN_GLOBAL_LIST(smb_ports, smb_ports)
1530 FN_GLOBAL_STRING(cachedir, szCacheDir)
1531 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1532 FN_GLOBAL_STRING(statedir, szStateDir)
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 lpcfg_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 unsigned long lp_ulong(const char *s)
1617 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
1621 return strtoul(s, NULL, 0);
1625 * convenience routine to return unsigned long parameters.
1627 static long lp_long(const char *s)
1631 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
1635 return strtol(s, NULL, 0);
1639 * convenience routine to return unsigned long parameters.
1641 static double lp_double(const char *s)
1645 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1649 return strtod(s, NULL);
1653 * convenience routine to return boolean parameters.
1655 static bool lp_bool(const char *s)
1660 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1664 if (!set_boolean(s, &ret)) {
1665 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1674 * Return parametric option from a given service. Type is a part of option before ':'
1675 * Parametric option has following syntax: 'Type: option = value'
1676 * Returned value is allocated in 'lp_talloc' context
1679 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1680 struct loadparm_service *service, const char *type,
1683 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1686 return lp_string(value);
1692 * Return parametric option from a given service. Type is a part of option before ':'
1693 * Parametric option has following syntax: 'Type: option = value'
1694 * Returned value is allocated in 'lp_talloc' context
1697 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1698 struct loadparm_context *lp_ctx,
1699 struct loadparm_service *service,
1701 const char *option, const char *separator)
1703 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1706 return (const char **)str_list_make(mem_ctx, value, separator);
1712 * Return parametric option from a given service. Type is a part of option before ':'
1713 * Parametric option has following syntax: 'Type: option = value'
1716 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1717 struct loadparm_service *service, const char *type,
1718 const char *option, int default_v)
1720 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1723 return lp_int(value);
1729 * Return parametric option from a given service. Type is a part of
1730 * option before ':'.
1731 * Parametric option has following syntax: 'Type: option = value'.
1734 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1735 struct loadparm_service *service, const char *type,
1736 const char *option, int default_v)
1740 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1742 if (value && conv_str_size_error(value, &bval)) {
1743 if (bval <= INT_MAX) {
1752 * Return parametric option from a given service.
1753 * Type is a part of option before ':'
1754 * Parametric option has following syntax: 'Type: option = value'
1756 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1757 struct loadparm_service *service, const char *type,
1758 const char *option, unsigned long default_v)
1760 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1763 return lp_ulong(value);
1768 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
1769 struct loadparm_service *service, const char *type,
1770 const char *option, long default_v)
1772 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1775 return lp_long(value);
1780 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1781 struct loadparm_service *service, const char *type,
1782 const char *option, double default_v)
1784 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1787 return lp_double(value);
1793 * Return parametric option from a given service. Type is a part of option before ':'
1794 * Parametric option has following syntax: 'Type: option = value'
1797 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1798 struct loadparm_service *service, const char *type,
1799 const char *option, bool default_v)
1801 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1804 return lp_bool(value);
1811 * Initialise a service to the defaults.
1814 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1816 struct loadparm_service *pservice =
1817 talloc_zero(mem_ctx, struct loadparm_service);
1818 copy_service(pservice, sDefault, NULL);
1823 * Set a string value, deallocating any existing space, and allocing the space
1826 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1833 *dest = talloc_strdup(mem_ctx, src);
1834 if ((*dest) == NULL) {
1835 DEBUG(0,("Out of memory in string_set\n"));
1843 * Set a string value, deallocating any existing space, and allocing the space
1846 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1853 *dest = strupper_talloc(mem_ctx, src);
1854 if ((*dest) == NULL) {
1855 DEBUG(0,("Out of memory in string_set_upper\n"));
1865 * Add a new service to the services array initialising it with the given
1869 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1870 const struct loadparm_service *pservice,
1874 struct loadparm_service tservice;
1875 int num_to_alloc = lp_ctx->iNumServices + 1;
1876 struct parmlist_entry *data, *pdata;
1878 if (pservice == NULL) {
1879 pservice = lp_ctx->sDefault;
1882 tservice = *pservice;
1884 /* it might already exist */
1886 struct loadparm_service *service = getservicebyname(lp_ctx,
1888 if (service != NULL) {
1889 /* Clean all parametric options for service */
1890 /* They will be added during parsing again */
1891 data = service->param_opt;
1897 service->param_opt = NULL;
1902 /* find an invalid one */
1903 for (i = 0; i < lp_ctx->iNumServices; i++)
1904 if (lp_ctx->services[i] == NULL)
1907 /* if not, then create one */
1908 if (i == lp_ctx->iNumServices) {
1909 struct loadparm_service **tsp;
1911 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1914 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1917 lp_ctx->services = tsp;
1918 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1921 lp_ctx->iNumServices++;
1924 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1925 if (lp_ctx->services[i] == NULL) {
1926 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1929 copy_service(lp_ctx->services[i], &tservice, NULL);
1931 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1932 return lp_ctx->services[i];
1936 * Add a new home service, with the specified home directory, defaults coming
1937 * from service ifrom.
1940 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1941 const char *pszHomename,
1942 struct loadparm_service *default_service,
1943 const char *user, const char *pszHomedir)
1945 struct loadparm_service *service;
1947 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1949 if (service == NULL)
1952 if (!(*(default_service->szPath))
1953 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1954 service->szPath = talloc_strdup(service, pszHomedir);
1956 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1959 if (!(*(service->comment))) {
1960 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1962 service->bAvailable = default_service->bAvailable;
1963 service->bBrowseable = default_service->bBrowseable;
1965 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1966 pszHomename, user, service->szPath));
1972 * Add a new printer service, with defaults coming from service iFrom.
1975 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1976 const char *pszPrintername,
1977 struct loadparm_service *default_service)
1979 const char *comment = "From Printcap";
1980 struct loadparm_service *service;
1981 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1983 if (service == NULL)
1986 /* note that we do NOT default the availability flag to True - */
1987 /* we take it from the default service passed. This allows all */
1988 /* dynamic printers to be disabled by disabling the [printers] */
1989 /* entry (if/when the 'available' keyword is implemented!). */
1991 /* the printer name is set to the service name. */
1992 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
1993 lpcfg_string_set(service, &service->comment, comment);
1994 service->bBrowseable = default_service->bBrowseable;
1995 /* Printers cannot be read_only. */
1996 service->bRead_only = false;
1997 /* Printer services must be printable. */
1998 service->bPrint_ok = true;
2000 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2006 * Map a parameter's string representation to something we can use.
2007 * Returns False if the parameter string is not recognised, else TRUE.
2010 static int map_parameter(const char *pszParmName)
2014 if (*pszParmName == '-')
2017 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2018 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2021 /* Warn only if it isn't parametric option */
2022 if (strchr(pszParmName, ':') == NULL)
2023 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2024 /* We do return 'fail' for parametric options as well because they are
2025 stored in different storage
2032 return the parameter structure for a parameter
2034 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2038 if (lp_ctx->s3_fns) {
2039 return lp_ctx->s3_fns->get_parm_struct(name);
2042 parmnum = map_parameter(name);
2043 if (parmnum == -1) return NULL;
2044 return &parm_table[parmnum];
2048 return the parameter pointer for a parameter
2050 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2051 struct loadparm_service *service, struct parm_struct *parm)
2053 if (lp_ctx->s3_fns) {
2054 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2057 if (service == NULL) {
2058 if (parm->p_class == P_LOCAL)
2059 return ((char *)lp_ctx->sDefault)+parm->offset;
2060 else if (parm->p_class == P_GLOBAL)
2061 return ((char *)lp_ctx->globals)+parm->offset;
2064 return ((char *)service) + parm->offset;
2069 return the parameter pointer for a parameter
2071 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2075 if (lp_ctx->s3_fns) {
2076 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2078 return parm->flags & FLAG_CMDLINE;
2083 parmnum = map_parameter(name);
2084 if (parmnum == -1) return false;
2086 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2090 * Find a service by name. Otherwise works like get_service.
2093 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2094 const char *pszServiceName)
2098 if (lp_ctx->s3_fns) {
2099 return lp_ctx->s3_fns->get_service(pszServiceName);
2102 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2103 if (lp_ctx->services[iService] != NULL &&
2104 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2105 return lp_ctx->services[iService];
2112 * Copy a service structure to another.
2113 * If pcopymapDest is NULL then copy all fields
2116 static void copy_service(struct loadparm_service *pserviceDest,
2117 struct loadparm_service *pserviceSource,
2118 struct bitmap *pcopymapDest)
2121 bool bcopyall = (pcopymapDest == NULL);
2122 struct parmlist_entry *data, *pdata, *paramo;
2125 for (i = 0; parm_table[i].label; i++)
2126 if (parm_table[i].p_class == P_LOCAL &&
2127 (bcopyall || bitmap_query(pcopymapDest, i))) {
2129 ((char *)pserviceSource) + parm_table[i].offset;
2131 ((char *)pserviceDest) + parm_table[i].offset;
2133 switch (parm_table[i].type) {
2135 *(bool *)dest_ptr = *(bool *)src_ptr;
2142 *(int *)dest_ptr = *(int *)src_ptr;
2146 lpcfg_string_set(pserviceDest,
2152 lpcfg_string_set_upper(pserviceDest,
2157 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2158 *(const char ***)src_ptr);
2166 init_copymap(pserviceDest);
2167 if (pserviceSource->copymap)
2168 bitmap_copy(pserviceDest->copymap,
2169 pserviceSource->copymap);
2172 data = pserviceSource->param_opt;
2175 pdata = pserviceDest->param_opt;
2176 /* Traverse destination */
2178 /* If we already have same option, override it */
2179 if (strcmp(pdata->key, data->key) == 0) {
2180 talloc_free(pdata->value);
2181 pdata->value = talloc_strdup(pdata,
2186 pdata = pdata->next;
2189 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2192 paramo->key = talloc_strdup(paramo, data->key);
2193 paramo->value = talloc_strdup(paramo, data->value);
2194 DLIST_ADD(pserviceDest->param_opt, paramo);
2201 * Check a service for consistency. Return False if the service is in any way
2202 * incomplete or faulty, else True.
2204 static bool lpcfg_service_ok(struct loadparm_service *service)
2209 if (service->szService[0] == '\0') {
2210 DEBUG(0, ("The following message indicates an internal error:\n"));
2211 DEBUG(0, ("No service name in service entry.\n"));
2215 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2216 /* I can't see why you'd want a non-printable printer service... */
2217 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2218 if (!service->bPrint_ok) {
2219 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2220 service->szService));
2221 service->bPrint_ok = true;
2223 /* [printers] service must also be non-browsable. */
2224 if (service->bBrowseable)
2225 service->bBrowseable = false;
2228 /* If a service is flagged unavailable, log the fact at level 0. */
2229 if (!service->bAvailable)
2230 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2231 service->szService));
2237 /*******************************************************************
2238 Keep a linked list of all config files so we know when one has changed
2239 it's date and needs to be reloaded.
2240 ********************************************************************/
2242 static void add_to_file_list(struct loadparm_context *lp_ctx,
2243 const char *fname, const char *subfname)
2245 struct file_lists *f = lp_ctx->file_lists;
2248 if (f->name && !strcmp(f->name, fname))
2254 f = talloc(lp_ctx, struct file_lists);
2257 f->next = lp_ctx->file_lists;
2258 f->name = talloc_strdup(f, fname);
2263 f->subfname = talloc_strdup(f, subfname);
2268 lp_ctx->file_lists = f;
2269 f->modtime = file_modtime(subfname);
2271 time_t t = file_modtime(subfname);
2277 /*******************************************************************
2278 Check if a config file has changed date.
2279 ********************************************************************/
2280 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2282 struct file_lists *f;
2283 DEBUG(6, ("lp_file_list_changed()\n"));
2285 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2289 n2 = standard_sub_basic(lp_ctx, f->name);
2291 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2292 f->name, n2, ctime(&f->modtime)));
2294 mod_time = file_modtime(n2);
2296 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2297 DEBUGADD(6, ("file %s modified: %s\n", n2,
2299 f->modtime = mod_time;
2300 talloc_free(f->subfname);
2301 f->subfname = talloc_strdup(f, n2);
2308 /***************************************************************************
2309 Handle the "realm" parameter
2310 ***************************************************************************/
2312 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2313 const char *pszParmValue, char **ptr)
2315 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2317 talloc_free(lp_ctx->globals->szRealm_upper);
2318 talloc_free(lp_ctx->globals->szRealm_lower);
2320 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2321 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2326 /***************************************************************************
2327 Handle the include operation.
2328 ***************************************************************************/
2330 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2331 const char *pszParmValue, char **ptr)
2333 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2335 add_to_file_list(lp_ctx, pszParmValue, fname);
2337 lpcfg_string_set(lp_ctx, ptr, fname);
2339 if (file_exist(fname))
2340 return pm_process(fname, do_section, do_parameter, lp_ctx);
2342 DEBUG(2, ("Can't find include file %s\n", fname));
2347 /***************************************************************************
2348 Handle the interpretation of the copy parameter.
2349 ***************************************************************************/
2351 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2352 const char *pszParmValue, char **ptr)
2355 struct loadparm_service *serviceTemp;
2357 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2361 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2363 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2364 if (serviceTemp == lp_ctx->currentService) {
2365 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2367 copy_service(lp_ctx->currentService,
2369 lp_ctx->currentService->copymap);
2373 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2381 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2382 const char *pszParmValue, char **ptr)
2385 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2386 if (lp_ctx->global) {
2387 return debug_parse_levels(pszParmValue);
2392 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2393 const char *pszParmValue, char **ptr)
2395 debug_set_logfile(pszParmValue);
2396 if (lp_ctx->global) {
2397 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2402 /***************************************************************************
2403 Initialise a copymap.
2404 ***************************************************************************/
2406 static void init_copymap(struct loadparm_service *pservice)
2410 TALLOC_FREE(pservice->copymap);
2412 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2413 if (!pservice->copymap)
2415 ("Couldn't allocate copymap!! (size %d)\n",
2416 (int)NUMPARAMETERS));
2418 for (i = 0; i < NUMPARAMETERS; i++)
2419 bitmap_set(pservice->copymap, i);
2423 * Process a parametric option
2425 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2426 struct loadparm_service *service,
2427 const char *pszParmName,
2428 const char *pszParmValue, int flags)
2430 struct parmlist_entry *paramo, *data;
2432 TALLOC_CTX *mem_ctx;
2434 while (isspace((unsigned char)*pszParmName)) {
2438 name = strlower_talloc(lp_ctx, pszParmName);
2439 if (!name) return false;
2441 if (service == NULL) {
2442 data = lp_ctx->globals->param_opt;
2443 mem_ctx = lp_ctx->globals;
2445 data = service->param_opt;
2449 /* Traverse destination */
2450 for (paramo=data; paramo; paramo=paramo->next) {
2451 /* If we already have the option set, override it unless
2452 it was a command line option and the new one isn't */
2453 if (strcmp(paramo->key, name) == 0) {
2454 if ((paramo->priority & FLAG_CMDLINE) &&
2455 !(flags & FLAG_CMDLINE)) {
2460 talloc_free(paramo->value);
2461 paramo->value = talloc_strdup(paramo, pszParmValue);
2462 paramo->priority = flags;
2468 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2471 paramo->key = talloc_strdup(paramo, name);
2472 paramo->value = talloc_strdup(paramo, pszParmValue);
2473 paramo->priority = flags;
2474 if (service == NULL) {
2475 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2477 DLIST_ADD(service->param_opt, paramo);
2485 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2486 const char *pszParmName, const char *pszParmValue,
2487 struct loadparm_context *lp_ctx, bool on_globals)
2490 /* if it is a special case then go ahead */
2491 if (parm_table[parmnum].special) {
2493 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2498 goto mark_non_default;
2501 /* now switch on the type of variable it is */
2502 switch (parm_table[parmnum].type)
2506 if (!set_boolean(pszParmValue, &b)) {
2507 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2510 *(bool *)parm_ptr = b;
2516 if (!set_boolean(pszParmValue, &b)) {
2517 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2520 *(bool *)parm_ptr = !b;
2525 *(int *)parm_ptr = atoi(pszParmValue);
2529 *(char *)parm_ptr = *pszParmValue;
2533 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2539 if (conv_str_size_error(pszParmValue, &val)) {
2540 if (val <= INT_MAX) {
2541 *(int *)parm_ptr = (int)val;
2546 DEBUG(0,("lp_do_parameter(%s): value is not "
2547 "a valid size specifier!\n", pszParmValue));
2552 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2553 pszParmValue, NULL);
2557 char **new_list = str_list_make(mem_ctx,
2558 pszParmValue, NULL);
2559 for (i=0; new_list[i]; i++) {
2560 if (new_list[i][0] == '+' && new_list[i][1]) {
2561 if (!str_list_check(*(const char ***)parm_ptr,
2563 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2566 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2567 str_list_remove(*(const char ***)parm_ptr,
2571 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2572 pszParmName, pszParmValue));
2575 *(const char ***)parm_ptr = (const char **) new_list;
2582 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2586 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2590 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2593 parm_table[parmnum].enum_list[i].name)) {
2595 parm_table[parmnum].
2600 if (!parm_table[parmnum].enum_list[i].name) {
2601 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2602 pszParmValue, pszParmName));
2612 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2613 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2614 /* we have to also unset FLAG_DEFAULT on aliases */
2615 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2616 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2618 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2619 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2626 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2627 const char *pszParmName, const char *pszParmValue)
2629 int parmnum = map_parameter(pszParmName);
2633 if (strchr(pszParmName, ':')) {
2634 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2636 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2640 /* if the flag has been set on the command line, then don't allow override,
2641 but don't report an error */
2642 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2646 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2648 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2649 pszParmName, pszParmValue, lp_ctx, true);
2652 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2653 struct loadparm_service *service,
2654 const char *pszParmName, const char *pszParmValue)
2658 int parmnum = map_parameter(pszParmName);
2661 if (strchr(pszParmName, ':')) {
2662 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2664 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2668 /* if the flag has been set on the command line, then don't allow override,
2669 but don't report an error */
2670 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2674 if (parm_table[parmnum].p_class == P_GLOBAL) {
2676 ("Global parameter %s found in service section!\n",
2680 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2682 if (!service->copymap)
2683 init_copymap(service);
2685 /* this handles the aliases - set the copymap for other
2686 * entries with the same data pointer */
2687 for (i = 0; parm_table[i].label; i++)
2688 if (parm_table[i].offset == parm_table[parmnum].offset &&
2689 parm_table[i].p_class == parm_table[parmnum].p_class)
2690 bitmap_clear(service->copymap, i);
2692 return set_variable(service, parmnum, parm_ptr, pszParmName,
2693 pszParmValue, lp_ctx, false);
2697 * Process a parameter.
2700 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2703 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2705 if (lp_ctx->bInGlobalSection)
2706 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2709 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2710 pszParmName, pszParmValue);
2714 variable argument do parameter
2716 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2717 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2718 const char *pszParmName, const char *fmt, ...)
2725 s = talloc_vasprintf(NULL, fmt, ap);
2727 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2734 set a parameter from the commandline - this is called from command line parameter
2735 parsing code. It sets the parameter then marks the parameter as unable to be modified
2736 by smb.conf processing
2738 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2739 const char *pszParmValue)
2744 if (lp_ctx->s3_fns) {
2745 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2748 parmnum = map_parameter(pszParmName);
2750 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2753 if (parmnum < 0 && strchr(pszParmName, ':')) {
2754 /* set a parametric option */
2755 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2756 pszParmValue, FLAG_CMDLINE);
2760 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2764 /* reset the CMDLINE flag in case this has been called before */
2765 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2767 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2771 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2773 /* we have to also set FLAG_CMDLINE on aliases */
2774 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2775 lp_ctx->flags[i] |= FLAG_CMDLINE;
2777 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2778 lp_ctx->flags[i] |= FLAG_CMDLINE;
2785 set a option from the commandline in 'a=b' format. Use to support --option
2787 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2792 s = talloc_strdup(NULL, option);
2805 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2811 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2814 * Print a parameter of the specified type.
2817 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2819 /* For the seperation of lists values that we print below */
2820 const char *list_sep = ", ";
2825 for (i = 0; p->enum_list[i].name; i++) {
2826 if (*(int *)ptr == p->enum_list[i].value) {
2828 p->enum_list[i].name);
2835 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2839 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2844 fprintf(f, "%d", *(int *)ptr);
2848 fprintf(f, "%c", *(char *)ptr);
2852 int val = *(int *)ptr;
2856 fprintf(f, "0%o", val);
2865 if ((char ***)ptr && *(char ***)ptr) {
2866 char **list = *(char ***)ptr;
2867 for (; *list; list++) {
2868 /* surround strings with whitespace in double quotes */
2869 if (*(list+1) == NULL) {
2870 /* last item, no extra separator */
2873 if ( strchr_m( *list, ' ' ) ) {
2874 fprintf(f, "\"%s\"%s", *list, list_sep);
2876 fprintf(f, "%s%s", *list, list_sep);
2884 if (*(char **)ptr) {
2885 fprintf(f, "%s", *(char **)ptr);
2894 * Check if two parameters are equal.
2897 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2902 return (*((bool *)ptr1) == *((bool *)ptr2));
2908 return (*((int *)ptr1) == *((int *)ptr2));
2911 return (*((char *)ptr1) == *((char *)ptr2));
2915 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2920 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2925 return (p1 == p2 || strequal(p1, p2));
2934 * Process a new section (service).
2936 * At this stage all sections are services.
2937 * Later we'll have special sections that permit server parameters to be set.
2938 * Returns True on success, False on failure.
2941 static bool do_section(const char *pszSectionName, void *userdata)
2943 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2945 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2946 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2949 /* if we've just struck a global section, note the fact. */
2950 lp_ctx->bInGlobalSection = isglobal;
2952 /* check for multiple global sections */
2953 if (lp_ctx->bInGlobalSection) {
2954 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2958 /* if we have a current service, tidy it up before moving on */
2961 if (lp_ctx->currentService != NULL)
2962 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2964 /* if all is still well, move to the next record in the services array */
2966 /* We put this here to avoid an odd message order if messages are */
2967 /* issued by the post-processing of a previous section. */
2968 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2970 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2973 DEBUG(0, ("Failed to add a new service\n"));
2983 * Determine if a particular base parameter is currently set to the default value.
2986 static bool is_default(struct loadparm_service *sDefault, int i)
2988 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2989 if (!defaults_saved)
2991 switch (parm_table[i].type) {
2994 return str_list_equal((const char **)parm_table[i].def.lvalue,
2995 (const char **)def_ptr);
2998 return strequal(parm_table[i].def.svalue,
3002 return parm_table[i].def.bvalue ==
3009 return parm_table[i].def.ivalue ==
3018 *Display the contents of the global structure.
3021 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3025 struct parmlist_entry *data;
3027 fprintf(f, "# Global parameters\n[global]\n");
3029 for (i = 0; parm_table[i].label; i++)
3030 if (parm_table[i].p_class == P_GLOBAL &&
3031 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3032 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3034 fprintf(f, "\t%s = ", parm_table[i].label);
3035 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3038 if (lp_ctx->globals->param_opt != NULL) {
3039 for (data = lp_ctx->globals->param_opt; data;
3040 data = data->next) {
3041 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3044 fprintf(f, "\t%s = %s\n", data->key, data->value);
3051 * Display the contents of a single services record.
3054 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3055 unsigned int *flags)
3058 struct parmlist_entry *data;
3060 if (pService != sDefault)
3061 fprintf(f, "\n[%s]\n", pService->szService);
3063 for (i = 0; parm_table[i].label; i++) {
3064 if (parm_table[i].p_class == P_LOCAL &&
3065 (*parm_table[i].label != '-') &&
3066 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3068 if (pService == sDefault) {
3069 if (flags && (flags[i] & FLAG_DEFAULT)) {
3072 if (defaults_saved) {
3073 if (is_default(sDefault, i)) {
3078 if (equal_parameter(parm_table[i].type,
3079 ((char *)pService) +
3080 parm_table[i].offset,
3081 ((char *)sDefault) +
3082 parm_table[i].offset))
3086 fprintf(f, "\t%s = ", parm_table[i].label);
3087 print_parameter(&parm_table[i],
3088 ((char *)pService) + parm_table[i].offset, f);
3092 if (pService->param_opt != NULL) {
3093 for (data = pService->param_opt; data; data = data->next) {
3094 fprintf(f, "\t%s = %s\n", data->key, data->value);
3099 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3100 struct loadparm_service *service,
3101 const char *parm_name, FILE * f)
3103 struct parm_struct *parm;
3106 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3111 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3113 print_parameter(parm, ptr, f);
3119 * Return info about the next parameter in a service.
3120 * snum==-1 gives the globals.
3121 * Return NULL when out of parameters.
3125 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3129 /* do the globals */
3130 for (; parm_table[*i].label; (*i)++) {
3131 if ((*parm_table[*i].label == '-'))
3135 && (parm_table[*i].offset ==
3136 parm_table[(*i) - 1].offset)
3137 && (parm_table[*i].p_class ==
3138 parm_table[(*i) - 1].p_class))
3141 return &parm_table[(*i)++];
3144 struct loadparm_service *pService = lp_ctx->services[snum];
3146 for (; parm_table[*i].label; (*i)++) {
3147 if (parm_table[*i].p_class == P_LOCAL &&
3148 (*parm_table[*i].label != '-') &&
3150 (parm_table[*i].offset !=
3151 parm_table[(*i) - 1].offset)))
3153 if (allparameters ||
3154 !equal_parameter(parm_table[*i].type,
3155 ((char *)pService) +
3156 parm_table[*i].offset,
3157 ((char *)lp_ctx->sDefault) +
3158 parm_table[*i].offset))
3160 return &parm_table[(*i)++];
3171 * Auto-load some home services.
3173 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3181 * Unload unused services.
3184 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3185 struct smbsrv_connection *smb,
3186 bool (*snumused) (struct smbsrv_connection *, int))
3189 for (i = 0; i < lp_ctx->iNumServices; i++) {
3190 if (lp_ctx->services[i] == NULL)
3193 if (!snumused || !snumused(smb, i)) {
3194 talloc_free(lp_ctx->services[i]);
3195 lp_ctx->services[i] = NULL;
3201 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3203 struct parmlist_entry *data;
3205 if (lp_ctx->refuse_free) {
3206 /* someone is trying to free the
3207 global_loadparm_context.
3208 We can't allow that. */
3212 if (lp_ctx->globals->param_opt != NULL) {
3213 struct parmlist_entry *next;
3214 for (data = lp_ctx->globals->param_opt; data; data=next) {
3216 if (data->priority & FLAG_CMDLINE) continue;
3217 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3226 * Initialise the global parameter structure.
3228 * Note that most callers should use loadparm_init_global() instead
3230 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3234 struct loadparm_context *lp_ctx;
3235 struct parmlist_entry *parm;
3238 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3242 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3243 lp_ctx->bInGlobalSection = true;
3244 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3245 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3247 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3248 lp_ctx->sDefault->bAvailable = true;
3249 lp_ctx->sDefault->bBrowseable = true;
3250 lp_ctx->sDefault->bRead_only = true;
3251 lp_ctx->sDefault->bMap_archive = true;
3252 lp_ctx->sDefault->iStrictLocking = true;
3253 lp_ctx->sDefault->bOpLocks = true;
3254 lp_ctx->sDefault->iCreate_mask = 0744;
3255 lp_ctx->sDefault->iCreate_force_mode = 0000;
3256 lp_ctx->sDefault->iDir_mask = 0755;
3257 lp_ctx->sDefault->iDir_force_mode = 0000;
3259 DEBUG(3, ("Initialising global parameters\n"));
3261 for (i = 0; parm_table[i].label; i++) {
3262 if ((parm_table[i].type == P_STRING ||
3263 parm_table[i].type == P_USTRING) &&
3264 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3266 if (parm_table[i].p_class == P_LOCAL) {
3267 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3269 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3271 *r = talloc_strdup(lp_ctx, "");
3275 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3276 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3277 talloc_free(logfile);
3279 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3281 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3283 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3284 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3285 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3287 /* options that can be set on the command line must be initialised via
3288 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3290 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3292 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3293 myname = get_myname(lp_ctx);
3294 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3295 talloc_free(myname);
3296 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3298 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3300 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3301 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3303 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
3304 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3305 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3306 /* the winbind method for domain controllers is for both RODC
3307 auth forwarding and for trusted domains */
3308 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3309 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3311 /* This hive should be dynamically generated by Samba using
3312 data from the sam, but for the moment leave it in a tdb to
3313 keep regedt32 from popping up an annoying dialog. */
3314 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3316 /* using UTF8 by default allows us to support all chars */
3317 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3319 /* Use codepage 850 as a default for the dos character set */
3320 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3323 * Allow the default PASSWD_CHAT to be overridden in local.h.
3325 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3327 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3328 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3329 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3330 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3331 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3333 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3334 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3335 "Samba %s", SAMBA_VERSION_STRING);
3337 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3339 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3340 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3341 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3343 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3344 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3345 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3346 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3347 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3348 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3349 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3350 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3351 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3352 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3353 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3354 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3355 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3357 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3358 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3359 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3360 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3361 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3362 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3363 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3364 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3366 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3368 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3369 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3371 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3372 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3374 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3375 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3376 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3377 #if _SAMBA_BUILD_ >= 4
3378 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3379 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3380 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3381 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3382 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3383 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3385 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3386 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3388 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3389 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3391 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3393 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3395 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3396 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3397 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3398 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3399 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3400 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3401 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3403 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3405 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3406 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3408 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3409 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3410 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3411 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3412 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3414 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3415 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3417 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3418 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3419 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3421 for (i = 0; parm_table[i].label; i++) {
3422 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3423 lp_ctx->flags[i] |= FLAG_DEFAULT;
3427 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3428 if (!(parm->priority & FLAG_CMDLINE)) {
3429 parm->priority |= FLAG_DEFAULT;
3437 * Initialise the global parameter structure.
3439 struct loadparm_context *loadparm_init_global(bool load_default)
3441 if (global_loadparm_context == NULL) {
3442 global_loadparm_context = loadparm_init(NULL);
3444 if (global_loadparm_context == NULL) {
3447 global_loadparm_context->global = true;
3448 if (load_default && !global_loadparm_context->loaded) {
3449 lpcfg_load_default(global_loadparm_context);
3451 global_loadparm_context->refuse_free = true;
3452 return global_loadparm_context;
3456 * Initialise the global parameter structure.
3458 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3459 const struct loadparm_s3_helpers *s3_fns)
3461 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3462 if (!loadparm_context) {
3465 loadparm_context->s3_fns = s3_fns;
3466 return loadparm_context;
3469 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3471 return lp_ctx->szConfigFile;
3474 const char *lp_default_path(void)
3476 if (getenv("SMB_CONF_PATH"))
3477 return getenv("SMB_CONF_PATH");
3479 return dyn_CONFIGFILE;
3483 * Update the internal state of a loadparm context after settings
3486 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3488 struct debug_settings settings;
3489 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3491 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3492 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3495 if (!lp_ctx->global) {
3499 panic_action = lp_ctx->globals->panic_action;
3501 reload_charcnv(lp_ctx);
3503 ZERO_STRUCT(settings);
3504 /* Add any more debug-related smb.conf parameters created in
3506 settings.timestamp_logs = true;
3507 debug_set_settings(&settings);
3509 /* FIXME: This is a bit of a hack, but we can't use a global, since
3510 * not everything that uses lp also uses the socket library */
3511 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3512 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3514 unsetenv("SOCKET_TESTNONBLOCK");
3520 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3524 path = lp_default_path();
3526 if (!file_exist(path)) {
3527 /* We allow the default smb.conf file to not exist,
3528 * basically the equivalent of an empty file. */
3529 return lpcfg_update(lp_ctx);
3532 return lpcfg_load(lp_ctx, path);
3536 * Load the services array from the services file.
3538 * Return True on success, False on failure.
3540 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3545 filename = talloc_strdup(lp_ctx, filename);
3547 lp_ctx->szConfigFile = filename;
3549 if (lp_ctx->s3_fns) {
3550 return lp_ctx->s3_fns->load(filename);
3553 lp_ctx->bInGlobalSection = true;
3554 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3555 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3557 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3559 /* We get sections first, so have to start 'behind' to make up */
3560 lp_ctx->currentService = NULL;
3561 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3563 /* finish up the last section */
3564 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3566 if (lp_ctx->currentService != NULL)
3567 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3569 bRetval = bRetval && lpcfg_update(lp_ctx);
3571 /* we do this unconditionally, so that it happens even
3572 for a missing smb.conf */
3573 reload_charcnv(lp_ctx);
3575 if (bRetval == true) {
3576 /* set this up so that any child python tasks will
3577 find the right smb.conf */
3578 setenv("SMB_CONF_PATH", filename, 1);
3580 /* set the context used by the lp_*() function
3582 global_loadparm_context = lp_ctx;
3583 lp_ctx->loaded = true;
3590 * Return the max number of services.
3593 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3595 if (lp_ctx->s3_fns) {
3596 return lp_ctx->s3_fns->get_numservices();
3599 return lp_ctx->iNumServices;
3603 * Display the contents of the services array in human-readable form.
3606 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3611 if (lp_ctx->s3_fns) {
3612 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3616 defaults_saved = !show_defaults;
3618 dump_globals(lp_ctx, f, show_defaults);
3620 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3622 for (iService = 0; iService < maxtoprint; iService++)
3623 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3627 * Display the contents of one service in human-readable form.
3629 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3631 if (service != NULL) {
3632 if (service->szService[0] == '\0')
3634 dump_a_service(service, sDefault, f, NULL);
3638 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3641 if (lp_ctx->s3_fns) {
3642 return lp_ctx->s3_fns->get_servicebynum(snum);
3645 return lp_ctx->services[snum];
3648 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3649 const char *service_name)
3654 if (lp_ctx->s3_fns) {
3655 return lp_ctx->s3_fns->get_service(service_name);
3658 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3659 if (lp_ctx->services[iService] &&
3660 lp_ctx->services[iService]->szService) {
3662 * The substitution here is used to support %U is
3665 serviceName = standard_sub_basic(
3666 lp_ctx->services[iService],
3667 lp_ctx->services[iService]->szService);
3668 if (strequal(serviceName, service_name)) {
3669 talloc_free(serviceName);
3670 return lp_ctx->services[iService];
3672 talloc_free(serviceName);
3676 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3680 const char *lpcfg_servicename(const struct loadparm_service *service)
3682 return lp_string((const char *)service->szService);
3686 * A useful volume label function.
3688 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3691 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3692 service->volume : sDefault->volume));
3694 return lpcfg_servicename(service);
3699 * If we are PDC then prefer us as DMB
3701 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3704 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3705 service->szPrintername : sDefault->szPrintername));
3706 if (ret == NULL || (ret != NULL && *ret == '\0'))
3707 ret = lpcfg_servicename(service);
3714 * Return the max print jobs per queue.
3716 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3718 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3719 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3720 maxjobs = PRINT_MAX_JOBID - 1;
3725 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3727 if (lp_ctx == NULL) {
3728 return get_iconv_handle();
3730 return lp_ctx->iconv_handle;
3733 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3735 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3736 if (!lp_ctx->global) {
3740 if (old_ic == NULL) {
3741 old_ic = global_iconv_handle;
3743 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3744 global_iconv_handle = lp_ctx->iconv_handle;
3747 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3749 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3752 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3754 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3757 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3759 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3762 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3764 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3767 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3769 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3772 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3774 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3775 if (settings == NULL)
3777 SMB_ASSERT(lp_ctx != NULL);
3778 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3779 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3783 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3785 if (lp_ctx->s3_fns) {
3786 return lp_ctx->s3_fns->server_role();
3789 return lp_find_server_role(lp_ctx->globals->server_role,
3790 lp_ctx->globals->security,
3791 lp_ctx->globals->domain_logons,
3792 (lp_ctx->globals->domain_master == true) ||
3793 (lp_ctx->globals->domain_master == Auto));
3796 int lpcfg_security(struct loadparm_context *lp_ctx)
3798 if (lp_ctx->s3_fns) {
3799 return lp_ctx->s3_fns->security();
3802 return lp_find_security(lp_ctx->globals->server_role,
3803 lp_ctx->globals->security);