2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * This module provides suitable callback functions for the params
33 * module. It builds the internal table of service details which is
34 * then used by the rest of the server.
38 * 1) add it to the global or service structure definition
39 * 2) add it to the parm_table
40 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
41 * 4) If it's a global then initialise it in init_globals. If a local
42 * (ie. service) parameter then initialise it in the sDefault structure
46 * The configuration file is processed sequentially for speed. It is NOT
47 * accessed randomly as happens in 'real' Windows. For this reason, there
48 * is a fair bit of sequence-dependent code here - ie., code which assumes
49 * that certain things happen before others. In particular, the code which
50 * happens at the boundary between sections is delicately poised, so be
57 #include "dynconfig/dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "../lib/util/dlinklist.h"
62 #include "lib/param/param.h"
63 #include "lib/param/loadparm.h"
64 #include "auth/gensec/gensec.h"
66 #include "lib/util/bitmap.h"
67 #include "libcli/smb/smb_constants.h"
68 #include "source4/dns_server/dns_update.h"
70 #define standard_sub_basic talloc_strdup
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved = false;
75 #define LOADPARM_EXTRA_GLOBALS \
76 struct parmlist_entry *param_opt; \
91 #include "param_global.h"
93 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
96 /* prototypes for the special type handlers */
97 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
98 const char *pszParmValue, char **ptr);
99 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
100 const char *pszParmValue, char **ptr);
101 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
102 const char *pszParmValue, char **ptr);
103 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
104 const char *pszParmValue, char **ptr);
105 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
106 const char *pszParmValue, char **ptr);
108 #include "param_enums.c"
110 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
111 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
113 static struct parm_struct parm_table[] = {
115 .label = "server role",
118 .offset = GLOBAL_VAR(server_role),
120 .enum_list = enum_server_role
123 .label = "domain logons",
126 .offset = GLOBAL_VAR(domain_logons),
128 .enum_list = enum_bool_auto
131 .label = "domain master",
134 .offset = GLOBAL_VAR(domain_master),
136 .enum_list = enum_bool_auto
139 .label = "dos charset",
142 .offset = GLOBAL_VAR(dos_charset),
147 .label = "unix charset",
150 .offset = GLOBAL_VAR(unix_charset),
155 .label = "ncalrpc dir",
158 .offset = GLOBAL_VAR(ncalrpc_dir),
166 .offset = LOCAL_VAR(comment),
169 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
175 .offset = LOCAL_VAR(szPath),
178 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
181 .label = "directory",
184 .offset = LOCAL_VAR(szPath),
190 .label = "workgroup",
193 .offset = GLOBAL_VAR(szWorkgroup),
196 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
202 .offset = GLOBAL_VAR(szRealm),
203 .special = handle_realm,
205 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
208 .label = "netbios name",
211 .offset = GLOBAL_VAR(szNetbiosName),
214 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
217 .label = "netbios aliases",
220 .offset = GLOBAL_VAR(szNetbiosAliases),
225 .label = "netbios scope",
228 .offset = GLOBAL_VAR(szNetbiosScope),
231 .flags = FLAG_ADVANCED,
234 .label = "server string",
237 .offset = GLOBAL_VAR(szServerString),
240 .flags = FLAG_BASIC | FLAG_ADVANCED,
243 .label = "interfaces",
246 .offset = GLOBAL_VAR(szInterfaces),
249 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
252 .label = "bind interfaces only",
255 .offset = GLOBAL_VAR(bBindInterfacesOnly),
258 .flags = FLAG_ADVANCED | FLAG_WIZARD,
261 .label = "ntvfs handler",
264 .offset = LOCAL_VAR(ntvfs_handler),
269 .label = "ntptr providor",
272 .offset = GLOBAL_VAR(ntptr_providor),
277 .label = "passdb backend",
280 .offset = GLOBAL_VAR(passdb_backend),
285 .label = "dcerpc endpoint servers",
288 .offset = GLOBAL_VAR(dcerpc_ep_servers),
293 .label = "server services",
296 .offset = GLOBAL_VAR(server_services),
305 .offset = GLOBAL_VAR(security),
307 .enum_list = enum_security
310 .label = "encrypt passwords",
313 .offset = GLOBAL_VAR(bEncryptPasswords),
318 .label = "null passwords",
321 .offset = GLOBAL_VAR(bNullPasswords),
324 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
327 .label = "obey pam restrictions",
330 .offset = GLOBAL_VAR(bObeyPamRestrictions),
333 .flags = FLAG_ADVANCED,
336 .label = "password server",
339 .offset = GLOBAL_VAR(szPasswordServers),
344 .label = "private dir",
347 .offset = GLOBAL_VAR(szPrivateDir),
352 .label = "passwd chat",
355 .offset = GLOBAL_VAR(szPasswdChat),
360 .label = "password level",
363 .offset = GLOBAL_VAR(pwordlevel),
368 .label = "lanman auth",
371 .offset = GLOBAL_VAR(bLanmanAuth),
374 .flags = FLAG_ADVANCED,
377 .label = "ntlm auth",
380 .offset = GLOBAL_VAR(bNTLMAuth),
383 .flags = FLAG_ADVANCED,
386 .label = "client NTLMv2 auth",
389 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
392 .flags = FLAG_ADVANCED,
395 .label = "client lanman auth",
398 .offset = GLOBAL_VAR(bClientLanManAuth),
401 .flags = FLAG_ADVANCED,
404 .label = "client plaintext auth",
407 .offset = GLOBAL_VAR(bClientPlaintextAuth),
410 .flags = FLAG_ADVANCED,
413 .label = "client use spnego principal",
416 .offset = GLOBAL_VAR(client_use_spnego_principal),
422 .label = "read only",
425 .offset = LOCAL_VAR(bRead_only),
431 .label = "create mask",
434 .offset = LOCAL_VAR(iCreate_mask),
439 .label = "force create mode",
442 .offset = LOCAL_VAR(iCreate_force_mode),
447 .label = "directory mask",
450 .offset = LOCAL_VAR(iDir_mask),
455 .label = "force directory mode",
458 .offset = LOCAL_VAR(iDir_force_mode),
464 .label = "hosts allow",
467 .offset = LOCAL_VAR(szHostsallow),
472 .label = "hosts deny",
475 .offset = LOCAL_VAR(szHostsdeny),
481 .label = "log level",
484 .offset = GLOBAL_VAR(loglevel),
485 .special = handle_debuglevel,
489 .label = "debuglevel",
492 .offset = GLOBAL_VAR(loglevel),
493 .special = handle_debuglevel,
500 .offset = GLOBAL_VAR(logfile),
501 .special = handle_logfile,
503 .flags = FLAG_ADVANCED,
507 .label = "smb ports",
510 .offset = GLOBAL_VAR(smb_ports),
518 .offset = GLOBAL_VAR(nbt_port),
523 .label = "dgram port",
526 .offset = GLOBAL_VAR(dgram_port),
531 .label = "cldap port",
534 .offset = GLOBAL_VAR(cldap_port),
539 .label = "krb5 port",
542 .offset = GLOBAL_VAR(krb5_port),
547 .label = "kpasswd port",
550 .offset = GLOBAL_VAR(kpasswd_port),
558 .offset = GLOBAL_VAR(web_port),
563 .label = "tls enabled",
566 .offset = GLOBAL_VAR(tls_enabled),
571 .label = "tls keyfile",
574 .offset = GLOBAL_VAR(tls_keyfile),
579 .label = "tls certfile",
582 .offset = GLOBAL_VAR(tls_certfile),
587 .label = "tls cafile",
590 .offset = GLOBAL_VAR(tls_cafile),
595 .label = "tls crlfile",
598 .offset = GLOBAL_VAR(tls_crlfile),
603 .label = "tls dh params file",
606 .offset = GLOBAL_VAR(tls_dhpfile),
611 .label = "large readwrite",
614 .offset = GLOBAL_VAR(bLargeReadwrite),
617 .flags = FLAG_ADVANCED,
620 .label = "server max protocol",
623 .offset = GLOBAL_VAR(srv_maxprotocol),
625 .enum_list = enum_protocol
628 .label = "max protocol",
631 .offset = GLOBAL_VAR(srv_maxprotocol),
633 .enum_list = enum_protocol
639 .offset = GLOBAL_VAR(srv_maxprotocol),
641 .enum_list = enum_protocol,
642 .flags = FLAG_ADVANCED,
645 .label = "server min protocol",
648 .offset = GLOBAL_VAR(srv_minprotocol),
650 .enum_list = enum_protocol
653 .label = "min protocol",
656 .offset = GLOBAL_VAR(srv_minprotocol),
658 .enum_list = enum_protocol
661 .label = "client max protocol",
664 .offset = GLOBAL_VAR(cli_maxprotocol),
666 .enum_list = enum_protocol
669 .label = "client min protocol",
672 .offset = GLOBAL_VAR(cli_minprotocol),
674 .enum_list = enum_protocol
680 .offset = GLOBAL_VAR(bUnicode),
688 .offset = GLOBAL_VAR(bReadRaw),
693 .label = "write raw",
696 .offset = GLOBAL_VAR(bWriteRaw),
701 .label = "disable netbios",
704 .offset = GLOBAL_VAR(bDisableNetbios),
710 .label = "nt status support",
713 .offset = GLOBAL_VAR(bNTStatusSupport),
722 .offset = GLOBAL_VAR(max_mux),
725 .flags = FLAG_ADVANCED,
731 .offset = GLOBAL_VAR(max_xmit),
734 .flags = FLAG_ADVANCED,
738 .label = "name resolve order",
741 .offset = GLOBAL_VAR(szNameResolveOrder),
746 .label = "max wins ttl",
749 .offset = GLOBAL_VAR(max_wins_ttl),
752 .flags = FLAG_ADVANCED,
755 .label = "min wins ttl",
758 .offset = GLOBAL_VAR(min_wins_ttl),
761 .flags = FLAG_ADVANCED,
764 .label = "time server",
767 .offset = GLOBAL_VAR(bTimeServer),
770 .flags = FLAG_ADVANCED,
773 .label = "unix extensions",
776 .offset = GLOBAL_VAR(bUnixExtensions),
779 .flags = FLAG_ADVANCED,
782 .label = "use spnego",
785 .offset = GLOBAL_VAR(bUseSpnego),
790 .label = "server signing",
793 .offset = GLOBAL_VAR(server_signing),
795 .enum_list = enum_smb_signing_vals,
796 .flags = FLAG_ADVANCED,
799 .label = "client signing",
802 .offset = GLOBAL_VAR(client_signing),
804 .enum_list = enum_smb_signing_vals
807 .label = "rpc big endian",
810 .offset = GLOBAL_VAR(bRpcBigEndian),
816 .label = "max connections",
819 .offset = LOCAL_VAR(iMaxConnections),
822 .flags = FLAG_ADVANCED | FLAG_SHARE,
825 .label = "paranoid server security",
828 .offset = GLOBAL_VAR(paranoid_server_security),
833 .label = "socket options",
836 .offset = GLOBAL_VAR(socket_options),
842 .label = "strict sync",
845 .offset = LOCAL_VAR(bStrictSync),
853 .offset = GLOBAL_VAR(bUseMmap),
856 .flags = FLAG_ADVANCED,
859 .label = "case insensitive filesystem",
862 .offset = LOCAL_VAR(bCIFileSystem),
868 .label = "max print jobs",
871 .offset = LOCAL_VAR(iMaxPrintJobs),
876 .label = "printable",
879 .offset = LOCAL_VAR(bPrint_ok),
887 .offset = LOCAL_VAR(bPrint_ok),
893 .label = "printer name",
896 .offset = LOCAL_VAR(szPrintername),
899 .flags = FLAG_ADVANCED | FLAG_PRINT,
905 .offset = LOCAL_VAR(szPrintername),
912 .label = "map system",
915 .offset = LOCAL_VAR(bMap_system),
920 .label = "map hidden",
923 .offset = LOCAL_VAR(bMap_hidden),
928 .label = "map archive",
931 .offset = LOCAL_VAR(bMap_archive),
937 .label = "preferred master",
940 .offset = GLOBAL_VAR(bPreferredMaster),
942 .enum_list = enum_bool_auto,
943 .flags = FLAG_BASIC | FLAG_ADVANCED,
946 .label = "prefered master",
949 .offset = GLOBAL_VAR(bPreferredMaster),
951 .enum_list = enum_bool_auto,
955 .label = "local master",
958 .offset = GLOBAL_VAR(bLocalMaster),
963 .label = "browseable",
966 .offset = LOCAL_VAR(bBrowseable),
969 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
972 .label = "browsable",
975 .offset = LOCAL_VAR(bBrowseable),
981 .label = "dns proxy",
984 .offset = GLOBAL_VAR(bWINSdnsProxy),
989 .label = "wins server",
992 .offset = GLOBAL_VAR(szWINSservers),
997 .label = "wins support",
1000 .offset = GLOBAL_VAR(bWINSsupport),
1005 .label = "wins hook",
1007 .p_class = P_GLOBAL,
1008 .offset = GLOBAL_VAR(szWINSHook),
1011 .flags = FLAG_ADVANCED,
1015 .label = "csc policy",
1018 .offset = LOCAL_VAR(iCSCPolicy),
1020 .enum_list = enum_csc_policy,
1021 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1025 .label = "strict locking",
1028 .offset = LOCAL_VAR(iStrictLocking),
1036 .offset = LOCAL_VAR(bOpLocks),
1042 .label = "share backend",
1044 .p_class = P_GLOBAL,
1045 .offset = GLOBAL_VAR(szShareBackend),
1052 .p_class = P_GLOBAL,
1053 .offset = GLOBAL_VAR(szAutoServices),
1056 .flags = FLAG_ADVANCED,
1059 .label = "auto services",
1061 .p_class = P_GLOBAL,
1062 .offset = GLOBAL_VAR(szAutoServices),
1065 .flags = FLAG_ADVANCED,
1068 .label = "lock directory",
1070 .p_class = P_GLOBAL,
1071 .offset = GLOBAL_VAR(szLockDir),
1074 .flags = FLAG_ADVANCED,
1077 .label = "lock dir",
1079 .p_class = P_GLOBAL,
1080 .offset = GLOBAL_VAR(szLockDir),
1086 .label = "state directory",
1088 .p_class = P_GLOBAL,
1089 .offset = GLOBAL_VAR(szStateDir),
1092 .flags = FLAG_ADVANCED,
1095 .label = "cache directory",
1097 .p_class = P_GLOBAL,
1098 .offset = GLOBAL_VAR(szCacheDir),
1101 .flags = FLAG_ADVANCED,
1104 .label = "pid directory",
1106 .p_class = P_GLOBAL,
1107 .offset = GLOBAL_VAR(szPidDir),
1113 .label = "socket address",
1115 .p_class = P_GLOBAL,
1116 .offset = GLOBAL_VAR(szSocketAddress),
1124 .offset = LOCAL_VAR(szCopy),
1125 .special = handle_copy,
1133 .offset = LOCAL_VAR(szInclude),
1134 .special = handle_include,
1139 .label = "available",
1142 .offset = LOCAL_VAR(bAvailable),
1150 .offset = LOCAL_VAR(volume),
1153 .flags = FLAG_ADVANCED | FLAG_SHARE,
1159 .offset = LOCAL_VAR(fstype),
1165 .label = "panic action",
1167 .p_class = P_GLOBAL,
1168 .offset = GLOBAL_VAR(panic_action),
1174 .label = "msdfs root",
1177 .offset = LOCAL_VAR(bMSDfsRoot),
1182 .label = "host msdfs",
1184 .p_class = P_GLOBAL,
1185 .offset = GLOBAL_VAR(bHostMSDfs),
1188 .flags = FLAG_ADVANCED,
1191 .label = "winbind separator",
1193 .p_class = P_GLOBAL,
1194 .offset = GLOBAL_VAR(szWinbindSeparator),
1199 .label = "winbindd socket directory",
1201 .p_class = P_GLOBAL,
1202 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1205 .flags = FLAG_ADVANCED,
1208 .label = "winbindd privileged socket directory",
1210 .p_class = P_GLOBAL,
1211 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1214 .flags = FLAG_ADVANCED,
1217 .label = "winbind sealed pipes",
1219 .p_class = P_GLOBAL,
1220 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1223 .flags = FLAG_ADVANCED,
1226 .label = "template shell",
1228 .p_class = P_GLOBAL,
1229 .offset = GLOBAL_VAR(szTemplateShell),
1232 .flags = FLAG_ADVANCED,
1235 .label = "template homedir",
1237 .p_class = P_GLOBAL,
1238 .offset = GLOBAL_VAR(szTemplateHomedir),
1241 .flags = FLAG_ADVANCED,
1244 .label = "idmap trusted only",
1246 .p_class = P_GLOBAL,
1247 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1250 .flags = FLAG_ADVANCED,
1254 .label = "ntp signd socket directory",
1256 .p_class = P_GLOBAL,
1257 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1260 .flags = FLAG_ADVANCED,
1263 .label = "rndc command",
1265 .p_class = P_GLOBAL,
1266 .offset = GLOBAL_VAR(szRNDCCommand),
1269 .flags = FLAG_ADVANCED,
1272 .label = "dns update command",
1274 .p_class = P_GLOBAL,
1275 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1278 .flags = FLAG_ADVANCED,
1281 .label = "spn update command",
1283 .p_class = P_GLOBAL,
1284 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1287 .flags = FLAG_ADVANCED,
1290 .label = "samba kcc command",
1292 .p_class = P_GLOBAL,
1293 .offset = GLOBAL_VAR(szSambaKCCCommand),
1296 .flags = FLAG_ADVANCED,
1299 .label = "nsupdate command",
1301 .p_class = P_GLOBAL,
1302 .offset = GLOBAL_VAR(szNSUpdateCommand),
1305 .flags = FLAG_ADVANCED,
1308 .label = "allow dns updates",
1310 .p_class = P_GLOBAL,
1311 .offset = GLOBAL_VAR(allow_dns_updates),
1313 .enum_list = enum_dns_update_settings,
1314 .flags = FLAG_ADVANCED,
1317 .label = "dns forwarder",
1319 .p_class = P_GLOBAL,
1320 .offset = GLOBAL_VAR(dns_forwarder),
1323 .flags = FLAG_ADVANCED,
1326 .label = "dns recursive queries",
1328 .p_class = P_GLOBAL,
1329 .offset = GLOBAL_VAR(dns_recursive_queries),
1334 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1338 /* local variables */
1339 struct loadparm_context {
1340 const char *szConfigFile;
1341 struct loadparm_global *globals;
1342 struct loadparm_service **services;
1343 struct loadparm_service *sDefault;
1344 struct smb_iconv_handle *iconv_handle;
1346 struct loadparm_service *currentService;
1347 bool bInGlobalSection;
1349 struct file_lists *next;
1354 unsigned int flags[NUMPARAMETERS];
1357 bool global; /* Is this the global context, which may set
1358 * global variables such as debug level etc? */
1359 const struct loadparm_s3_context *s3_fns;
1363 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1365 if (lp_ctx->s3_fns) {
1366 return lp_ctx->s3_fns->get_default_loadparm_service();
1368 return lp_ctx->sDefault;
1372 * Convenience routine to grab string parameters into temporary memory
1373 * and run standard_sub_basic on them.
1375 * The buffers can be written to by
1376 * callers without affecting the source string.
1379 static const char *lp_string(const char *s)
1381 #if 0 /* until REWRITE done to make thread-safe */
1382 size_t len = s ? strlen(s) : 0;
1386 /* The follow debug is useful for tracking down memory problems
1387 especially if you have an inner loop that is calling a lp_*()
1388 function that returns a string. Perhaps this debug should be
1389 present all the time? */
1392 DEBUG(10, ("lp_string(%s)\n", s));
1395 #if 0 /* until REWRITE done to make thread-safe */
1397 lp_talloc = talloc_init("lp_talloc");
1399 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1407 strlcpy(ret, s, len);
1409 if (trim_string(ret, "\"", "\"")) {
1410 if (strchr(ret,'"') != NULL)
1411 strlcpy(ret, s, len);
1414 standard_sub_basic(ret,len+100);
1421 In this section all the functions that are used to access the
1422 parameters from the rest of the program are defined
1426 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1427 * for code compatibility between existing Samba4 and Samba3 code.
1430 /* this global context supports the lp_*() function varients */
1431 static struct loadparm_context *global_loadparm_context;
1433 #define lpcfg_default_service global_loadparm_context->sDefault
1434 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1436 #define FN_GLOBAL_STRING(fn_name,var_name) \
1437 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1438 if (lp_ctx == NULL) return NULL; \
1439 if (lp_ctx->s3_fns) { \
1440 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1441 return lp_ctx->s3_fns->fn_name(); \
1443 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1446 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1447 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1448 if (lp_ctx == NULL) return NULL; \
1449 if (lp_ctx->s3_fns) { \
1450 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1451 return lp_ctx->s3_fns->fn_name(); \
1453 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1456 #define FN_GLOBAL_LIST(fn_name,var_name) \
1457 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1458 if (lp_ctx == NULL) return NULL; \
1459 if (lp_ctx->s3_fns) { \
1460 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1461 return lp_ctx->s3_fns->fn_name(); \
1463 return lp_ctx->globals->var_name; \
1466 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1467 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1468 if (lp_ctx == NULL) return false; \
1469 if (lp_ctx->s3_fns) { \
1470 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1471 return lp_ctx->s3_fns->fn_name(); \
1473 return lp_ctx->globals->var_name; \
1476 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1477 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1478 if (lp_ctx->s3_fns) { \
1479 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1480 return lp_ctx->s3_fns->fn_name(); \
1482 return lp_ctx->globals->var_name; \
1485 /* Local parameters don't need the ->s3_fns because the struct
1486 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1488 #define FN_LOCAL_STRING(fn_name,val) \
1489 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1490 struct loadparm_service *sDefault) { \
1491 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1494 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1496 #define FN_LOCAL_LIST(fn_name,val) \
1497 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1498 struct loadparm_service *sDefault) {\
1499 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1502 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1504 #define FN_LOCAL_BOOL(fn_name,val) \
1505 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1506 struct loadparm_service *sDefault) { \
1507 return((service != NULL)? service->val : sDefault->val); \
1510 #define FN_LOCAL_INTEGER(fn_name,val) \
1511 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1512 struct loadparm_service *sDefault) { \
1513 return((service != NULL)? service->val : sDefault->val); \
1516 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1518 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1520 #define FN_LOCAL_CHAR(fn_name,val) \
1521 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1522 struct loadparm_service *sDefault) { \
1523 return((service != NULL)? service->val : sDefault->val); \
1526 #include "lib/param/param_functions.c"
1528 FN_GLOBAL_LIST(smb_ports, smb_ports)
1529 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1530 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1531 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1532 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1533 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1534 FN_GLOBAL_INTEGER(web_port, web_port)
1535 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1536 FN_GLOBAL_STRING(logfile, logfile)
1537 FN_GLOBAL_STRING(share_backend, szShareBackend)
1538 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1539 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1540 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1541 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1542 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1543 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1544 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1545 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1546 FN_GLOBAL_STRING(serverstring, szServerString)
1547 FN_GLOBAL_STRING(lockdir, szLockDir)
1548 FN_GLOBAL_STRING(statedir, szStateDir)
1549 FN_GLOBAL_STRING(cachedir, szCacheDir)
1550 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1551 FN_GLOBAL_STRING(dos_charset, dos_charset)
1552 FN_GLOBAL_STRING(unix_charset, unix_charset)
1553 FN_GLOBAL_STRING(piddir, szPidDir)
1554 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1555 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1556 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1557 FN_GLOBAL_LIST(samba_kcc_command, szSambaKCCCommand)
1558 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1559 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1560 FN_GLOBAL_LIST(server_services, server_services)
1561 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1562 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1563 FN_GLOBAL_STRING(auto_services, szAutoServices)
1564 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1565 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1566 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1567 FN_GLOBAL_STRING(realm, szRealm_upper)
1568 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1569 FN_GLOBAL_STRING(socket_options, socket_options)
1570 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1571 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1572 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1573 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1574 FN_GLOBAL_LIST(interfaces, szInterfaces)
1575 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1576 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1577 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1578 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1579 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1580 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1581 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1582 FN_GLOBAL_BOOL(readraw, bReadRaw)
1583 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1584 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1585 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1586 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1587 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1588 FN_GLOBAL_BOOL(time_server, bTimeServer)
1589 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1590 FN_GLOBAL_BOOL(unicode, bUnicode)
1591 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1592 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1593 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1594 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1595 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1596 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1597 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1598 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1599 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1600 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1601 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1602 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1603 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1604 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1605 FN_GLOBAL_INTEGER(maxmux, max_mux)
1606 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1607 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1608 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1609 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1610 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1611 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1612 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1614 FN_GLOBAL_INTEGER(allow_dns_updates, allow_dns_updates)
1615 FN_GLOBAL_CONST_STRING(dns_forwarder, dns_forwarder)
1616 FN_GLOBAL_BOOL(dns_recursive_queries, dns_recursive_queries)
1618 FN_GLOBAL_INTEGER(server_signing, server_signing)
1619 FN_GLOBAL_INTEGER(client_signing, client_signing)
1621 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1623 /* local prototypes */
1624 static int map_parameter(const char *pszParmName);
1625 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1626 const char *pszServiceName);
1627 static void copy_service(struct loadparm_service *pserviceDest,
1628 struct loadparm_service *pserviceSource,
1629 struct bitmap *pcopymapDest);
1630 static bool lpcfg_service_ok(struct loadparm_service *service);
1631 static bool do_section(const char *pszSectionName, void *);
1632 static void init_copymap(struct loadparm_service *pservice);
1634 /* This is a helper function for parametrical options support. */
1635 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1636 /* Actual parametrical functions are quite simple */
1637 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1638 struct loadparm_service *service,
1639 const char *type, const char *option)
1641 char *vfskey_tmp = NULL;
1642 char *vfskey = NULL;
1643 struct parmlist_entry *data;
1648 if (lp_ctx->s3_fns) {
1649 return lp_ctx->s3_fns->get_parametric(service, type, option);
1652 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1654 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1655 if (vfskey_tmp == NULL) return NULL;
1656 vfskey = strlower_talloc(NULL, vfskey_tmp);
1657 talloc_free(vfskey_tmp);
1660 if (strcmp(data->key, vfskey) == 0) {
1661 talloc_free(vfskey);
1667 if (service != NULL) {
1668 /* Try to fetch the same option but from globals */
1669 /* but only if we are not already working with globals */
1670 for (data = lp_ctx->globals->param_opt; data;
1671 data = data->next) {
1672 if (strcmp(data->key, vfskey) == 0) {
1673 talloc_free(vfskey);
1679 talloc_free(vfskey);
1686 * convenience routine to return int parameters.
1688 static int lp_int(const char *s)
1692 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1696 return strtol(s, NULL, 0);
1700 * convenience routine to return unsigned long parameters.
1702 static int lp_ulong(const char *s)
1706 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1710 return strtoul(s, NULL, 0);
1714 * convenience routine to return unsigned long parameters.
1716 static double lp_double(const char *s)
1720 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1724 return strtod(s, NULL);
1728 * convenience routine to return boolean parameters.
1730 static bool lp_bool(const char *s)
1735 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1739 if (!set_boolean(s, &ret)) {
1740 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1749 * Return parametric option from a given service. Type is a part of option before ':'
1750 * Parametric option has following syntax: 'Type: option = value'
1751 * Returned value is allocated in 'lp_talloc' context
1754 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1755 struct loadparm_service *service, const char *type,
1758 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1761 return lp_string(value);
1767 * Return parametric option from a given service. Type is a part of option before ':'
1768 * Parametric option has following syntax: 'Type: option = value'
1769 * Returned value is allocated in 'lp_talloc' context
1772 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1773 struct loadparm_context *lp_ctx,
1774 struct loadparm_service *service,
1776 const char *option, const char *separator)
1778 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1781 return (const char **)str_list_make(mem_ctx, value, separator);
1787 * Return parametric option from a given service. Type is a part of option before ':'
1788 * Parametric option has following syntax: 'Type: option = value'
1791 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1792 struct loadparm_service *service, const char *type,
1793 const char *option, int default_v)
1795 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1798 return lp_int(value);
1804 * Return parametric option from a given service. Type is a part of
1805 * option before ':'.
1806 * Parametric option has following syntax: 'Type: option = value'.
1809 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1810 struct loadparm_service *service, const char *type,
1811 const char *option, int default_v)
1815 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1817 if (value && conv_str_size_error(value, &bval)) {
1818 if (bval <= INT_MAX) {
1827 * Return parametric option from a given service.
1828 * Type is a part of option before ':'
1829 * Parametric option has following syntax: 'Type: option = value'
1831 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1832 struct loadparm_service *service, const char *type,
1833 const char *option, unsigned long default_v)
1835 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1838 return lp_ulong(value);
1844 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1845 struct loadparm_service *service, const char *type,
1846 const char *option, double default_v)
1848 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1851 return lp_double(value);
1857 * Return parametric option from a given service. Type is a part of option before ':'
1858 * Parametric option has following syntax: 'Type: option = value'
1861 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1862 struct loadparm_service *service, const char *type,
1863 const char *option, bool default_v)
1865 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1868 return lp_bool(value);
1875 * Initialise a service to the defaults.
1878 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1880 struct loadparm_service *pservice =
1881 talloc_zero(mem_ctx, struct loadparm_service);
1882 copy_service(pservice, sDefault, NULL);
1887 * Set a string value, deallocating any existing space, and allocing the space
1890 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1897 *dest = talloc_strdup(mem_ctx, src);
1898 if ((*dest) == NULL) {
1899 DEBUG(0,("Out of memory in string_set\n"));
1907 * Set a string value, deallocating any existing space, and allocing the space
1910 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1917 *dest = strupper_talloc(mem_ctx, src);
1918 if ((*dest) == NULL) {
1919 DEBUG(0,("Out of memory in string_set_upper\n"));
1929 * Add a new service to the services array initialising it with the given
1933 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1934 const struct loadparm_service *pservice,
1938 struct loadparm_service tservice;
1939 int num_to_alloc = lp_ctx->iNumServices + 1;
1940 struct parmlist_entry *data, *pdata;
1942 if (pservice == NULL) {
1943 pservice = lp_ctx->sDefault;
1946 tservice = *pservice;
1948 /* it might already exist */
1950 struct loadparm_service *service = getservicebyname(lp_ctx,
1952 if (service != NULL) {
1953 /* Clean all parametric options for service */
1954 /* They will be added during parsing again */
1955 data = service->param_opt;
1961 service->param_opt = NULL;
1966 /* find an invalid one */
1967 for (i = 0; i < lp_ctx->iNumServices; i++)
1968 if (lp_ctx->services[i] == NULL)
1971 /* if not, then create one */
1972 if (i == lp_ctx->iNumServices) {
1973 struct loadparm_service **tsp;
1975 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1978 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1981 lp_ctx->services = tsp;
1982 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1985 lp_ctx->iNumServices++;
1988 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1989 if (lp_ctx->services[i] == NULL) {
1990 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1993 copy_service(lp_ctx->services[i], &tservice, NULL);
1995 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1996 return lp_ctx->services[i];
2000 * Add a new home service, with the specified home directory, defaults coming
2001 * from service ifrom.
2004 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
2005 const char *pszHomename,
2006 struct loadparm_service *default_service,
2007 const char *user, const char *pszHomedir)
2009 struct loadparm_service *service;
2011 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
2013 if (service == NULL)
2016 if (!(*(default_service->szPath))
2017 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
2018 service->szPath = talloc_strdup(service, pszHomedir);
2020 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
2023 if (!(*(service->comment))) {
2024 service->comment = talloc_asprintf(service, "Home directory of %s", user);
2026 service->bAvailable = default_service->bAvailable;
2027 service->bBrowseable = default_service->bBrowseable;
2029 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2030 pszHomename, user, service->szPath));
2036 * Add a new printer service, with defaults coming from service iFrom.
2039 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
2040 const char *pszPrintername,
2041 struct loadparm_service *default_service)
2043 const char *comment = "From Printcap";
2044 struct loadparm_service *service;
2045 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2047 if (service == NULL)
2050 /* note that we do NOT default the availability flag to True - */
2051 /* we take it from the default service passed. This allows all */
2052 /* dynamic printers to be disabled by disabling the [printers] */
2053 /* entry (if/when the 'available' keyword is implemented!). */
2055 /* the printer name is set to the service name. */
2056 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
2057 lpcfg_string_set(service, &service->comment, comment);
2058 service->bBrowseable = default_service->bBrowseable;
2059 /* Printers cannot be read_only. */
2060 service->bRead_only = false;
2061 /* Printer services must be printable. */
2062 service->bPrint_ok = true;
2064 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2070 * Map a parameter's string representation to something we can use.
2071 * Returns False if the parameter string is not recognised, else TRUE.
2074 static int map_parameter(const char *pszParmName)
2078 if (*pszParmName == '-')
2081 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2082 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2085 /* Warn only if it isn't parametric option */
2086 if (strchr(pszParmName, ':') == NULL)
2087 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2088 /* We do return 'fail' for parametric options as well because they are
2089 stored in different storage
2096 return the parameter structure for a parameter
2098 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2102 if (lp_ctx->s3_fns) {
2103 return lp_ctx->s3_fns->get_parm_struct(name);
2106 parmnum = map_parameter(name);
2107 if (parmnum == -1) return NULL;
2108 return &parm_table[parmnum];
2112 return the parameter pointer for a parameter
2114 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2115 struct loadparm_service *service, struct parm_struct *parm)
2117 if (lp_ctx->s3_fns) {
2118 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2121 if (service == NULL) {
2122 if (parm->p_class == P_LOCAL)
2123 return ((char *)lp_ctx->sDefault)+parm->offset;
2124 else if (parm->p_class == P_GLOBAL)
2125 return ((char *)lp_ctx->globals)+parm->offset;
2128 return ((char *)service) + parm->offset;
2133 return the parameter pointer for a parameter
2135 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2139 if (lp_ctx->s3_fns) {
2140 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2142 return parm->flags & FLAG_CMDLINE;
2147 parmnum = map_parameter(name);
2148 if (parmnum == -1) return false;
2150 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2154 * Find a service by name. Otherwise works like get_service.
2157 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2158 const char *pszServiceName)
2162 if (lp_ctx->s3_fns) {
2163 return lp_ctx->s3_fns->get_service(pszServiceName);
2166 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2167 if (lp_ctx->services[iService] != NULL &&
2168 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2169 return lp_ctx->services[iService];
2176 * Copy a service structure to another.
2177 * If pcopymapDest is NULL then copy all fields
2180 static void copy_service(struct loadparm_service *pserviceDest,
2181 struct loadparm_service *pserviceSource,
2182 struct bitmap *pcopymapDest)
2185 bool bcopyall = (pcopymapDest == NULL);
2186 struct parmlist_entry *data, *pdata, *paramo;
2189 for (i = 0; parm_table[i].label; i++)
2190 if (parm_table[i].p_class == P_LOCAL &&
2191 (bcopyall || bitmap_query(pcopymapDest, i))) {
2193 ((char *)pserviceSource) + parm_table[i].offset;
2195 ((char *)pserviceDest) + parm_table[i].offset;
2197 switch (parm_table[i].type) {
2199 *(bool *)dest_ptr = *(bool *)src_ptr;
2206 *(int *)dest_ptr = *(int *)src_ptr;
2210 lpcfg_string_set(pserviceDest,
2216 lpcfg_string_set_upper(pserviceDest,
2221 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2222 *(const char ***)src_ptr);
2230 init_copymap(pserviceDest);
2231 if (pserviceSource->copymap)
2232 bitmap_copy(pserviceDest->copymap,
2233 pserviceSource->copymap);
2236 data = pserviceSource->param_opt;
2239 pdata = pserviceDest->param_opt;
2240 /* Traverse destination */
2242 /* If we already have same option, override it */
2243 if (strcmp(pdata->key, data->key) == 0) {
2244 talloc_free(pdata->value);
2245 pdata->value = talloc_strdup(pdata,
2250 pdata = pdata->next;
2253 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2256 paramo->key = talloc_strdup(paramo, data->key);
2257 paramo->value = talloc_strdup(paramo, data->value);
2258 DLIST_ADD(pserviceDest->param_opt, paramo);
2265 * Check a service for consistency. Return False if the service is in any way
2266 * incomplete or faulty, else True.
2268 static bool lpcfg_service_ok(struct loadparm_service *service)
2273 if (service->szService[0] == '\0') {
2274 DEBUG(0, ("The following message indicates an internal error:\n"));
2275 DEBUG(0, ("No service name in service entry.\n"));
2279 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2280 /* I can't see why you'd want a non-printable printer service... */
2281 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2282 if (!service->bPrint_ok) {
2283 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2284 service->szService));
2285 service->bPrint_ok = true;
2287 /* [printers] service must also be non-browsable. */
2288 if (service->bBrowseable)
2289 service->bBrowseable = false;
2292 /* If a service is flagged unavailable, log the fact at level 0. */
2293 if (!service->bAvailable)
2294 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2295 service->szService));
2301 /*******************************************************************
2302 Keep a linked list of all config files so we know when one has changed
2303 it's date and needs to be reloaded.
2304 ********************************************************************/
2306 static void add_to_file_list(struct loadparm_context *lp_ctx,
2307 const char *fname, const char *subfname)
2309 struct file_lists *f = lp_ctx->file_lists;
2312 if (f->name && !strcmp(f->name, fname))
2318 f = talloc(lp_ctx, struct file_lists);
2321 f->next = lp_ctx->file_lists;
2322 f->name = talloc_strdup(f, fname);
2327 f->subfname = talloc_strdup(f, subfname);
2332 lp_ctx->file_lists = f;
2333 f->modtime = file_modtime(subfname);
2335 time_t t = file_modtime(subfname);
2341 /*******************************************************************
2342 Check if a config file has changed date.
2343 ********************************************************************/
2344 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2346 struct file_lists *f;
2347 DEBUG(6, ("lp_file_list_changed()\n"));
2349 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2353 n2 = standard_sub_basic(lp_ctx, f->name);
2355 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2356 f->name, n2, ctime(&f->modtime)));
2358 mod_time = file_modtime(n2);
2360 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2361 DEBUGADD(6, ("file %s modified: %s\n", n2,
2363 f->modtime = mod_time;
2364 talloc_free(f->subfname);
2365 f->subfname = talloc_strdup(f, n2);
2372 /***************************************************************************
2373 Handle the "realm" parameter
2374 ***************************************************************************/
2376 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2377 const char *pszParmValue, char **ptr)
2379 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2381 talloc_free(lp_ctx->globals->szRealm_upper);
2382 talloc_free(lp_ctx->globals->szRealm_lower);
2384 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2385 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2390 /***************************************************************************
2391 Handle the include operation.
2392 ***************************************************************************/
2394 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2395 const char *pszParmValue, char **ptr)
2397 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2399 add_to_file_list(lp_ctx, pszParmValue, fname);
2401 lpcfg_string_set(lp_ctx, ptr, fname);
2403 if (file_exist(fname))
2404 return pm_process(fname, do_section, do_parameter, lp_ctx);
2406 DEBUG(2, ("Can't find include file %s\n", fname));
2411 /***************************************************************************
2412 Handle the interpretation of the copy parameter.
2413 ***************************************************************************/
2415 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2416 const char *pszParmValue, char **ptr)
2419 struct loadparm_service *serviceTemp;
2421 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2425 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2427 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2428 if (serviceTemp == lp_ctx->currentService) {
2429 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2431 copy_service(lp_ctx->currentService,
2433 lp_ctx->currentService->copymap);
2437 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2445 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2446 const char *pszParmValue, char **ptr)
2449 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2450 if (lp_ctx->global) {
2451 return debug_parse_levels(pszParmValue);
2456 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2457 const char *pszParmValue, char **ptr)
2459 debug_set_logfile(pszParmValue);
2460 if (lp_ctx->global) {
2461 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2466 /***************************************************************************
2467 Initialise a copymap.
2468 ***************************************************************************/
2470 static void init_copymap(struct loadparm_service *pservice)
2474 TALLOC_FREE(pservice->copymap);
2476 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2477 if (!pservice->copymap)
2479 ("Couldn't allocate copymap!! (size %d)\n",
2480 (int)NUMPARAMETERS));
2482 for (i = 0; i < NUMPARAMETERS; i++)
2483 bitmap_set(pservice->copymap, i);
2487 * Process a parametric option
2489 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2490 struct loadparm_service *service,
2491 const char *pszParmName,
2492 const char *pszParmValue, int flags)
2494 struct parmlist_entry *paramo, *data;
2496 TALLOC_CTX *mem_ctx;
2498 while (isspace((unsigned char)*pszParmName)) {
2502 name = strlower_talloc(lp_ctx, pszParmName);
2503 if (!name) return false;
2505 if (service == NULL) {
2506 data = lp_ctx->globals->param_opt;
2507 mem_ctx = lp_ctx->globals;
2509 data = service->param_opt;
2513 /* Traverse destination */
2514 for (paramo=data; paramo; paramo=paramo->next) {
2515 /* If we already have the option set, override it unless
2516 it was a command line option and the new one isn't */
2517 if (strcmp(paramo->key, name) == 0) {
2518 if ((paramo->priority & FLAG_CMDLINE) &&
2519 !(flags & FLAG_CMDLINE)) {
2524 talloc_free(paramo->value);
2525 paramo->value = talloc_strdup(paramo, pszParmValue);
2526 paramo->priority = flags;
2532 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2535 paramo->key = talloc_strdup(paramo, name);
2536 paramo->value = talloc_strdup(paramo, pszParmValue);
2537 paramo->priority = flags;
2538 if (service == NULL) {
2539 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2541 DLIST_ADD(service->param_opt, paramo);
2549 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2550 const char *pszParmName, const char *pszParmValue,
2551 struct loadparm_context *lp_ctx, bool on_globals)
2554 /* if it is a special case then go ahead */
2555 if (parm_table[parmnum].special) {
2557 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2562 goto mark_non_default;
2565 /* now switch on the type of variable it is */
2566 switch (parm_table[parmnum].type)
2570 if (!set_boolean(pszParmValue, &b)) {
2571 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2574 *(bool *)parm_ptr = b;
2580 if (!set_boolean(pszParmValue, &b)) {
2581 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2584 *(bool *)parm_ptr = !b;
2589 *(int *)parm_ptr = atoi(pszParmValue);
2593 *(char *)parm_ptr = *pszParmValue;
2597 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2603 if (conv_str_size_error(pszParmValue, &val)) {
2604 if (val <= INT_MAX) {
2605 *(int *)parm_ptr = (int)val;
2610 DEBUG(0,("lp_do_parameter(%s): value is not "
2611 "a valid size specifier!\n", pszParmValue));
2616 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2617 pszParmValue, NULL);
2621 char **new_list = str_list_make(mem_ctx,
2622 pszParmValue, NULL);
2623 for (i=0; new_list[i]; i++) {
2624 if (new_list[i][0] == '+' && new_list[i][1]) {
2625 if (!str_list_check(*(const char ***)parm_ptr,
2627 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2630 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2631 str_list_remove(*(const char ***)parm_ptr,
2635 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2636 pszParmName, pszParmValue));
2639 *(const char ***)parm_ptr = (const char **) new_list;
2646 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2650 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2654 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2657 parm_table[parmnum].enum_list[i].name)) {
2659 parm_table[parmnum].
2664 if (!parm_table[parmnum].enum_list[i].name) {
2665 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2666 pszParmValue, pszParmName));
2676 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2677 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2678 /* we have to also unset FLAG_DEFAULT on aliases */
2679 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2680 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2682 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2683 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2690 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2691 const char *pszParmName, const char *pszParmValue)
2693 int parmnum = map_parameter(pszParmName);
2697 if (strchr(pszParmName, ':')) {
2698 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2700 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2704 /* if the flag has been set on the command line, then don't allow override,
2705 but don't report an error */
2706 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2710 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2712 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2713 pszParmName, pszParmValue, lp_ctx, true);
2716 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2717 struct loadparm_service *service,
2718 const char *pszParmName, const char *pszParmValue)
2722 int parmnum = map_parameter(pszParmName);
2725 if (strchr(pszParmName, ':')) {
2726 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2728 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2732 /* if the flag has been set on the command line, then don't allow override,
2733 but don't report an error */
2734 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2738 if (parm_table[parmnum].p_class == P_GLOBAL) {
2740 ("Global parameter %s found in service section!\n",
2744 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2746 if (!service->copymap)
2747 init_copymap(service);
2749 /* this handles the aliases - set the copymap for other
2750 * entries with the same data pointer */
2751 for (i = 0; parm_table[i].label; i++)
2752 if (parm_table[i].offset == parm_table[parmnum].offset &&
2753 parm_table[i].p_class == parm_table[parmnum].p_class)
2754 bitmap_clear(service->copymap, i);
2756 return set_variable(service, parmnum, parm_ptr, pszParmName,
2757 pszParmValue, lp_ctx, false);
2761 * Process a parameter.
2764 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2767 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2769 if (lp_ctx->bInGlobalSection)
2770 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2773 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2774 pszParmName, pszParmValue);
2778 variable argument do parameter
2780 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2781 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2782 const char *pszParmName, const char *fmt, ...)
2789 s = talloc_vasprintf(NULL, fmt, ap);
2791 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2798 set a parameter from the commandline - this is called from command line parameter
2799 parsing code. It sets the parameter then marks the parameter as unable to be modified
2800 by smb.conf processing
2802 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2803 const char *pszParmValue)
2808 if (lp_ctx->s3_fns) {
2809 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2812 parmnum = map_parameter(pszParmName);
2814 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2817 if (parmnum < 0 && strchr(pszParmName, ':')) {
2818 /* set a parametric option */
2819 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2820 pszParmValue, FLAG_CMDLINE);
2824 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2828 /* reset the CMDLINE flag in case this has been called before */
2829 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2831 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2835 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2837 /* we have to also set FLAG_CMDLINE on aliases */
2838 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2839 lp_ctx->flags[i] |= FLAG_CMDLINE;
2841 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2842 lp_ctx->flags[i] |= FLAG_CMDLINE;
2849 set a option from the commandline in 'a=b' format. Use to support --option
2851 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2856 s = talloc_strdup(NULL, option);
2869 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2875 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2878 * Print a parameter of the specified type.
2881 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2883 /* For the seperation of lists values that we print below */
2884 const char *list_sep = ", ";
2889 for (i = 0; p->enum_list[i].name; i++) {
2890 if (*(int *)ptr == p->enum_list[i].value) {
2892 p->enum_list[i].name);
2899 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2903 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2908 fprintf(f, "%d", *(int *)ptr);
2912 fprintf(f, "%c", *(char *)ptr);
2916 int val = *(int *)ptr;
2920 fprintf(f, "0%o", val);
2929 if ((char ***)ptr && *(char ***)ptr) {
2930 char **list = *(char ***)ptr;
2931 for (; *list; list++) {
2932 /* surround strings with whitespace in double quotes */
2933 if (*(list+1) == NULL) {
2934 /* last item, no extra separator */
2937 if ( strchr_m( *list, ' ' ) ) {
2938 fprintf(f, "\"%s\"%s", *list, list_sep);
2940 fprintf(f, "%s%s", *list, list_sep);
2948 if (*(char **)ptr) {
2949 fprintf(f, "%s", *(char **)ptr);
2958 * Check if two parameters are equal.
2961 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2966 return (*((bool *)ptr1) == *((bool *)ptr2));
2972 return (*((int *)ptr1) == *((int *)ptr2));
2975 return (*((char *)ptr1) == *((char *)ptr2));
2979 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2984 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2989 return (p1 == p2 || strequal(p1, p2));
2998 * Process a new section (service).
3000 * At this stage all sections are services.
3001 * Later we'll have special sections that permit server parameters to be set.
3002 * Returns True on success, False on failure.
3005 static bool do_section(const char *pszSectionName, void *userdata)
3007 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3009 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3010 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3013 /* if we've just struck a global section, note the fact. */
3014 lp_ctx->bInGlobalSection = isglobal;
3016 /* check for multiple global sections */
3017 if (lp_ctx->bInGlobalSection) {
3018 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3022 /* if we have a current service, tidy it up before moving on */
3025 if (lp_ctx->currentService != NULL)
3026 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3028 /* if all is still well, move to the next record in the services array */
3030 /* We put this here to avoid an odd message order if messages are */
3031 /* issued by the post-processing of a previous section. */
3032 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3034 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
3037 DEBUG(0, ("Failed to add a new service\n"));
3047 * Determine if a particular base parameter is currently set to the default value.
3050 static bool is_default(struct loadparm_service *sDefault, int i)
3052 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
3053 if (!defaults_saved)
3055 switch (parm_table[i].type) {
3058 return str_list_equal((const char **)parm_table[i].def.lvalue,
3059 (const char **)def_ptr);
3062 return strequal(parm_table[i].def.svalue,
3066 return parm_table[i].def.bvalue ==
3073 return parm_table[i].def.ivalue ==
3082 *Display the contents of the global structure.
3085 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3089 struct parmlist_entry *data;
3091 fprintf(f, "# Global parameters\n[global]\n");
3093 for (i = 0; parm_table[i].label; i++)
3094 if (parm_table[i].p_class == P_GLOBAL &&
3095 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3096 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3098 fprintf(f, "\t%s = ", parm_table[i].label);
3099 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3102 if (lp_ctx->globals->param_opt != NULL) {
3103 for (data = lp_ctx->globals->param_opt; data;
3104 data = data->next) {
3105 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3108 fprintf(f, "\t%s = %s\n", data->key, data->value);
3115 * Display the contents of a single services record.
3118 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3119 unsigned int *flags)
3122 struct parmlist_entry *data;
3124 if (pService != sDefault)
3125 fprintf(f, "\n[%s]\n", pService->szService);
3127 for (i = 0; parm_table[i].label; i++) {
3128 if (parm_table[i].p_class == P_LOCAL &&
3129 (*parm_table[i].label != '-') &&
3130 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3132 if (pService == sDefault) {
3133 if (flags && (flags[i] & FLAG_DEFAULT)) {
3136 if (defaults_saved) {
3137 if (is_default(sDefault, i)) {
3142 if (equal_parameter(parm_table[i].type,
3143 ((char *)pService) +
3144 parm_table[i].offset,
3145 ((char *)sDefault) +
3146 parm_table[i].offset))
3150 fprintf(f, "\t%s = ", parm_table[i].label);
3151 print_parameter(&parm_table[i],
3152 ((char *)pService) + parm_table[i].offset, f);
3156 if (pService->param_opt != NULL) {
3157 for (data = pService->param_opt; data; data = data->next) {
3158 fprintf(f, "\t%s = %s\n", data->key, data->value);
3163 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3164 struct loadparm_service *service,
3165 const char *parm_name, FILE * f)
3167 struct parm_struct *parm;
3170 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3175 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3177 print_parameter(parm, ptr, f);
3183 * Return info about the next parameter in a service.
3184 * snum==-1 gives the globals.
3185 * Return NULL when out of parameters.
3189 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3193 /* do the globals */
3194 for (; parm_table[*i].label; (*i)++) {
3195 if ((*parm_table[*i].label == '-'))
3199 && (parm_table[*i].offset ==
3200 parm_table[(*i) - 1].offset)
3201 && (parm_table[*i].p_class ==
3202 parm_table[(*i) - 1].p_class))
3205 return &parm_table[(*i)++];
3208 struct loadparm_service *pService = lp_ctx->services[snum];
3210 for (; parm_table[*i].label; (*i)++) {
3211 if (parm_table[*i].p_class == P_LOCAL &&
3212 (*parm_table[*i].label != '-') &&
3214 (parm_table[*i].offset !=
3215 parm_table[(*i) - 1].offset)))
3217 if (allparameters ||
3218 !equal_parameter(parm_table[*i].type,
3219 ((char *)pService) +
3220 parm_table[*i].offset,
3221 ((char *)lp_ctx->sDefault) +
3222 parm_table[*i].offset))
3224 return &parm_table[(*i)++];
3235 * Auto-load some home services.
3237 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3245 * Unload unused services.
3248 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3249 struct smbsrv_connection *smb,
3250 bool (*snumused) (struct smbsrv_connection *, int))
3253 for (i = 0; i < lp_ctx->iNumServices; i++) {
3254 if (lp_ctx->services[i] == NULL)
3257 if (!snumused || !snumused(smb, i)) {
3258 talloc_free(lp_ctx->services[i]);
3259 lp_ctx->services[i] = NULL;
3265 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3267 struct parmlist_entry *data;
3269 if (lp_ctx->refuse_free) {
3270 /* someone is trying to free the
3271 global_loadparm_context.
3272 We can't allow that. */
3276 if (lp_ctx->globals->param_opt != NULL) {
3277 struct parmlist_entry *next;
3278 for (data = lp_ctx->globals->param_opt; data; data=next) {
3280 if (data->priority & FLAG_CMDLINE) continue;
3281 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3290 * Initialise the global parameter structure.
3292 * Note that most callers should use loadparm_init_global() instead
3294 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3298 struct loadparm_context *lp_ctx;
3299 struct parmlist_entry *parm;
3302 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3306 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3307 lp_ctx->bInGlobalSection = true;
3308 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3309 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3311 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3312 lp_ctx->sDefault->bAvailable = true;
3313 lp_ctx->sDefault->bBrowseable = true;
3314 lp_ctx->sDefault->bRead_only = true;
3315 lp_ctx->sDefault->bMap_archive = true;
3316 lp_ctx->sDefault->iStrictLocking = true;
3317 lp_ctx->sDefault->bOpLocks = true;
3318 lp_ctx->sDefault->iCreate_mask = 0744;
3319 lp_ctx->sDefault->iCreate_force_mode = 0000;
3320 lp_ctx->sDefault->iDir_mask = 0755;
3321 lp_ctx->sDefault->iDir_force_mode = 0000;
3323 DEBUG(3, ("Initialising global parameters\n"));
3325 for (i = 0; parm_table[i].label; i++) {
3326 if ((parm_table[i].type == P_STRING ||
3327 parm_table[i].type == P_USTRING) &&
3328 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3330 if (parm_table[i].p_class == P_LOCAL) {
3331 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3333 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3335 *r = talloc_strdup(lp_ctx, "");
3339 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3340 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3341 talloc_free(logfile);
3343 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3345 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3347 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3348 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3349 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3351 /* options that can be set on the command line must be initialised via
3352 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3354 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3356 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3357 myname = get_myname(lp_ctx);
3358 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3359 talloc_free(myname);
3360 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3362 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3364 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3365 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3367 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey dnsserver");
3368 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3369 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3370 /* the winbind method for domain controllers is for both RODC
3371 auth forwarding and for trusted domains */
3372 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3373 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3375 /* This hive should be dynamically generated by Samba using
3376 data from the sam, but for the moment leave it in a tdb to
3377 keep regedt32 from popping up an annoying dialog. */
3378 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3380 /* using UTF8 by default allows us to support all chars */
3381 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3383 /* Use codepage 850 as a default for the dos character set */
3384 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3387 * Allow the default PASSWD_CHAT to be overridden in local.h.
3389 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3391 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3392 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3393 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3394 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3395 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3397 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3398 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3399 "Samba %s", SAMBA_VERSION_STRING);
3401 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3403 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3404 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3405 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3407 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3408 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3409 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3410 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3411 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3412 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3413 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3414 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3415 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3416 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3417 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3418 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3419 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3421 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3422 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3423 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3424 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3425 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3426 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3427 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3428 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3430 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3432 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3433 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3435 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3436 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3438 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3439 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3440 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3441 #if _SAMBA_BUILD_ >= 4
3442 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3443 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3444 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3445 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3446 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3447 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3449 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3450 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3451 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3453 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3454 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3456 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3458 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3460 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3461 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3462 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3463 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3464 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3465 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3466 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3468 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3470 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3471 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3473 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3474 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3475 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3476 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3477 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3479 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3480 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3482 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3483 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3484 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3486 for (i = 0; parm_table[i].label; i++) {
3487 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3488 lp_ctx->flags[i] |= FLAG_DEFAULT;
3492 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3493 if (!(parm->priority & FLAG_CMDLINE)) {
3494 parm->priority |= FLAG_DEFAULT;
3502 * Initialise the global parameter structure.
3504 struct loadparm_context *loadparm_init_global(bool load_default)
3506 if (global_loadparm_context == NULL) {
3507 global_loadparm_context = loadparm_init(NULL);
3509 if (global_loadparm_context == NULL) {
3512 global_loadparm_context->global = true;
3513 if (load_default && !global_loadparm_context->loaded) {
3514 lpcfg_load_default(global_loadparm_context);
3516 global_loadparm_context->refuse_free = true;
3517 return global_loadparm_context;
3521 * Initialise the global parameter structure.
3523 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3524 const struct loadparm_s3_context *s3_fns)
3526 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3527 if (!loadparm_context) {
3530 loadparm_context->s3_fns = s3_fns;
3531 return loadparm_context;
3534 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3536 return lp_ctx->szConfigFile;
3539 const char *lp_default_path(void)
3541 if (getenv("SMB_CONF_PATH"))
3542 return getenv("SMB_CONF_PATH");
3544 return dyn_CONFIGFILE;
3548 * Update the internal state of a loadparm context after settings
3551 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3553 struct debug_settings settings;
3554 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3556 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3557 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3560 if (!lp_ctx->global) {
3564 panic_action = lp_ctx->globals->panic_action;
3566 reload_charcnv(lp_ctx);
3568 ZERO_STRUCT(settings);
3569 /* Add any more debug-related smb.conf parameters created in
3571 settings.timestamp_logs = true;
3572 debug_set_settings(&settings);
3574 /* FIXME: This is a bit of a hack, but we can't use a global, since
3575 * not everything that uses lp also uses the socket library */
3576 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3577 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3579 unsetenv("SOCKET_TESTNONBLOCK");
3585 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3589 path = lp_default_path();
3591 if (!file_exist(path)) {
3592 /* We allow the default smb.conf file to not exist,
3593 * basically the equivalent of an empty file. */
3594 return lpcfg_update(lp_ctx);
3597 return lpcfg_load(lp_ctx, path);
3601 * Load the services array from the services file.
3603 * Return True on success, False on failure.
3605 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3610 filename = talloc_strdup(lp_ctx, filename);
3612 lp_ctx->szConfigFile = filename;
3614 if (lp_ctx->s3_fns) {
3615 return lp_ctx->s3_fns->load(filename);
3618 lp_ctx->bInGlobalSection = true;
3619 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3620 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3622 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3624 /* We get sections first, so have to start 'behind' to make up */
3625 lp_ctx->currentService = NULL;
3626 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3628 /* finish up the last section */
3629 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3631 if (lp_ctx->currentService != NULL)
3632 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3634 bRetval = bRetval && lpcfg_update(lp_ctx);
3636 /* we do this unconditionally, so that it happens even
3637 for a missing smb.conf */
3638 reload_charcnv(lp_ctx);
3640 if (bRetval == true) {
3641 /* set this up so that any child python tasks will
3642 find the right smb.conf */
3643 setenv("SMB_CONF_PATH", filename, 1);
3645 /* set the context used by the lp_*() function
3647 global_loadparm_context = lp_ctx;
3648 lp_ctx->loaded = true;
3655 * Return the max number of services.
3658 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3660 if (lp_ctx->s3_fns) {
3661 return lp_ctx->s3_fns->get_numservices();
3664 return lp_ctx->iNumServices;
3668 * Display the contents of the services array in human-readable form.
3671 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3676 if (lp_ctx->s3_fns) {
3677 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3681 defaults_saved = !show_defaults;
3683 dump_globals(lp_ctx, f, show_defaults);
3685 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3687 for (iService = 0; iService < maxtoprint; iService++)
3688 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3692 * Display the contents of one service in human-readable form.
3694 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3696 if (service != NULL) {
3697 if (service->szService[0] == '\0')
3699 dump_a_service(service, sDefault, f, NULL);
3703 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3706 if (lp_ctx->s3_fns) {
3707 return lp_ctx->s3_fns->get_servicebynum(snum);
3710 return lp_ctx->services[snum];
3713 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3714 const char *service_name)
3719 if (lp_ctx->s3_fns) {
3720 return lp_ctx->s3_fns->get_service(service_name);
3723 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3724 if (lp_ctx->services[iService] &&
3725 lp_ctx->services[iService]->szService) {
3727 * The substitution here is used to support %U is
3730 serviceName = standard_sub_basic(
3731 lp_ctx->services[iService],
3732 lp_ctx->services[iService]->szService);
3733 if (strequal(serviceName, service_name)) {
3734 talloc_free(serviceName);
3735 return lp_ctx->services[iService];
3737 talloc_free(serviceName);
3741 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3745 const char *lpcfg_servicename(const struct loadparm_service *service)
3747 return lp_string((const char *)service->szService);
3751 * A useful volume label function.
3753 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3756 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3757 service->volume : sDefault->volume));
3759 return lpcfg_servicename(service);
3764 * If we are PDC then prefer us as DMB
3766 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3769 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3770 service->szPrintername : sDefault->szPrintername));
3771 if (ret == NULL || (ret != NULL && *ret == '\0'))
3772 ret = lpcfg_servicename(service);
3779 * Return the max print jobs per queue.
3781 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3783 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3784 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3785 maxjobs = PRINT_MAX_JOBID - 1;
3790 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3792 if (lp_ctx == NULL) {
3793 return get_iconv_handle();
3795 return lp_ctx->iconv_handle;
3798 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3800 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3801 if (!lp_ctx->global) {
3805 if (old_ic == NULL) {
3806 old_ic = global_iconv_handle;
3808 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3809 global_iconv_handle = lp_ctx->iconv_handle;
3812 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3814 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3817 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3819 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3822 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3824 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3827 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3829 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3832 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3834 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3837 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3839 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3840 if (settings == NULL)
3842 SMB_ASSERT(lp_ctx != NULL);
3843 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3844 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3848 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3850 if (lp_ctx->s3_fns) {
3851 return lp_ctx->s3_fns->server_role();
3854 return lp_find_server_role(lp_ctx->globals->server_role,
3855 lp_ctx->globals->security,
3856 lp_ctx->globals->domain_logons,
3857 (lp_ctx->globals->domain_master == true) ||
3858 (lp_ctx->globals->domain_master == Auto));
3861 int lpcfg_security(struct loadparm_context *lp_ctx)
3863 if (lp_ctx->s3_fns) {
3864 return lp_ctx->s3_fns->security();
3867 return lp_find_security(lp_ctx->globals->server_role,
3868 lp_ctx->globals->security);