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; \
88 #include "lib/param/param_global.h"
90 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
93 /* prototypes for the special type handlers */
94 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
95 const char *pszParmValue, char **ptr);
96 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
97 const char *pszParmValue, char **ptr);
98 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
99 const char *pszParmValue, char **ptr);
100 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
101 const char *pszParmValue, char **ptr);
102 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
103 const char *pszParmValue, char **ptr);
105 #include "lib/param/param_table.c"
107 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
108 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
110 static struct parm_struct parm_table[] = {
112 .label = "server role",
115 .offset = GLOBAL_VAR(server_role),
117 .enum_list = enum_server_role
120 .label = "domain logons",
123 .offset = GLOBAL_VAR(bDomainLogons),
125 .enum_list = enum_bool_auto
128 .label = "domain master",
131 .offset = GLOBAL_VAR(domain_master),
133 .enum_list = enum_bool_auto
136 .label = "dos charset",
139 .offset = GLOBAL_VAR(dos_charset),
144 .label = "unix charset",
147 .offset = GLOBAL_VAR(unix_charset),
152 .label = "ncalrpc dir",
155 .offset = GLOBAL_VAR(ncalrpc_dir),
163 .offset = LOCAL_VAR(comment),
166 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
172 .offset = LOCAL_VAR(szPath),
175 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
178 .label = "directory",
181 .offset = LOCAL_VAR(szPath),
187 .label = "workgroup",
190 .offset = GLOBAL_VAR(szWorkgroup),
193 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
199 .offset = GLOBAL_VAR(szRealm),
200 .special = handle_realm,
202 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
205 .label = "netbios name",
208 .offset = GLOBAL_VAR(szNetbiosName),
211 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
214 .label = "netbios aliases",
217 .offset = GLOBAL_VAR(szNetbiosAliases),
222 .label = "netbios scope",
225 .offset = GLOBAL_VAR(szNetbiosScope),
228 .flags = FLAG_ADVANCED,
231 .label = "server string",
234 .offset = GLOBAL_VAR(szServerString),
237 .flags = FLAG_BASIC | FLAG_ADVANCED,
240 .label = "interfaces",
243 .offset = GLOBAL_VAR(szInterfaces),
246 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
249 .label = "bind interfaces only",
252 .offset = GLOBAL_VAR(bBindInterfacesOnly),
255 .flags = FLAG_ADVANCED | FLAG_WIZARD,
258 .label = "ntvfs handler",
261 .offset = LOCAL_VAR(ntvfs_handler),
266 .label = "passdb backend",
269 .offset = GLOBAL_VAR(passdb_backend),
274 .label = "dcerpc endpoint servers",
277 .offset = GLOBAL_VAR(dcerpc_ep_servers),
282 .label = "server services",
285 .offset = GLOBAL_VAR(server_services),
294 .offset = GLOBAL_VAR(security),
296 .enum_list = enum_security
299 .label = "encrypt passwords",
302 .offset = GLOBAL_VAR(bEncryptPasswords),
307 .label = "null passwords",
310 .offset = GLOBAL_VAR(bNullPasswords),
313 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
316 .label = "obey pam restrictions",
319 .offset = GLOBAL_VAR(bObeyPamRestrictions),
322 .flags = FLAG_ADVANCED,
325 .label = "password server",
328 .offset = GLOBAL_VAR(szPasswordServer),
333 .label = "private dir",
336 .offset = GLOBAL_VAR(szPrivateDir),
341 .label = "passwd chat",
344 .offset = GLOBAL_VAR(szPasswdChat),
349 .label = "password level",
352 .offset = GLOBAL_VAR(pwordlevel),
357 .label = "lanman auth",
360 .offset = GLOBAL_VAR(bLanmanAuth),
363 .flags = FLAG_ADVANCED,
366 .label = "ntlm auth",
369 .offset = GLOBAL_VAR(bNTLMAuth),
372 .flags = FLAG_ADVANCED,
375 .label = "client NTLMv2 auth",
378 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
381 .flags = FLAG_ADVANCED,
384 .label = "client lanman auth",
387 .offset = GLOBAL_VAR(bClientLanManAuth),
390 .flags = FLAG_ADVANCED,
393 .label = "client plaintext auth",
396 .offset = GLOBAL_VAR(bClientPlaintextAuth),
399 .flags = FLAG_ADVANCED,
402 .label = "client use spnego principal",
405 .offset = GLOBAL_VAR(client_use_spnego_principal),
411 .label = "read only",
414 .offset = LOCAL_VAR(bRead_only),
420 .label = "create mask",
423 .offset = LOCAL_VAR(iCreate_mask),
428 .label = "force create mode",
431 .offset = LOCAL_VAR(iCreate_force_mode),
436 .label = "directory mask",
439 .offset = LOCAL_VAR(iDir_mask),
444 .label = "force directory mode",
447 .offset = LOCAL_VAR(iDir_force_mode),
453 .label = "hosts allow",
456 .offset = LOCAL_VAR(szHostsallow),
461 .label = "hosts deny",
464 .offset = LOCAL_VAR(szHostsdeny),
470 .label = "log level",
473 .offset = GLOBAL_VAR(loglevel),
474 .special = handle_debuglevel,
478 .label = "debuglevel",
481 .offset = GLOBAL_VAR(loglevel),
482 .special = handle_debuglevel,
489 .offset = GLOBAL_VAR(logfile),
490 .special = handle_logfile,
492 .flags = FLAG_ADVANCED,
496 .label = "smb ports",
499 .offset = GLOBAL_VAR(smb_ports),
507 .offset = GLOBAL_VAR(nbt_port),
512 .label = "dgram port",
515 .offset = GLOBAL_VAR(dgram_port),
520 .label = "cldap port",
523 .offset = GLOBAL_VAR(cldap_port),
528 .label = "krb5 port",
531 .offset = GLOBAL_VAR(krb5_port),
536 .label = "kpasswd port",
539 .offset = GLOBAL_VAR(kpasswd_port),
547 .offset = GLOBAL_VAR(web_port),
552 .label = "tls enabled",
555 .offset = GLOBAL_VAR(tls_enabled),
560 .label = "tls keyfile",
563 .offset = GLOBAL_VAR(tls_keyfile),
568 .label = "tls certfile",
571 .offset = GLOBAL_VAR(tls_certfile),
576 .label = "tls cafile",
579 .offset = GLOBAL_VAR(tls_cafile),
584 .label = "tls crlfile",
587 .offset = GLOBAL_VAR(tls_crlfile),
592 .label = "tls dh params file",
595 .offset = GLOBAL_VAR(tls_dhpfile),
600 .label = "large readwrite",
603 .offset = GLOBAL_VAR(bLargeReadwrite),
606 .flags = FLAG_ADVANCED,
609 .label = "server max protocol",
612 .offset = GLOBAL_VAR(srv_maxprotocol),
614 .enum_list = enum_protocol,
615 .flags = FLAG_ADVANCED,
618 .label = "max protocol",
621 .offset = GLOBAL_VAR(srv_maxprotocol),
623 .enum_list = enum_protocol,
624 .flags = FLAG_ADVANCED,
630 .offset = GLOBAL_VAR(srv_maxprotocol),
632 .enum_list = enum_protocol,
633 .flags = FLAG_ADVANCED,
636 .label = "server min protocol",
639 .offset = GLOBAL_VAR(srv_minprotocol),
641 .enum_list = enum_protocol,
642 .flags = FLAG_ADVANCED,
645 .label = "min protocol",
648 .offset = GLOBAL_VAR(srv_minprotocol),
650 .enum_list = enum_protocol,
651 .flags = FLAG_ADVANCED,
654 .label = "client max protocol",
657 .offset = GLOBAL_VAR(cli_maxprotocol),
659 .enum_list = enum_protocol
662 .label = "client min protocol",
665 .offset = GLOBAL_VAR(cli_minprotocol),
667 .enum_list = enum_protocol
673 .offset = GLOBAL_VAR(bUnicode),
681 .offset = GLOBAL_VAR(bReadRaw),
686 .label = "write raw",
689 .offset = GLOBAL_VAR(bWriteRaw),
694 .label = "disable netbios",
697 .offset = GLOBAL_VAR(bDisableNetbios),
703 .label = "nt status support",
706 .offset = GLOBAL_VAR(bNTStatusSupport),
715 .offset = GLOBAL_VAR(max_mux),
718 .flags = FLAG_ADVANCED,
724 .offset = GLOBAL_VAR(max_xmit),
727 .flags = FLAG_ADVANCED,
731 .label = "name resolve order",
734 .offset = GLOBAL_VAR(szNameResolveOrder),
739 .label = "max wins ttl",
742 .offset = GLOBAL_VAR(max_wins_ttl),
745 .flags = FLAG_ADVANCED,
748 .label = "min wins ttl",
751 .offset = GLOBAL_VAR(min_wins_ttl),
754 .flags = FLAG_ADVANCED,
757 .label = "time server",
760 .offset = GLOBAL_VAR(bTimeServer),
763 .flags = FLAG_ADVANCED,
766 .label = "unix extensions",
769 .offset = GLOBAL_VAR(bUnixExtensions),
772 .flags = FLAG_ADVANCED,
775 .label = "use spnego",
778 .offset = GLOBAL_VAR(bUseSpnego),
783 .label = "server signing",
786 .offset = GLOBAL_VAR(server_signing),
788 .enum_list = enum_smb_signing_vals,
789 .flags = FLAG_ADVANCED,
792 .label = "client signing",
795 .offset = GLOBAL_VAR(client_signing),
797 .enum_list = enum_smb_signing_vals
800 .label = "rpc big endian",
803 .offset = GLOBAL_VAR(bRpcBigEndian),
809 .label = "max connections",
812 .offset = LOCAL_VAR(iMaxConnections),
815 .flags = FLAG_ADVANCED | FLAG_SHARE,
818 .label = "paranoid server security",
821 .offset = GLOBAL_VAR(paranoid_server_security),
826 .label = "socket options",
829 .offset = GLOBAL_VAR(socket_options),
835 .label = "strict sync",
838 .offset = LOCAL_VAR(bStrictSync),
846 .offset = GLOBAL_VAR(bUseMmap),
849 .flags = FLAG_ADVANCED,
853 .label = "max print jobs",
856 .offset = LOCAL_VAR(iMaxPrintJobs),
861 .label = "printable",
864 .offset = LOCAL_VAR(bPrint_ok),
872 .offset = LOCAL_VAR(bPrint_ok),
878 .label = "printer name",
881 .offset = LOCAL_VAR(szPrintername),
884 .flags = FLAG_ADVANCED | FLAG_PRINT,
890 .offset = LOCAL_VAR(szPrintername),
897 .label = "map system",
900 .offset = LOCAL_VAR(bMap_system),
905 .label = "map hidden",
908 .offset = LOCAL_VAR(bMap_hidden),
913 .label = "map archive",
916 .offset = LOCAL_VAR(bMap_archive),
922 .label = "preferred master",
925 .offset = GLOBAL_VAR(bPreferredMaster),
927 .enum_list = enum_bool_auto,
928 .flags = FLAG_BASIC | FLAG_ADVANCED,
931 .label = "prefered master",
934 .offset = GLOBAL_VAR(bPreferredMaster),
936 .enum_list = enum_bool_auto,
940 .label = "local master",
943 .offset = GLOBAL_VAR(bLocalMaster),
948 .label = "browseable",
951 .offset = LOCAL_VAR(bBrowseable),
954 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
957 .label = "browsable",
960 .offset = LOCAL_VAR(bBrowseable),
966 .label = "dns proxy",
969 .offset = GLOBAL_VAR(bWINSdnsProxy),
974 .label = "wins server",
977 .offset = GLOBAL_VAR(szWINSservers),
980 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
983 .label = "wins support",
986 .offset = GLOBAL_VAR(bWINSsupport),
989 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
992 .label = "wins hook",
995 .offset = GLOBAL_VAR(szWINSHook),
998 .flags = FLAG_ADVANCED,
1002 .label = "csc policy",
1005 .offset = LOCAL_VAR(iCSCPolicy),
1007 .enum_list = enum_csc_policy,
1008 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1012 .label = "strict locking",
1015 .offset = LOCAL_VAR(iStrictLocking),
1023 .offset = LOCAL_VAR(bOpLocks),
1029 .label = "share backend",
1031 .p_class = P_GLOBAL,
1032 .offset = GLOBAL_VAR(szShareBackend),
1039 .p_class = P_GLOBAL,
1040 .offset = GLOBAL_VAR(szAutoServices),
1043 .flags = FLAG_ADVANCED,
1046 .label = "auto services",
1048 .p_class = P_GLOBAL,
1049 .offset = GLOBAL_VAR(szAutoServices),
1052 .flags = FLAG_ADVANCED,
1055 .label = "lock directory",
1057 .p_class = P_GLOBAL,
1058 .offset = GLOBAL_VAR(szLockDir),
1061 .flags = FLAG_ADVANCED,
1064 .label = "lock dir",
1066 .p_class = P_GLOBAL,
1067 .offset = GLOBAL_VAR(szLockDir),
1073 .label = "state directory",
1075 .p_class = P_GLOBAL,
1076 .offset = GLOBAL_VAR(szStateDir),
1079 .flags = FLAG_ADVANCED,
1082 .label = "cache directory",
1084 .p_class = P_GLOBAL,
1085 .offset = GLOBAL_VAR(szCacheDir),
1088 .flags = FLAG_ADVANCED,
1091 .label = "pid directory",
1093 .p_class = P_GLOBAL,
1094 .offset = GLOBAL_VAR(szPidDir),
1100 .label = "socket address",
1102 .p_class = P_GLOBAL,
1103 .offset = GLOBAL_VAR(szSocketAddress),
1111 .offset = LOCAL_VAR(szCopy),
1112 .special = handle_copy,
1120 .offset = LOCAL_VAR(szInclude),
1121 .special = handle_include,
1126 .label = "available",
1129 .offset = LOCAL_VAR(bAvailable),
1137 .offset = LOCAL_VAR(volume),
1140 .flags = FLAG_ADVANCED | FLAG_SHARE,
1146 .offset = LOCAL_VAR(fstype),
1152 .label = "panic action",
1154 .p_class = P_GLOBAL,
1155 .offset = GLOBAL_VAR(panic_action),
1161 .label = "msdfs root",
1164 .offset = LOCAL_VAR(bMSDfsRoot),
1169 .label = "host msdfs",
1171 .p_class = P_GLOBAL,
1172 .offset = GLOBAL_VAR(bHostMSDfs),
1175 .flags = FLAG_ADVANCED,
1178 .label = "winbind separator",
1180 .p_class = P_GLOBAL,
1181 .offset = GLOBAL_VAR(szWinbindSeparator),
1186 .label = "winbindd socket directory",
1188 .p_class = P_GLOBAL,
1189 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1192 .flags = FLAG_ADVANCED,
1195 .label = "winbindd privileged socket directory",
1197 .p_class = P_GLOBAL,
1198 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1201 .flags = FLAG_ADVANCED,
1204 .label = "winbind sealed pipes",
1206 .p_class = P_GLOBAL,
1207 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1210 .flags = FLAG_ADVANCED,
1213 .label = "template shell",
1215 .p_class = P_GLOBAL,
1216 .offset = GLOBAL_VAR(szTemplateShell),
1219 .flags = FLAG_ADVANCED,
1222 .label = "template homedir",
1224 .p_class = P_GLOBAL,
1225 .offset = GLOBAL_VAR(szTemplateHomedir),
1228 .flags = FLAG_ADVANCED,
1231 .label = "ntp signd socket directory",
1233 .p_class = P_GLOBAL,
1234 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1237 .flags = FLAG_ADVANCED,
1240 .label = "rndc command",
1242 .p_class = P_GLOBAL,
1243 .offset = GLOBAL_VAR(szRNDCCommand),
1246 .flags = FLAG_ADVANCED,
1249 .label = "dns update command",
1251 .p_class = P_GLOBAL,
1252 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1255 .flags = FLAG_ADVANCED,
1258 .label = "spn update command",
1260 .p_class = P_GLOBAL,
1261 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1264 .flags = FLAG_ADVANCED,
1267 .label = "samba kcc command",
1269 .p_class = P_GLOBAL,
1270 .offset = GLOBAL_VAR(szSambaKCCCommand),
1273 .flags = FLAG_ADVANCED,
1276 .label = "nsupdate command",
1278 .p_class = P_GLOBAL,
1279 .offset = GLOBAL_VAR(szNSUpdateCommand),
1282 .flags = FLAG_ADVANCED,
1285 .label = "allow dns updates",
1287 .p_class = P_GLOBAL,
1288 .offset = GLOBAL_VAR(allow_dns_updates),
1290 .enum_list = enum_dns_update_settings,
1291 .flags = FLAG_ADVANCED,
1294 .label = "dns forwarder",
1296 .p_class = P_GLOBAL,
1297 .offset = GLOBAL_VAR(dns_forwarder),
1300 .flags = FLAG_ADVANCED,
1303 .label = "dns recursive queries",
1305 .p_class = P_GLOBAL,
1306 .offset = GLOBAL_VAR(dns_recursive_queries),
1311 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1315 /* local variables */
1316 struct loadparm_context {
1317 const char *szConfigFile;
1318 struct loadparm_global *globals;
1319 struct loadparm_service **services;
1320 struct loadparm_service *sDefault;
1321 struct smb_iconv_handle *iconv_handle;
1323 struct loadparm_service *currentService;
1324 bool bInGlobalSection;
1326 struct file_lists *next;
1331 unsigned int flags[NUMPARAMETERS];
1334 bool global; /* Is this the global context, which may set
1335 * global variables such as debug level etc? */
1336 const struct loadparm_s3_helpers *s3_fns;
1340 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1342 if (lp_ctx->s3_fns) {
1343 return lp_ctx->s3_fns->get_default_loadparm_service();
1345 return lp_ctx->sDefault;
1349 * Convenience routine to grab string parameters into temporary memory
1350 * and run standard_sub_basic on them.
1352 * The buffers can be written to by
1353 * callers without affecting the source string.
1356 static const char *lp_string(const char *s)
1358 #if 0 /* until REWRITE done to make thread-safe */
1359 size_t len = s ? strlen(s) : 0;
1363 /* The follow debug is useful for tracking down memory problems
1364 especially if you have an inner loop that is calling a lp_*()
1365 function that returns a string. Perhaps this debug should be
1366 present all the time? */
1369 DEBUG(10, ("lp_string(%s)\n", s));
1372 #if 0 /* until REWRITE done to make thread-safe */
1374 lp_talloc = talloc_init("lp_talloc");
1376 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1384 strlcpy(ret, s, len);
1386 if (trim_string(ret, "\"", "\"")) {
1387 if (strchr(ret,'"') != NULL)
1388 strlcpy(ret, s, len);
1391 standard_sub_basic(ret,len+100);
1398 In this section all the functions that are used to access the
1399 parameters from the rest of the program are defined
1403 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1404 * for code compatibility between existing Samba4 and Samba3 code.
1407 /* this global context supports the lp_*() function varients */
1408 static struct loadparm_context *global_loadparm_context;
1410 #define lpcfg_default_service global_loadparm_context->sDefault
1411 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1413 #define FN_GLOBAL_STRING(fn_name,var_name) \
1414 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1415 if (lp_ctx == NULL) return NULL; \
1416 if (lp_ctx->s3_fns) { \
1417 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1418 return lp_ctx->s3_fns->fn_name(); \
1420 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1423 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1424 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1425 if (lp_ctx == NULL) return NULL; \
1426 if (lp_ctx->s3_fns) { \
1427 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1428 return lp_ctx->s3_fns->fn_name(); \
1430 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1433 #define FN_GLOBAL_LIST(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; \
1443 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1444 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1445 if (lp_ctx == NULL) return false; \
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; \
1453 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1454 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1455 if (lp_ctx->s3_fns) { \
1456 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1457 return lp_ctx->s3_fns->fn_name(); \
1459 return lp_ctx->globals->var_name; \
1462 /* Local parameters don't need the ->s3_fns because the struct
1463 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1465 #define FN_LOCAL_STRING(fn_name,val) \
1466 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1467 struct loadparm_service *sDefault) { \
1468 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1471 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1473 #define FN_LOCAL_LIST(fn_name,val) \
1474 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1475 struct loadparm_service *sDefault) {\
1476 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1479 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1481 #define FN_LOCAL_BOOL(fn_name,val) \
1482 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1483 struct loadparm_service *sDefault) { \
1484 return((service != NULL)? service->val : sDefault->val); \
1487 #define FN_LOCAL_INTEGER(fn_name,val) \
1488 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1489 struct loadparm_service *sDefault) { \
1490 return((service != NULL)? service->val : sDefault->val); \
1493 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1495 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1497 #define FN_LOCAL_CHAR(fn_name,val) \
1498 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1499 struct loadparm_service *sDefault) { \
1500 return((service != NULL)? service->val : sDefault->val); \
1503 #include "lib/param/param_functions.c"
1505 /* These functions remain only in lib/param for now */
1506 FN_GLOBAL_BOOL(readraw, bReadRaw)
1507 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1508 FN_GLOBAL_STRING(cachedir, szCacheDir)
1509 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1510 FN_GLOBAL_STRING(statedir, szStateDir)
1512 /* local prototypes */
1513 static int map_parameter(const char *pszParmName);
1514 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1515 const char *pszServiceName);
1516 static void copy_service(struct loadparm_service *pserviceDest,
1517 struct loadparm_service *pserviceSource,
1518 struct bitmap *pcopymapDest);
1519 static bool lpcfg_service_ok(struct loadparm_service *service);
1520 static bool do_section(const char *pszSectionName, void *);
1521 static void init_copymap(struct loadparm_service *pservice);
1523 /* This is a helper function for parametrical options support. */
1524 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1525 /* Actual parametrical functions are quite simple */
1526 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1527 struct loadparm_service *service,
1528 const char *type, const char *option)
1530 char *vfskey_tmp = NULL;
1531 char *vfskey = NULL;
1532 struct parmlist_entry *data;
1537 if (lp_ctx->s3_fns) {
1538 return lp_ctx->s3_fns->get_parametric(service, type, option);
1541 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1543 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1544 if (vfskey_tmp == NULL) return NULL;
1545 vfskey = strlower_talloc(NULL, vfskey_tmp);
1546 talloc_free(vfskey_tmp);
1549 if (strcmp(data->key, vfskey) == 0) {
1550 talloc_free(vfskey);
1556 if (service != NULL) {
1557 /* Try to fetch the same option but from globals */
1558 /* but only if we are not already working with globals */
1559 for (data = lp_ctx->globals->param_opt; data;
1560 data = data->next) {
1561 if (strcmp(data->key, vfskey) == 0) {
1562 talloc_free(vfskey);
1568 talloc_free(vfskey);
1575 * convenience routine to return int parameters.
1577 static int lp_int(const char *s)
1581 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1585 return strtol(s, NULL, 0);
1589 * convenience routine to return unsigned long parameters.
1591 static unsigned long lp_ulong(const char *s)
1595 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
1599 return strtoul(s, NULL, 0);
1603 * convenience routine to return unsigned long parameters.
1605 static long lp_long(const char *s)
1609 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
1613 return strtol(s, NULL, 0);
1617 * convenience routine to return unsigned long parameters.
1619 static double lp_double(const char *s)
1623 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1627 return strtod(s, NULL);
1631 * convenience routine to return boolean parameters.
1633 static bool lp_bool(const char *s)
1638 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1642 if (!set_boolean(s, &ret)) {
1643 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1652 * Return parametric option from a given service. Type is a part of option before ':'
1653 * Parametric option has following syntax: 'Type: option = value'
1654 * Returned value is allocated in 'lp_talloc' context
1657 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1658 struct loadparm_service *service, const char *type,
1661 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1664 return lp_string(value);
1670 * Return parametric option from a given service. Type is a part of option before ':'
1671 * Parametric option has following syntax: 'Type: option = value'
1672 * Returned value is allocated in 'lp_talloc' context
1675 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1676 struct loadparm_context *lp_ctx,
1677 struct loadparm_service *service,
1679 const char *option, const char *separator)
1681 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1684 return (const char **)str_list_make(mem_ctx, value, separator);
1690 * Return parametric option from a given service. Type is a part of option before ':'
1691 * Parametric option has following syntax: 'Type: option = value'
1694 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1695 struct loadparm_service *service, const char *type,
1696 const char *option, int default_v)
1698 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1701 return lp_int(value);
1707 * Return parametric option from a given service. Type is a part of
1708 * option before ':'.
1709 * Parametric option has following syntax: 'Type: option = value'.
1712 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1713 struct loadparm_service *service, const char *type,
1714 const char *option, int default_v)
1718 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1720 if (value && conv_str_size_error(value, &bval)) {
1721 if (bval <= INT_MAX) {
1730 * Return parametric option from a given service.
1731 * Type is a part of option before ':'
1732 * Parametric option has following syntax: 'Type: option = value'
1734 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1735 struct loadparm_service *service, const char *type,
1736 const char *option, unsigned long default_v)
1738 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1741 return lp_ulong(value);
1746 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
1747 struct loadparm_service *service, const char *type,
1748 const char *option, long default_v)
1750 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1753 return lp_long(value);
1758 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1759 struct loadparm_service *service, const char *type,
1760 const char *option, double default_v)
1762 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1765 return lp_double(value);
1771 * Return parametric option from a given service. Type is a part of option before ':'
1772 * Parametric option has following syntax: 'Type: option = value'
1775 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1776 struct loadparm_service *service, const char *type,
1777 const char *option, bool default_v)
1779 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1782 return lp_bool(value);
1789 * Initialise a service to the defaults.
1792 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1794 struct loadparm_service *pservice =
1795 talloc_zero(mem_ctx, struct loadparm_service);
1796 copy_service(pservice, sDefault, NULL);
1801 * Set a string value, deallocating any existing space, and allocing the space
1804 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1811 *dest = talloc_strdup(mem_ctx, src);
1812 if ((*dest) == NULL) {
1813 DEBUG(0,("Out of memory in string_set\n"));
1821 * Set a string value, deallocating any existing space, and allocing the space
1824 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1831 *dest = strupper_talloc(mem_ctx, src);
1832 if ((*dest) == NULL) {
1833 DEBUG(0,("Out of memory in string_set_upper\n"));
1843 * Add a new service to the services array initialising it with the given
1847 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1848 const struct loadparm_service *pservice,
1852 struct loadparm_service tservice;
1853 int num_to_alloc = lp_ctx->iNumServices + 1;
1854 struct parmlist_entry *data, *pdata;
1856 if (pservice == NULL) {
1857 pservice = lp_ctx->sDefault;
1860 tservice = *pservice;
1862 /* it might already exist */
1864 struct loadparm_service *service = getservicebyname(lp_ctx,
1866 if (service != NULL) {
1867 /* Clean all parametric options for service */
1868 /* They will be added during parsing again */
1869 data = service->param_opt;
1875 service->param_opt = NULL;
1880 /* find an invalid one */
1881 for (i = 0; i < lp_ctx->iNumServices; i++)
1882 if (lp_ctx->services[i] == NULL)
1885 /* if not, then create one */
1886 if (i == lp_ctx->iNumServices) {
1887 struct loadparm_service **tsp;
1889 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1892 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1895 lp_ctx->services = tsp;
1896 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1899 lp_ctx->iNumServices++;
1902 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1903 if (lp_ctx->services[i] == NULL) {
1904 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1907 copy_service(lp_ctx->services[i], &tservice, NULL);
1909 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1910 return lp_ctx->services[i];
1914 * Add a new home service, with the specified home directory, defaults coming
1915 * from service ifrom.
1918 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1919 const char *pszHomename,
1920 struct loadparm_service *default_service,
1921 const char *user, const char *pszHomedir)
1923 struct loadparm_service *service;
1925 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1927 if (service == NULL)
1930 if (!(*(default_service->szPath))
1931 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1932 service->szPath = talloc_strdup(service, pszHomedir);
1934 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1937 if (!(*(service->comment))) {
1938 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1940 service->bAvailable = default_service->bAvailable;
1941 service->bBrowseable = default_service->bBrowseable;
1943 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1944 pszHomename, user, service->szPath));
1950 * Add a new printer service, with defaults coming from service iFrom.
1953 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1954 const char *pszPrintername,
1955 struct loadparm_service *default_service)
1957 const char *comment = "From Printcap";
1958 struct loadparm_service *service;
1959 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1961 if (service == NULL)
1964 /* note that we do NOT default the availability flag to True - */
1965 /* we take it from the default service passed. This allows all */
1966 /* dynamic printers to be disabled by disabling the [printers] */
1967 /* entry (if/when the 'available' keyword is implemented!). */
1969 /* the printer name is set to the service name. */
1970 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
1971 lpcfg_string_set(service, &service->comment, comment);
1972 service->bBrowseable = default_service->bBrowseable;
1973 /* Printers cannot be read_only. */
1974 service->bRead_only = false;
1975 /* Printer services must be printable. */
1976 service->bPrint_ok = true;
1978 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1984 * Map a parameter's string representation to something we can use.
1985 * Returns False if the parameter string is not recognised, else TRUE.
1988 static int map_parameter(const char *pszParmName)
1992 if (*pszParmName == '-')
1995 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1996 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1999 /* Warn only if it isn't parametric option */
2000 if (strchr(pszParmName, ':') == NULL)
2001 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2002 /* We do return 'fail' for parametric options as well because they are
2003 stored in different storage
2010 return the parameter structure for a parameter
2012 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2016 if (lp_ctx->s3_fns) {
2017 return lp_ctx->s3_fns->get_parm_struct(name);
2020 parmnum = map_parameter(name);
2021 if (parmnum == -1) return NULL;
2022 return &parm_table[parmnum];
2026 return the parameter pointer for a parameter
2028 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2029 struct loadparm_service *service, struct parm_struct *parm)
2031 if (lp_ctx->s3_fns) {
2032 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2035 if (service == NULL) {
2036 if (parm->p_class == P_LOCAL)
2037 return ((char *)lp_ctx->sDefault)+parm->offset;
2038 else if (parm->p_class == P_GLOBAL)
2039 return ((char *)lp_ctx->globals)+parm->offset;
2042 return ((char *)service) + parm->offset;
2047 return the parameter pointer for a parameter
2049 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2053 if (lp_ctx->s3_fns) {
2054 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2056 return parm->flags & FLAG_CMDLINE;
2061 parmnum = map_parameter(name);
2062 if (parmnum == -1) return false;
2064 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2068 * Find a service by name. Otherwise works like get_service.
2071 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2072 const char *pszServiceName)
2076 if (lp_ctx->s3_fns) {
2077 return lp_ctx->s3_fns->get_service(pszServiceName);
2080 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2081 if (lp_ctx->services[iService] != NULL &&
2082 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2083 return lp_ctx->services[iService];
2090 * Copy a service structure to another.
2091 * If pcopymapDest is NULL then copy all fields
2094 static void copy_service(struct loadparm_service *pserviceDest,
2095 struct loadparm_service *pserviceSource,
2096 struct bitmap *pcopymapDest)
2099 bool bcopyall = (pcopymapDest == NULL);
2100 struct parmlist_entry *data, *pdata, *paramo;
2103 for (i = 0; parm_table[i].label; i++)
2104 if (parm_table[i].p_class == P_LOCAL &&
2105 (bcopyall || bitmap_query(pcopymapDest, i))) {
2107 ((char *)pserviceSource) + parm_table[i].offset;
2109 ((char *)pserviceDest) + parm_table[i].offset;
2111 switch (parm_table[i].type) {
2113 *(bool *)dest_ptr = *(bool *)src_ptr;
2120 *(int *)dest_ptr = *(int *)src_ptr;
2124 lpcfg_string_set(pserviceDest,
2130 lpcfg_string_set_upper(pserviceDest,
2135 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2136 *(const char ***)src_ptr);
2144 init_copymap(pserviceDest);
2145 if (pserviceSource->copymap)
2146 bitmap_copy(pserviceDest->copymap,
2147 pserviceSource->copymap);
2150 data = pserviceSource->param_opt;
2153 pdata = pserviceDest->param_opt;
2154 /* Traverse destination */
2156 /* If we already have same option, override it */
2157 if (strcmp(pdata->key, data->key) == 0) {
2158 talloc_free(pdata->value);
2159 pdata->value = talloc_strdup(pdata,
2164 pdata = pdata->next;
2167 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2170 paramo->key = talloc_strdup(paramo, data->key);
2171 paramo->value = talloc_strdup(paramo, data->value);
2172 DLIST_ADD(pserviceDest->param_opt, paramo);
2179 * Check a service for consistency. Return False if the service is in any way
2180 * incomplete or faulty, else True.
2182 static bool lpcfg_service_ok(struct loadparm_service *service)
2187 if (service->szService[0] == '\0') {
2188 DEBUG(0, ("The following message indicates an internal error:\n"));
2189 DEBUG(0, ("No service name in service entry.\n"));
2193 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2194 /* I can't see why you'd want a non-printable printer service... */
2195 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2196 if (!service->bPrint_ok) {
2197 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2198 service->szService));
2199 service->bPrint_ok = true;
2201 /* [printers] service must also be non-browsable. */
2202 if (service->bBrowseable)
2203 service->bBrowseable = false;
2206 /* If a service is flagged unavailable, log the fact at level 0. */
2207 if (!service->bAvailable)
2208 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2209 service->szService));
2215 /*******************************************************************
2216 Keep a linked list of all config files so we know when one has changed
2217 it's date and needs to be reloaded.
2218 ********************************************************************/
2220 static void add_to_file_list(struct loadparm_context *lp_ctx,
2221 const char *fname, const char *subfname)
2223 struct file_lists *f = lp_ctx->file_lists;
2226 if (f->name && !strcmp(f->name, fname))
2232 f = talloc(lp_ctx, struct file_lists);
2235 f->next = lp_ctx->file_lists;
2236 f->name = talloc_strdup(f, fname);
2241 f->subfname = talloc_strdup(f, subfname);
2246 lp_ctx->file_lists = f;
2247 f->modtime = file_modtime(subfname);
2249 time_t t = file_modtime(subfname);
2255 /*******************************************************************
2256 Check if a config file has changed date.
2257 ********************************************************************/
2258 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2260 struct file_lists *f;
2261 DEBUG(6, ("lp_file_list_changed()\n"));
2263 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2267 n2 = standard_sub_basic(lp_ctx, f->name);
2269 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2270 f->name, n2, ctime(&f->modtime)));
2272 mod_time = file_modtime(n2);
2274 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2275 DEBUGADD(6, ("file %s modified: %s\n", n2,
2277 f->modtime = mod_time;
2278 talloc_free(f->subfname);
2279 f->subfname = talloc_strdup(f, n2);
2286 /***************************************************************************
2287 Handle the "realm" parameter
2288 ***************************************************************************/
2290 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2291 const char *pszParmValue, char **ptr)
2293 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2295 talloc_free(lp_ctx->globals->szRealm_upper);
2296 talloc_free(lp_ctx->globals->szRealm_lower);
2298 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2299 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2304 /***************************************************************************
2305 Handle the include operation.
2306 ***************************************************************************/
2308 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2309 const char *pszParmValue, char **ptr)
2311 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2313 add_to_file_list(lp_ctx, pszParmValue, fname);
2315 lpcfg_string_set(lp_ctx, ptr, fname);
2317 if (file_exist(fname))
2318 return pm_process(fname, do_section, do_parameter, lp_ctx);
2320 DEBUG(2, ("Can't find include file %s\n", fname));
2325 /***************************************************************************
2326 Handle the interpretation of the copy parameter.
2327 ***************************************************************************/
2329 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2330 const char *pszParmValue, char **ptr)
2333 struct loadparm_service *serviceTemp;
2335 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2339 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2341 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2342 if (serviceTemp == lp_ctx->currentService) {
2343 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2345 copy_service(lp_ctx->currentService,
2347 lp_ctx->currentService->copymap);
2351 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2359 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2360 const char *pszParmValue, char **ptr)
2363 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2364 if (lp_ctx->global) {
2365 return debug_parse_levels(pszParmValue);
2370 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2371 const char *pszParmValue, char **ptr)
2373 debug_set_logfile(pszParmValue);
2374 if (lp_ctx->global) {
2375 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2380 /***************************************************************************
2381 Initialise a copymap.
2382 ***************************************************************************/
2384 static void init_copymap(struct loadparm_service *pservice)
2388 TALLOC_FREE(pservice->copymap);
2390 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2391 if (!pservice->copymap)
2393 ("Couldn't allocate copymap!! (size %d)\n",
2394 (int)NUMPARAMETERS));
2396 for (i = 0; i < NUMPARAMETERS; i++)
2397 bitmap_set(pservice->copymap, i);
2401 * Process a parametric option
2403 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2404 struct loadparm_service *service,
2405 const char *pszParmName,
2406 const char *pszParmValue, int flags)
2408 struct parmlist_entry *paramo, *data;
2410 TALLOC_CTX *mem_ctx;
2412 while (isspace((unsigned char)*pszParmName)) {
2416 name = strlower_talloc(lp_ctx, pszParmName);
2417 if (!name) return false;
2419 if (service == NULL) {
2420 data = lp_ctx->globals->param_opt;
2421 mem_ctx = lp_ctx->globals;
2423 data = service->param_opt;
2427 /* Traverse destination */
2428 for (paramo=data; paramo; paramo=paramo->next) {
2429 /* If we already have the option set, override it unless
2430 it was a command line option and the new one isn't */
2431 if (strcmp(paramo->key, name) == 0) {
2432 if ((paramo->priority & FLAG_CMDLINE) &&
2433 !(flags & FLAG_CMDLINE)) {
2438 talloc_free(paramo->value);
2439 paramo->value = talloc_strdup(paramo, pszParmValue);
2440 paramo->priority = flags;
2446 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2449 paramo->key = talloc_strdup(paramo, name);
2450 paramo->value = talloc_strdup(paramo, pszParmValue);
2451 paramo->priority = flags;
2452 if (service == NULL) {
2453 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2455 DLIST_ADD(service->param_opt, paramo);
2463 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2464 const char *pszParmName, const char *pszParmValue,
2465 struct loadparm_context *lp_ctx, bool on_globals)
2468 /* if it is a special case then go ahead */
2469 if (parm_table[parmnum].special) {
2471 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2476 goto mark_non_default;
2479 /* now switch on the type of variable it is */
2480 switch (parm_table[parmnum].type)
2484 if (!set_boolean(pszParmValue, &b)) {
2485 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2488 *(bool *)parm_ptr = b;
2494 if (!set_boolean(pszParmValue, &b)) {
2495 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2498 *(bool *)parm_ptr = !b;
2503 *(int *)parm_ptr = atoi(pszParmValue);
2507 *(char *)parm_ptr = *pszParmValue;
2511 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2517 if (conv_str_size_error(pszParmValue, &val)) {
2518 if (val <= INT_MAX) {
2519 *(int *)parm_ptr = (int)val;
2524 DEBUG(0,("lp_do_parameter(%s): value is not "
2525 "a valid size specifier!\n", pszParmValue));
2530 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2531 pszParmValue, NULL);
2535 char **new_list = str_list_make(mem_ctx,
2536 pszParmValue, NULL);
2537 for (i=0; new_list[i]; i++) {
2538 if (new_list[i][0] == '+' && new_list[i][1]) {
2539 if (!str_list_check(*(const char ***)parm_ptr,
2541 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2544 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2545 str_list_remove(*(const char ***)parm_ptr,
2549 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2550 pszParmName, pszParmValue));
2553 *(const char ***)parm_ptr = (const char **) new_list;
2560 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2564 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2568 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2571 parm_table[parmnum].enum_list[i].name)) {
2573 parm_table[parmnum].
2578 if (!parm_table[parmnum].enum_list[i].name) {
2579 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2580 pszParmValue, pszParmName));
2590 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2591 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2592 /* we have to also unset FLAG_DEFAULT on aliases */
2593 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2594 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2596 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2597 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2604 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2605 const char *pszParmName, const char *pszParmValue)
2607 int parmnum = map_parameter(pszParmName);
2611 if (strchr(pszParmName, ':')) {
2612 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2614 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2618 /* if the flag has been set on the command line, then don't allow override,
2619 but don't report an error */
2620 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2624 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2626 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2627 pszParmName, pszParmValue, lp_ctx, true);
2630 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2631 struct loadparm_service *service,
2632 const char *pszParmName, const char *pszParmValue)
2636 int parmnum = map_parameter(pszParmName);
2639 if (strchr(pszParmName, ':')) {
2640 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2642 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2646 /* if the flag has been set on the command line, then don't allow override,
2647 but don't report an error */
2648 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2652 if (parm_table[parmnum].p_class == P_GLOBAL) {
2654 ("Global parameter %s found in service section!\n",
2658 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2660 if (!service->copymap)
2661 init_copymap(service);
2663 /* this handles the aliases - set the copymap for other
2664 * entries with the same data pointer */
2665 for (i = 0; parm_table[i].label; i++)
2666 if (parm_table[i].offset == parm_table[parmnum].offset &&
2667 parm_table[i].p_class == parm_table[parmnum].p_class)
2668 bitmap_clear(service->copymap, i);
2670 return set_variable(service, parmnum, parm_ptr, pszParmName,
2671 pszParmValue, lp_ctx, false);
2675 * Process a parameter.
2678 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2681 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2683 if (lp_ctx->bInGlobalSection)
2684 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2687 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2688 pszParmName, pszParmValue);
2692 variable argument do parameter
2694 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2695 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2696 const char *pszParmName, const char *fmt, ...)
2703 s = talloc_vasprintf(NULL, fmt, ap);
2705 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2712 set a parameter from the commandline - this is called from command line parameter
2713 parsing code. It sets the parameter then marks the parameter as unable to be modified
2714 by smb.conf processing
2716 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2717 const char *pszParmValue)
2722 if (lp_ctx->s3_fns) {
2723 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2726 parmnum = map_parameter(pszParmName);
2728 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2731 if (parmnum < 0 && strchr(pszParmName, ':')) {
2732 /* set a parametric option */
2733 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2734 pszParmValue, FLAG_CMDLINE);
2738 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2742 /* reset the CMDLINE flag in case this has been called before */
2743 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2745 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2749 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2751 /* we have to also set FLAG_CMDLINE on aliases */
2752 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2753 lp_ctx->flags[i] |= FLAG_CMDLINE;
2755 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2756 lp_ctx->flags[i] |= FLAG_CMDLINE;
2763 set a option from the commandline in 'a=b' format. Use to support --option
2765 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2770 s = talloc_strdup(NULL, option);
2783 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2789 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2792 * Print a parameter of the specified type.
2795 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2797 /* For the seperation of lists values that we print below */
2798 const char *list_sep = ", ";
2803 for (i = 0; p->enum_list[i].name; i++) {
2804 if (*(int *)ptr == p->enum_list[i].value) {
2806 p->enum_list[i].name);
2813 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2817 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2822 fprintf(f, "%d", *(int *)ptr);
2826 fprintf(f, "%c", *(char *)ptr);
2830 int val = *(int *)ptr;
2834 fprintf(f, "0%o", val);
2843 if ((char ***)ptr && *(char ***)ptr) {
2844 char **list = *(char ***)ptr;
2845 for (; *list; list++) {
2846 /* surround strings with whitespace in double quotes */
2847 if (*(list+1) == NULL) {
2848 /* last item, no extra separator */
2851 if ( strchr_m( *list, ' ' ) ) {
2852 fprintf(f, "\"%s\"%s", *list, list_sep);
2854 fprintf(f, "%s%s", *list, list_sep);
2862 if (*(char **)ptr) {
2863 fprintf(f, "%s", *(char **)ptr);
2872 * Check if two parameters are equal.
2875 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2880 return (*((bool *)ptr1) == *((bool *)ptr2));
2886 return (*((int *)ptr1) == *((int *)ptr2));
2889 return (*((char *)ptr1) == *((char *)ptr2));
2893 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2898 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2903 return (p1 == p2 || strequal(p1, p2));
2912 * Process a new section (service).
2914 * At this stage all sections are services.
2915 * Later we'll have special sections that permit server parameters to be set.
2916 * Returns True on success, False on failure.
2919 static bool do_section(const char *pszSectionName, void *userdata)
2921 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2923 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2924 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2927 /* if we've just struck a global section, note the fact. */
2928 lp_ctx->bInGlobalSection = isglobal;
2930 /* check for multiple global sections */
2931 if (lp_ctx->bInGlobalSection) {
2932 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2936 /* if we have a current service, tidy it up before moving on */
2939 if (lp_ctx->currentService != NULL)
2940 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2942 /* if all is still well, move to the next record in the services array */
2944 /* We put this here to avoid an odd message order if messages are */
2945 /* issued by the post-processing of a previous section. */
2946 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2948 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2951 DEBUG(0, ("Failed to add a new service\n"));
2961 * Determine if a particular base parameter is currently set to the default value.
2964 static bool is_default(struct loadparm_service *sDefault, int i)
2966 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2967 if (!defaults_saved)
2969 switch (parm_table[i].type) {
2972 return str_list_equal((const char **)parm_table[i].def.lvalue,
2973 (const char **)def_ptr);
2976 return strequal(parm_table[i].def.svalue,
2980 return parm_table[i].def.bvalue ==
2987 return parm_table[i].def.ivalue ==
2996 *Display the contents of the global structure.
2999 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3003 struct parmlist_entry *data;
3005 fprintf(f, "# Global parameters\n[global]\n");
3007 for (i = 0; parm_table[i].label; i++)
3008 if (parm_table[i].p_class == P_GLOBAL &&
3009 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3010 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3012 fprintf(f, "\t%s = ", parm_table[i].label);
3013 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3016 if (lp_ctx->globals->param_opt != NULL) {
3017 for (data = lp_ctx->globals->param_opt; data;
3018 data = data->next) {
3019 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3022 fprintf(f, "\t%s = %s\n", data->key, data->value);
3029 * Display the contents of a single services record.
3032 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3033 unsigned int *flags)
3036 struct parmlist_entry *data;
3038 if (pService != sDefault)
3039 fprintf(f, "\n[%s]\n", pService->szService);
3041 for (i = 0; parm_table[i].label; i++) {
3042 if (parm_table[i].p_class == P_LOCAL &&
3043 (*parm_table[i].label != '-') &&
3044 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3046 if (pService == sDefault) {
3047 if (flags && (flags[i] & FLAG_DEFAULT)) {
3050 if (defaults_saved) {
3051 if (is_default(sDefault, i)) {
3056 if (equal_parameter(parm_table[i].type,
3057 ((char *)pService) +
3058 parm_table[i].offset,
3059 ((char *)sDefault) +
3060 parm_table[i].offset))
3064 fprintf(f, "\t%s = ", parm_table[i].label);
3065 print_parameter(&parm_table[i],
3066 ((char *)pService) + parm_table[i].offset, f);
3070 if (pService->param_opt != NULL) {
3071 for (data = pService->param_opt; data; data = data->next) {
3072 fprintf(f, "\t%s = %s\n", data->key, data->value);
3077 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3078 struct loadparm_service *service,
3079 const char *parm_name, FILE * f)
3081 struct parm_struct *parm;
3084 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3089 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3091 print_parameter(parm, ptr, f);
3097 * Return info about the next parameter in a service.
3098 * snum==-1 gives the globals.
3099 * Return NULL when out of parameters.
3103 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3107 /* do the globals */
3108 for (; parm_table[*i].label; (*i)++) {
3109 if ((*parm_table[*i].label == '-'))
3113 && (parm_table[*i].offset ==
3114 parm_table[(*i) - 1].offset)
3115 && (parm_table[*i].p_class ==
3116 parm_table[(*i) - 1].p_class))
3119 return &parm_table[(*i)++];
3122 struct loadparm_service *pService = lp_ctx->services[snum];
3124 for (; parm_table[*i].label; (*i)++) {
3125 if (parm_table[*i].p_class == P_LOCAL &&
3126 (*parm_table[*i].label != '-') &&
3128 (parm_table[*i].offset !=
3129 parm_table[(*i) - 1].offset)))
3131 if (allparameters ||
3132 !equal_parameter(parm_table[*i].type,
3133 ((char *)pService) +
3134 parm_table[*i].offset,
3135 ((char *)lp_ctx->sDefault) +
3136 parm_table[*i].offset))
3138 return &parm_table[(*i)++];
3149 * Auto-load some home services.
3151 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3159 * Unload unused services.
3162 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3163 struct smbsrv_connection *smb,
3164 bool (*snumused) (struct smbsrv_connection *, int))
3167 for (i = 0; i < lp_ctx->iNumServices; i++) {
3168 if (lp_ctx->services[i] == NULL)
3171 if (!snumused || !snumused(smb, i)) {
3172 talloc_free(lp_ctx->services[i]);
3173 lp_ctx->services[i] = NULL;
3179 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3181 struct parmlist_entry *data;
3183 if (lp_ctx->refuse_free) {
3184 /* someone is trying to free the
3185 global_loadparm_context.
3186 We can't allow that. */
3190 if (lp_ctx->globals->param_opt != NULL) {
3191 struct parmlist_entry *next;
3192 for (data = lp_ctx->globals->param_opt; data; data=next) {
3194 if (data->priority & FLAG_CMDLINE) continue;
3195 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3204 * Initialise the global parameter structure.
3206 * Note that most callers should use loadparm_init_global() instead
3208 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3212 struct loadparm_context *lp_ctx;
3213 struct parmlist_entry *parm;
3216 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3220 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3221 lp_ctx->bInGlobalSection = true;
3222 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3223 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3225 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3226 lp_ctx->sDefault->bAvailable = true;
3227 lp_ctx->sDefault->bBrowseable = true;
3228 lp_ctx->sDefault->bRead_only = true;
3229 lp_ctx->sDefault->bMap_archive = true;
3230 lp_ctx->sDefault->iStrictLocking = true;
3231 lp_ctx->sDefault->bOpLocks = true;
3232 lp_ctx->sDefault->iCreate_mask = 0744;
3233 lp_ctx->sDefault->iCreate_force_mode = 0000;
3234 lp_ctx->sDefault->iDir_mask = 0755;
3235 lp_ctx->sDefault->iDir_force_mode = 0000;
3237 DEBUG(3, ("Initialising global parameters\n"));
3239 for (i = 0; parm_table[i].label; i++) {
3240 if ((parm_table[i].type == P_STRING ||
3241 parm_table[i].type == P_USTRING) &&
3242 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3244 if (parm_table[i].p_class == P_LOCAL) {
3245 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3247 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3249 *r = talloc_strdup(lp_ctx, "");
3253 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3254 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3255 talloc_free(logfile);
3257 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3259 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3261 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3262 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3263 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3265 /* options that can be set on the command line must be initialised via
3266 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3268 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3270 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3271 myname = get_myname(lp_ctx);
3272 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3273 talloc_free(myname);
3274 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3276 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3278 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3279 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3281 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
3282 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3283 /* the winbind method for domain controllers is for both RODC
3284 auth forwarding and for trusted domains */
3285 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3286 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3288 /* This hive should be dynamically generated by Samba using
3289 data from the sam, but for the moment leave it in a tdb to
3290 keep regedt32 from popping up an annoying dialog. */
3291 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3293 /* using UTF8 by default allows us to support all chars */
3294 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3296 /* Use codepage 850 as a default for the dos character set */
3297 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3300 * Allow the default PASSWD_CHAT to be overridden in local.h.
3302 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3304 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3305 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3306 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3307 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3308 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3310 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3311 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3312 "Samba %s", SAMBA_VERSION_STRING);
3314 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3316 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3317 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3318 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3320 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3321 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3322 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3323 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3324 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3325 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3326 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3327 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3328 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3329 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3330 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3331 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3332 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3334 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3335 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3336 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3337 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3338 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3339 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3340 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3341 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3343 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3345 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3346 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3348 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3349 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3351 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3352 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3353 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3354 #if _SAMBA_BUILD_ >= 4
3355 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3356 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3357 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3358 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3359 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3360 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3362 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3363 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3365 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3366 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3368 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3370 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3372 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3373 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3374 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3375 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3376 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3377 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3378 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3380 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3382 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3383 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3385 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3386 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3387 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3388 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3389 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3391 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3392 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3394 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3395 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3396 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3398 for (i = 0; parm_table[i].label; i++) {
3399 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3400 lp_ctx->flags[i] |= FLAG_DEFAULT;
3404 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3405 if (!(parm->priority & FLAG_CMDLINE)) {
3406 parm->priority |= FLAG_DEFAULT;
3414 * Initialise the global parameter structure.
3416 struct loadparm_context *loadparm_init_global(bool load_default)
3418 if (global_loadparm_context == NULL) {
3419 global_loadparm_context = loadparm_init(NULL);
3421 if (global_loadparm_context == NULL) {
3424 global_loadparm_context->global = true;
3425 if (load_default && !global_loadparm_context->loaded) {
3426 lpcfg_load_default(global_loadparm_context);
3428 global_loadparm_context->refuse_free = true;
3429 return global_loadparm_context;
3433 * Initialise the global parameter structure.
3435 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3436 const struct loadparm_s3_helpers *s3_fns)
3438 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3439 if (!loadparm_context) {
3442 loadparm_context->s3_fns = s3_fns;
3443 return loadparm_context;
3446 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3448 return lp_ctx->szConfigFile;
3451 const char *lp_default_path(void)
3453 if (getenv("SMB_CONF_PATH"))
3454 return getenv("SMB_CONF_PATH");
3456 return dyn_CONFIGFILE;
3460 * Update the internal state of a loadparm context after settings
3463 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3465 struct debug_settings settings;
3466 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3468 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3469 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3472 if (!lp_ctx->global) {
3476 panic_action = lp_ctx->globals->panic_action;
3478 reload_charcnv(lp_ctx);
3480 ZERO_STRUCT(settings);
3481 /* Add any more debug-related smb.conf parameters created in
3483 settings.timestamp_logs = true;
3484 debug_set_settings(&settings);
3486 /* FIXME: This is a bit of a hack, but we can't use a global, since
3487 * not everything that uses lp also uses the socket library */
3488 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3489 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3491 unsetenv("SOCKET_TESTNONBLOCK");
3497 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3501 path = lp_default_path();
3503 if (!file_exist(path)) {
3504 /* We allow the default smb.conf file to not exist,
3505 * basically the equivalent of an empty file. */
3506 return lpcfg_update(lp_ctx);
3509 return lpcfg_load(lp_ctx, path);
3513 * Load the services array from the services file.
3515 * Return True on success, False on failure.
3517 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3522 filename = talloc_strdup(lp_ctx, filename);
3524 lp_ctx->szConfigFile = filename;
3526 if (lp_ctx->s3_fns) {
3527 return lp_ctx->s3_fns->load(filename);
3530 lp_ctx->bInGlobalSection = true;
3531 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3532 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3534 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3536 /* We get sections first, so have to start 'behind' to make up */
3537 lp_ctx->currentService = NULL;
3538 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3540 /* finish up the last section */
3541 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3543 if (lp_ctx->currentService != NULL)
3544 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3546 bRetval = bRetval && lpcfg_update(lp_ctx);
3548 /* we do this unconditionally, so that it happens even
3549 for a missing smb.conf */
3550 reload_charcnv(lp_ctx);
3552 if (bRetval == true) {
3553 /* set this up so that any child python tasks will
3554 find the right smb.conf */
3555 setenv("SMB_CONF_PATH", filename, 1);
3557 /* set the context used by the lp_*() function
3559 global_loadparm_context = lp_ctx;
3560 lp_ctx->loaded = true;
3567 * Return the max number of services.
3570 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3572 if (lp_ctx->s3_fns) {
3573 return lp_ctx->s3_fns->get_numservices();
3576 return lp_ctx->iNumServices;
3580 * Display the contents of the services array in human-readable form.
3583 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3588 if (lp_ctx->s3_fns) {
3589 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3593 defaults_saved = !show_defaults;
3595 dump_globals(lp_ctx, f, show_defaults);
3597 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3599 for (iService = 0; iService < maxtoprint; iService++)
3600 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3604 * Display the contents of one service in human-readable form.
3606 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3608 if (service != NULL) {
3609 if (service->szService[0] == '\0')
3611 dump_a_service(service, sDefault, f, NULL);
3615 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3618 if (lp_ctx->s3_fns) {
3619 return lp_ctx->s3_fns->get_servicebynum(snum);
3622 return lp_ctx->services[snum];
3625 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3626 const char *service_name)
3631 if (lp_ctx->s3_fns) {
3632 return lp_ctx->s3_fns->get_service(service_name);
3635 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3636 if (lp_ctx->services[iService] &&
3637 lp_ctx->services[iService]->szService) {
3639 * The substitution here is used to support %U is
3642 serviceName = standard_sub_basic(
3643 lp_ctx->services[iService],
3644 lp_ctx->services[iService]->szService);
3645 if (strequal(serviceName, service_name)) {
3646 talloc_free(serviceName);
3647 return lp_ctx->services[iService];
3649 talloc_free(serviceName);
3653 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3657 const char *lpcfg_servicename(const struct loadparm_service *service)
3659 return lp_string((const char *)service->szService);
3663 * A useful volume label function.
3665 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3668 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3669 service->volume : sDefault->volume));
3671 return lpcfg_servicename(service);
3676 * If we are PDC then prefer us as DMB
3678 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3681 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3682 service->szPrintername : sDefault->szPrintername));
3683 if (ret == NULL || (ret != NULL && *ret == '\0'))
3684 ret = lpcfg_servicename(service);
3691 * Return the max print jobs per queue.
3693 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3695 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3696 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3697 maxjobs = PRINT_MAX_JOBID - 1;
3702 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3704 if (lp_ctx == NULL) {
3705 return get_iconv_handle();
3707 return lp_ctx->iconv_handle;
3710 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3712 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3713 if (!lp_ctx->global) {
3717 if (old_ic == NULL) {
3718 old_ic = global_iconv_handle;
3720 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3721 global_iconv_handle = lp_ctx->iconv_handle;
3724 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3726 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3729 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3731 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3734 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3736 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3739 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3741 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3744 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3746 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3749 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3751 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3752 if (settings == NULL)
3754 SMB_ASSERT(lp_ctx != NULL);
3755 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3756 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3760 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3762 int domain_master = lpcfg__domain_master(lp_ctx);
3764 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3765 lpcfg__security(lp_ctx),
3766 lpcfg__domain_logons(lp_ctx),
3767 (domain_master == true) ||
3768 (domain_master == Auto));
3771 int lpcfg_security(struct loadparm_context *lp_ctx)
3773 return lp_find_security(lpcfg__server_role(lp_ctx),
3774 lpcfg__security(lp_ctx));