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(szPasswordServer),
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),
995 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
998 .label = "wins support",
1000 .p_class = P_GLOBAL,
1001 .offset = GLOBAL_VAR(bWINSsupport),
1004 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
1007 .label = "wins hook",
1009 .p_class = P_GLOBAL,
1010 .offset = GLOBAL_VAR(szWINSHook),
1013 .flags = FLAG_ADVANCED,
1017 .label = "csc policy",
1020 .offset = LOCAL_VAR(iCSCPolicy),
1022 .enum_list = enum_csc_policy,
1023 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1027 .label = "strict locking",
1030 .offset = LOCAL_VAR(iStrictLocking),
1038 .offset = LOCAL_VAR(bOpLocks),
1044 .label = "share backend",
1046 .p_class = P_GLOBAL,
1047 .offset = GLOBAL_VAR(szShareBackend),
1054 .p_class = P_GLOBAL,
1055 .offset = GLOBAL_VAR(szAutoServices),
1058 .flags = FLAG_ADVANCED,
1061 .label = "auto services",
1063 .p_class = P_GLOBAL,
1064 .offset = GLOBAL_VAR(szAutoServices),
1067 .flags = FLAG_ADVANCED,
1070 .label = "lock directory",
1072 .p_class = P_GLOBAL,
1073 .offset = GLOBAL_VAR(szLockDir),
1076 .flags = FLAG_ADVANCED,
1079 .label = "lock dir",
1081 .p_class = P_GLOBAL,
1082 .offset = GLOBAL_VAR(szLockDir),
1088 .label = "state directory",
1090 .p_class = P_GLOBAL,
1091 .offset = GLOBAL_VAR(szStateDir),
1094 .flags = FLAG_ADVANCED,
1097 .label = "cache directory",
1099 .p_class = P_GLOBAL,
1100 .offset = GLOBAL_VAR(szCacheDir),
1103 .flags = FLAG_ADVANCED,
1106 .label = "pid directory",
1108 .p_class = P_GLOBAL,
1109 .offset = GLOBAL_VAR(szPidDir),
1115 .label = "socket address",
1117 .p_class = P_GLOBAL,
1118 .offset = GLOBAL_VAR(szSocketAddress),
1126 .offset = LOCAL_VAR(szCopy),
1127 .special = handle_copy,
1135 .offset = LOCAL_VAR(szInclude),
1136 .special = handle_include,
1141 .label = "available",
1144 .offset = LOCAL_VAR(bAvailable),
1152 .offset = LOCAL_VAR(volume),
1155 .flags = FLAG_ADVANCED | FLAG_SHARE,
1161 .offset = LOCAL_VAR(fstype),
1167 .label = "panic action",
1169 .p_class = P_GLOBAL,
1170 .offset = GLOBAL_VAR(panic_action),
1176 .label = "msdfs root",
1179 .offset = LOCAL_VAR(bMSDfsRoot),
1184 .label = "host msdfs",
1186 .p_class = P_GLOBAL,
1187 .offset = GLOBAL_VAR(bHostMSDfs),
1190 .flags = FLAG_ADVANCED,
1193 .label = "winbind separator",
1195 .p_class = P_GLOBAL,
1196 .offset = GLOBAL_VAR(szWinbindSeparator),
1201 .label = "winbindd socket directory",
1203 .p_class = P_GLOBAL,
1204 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1207 .flags = FLAG_ADVANCED,
1210 .label = "winbindd privileged socket directory",
1212 .p_class = P_GLOBAL,
1213 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1216 .flags = FLAG_ADVANCED,
1219 .label = "winbind sealed pipes",
1221 .p_class = P_GLOBAL,
1222 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1225 .flags = FLAG_ADVANCED,
1228 .label = "template shell",
1230 .p_class = P_GLOBAL,
1231 .offset = GLOBAL_VAR(szTemplateShell),
1234 .flags = FLAG_ADVANCED,
1237 .label = "template homedir",
1239 .p_class = P_GLOBAL,
1240 .offset = GLOBAL_VAR(szTemplateHomedir),
1243 .flags = FLAG_ADVANCED,
1246 .label = "idmap trusted only",
1248 .p_class = P_GLOBAL,
1249 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1252 .flags = FLAG_ADVANCED,
1256 .label = "ntp signd socket directory",
1258 .p_class = P_GLOBAL,
1259 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1262 .flags = FLAG_ADVANCED,
1265 .label = "rndc command",
1267 .p_class = P_GLOBAL,
1268 .offset = GLOBAL_VAR(szRNDCCommand),
1271 .flags = FLAG_ADVANCED,
1274 .label = "dns update command",
1276 .p_class = P_GLOBAL,
1277 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1280 .flags = FLAG_ADVANCED,
1283 .label = "spn update command",
1285 .p_class = P_GLOBAL,
1286 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1289 .flags = FLAG_ADVANCED,
1292 .label = "samba kcc command",
1294 .p_class = P_GLOBAL,
1295 .offset = GLOBAL_VAR(szSambaKCCCommand),
1298 .flags = FLAG_ADVANCED,
1301 .label = "nsupdate command",
1303 .p_class = P_GLOBAL,
1304 .offset = GLOBAL_VAR(szNSUpdateCommand),
1307 .flags = FLAG_ADVANCED,
1310 .label = "allow dns updates",
1312 .p_class = P_GLOBAL,
1313 .offset = GLOBAL_VAR(allow_dns_updates),
1315 .enum_list = enum_dns_update_settings,
1316 .flags = FLAG_ADVANCED,
1319 .label = "dns forwarder",
1321 .p_class = P_GLOBAL,
1322 .offset = GLOBAL_VAR(dns_forwarder),
1325 .flags = FLAG_ADVANCED,
1328 .label = "dns recursive queries",
1330 .p_class = P_GLOBAL,
1331 .offset = GLOBAL_VAR(dns_recursive_queries),
1336 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1340 /* local variables */
1341 struct loadparm_context {
1342 const char *szConfigFile;
1343 struct loadparm_global *globals;
1344 struct loadparm_service **services;
1345 struct loadparm_service *sDefault;
1346 struct smb_iconv_handle *iconv_handle;
1348 struct loadparm_service *currentService;
1349 bool bInGlobalSection;
1351 struct file_lists *next;
1356 unsigned int flags[NUMPARAMETERS];
1359 bool global; /* Is this the global context, which may set
1360 * global variables such as debug level etc? */
1361 const struct loadparm_s3_context *s3_fns;
1365 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1367 if (lp_ctx->s3_fns) {
1368 return lp_ctx->s3_fns->get_default_loadparm_service();
1370 return lp_ctx->sDefault;
1374 * Convenience routine to grab string parameters into temporary memory
1375 * and run standard_sub_basic on them.
1377 * The buffers can be written to by
1378 * callers without affecting the source string.
1381 static const char *lp_string(const char *s)
1383 #if 0 /* until REWRITE done to make thread-safe */
1384 size_t len = s ? strlen(s) : 0;
1388 /* The follow debug is useful for tracking down memory problems
1389 especially if you have an inner loop that is calling a lp_*()
1390 function that returns a string. Perhaps this debug should be
1391 present all the time? */
1394 DEBUG(10, ("lp_string(%s)\n", s));
1397 #if 0 /* until REWRITE done to make thread-safe */
1399 lp_talloc = talloc_init("lp_talloc");
1401 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1409 strlcpy(ret, s, len);
1411 if (trim_string(ret, "\"", "\"")) {
1412 if (strchr(ret,'"') != NULL)
1413 strlcpy(ret, s, len);
1416 standard_sub_basic(ret,len+100);
1423 In this section all the functions that are used to access the
1424 parameters from the rest of the program are defined
1428 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1429 * for code compatibility between existing Samba4 and Samba3 code.
1432 /* this global context supports the lp_*() function varients */
1433 static struct loadparm_context *global_loadparm_context;
1435 #define lpcfg_default_service global_loadparm_context->sDefault
1436 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1438 #define FN_GLOBAL_STRING(fn_name,var_name) \
1439 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1440 if (lp_ctx == NULL) return NULL; \
1441 if (lp_ctx->s3_fns) { \
1442 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1443 return lp_ctx->s3_fns->fn_name(); \
1445 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1448 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1449 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1450 if (lp_ctx == NULL) return NULL; \
1451 if (lp_ctx->s3_fns) { \
1452 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1453 return lp_ctx->s3_fns->fn_name(); \
1455 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1458 #define FN_GLOBAL_LIST(fn_name,var_name) \
1459 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1460 if (lp_ctx == NULL) return NULL; \
1461 if (lp_ctx->s3_fns) { \
1462 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1463 return lp_ctx->s3_fns->fn_name(); \
1465 return lp_ctx->globals->var_name; \
1468 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1469 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1470 if (lp_ctx == NULL) return false; \
1471 if (lp_ctx->s3_fns) { \
1472 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1473 return lp_ctx->s3_fns->fn_name(); \
1475 return lp_ctx->globals->var_name; \
1478 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1479 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1480 if (lp_ctx->s3_fns) { \
1481 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1482 return lp_ctx->s3_fns->fn_name(); \
1484 return lp_ctx->globals->var_name; \
1487 /* Local parameters don't need the ->s3_fns because the struct
1488 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1490 #define FN_LOCAL_STRING(fn_name,val) \
1491 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1492 struct loadparm_service *sDefault) { \
1493 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1496 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1498 #define FN_LOCAL_LIST(fn_name,val) \
1499 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1500 struct loadparm_service *sDefault) {\
1501 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1504 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1506 #define FN_LOCAL_BOOL(fn_name,val) \
1507 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1508 struct loadparm_service *sDefault) { \
1509 return((service != NULL)? service->val : sDefault->val); \
1512 #define FN_LOCAL_INTEGER(fn_name,val) \
1513 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1514 struct loadparm_service *sDefault) { \
1515 return((service != NULL)? service->val : sDefault->val); \
1518 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1520 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1522 #define FN_LOCAL_CHAR(fn_name,val) \
1523 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1524 struct loadparm_service *sDefault) { \
1525 return((service != NULL)? service->val : sDefault->val); \
1528 #include "lib/param/param_functions.c"
1530 FN_GLOBAL_LIST(smb_ports, smb_ports)
1531 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1532 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1533 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1534 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1535 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1536 FN_GLOBAL_INTEGER(web_port, web_port)
1537 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1538 FN_GLOBAL_STRING(logfile, logfile)
1539 FN_GLOBAL_STRING(share_backend, szShareBackend)
1540 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1541 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1542 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1543 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1544 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1545 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1546 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1547 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1548 FN_GLOBAL_STRING(serverstring, szServerString)
1549 FN_GLOBAL_STRING(lockdir, szLockDir)
1550 FN_GLOBAL_STRING(statedir, szStateDir)
1551 FN_GLOBAL_STRING(cachedir, szCacheDir)
1552 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1553 FN_GLOBAL_STRING(dos_charset, dos_charset)
1554 FN_GLOBAL_STRING(unix_charset, unix_charset)
1555 FN_GLOBAL_STRING(piddir, szPidDir)
1556 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1557 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1558 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1559 FN_GLOBAL_LIST(samba_kcc_command, szSambaKCCCommand)
1560 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1561 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1562 FN_GLOBAL_LIST(server_services, server_services)
1563 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1564 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1565 FN_GLOBAL_STRING(auto_services, szAutoServices)
1566 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1567 FN_GLOBAL_CONST_STRING(passwordserver, szPasswordServer)
1568 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1569 FN_GLOBAL_STRING(realm, szRealm_upper)
1570 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1571 FN_GLOBAL_STRING(socket_options, socket_options)
1572 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1573 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1574 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1575 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1576 FN_GLOBAL_LIST(interfaces, szInterfaces)
1577 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1578 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1579 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1580 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1581 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1582 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1583 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1584 FN_GLOBAL_BOOL(readraw, bReadRaw)
1585 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1586 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1587 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1588 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1589 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1590 FN_GLOBAL_BOOL(time_server, bTimeServer)
1591 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1592 FN_GLOBAL_BOOL(unicode, bUnicode)
1593 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1594 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1595 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1596 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1597 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1598 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1599 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1600 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1601 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1602 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1603 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1604 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1605 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1606 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1607 FN_GLOBAL_INTEGER(maxmux, max_mux)
1608 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1609 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1610 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1611 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1612 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1613 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1614 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1616 FN_GLOBAL_INTEGER(allow_dns_updates, allow_dns_updates)
1617 FN_GLOBAL_CONST_STRING(dns_forwarder, dns_forwarder)
1618 FN_GLOBAL_BOOL(dns_recursive_queries, dns_recursive_queries)
1620 FN_GLOBAL_INTEGER(server_signing, server_signing)
1621 FN_GLOBAL_INTEGER(client_signing, client_signing)
1623 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1625 /* local prototypes */
1626 static int map_parameter(const char *pszParmName);
1627 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1628 const char *pszServiceName);
1629 static void copy_service(struct loadparm_service *pserviceDest,
1630 struct loadparm_service *pserviceSource,
1631 struct bitmap *pcopymapDest);
1632 static bool lpcfg_service_ok(struct loadparm_service *service);
1633 static bool do_section(const char *pszSectionName, void *);
1634 static void init_copymap(struct loadparm_service *pservice);
1636 /* This is a helper function for parametrical options support. */
1637 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1638 /* Actual parametrical functions are quite simple */
1639 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1640 struct loadparm_service *service,
1641 const char *type, const char *option)
1643 char *vfskey_tmp = NULL;
1644 char *vfskey = NULL;
1645 struct parmlist_entry *data;
1650 if (lp_ctx->s3_fns) {
1651 return lp_ctx->s3_fns->get_parametric(service, type, option);
1654 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1656 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1657 if (vfskey_tmp == NULL) return NULL;
1658 vfskey = strlower_talloc(NULL, vfskey_tmp);
1659 talloc_free(vfskey_tmp);
1662 if (strcmp(data->key, vfskey) == 0) {
1663 talloc_free(vfskey);
1669 if (service != NULL) {
1670 /* Try to fetch the same option but from globals */
1671 /* but only if we are not already working with globals */
1672 for (data = lp_ctx->globals->param_opt; data;
1673 data = data->next) {
1674 if (strcmp(data->key, vfskey) == 0) {
1675 talloc_free(vfskey);
1681 talloc_free(vfskey);
1688 * convenience routine to return int parameters.
1690 static int lp_int(const char *s)
1694 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1698 return strtol(s, NULL, 0);
1702 * convenience routine to return unsigned long parameters.
1704 static unsigned long lp_ulong(const char *s)
1708 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
1712 return strtoul(s, NULL, 0);
1716 * convenience routine to return unsigned long parameters.
1718 static long lp_long(const char *s)
1722 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
1726 return strtol(s, NULL, 0);
1730 * convenience routine to return unsigned long parameters.
1732 static double lp_double(const char *s)
1736 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1740 return strtod(s, NULL);
1744 * convenience routine to return boolean parameters.
1746 static bool lp_bool(const char *s)
1751 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1755 if (!set_boolean(s, &ret)) {
1756 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1765 * Return parametric option from a given service. Type is a part of option before ':'
1766 * Parametric option has following syntax: 'Type: option = value'
1767 * Returned value is allocated in 'lp_talloc' context
1770 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1771 struct loadparm_service *service, const char *type,
1774 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1777 return lp_string(value);
1783 * Return parametric option from a given service. Type is a part of option before ':'
1784 * Parametric option has following syntax: 'Type: option = value'
1785 * Returned value is allocated in 'lp_talloc' context
1788 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1789 struct loadparm_context *lp_ctx,
1790 struct loadparm_service *service,
1792 const char *option, const char *separator)
1794 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1797 return (const char **)str_list_make(mem_ctx, value, separator);
1803 * Return parametric option from a given service. Type is a part of option before ':'
1804 * Parametric option has following syntax: 'Type: option = value'
1807 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1808 struct loadparm_service *service, const char *type,
1809 const char *option, int default_v)
1811 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1814 return lp_int(value);
1820 * Return parametric option from a given service. Type is a part of
1821 * option before ':'.
1822 * Parametric option has following syntax: 'Type: option = value'.
1825 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1826 struct loadparm_service *service, const char *type,
1827 const char *option, int default_v)
1831 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1833 if (value && conv_str_size_error(value, &bval)) {
1834 if (bval <= INT_MAX) {
1843 * Return parametric option from a given service.
1844 * Type is a part of option before ':'
1845 * Parametric option has following syntax: 'Type: option = value'
1847 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1848 struct loadparm_service *service, const char *type,
1849 const char *option, unsigned long default_v)
1851 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1854 return lp_ulong(value);
1859 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
1860 struct loadparm_service *service, const char *type,
1861 const char *option, long default_v)
1863 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1866 return lp_long(value);
1871 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1872 struct loadparm_service *service, const char *type,
1873 const char *option, double default_v)
1875 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1878 return lp_double(value);
1884 * Return parametric option from a given service. Type is a part of option before ':'
1885 * Parametric option has following syntax: 'Type: option = value'
1888 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1889 struct loadparm_service *service, const char *type,
1890 const char *option, bool default_v)
1892 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1895 return lp_bool(value);
1902 * Initialise a service to the defaults.
1905 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1907 struct loadparm_service *pservice =
1908 talloc_zero(mem_ctx, struct loadparm_service);
1909 copy_service(pservice, sDefault, NULL);
1914 * Set a string value, deallocating any existing space, and allocing the space
1917 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1924 *dest = talloc_strdup(mem_ctx, src);
1925 if ((*dest) == NULL) {
1926 DEBUG(0,("Out of memory in string_set\n"));
1934 * Set a string value, deallocating any existing space, and allocing the space
1937 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1944 *dest = strupper_talloc(mem_ctx, src);
1945 if ((*dest) == NULL) {
1946 DEBUG(0,("Out of memory in string_set_upper\n"));
1956 * Add a new service to the services array initialising it with the given
1960 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1961 const struct loadparm_service *pservice,
1965 struct loadparm_service tservice;
1966 int num_to_alloc = lp_ctx->iNumServices + 1;
1967 struct parmlist_entry *data, *pdata;
1969 if (pservice == NULL) {
1970 pservice = lp_ctx->sDefault;
1973 tservice = *pservice;
1975 /* it might already exist */
1977 struct loadparm_service *service = getservicebyname(lp_ctx,
1979 if (service != NULL) {
1980 /* Clean all parametric options for service */
1981 /* They will be added during parsing again */
1982 data = service->param_opt;
1988 service->param_opt = NULL;
1993 /* find an invalid one */
1994 for (i = 0; i < lp_ctx->iNumServices; i++)
1995 if (lp_ctx->services[i] == NULL)
1998 /* if not, then create one */
1999 if (i == lp_ctx->iNumServices) {
2000 struct loadparm_service **tsp;
2002 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
2005 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2008 lp_ctx->services = tsp;
2009 lp_ctx->services[lp_ctx->iNumServices] = NULL;
2012 lp_ctx->iNumServices++;
2015 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
2016 if (lp_ctx->services[i] == NULL) {
2017 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2020 copy_service(lp_ctx->services[i], &tservice, NULL);
2022 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
2023 return lp_ctx->services[i];
2027 * Add a new home service, with the specified home directory, defaults coming
2028 * from service ifrom.
2031 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
2032 const char *pszHomename,
2033 struct loadparm_service *default_service,
2034 const char *user, const char *pszHomedir)
2036 struct loadparm_service *service;
2038 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
2040 if (service == NULL)
2043 if (!(*(default_service->szPath))
2044 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
2045 service->szPath = talloc_strdup(service, pszHomedir);
2047 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
2050 if (!(*(service->comment))) {
2051 service->comment = talloc_asprintf(service, "Home directory of %s", user);
2053 service->bAvailable = default_service->bAvailable;
2054 service->bBrowseable = default_service->bBrowseable;
2056 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2057 pszHomename, user, service->szPath));
2063 * Add a new printer service, with defaults coming from service iFrom.
2066 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
2067 const char *pszPrintername,
2068 struct loadparm_service *default_service)
2070 const char *comment = "From Printcap";
2071 struct loadparm_service *service;
2072 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2074 if (service == NULL)
2077 /* note that we do NOT default the availability flag to True - */
2078 /* we take it from the default service passed. This allows all */
2079 /* dynamic printers to be disabled by disabling the [printers] */
2080 /* entry (if/when the 'available' keyword is implemented!). */
2082 /* the printer name is set to the service name. */
2083 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
2084 lpcfg_string_set(service, &service->comment, comment);
2085 service->bBrowseable = default_service->bBrowseable;
2086 /* Printers cannot be read_only. */
2087 service->bRead_only = false;
2088 /* Printer services must be printable. */
2089 service->bPrint_ok = true;
2091 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2097 * Map a parameter's string representation to something we can use.
2098 * Returns False if the parameter string is not recognised, else TRUE.
2101 static int map_parameter(const char *pszParmName)
2105 if (*pszParmName == '-')
2108 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2109 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2112 /* Warn only if it isn't parametric option */
2113 if (strchr(pszParmName, ':') == NULL)
2114 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2115 /* We do return 'fail' for parametric options as well because they are
2116 stored in different storage
2123 return the parameter structure for a parameter
2125 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2129 if (lp_ctx->s3_fns) {
2130 return lp_ctx->s3_fns->get_parm_struct(name);
2133 parmnum = map_parameter(name);
2134 if (parmnum == -1) return NULL;
2135 return &parm_table[parmnum];
2139 return the parameter pointer for a parameter
2141 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2142 struct loadparm_service *service, struct parm_struct *parm)
2144 if (lp_ctx->s3_fns) {
2145 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2148 if (service == NULL) {
2149 if (parm->p_class == P_LOCAL)
2150 return ((char *)lp_ctx->sDefault)+parm->offset;
2151 else if (parm->p_class == P_GLOBAL)
2152 return ((char *)lp_ctx->globals)+parm->offset;
2155 return ((char *)service) + parm->offset;
2160 return the parameter pointer for a parameter
2162 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2166 if (lp_ctx->s3_fns) {
2167 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2169 return parm->flags & FLAG_CMDLINE;
2174 parmnum = map_parameter(name);
2175 if (parmnum == -1) return false;
2177 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2181 * Find a service by name. Otherwise works like get_service.
2184 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2185 const char *pszServiceName)
2189 if (lp_ctx->s3_fns) {
2190 return lp_ctx->s3_fns->get_service(pszServiceName);
2193 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2194 if (lp_ctx->services[iService] != NULL &&
2195 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2196 return lp_ctx->services[iService];
2203 * Copy a service structure to another.
2204 * If pcopymapDest is NULL then copy all fields
2207 static void copy_service(struct loadparm_service *pserviceDest,
2208 struct loadparm_service *pserviceSource,
2209 struct bitmap *pcopymapDest)
2212 bool bcopyall = (pcopymapDest == NULL);
2213 struct parmlist_entry *data, *pdata, *paramo;
2216 for (i = 0; parm_table[i].label; i++)
2217 if (parm_table[i].p_class == P_LOCAL &&
2218 (bcopyall || bitmap_query(pcopymapDest, i))) {
2220 ((char *)pserviceSource) + parm_table[i].offset;
2222 ((char *)pserviceDest) + parm_table[i].offset;
2224 switch (parm_table[i].type) {
2226 *(bool *)dest_ptr = *(bool *)src_ptr;
2233 *(int *)dest_ptr = *(int *)src_ptr;
2237 lpcfg_string_set(pserviceDest,
2243 lpcfg_string_set_upper(pserviceDest,
2248 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2249 *(const char ***)src_ptr);
2257 init_copymap(pserviceDest);
2258 if (pserviceSource->copymap)
2259 bitmap_copy(pserviceDest->copymap,
2260 pserviceSource->copymap);
2263 data = pserviceSource->param_opt;
2266 pdata = pserviceDest->param_opt;
2267 /* Traverse destination */
2269 /* If we already have same option, override it */
2270 if (strcmp(pdata->key, data->key) == 0) {
2271 talloc_free(pdata->value);
2272 pdata->value = talloc_strdup(pdata,
2277 pdata = pdata->next;
2280 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2283 paramo->key = talloc_strdup(paramo, data->key);
2284 paramo->value = talloc_strdup(paramo, data->value);
2285 DLIST_ADD(pserviceDest->param_opt, paramo);
2292 * Check a service for consistency. Return False if the service is in any way
2293 * incomplete or faulty, else True.
2295 static bool lpcfg_service_ok(struct loadparm_service *service)
2300 if (service->szService[0] == '\0') {
2301 DEBUG(0, ("The following message indicates an internal error:\n"));
2302 DEBUG(0, ("No service name in service entry.\n"));
2306 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2307 /* I can't see why you'd want a non-printable printer service... */
2308 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2309 if (!service->bPrint_ok) {
2310 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2311 service->szService));
2312 service->bPrint_ok = true;
2314 /* [printers] service must also be non-browsable. */
2315 if (service->bBrowseable)
2316 service->bBrowseable = false;
2319 /* If a service is flagged unavailable, log the fact at level 0. */
2320 if (!service->bAvailable)
2321 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2322 service->szService));
2328 /*******************************************************************
2329 Keep a linked list of all config files so we know when one has changed
2330 it's date and needs to be reloaded.
2331 ********************************************************************/
2333 static void add_to_file_list(struct loadparm_context *lp_ctx,
2334 const char *fname, const char *subfname)
2336 struct file_lists *f = lp_ctx->file_lists;
2339 if (f->name && !strcmp(f->name, fname))
2345 f = talloc(lp_ctx, struct file_lists);
2348 f->next = lp_ctx->file_lists;
2349 f->name = talloc_strdup(f, fname);
2354 f->subfname = talloc_strdup(f, subfname);
2359 lp_ctx->file_lists = f;
2360 f->modtime = file_modtime(subfname);
2362 time_t t = file_modtime(subfname);
2368 /*******************************************************************
2369 Check if a config file has changed date.
2370 ********************************************************************/
2371 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2373 struct file_lists *f;
2374 DEBUG(6, ("lp_file_list_changed()\n"));
2376 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2380 n2 = standard_sub_basic(lp_ctx, f->name);
2382 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2383 f->name, n2, ctime(&f->modtime)));
2385 mod_time = file_modtime(n2);
2387 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2388 DEBUGADD(6, ("file %s modified: %s\n", n2,
2390 f->modtime = mod_time;
2391 talloc_free(f->subfname);
2392 f->subfname = talloc_strdup(f, n2);
2399 /***************************************************************************
2400 Handle the "realm" parameter
2401 ***************************************************************************/
2403 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2404 const char *pszParmValue, char **ptr)
2406 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2408 talloc_free(lp_ctx->globals->szRealm_upper);
2409 talloc_free(lp_ctx->globals->szRealm_lower);
2411 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2412 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2417 /***************************************************************************
2418 Handle the include operation.
2419 ***************************************************************************/
2421 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2422 const char *pszParmValue, char **ptr)
2424 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2426 add_to_file_list(lp_ctx, pszParmValue, fname);
2428 lpcfg_string_set(lp_ctx, ptr, fname);
2430 if (file_exist(fname))
2431 return pm_process(fname, do_section, do_parameter, lp_ctx);
2433 DEBUG(2, ("Can't find include file %s\n", fname));
2438 /***************************************************************************
2439 Handle the interpretation of the copy parameter.
2440 ***************************************************************************/
2442 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2443 const char *pszParmValue, char **ptr)
2446 struct loadparm_service *serviceTemp;
2448 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2452 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2454 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2455 if (serviceTemp == lp_ctx->currentService) {
2456 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2458 copy_service(lp_ctx->currentService,
2460 lp_ctx->currentService->copymap);
2464 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2472 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2473 const char *pszParmValue, char **ptr)
2476 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2477 if (lp_ctx->global) {
2478 return debug_parse_levels(pszParmValue);
2483 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2484 const char *pszParmValue, char **ptr)
2486 debug_set_logfile(pszParmValue);
2487 if (lp_ctx->global) {
2488 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2493 /***************************************************************************
2494 Initialise a copymap.
2495 ***************************************************************************/
2497 static void init_copymap(struct loadparm_service *pservice)
2501 TALLOC_FREE(pservice->copymap);
2503 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2504 if (!pservice->copymap)
2506 ("Couldn't allocate copymap!! (size %d)\n",
2507 (int)NUMPARAMETERS));
2509 for (i = 0; i < NUMPARAMETERS; i++)
2510 bitmap_set(pservice->copymap, i);
2514 * Process a parametric option
2516 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2517 struct loadparm_service *service,
2518 const char *pszParmName,
2519 const char *pszParmValue, int flags)
2521 struct parmlist_entry *paramo, *data;
2523 TALLOC_CTX *mem_ctx;
2525 while (isspace((unsigned char)*pszParmName)) {
2529 name = strlower_talloc(lp_ctx, pszParmName);
2530 if (!name) return false;
2532 if (service == NULL) {
2533 data = lp_ctx->globals->param_opt;
2534 mem_ctx = lp_ctx->globals;
2536 data = service->param_opt;
2540 /* Traverse destination */
2541 for (paramo=data; paramo; paramo=paramo->next) {
2542 /* If we already have the option set, override it unless
2543 it was a command line option and the new one isn't */
2544 if (strcmp(paramo->key, name) == 0) {
2545 if ((paramo->priority & FLAG_CMDLINE) &&
2546 !(flags & FLAG_CMDLINE)) {
2551 talloc_free(paramo->value);
2552 paramo->value = talloc_strdup(paramo, pszParmValue);
2553 paramo->priority = flags;
2559 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2562 paramo->key = talloc_strdup(paramo, name);
2563 paramo->value = talloc_strdup(paramo, pszParmValue);
2564 paramo->priority = flags;
2565 if (service == NULL) {
2566 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2568 DLIST_ADD(service->param_opt, paramo);
2576 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2577 const char *pszParmName, const char *pszParmValue,
2578 struct loadparm_context *lp_ctx, bool on_globals)
2581 /* if it is a special case then go ahead */
2582 if (parm_table[parmnum].special) {
2584 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2589 goto mark_non_default;
2592 /* now switch on the type of variable it is */
2593 switch (parm_table[parmnum].type)
2597 if (!set_boolean(pszParmValue, &b)) {
2598 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2601 *(bool *)parm_ptr = b;
2607 if (!set_boolean(pszParmValue, &b)) {
2608 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2611 *(bool *)parm_ptr = !b;
2616 *(int *)parm_ptr = atoi(pszParmValue);
2620 *(char *)parm_ptr = *pszParmValue;
2624 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2630 if (conv_str_size_error(pszParmValue, &val)) {
2631 if (val <= INT_MAX) {
2632 *(int *)parm_ptr = (int)val;
2637 DEBUG(0,("lp_do_parameter(%s): value is not "
2638 "a valid size specifier!\n", pszParmValue));
2643 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2644 pszParmValue, NULL);
2648 char **new_list = str_list_make(mem_ctx,
2649 pszParmValue, NULL);
2650 for (i=0; new_list[i]; i++) {
2651 if (new_list[i][0] == '+' && new_list[i][1]) {
2652 if (!str_list_check(*(const char ***)parm_ptr,
2654 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2657 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2658 str_list_remove(*(const char ***)parm_ptr,
2662 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2663 pszParmName, pszParmValue));
2666 *(const char ***)parm_ptr = (const char **) new_list;
2673 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2677 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2681 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2684 parm_table[parmnum].enum_list[i].name)) {
2686 parm_table[parmnum].
2691 if (!parm_table[parmnum].enum_list[i].name) {
2692 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2693 pszParmValue, pszParmName));
2703 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2704 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2705 /* we have to also unset FLAG_DEFAULT on aliases */
2706 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2707 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2709 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2710 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2717 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2718 const char *pszParmName, const char *pszParmValue)
2720 int parmnum = map_parameter(pszParmName);
2724 if (strchr(pszParmName, ':')) {
2725 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2727 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2731 /* if the flag has been set on the command line, then don't allow override,
2732 but don't report an error */
2733 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2737 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2739 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2740 pszParmName, pszParmValue, lp_ctx, true);
2743 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2744 struct loadparm_service *service,
2745 const char *pszParmName, const char *pszParmValue)
2749 int parmnum = map_parameter(pszParmName);
2752 if (strchr(pszParmName, ':')) {
2753 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2755 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2759 /* if the flag has been set on the command line, then don't allow override,
2760 but don't report an error */
2761 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2765 if (parm_table[parmnum].p_class == P_GLOBAL) {
2767 ("Global parameter %s found in service section!\n",
2771 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2773 if (!service->copymap)
2774 init_copymap(service);
2776 /* this handles the aliases - set the copymap for other
2777 * entries with the same data pointer */
2778 for (i = 0; parm_table[i].label; i++)
2779 if (parm_table[i].offset == parm_table[parmnum].offset &&
2780 parm_table[i].p_class == parm_table[parmnum].p_class)
2781 bitmap_clear(service->copymap, i);
2783 return set_variable(service, parmnum, parm_ptr, pszParmName,
2784 pszParmValue, lp_ctx, false);
2788 * Process a parameter.
2791 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2794 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2796 if (lp_ctx->bInGlobalSection)
2797 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2800 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2801 pszParmName, pszParmValue);
2805 variable argument do parameter
2807 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2808 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2809 const char *pszParmName, const char *fmt, ...)
2816 s = talloc_vasprintf(NULL, fmt, ap);
2818 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2825 set a parameter from the commandline - this is called from command line parameter
2826 parsing code. It sets the parameter then marks the parameter as unable to be modified
2827 by smb.conf processing
2829 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2830 const char *pszParmValue)
2835 if (lp_ctx->s3_fns) {
2836 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2839 parmnum = map_parameter(pszParmName);
2841 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2844 if (parmnum < 0 && strchr(pszParmName, ':')) {
2845 /* set a parametric option */
2846 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2847 pszParmValue, FLAG_CMDLINE);
2851 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2855 /* reset the CMDLINE flag in case this has been called before */
2856 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2858 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2862 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2864 /* we have to also set FLAG_CMDLINE on aliases */
2865 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2866 lp_ctx->flags[i] |= FLAG_CMDLINE;
2868 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2869 lp_ctx->flags[i] |= FLAG_CMDLINE;
2876 set a option from the commandline in 'a=b' format. Use to support --option
2878 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2883 s = talloc_strdup(NULL, option);
2896 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2902 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2905 * Print a parameter of the specified type.
2908 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2910 /* For the seperation of lists values that we print below */
2911 const char *list_sep = ", ";
2916 for (i = 0; p->enum_list[i].name; i++) {
2917 if (*(int *)ptr == p->enum_list[i].value) {
2919 p->enum_list[i].name);
2926 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2930 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2935 fprintf(f, "%d", *(int *)ptr);
2939 fprintf(f, "%c", *(char *)ptr);
2943 int val = *(int *)ptr;
2947 fprintf(f, "0%o", val);
2956 if ((char ***)ptr && *(char ***)ptr) {
2957 char **list = *(char ***)ptr;
2958 for (; *list; list++) {
2959 /* surround strings with whitespace in double quotes */
2960 if (*(list+1) == NULL) {
2961 /* last item, no extra separator */
2964 if ( strchr_m( *list, ' ' ) ) {
2965 fprintf(f, "\"%s\"%s", *list, list_sep);
2967 fprintf(f, "%s%s", *list, list_sep);
2975 if (*(char **)ptr) {
2976 fprintf(f, "%s", *(char **)ptr);
2985 * Check if two parameters are equal.
2988 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2993 return (*((bool *)ptr1) == *((bool *)ptr2));
2999 return (*((int *)ptr1) == *((int *)ptr2));
3002 return (*((char *)ptr1) == *((char *)ptr2));
3006 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
3011 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
3016 return (p1 == p2 || strequal(p1, p2));
3025 * Process a new section (service).
3027 * At this stage all sections are services.
3028 * Later we'll have special sections that permit server parameters to be set.
3029 * Returns True on success, False on failure.
3032 static bool do_section(const char *pszSectionName, void *userdata)
3034 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3036 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3037 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3040 /* if we've just struck a global section, note the fact. */
3041 lp_ctx->bInGlobalSection = isglobal;
3043 /* check for multiple global sections */
3044 if (lp_ctx->bInGlobalSection) {
3045 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3049 /* if we have a current service, tidy it up before moving on */
3052 if (lp_ctx->currentService != NULL)
3053 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3055 /* if all is still well, move to the next record in the services array */
3057 /* We put this here to avoid an odd message order if messages are */
3058 /* issued by the post-processing of a previous section. */
3059 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3061 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
3064 DEBUG(0, ("Failed to add a new service\n"));
3074 * Determine if a particular base parameter is currently set to the default value.
3077 static bool is_default(struct loadparm_service *sDefault, int i)
3079 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
3080 if (!defaults_saved)
3082 switch (parm_table[i].type) {
3085 return str_list_equal((const char **)parm_table[i].def.lvalue,
3086 (const char **)def_ptr);
3089 return strequal(parm_table[i].def.svalue,
3093 return parm_table[i].def.bvalue ==
3100 return parm_table[i].def.ivalue ==
3109 *Display the contents of the global structure.
3112 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3116 struct parmlist_entry *data;
3118 fprintf(f, "# Global parameters\n[global]\n");
3120 for (i = 0; parm_table[i].label; i++)
3121 if (parm_table[i].p_class == P_GLOBAL &&
3122 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3123 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3125 fprintf(f, "\t%s = ", parm_table[i].label);
3126 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3129 if (lp_ctx->globals->param_opt != NULL) {
3130 for (data = lp_ctx->globals->param_opt; data;
3131 data = data->next) {
3132 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3135 fprintf(f, "\t%s = %s\n", data->key, data->value);
3142 * Display the contents of a single services record.
3145 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3146 unsigned int *flags)
3149 struct parmlist_entry *data;
3151 if (pService != sDefault)
3152 fprintf(f, "\n[%s]\n", pService->szService);
3154 for (i = 0; parm_table[i].label; i++) {
3155 if (parm_table[i].p_class == P_LOCAL &&
3156 (*parm_table[i].label != '-') &&
3157 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3159 if (pService == sDefault) {
3160 if (flags && (flags[i] & FLAG_DEFAULT)) {
3163 if (defaults_saved) {
3164 if (is_default(sDefault, i)) {
3169 if (equal_parameter(parm_table[i].type,
3170 ((char *)pService) +
3171 parm_table[i].offset,
3172 ((char *)sDefault) +
3173 parm_table[i].offset))
3177 fprintf(f, "\t%s = ", parm_table[i].label);
3178 print_parameter(&parm_table[i],
3179 ((char *)pService) + parm_table[i].offset, f);
3183 if (pService->param_opt != NULL) {
3184 for (data = pService->param_opt; data; data = data->next) {
3185 fprintf(f, "\t%s = %s\n", data->key, data->value);
3190 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3191 struct loadparm_service *service,
3192 const char *parm_name, FILE * f)
3194 struct parm_struct *parm;
3197 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3202 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3204 print_parameter(parm, ptr, f);
3210 * Return info about the next parameter in a service.
3211 * snum==-1 gives the globals.
3212 * Return NULL when out of parameters.
3216 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3220 /* do the globals */
3221 for (; parm_table[*i].label; (*i)++) {
3222 if ((*parm_table[*i].label == '-'))
3226 && (parm_table[*i].offset ==
3227 parm_table[(*i) - 1].offset)
3228 && (parm_table[*i].p_class ==
3229 parm_table[(*i) - 1].p_class))
3232 return &parm_table[(*i)++];
3235 struct loadparm_service *pService = lp_ctx->services[snum];
3237 for (; parm_table[*i].label; (*i)++) {
3238 if (parm_table[*i].p_class == P_LOCAL &&
3239 (*parm_table[*i].label != '-') &&
3241 (parm_table[*i].offset !=
3242 parm_table[(*i) - 1].offset)))
3244 if (allparameters ||
3245 !equal_parameter(parm_table[*i].type,
3246 ((char *)pService) +
3247 parm_table[*i].offset,
3248 ((char *)lp_ctx->sDefault) +
3249 parm_table[*i].offset))
3251 return &parm_table[(*i)++];
3262 * Auto-load some home services.
3264 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3272 * Unload unused services.
3275 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3276 struct smbsrv_connection *smb,
3277 bool (*snumused) (struct smbsrv_connection *, int))
3280 for (i = 0; i < lp_ctx->iNumServices; i++) {
3281 if (lp_ctx->services[i] == NULL)
3284 if (!snumused || !snumused(smb, i)) {
3285 talloc_free(lp_ctx->services[i]);
3286 lp_ctx->services[i] = NULL;
3292 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3294 struct parmlist_entry *data;
3296 if (lp_ctx->refuse_free) {
3297 /* someone is trying to free the
3298 global_loadparm_context.
3299 We can't allow that. */
3303 if (lp_ctx->globals->param_opt != NULL) {
3304 struct parmlist_entry *next;
3305 for (data = lp_ctx->globals->param_opt; data; data=next) {
3307 if (data->priority & FLAG_CMDLINE) continue;
3308 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3317 * Initialise the global parameter structure.
3319 * Note that most callers should use loadparm_init_global() instead
3321 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3325 struct loadparm_context *lp_ctx;
3326 struct parmlist_entry *parm;
3329 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3333 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3334 lp_ctx->bInGlobalSection = true;
3335 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3336 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3338 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3339 lp_ctx->sDefault->bAvailable = true;
3340 lp_ctx->sDefault->bBrowseable = true;
3341 lp_ctx->sDefault->bRead_only = true;
3342 lp_ctx->sDefault->bMap_archive = true;
3343 lp_ctx->sDefault->iStrictLocking = true;
3344 lp_ctx->sDefault->bOpLocks = true;
3345 lp_ctx->sDefault->iCreate_mask = 0744;
3346 lp_ctx->sDefault->iCreate_force_mode = 0000;
3347 lp_ctx->sDefault->iDir_mask = 0755;
3348 lp_ctx->sDefault->iDir_force_mode = 0000;
3350 DEBUG(3, ("Initialising global parameters\n"));
3352 for (i = 0; parm_table[i].label; i++) {
3353 if ((parm_table[i].type == P_STRING ||
3354 parm_table[i].type == P_USTRING) &&
3355 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3357 if (parm_table[i].p_class == P_LOCAL) {
3358 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3360 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3362 *r = talloc_strdup(lp_ctx, "");
3366 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3367 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3368 talloc_free(logfile);
3370 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3372 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3374 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3375 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3376 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3378 /* options that can be set on the command line must be initialised via
3379 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3381 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3383 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3384 myname = get_myname(lp_ctx);
3385 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3386 talloc_free(myname);
3387 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3389 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3391 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3392 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3394 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");
3395 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3396 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3397 /* the winbind method for domain controllers is for both RODC
3398 auth forwarding and for trusted domains */
3399 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3400 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3402 /* This hive should be dynamically generated by Samba using
3403 data from the sam, but for the moment leave it in a tdb to
3404 keep regedt32 from popping up an annoying dialog. */
3405 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3407 /* using UTF8 by default allows us to support all chars */
3408 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3410 /* Use codepage 850 as a default for the dos character set */
3411 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3414 * Allow the default PASSWD_CHAT to be overridden in local.h.
3416 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3418 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3419 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3420 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3421 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3422 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3424 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3425 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3426 "Samba %s", SAMBA_VERSION_STRING);
3428 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3430 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3431 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3432 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3434 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3435 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3436 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3437 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3438 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3439 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3440 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3441 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3442 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3443 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3444 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3445 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3446 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3448 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3449 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3450 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3451 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3452 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3453 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3454 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3455 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3457 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3459 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3460 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3462 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3463 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3465 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3466 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3467 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3468 #if _SAMBA_BUILD_ >= 4
3469 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3470 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3471 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3472 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3473 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3474 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3476 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3477 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3478 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3480 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3481 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3483 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3485 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3487 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3488 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3489 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3490 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3491 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3492 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3493 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3495 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3497 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3498 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3500 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3501 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3502 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3503 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3504 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3506 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3507 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3509 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3510 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3511 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3513 for (i = 0; parm_table[i].label; i++) {
3514 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3515 lp_ctx->flags[i] |= FLAG_DEFAULT;
3519 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3520 if (!(parm->priority & FLAG_CMDLINE)) {
3521 parm->priority |= FLAG_DEFAULT;
3529 * Initialise the global parameter structure.
3531 struct loadparm_context *loadparm_init_global(bool load_default)
3533 if (global_loadparm_context == NULL) {
3534 global_loadparm_context = loadparm_init(NULL);
3536 if (global_loadparm_context == NULL) {
3539 global_loadparm_context->global = true;
3540 if (load_default && !global_loadparm_context->loaded) {
3541 lpcfg_load_default(global_loadparm_context);
3543 global_loadparm_context->refuse_free = true;
3544 return global_loadparm_context;
3548 * Initialise the global parameter structure.
3550 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3551 const struct loadparm_s3_context *s3_fns)
3553 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3554 if (!loadparm_context) {
3557 loadparm_context->s3_fns = s3_fns;
3558 return loadparm_context;
3561 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3563 return lp_ctx->szConfigFile;
3566 const char *lp_default_path(void)
3568 if (getenv("SMB_CONF_PATH"))
3569 return getenv("SMB_CONF_PATH");
3571 return dyn_CONFIGFILE;
3575 * Update the internal state of a loadparm context after settings
3578 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3580 struct debug_settings settings;
3581 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3583 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3584 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3587 if (!lp_ctx->global) {
3591 panic_action = lp_ctx->globals->panic_action;
3593 reload_charcnv(lp_ctx);
3595 ZERO_STRUCT(settings);
3596 /* Add any more debug-related smb.conf parameters created in
3598 settings.timestamp_logs = true;
3599 debug_set_settings(&settings);
3601 /* FIXME: This is a bit of a hack, but we can't use a global, since
3602 * not everything that uses lp also uses the socket library */
3603 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3604 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3606 unsetenv("SOCKET_TESTNONBLOCK");
3612 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3616 path = lp_default_path();
3618 if (!file_exist(path)) {
3619 /* We allow the default smb.conf file to not exist,
3620 * basically the equivalent of an empty file. */
3621 return lpcfg_update(lp_ctx);
3624 return lpcfg_load(lp_ctx, path);
3628 * Load the services array from the services file.
3630 * Return True on success, False on failure.
3632 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3637 filename = talloc_strdup(lp_ctx, filename);
3639 lp_ctx->szConfigFile = filename;
3641 if (lp_ctx->s3_fns) {
3642 return lp_ctx->s3_fns->load(filename);
3645 lp_ctx->bInGlobalSection = true;
3646 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3647 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3649 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3651 /* We get sections first, so have to start 'behind' to make up */
3652 lp_ctx->currentService = NULL;
3653 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3655 /* finish up the last section */
3656 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3658 if (lp_ctx->currentService != NULL)
3659 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3661 bRetval = bRetval && lpcfg_update(lp_ctx);
3663 /* we do this unconditionally, so that it happens even
3664 for a missing smb.conf */
3665 reload_charcnv(lp_ctx);
3667 if (bRetval == true) {
3668 /* set this up so that any child python tasks will
3669 find the right smb.conf */
3670 setenv("SMB_CONF_PATH", filename, 1);
3672 /* set the context used by the lp_*() function
3674 global_loadparm_context = lp_ctx;
3675 lp_ctx->loaded = true;
3682 * Return the max number of services.
3685 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3687 if (lp_ctx->s3_fns) {
3688 return lp_ctx->s3_fns->get_numservices();
3691 return lp_ctx->iNumServices;
3695 * Display the contents of the services array in human-readable form.
3698 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3703 if (lp_ctx->s3_fns) {
3704 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3708 defaults_saved = !show_defaults;
3710 dump_globals(lp_ctx, f, show_defaults);
3712 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3714 for (iService = 0; iService < maxtoprint; iService++)
3715 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3719 * Display the contents of one service in human-readable form.
3721 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3723 if (service != NULL) {
3724 if (service->szService[0] == '\0')
3726 dump_a_service(service, sDefault, f, NULL);
3730 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3733 if (lp_ctx->s3_fns) {
3734 return lp_ctx->s3_fns->get_servicebynum(snum);
3737 return lp_ctx->services[snum];
3740 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3741 const char *service_name)
3746 if (lp_ctx->s3_fns) {
3747 return lp_ctx->s3_fns->get_service(service_name);
3750 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3751 if (lp_ctx->services[iService] &&
3752 lp_ctx->services[iService]->szService) {
3754 * The substitution here is used to support %U is
3757 serviceName = standard_sub_basic(
3758 lp_ctx->services[iService],
3759 lp_ctx->services[iService]->szService);
3760 if (strequal(serviceName, service_name)) {
3761 talloc_free(serviceName);
3762 return lp_ctx->services[iService];
3764 talloc_free(serviceName);
3768 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3772 const char *lpcfg_servicename(const struct loadparm_service *service)
3774 return lp_string((const char *)service->szService);
3778 * A useful volume label function.
3780 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3783 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3784 service->volume : sDefault->volume));
3786 return lpcfg_servicename(service);
3791 * If we are PDC then prefer us as DMB
3793 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3796 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3797 service->szPrintername : sDefault->szPrintername));
3798 if (ret == NULL || (ret != NULL && *ret == '\0'))
3799 ret = lpcfg_servicename(service);
3806 * Return the max print jobs per queue.
3808 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3810 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3811 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3812 maxjobs = PRINT_MAX_JOBID - 1;
3817 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3819 if (lp_ctx == NULL) {
3820 return get_iconv_handle();
3822 return lp_ctx->iconv_handle;
3825 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3827 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3828 if (!lp_ctx->global) {
3832 if (old_ic == NULL) {
3833 old_ic = global_iconv_handle;
3835 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3836 global_iconv_handle = lp_ctx->iconv_handle;
3839 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3841 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3844 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3846 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3849 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3851 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3854 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3856 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3859 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3861 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3864 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3866 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3867 if (settings == NULL)
3869 SMB_ASSERT(lp_ctx != NULL);
3870 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3871 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3875 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3877 if (lp_ctx->s3_fns) {
3878 return lp_ctx->s3_fns->server_role();
3881 return lp_find_server_role(lp_ctx->globals->server_role,
3882 lp_ctx->globals->security,
3883 lp_ctx->globals->domain_logons,
3884 (lp_ctx->globals->domain_master == true) ||
3885 (lp_ctx->globals->domain_master == Auto));
3888 int lpcfg_security(struct loadparm_context *lp_ctx)
3890 if (lp_ctx->s3_fns) {
3891 return lp_ctx->s3_fns->security();
3894 return lp_find_security(lp_ctx->globals->server_role,
3895 lp_ctx->globals->security);