2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
69 #include "source4/dns_server/dns_update.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved = false;
76 #define LOADPARM_EXTRA_GLOBALS \
77 struct parmlist_entry *param_opt; \
80 char *szUsershareTemplateShare; \
83 int winbindMaxDomainConnections; \
93 #include "lib/param/param_global.h"
95 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
97 /* we don't need a special handler for "dos charset" and "unix charset" */
98 #define handle_dos_charset NULL
99 #define handle_charset NULL
101 /* these are parameter handlers which are not needed in the
104 #define handle_netbios_aliases NULL
105 #define handle_debug_list NULL
106 #define handle_printing NULL
107 #define handle_ldap_debug_level NULL
108 #define handle_idmap_backend NULL
109 #define handle_idmap_uid NULL
110 #define handle_idmap_gid NULL
116 /* prototypes for the special type handlers */
117 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
118 const char *pszParmValue, char **ptr);
119 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
120 const char *pszParmValue, char **ptr);
121 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
122 const char *pszParmValue, char **ptr);
123 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
124 const char *pszParmValue, char **ptr);
125 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
126 const char *pszParmValue, char **ptr);
128 #include "lib/param/param_table.c"
130 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
131 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
133 static struct parm_struct parm_table[] = {
135 .label = "server role",
138 .offset = GLOBAL_VAR(server_role),
140 .enum_list = enum_server_role
143 .label = "domain logons",
146 .offset = GLOBAL_VAR(bDomainLogons),
148 .enum_list = enum_bool_auto
151 .label = "domain master",
154 .offset = GLOBAL_VAR(domain_master),
156 .enum_list = enum_bool_auto
159 .label = "dos charset",
162 .offset = GLOBAL_VAR(dos_charset),
167 .label = "unix charset",
170 .offset = GLOBAL_VAR(unix_charset),
178 .offset = LOCAL_VAR(comment),
181 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
187 .offset = LOCAL_VAR(szPath),
190 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
193 .label = "directory",
196 .offset = LOCAL_VAR(szPath),
202 .label = "workgroup",
205 .offset = GLOBAL_VAR(szWorkgroup),
208 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
214 .offset = GLOBAL_VAR(szRealm),
215 .special = handle_realm,
217 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
220 .label = "netbios name",
223 .offset = GLOBAL_VAR(szNetbiosName),
226 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
229 .label = "netbios aliases",
232 .offset = GLOBAL_VAR(szNetbiosAliases),
237 .label = "netbios scope",
240 .offset = GLOBAL_VAR(szNetbiosScope),
243 .flags = FLAG_ADVANCED,
246 .label = "server string",
249 .offset = GLOBAL_VAR(szServerString),
252 .flags = FLAG_BASIC | FLAG_ADVANCED,
255 .label = "interfaces",
258 .offset = GLOBAL_VAR(szInterfaces),
261 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
264 .label = "bind interfaces only",
267 .offset = GLOBAL_VAR(bBindInterfacesOnly),
270 .flags = FLAG_ADVANCED | FLAG_WIZARD,
273 .label = "passdb backend",
276 .offset = GLOBAL_VAR(passdb_backend),
285 .offset = GLOBAL_VAR(security),
287 .enum_list = enum_security
290 .label = "encrypt passwords",
293 .offset = GLOBAL_VAR(bEncryptPasswords),
298 .label = "null passwords",
301 .offset = GLOBAL_VAR(bNullPasswords),
304 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
307 .label = "obey pam restrictions",
310 .offset = GLOBAL_VAR(bObeyPamRestrictions),
313 .flags = FLAG_ADVANCED,
316 .label = "password server",
319 .offset = GLOBAL_VAR(szPasswordServer),
324 .label = "private dir",
327 .offset = GLOBAL_VAR(szPrivateDir),
332 .label = "passwd chat",
335 .offset = GLOBAL_VAR(szPasswdChat),
340 .label = "password level",
343 .offset = GLOBAL_VAR(pwordlevel),
348 .label = "lanman auth",
351 .offset = GLOBAL_VAR(bLanmanAuth),
354 .flags = FLAG_ADVANCED,
357 .label = "ntlm auth",
360 .offset = GLOBAL_VAR(bNTLMAuth),
363 .flags = FLAG_ADVANCED,
366 .label = "client NTLMv2 auth",
369 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
372 .flags = FLAG_ADVANCED,
375 .label = "client lanman auth",
378 .offset = GLOBAL_VAR(bClientLanManAuth),
381 .flags = FLAG_ADVANCED,
384 .label = "client plaintext auth",
387 .offset = GLOBAL_VAR(bClientPlaintextAuth),
390 .flags = FLAG_ADVANCED,
393 .label = "client use spnego principal",
396 .offset = GLOBAL_VAR(client_use_spnego_principal),
402 .label = "read only",
405 .offset = LOCAL_VAR(bRead_only),
411 .label = "create mask",
414 .offset = LOCAL_VAR(iCreate_mask),
419 .label = "force create mode",
422 .offset = LOCAL_VAR(iCreate_force_mode),
427 .label = "directory mask",
430 .offset = LOCAL_VAR(iDir_mask),
435 .label = "force directory mode",
438 .offset = LOCAL_VAR(iDir_force_mode),
444 .label = "hosts allow",
447 .offset = LOCAL_VAR(szHostsallow),
452 .label = "hosts deny",
455 .offset = LOCAL_VAR(szHostsdeny),
461 .label = "log level",
464 .offset = GLOBAL_VAR(loglevel),
465 .special = handle_debuglevel,
469 .label = "debuglevel",
472 .offset = GLOBAL_VAR(loglevel),
473 .special = handle_debuglevel,
480 .offset = GLOBAL_VAR(logfile),
481 .special = handle_logfile,
483 .flags = FLAG_ADVANCED,
487 .label = "smb ports",
490 .offset = GLOBAL_VAR(smb_ports),
498 .offset = GLOBAL_VAR(nbt_port),
503 .label = "dgram port",
506 .offset = GLOBAL_VAR(dgram_port),
511 .label = "cldap port",
514 .offset = GLOBAL_VAR(cldap_port),
519 .label = "krb5 port",
522 .offset = GLOBAL_VAR(krb5_port),
527 .label = "kpasswd port",
530 .offset = GLOBAL_VAR(kpasswd_port),
538 .offset = GLOBAL_VAR(web_port),
543 .label = "large readwrite",
546 .offset = GLOBAL_VAR(bLargeReadwrite),
549 .flags = FLAG_ADVANCED,
552 .label = "server max protocol",
555 .offset = GLOBAL_VAR(srv_maxprotocol),
557 .enum_list = enum_protocol,
558 .flags = FLAG_ADVANCED,
561 .label = "max protocol",
564 .offset = GLOBAL_VAR(srv_maxprotocol),
566 .enum_list = enum_protocol,
567 .flags = FLAG_ADVANCED,
573 .offset = GLOBAL_VAR(srv_maxprotocol),
575 .enum_list = enum_protocol,
576 .flags = FLAG_ADVANCED,
579 .label = "server min protocol",
582 .offset = GLOBAL_VAR(srv_minprotocol),
584 .enum_list = enum_protocol,
585 .flags = FLAG_ADVANCED,
588 .label = "min protocol",
591 .offset = GLOBAL_VAR(srv_minprotocol),
593 .enum_list = enum_protocol,
594 .flags = FLAG_ADVANCED,
597 .label = "client max protocol",
600 .offset = GLOBAL_VAR(cli_maxprotocol),
602 .enum_list = enum_protocol
605 .label = "client min protocol",
608 .offset = GLOBAL_VAR(cli_minprotocol),
610 .enum_list = enum_protocol
616 .offset = GLOBAL_VAR(bUnicode),
624 .offset = GLOBAL_VAR(bReadRaw),
629 .label = "write raw",
632 .offset = GLOBAL_VAR(bWriteRaw),
637 .label = "disable netbios",
640 .offset = GLOBAL_VAR(bDisableNetbios),
646 .label = "nt status support",
649 .offset = GLOBAL_VAR(bNTStatusSupport),
658 .offset = GLOBAL_VAR(max_mux),
661 .flags = FLAG_ADVANCED,
667 .offset = GLOBAL_VAR(max_xmit),
670 .flags = FLAG_ADVANCED,
674 .label = "name resolve order",
677 .offset = GLOBAL_VAR(szNameResolveOrder),
682 .label = "max wins ttl",
685 .offset = GLOBAL_VAR(max_wins_ttl),
688 .flags = FLAG_ADVANCED,
691 .label = "min wins ttl",
694 .offset = GLOBAL_VAR(min_wins_ttl),
697 .flags = FLAG_ADVANCED,
700 .label = "time server",
703 .offset = GLOBAL_VAR(bTimeServer),
706 .flags = FLAG_ADVANCED,
709 .label = "unix extensions",
712 .offset = GLOBAL_VAR(bUnixExtensions),
715 .flags = FLAG_ADVANCED,
718 .label = "use spnego",
721 .offset = GLOBAL_VAR(bUseSpnego),
726 .label = "server signing",
729 .offset = GLOBAL_VAR(server_signing),
731 .enum_list = enum_smb_signing_vals,
732 .flags = FLAG_ADVANCED,
735 .label = "client signing",
738 .offset = GLOBAL_VAR(client_signing),
740 .enum_list = enum_smb_signing_vals
743 .label = "rpc big endian",
746 .offset = GLOBAL_VAR(bRpcBigEndian),
752 .label = "max connections",
755 .offset = LOCAL_VAR(iMaxConnections),
758 .flags = FLAG_ADVANCED | FLAG_SHARE,
761 .label = "paranoid server security",
764 .offset = GLOBAL_VAR(paranoid_server_security),
769 .label = "socket options",
772 .offset = GLOBAL_VAR(socket_options),
778 .label = "strict sync",
781 .offset = LOCAL_VAR(bStrictSync),
789 .offset = GLOBAL_VAR(bUseMmap),
792 .flags = FLAG_ADVANCED,
796 .label = "max print jobs",
799 .offset = LOCAL_VAR(iMaxPrintJobs),
804 .label = "printable",
807 .offset = LOCAL_VAR(bPrint_ok),
815 .offset = LOCAL_VAR(bPrint_ok),
821 .label = "printer name",
824 .offset = LOCAL_VAR(szPrintername),
827 .flags = FLAG_ADVANCED | FLAG_PRINT,
833 .offset = LOCAL_VAR(szPrintername),
840 .label = "map system",
843 .offset = LOCAL_VAR(bMap_system),
848 .label = "map hidden",
851 .offset = LOCAL_VAR(bMap_hidden),
856 .label = "map archive",
859 .offset = LOCAL_VAR(bMap_archive),
865 .label = "preferred master",
868 .offset = GLOBAL_VAR(bPreferredMaster),
870 .enum_list = enum_bool_auto,
871 .flags = FLAG_BASIC | FLAG_ADVANCED,
874 .label = "prefered master",
877 .offset = GLOBAL_VAR(bPreferredMaster),
879 .enum_list = enum_bool_auto,
883 .label = "local master",
886 .offset = GLOBAL_VAR(bLocalMaster),
891 .label = "browseable",
894 .offset = LOCAL_VAR(bBrowseable),
897 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
900 .label = "browsable",
903 .offset = LOCAL_VAR(bBrowseable),
909 .label = "dns proxy",
912 .offset = GLOBAL_VAR(bWINSdnsProxy),
917 .label = "wins server",
920 .offset = GLOBAL_VAR(szWINSservers),
923 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
926 .label = "wins support",
929 .offset = GLOBAL_VAR(bWINSsupport),
932 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
935 .label = "wins hook",
938 .offset = GLOBAL_VAR(szWINSHook),
941 .flags = FLAG_ADVANCED,
945 .label = "csc policy",
948 .offset = LOCAL_VAR(iCSCPolicy),
950 .enum_list = enum_csc_policy,
951 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
955 .label = "strict locking",
958 .offset = LOCAL_VAR(iStrictLocking),
966 .offset = LOCAL_VAR(bOpLocks),
971 {N_("EventLog Options"), P_SEP, P_SEPARATOR},
974 .label = "eventlog list",
977 .offset = GLOBAL_VAR(szEventLogs),
980 .flags = FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE,
983 {N_("Miscellaneous Options"), P_SEP, P_SEPARATOR},
986 .label = "add share command",
989 .offset = GLOBAL_VAR(szAddShareCommand),
992 .flags = FLAG_ADVANCED,
995 .label = "change share command",
998 .offset = GLOBAL_VAR(szChangeShareCommand),
1001 .flags = FLAG_ADVANCED,
1004 .label = "delete share command",
1006 .p_class = P_GLOBAL,
1007 .offset = GLOBAL_VAR(szDeleteShareCommand),
1010 .flags = FLAG_ADVANCED,
1013 .label = "config file",
1015 .p_class = P_GLOBAL,
1016 .offset = GLOBAL_VAR(szConfigFile),
1019 .flags = FLAG_HIDE|FLAG_META,
1024 .p_class = P_GLOBAL,
1025 .offset = GLOBAL_VAR(szAutoServices),
1028 .flags = FLAG_ADVANCED,
1031 .label = "auto services",
1033 .p_class = P_GLOBAL,
1034 .offset = GLOBAL_VAR(szAutoServices),
1037 .flags = FLAG_ADVANCED,
1040 .label = "lock directory",
1042 .p_class = P_GLOBAL,
1043 .offset = GLOBAL_VAR(szLockDir),
1046 .flags = FLAG_ADVANCED,
1049 .label = "lock dir",
1051 .p_class = P_GLOBAL,
1052 .offset = GLOBAL_VAR(szLockDir),
1058 .label = "state directory",
1060 .p_class = P_GLOBAL,
1061 .offset = GLOBAL_VAR(szStateDir),
1064 .flags = FLAG_ADVANCED,
1067 .label = "cache directory",
1069 .p_class = P_GLOBAL,
1070 .offset = GLOBAL_VAR(szCacheDir),
1073 .flags = FLAG_ADVANCED,
1076 .label = "pid directory",
1078 .p_class = P_GLOBAL,
1079 .offset = GLOBAL_VAR(szPidDir),
1082 .flags = FLAG_ADVANCED,
1085 .label = "ntp signd socket directory",
1087 .p_class = P_GLOBAL,
1088 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1091 .flags = FLAG_ADVANCED,
1096 .label = "utmp directory",
1098 .p_class = P_GLOBAL,
1099 .offset = GLOBAL_VAR(szUtmpDir),
1102 .flags = FLAG_ADVANCED,
1105 .label = "wtmp directory",
1107 .p_class = P_GLOBAL,
1108 .offset = GLOBAL_VAR(szWtmpDir),
1111 .flags = FLAG_ADVANCED,
1116 .p_class = P_GLOBAL,
1117 .offset = GLOBAL_VAR(bUtmp),
1120 .flags = FLAG_ADVANCED,
1124 .label = "default service",
1126 .p_class = P_GLOBAL,
1127 .offset = GLOBAL_VAR(szDefaultService),
1130 .flags = FLAG_ADVANCED,
1135 .p_class = P_GLOBAL,
1136 .offset = GLOBAL_VAR(szDefaultService),
1139 .flags = FLAG_ADVANCED,
1142 .label = "message command",
1144 .p_class = P_GLOBAL,
1145 .offset = GLOBAL_VAR(szMsgCommand),
1148 .flags = FLAG_ADVANCED,
1151 .label = "dfree cache time",
1154 .offset = LOCAL_VAR(iDfreeCacheTime),
1157 .flags = FLAG_ADVANCED,
1160 .label = "dfree command",
1163 .offset = LOCAL_VAR(szDfree),
1166 .flags = FLAG_ADVANCED,
1169 .label = "get quota command",
1171 .p_class = P_GLOBAL,
1172 .offset = GLOBAL_VAR(szGetQuota),
1175 .flags = FLAG_ADVANCED,
1178 .label = "set quota command",
1180 .p_class = P_GLOBAL,
1181 .offset = GLOBAL_VAR(szSetQuota),
1184 .flags = FLAG_ADVANCED,
1187 .label = "remote announce",
1189 .p_class = P_GLOBAL,
1190 .offset = GLOBAL_VAR(szRemoteAnnounce),
1193 .flags = FLAG_ADVANCED,
1196 .label = "remote browse sync",
1198 .p_class = P_GLOBAL,
1199 .offset = GLOBAL_VAR(szRemoteBrowseSync),
1202 .flags = FLAG_ADVANCED,
1205 .label = "socket address",
1207 .p_class = P_GLOBAL,
1208 .offset = GLOBAL_VAR(szSocketAddress),
1211 .flags = FLAG_ADVANCED,
1214 .label = "nmbd bind explicit broadcast",
1216 .p_class = P_GLOBAL,
1217 .offset = GLOBAL_VAR(bNmbdBindExplicitBroadcast),
1220 .flags = FLAG_ADVANCED,
1223 .label = "homedir map",
1225 .p_class = P_GLOBAL,
1226 .offset = GLOBAL_VAR(szNISHomeMapName),
1229 .flags = FLAG_ADVANCED,
1232 .label = "afs username map",
1234 .p_class = P_GLOBAL,
1235 .offset = GLOBAL_VAR(szAfsUsernameMap),
1238 .flags = FLAG_ADVANCED,
1241 .label = "afs token lifetime",
1243 .p_class = P_GLOBAL,
1244 .offset = GLOBAL_VAR(iAfsTokenLifetime),
1247 .flags = FLAG_ADVANCED,
1250 .label = "log nt token command",
1252 .p_class = P_GLOBAL,
1253 .offset = GLOBAL_VAR(szLogNtTokenCommand),
1256 .flags = FLAG_ADVANCED,
1259 .label = "NIS homedir",
1261 .p_class = P_GLOBAL,
1262 .offset = GLOBAL_VAR(bNISHomeMap),
1265 .flags = FLAG_ADVANCED,
1271 .offset = LOCAL_VAR(valid),
1280 .offset = LOCAL_VAR(szCopy),
1281 .special = handle_copy,
1289 .offset = LOCAL_VAR(szInclude),
1290 .special = handle_include,
1292 .flags = FLAG_HIDE|FLAG_META,
1298 .offset = LOCAL_VAR(szPreExec),
1301 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1307 .offset = LOCAL_VAR(szPreExec),
1310 .flags = FLAG_ADVANCED,
1313 .label = "preexec close",
1316 .offset = LOCAL_VAR(bPreexecClose),
1319 .flags = FLAG_ADVANCED | FLAG_SHARE,
1322 .label = "postexec",
1325 .offset = LOCAL_VAR(szPostExec),
1328 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1331 .label = "root preexec",
1334 .offset = LOCAL_VAR(szRootPreExec),
1337 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1340 .label = "root preexec close",
1343 .offset = LOCAL_VAR(bRootpreexecClose),
1346 .flags = FLAG_ADVANCED | FLAG_SHARE,
1349 .label = "root postexec",
1352 .offset = LOCAL_VAR(szRootPostExec),
1355 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1358 .label = "available",
1361 .offset = LOCAL_VAR(bAvailable),
1364 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1367 .label = "registry shares",
1369 .p_class = P_GLOBAL,
1370 .offset = GLOBAL_VAR(bRegistryShares),
1373 .flags = FLAG_ADVANCED,
1376 .label = "usershare allow guests",
1378 .p_class = P_GLOBAL,
1379 .offset = GLOBAL_VAR(bUsershareAllowGuests),
1382 .flags = FLAG_ADVANCED,
1385 .label = "usershare max shares",
1387 .p_class = P_GLOBAL,
1388 .offset = GLOBAL_VAR(iUsershareMaxShares),
1391 .flags = FLAG_ADVANCED,
1394 .label = "usershare owner only",
1396 .p_class = P_GLOBAL,
1397 .offset = GLOBAL_VAR(bUsershareOwnerOnly),
1400 .flags = FLAG_ADVANCED,
1403 .label = "usershare path",
1405 .p_class = P_GLOBAL,
1406 .offset = GLOBAL_VAR(szUsersharePath),
1409 .flags = FLAG_ADVANCED,
1412 .label = "usershare prefix allow list",
1414 .p_class = P_GLOBAL,
1415 .offset = GLOBAL_VAR(szUsersharePrefixAllowList),
1418 .flags = FLAG_ADVANCED,
1421 .label = "usershare prefix deny list",
1423 .p_class = P_GLOBAL,
1424 .offset = GLOBAL_VAR(szUsersharePrefixDenyList),
1427 .flags = FLAG_ADVANCED,
1430 .label = "usershare template share",
1432 .p_class = P_GLOBAL,
1433 .offset = GLOBAL_VAR(szUsershareTemplateShare),
1436 .flags = FLAG_ADVANCED,
1442 .offset = LOCAL_VAR(volume),
1445 .flags = FLAG_ADVANCED | FLAG_SHARE,
1451 .offset = LOCAL_VAR(fstype),
1454 .flags = FLAG_ADVANCED | FLAG_SHARE,
1457 .label = "set directory",
1460 .offset = LOCAL_VAR(bNo_set_dir),
1463 .flags = FLAG_ADVANCED | FLAG_SHARE,
1466 .label = "allow insecure wide links",
1468 .p_class = P_GLOBAL,
1469 .offset = GLOBAL_VAR(bAllowInsecureWidelinks),
1472 .flags = FLAG_ADVANCED,
1475 .label = "wide links",
1478 .offset = LOCAL_VAR(bWidelinks),
1481 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1484 .label = "follow symlinks",
1487 .offset = LOCAL_VAR(bSymlinks),
1490 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1493 .label = "dont descend",
1496 .offset = LOCAL_VAR(szDontdescend),
1499 .flags = FLAG_ADVANCED | FLAG_SHARE,
1502 .label = "magic script",
1505 .offset = LOCAL_VAR(szMagicScript),
1508 .flags = FLAG_ADVANCED | FLAG_SHARE,
1511 .label = "magic output",
1514 .offset = LOCAL_VAR(szMagicOutput),
1517 .flags = FLAG_ADVANCED | FLAG_SHARE,
1520 .label = "delete readonly",
1523 .offset = LOCAL_VAR(bDeleteReadonly),
1526 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1529 .label = "dos filemode",
1532 .offset = LOCAL_VAR(bDosFilemode),
1535 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1538 .label = "dos filetimes",
1541 .offset = LOCAL_VAR(bDosFiletimes),
1544 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1547 .label = "dos filetime resolution",
1550 .offset = LOCAL_VAR(bDosFiletimeResolution),
1553 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1556 .label = "fake directory create times",
1559 .offset = LOCAL_VAR(bFakeDirCreateTimes),
1562 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1565 .label = "async smb echo handler",
1567 .p_class = P_GLOBAL,
1568 .offset = GLOBAL_VAR(bAsyncSMBEchoHandler),
1571 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1574 .label = "panic action",
1576 .p_class = P_GLOBAL,
1577 .offset = GLOBAL_VAR(szPanicAction),
1580 .flags = FLAG_ADVANCED,
1583 .label = "perfcount module",
1585 .p_class = P_GLOBAL,
1586 .offset = GLOBAL_VAR(szSMBPerfcountModule),
1589 .flags = FLAG_ADVANCED,
1592 {N_("VFS module options"), P_SEP, P_SEPARATOR},
1595 .label = "vfs objects",
1598 .offset = LOCAL_VAR(szVfsObjects),
1601 .flags = FLAG_ADVANCED | FLAG_SHARE,
1604 .label = "vfs object",
1607 .offset = LOCAL_VAR(szVfsObjects),
1614 {N_("MSDFS options"), P_SEP, P_SEPARATOR},
1617 .label = "msdfs root",
1620 .offset = LOCAL_VAR(bMSDfsRoot),
1623 .flags = FLAG_ADVANCED | FLAG_SHARE,
1626 .label = "msdfs proxy",
1629 .offset = LOCAL_VAR(szMSDfsProxy),
1632 .flags = FLAG_ADVANCED | FLAG_SHARE,
1635 .label = "host msdfs",
1637 .p_class = P_GLOBAL,
1638 .offset = GLOBAL_VAR(bHostMSDfs),
1641 .flags = FLAG_ADVANCED,
1644 {N_("Winbind options"), P_SEP, P_SEPARATOR},
1647 .label = "passdb expand explicit",
1649 .p_class = P_GLOBAL,
1650 .offset = GLOBAL_VAR(bPassdbExpandExplicit),
1653 .flags = FLAG_ADVANCED,
1656 .label = "idmap backend",
1658 .p_class = P_GLOBAL,
1659 .offset = GLOBAL_VAR(szIdmapBackend),
1660 .special = handle_idmap_backend,
1662 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1665 .label = "idmap cache time",
1667 .p_class = P_GLOBAL,
1668 .offset = GLOBAL_VAR(iIdmapCacheTime),
1671 .flags = FLAG_ADVANCED,
1674 .label = "idmap negative cache time",
1676 .p_class = P_GLOBAL,
1677 .offset = GLOBAL_VAR(iIdmapNegativeCacheTime),
1680 .flags = FLAG_ADVANCED,
1683 .label = "idmap uid",
1685 .p_class = P_GLOBAL,
1686 .offset = GLOBAL_VAR(szIdmapUID),
1687 .special = handle_idmap_uid,
1689 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1692 .label = "winbind uid",
1694 .p_class = P_GLOBAL,
1695 .offset = GLOBAL_VAR(szIdmapUID),
1696 .special = handle_idmap_uid,
1701 .label = "idmap gid",
1703 .p_class = P_GLOBAL,
1704 .offset = GLOBAL_VAR(szIdmapGID),
1705 .special = handle_idmap_gid,
1707 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1710 .label = "winbind gid",
1712 .p_class = P_GLOBAL,
1713 .offset = GLOBAL_VAR(szIdmapGID),
1714 .special = handle_idmap_gid,
1719 .label = "template homedir",
1721 .p_class = P_GLOBAL,
1722 .offset = GLOBAL_VAR(szTemplateHomedir),
1725 .flags = FLAG_ADVANCED,
1728 .label = "template shell",
1730 .p_class = P_GLOBAL,
1731 .offset = GLOBAL_VAR(szTemplateShell),
1734 .flags = FLAG_ADVANCED,
1737 .label = "winbind separator",
1739 .p_class = P_GLOBAL,
1740 .offset = GLOBAL_VAR(szWinbindSeparator),
1743 .flags = FLAG_ADVANCED,
1746 .label = "winbind cache time",
1748 .p_class = P_GLOBAL,
1749 .offset = GLOBAL_VAR(winbind_cache_time),
1752 .flags = FLAG_ADVANCED,
1755 .label = "winbind reconnect delay",
1757 .p_class = P_GLOBAL,
1758 .offset = GLOBAL_VAR(winbind_reconnect_delay),
1761 .flags = FLAG_ADVANCED,
1764 .label = "winbind max clients",
1766 .p_class = P_GLOBAL,
1767 .offset = GLOBAL_VAR(winbind_max_clients),
1770 .flags = FLAG_ADVANCED,
1773 .label = "winbind enum users",
1775 .p_class = P_GLOBAL,
1776 .offset = GLOBAL_VAR(bWinbindEnumUsers),
1779 .flags = FLAG_ADVANCED,
1782 .label = "winbind enum groups",
1784 .p_class = P_GLOBAL,
1785 .offset = GLOBAL_VAR(bWinbindEnumGroups),
1788 .flags = FLAG_ADVANCED,
1791 .label = "winbind use default domain",
1793 .p_class = P_GLOBAL,
1794 .offset = GLOBAL_VAR(bWinbindUseDefaultDomain),
1797 .flags = FLAG_ADVANCED,
1800 .label = "winbind trusted domains only",
1802 .p_class = P_GLOBAL,
1803 .offset = GLOBAL_VAR(bWinbindTrustedDomainsOnly),
1806 .flags = FLAG_ADVANCED,
1809 .label = "winbind nested groups",
1811 .p_class = P_GLOBAL,
1812 .offset = GLOBAL_VAR(bWinbindNestedGroups),
1815 .flags = FLAG_ADVANCED,
1818 .label = "winbind expand groups",
1820 .p_class = P_GLOBAL,
1821 .offset = GLOBAL_VAR(winbind_expand_groups),
1824 .flags = FLAG_ADVANCED,
1827 .label = "winbind nss info",
1829 .p_class = P_GLOBAL,
1830 .offset = GLOBAL_VAR(szWinbindNssInfo),
1833 .flags = FLAG_ADVANCED,
1836 .label = "winbind refresh tickets",
1838 .p_class = P_GLOBAL,
1839 .offset = GLOBAL_VAR(bWinbindRefreshTickets),
1842 .flags = FLAG_ADVANCED,
1845 .label = "winbind offline logon",
1847 .p_class = P_GLOBAL,
1848 .offset = GLOBAL_VAR(bWinbindOfflineLogon),
1851 .flags = FLAG_ADVANCED,
1854 .label = "winbind normalize names",
1856 .p_class = P_GLOBAL,
1857 .offset = GLOBAL_VAR(bWinbindNormalizeNames),
1860 .flags = FLAG_ADVANCED,
1863 .label = "winbind rpc only",
1865 .p_class = P_GLOBAL,
1866 .offset = GLOBAL_VAR(bWinbindRpcOnly),
1869 .flags = FLAG_ADVANCED,
1872 .label = "create krb5 conf",
1874 .p_class = P_GLOBAL,
1875 .offset = GLOBAL_VAR(bCreateKrb5Conf),
1878 .flags = FLAG_ADVANCED,
1881 .label = "ncalrpc dir",
1883 .p_class = P_GLOBAL,
1884 .offset = GLOBAL_VAR(ncalrpc_dir),
1887 .flags = FLAG_ADVANCED,
1890 .label = "winbind max domain connections",
1892 .p_class = P_GLOBAL,
1893 .offset = GLOBAL_VAR(winbindMaxDomainConnections),
1896 .flags = FLAG_ADVANCED,
1899 .label = "winbindd socket directory",
1901 .p_class = P_GLOBAL,
1902 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1905 .flags = FLAG_ADVANCED,
1908 .label = "winbindd privileged socket directory",
1910 .p_class = P_GLOBAL,
1911 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1914 .flags = FLAG_ADVANCED,
1917 .label = "winbind sealed pipes",
1919 .p_class = P_GLOBAL,
1920 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1923 .flags = FLAG_ADVANCED,
1926 {N_("DNS options"), P_SEP, P_SEPARATOR},
1928 .label = "allow dns updates",
1930 .p_class = P_GLOBAL,
1931 .offset = GLOBAL_VAR(allow_dns_updates),
1933 .enum_list = enum_dns_update_settings,
1934 .flags = FLAG_ADVANCED,
1937 .label = "dns forwarder",
1939 .p_class = P_GLOBAL,
1940 .offset = GLOBAL_VAR(dns_forwarder),
1943 .flags = FLAG_ADVANCED,
1946 .label = "dns recursive queries",
1948 .p_class = P_GLOBAL,
1949 .offset = GLOBAL_VAR(dns_recursive_queries),
1954 .label = "dns update command",
1956 .p_class = P_GLOBAL,
1957 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1960 .flags = FLAG_ADVANCED,
1963 .label = "nsupdate command",
1965 .p_class = P_GLOBAL,
1966 .offset = GLOBAL_VAR(szNSUpdateCommand),
1969 .flags = FLAG_ADVANCED,
1972 .label = "rndc command",
1974 .p_class = P_GLOBAL,
1975 .offset = GLOBAL_VAR(szRNDCCommand),
1978 .flags = FLAG_ADVANCED,
1981 .label = "multicast dns register",
1983 .p_class = P_GLOBAL,
1984 .offset = GLOBAL_VAR(bMulticastDnsRegister),
1987 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1990 {N_("AD DC options"), P_SEP, P_SEPARATOR},
1993 .label = "samba kcc command",
1995 .p_class = P_GLOBAL,
1996 .offset = GLOBAL_VAR(szSambaKCCCommand),
1999 .flags = FLAG_ADVANCED,
2002 .label = "server services",
2004 .p_class = P_GLOBAL,
2005 .offset = GLOBAL_VAR(server_services),
2010 .label = "dcerpc endpoint servers",
2012 .p_class = P_GLOBAL,
2013 .offset = GLOBAL_VAR(dcerpc_ep_servers),
2018 .label = "spn update command",
2020 .p_class = P_GLOBAL,
2021 .offset = GLOBAL_VAR(szSPNUpdateCommand),
2024 .flags = FLAG_ADVANCED,
2027 .label = "share backend",
2029 .p_class = P_GLOBAL,
2030 .offset = GLOBAL_VAR(szShareBackend),
2035 .label = "ntvfs handler",
2038 .offset = LOCAL_VAR(ntvfs_handler),
2043 {N_("TLS options"), P_SEP, P_SEPARATOR},
2046 .label = "tls enabled",
2048 .p_class = P_GLOBAL,
2049 .offset = GLOBAL_VAR(tls_enabled),
2054 .label = "tls keyfile",
2056 .p_class = P_GLOBAL,
2057 .offset = GLOBAL_VAR(tls_keyfile),
2062 .label = "tls certfile",
2064 .p_class = P_GLOBAL,
2065 .offset = GLOBAL_VAR(tls_certfile),
2070 .label = "tls cafile",
2072 .p_class = P_GLOBAL,
2073 .offset = GLOBAL_VAR(tls_cafile),
2078 .label = "tls crlfile",
2080 .p_class = P_GLOBAL,
2081 .offset = GLOBAL_VAR(tls_crlfile),
2086 .label = "tls dh params file",
2088 .p_class = P_GLOBAL,
2089 .offset = GLOBAL_VAR(tls_dhpfile),
2094 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
2098 /* local variables */
2099 struct loadparm_context {
2100 const char *szConfigFile;
2101 struct loadparm_global *globals;
2102 struct loadparm_service **services;
2103 struct loadparm_service *sDefault;
2104 struct smb_iconv_handle *iconv_handle;
2106 struct loadparm_service *currentService;
2107 bool bInGlobalSection;
2109 struct file_lists *next;
2114 unsigned int flags[NUMPARAMETERS];
2117 bool global; /* Is this the global context, which may set
2118 * global variables such as debug level etc? */
2119 const struct loadparm_s3_helpers *s3_fns;
2123 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
2125 if (lp_ctx->s3_fns) {
2126 return lp_ctx->s3_fns->get_default_loadparm_service();
2128 return lp_ctx->sDefault;
2132 * Convenience routine to grab string parameters into temporary memory
2133 * and run standard_sub_basic on them.
2135 * The buffers can be written to by
2136 * callers without affecting the source string.
2139 static const char *lp_string(const char *s)
2141 #if 0 /* until REWRITE done to make thread-safe */
2142 size_t len = s ? strlen(s) : 0;
2146 /* The follow debug is useful for tracking down memory problems
2147 especially if you have an inner loop that is calling a lp_*()
2148 function that returns a string. Perhaps this debug should be
2149 present all the time? */
2152 DEBUG(10, ("lp_string(%s)\n", s));
2155 #if 0 /* until REWRITE done to make thread-safe */
2157 lp_talloc = talloc_init("lp_talloc");
2159 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
2167 strlcpy(ret, s, len);
2169 if (trim_string(ret, "\"", "\"")) {
2170 if (strchr(ret,'"') != NULL)
2171 strlcpy(ret, s, len);
2174 standard_sub_basic(ret,len+100);
2181 In this section all the functions that are used to access the
2182 parameters from the rest of the program are defined
2186 * the creation of separate lpcfg_*() and lp_*() functions is to allow
2187 * for code compatibility between existing Samba4 and Samba3 code.
2190 /* this global context supports the lp_*() function varients */
2191 static struct loadparm_context *global_loadparm_context;
2193 #define lpcfg_default_service global_loadparm_context->sDefault
2194 #define lpcfg_global_service(i) global_loadparm_context->services[i]
2196 #define FN_GLOBAL_STRING(fn_name,var_name) \
2197 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
2198 if (lp_ctx == NULL) return NULL; \
2199 if (lp_ctx->s3_fns) { \
2200 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2201 return lp_ctx->s3_fns->fn_name(); \
2203 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
2206 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
2207 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
2208 if (lp_ctx == NULL) return NULL; \
2209 if (lp_ctx->s3_fns) { \
2210 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2211 return lp_ctx->s3_fns->fn_name(); \
2213 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
2216 #define FN_GLOBAL_LIST(fn_name,var_name) \
2217 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
2218 if (lp_ctx == NULL) return NULL; \
2219 if (lp_ctx->s3_fns) { \
2220 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2221 return lp_ctx->s3_fns->fn_name(); \
2223 return lp_ctx->globals->var_name; \
2226 #define FN_GLOBAL_BOOL(fn_name,var_name) \
2227 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
2228 if (lp_ctx == NULL) return false; \
2229 if (lp_ctx->s3_fns) { \
2230 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2231 return lp_ctx->s3_fns->fn_name(); \
2233 return lp_ctx->globals->var_name; \
2236 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
2237 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
2238 if (lp_ctx->s3_fns) { \
2239 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2240 return lp_ctx->s3_fns->fn_name(); \
2242 return lp_ctx->globals->var_name; \
2245 /* Local parameters don't need the ->s3_fns because the struct
2246 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
2248 #define FN_LOCAL_STRING(fn_name,val) \
2249 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
2250 struct loadparm_service *sDefault) { \
2251 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
2254 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
2256 #define FN_LOCAL_LIST(fn_name,val) \
2257 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
2258 struct loadparm_service *sDefault) {\
2259 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
2262 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
2264 #define FN_LOCAL_BOOL(fn_name,val) \
2265 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
2266 struct loadparm_service *sDefault) { \
2267 return((service != NULL)? service->val : sDefault->val); \
2270 #define FN_LOCAL_INTEGER(fn_name,val) \
2271 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
2272 struct loadparm_service *sDefault) { \
2273 return((service != NULL)? service->val : sDefault->val); \
2276 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
2278 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
2280 #define FN_LOCAL_CHAR(fn_name,val) \
2281 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
2282 struct loadparm_service *sDefault) { \
2283 return((service != NULL)? service->val : sDefault->val); \
2286 #include "lib/param/param_functions.c"
2288 /* These functions remain only in lib/param for now */
2289 FN_GLOBAL_BOOL(readraw, bReadRaw)
2290 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
2291 FN_GLOBAL_STRING(cachedir, szCacheDir)
2292 FN_GLOBAL_STRING(socket_address, szSocketAddress)
2293 FN_GLOBAL_STRING(statedir, szStateDir)
2295 /* local prototypes */
2296 static int map_parameter(const char *pszParmName);
2297 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2298 const char *pszServiceName);
2299 static void copy_service(struct loadparm_service *pserviceDest,
2300 struct loadparm_service *pserviceSource,
2301 struct bitmap *pcopymapDest);
2302 static bool lpcfg_service_ok(struct loadparm_service *service);
2303 static bool do_section(const char *pszSectionName, void *);
2304 static void init_copymap(struct loadparm_service *pservice);
2306 /* This is a helper function for parametrical options support. */
2307 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
2308 /* Actual parametrical functions are quite simple */
2309 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
2310 struct loadparm_service *service,
2311 const char *type, const char *option)
2313 char *vfskey_tmp = NULL;
2314 char *vfskey = NULL;
2315 struct parmlist_entry *data;
2320 if (lp_ctx->s3_fns) {
2321 return lp_ctx->s3_fns->get_parametric(service, type, option);
2324 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
2326 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
2327 if (vfskey_tmp == NULL) return NULL;
2328 vfskey = strlower_talloc(NULL, vfskey_tmp);
2329 talloc_free(vfskey_tmp);
2332 if (strcmp(data->key, vfskey) == 0) {
2333 talloc_free(vfskey);
2339 if (service != NULL) {
2340 /* Try to fetch the same option but from globals */
2341 /* but only if we are not already working with globals */
2342 for (data = lp_ctx->globals->param_opt; data;
2343 data = data->next) {
2344 if (strcmp(data->key, vfskey) == 0) {
2345 talloc_free(vfskey);
2351 talloc_free(vfskey);
2358 * convenience routine to return int parameters.
2360 static int lp_int(const char *s)
2364 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
2368 return strtol(s, NULL, 0);
2372 * convenience routine to return unsigned long parameters.
2374 static unsigned long lp_ulong(const char *s)
2378 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
2382 return strtoul(s, NULL, 0);
2386 * convenience routine to return unsigned long parameters.
2388 static long lp_long(const char *s)
2392 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
2396 return strtol(s, NULL, 0);
2400 * convenience routine to return unsigned long parameters.
2402 static double lp_double(const char *s)
2406 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
2410 return strtod(s, NULL);
2414 * convenience routine to return boolean parameters.
2416 static bool lp_bool(const char *s)
2421 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
2425 if (!set_boolean(s, &ret)) {
2426 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
2435 * Return parametric option from a given service. Type is a part of option before ':'
2436 * Parametric option has following syntax: 'Type: option = value'
2437 * Returned value is allocated in 'lp_talloc' context
2440 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
2441 struct loadparm_service *service, const char *type,
2444 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2447 return lp_string(value);
2453 * Return parametric option from a given service. Type is a part of option before ':'
2454 * Parametric option has following syntax: 'Type: option = value'
2455 * Returned value is allocated in 'lp_talloc' context
2458 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
2459 struct loadparm_context *lp_ctx,
2460 struct loadparm_service *service,
2462 const char *option, const char *separator)
2464 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2467 return (const char **)str_list_make(mem_ctx, value, separator);
2473 * Return parametric option from a given service. Type is a part of option before ':'
2474 * Parametric option has following syntax: 'Type: option = value'
2477 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
2478 struct loadparm_service *service, const char *type,
2479 const char *option, int default_v)
2481 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2484 return lp_int(value);
2490 * Return parametric option from a given service. Type is a part of
2491 * option before ':'.
2492 * Parametric option has following syntax: 'Type: option = value'.
2495 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
2496 struct loadparm_service *service, const char *type,
2497 const char *option, int default_v)
2501 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2503 if (value && conv_str_size_error(value, &bval)) {
2504 if (bval <= INT_MAX) {
2513 * Return parametric option from a given service.
2514 * Type is a part of option before ':'
2515 * Parametric option has following syntax: 'Type: option = value'
2517 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
2518 struct loadparm_service *service, const char *type,
2519 const char *option, unsigned long default_v)
2521 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2524 return lp_ulong(value);
2529 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
2530 struct loadparm_service *service, const char *type,
2531 const char *option, long default_v)
2533 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2536 return lp_long(value);
2541 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
2542 struct loadparm_service *service, const char *type,
2543 const char *option, double default_v)
2545 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2548 return lp_double(value);
2554 * Return parametric option from a given service. Type is a part of option before ':'
2555 * Parametric option has following syntax: 'Type: option = value'
2558 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
2559 struct loadparm_service *service, const char *type,
2560 const char *option, bool default_v)
2562 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2565 return lp_bool(value);
2572 * Initialise a service to the defaults.
2575 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
2577 struct loadparm_service *pservice =
2578 talloc_zero(mem_ctx, struct loadparm_service);
2579 copy_service(pservice, sDefault, NULL);
2584 * Set a string value, deallocating any existing space, and allocing the space
2587 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
2594 *dest = talloc_strdup(mem_ctx, src);
2595 if ((*dest) == NULL) {
2596 DEBUG(0,("Out of memory in string_set\n"));
2604 * Set a string value, deallocating any existing space, and allocing the space
2607 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
2614 *dest = strupper_talloc(mem_ctx, src);
2615 if ((*dest) == NULL) {
2616 DEBUG(0,("Out of memory in string_set_upper\n"));
2626 * Add a new service to the services array initialising it with the given
2630 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
2631 const struct loadparm_service *pservice,
2635 struct loadparm_service tservice;
2636 int num_to_alloc = lp_ctx->iNumServices + 1;
2637 struct parmlist_entry *data, *pdata;
2639 if (pservice == NULL) {
2640 pservice = lp_ctx->sDefault;
2643 tservice = *pservice;
2645 /* it might already exist */
2647 struct loadparm_service *service = getservicebyname(lp_ctx,
2649 if (service != NULL) {
2650 /* Clean all parametric options for service */
2651 /* They will be added during parsing again */
2652 data = service->param_opt;
2658 service->param_opt = NULL;
2663 /* find an invalid one */
2664 for (i = 0; i < lp_ctx->iNumServices; i++)
2665 if (lp_ctx->services[i] == NULL)
2668 /* if not, then create one */
2669 if (i == lp_ctx->iNumServices) {
2670 struct loadparm_service **tsp;
2672 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
2675 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2678 lp_ctx->services = tsp;
2679 lp_ctx->services[lp_ctx->iNumServices] = NULL;
2682 lp_ctx->iNumServices++;
2685 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
2686 if (lp_ctx->services[i] == NULL) {
2687 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2690 copy_service(lp_ctx->services[i], &tservice, NULL);
2692 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
2693 return lp_ctx->services[i];
2697 * Add a new home service, with the specified home directory, defaults coming
2698 * from service ifrom.
2701 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
2702 const char *pszHomename,
2703 struct loadparm_service *default_service,
2704 const char *user, const char *pszHomedir)
2706 struct loadparm_service *service;
2708 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
2710 if (service == NULL)
2713 if (!(*(default_service->szPath))
2714 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
2715 service->szPath = talloc_strdup(service, pszHomedir);
2717 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
2720 if (!(*(service->comment))) {
2721 service->comment = talloc_asprintf(service, "Home directory of %s", user);
2723 service->bAvailable = default_service->bAvailable;
2724 service->bBrowseable = default_service->bBrowseable;
2726 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2727 pszHomename, user, service->szPath));
2733 * Add a new printer service, with defaults coming from service iFrom.
2736 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
2737 const char *pszPrintername,
2738 struct loadparm_service *default_service)
2740 const char *comment = "From Printcap";
2741 struct loadparm_service *service;
2742 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2744 if (service == NULL)
2747 /* note that we do NOT default the availability flag to True - */
2748 /* we take it from the default service passed. This allows all */
2749 /* dynamic printers to be disabled by disabling the [printers] */
2750 /* entry (if/when the 'available' keyword is implemented!). */
2752 /* the printer name is set to the service name. */
2753 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
2754 lpcfg_string_set(service, &service->comment, comment);
2755 service->bBrowseable = default_service->bBrowseable;
2756 /* Printers cannot be read_only. */
2757 service->bRead_only = false;
2758 /* Printer services must be printable. */
2759 service->bPrint_ok = true;
2761 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2767 * Map a parameter's string representation to something we can use.
2768 * Returns False if the parameter string is not recognised, else TRUE.
2771 static int map_parameter(const char *pszParmName)
2775 if (*pszParmName == '-')
2778 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2779 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2782 /* Warn only if it isn't parametric option */
2783 if (strchr(pszParmName, ':') == NULL)
2784 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2785 /* We do return 'fail' for parametric options as well because they are
2786 stored in different storage
2793 return the parameter structure for a parameter
2795 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2799 if (lp_ctx->s3_fns) {
2800 return lp_ctx->s3_fns->get_parm_struct(name);
2803 parmnum = map_parameter(name);
2804 if (parmnum == -1) return NULL;
2805 return &parm_table[parmnum];
2809 return the parameter pointer for a parameter
2811 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2812 struct loadparm_service *service, struct parm_struct *parm)
2814 if (lp_ctx->s3_fns) {
2815 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2818 if (service == NULL) {
2819 if (parm->p_class == P_LOCAL)
2820 return ((char *)lp_ctx->sDefault)+parm->offset;
2821 else if (parm->p_class == P_GLOBAL)
2822 return ((char *)lp_ctx->globals)+parm->offset;
2825 return ((char *)service) + parm->offset;
2830 return the parameter pointer for a parameter
2832 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2836 if (lp_ctx->s3_fns) {
2837 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2839 return parm->flags & FLAG_CMDLINE;
2844 parmnum = map_parameter(name);
2845 if (parmnum == -1) return false;
2847 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2851 * Find a service by name. Otherwise works like get_service.
2854 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2855 const char *pszServiceName)
2859 if (lp_ctx->s3_fns) {
2860 return lp_ctx->s3_fns->get_service(pszServiceName);
2863 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2864 if (lp_ctx->services[iService] != NULL &&
2865 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2866 return lp_ctx->services[iService];
2873 * Copy a service structure to another.
2874 * If pcopymapDest is NULL then copy all fields
2877 static void copy_service(struct loadparm_service *pserviceDest,
2878 struct loadparm_service *pserviceSource,
2879 struct bitmap *pcopymapDest)
2882 bool bcopyall = (pcopymapDest == NULL);
2883 struct parmlist_entry *data, *pdata, *paramo;
2886 for (i = 0; parm_table[i].label; i++)
2887 if (parm_table[i].p_class == P_LOCAL &&
2888 (bcopyall || bitmap_query(pcopymapDest, i))) {
2890 ((char *)pserviceSource) + parm_table[i].offset;
2892 ((char *)pserviceDest) + parm_table[i].offset;
2894 switch (parm_table[i].type) {
2896 *(bool *)dest_ptr = *(bool *)src_ptr;
2903 *(int *)dest_ptr = *(int *)src_ptr;
2907 lpcfg_string_set(pserviceDest,
2913 lpcfg_string_set_upper(pserviceDest,
2918 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2919 *(const char ***)src_ptr);
2927 init_copymap(pserviceDest);
2928 if (pserviceSource->copymap)
2929 bitmap_copy(pserviceDest->copymap,
2930 pserviceSource->copymap);
2933 data = pserviceSource->param_opt;
2936 pdata = pserviceDest->param_opt;
2937 /* Traverse destination */
2939 /* If we already have same option, override it */
2940 if (strcmp(pdata->key, data->key) == 0) {
2941 talloc_free(pdata->value);
2942 pdata->value = talloc_strdup(pdata,
2947 pdata = pdata->next;
2950 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2953 paramo->key = talloc_strdup(paramo, data->key);
2954 paramo->value = talloc_strdup(paramo, data->value);
2955 DLIST_ADD(pserviceDest->param_opt, paramo);
2962 * Check a service for consistency. Return False if the service is in any way
2963 * incomplete or faulty, else True.
2965 static bool lpcfg_service_ok(struct loadparm_service *service)
2970 if (service->szService[0] == '\0') {
2971 DEBUG(0, ("The following message indicates an internal error:\n"));
2972 DEBUG(0, ("No service name in service entry.\n"));
2976 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2977 /* I can't see why you'd want a non-printable printer service... */
2978 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2979 if (!service->bPrint_ok) {
2980 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2981 service->szService));
2982 service->bPrint_ok = true;
2984 /* [printers] service must also be non-browsable. */
2985 if (service->bBrowseable)
2986 service->bBrowseable = false;
2989 /* If a service is flagged unavailable, log the fact at level 0. */
2990 if (!service->bAvailable)
2991 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2992 service->szService));
2998 /*******************************************************************
2999 Keep a linked list of all config files so we know when one has changed
3000 it's date and needs to be reloaded.
3001 ********************************************************************/
3003 static void add_to_file_list(struct loadparm_context *lp_ctx,
3004 const char *fname, const char *subfname)
3006 struct file_lists *f = lp_ctx->file_lists;
3009 if (f->name && !strcmp(f->name, fname))
3015 f = talloc(lp_ctx, struct file_lists);
3018 f->next = lp_ctx->file_lists;
3019 f->name = talloc_strdup(f, fname);
3024 f->subfname = talloc_strdup(f, subfname);
3029 lp_ctx->file_lists = f;
3030 f->modtime = file_modtime(subfname);
3032 time_t t = file_modtime(subfname);
3038 /*******************************************************************
3039 Check if a config file has changed date.
3040 ********************************************************************/
3041 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
3043 struct file_lists *f;
3044 DEBUG(6, ("lp_file_list_changed()\n"));
3046 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
3050 n2 = standard_sub_basic(lp_ctx, f->name);
3052 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
3053 f->name, n2, ctime(&f->modtime)));
3055 mod_time = file_modtime(n2);
3057 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
3058 DEBUGADD(6, ("file %s modified: %s\n", n2,
3060 f->modtime = mod_time;
3061 talloc_free(f->subfname);
3062 f->subfname = talloc_strdup(f, n2);
3069 /***************************************************************************
3070 Handle the "realm" parameter
3071 ***************************************************************************/
3073 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
3074 const char *pszParmValue, char **ptr)
3076 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3078 talloc_free(lp_ctx->globals->szRealm_upper);
3079 talloc_free(lp_ctx->globals->szRealm_lower);
3081 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
3082 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
3087 /***************************************************************************
3088 Handle the include operation.
3089 ***************************************************************************/
3091 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
3092 const char *pszParmValue, char **ptr)
3094 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
3096 add_to_file_list(lp_ctx, pszParmValue, fname);
3098 lpcfg_string_set(lp_ctx, ptr, fname);
3100 if (file_exist(fname))
3101 return pm_process(fname, do_section, do_parameter, lp_ctx);
3103 DEBUG(2, ("Can't find include file %s\n", fname));
3108 /***************************************************************************
3109 Handle the interpretation of the copy parameter.
3110 ***************************************************************************/
3112 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
3113 const char *pszParmValue, char **ptr)
3116 struct loadparm_service *serviceTemp;
3118 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3122 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
3124 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
3125 if (serviceTemp == lp_ctx->currentService) {
3126 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
3128 copy_service(lp_ctx->currentService,
3130 lp_ctx->currentService->copymap);
3134 DEBUG(0, ("Unable to copy service - source not found: %s\n",
3142 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
3143 const char *pszParmValue, char **ptr)
3146 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3147 if (lp_ctx->global) {
3148 return debug_parse_levels(pszParmValue);
3153 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
3154 const char *pszParmValue, char **ptr)
3156 debug_set_logfile(pszParmValue);
3157 if (lp_ctx->global) {
3158 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3163 /***************************************************************************
3164 Initialise a copymap.
3165 ***************************************************************************/
3167 static void init_copymap(struct loadparm_service *pservice)
3171 TALLOC_FREE(pservice->copymap);
3173 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
3174 if (!pservice->copymap)
3176 ("Couldn't allocate copymap!! (size %d)\n",
3177 (int)NUMPARAMETERS));
3179 for (i = 0; i < NUMPARAMETERS; i++)
3180 bitmap_set(pservice->copymap, i);
3184 * Process a parametric option
3186 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
3187 struct loadparm_service *service,
3188 const char *pszParmName,
3189 const char *pszParmValue, int flags)
3191 struct parmlist_entry *paramo, *data;
3193 TALLOC_CTX *mem_ctx;
3195 while (isspace((unsigned char)*pszParmName)) {
3199 name = strlower_talloc(lp_ctx, pszParmName);
3200 if (!name) return false;
3202 if (service == NULL) {
3203 data = lp_ctx->globals->param_opt;
3204 mem_ctx = lp_ctx->globals;
3206 data = service->param_opt;
3210 /* Traverse destination */
3211 for (paramo=data; paramo; paramo=paramo->next) {
3212 /* If we already have the option set, override it unless
3213 it was a command line option and the new one isn't */
3214 if (strcmp(paramo->key, name) == 0) {
3215 if ((paramo->priority & FLAG_CMDLINE) &&
3216 !(flags & FLAG_CMDLINE)) {
3221 talloc_free(paramo->value);
3222 paramo->value = talloc_strdup(paramo, pszParmValue);
3223 paramo->priority = flags;
3229 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
3232 paramo->key = talloc_strdup(paramo, name);
3233 paramo->value = talloc_strdup(paramo, pszParmValue);
3234 paramo->priority = flags;
3235 if (service == NULL) {
3236 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
3238 DLIST_ADD(service->param_opt, paramo);
3246 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
3247 const char *pszParmName, const char *pszParmValue,
3248 struct loadparm_context *lp_ctx, bool on_globals)
3251 /* if it is a special case then go ahead */
3252 if (parm_table[parmnum].special) {
3254 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
3259 goto mark_non_default;
3262 /* now switch on the type of variable it is */
3263 switch (parm_table[parmnum].type)
3267 if (!set_boolean(pszParmValue, &b)) {
3268 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
3271 *(bool *)parm_ptr = b;
3277 if (!set_boolean(pszParmValue, &b)) {
3278 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
3281 *(bool *)parm_ptr = !b;
3286 *(int *)parm_ptr = atoi(pszParmValue);
3290 *(char *)parm_ptr = *pszParmValue;
3294 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
3300 if (conv_str_size_error(pszParmValue, &val)) {
3301 if (val <= INT_MAX) {
3302 *(int *)parm_ptr = (int)val;
3307 DEBUG(0,("lp_do_parameter(%s): value is not "
3308 "a valid size specifier!\n", pszParmValue));
3313 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
3314 pszParmValue, NULL);
3318 char **new_list = str_list_make(mem_ctx,
3319 pszParmValue, NULL);
3320 for (i=0; new_list[i]; i++) {
3321 if (new_list[i][0] == '+' && new_list[i][1]) {
3322 if (!str_list_check(*(const char ***)parm_ptr,
3324 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
3327 } else if (new_list[i][0] == '-' && new_list[i][1]) {
3328 str_list_remove(*(const char ***)parm_ptr,
3332 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
3333 pszParmName, pszParmValue));
3336 *(const char ***)parm_ptr = (const char **) new_list;
3343 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
3347 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
3351 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
3354 parm_table[parmnum].enum_list[i].name)) {
3356 parm_table[parmnum].
3361 if (!parm_table[parmnum].enum_list[i].name) {
3362 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
3363 pszParmValue, pszParmName));
3373 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
3374 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
3375 /* we have to also unset FLAG_DEFAULT on aliases */
3376 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
3377 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
3379 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
3380 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
3387 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
3388 const char *pszParmName, const char *pszParmValue)
3390 int parmnum = map_parameter(pszParmName);
3394 if (strchr(pszParmName, ':')) {
3395 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
3397 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
3401 /* if the flag has been set on the command line, then don't allow override,
3402 but don't report an error */
3403 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
3407 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
3409 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
3410 pszParmName, pszParmValue, lp_ctx, true);
3413 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
3414 struct loadparm_service *service,
3415 const char *pszParmName, const char *pszParmValue)
3419 int parmnum = map_parameter(pszParmName);
3422 if (strchr(pszParmName, ':')) {
3423 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
3425 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
3429 /* if the flag has been set on the command line, then don't allow override,
3430 but don't report an error */
3431 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
3435 if (parm_table[parmnum].p_class == P_GLOBAL) {
3437 ("Global parameter %s found in service section!\n",
3441 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
3443 if (!service->copymap)
3444 init_copymap(service);
3446 /* this handles the aliases - set the copymap for other
3447 * entries with the same data pointer */
3448 for (i = 0; parm_table[i].label; i++)
3449 if (parm_table[i].offset == parm_table[parmnum].offset &&
3450 parm_table[i].p_class == parm_table[parmnum].p_class)
3451 bitmap_clear(service->copymap, i);
3453 return set_variable(service, parmnum, parm_ptr, pszParmName,
3454 pszParmValue, lp_ctx, false);
3458 * Process a parameter.
3461 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
3464 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3466 if (lp_ctx->bInGlobalSection)
3467 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
3470 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
3471 pszParmName, pszParmValue);
3475 variable argument do parameter
3477 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
3478 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
3479 const char *pszParmName, const char *fmt, ...)
3486 s = talloc_vasprintf(NULL, fmt, ap);
3488 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
3495 set a parameter from the commandline - this is called from command line parameter
3496 parsing code. It sets the parameter then marks the parameter as unable to be modified
3497 by smb.conf processing
3499 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
3500 const char *pszParmValue)
3505 if (lp_ctx->s3_fns) {
3506 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
3509 parmnum = map_parameter(pszParmName);
3511 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
3514 if (parmnum < 0 && strchr(pszParmName, ':')) {
3515 /* set a parametric option */
3516 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
3517 pszParmValue, FLAG_CMDLINE);
3521 DEBUG(0,("Unknown option '%s'\n", pszParmName));
3525 /* reset the CMDLINE flag in case this has been called before */
3526 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
3528 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
3532 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
3534 /* we have to also set FLAG_CMDLINE on aliases */
3535 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
3536 lp_ctx->flags[i] |= FLAG_CMDLINE;
3538 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
3539 lp_ctx->flags[i] |= FLAG_CMDLINE;
3546 set a option from the commandline in 'a=b' format. Use to support --option
3548 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
3553 s = talloc_strdup(NULL, option);
3566 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
3572 #define BOOLSTR(b) ((b) ? "Yes" : "No")
3575 * Print a parameter of the specified type.
3578 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
3580 /* For the seperation of lists values that we print below */
3581 const char *list_sep = ", ";
3586 for (i = 0; p->enum_list[i].name; i++) {
3587 if (*(int *)ptr == p->enum_list[i].value) {
3589 p->enum_list[i].name);
3596 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
3600 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
3605 fprintf(f, "%d", *(int *)ptr);
3609 fprintf(f, "%c", *(char *)ptr);
3613 int val = *(int *)ptr;
3617 fprintf(f, "0%o", val);
3626 if ((char ***)ptr && *(char ***)ptr) {
3627 char **list = *(char ***)ptr;
3628 for (; *list; list++) {
3629 /* surround strings with whitespace in double quotes */
3630 if (*(list+1) == NULL) {
3631 /* last item, no extra separator */
3634 if ( strchr_m( *list, ' ' ) ) {
3635 fprintf(f, "\"%s\"%s", *list, list_sep);
3637 fprintf(f, "%s%s", *list, list_sep);
3645 if (*(char **)ptr) {
3646 fprintf(f, "%s", *(char **)ptr);
3655 * Check if two parameters are equal.
3658 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
3663 return (*((bool *)ptr1) == *((bool *)ptr2));
3669 return (*((int *)ptr1) == *((int *)ptr2));
3672 return (*((char *)ptr1) == *((char *)ptr2));
3676 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
3681 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
3686 return (p1 == p2 || strequal(p1, p2));
3695 * Process a new section (service).
3697 * At this stage all sections are services.
3698 * Later we'll have special sections that permit server parameters to be set.
3699 * Returns True on success, False on failure.
3702 static bool do_section(const char *pszSectionName, void *userdata)
3704 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3706 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3707 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3710 /* if we've just struck a global section, note the fact. */
3711 lp_ctx->bInGlobalSection = isglobal;
3713 /* check for multiple global sections */
3714 if (lp_ctx->bInGlobalSection) {
3715 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3719 /* if we have a current service, tidy it up before moving on */
3722 if (lp_ctx->currentService != NULL)
3723 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3725 /* if all is still well, move to the next record in the services array */
3727 /* We put this here to avoid an odd message order if messages are */
3728 /* issued by the post-processing of a previous section. */
3729 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3731 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
3734 DEBUG(0, ("Failed to add a new service\n"));
3744 * Determine if a particular base parameter is currently set to the default value.
3747 static bool is_default(struct loadparm_service *sDefault, int i)
3749 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
3750 if (!defaults_saved)
3752 switch (parm_table[i].type) {
3755 return str_list_equal((const char **)parm_table[i].def.lvalue,
3756 (const char **)def_ptr);
3759 return strequal(parm_table[i].def.svalue,
3763 return parm_table[i].def.bvalue ==
3770 return parm_table[i].def.ivalue ==
3779 *Display the contents of the global structure.
3782 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3786 struct parmlist_entry *data;
3788 fprintf(f, "# Global parameters\n[global]\n");
3790 for (i = 0; parm_table[i].label; i++)
3791 if (parm_table[i].p_class == P_GLOBAL &&
3792 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3793 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3795 fprintf(f, "\t%s = ", parm_table[i].label);
3796 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3799 if (lp_ctx->globals->param_opt != NULL) {
3800 for (data = lp_ctx->globals->param_opt; data;
3801 data = data->next) {
3802 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3805 fprintf(f, "\t%s = %s\n", data->key, data->value);
3812 * Display the contents of a single services record.
3815 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3816 unsigned int *flags)
3819 struct parmlist_entry *data;
3821 if (pService != sDefault)
3822 fprintf(f, "\n[%s]\n", pService->szService);
3824 for (i = 0; parm_table[i].label; i++) {
3825 if (parm_table[i].p_class == P_LOCAL &&
3826 (*parm_table[i].label != '-') &&
3827 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3829 if (pService == sDefault) {
3830 if (flags && (flags[i] & FLAG_DEFAULT)) {
3833 if (defaults_saved) {
3834 if (is_default(sDefault, i)) {
3839 if (equal_parameter(parm_table[i].type,
3840 ((char *)pService) +
3841 parm_table[i].offset,
3842 ((char *)sDefault) +
3843 parm_table[i].offset))
3847 fprintf(f, "\t%s = ", parm_table[i].label);
3848 print_parameter(&parm_table[i],
3849 ((char *)pService) + parm_table[i].offset, f);
3853 if (pService->param_opt != NULL) {
3854 for (data = pService->param_opt; data; data = data->next) {
3855 fprintf(f, "\t%s = %s\n", data->key, data->value);
3860 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3861 struct loadparm_service *service,
3862 const char *parm_name, FILE * f)
3864 struct parm_struct *parm;
3867 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3872 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3874 print_parameter(parm, ptr, f);
3880 * Return info about the next parameter in a service.
3881 * snum==-1 gives the globals.
3882 * Return NULL when out of parameters.
3886 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3890 /* do the globals */
3891 for (; parm_table[*i].label; (*i)++) {
3892 if ((*parm_table[*i].label == '-'))
3896 && (parm_table[*i].offset ==
3897 parm_table[(*i) - 1].offset)
3898 && (parm_table[*i].p_class ==
3899 parm_table[(*i) - 1].p_class))
3902 return &parm_table[(*i)++];
3905 struct loadparm_service *pService = lp_ctx->services[snum];
3907 for (; parm_table[*i].label; (*i)++) {
3908 if (parm_table[*i].p_class == P_LOCAL &&
3909 (*parm_table[*i].label != '-') &&
3911 (parm_table[*i].offset !=
3912 parm_table[(*i) - 1].offset)))
3914 if (allparameters ||
3915 !equal_parameter(parm_table[*i].type,
3916 ((char *)pService) +
3917 parm_table[*i].offset,
3918 ((char *)lp_ctx->sDefault) +
3919 parm_table[*i].offset))
3921 return &parm_table[(*i)++];
3932 * Auto-load some home services.
3934 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3942 * Unload unused services.
3945 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3946 struct smbsrv_connection *smb,
3947 bool (*snumused) (struct smbsrv_connection *, int))
3950 for (i = 0; i < lp_ctx->iNumServices; i++) {
3951 if (lp_ctx->services[i] == NULL)
3954 if (!snumused || !snumused(smb, i)) {
3955 talloc_free(lp_ctx->services[i]);
3956 lp_ctx->services[i] = NULL;
3962 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3964 struct parmlist_entry *data;
3966 if (lp_ctx->refuse_free) {
3967 /* someone is trying to free the
3968 global_loadparm_context.
3969 We can't allow that. */
3973 if (lp_ctx->globals->param_opt != NULL) {
3974 struct parmlist_entry *next;
3975 for (data = lp_ctx->globals->param_opt; data; data=next) {
3977 if (data->priority & FLAG_CMDLINE) continue;
3978 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3987 * Initialise the global parameter structure.
3989 * Note that most callers should use loadparm_init_global() instead
3991 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3995 struct loadparm_context *lp_ctx;
3996 struct parmlist_entry *parm;
3999 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
4003 talloc_set_destructor(lp_ctx, lpcfg_destructor);
4004 lp_ctx->bInGlobalSection = true;
4005 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
4006 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
4008 lp_ctx->sDefault->iMaxPrintJobs = 1000;
4009 lp_ctx->sDefault->bAvailable = true;
4010 lp_ctx->sDefault->bBrowseable = true;
4011 lp_ctx->sDefault->bRead_only = true;
4012 lp_ctx->sDefault->bMap_archive = true;
4013 lp_ctx->sDefault->iStrictLocking = true;
4014 lp_ctx->sDefault->bOpLocks = true;
4015 lp_ctx->sDefault->iCreate_mask = 0744;
4016 lp_ctx->sDefault->iCreate_force_mode = 0000;
4017 lp_ctx->sDefault->iDir_mask = 0755;
4018 lp_ctx->sDefault->iDir_force_mode = 0000;
4020 DEBUG(3, ("Initialising global parameters\n"));
4022 for (i = 0; parm_table[i].label; i++) {
4023 if ((parm_table[i].type == P_STRING ||
4024 parm_table[i].type == P_USTRING) &&
4025 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
4027 if (parm_table[i].p_class == P_LOCAL) {
4028 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
4030 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
4032 *r = talloc_strdup(lp_ctx, "");
4036 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
4037 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
4038 talloc_free(logfile);
4040 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
4042 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
4044 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
4045 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
4046 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
4048 /* options that can be set on the command line must be initialised via
4049 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
4051 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
4053 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
4054 myname = get_myname(lp_ctx);
4055 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
4056 talloc_free(myname);
4057 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
4059 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
4061 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
4062 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
4064 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
4065 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
4066 /* the winbind method for domain controllers is for both RODC
4067 auth forwarding and for trusted domains */
4068 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
4069 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
4071 /* This hive should be dynamically generated by Samba using
4072 data from the sam, but for the moment leave it in a tdb to
4073 keep regedt32 from popping up an annoying dialog. */
4074 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
4076 /* using UTF8 by default allows us to support all chars */
4077 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
4079 /* Use codepage 850 as a default for the dos character set */
4080 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
4083 * Allow the default PASSWD_CHAT to be overridden in local.h.
4085 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
4087 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
4088 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
4089 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
4090 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
4091 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
4093 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
4094 lpcfg_do_global_parameter_var(lp_ctx, "server string",
4095 "Samba %s", SAMBA_VERSION_STRING);
4097 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
4099 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
4100 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
4101 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
4103 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
4104 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
4105 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
4106 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
4107 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
4108 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
4109 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
4110 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
4111 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
4112 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
4113 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
4114 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
4115 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
4117 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
4118 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
4119 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
4120 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
4121 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
4122 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
4123 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
4124 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
4126 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
4128 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
4129 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
4131 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
4132 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
4134 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
4135 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
4136 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
4137 #if _SAMBA_BUILD_ >= 4
4138 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
4139 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
4140 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
4141 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
4142 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
4143 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
4145 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
4146 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
4148 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
4149 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
4151 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
4153 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
4155 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
4156 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
4157 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
4158 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
4159 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
4160 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
4161 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
4163 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
4165 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
4166 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
4168 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
4169 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
4170 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
4171 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
4172 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
4174 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
4175 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
4177 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
4178 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
4179 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
4181 for (i = 0; parm_table[i].label; i++) {
4182 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
4183 lp_ctx->flags[i] |= FLAG_DEFAULT;
4187 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
4188 if (!(parm->priority & FLAG_CMDLINE)) {
4189 parm->priority |= FLAG_DEFAULT;
4197 * Initialise the global parameter structure.
4199 struct loadparm_context *loadparm_init_global(bool load_default)
4201 if (global_loadparm_context == NULL) {
4202 global_loadparm_context = loadparm_init(NULL);
4204 if (global_loadparm_context == NULL) {
4207 global_loadparm_context->global = true;
4208 if (load_default && !global_loadparm_context->loaded) {
4209 lpcfg_load_default(global_loadparm_context);
4211 global_loadparm_context->refuse_free = true;
4212 return global_loadparm_context;
4216 * Initialise the global parameter structure.
4218 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
4219 const struct loadparm_s3_helpers *s3_fns)
4221 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
4222 if (!loadparm_context) {
4225 loadparm_context->s3_fns = s3_fns;
4226 return loadparm_context;
4229 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
4231 return lp_ctx->szConfigFile;
4234 const char *lp_default_path(void)
4236 if (getenv("SMB_CONF_PATH"))
4237 return getenv("SMB_CONF_PATH");
4239 return dyn_CONFIGFILE;
4243 * Update the internal state of a loadparm context after settings
4246 static bool lpcfg_update(struct loadparm_context *lp_ctx)
4248 struct debug_settings settings;
4249 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
4251 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
4252 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
4255 if (!lp_ctx->global) {
4259 panic_action = lp_ctx->globals->panic_action;
4261 reload_charcnv(lp_ctx);
4263 ZERO_STRUCT(settings);
4264 /* Add any more debug-related smb.conf parameters created in
4266 settings.timestamp_logs = true;
4267 debug_set_settings(&settings);
4269 /* FIXME: This is a bit of a hack, but we can't use a global, since
4270 * not everything that uses lp also uses the socket library */
4271 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
4272 setenv("SOCKET_TESTNONBLOCK", "1", 1);
4274 unsetenv("SOCKET_TESTNONBLOCK");
4280 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
4284 path = lp_default_path();
4286 if (!file_exist(path)) {
4287 /* We allow the default smb.conf file to not exist,
4288 * basically the equivalent of an empty file. */
4289 return lpcfg_update(lp_ctx);
4292 return lpcfg_load(lp_ctx, path);
4296 * Load the services array from the services file.
4298 * Return True on success, False on failure.
4300 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
4305 filename = talloc_strdup(lp_ctx, filename);
4307 lp_ctx->szConfigFile = filename;
4309 if (lp_ctx->s3_fns) {
4310 return lp_ctx->s3_fns->load(filename);
4313 lp_ctx->bInGlobalSection = true;
4314 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
4315 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
4317 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
4319 /* We get sections first, so have to start 'behind' to make up */
4320 lp_ctx->currentService = NULL;
4321 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
4323 /* finish up the last section */
4324 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
4326 if (lp_ctx->currentService != NULL)
4327 bRetval = lpcfg_service_ok(lp_ctx->currentService);
4329 bRetval = bRetval && lpcfg_update(lp_ctx);
4331 /* we do this unconditionally, so that it happens even
4332 for a missing smb.conf */
4333 reload_charcnv(lp_ctx);
4335 if (bRetval == true) {
4336 /* set this up so that any child python tasks will
4337 find the right smb.conf */
4338 setenv("SMB_CONF_PATH", filename, 1);
4340 /* set the context used by the lp_*() function
4342 global_loadparm_context = lp_ctx;
4343 lp_ctx->loaded = true;
4350 * Return the max number of services.
4353 int lpcfg_numservices(struct loadparm_context *lp_ctx)
4355 if (lp_ctx->s3_fns) {
4356 return lp_ctx->s3_fns->get_numservices();
4359 return lp_ctx->iNumServices;
4363 * Display the contents of the services array in human-readable form.
4366 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
4371 if (lp_ctx->s3_fns) {
4372 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
4376 defaults_saved = !show_defaults;
4378 dump_globals(lp_ctx, f, show_defaults);
4380 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
4382 for (iService = 0; iService < maxtoprint; iService++)
4383 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
4387 * Display the contents of one service in human-readable form.
4389 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
4391 if (service != NULL) {
4392 if (service->szService[0] == '\0')
4394 dump_a_service(service, sDefault, f, NULL);
4398 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
4401 if (lp_ctx->s3_fns) {
4402 return lp_ctx->s3_fns->get_servicebynum(snum);
4405 return lp_ctx->services[snum];
4408 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
4409 const char *service_name)
4414 if (lp_ctx->s3_fns) {
4415 return lp_ctx->s3_fns->get_service(service_name);
4418 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
4419 if (lp_ctx->services[iService] &&
4420 lp_ctx->services[iService]->szService) {
4422 * The substitution here is used to support %U is
4425 serviceName = standard_sub_basic(
4426 lp_ctx->services[iService],
4427 lp_ctx->services[iService]->szService);
4428 if (strequal(serviceName, service_name)) {
4429 talloc_free(serviceName);
4430 return lp_ctx->services[iService];
4432 talloc_free(serviceName);
4436 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
4440 const char *lpcfg_servicename(const struct loadparm_service *service)
4442 return lp_string((const char *)service->szService);
4446 * A useful volume label function.
4448 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
4451 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
4452 service->volume : sDefault->volume));
4454 return lpcfg_servicename(service);
4459 * If we are PDC then prefer us as DMB
4461 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
4464 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
4465 service->szPrintername : sDefault->szPrintername));
4466 if (ret == NULL || (ret != NULL && *ret == '\0'))
4467 ret = lpcfg_servicename(service);
4474 * Return the max print jobs per queue.
4476 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
4478 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
4479 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
4480 maxjobs = PRINT_MAX_JOBID - 1;
4485 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
4487 if (lp_ctx == NULL) {
4488 return get_iconv_handle();
4490 return lp_ctx->iconv_handle;
4493 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
4495 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
4496 if (!lp_ctx->global) {
4500 if (old_ic == NULL) {
4501 old_ic = global_iconv_handle;
4503 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
4504 global_iconv_handle = lp_ctx->iconv_handle;
4507 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4509 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
4512 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4514 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
4517 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4519 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
4522 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4524 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
4527 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4529 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
4532 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4534 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
4535 if (settings == NULL)
4537 SMB_ASSERT(lp_ctx != NULL);
4538 settings->lp_ctx = talloc_reference(settings, lp_ctx);
4539 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
4543 int lpcfg_server_role(struct loadparm_context *lp_ctx)
4545 int domain_master = lpcfg__domain_master(lp_ctx);
4547 return lp_find_server_role(lpcfg__server_role(lp_ctx),
4548 lpcfg__security(lp_ctx),
4549 lpcfg__domain_logons(lp_ctx),
4550 (domain_master == true) ||
4551 (domain_master == Auto));
4554 int lpcfg_security(struct loadparm_context *lp_ctx)
4556 return lp_find_security(lpcfg__server_role(lp_ctx),
4557 lpcfg__security(lp_ctx));