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 *szLdapMachineSuffix; \
81 char *szLdapUserSuffix; \
82 char *szLdapIdmapSuffix; \
83 char *szLdapGroupSuffix; \
84 char *szUsershareTemplateShare; \
87 int winbindMaxDomainConnections; \
97 #include "lib/param/param_global.h"
99 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
101 /* we don't need a special handler for "dos charset" and "unix charset" */
102 #define handle_dos_charset NULL
103 #define handle_charset NULL
105 /* these are parameter handlers which are not needed in the
108 #define handle_netbios_aliases NULL
109 #define handle_debug_list NULL
110 #define handle_printing NULL
111 #define handle_ldap_debug_level NULL
112 #define handle_idmap_backend NULL
113 #define handle_idmap_uid NULL
114 #define handle_idmap_gid NULL
120 /* prototypes for the special type handlers */
121 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
122 const char *pszParmValue, char **ptr);
123 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
124 const char *pszParmValue, char **ptr);
125 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
126 const char *pszParmValue, char **ptr);
127 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
128 const char *pszParmValue, char **ptr);
129 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
130 const char *pszParmValue, char **ptr);
132 #include "lib/param/param_table.c"
134 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
135 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
137 static struct parm_struct parm_table[] = {
139 .label = "server role",
142 .offset = GLOBAL_VAR(server_role),
144 .enum_list = enum_server_role
147 .label = "domain logons",
150 .offset = GLOBAL_VAR(bDomainLogons),
152 .enum_list = enum_bool_auto
155 .label = "domain master",
158 .offset = GLOBAL_VAR(domain_master),
160 .enum_list = enum_bool_auto
163 .label = "dos charset",
166 .offset = GLOBAL_VAR(dos_charset),
171 .label = "unix charset",
174 .offset = GLOBAL_VAR(unix_charset),
182 .offset = LOCAL_VAR(comment),
185 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
191 .offset = LOCAL_VAR(szPath),
194 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
197 .label = "directory",
200 .offset = LOCAL_VAR(szPath),
206 .label = "workgroup",
209 .offset = GLOBAL_VAR(szWorkgroup),
212 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
218 .offset = GLOBAL_VAR(szRealm),
219 .special = handle_realm,
221 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
224 .label = "netbios name",
227 .offset = GLOBAL_VAR(szNetbiosName),
230 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
233 .label = "netbios aliases",
236 .offset = GLOBAL_VAR(szNetbiosAliases),
241 .label = "netbios scope",
244 .offset = GLOBAL_VAR(szNetbiosScope),
247 .flags = FLAG_ADVANCED,
250 .label = "server string",
253 .offset = GLOBAL_VAR(szServerString),
256 .flags = FLAG_BASIC | FLAG_ADVANCED,
259 .label = "interfaces",
262 .offset = GLOBAL_VAR(szInterfaces),
265 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
268 .label = "bind interfaces only",
271 .offset = GLOBAL_VAR(bBindInterfacesOnly),
274 .flags = FLAG_ADVANCED | FLAG_WIZARD,
277 .label = "passdb backend",
280 .offset = GLOBAL_VAR(passdb_backend),
289 .offset = GLOBAL_VAR(security),
291 .enum_list = enum_security
294 .label = "encrypt passwords",
297 .offset = GLOBAL_VAR(bEncryptPasswords),
302 .label = "null passwords",
305 .offset = GLOBAL_VAR(bNullPasswords),
308 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
311 .label = "obey pam restrictions",
314 .offset = GLOBAL_VAR(bObeyPamRestrictions),
317 .flags = FLAG_ADVANCED,
320 .label = "password server",
323 .offset = GLOBAL_VAR(szPasswordServer),
328 .label = "private dir",
331 .offset = GLOBAL_VAR(szPrivateDir),
336 .label = "passwd chat",
339 .offset = GLOBAL_VAR(szPasswdChat),
344 .label = "password level",
347 .offset = GLOBAL_VAR(pwordlevel),
352 .label = "lanman auth",
355 .offset = GLOBAL_VAR(bLanmanAuth),
358 .flags = FLAG_ADVANCED,
361 .label = "ntlm auth",
364 .offset = GLOBAL_VAR(bNTLMAuth),
367 .flags = FLAG_ADVANCED,
370 .label = "client NTLMv2 auth",
373 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
376 .flags = FLAG_ADVANCED,
379 .label = "client lanman auth",
382 .offset = GLOBAL_VAR(bClientLanManAuth),
385 .flags = FLAG_ADVANCED,
388 .label = "client plaintext auth",
391 .offset = GLOBAL_VAR(bClientPlaintextAuth),
394 .flags = FLAG_ADVANCED,
397 .label = "client use spnego principal",
400 .offset = GLOBAL_VAR(client_use_spnego_principal),
406 .label = "read only",
409 .offset = LOCAL_VAR(bRead_only),
415 .label = "create mask",
418 .offset = LOCAL_VAR(iCreate_mask),
423 .label = "force create mode",
426 .offset = LOCAL_VAR(iCreate_force_mode),
431 .label = "directory mask",
434 .offset = LOCAL_VAR(iDir_mask),
439 .label = "force directory mode",
442 .offset = LOCAL_VAR(iDir_force_mode),
448 .label = "hosts allow",
451 .offset = LOCAL_VAR(szHostsallow),
456 .label = "hosts deny",
459 .offset = LOCAL_VAR(szHostsdeny),
465 .label = "log level",
468 .offset = GLOBAL_VAR(loglevel),
469 .special = handle_debuglevel,
473 .label = "debuglevel",
476 .offset = GLOBAL_VAR(loglevel),
477 .special = handle_debuglevel,
484 .offset = GLOBAL_VAR(logfile),
485 .special = handle_logfile,
487 .flags = FLAG_ADVANCED,
491 .label = "smb ports",
494 .offset = GLOBAL_VAR(smb_ports),
502 .offset = GLOBAL_VAR(nbt_port),
507 .label = "dgram port",
510 .offset = GLOBAL_VAR(dgram_port),
515 .label = "cldap port",
518 .offset = GLOBAL_VAR(cldap_port),
523 .label = "krb5 port",
526 .offset = GLOBAL_VAR(krb5_port),
531 .label = "kpasswd port",
534 .offset = GLOBAL_VAR(kpasswd_port),
542 .offset = GLOBAL_VAR(web_port),
547 .label = "large readwrite",
550 .offset = GLOBAL_VAR(bLargeReadwrite),
553 .flags = FLAG_ADVANCED,
556 .label = "server max protocol",
559 .offset = GLOBAL_VAR(srv_maxprotocol),
561 .enum_list = enum_protocol,
562 .flags = FLAG_ADVANCED,
565 .label = "max protocol",
568 .offset = GLOBAL_VAR(srv_maxprotocol),
570 .enum_list = enum_protocol,
571 .flags = FLAG_ADVANCED,
577 .offset = GLOBAL_VAR(srv_maxprotocol),
579 .enum_list = enum_protocol,
580 .flags = FLAG_ADVANCED,
583 .label = "server min protocol",
586 .offset = GLOBAL_VAR(srv_minprotocol),
588 .enum_list = enum_protocol,
589 .flags = FLAG_ADVANCED,
592 .label = "min protocol",
595 .offset = GLOBAL_VAR(srv_minprotocol),
597 .enum_list = enum_protocol,
598 .flags = FLAG_ADVANCED,
601 .label = "client max protocol",
604 .offset = GLOBAL_VAR(cli_maxprotocol),
606 .enum_list = enum_protocol
609 .label = "client min protocol",
612 .offset = GLOBAL_VAR(cli_minprotocol),
614 .enum_list = enum_protocol
620 .offset = GLOBAL_VAR(bUnicode),
628 .offset = GLOBAL_VAR(bReadRaw),
633 .label = "write raw",
636 .offset = GLOBAL_VAR(bWriteRaw),
641 .label = "disable netbios",
644 .offset = GLOBAL_VAR(bDisableNetbios),
650 .label = "nt status support",
653 .offset = GLOBAL_VAR(bNTStatusSupport),
662 .offset = GLOBAL_VAR(max_mux),
665 .flags = FLAG_ADVANCED,
671 .offset = GLOBAL_VAR(max_xmit),
674 .flags = FLAG_ADVANCED,
678 .label = "name resolve order",
681 .offset = GLOBAL_VAR(szNameResolveOrder),
686 .label = "max wins ttl",
689 .offset = GLOBAL_VAR(max_wins_ttl),
692 .flags = FLAG_ADVANCED,
695 .label = "min wins ttl",
698 .offset = GLOBAL_VAR(min_wins_ttl),
701 .flags = FLAG_ADVANCED,
704 .label = "time server",
707 .offset = GLOBAL_VAR(bTimeServer),
710 .flags = FLAG_ADVANCED,
713 .label = "unix extensions",
716 .offset = GLOBAL_VAR(bUnixExtensions),
719 .flags = FLAG_ADVANCED,
722 .label = "use spnego",
725 .offset = GLOBAL_VAR(bUseSpnego),
730 .label = "server signing",
733 .offset = GLOBAL_VAR(server_signing),
735 .enum_list = enum_smb_signing_vals,
736 .flags = FLAG_ADVANCED,
739 .label = "client signing",
742 .offset = GLOBAL_VAR(client_signing),
744 .enum_list = enum_smb_signing_vals
747 .label = "rpc big endian",
750 .offset = GLOBAL_VAR(bRpcBigEndian),
756 .label = "max connections",
759 .offset = LOCAL_VAR(iMaxConnections),
762 .flags = FLAG_ADVANCED | FLAG_SHARE,
765 .label = "paranoid server security",
768 .offset = GLOBAL_VAR(paranoid_server_security),
773 .label = "socket options",
776 .offset = GLOBAL_VAR(socket_options),
782 .label = "strict sync",
785 .offset = LOCAL_VAR(bStrictSync),
793 .offset = GLOBAL_VAR(bUseMmap),
796 .flags = FLAG_ADVANCED,
800 .label = "max print jobs",
803 .offset = LOCAL_VAR(iMaxPrintJobs),
808 .label = "printable",
811 .offset = LOCAL_VAR(bPrint_ok),
819 .offset = LOCAL_VAR(bPrint_ok),
825 .label = "printer name",
828 .offset = LOCAL_VAR(szPrintername),
831 .flags = FLAG_ADVANCED | FLAG_PRINT,
837 .offset = LOCAL_VAR(szPrintername),
844 .label = "map system",
847 .offset = LOCAL_VAR(bMap_system),
852 .label = "map hidden",
855 .offset = LOCAL_VAR(bMap_hidden),
860 .label = "map archive",
863 .offset = LOCAL_VAR(bMap_archive),
869 .label = "preferred master",
872 .offset = GLOBAL_VAR(bPreferredMaster),
874 .enum_list = enum_bool_auto,
875 .flags = FLAG_BASIC | FLAG_ADVANCED,
878 .label = "prefered master",
881 .offset = GLOBAL_VAR(bPreferredMaster),
883 .enum_list = enum_bool_auto,
887 .label = "local master",
890 .offset = GLOBAL_VAR(bLocalMaster),
895 .label = "browseable",
898 .offset = LOCAL_VAR(bBrowseable),
901 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
904 .label = "browsable",
907 .offset = LOCAL_VAR(bBrowseable),
912 {N_("WINS Options"), P_SEP, P_SEPARATOR},
915 .label = "dns proxy",
918 .offset = GLOBAL_VAR(bWINSdnsProxy),
921 .flags = FLAG_ADVANCED,
924 .label = "wins proxy",
927 .offset = GLOBAL_VAR(bWINSproxy),
930 .flags = FLAG_ADVANCED,
933 .label = "wins server",
936 .offset = GLOBAL_VAR(szWINSservers),
939 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
942 .label = "wins support",
945 .offset = GLOBAL_VAR(bWINSsupport),
948 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
951 .label = "wins hook",
954 .offset = GLOBAL_VAR(szWINSHook),
957 .flags = FLAG_ADVANCED,
960 {N_("Locking Options"), P_SEP, P_SEPARATOR},
963 .label = "blocking locks",
966 .offset = LOCAL_VAR(bBlockingLocks),
969 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
972 .label = "csc policy",
975 .offset = LOCAL_VAR(iCSCPolicy),
977 .enum_list = enum_csc_policy,
978 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
981 .label = "fake oplocks",
984 .offset = LOCAL_VAR(bFakeOplocks),
987 .flags = FLAG_ADVANCED | FLAG_SHARE,
990 .label = "kernel oplocks",
993 .offset = LOCAL_VAR(bKernelOplocks),
996 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1002 .offset = LOCAL_VAR(bLocking),
1005 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1008 .label = "lock spin time",
1010 .p_class = P_GLOBAL,
1011 .offset = GLOBAL_VAR(iLockSpinTime),
1014 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1020 .offset = LOCAL_VAR(bOpLocks),
1023 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1026 .label = "level2 oplocks",
1029 .offset = LOCAL_VAR(bLevel2OpLocks),
1032 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1035 .label = "oplock break wait time",
1037 .p_class = P_GLOBAL,
1038 .offset = GLOBAL_VAR(oplock_break_wait_time),
1041 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1044 .label = "oplock contention limit",
1047 .offset = LOCAL_VAR(iOplockContentionLimit),
1050 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1053 .label = "posix locking",
1056 .offset = LOCAL_VAR(bPosixLocking),
1059 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1062 .label = "strict locking",
1065 .offset = LOCAL_VAR(iStrictLocking),
1067 .enum_list = enum_bool_auto,
1068 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1071 {N_("Ldap Options"), P_SEP, P_SEPARATOR},
1074 .label = "ldap admin dn",
1076 .p_class = P_GLOBAL,
1077 .offset = GLOBAL_VAR(szLdapAdminDn),
1080 .flags = FLAG_ADVANCED,
1083 .label = "ldap delete dn",
1085 .p_class = P_GLOBAL,
1086 .offset = GLOBAL_VAR(ldap_delete_dn),
1089 .flags = FLAG_ADVANCED,
1092 .label = "ldap group suffix",
1094 .p_class = P_GLOBAL,
1095 .offset = GLOBAL_VAR(szLdapGroupSuffix),
1098 .flags = FLAG_ADVANCED,
1101 .label = "ldap idmap suffix",
1103 .p_class = P_GLOBAL,
1104 .offset = GLOBAL_VAR(szLdapIdmapSuffix),
1107 .flags = FLAG_ADVANCED,
1110 .label = "ldap machine suffix",
1112 .p_class = P_GLOBAL,
1113 .offset = GLOBAL_VAR(szLdapMachineSuffix),
1116 .flags = FLAG_ADVANCED,
1119 .label = "ldap passwd sync",
1121 .p_class = P_GLOBAL,
1122 .offset = GLOBAL_VAR(ldap_passwd_sync),
1124 .enum_list = enum_ldap_passwd_sync,
1125 .flags = FLAG_ADVANCED,
1128 .label = "ldap password sync",
1130 .p_class = P_GLOBAL,
1131 .offset = GLOBAL_VAR(ldap_passwd_sync),
1133 .enum_list = enum_ldap_passwd_sync,
1137 .label = "ldap replication sleep",
1139 .p_class = P_GLOBAL,
1140 .offset = GLOBAL_VAR(ldap_replication_sleep),
1143 .flags = FLAG_ADVANCED,
1146 .label = "ldap suffix",
1148 .p_class = P_GLOBAL,
1149 .offset = GLOBAL_VAR(szLdapSuffix),
1152 .flags = FLAG_ADVANCED,
1155 .label = "ldap ssl",
1157 .p_class = P_GLOBAL,
1158 .offset = GLOBAL_VAR(ldap_ssl),
1160 .enum_list = enum_ldap_ssl,
1161 .flags = FLAG_ADVANCED,
1164 .label = "ldap ssl ads",
1166 .p_class = P_GLOBAL,
1167 .offset = GLOBAL_VAR(ldap_ssl_ads),
1170 .flags = FLAG_ADVANCED,
1173 .label = "ldap deref",
1175 .p_class = P_GLOBAL,
1176 .offset = GLOBAL_VAR(ldap_deref),
1178 .enum_list = enum_ldap_deref,
1179 .flags = FLAG_ADVANCED,
1182 .label = "ldap follow referral",
1184 .p_class = P_GLOBAL,
1185 .offset = GLOBAL_VAR(ldap_follow_referral),
1187 .enum_list = enum_bool_auto,
1188 .flags = FLAG_ADVANCED,
1191 .label = "ldap timeout",
1193 .p_class = P_GLOBAL,
1194 .offset = GLOBAL_VAR(ldap_timeout),
1197 .flags = FLAG_ADVANCED,
1200 .label = "ldap connection timeout",
1202 .p_class = P_GLOBAL,
1203 .offset = GLOBAL_VAR(ldap_connection_timeout),
1206 .flags = FLAG_ADVANCED,
1209 .label = "ldap page size",
1211 .p_class = P_GLOBAL,
1212 .offset = GLOBAL_VAR(ldap_page_size),
1215 .flags = FLAG_ADVANCED,
1218 .label = "ldap user suffix",
1220 .p_class = P_GLOBAL,
1221 .offset = GLOBAL_VAR(szLdapUserSuffix),
1224 .flags = FLAG_ADVANCED,
1227 .label = "ldap debug level",
1229 .p_class = P_GLOBAL,
1230 .offset = GLOBAL_VAR(ldap_debug_level),
1231 .special = handle_ldap_debug_level,
1233 .flags = FLAG_ADVANCED,
1236 .label = "ldap debug threshold",
1238 .p_class = P_GLOBAL,
1239 .offset = GLOBAL_VAR(ldap_debug_threshold),
1242 .flags = FLAG_ADVANCED,
1245 {N_("EventLog Options"), P_SEP, P_SEPARATOR},
1248 .label = "eventlog list",
1250 .p_class = P_GLOBAL,
1251 .offset = GLOBAL_VAR(szEventLogs),
1254 .flags = FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE,
1257 {N_("Miscellaneous Options"), P_SEP, P_SEPARATOR},
1260 .label = "add share command",
1262 .p_class = P_GLOBAL,
1263 .offset = GLOBAL_VAR(szAddShareCommand),
1266 .flags = FLAG_ADVANCED,
1269 .label = "change share command",
1271 .p_class = P_GLOBAL,
1272 .offset = GLOBAL_VAR(szChangeShareCommand),
1275 .flags = FLAG_ADVANCED,
1278 .label = "delete share command",
1280 .p_class = P_GLOBAL,
1281 .offset = GLOBAL_VAR(szDeleteShareCommand),
1284 .flags = FLAG_ADVANCED,
1287 .label = "config file",
1289 .p_class = P_GLOBAL,
1290 .offset = GLOBAL_VAR(szConfigFile),
1293 .flags = FLAG_HIDE|FLAG_META,
1298 .p_class = P_GLOBAL,
1299 .offset = GLOBAL_VAR(szAutoServices),
1302 .flags = FLAG_ADVANCED,
1305 .label = "auto services",
1307 .p_class = P_GLOBAL,
1308 .offset = GLOBAL_VAR(szAutoServices),
1311 .flags = FLAG_ADVANCED,
1314 .label = "lock directory",
1316 .p_class = P_GLOBAL,
1317 .offset = GLOBAL_VAR(szLockDir),
1320 .flags = FLAG_ADVANCED,
1323 .label = "lock dir",
1325 .p_class = P_GLOBAL,
1326 .offset = GLOBAL_VAR(szLockDir),
1332 .label = "state directory",
1334 .p_class = P_GLOBAL,
1335 .offset = GLOBAL_VAR(szStateDir),
1338 .flags = FLAG_ADVANCED,
1341 .label = "cache directory",
1343 .p_class = P_GLOBAL,
1344 .offset = GLOBAL_VAR(szCacheDir),
1347 .flags = FLAG_ADVANCED,
1350 .label = "pid directory",
1352 .p_class = P_GLOBAL,
1353 .offset = GLOBAL_VAR(szPidDir),
1356 .flags = FLAG_ADVANCED,
1359 .label = "ntp signd socket directory",
1361 .p_class = P_GLOBAL,
1362 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1365 .flags = FLAG_ADVANCED,
1370 .label = "utmp directory",
1372 .p_class = P_GLOBAL,
1373 .offset = GLOBAL_VAR(szUtmpDir),
1376 .flags = FLAG_ADVANCED,
1379 .label = "wtmp directory",
1381 .p_class = P_GLOBAL,
1382 .offset = GLOBAL_VAR(szWtmpDir),
1385 .flags = FLAG_ADVANCED,
1390 .p_class = P_GLOBAL,
1391 .offset = GLOBAL_VAR(bUtmp),
1394 .flags = FLAG_ADVANCED,
1398 .label = "default service",
1400 .p_class = P_GLOBAL,
1401 .offset = GLOBAL_VAR(szDefaultService),
1404 .flags = FLAG_ADVANCED,
1409 .p_class = P_GLOBAL,
1410 .offset = GLOBAL_VAR(szDefaultService),
1413 .flags = FLAG_ADVANCED,
1416 .label = "message command",
1418 .p_class = P_GLOBAL,
1419 .offset = GLOBAL_VAR(szMsgCommand),
1422 .flags = FLAG_ADVANCED,
1425 .label = "dfree cache time",
1428 .offset = LOCAL_VAR(iDfreeCacheTime),
1431 .flags = FLAG_ADVANCED,
1434 .label = "dfree command",
1437 .offset = LOCAL_VAR(szDfree),
1440 .flags = FLAG_ADVANCED,
1443 .label = "get quota command",
1445 .p_class = P_GLOBAL,
1446 .offset = GLOBAL_VAR(szGetQuota),
1449 .flags = FLAG_ADVANCED,
1452 .label = "set quota command",
1454 .p_class = P_GLOBAL,
1455 .offset = GLOBAL_VAR(szSetQuota),
1458 .flags = FLAG_ADVANCED,
1461 .label = "remote announce",
1463 .p_class = P_GLOBAL,
1464 .offset = GLOBAL_VAR(szRemoteAnnounce),
1467 .flags = FLAG_ADVANCED,
1470 .label = "remote browse sync",
1472 .p_class = P_GLOBAL,
1473 .offset = GLOBAL_VAR(szRemoteBrowseSync),
1476 .flags = FLAG_ADVANCED,
1479 .label = "socket address",
1481 .p_class = P_GLOBAL,
1482 .offset = GLOBAL_VAR(szSocketAddress),
1485 .flags = FLAG_ADVANCED,
1488 .label = "nmbd bind explicit broadcast",
1490 .p_class = P_GLOBAL,
1491 .offset = GLOBAL_VAR(bNmbdBindExplicitBroadcast),
1494 .flags = FLAG_ADVANCED,
1497 .label = "homedir map",
1499 .p_class = P_GLOBAL,
1500 .offset = GLOBAL_VAR(szNISHomeMapName),
1503 .flags = FLAG_ADVANCED,
1506 .label = "afs username map",
1508 .p_class = P_GLOBAL,
1509 .offset = GLOBAL_VAR(szAfsUsernameMap),
1512 .flags = FLAG_ADVANCED,
1515 .label = "afs token lifetime",
1517 .p_class = P_GLOBAL,
1518 .offset = GLOBAL_VAR(iAfsTokenLifetime),
1521 .flags = FLAG_ADVANCED,
1524 .label = "log nt token command",
1526 .p_class = P_GLOBAL,
1527 .offset = GLOBAL_VAR(szLogNtTokenCommand),
1530 .flags = FLAG_ADVANCED,
1533 .label = "NIS homedir",
1535 .p_class = P_GLOBAL,
1536 .offset = GLOBAL_VAR(bNISHomeMap),
1539 .flags = FLAG_ADVANCED,
1545 .offset = LOCAL_VAR(valid),
1554 .offset = LOCAL_VAR(szCopy),
1555 .special = handle_copy,
1563 .offset = LOCAL_VAR(szInclude),
1564 .special = handle_include,
1566 .flags = FLAG_HIDE|FLAG_META,
1572 .offset = LOCAL_VAR(szPreExec),
1575 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1581 .offset = LOCAL_VAR(szPreExec),
1584 .flags = FLAG_ADVANCED,
1587 .label = "preexec close",
1590 .offset = LOCAL_VAR(bPreexecClose),
1593 .flags = FLAG_ADVANCED | FLAG_SHARE,
1596 .label = "postexec",
1599 .offset = LOCAL_VAR(szPostExec),
1602 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1605 .label = "root preexec",
1608 .offset = LOCAL_VAR(szRootPreExec),
1611 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1614 .label = "root preexec close",
1617 .offset = LOCAL_VAR(bRootpreexecClose),
1620 .flags = FLAG_ADVANCED | FLAG_SHARE,
1623 .label = "root postexec",
1626 .offset = LOCAL_VAR(szRootPostExec),
1629 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1632 .label = "available",
1635 .offset = LOCAL_VAR(bAvailable),
1638 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
1641 .label = "registry shares",
1643 .p_class = P_GLOBAL,
1644 .offset = GLOBAL_VAR(bRegistryShares),
1647 .flags = FLAG_ADVANCED,
1650 .label = "usershare allow guests",
1652 .p_class = P_GLOBAL,
1653 .offset = GLOBAL_VAR(bUsershareAllowGuests),
1656 .flags = FLAG_ADVANCED,
1659 .label = "usershare max shares",
1661 .p_class = P_GLOBAL,
1662 .offset = GLOBAL_VAR(iUsershareMaxShares),
1665 .flags = FLAG_ADVANCED,
1668 .label = "usershare owner only",
1670 .p_class = P_GLOBAL,
1671 .offset = GLOBAL_VAR(bUsershareOwnerOnly),
1674 .flags = FLAG_ADVANCED,
1677 .label = "usershare path",
1679 .p_class = P_GLOBAL,
1680 .offset = GLOBAL_VAR(szUsersharePath),
1683 .flags = FLAG_ADVANCED,
1686 .label = "usershare prefix allow list",
1688 .p_class = P_GLOBAL,
1689 .offset = GLOBAL_VAR(szUsersharePrefixAllowList),
1692 .flags = FLAG_ADVANCED,
1695 .label = "usershare prefix deny list",
1697 .p_class = P_GLOBAL,
1698 .offset = GLOBAL_VAR(szUsersharePrefixDenyList),
1701 .flags = FLAG_ADVANCED,
1704 .label = "usershare template share",
1706 .p_class = P_GLOBAL,
1707 .offset = GLOBAL_VAR(szUsershareTemplateShare),
1710 .flags = FLAG_ADVANCED,
1716 .offset = LOCAL_VAR(volume),
1719 .flags = FLAG_ADVANCED | FLAG_SHARE,
1725 .offset = LOCAL_VAR(fstype),
1728 .flags = FLAG_ADVANCED | FLAG_SHARE,
1731 .label = "set directory",
1734 .offset = LOCAL_VAR(bNo_set_dir),
1737 .flags = FLAG_ADVANCED | FLAG_SHARE,
1740 .label = "allow insecure wide links",
1742 .p_class = P_GLOBAL,
1743 .offset = GLOBAL_VAR(bAllowInsecureWidelinks),
1746 .flags = FLAG_ADVANCED,
1749 .label = "wide links",
1752 .offset = LOCAL_VAR(bWidelinks),
1755 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1758 .label = "follow symlinks",
1761 .offset = LOCAL_VAR(bSymlinks),
1764 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1767 .label = "dont descend",
1770 .offset = LOCAL_VAR(szDontdescend),
1773 .flags = FLAG_ADVANCED | FLAG_SHARE,
1776 .label = "magic script",
1779 .offset = LOCAL_VAR(szMagicScript),
1782 .flags = FLAG_ADVANCED | FLAG_SHARE,
1785 .label = "magic output",
1788 .offset = LOCAL_VAR(szMagicOutput),
1791 .flags = FLAG_ADVANCED | FLAG_SHARE,
1794 .label = "delete readonly",
1797 .offset = LOCAL_VAR(bDeleteReadonly),
1800 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1803 .label = "dos filemode",
1806 .offset = LOCAL_VAR(bDosFilemode),
1809 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1812 .label = "dos filetimes",
1815 .offset = LOCAL_VAR(bDosFiletimes),
1818 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1821 .label = "dos filetime resolution",
1824 .offset = LOCAL_VAR(bDosFiletimeResolution),
1827 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1830 .label = "fake directory create times",
1833 .offset = LOCAL_VAR(bFakeDirCreateTimes),
1836 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1839 .label = "async smb echo handler",
1841 .p_class = P_GLOBAL,
1842 .offset = GLOBAL_VAR(bAsyncSMBEchoHandler),
1845 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1848 .label = "panic action",
1850 .p_class = P_GLOBAL,
1851 .offset = GLOBAL_VAR(szPanicAction),
1854 .flags = FLAG_ADVANCED,
1857 .label = "perfcount module",
1859 .p_class = P_GLOBAL,
1860 .offset = GLOBAL_VAR(szSMBPerfcountModule),
1863 .flags = FLAG_ADVANCED,
1866 {N_("VFS module options"), P_SEP, P_SEPARATOR},
1869 .label = "vfs objects",
1872 .offset = LOCAL_VAR(szVfsObjects),
1875 .flags = FLAG_ADVANCED | FLAG_SHARE,
1878 .label = "vfs object",
1881 .offset = LOCAL_VAR(szVfsObjects),
1888 {N_("MSDFS options"), P_SEP, P_SEPARATOR},
1891 .label = "msdfs root",
1894 .offset = LOCAL_VAR(bMSDfsRoot),
1897 .flags = FLAG_ADVANCED | FLAG_SHARE,
1900 .label = "msdfs proxy",
1903 .offset = LOCAL_VAR(szMSDfsProxy),
1906 .flags = FLAG_ADVANCED | FLAG_SHARE,
1909 .label = "host msdfs",
1911 .p_class = P_GLOBAL,
1912 .offset = GLOBAL_VAR(bHostMSDfs),
1915 .flags = FLAG_ADVANCED,
1918 {N_("Winbind options"), P_SEP, P_SEPARATOR},
1921 .label = "passdb expand explicit",
1923 .p_class = P_GLOBAL,
1924 .offset = GLOBAL_VAR(bPassdbExpandExplicit),
1927 .flags = FLAG_ADVANCED,
1930 .label = "idmap backend",
1932 .p_class = P_GLOBAL,
1933 .offset = GLOBAL_VAR(szIdmapBackend),
1934 .special = handle_idmap_backend,
1936 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1939 .label = "idmap cache time",
1941 .p_class = P_GLOBAL,
1942 .offset = GLOBAL_VAR(iIdmapCacheTime),
1945 .flags = FLAG_ADVANCED,
1948 .label = "idmap negative cache time",
1950 .p_class = P_GLOBAL,
1951 .offset = GLOBAL_VAR(iIdmapNegativeCacheTime),
1954 .flags = FLAG_ADVANCED,
1957 .label = "idmap uid",
1959 .p_class = P_GLOBAL,
1960 .offset = GLOBAL_VAR(szIdmapUID),
1961 .special = handle_idmap_uid,
1963 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1966 .label = "winbind uid",
1968 .p_class = P_GLOBAL,
1969 .offset = GLOBAL_VAR(szIdmapUID),
1970 .special = handle_idmap_uid,
1975 .label = "idmap gid",
1977 .p_class = P_GLOBAL,
1978 .offset = GLOBAL_VAR(szIdmapGID),
1979 .special = handle_idmap_gid,
1981 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1984 .label = "winbind gid",
1986 .p_class = P_GLOBAL,
1987 .offset = GLOBAL_VAR(szIdmapGID),
1988 .special = handle_idmap_gid,
1993 .label = "template homedir",
1995 .p_class = P_GLOBAL,
1996 .offset = GLOBAL_VAR(szTemplateHomedir),
1999 .flags = FLAG_ADVANCED,
2002 .label = "template shell",
2004 .p_class = P_GLOBAL,
2005 .offset = GLOBAL_VAR(szTemplateShell),
2008 .flags = FLAG_ADVANCED,
2011 .label = "winbind separator",
2013 .p_class = P_GLOBAL,
2014 .offset = GLOBAL_VAR(szWinbindSeparator),
2017 .flags = FLAG_ADVANCED,
2020 .label = "winbind cache time",
2022 .p_class = P_GLOBAL,
2023 .offset = GLOBAL_VAR(winbind_cache_time),
2026 .flags = FLAG_ADVANCED,
2029 .label = "winbind reconnect delay",
2031 .p_class = P_GLOBAL,
2032 .offset = GLOBAL_VAR(winbind_reconnect_delay),
2035 .flags = FLAG_ADVANCED,
2038 .label = "winbind max clients",
2040 .p_class = P_GLOBAL,
2041 .offset = GLOBAL_VAR(winbind_max_clients),
2044 .flags = FLAG_ADVANCED,
2047 .label = "winbind enum users",
2049 .p_class = P_GLOBAL,
2050 .offset = GLOBAL_VAR(bWinbindEnumUsers),
2053 .flags = FLAG_ADVANCED,
2056 .label = "winbind enum groups",
2058 .p_class = P_GLOBAL,
2059 .offset = GLOBAL_VAR(bWinbindEnumGroups),
2062 .flags = FLAG_ADVANCED,
2065 .label = "winbind use default domain",
2067 .p_class = P_GLOBAL,
2068 .offset = GLOBAL_VAR(bWinbindUseDefaultDomain),
2071 .flags = FLAG_ADVANCED,
2074 .label = "winbind trusted domains only",
2076 .p_class = P_GLOBAL,
2077 .offset = GLOBAL_VAR(bWinbindTrustedDomainsOnly),
2080 .flags = FLAG_ADVANCED,
2083 .label = "winbind nested groups",
2085 .p_class = P_GLOBAL,
2086 .offset = GLOBAL_VAR(bWinbindNestedGroups),
2089 .flags = FLAG_ADVANCED,
2092 .label = "winbind expand groups",
2094 .p_class = P_GLOBAL,
2095 .offset = GLOBAL_VAR(winbind_expand_groups),
2098 .flags = FLAG_ADVANCED,
2101 .label = "winbind nss info",
2103 .p_class = P_GLOBAL,
2104 .offset = GLOBAL_VAR(szWinbindNssInfo),
2107 .flags = FLAG_ADVANCED,
2110 .label = "winbind refresh tickets",
2112 .p_class = P_GLOBAL,
2113 .offset = GLOBAL_VAR(bWinbindRefreshTickets),
2116 .flags = FLAG_ADVANCED,
2119 .label = "winbind offline logon",
2121 .p_class = P_GLOBAL,
2122 .offset = GLOBAL_VAR(bWinbindOfflineLogon),
2125 .flags = FLAG_ADVANCED,
2128 .label = "winbind normalize names",
2130 .p_class = P_GLOBAL,
2131 .offset = GLOBAL_VAR(bWinbindNormalizeNames),
2134 .flags = FLAG_ADVANCED,
2137 .label = "winbind rpc only",
2139 .p_class = P_GLOBAL,
2140 .offset = GLOBAL_VAR(bWinbindRpcOnly),
2143 .flags = FLAG_ADVANCED,
2146 .label = "create krb5 conf",
2148 .p_class = P_GLOBAL,
2149 .offset = GLOBAL_VAR(bCreateKrb5Conf),
2152 .flags = FLAG_ADVANCED,
2155 .label = "ncalrpc dir",
2157 .p_class = P_GLOBAL,
2158 .offset = GLOBAL_VAR(ncalrpc_dir),
2161 .flags = FLAG_ADVANCED,
2164 .label = "winbind max domain connections",
2166 .p_class = P_GLOBAL,
2167 .offset = GLOBAL_VAR(winbindMaxDomainConnections),
2170 .flags = FLAG_ADVANCED,
2173 .label = "winbindd socket directory",
2175 .p_class = P_GLOBAL,
2176 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
2179 .flags = FLAG_ADVANCED,
2182 .label = "winbindd privileged socket directory",
2184 .p_class = P_GLOBAL,
2185 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
2188 .flags = FLAG_ADVANCED,
2191 .label = "winbind sealed pipes",
2193 .p_class = P_GLOBAL,
2194 .offset = GLOBAL_VAR(bWinbindSealedPipes),
2197 .flags = FLAG_ADVANCED,
2200 {N_("DNS options"), P_SEP, P_SEPARATOR},
2202 .label = "allow dns updates",
2204 .p_class = P_GLOBAL,
2205 .offset = GLOBAL_VAR(allow_dns_updates),
2207 .enum_list = enum_dns_update_settings,
2208 .flags = FLAG_ADVANCED,
2211 .label = "dns forwarder",
2213 .p_class = P_GLOBAL,
2214 .offset = GLOBAL_VAR(dns_forwarder),
2217 .flags = FLAG_ADVANCED,
2220 .label = "dns recursive queries",
2222 .p_class = P_GLOBAL,
2223 .offset = GLOBAL_VAR(dns_recursive_queries),
2228 .label = "dns update command",
2230 .p_class = P_GLOBAL,
2231 .offset = GLOBAL_VAR(szDNSUpdateCommand),
2234 .flags = FLAG_ADVANCED,
2237 .label = "nsupdate command",
2239 .p_class = P_GLOBAL,
2240 .offset = GLOBAL_VAR(szNSUpdateCommand),
2243 .flags = FLAG_ADVANCED,
2246 .label = "rndc command",
2248 .p_class = P_GLOBAL,
2249 .offset = GLOBAL_VAR(szRNDCCommand),
2252 .flags = FLAG_ADVANCED,
2255 .label = "multicast dns register",
2257 .p_class = P_GLOBAL,
2258 .offset = GLOBAL_VAR(bMulticastDnsRegister),
2261 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
2264 {N_("AD DC options"), P_SEP, P_SEPARATOR},
2267 .label = "samba kcc command",
2269 .p_class = P_GLOBAL,
2270 .offset = GLOBAL_VAR(szSambaKCCCommand),
2273 .flags = FLAG_ADVANCED,
2276 .label = "server services",
2278 .p_class = P_GLOBAL,
2279 .offset = GLOBAL_VAR(server_services),
2284 .label = "dcerpc endpoint servers",
2286 .p_class = P_GLOBAL,
2287 .offset = GLOBAL_VAR(dcerpc_ep_servers),
2292 .label = "spn update command",
2294 .p_class = P_GLOBAL,
2295 .offset = GLOBAL_VAR(szSPNUpdateCommand),
2298 .flags = FLAG_ADVANCED,
2301 .label = "share backend",
2303 .p_class = P_GLOBAL,
2304 .offset = GLOBAL_VAR(szShareBackend),
2309 .label = "ntvfs handler",
2312 .offset = LOCAL_VAR(ntvfs_handler),
2317 {N_("TLS options"), P_SEP, P_SEPARATOR},
2320 .label = "tls enabled",
2322 .p_class = P_GLOBAL,
2323 .offset = GLOBAL_VAR(tls_enabled),
2328 .label = "tls keyfile",
2330 .p_class = P_GLOBAL,
2331 .offset = GLOBAL_VAR(tls_keyfile),
2336 .label = "tls certfile",
2338 .p_class = P_GLOBAL,
2339 .offset = GLOBAL_VAR(tls_certfile),
2344 .label = "tls cafile",
2346 .p_class = P_GLOBAL,
2347 .offset = GLOBAL_VAR(tls_cafile),
2352 .label = "tls crlfile",
2354 .p_class = P_GLOBAL,
2355 .offset = GLOBAL_VAR(tls_crlfile),
2360 .label = "tls dh params file",
2362 .p_class = P_GLOBAL,
2363 .offset = GLOBAL_VAR(tls_dhpfile),
2368 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
2372 /* local variables */
2373 struct loadparm_context {
2374 const char *szConfigFile;
2375 struct loadparm_global *globals;
2376 struct loadparm_service **services;
2377 struct loadparm_service *sDefault;
2378 struct smb_iconv_handle *iconv_handle;
2380 struct loadparm_service *currentService;
2381 bool bInGlobalSection;
2383 struct file_lists *next;
2388 unsigned int flags[NUMPARAMETERS];
2391 bool global; /* Is this the global context, which may set
2392 * global variables such as debug level etc? */
2393 const struct loadparm_s3_helpers *s3_fns;
2397 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
2399 if (lp_ctx->s3_fns) {
2400 return lp_ctx->s3_fns->get_default_loadparm_service();
2402 return lp_ctx->sDefault;
2406 * Convenience routine to grab string parameters into temporary memory
2407 * and run standard_sub_basic on them.
2409 * The buffers can be written to by
2410 * callers without affecting the source string.
2413 static const char *lp_string(const char *s)
2415 #if 0 /* until REWRITE done to make thread-safe */
2416 size_t len = s ? strlen(s) : 0;
2420 /* The follow debug is useful for tracking down memory problems
2421 especially if you have an inner loop that is calling a lp_*()
2422 function that returns a string. Perhaps this debug should be
2423 present all the time? */
2426 DEBUG(10, ("lp_string(%s)\n", s));
2429 #if 0 /* until REWRITE done to make thread-safe */
2431 lp_talloc = talloc_init("lp_talloc");
2433 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
2441 strlcpy(ret, s, len);
2443 if (trim_string(ret, "\"", "\"")) {
2444 if (strchr(ret,'"') != NULL)
2445 strlcpy(ret, s, len);
2448 standard_sub_basic(ret,len+100);
2455 In this section all the functions that are used to access the
2456 parameters from the rest of the program are defined
2460 * the creation of separate lpcfg_*() and lp_*() functions is to allow
2461 * for code compatibility between existing Samba4 and Samba3 code.
2464 /* this global context supports the lp_*() function varients */
2465 static struct loadparm_context *global_loadparm_context;
2467 #define lpcfg_default_service global_loadparm_context->sDefault
2468 #define lpcfg_global_service(i) global_loadparm_context->services[i]
2470 #define FN_GLOBAL_STRING(fn_name,var_name) \
2471 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
2472 if (lp_ctx == NULL) return NULL; \
2473 if (lp_ctx->s3_fns) { \
2474 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2475 return lp_ctx->s3_fns->fn_name(); \
2477 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
2480 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
2481 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
2482 if (lp_ctx == NULL) return NULL; \
2483 if (lp_ctx->s3_fns) { \
2484 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2485 return lp_ctx->s3_fns->fn_name(); \
2487 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
2490 #define FN_GLOBAL_LIST(fn_name,var_name) \
2491 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
2492 if (lp_ctx == NULL) return NULL; \
2493 if (lp_ctx->s3_fns) { \
2494 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2495 return lp_ctx->s3_fns->fn_name(); \
2497 return lp_ctx->globals->var_name; \
2500 #define FN_GLOBAL_BOOL(fn_name,var_name) \
2501 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
2502 if (lp_ctx == NULL) return false; \
2503 if (lp_ctx->s3_fns) { \
2504 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2505 return lp_ctx->s3_fns->fn_name(); \
2507 return lp_ctx->globals->var_name; \
2510 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
2511 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
2512 if (lp_ctx->s3_fns) { \
2513 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
2514 return lp_ctx->s3_fns->fn_name(); \
2516 return lp_ctx->globals->var_name; \
2519 /* Local parameters don't need the ->s3_fns because the struct
2520 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
2522 #define FN_LOCAL_STRING(fn_name,val) \
2523 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
2524 struct loadparm_service *sDefault) { \
2525 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
2528 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
2530 #define FN_LOCAL_LIST(fn_name,val) \
2531 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
2532 struct loadparm_service *sDefault) {\
2533 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
2536 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
2538 #define FN_LOCAL_BOOL(fn_name,val) \
2539 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
2540 struct loadparm_service *sDefault) { \
2541 return((service != NULL)? service->val : sDefault->val); \
2544 #define FN_LOCAL_INTEGER(fn_name,val) \
2545 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
2546 struct loadparm_service *sDefault) { \
2547 return((service != NULL)? service->val : sDefault->val); \
2550 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
2552 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
2554 #define FN_LOCAL_CHAR(fn_name,val) \
2555 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
2556 struct loadparm_service *sDefault) { \
2557 return((service != NULL)? service->val : sDefault->val); \
2560 #include "lib/param/param_functions.c"
2562 /* These functions remain only in lib/param for now */
2563 FN_GLOBAL_BOOL(readraw, bReadRaw)
2564 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
2565 FN_GLOBAL_STRING(cachedir, szCacheDir)
2566 FN_GLOBAL_STRING(socket_address, szSocketAddress)
2567 FN_GLOBAL_STRING(statedir, szStateDir)
2569 /* local prototypes */
2570 static int map_parameter(const char *pszParmName);
2571 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2572 const char *pszServiceName);
2573 static void copy_service(struct loadparm_service *pserviceDest,
2574 struct loadparm_service *pserviceSource,
2575 struct bitmap *pcopymapDest);
2576 static bool lpcfg_service_ok(struct loadparm_service *service);
2577 static bool do_section(const char *pszSectionName, void *);
2578 static void init_copymap(struct loadparm_service *pservice);
2580 /* This is a helper function for parametrical options support. */
2581 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
2582 /* Actual parametrical functions are quite simple */
2583 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
2584 struct loadparm_service *service,
2585 const char *type, const char *option)
2587 char *vfskey_tmp = NULL;
2588 char *vfskey = NULL;
2589 struct parmlist_entry *data;
2594 if (lp_ctx->s3_fns) {
2595 return lp_ctx->s3_fns->get_parametric(service, type, option);
2598 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
2600 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
2601 if (vfskey_tmp == NULL) return NULL;
2602 vfskey = strlower_talloc(NULL, vfskey_tmp);
2603 talloc_free(vfskey_tmp);
2606 if (strcmp(data->key, vfskey) == 0) {
2607 talloc_free(vfskey);
2613 if (service != NULL) {
2614 /* Try to fetch the same option but from globals */
2615 /* but only if we are not already working with globals */
2616 for (data = lp_ctx->globals->param_opt; data;
2617 data = data->next) {
2618 if (strcmp(data->key, vfskey) == 0) {
2619 talloc_free(vfskey);
2625 talloc_free(vfskey);
2632 * convenience routine to return int parameters.
2634 static int lp_int(const char *s)
2638 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
2642 return strtol(s, NULL, 0);
2646 * convenience routine to return unsigned long parameters.
2648 static unsigned long lp_ulong(const char *s)
2652 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
2656 return strtoul(s, NULL, 0);
2660 * convenience routine to return unsigned long parameters.
2662 static long lp_long(const char *s)
2666 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
2670 return strtol(s, NULL, 0);
2674 * convenience routine to return unsigned long parameters.
2676 static double lp_double(const char *s)
2680 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
2684 return strtod(s, NULL);
2688 * convenience routine to return boolean parameters.
2690 static bool lp_bool(const char *s)
2695 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
2699 if (!set_boolean(s, &ret)) {
2700 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
2709 * Return parametric option from a given service. Type is a part of option before ':'
2710 * Parametric option has following syntax: 'Type: option = value'
2711 * Returned value is allocated in 'lp_talloc' context
2714 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
2715 struct loadparm_service *service, const char *type,
2718 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2721 return lp_string(value);
2727 * Return parametric option from a given service. Type is a part of option before ':'
2728 * Parametric option has following syntax: 'Type: option = value'
2729 * Returned value is allocated in 'lp_talloc' context
2732 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
2733 struct loadparm_context *lp_ctx,
2734 struct loadparm_service *service,
2736 const char *option, const char *separator)
2738 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2741 return (const char **)str_list_make(mem_ctx, value, separator);
2747 * Return parametric option from a given service. Type is a part of option before ':'
2748 * Parametric option has following syntax: 'Type: option = value'
2751 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
2752 struct loadparm_service *service, const char *type,
2753 const char *option, int default_v)
2755 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2758 return lp_int(value);
2764 * Return parametric option from a given service. Type is a part of
2765 * option before ':'.
2766 * Parametric option has following syntax: 'Type: option = value'.
2769 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
2770 struct loadparm_service *service, const char *type,
2771 const char *option, int default_v)
2775 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2777 if (value && conv_str_size_error(value, &bval)) {
2778 if (bval <= INT_MAX) {
2787 * Return parametric option from a given service.
2788 * Type is a part of option before ':'
2789 * Parametric option has following syntax: 'Type: option = value'
2791 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
2792 struct loadparm_service *service, const char *type,
2793 const char *option, unsigned long default_v)
2795 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2798 return lp_ulong(value);
2803 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
2804 struct loadparm_service *service, const char *type,
2805 const char *option, long default_v)
2807 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2810 return lp_long(value);
2815 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
2816 struct loadparm_service *service, const char *type,
2817 const char *option, double default_v)
2819 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2822 return lp_double(value);
2828 * Return parametric option from a given service. Type is a part of option before ':'
2829 * Parametric option has following syntax: 'Type: option = value'
2832 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
2833 struct loadparm_service *service, const char *type,
2834 const char *option, bool default_v)
2836 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2839 return lp_bool(value);
2846 * Initialise a service to the defaults.
2849 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
2851 struct loadparm_service *pservice =
2852 talloc_zero(mem_ctx, struct loadparm_service);
2853 copy_service(pservice, sDefault, NULL);
2858 * Set a string value, deallocating any existing space, and allocing the space
2861 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
2868 *dest = talloc_strdup(mem_ctx, src);
2869 if ((*dest) == NULL) {
2870 DEBUG(0,("Out of memory in string_set\n"));
2878 * Set a string value, deallocating any existing space, and allocing the space
2881 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
2888 *dest = strupper_talloc(mem_ctx, src);
2889 if ((*dest) == NULL) {
2890 DEBUG(0,("Out of memory in string_set_upper\n"));
2900 * Add a new service to the services array initialising it with the given
2904 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
2905 const struct loadparm_service *pservice,
2909 struct loadparm_service tservice;
2910 int num_to_alloc = lp_ctx->iNumServices + 1;
2911 struct parmlist_entry *data, *pdata;
2913 if (pservice == NULL) {
2914 pservice = lp_ctx->sDefault;
2917 tservice = *pservice;
2919 /* it might already exist */
2921 struct loadparm_service *service = getservicebyname(lp_ctx,
2923 if (service != NULL) {
2924 /* Clean all parametric options for service */
2925 /* They will be added during parsing again */
2926 data = service->param_opt;
2932 service->param_opt = NULL;
2937 /* find an invalid one */
2938 for (i = 0; i < lp_ctx->iNumServices; i++)
2939 if (lp_ctx->services[i] == NULL)
2942 /* if not, then create one */
2943 if (i == lp_ctx->iNumServices) {
2944 struct loadparm_service **tsp;
2946 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
2949 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2952 lp_ctx->services = tsp;
2953 lp_ctx->services[lp_ctx->iNumServices] = NULL;
2956 lp_ctx->iNumServices++;
2959 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
2960 if (lp_ctx->services[i] == NULL) {
2961 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2964 copy_service(lp_ctx->services[i], &tservice, NULL);
2966 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
2967 return lp_ctx->services[i];
2971 * Add a new home service, with the specified home directory, defaults coming
2972 * from service ifrom.
2975 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
2976 const char *pszHomename,
2977 struct loadparm_service *default_service,
2978 const char *user, const char *pszHomedir)
2980 struct loadparm_service *service;
2982 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
2984 if (service == NULL)
2987 if (!(*(default_service->szPath))
2988 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
2989 service->szPath = talloc_strdup(service, pszHomedir);
2991 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
2994 if (!(*(service->comment))) {
2995 service->comment = talloc_asprintf(service, "Home directory of %s", user);
2997 service->bAvailable = default_service->bAvailable;
2998 service->bBrowseable = default_service->bBrowseable;
3000 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
3001 pszHomename, user, service->szPath));
3007 * Add a new printer service, with defaults coming from service iFrom.
3010 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
3011 const char *pszPrintername,
3012 struct loadparm_service *default_service)
3014 const char *comment = "From Printcap";
3015 struct loadparm_service *service;
3016 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
3018 if (service == NULL)
3021 /* note that we do NOT default the availability flag to True - */
3022 /* we take it from the default service passed. This allows all */
3023 /* dynamic printers to be disabled by disabling the [printers] */
3024 /* entry (if/when the 'available' keyword is implemented!). */
3026 /* the printer name is set to the service name. */
3027 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
3028 lpcfg_string_set(service, &service->comment, comment);
3029 service->bBrowseable = default_service->bBrowseable;
3030 /* Printers cannot be read_only. */
3031 service->bRead_only = false;
3032 /* Printer services must be printable. */
3033 service->bPrint_ok = true;
3035 DEBUG(3, ("adding printer service %s\n", pszPrintername));
3041 * Map a parameter's string representation to something we can use.
3042 * Returns False if the parameter string is not recognised, else TRUE.
3045 static int map_parameter(const char *pszParmName)
3049 if (*pszParmName == '-')
3052 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
3053 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
3056 /* Warn only if it isn't parametric option */
3057 if (strchr(pszParmName, ':') == NULL)
3058 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
3059 /* We do return 'fail' for parametric options as well because they are
3060 stored in different storage
3067 return the parameter structure for a parameter
3069 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
3073 if (lp_ctx->s3_fns) {
3074 return lp_ctx->s3_fns->get_parm_struct(name);
3077 parmnum = map_parameter(name);
3078 if (parmnum == -1) return NULL;
3079 return &parm_table[parmnum];
3083 return the parameter pointer for a parameter
3085 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
3086 struct loadparm_service *service, struct parm_struct *parm)
3088 if (lp_ctx->s3_fns) {
3089 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
3092 if (service == NULL) {
3093 if (parm->p_class == P_LOCAL)
3094 return ((char *)lp_ctx->sDefault)+parm->offset;
3095 else if (parm->p_class == P_GLOBAL)
3096 return ((char *)lp_ctx->globals)+parm->offset;
3099 return ((char *)service) + parm->offset;
3104 return the parameter pointer for a parameter
3106 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
3110 if (lp_ctx->s3_fns) {
3111 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
3113 return parm->flags & FLAG_CMDLINE;
3118 parmnum = map_parameter(name);
3119 if (parmnum == -1) return false;
3121 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
3125 * Find a service by name. Otherwise works like get_service.
3128 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
3129 const char *pszServiceName)
3133 if (lp_ctx->s3_fns) {
3134 return lp_ctx->s3_fns->get_service(pszServiceName);
3137 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
3138 if (lp_ctx->services[iService] != NULL &&
3139 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
3140 return lp_ctx->services[iService];
3147 * Copy a service structure to another.
3148 * If pcopymapDest is NULL then copy all fields
3151 static void copy_service(struct loadparm_service *pserviceDest,
3152 struct loadparm_service *pserviceSource,
3153 struct bitmap *pcopymapDest)
3156 bool bcopyall = (pcopymapDest == NULL);
3157 struct parmlist_entry *data, *pdata, *paramo;
3160 for (i = 0; parm_table[i].label; i++)
3161 if (parm_table[i].p_class == P_LOCAL &&
3162 (bcopyall || bitmap_query(pcopymapDest, i))) {
3164 ((char *)pserviceSource) + parm_table[i].offset;
3166 ((char *)pserviceDest) + parm_table[i].offset;
3168 switch (parm_table[i].type) {
3170 *(bool *)dest_ptr = *(bool *)src_ptr;
3177 *(int *)dest_ptr = *(int *)src_ptr;
3181 lpcfg_string_set(pserviceDest,
3187 lpcfg_string_set_upper(pserviceDest,
3192 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
3193 *(const char ***)src_ptr);
3201 init_copymap(pserviceDest);
3202 if (pserviceSource->copymap)
3203 bitmap_copy(pserviceDest->copymap,
3204 pserviceSource->copymap);
3207 data = pserviceSource->param_opt;
3210 pdata = pserviceDest->param_opt;
3211 /* Traverse destination */
3213 /* If we already have same option, override it */
3214 if (strcmp(pdata->key, data->key) == 0) {
3215 talloc_free(pdata->value);
3216 pdata->value = talloc_strdup(pdata,
3221 pdata = pdata->next;
3224 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
3227 paramo->key = talloc_strdup(paramo, data->key);
3228 paramo->value = talloc_strdup(paramo, data->value);
3229 DLIST_ADD(pserviceDest->param_opt, paramo);
3236 * Check a service for consistency. Return False if the service is in any way
3237 * incomplete or faulty, else True.
3239 static bool lpcfg_service_ok(struct loadparm_service *service)
3244 if (service->szService[0] == '\0') {
3245 DEBUG(0, ("The following message indicates an internal error:\n"));
3246 DEBUG(0, ("No service name in service entry.\n"));
3250 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
3251 /* I can't see why you'd want a non-printable printer service... */
3252 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
3253 if (!service->bPrint_ok) {
3254 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
3255 service->szService));
3256 service->bPrint_ok = true;
3258 /* [printers] service must also be non-browsable. */
3259 if (service->bBrowseable)
3260 service->bBrowseable = false;
3263 /* If a service is flagged unavailable, log the fact at level 0. */
3264 if (!service->bAvailable)
3265 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
3266 service->szService));
3272 /*******************************************************************
3273 Keep a linked list of all config files so we know when one has changed
3274 it's date and needs to be reloaded.
3275 ********************************************************************/
3277 static void add_to_file_list(struct loadparm_context *lp_ctx,
3278 const char *fname, const char *subfname)
3280 struct file_lists *f = lp_ctx->file_lists;
3283 if (f->name && !strcmp(f->name, fname))
3289 f = talloc(lp_ctx, struct file_lists);
3292 f->next = lp_ctx->file_lists;
3293 f->name = talloc_strdup(f, fname);
3298 f->subfname = talloc_strdup(f, subfname);
3303 lp_ctx->file_lists = f;
3304 f->modtime = file_modtime(subfname);
3306 time_t t = file_modtime(subfname);
3312 /*******************************************************************
3313 Check if a config file has changed date.
3314 ********************************************************************/
3315 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
3317 struct file_lists *f;
3318 DEBUG(6, ("lp_file_list_changed()\n"));
3320 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
3324 n2 = standard_sub_basic(lp_ctx, f->name);
3326 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
3327 f->name, n2, ctime(&f->modtime)));
3329 mod_time = file_modtime(n2);
3331 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
3332 DEBUGADD(6, ("file %s modified: %s\n", n2,
3334 f->modtime = mod_time;
3335 talloc_free(f->subfname);
3336 f->subfname = talloc_strdup(f, n2);
3343 /***************************************************************************
3344 Handle the "realm" parameter
3345 ***************************************************************************/
3347 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
3348 const char *pszParmValue, char **ptr)
3350 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3352 talloc_free(lp_ctx->globals->szRealm_upper);
3353 talloc_free(lp_ctx->globals->szRealm_lower);
3355 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
3356 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
3361 /***************************************************************************
3362 Handle the include operation.
3363 ***************************************************************************/
3365 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
3366 const char *pszParmValue, char **ptr)
3368 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
3370 add_to_file_list(lp_ctx, pszParmValue, fname);
3372 lpcfg_string_set(lp_ctx, ptr, fname);
3374 if (file_exist(fname))
3375 return pm_process(fname, do_section, do_parameter, lp_ctx);
3377 DEBUG(2, ("Can't find include file %s\n", fname));
3382 /***************************************************************************
3383 Handle the interpretation of the copy parameter.
3384 ***************************************************************************/
3386 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
3387 const char *pszParmValue, char **ptr)
3390 struct loadparm_service *serviceTemp;
3392 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3396 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
3398 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
3399 if (serviceTemp == lp_ctx->currentService) {
3400 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
3402 copy_service(lp_ctx->currentService,
3404 lp_ctx->currentService->copymap);
3408 DEBUG(0, ("Unable to copy service - source not found: %s\n",
3416 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
3417 const char *pszParmValue, char **ptr)
3420 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3421 if (lp_ctx->global) {
3422 return debug_parse_levels(pszParmValue);
3427 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
3428 const char *pszParmValue, char **ptr)
3430 debug_set_logfile(pszParmValue);
3431 if (lp_ctx->global) {
3432 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
3437 /***************************************************************************
3438 Initialise a copymap.
3439 ***************************************************************************/
3441 static void init_copymap(struct loadparm_service *pservice)
3445 TALLOC_FREE(pservice->copymap);
3447 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
3448 if (!pservice->copymap)
3450 ("Couldn't allocate copymap!! (size %d)\n",
3451 (int)NUMPARAMETERS));
3453 for (i = 0; i < NUMPARAMETERS; i++)
3454 bitmap_set(pservice->copymap, i);
3458 * Process a parametric option
3460 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
3461 struct loadparm_service *service,
3462 const char *pszParmName,
3463 const char *pszParmValue, int flags)
3465 struct parmlist_entry *paramo, *data;
3467 TALLOC_CTX *mem_ctx;
3469 while (isspace((unsigned char)*pszParmName)) {
3473 name = strlower_talloc(lp_ctx, pszParmName);
3474 if (!name) return false;
3476 if (service == NULL) {
3477 data = lp_ctx->globals->param_opt;
3478 mem_ctx = lp_ctx->globals;
3480 data = service->param_opt;
3484 /* Traverse destination */
3485 for (paramo=data; paramo; paramo=paramo->next) {
3486 /* If we already have the option set, override it unless
3487 it was a command line option and the new one isn't */
3488 if (strcmp(paramo->key, name) == 0) {
3489 if ((paramo->priority & FLAG_CMDLINE) &&
3490 !(flags & FLAG_CMDLINE)) {
3495 talloc_free(paramo->value);
3496 paramo->value = talloc_strdup(paramo, pszParmValue);
3497 paramo->priority = flags;
3503 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
3506 paramo->key = talloc_strdup(paramo, name);
3507 paramo->value = talloc_strdup(paramo, pszParmValue);
3508 paramo->priority = flags;
3509 if (service == NULL) {
3510 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
3512 DLIST_ADD(service->param_opt, paramo);
3520 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
3521 const char *pszParmName, const char *pszParmValue,
3522 struct loadparm_context *lp_ctx, bool on_globals)
3525 /* if it is a special case then go ahead */
3526 if (parm_table[parmnum].special) {
3528 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
3533 goto mark_non_default;
3536 /* now switch on the type of variable it is */
3537 switch (parm_table[parmnum].type)
3541 if (!set_boolean(pszParmValue, &b)) {
3542 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
3545 *(bool *)parm_ptr = b;
3551 if (!set_boolean(pszParmValue, &b)) {
3552 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
3555 *(bool *)parm_ptr = !b;
3560 *(int *)parm_ptr = atoi(pszParmValue);
3564 *(char *)parm_ptr = *pszParmValue;
3568 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
3574 if (conv_str_size_error(pszParmValue, &val)) {
3575 if (val <= INT_MAX) {
3576 *(int *)parm_ptr = (int)val;
3581 DEBUG(0,("lp_do_parameter(%s): value is not "
3582 "a valid size specifier!\n", pszParmValue));
3587 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
3588 pszParmValue, NULL);
3592 char **new_list = str_list_make(mem_ctx,
3593 pszParmValue, NULL);
3594 for (i=0; new_list[i]; i++) {
3595 if (new_list[i][0] == '+' && new_list[i][1]) {
3596 if (!str_list_check(*(const char ***)parm_ptr,
3598 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
3601 } else if (new_list[i][0] == '-' && new_list[i][1]) {
3602 str_list_remove(*(const char ***)parm_ptr,
3606 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
3607 pszParmName, pszParmValue));
3610 *(const char ***)parm_ptr = (const char **) new_list;
3617 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
3621 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
3625 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
3628 parm_table[parmnum].enum_list[i].name)) {
3630 parm_table[parmnum].
3635 if (!parm_table[parmnum].enum_list[i].name) {
3636 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
3637 pszParmValue, pszParmName));
3647 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
3648 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
3649 /* we have to also unset FLAG_DEFAULT on aliases */
3650 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
3651 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
3653 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
3654 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
3661 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
3662 const char *pszParmName, const char *pszParmValue)
3664 int parmnum = map_parameter(pszParmName);
3668 if (strchr(pszParmName, ':')) {
3669 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
3671 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
3675 /* if the flag has been set on the command line, then don't allow override,
3676 but don't report an error */
3677 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
3681 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
3683 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
3684 pszParmName, pszParmValue, lp_ctx, true);
3687 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
3688 struct loadparm_service *service,
3689 const char *pszParmName, const char *pszParmValue)
3693 int parmnum = map_parameter(pszParmName);
3696 if (strchr(pszParmName, ':')) {
3697 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
3699 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
3703 /* if the flag has been set on the command line, then don't allow override,
3704 but don't report an error */
3705 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
3709 if (parm_table[parmnum].p_class == P_GLOBAL) {
3711 ("Global parameter %s found in service section!\n",
3715 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
3717 if (!service->copymap)
3718 init_copymap(service);
3720 /* this handles the aliases - set the copymap for other
3721 * entries with the same data pointer */
3722 for (i = 0; parm_table[i].label; i++)
3723 if (parm_table[i].offset == parm_table[parmnum].offset &&
3724 parm_table[i].p_class == parm_table[parmnum].p_class)
3725 bitmap_clear(service->copymap, i);
3727 return set_variable(service, parmnum, parm_ptr, pszParmName,
3728 pszParmValue, lp_ctx, false);
3732 * Process a parameter.
3735 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
3738 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3740 if (lp_ctx->bInGlobalSection)
3741 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
3744 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
3745 pszParmName, pszParmValue);
3749 variable argument do parameter
3751 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
3752 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
3753 const char *pszParmName, const char *fmt, ...)
3760 s = talloc_vasprintf(NULL, fmt, ap);
3762 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
3769 set a parameter from the commandline - this is called from command line parameter
3770 parsing code. It sets the parameter then marks the parameter as unable to be modified
3771 by smb.conf processing
3773 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
3774 const char *pszParmValue)
3779 if (lp_ctx->s3_fns) {
3780 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
3783 parmnum = map_parameter(pszParmName);
3785 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
3788 if (parmnum < 0 && strchr(pszParmName, ':')) {
3789 /* set a parametric option */
3790 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
3791 pszParmValue, FLAG_CMDLINE);
3795 DEBUG(0,("Unknown option '%s'\n", pszParmName));
3799 /* reset the CMDLINE flag in case this has been called before */
3800 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
3802 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
3806 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
3808 /* we have to also set FLAG_CMDLINE on aliases */
3809 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
3810 lp_ctx->flags[i] |= FLAG_CMDLINE;
3812 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
3813 lp_ctx->flags[i] |= FLAG_CMDLINE;
3820 set a option from the commandline in 'a=b' format. Use to support --option
3822 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
3827 s = talloc_strdup(NULL, option);
3840 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
3846 #define BOOLSTR(b) ((b) ? "Yes" : "No")
3849 * Print a parameter of the specified type.
3852 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
3854 /* For the seperation of lists values that we print below */
3855 const char *list_sep = ", ";
3860 for (i = 0; p->enum_list[i].name; i++) {
3861 if (*(int *)ptr == p->enum_list[i].value) {
3863 p->enum_list[i].name);
3870 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
3874 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
3879 fprintf(f, "%d", *(int *)ptr);
3883 fprintf(f, "%c", *(char *)ptr);
3887 int val = *(int *)ptr;
3891 fprintf(f, "0%o", val);
3900 if ((char ***)ptr && *(char ***)ptr) {
3901 char **list = *(char ***)ptr;
3902 for (; *list; list++) {
3903 /* surround strings with whitespace in double quotes */
3904 if (*(list+1) == NULL) {
3905 /* last item, no extra separator */
3908 if ( strchr_m( *list, ' ' ) ) {
3909 fprintf(f, "\"%s\"%s", *list, list_sep);
3911 fprintf(f, "%s%s", *list, list_sep);
3919 if (*(char **)ptr) {
3920 fprintf(f, "%s", *(char **)ptr);
3929 * Check if two parameters are equal.
3932 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
3937 return (*((bool *)ptr1) == *((bool *)ptr2));
3943 return (*((int *)ptr1) == *((int *)ptr2));
3946 return (*((char *)ptr1) == *((char *)ptr2));
3950 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
3955 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
3960 return (p1 == p2 || strequal(p1, p2));
3969 * Process a new section (service).
3971 * At this stage all sections are services.
3972 * Later we'll have special sections that permit server parameters to be set.
3973 * Returns True on success, False on failure.
3976 static bool do_section(const char *pszSectionName, void *userdata)
3978 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3980 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3981 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3984 /* if we've just struck a global section, note the fact. */
3985 lp_ctx->bInGlobalSection = isglobal;
3987 /* check for multiple global sections */
3988 if (lp_ctx->bInGlobalSection) {
3989 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3993 /* if we have a current service, tidy it up before moving on */
3996 if (lp_ctx->currentService != NULL)
3997 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3999 /* if all is still well, move to the next record in the services array */
4001 /* We put this here to avoid an odd message order if messages are */
4002 /* issued by the post-processing of a previous section. */
4003 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
4005 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
4008 DEBUG(0, ("Failed to add a new service\n"));
4018 * Determine if a particular base parameter is currently set to the default value.
4021 static bool is_default(struct loadparm_service *sDefault, int i)
4023 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
4024 if (!defaults_saved)
4026 switch (parm_table[i].type) {
4029 return str_list_equal((const char **)parm_table[i].def.lvalue,
4030 (const char **)def_ptr);
4033 return strequal(parm_table[i].def.svalue,
4037 return parm_table[i].def.bvalue ==
4044 return parm_table[i].def.ivalue ==
4053 *Display the contents of the global structure.
4056 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
4060 struct parmlist_entry *data;
4062 fprintf(f, "# Global parameters\n[global]\n");
4064 for (i = 0; parm_table[i].label; i++)
4065 if (parm_table[i].p_class == P_GLOBAL &&
4066 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
4067 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
4069 fprintf(f, "\t%s = ", parm_table[i].label);
4070 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
4073 if (lp_ctx->globals->param_opt != NULL) {
4074 for (data = lp_ctx->globals->param_opt; data;
4075 data = data->next) {
4076 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
4079 fprintf(f, "\t%s = %s\n", data->key, data->value);
4086 * Display the contents of a single services record.
4089 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
4090 unsigned int *flags)
4093 struct parmlist_entry *data;
4095 if (pService != sDefault)
4096 fprintf(f, "\n[%s]\n", pService->szService);
4098 for (i = 0; parm_table[i].label; i++) {
4099 if (parm_table[i].p_class == P_LOCAL &&
4100 (*parm_table[i].label != '-') &&
4101 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
4103 if (pService == sDefault) {
4104 if (flags && (flags[i] & FLAG_DEFAULT)) {
4107 if (defaults_saved) {
4108 if (is_default(sDefault, i)) {
4113 if (equal_parameter(parm_table[i].type,
4114 ((char *)pService) +
4115 parm_table[i].offset,
4116 ((char *)sDefault) +
4117 parm_table[i].offset))
4121 fprintf(f, "\t%s = ", parm_table[i].label);
4122 print_parameter(&parm_table[i],
4123 ((char *)pService) + parm_table[i].offset, f);
4127 if (pService->param_opt != NULL) {
4128 for (data = pService->param_opt; data; data = data->next) {
4129 fprintf(f, "\t%s = %s\n", data->key, data->value);
4134 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
4135 struct loadparm_service *service,
4136 const char *parm_name, FILE * f)
4138 struct parm_struct *parm;
4141 parm = lpcfg_parm_struct(lp_ctx, parm_name);
4146 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
4148 print_parameter(parm, ptr, f);
4154 * Return info about the next parameter in a service.
4155 * snum==-1 gives the globals.
4156 * Return NULL when out of parameters.
4160 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
4164 /* do the globals */
4165 for (; parm_table[*i].label; (*i)++) {
4166 if ((*parm_table[*i].label == '-'))
4170 && (parm_table[*i].offset ==
4171 parm_table[(*i) - 1].offset)
4172 && (parm_table[*i].p_class ==
4173 parm_table[(*i) - 1].p_class))
4176 return &parm_table[(*i)++];
4179 struct loadparm_service *pService = lp_ctx->services[snum];
4181 for (; parm_table[*i].label; (*i)++) {
4182 if (parm_table[*i].p_class == P_LOCAL &&
4183 (*parm_table[*i].label != '-') &&
4185 (parm_table[*i].offset !=
4186 parm_table[(*i) - 1].offset)))
4188 if (allparameters ||
4189 !equal_parameter(parm_table[*i].type,
4190 ((char *)pService) +
4191 parm_table[*i].offset,
4192 ((char *)lp_ctx->sDefault) +
4193 parm_table[*i].offset))
4195 return &parm_table[(*i)++];
4206 * Auto-load some home services.
4208 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
4216 * Unload unused services.
4219 void lpcfg_killunused(struct loadparm_context *lp_ctx,
4220 struct smbsrv_connection *smb,
4221 bool (*snumused) (struct smbsrv_connection *, int))
4224 for (i = 0; i < lp_ctx->iNumServices; i++) {
4225 if (lp_ctx->services[i] == NULL)
4228 if (!snumused || !snumused(smb, i)) {
4229 talloc_free(lp_ctx->services[i]);
4230 lp_ctx->services[i] = NULL;
4236 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
4238 struct parmlist_entry *data;
4240 if (lp_ctx->refuse_free) {
4241 /* someone is trying to free the
4242 global_loadparm_context.
4243 We can't allow that. */
4247 if (lp_ctx->globals->param_opt != NULL) {
4248 struct parmlist_entry *next;
4249 for (data = lp_ctx->globals->param_opt; data; data=next) {
4251 if (data->priority & FLAG_CMDLINE) continue;
4252 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
4261 * Initialise the global parameter structure.
4263 * Note that most callers should use loadparm_init_global() instead
4265 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
4269 struct loadparm_context *lp_ctx;
4270 struct parmlist_entry *parm;
4273 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
4277 talloc_set_destructor(lp_ctx, lpcfg_destructor);
4278 lp_ctx->bInGlobalSection = true;
4279 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
4280 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
4282 lp_ctx->sDefault->iMaxPrintJobs = 1000;
4283 lp_ctx->sDefault->bAvailable = true;
4284 lp_ctx->sDefault->bBrowseable = true;
4285 lp_ctx->sDefault->bRead_only = true;
4286 lp_ctx->sDefault->bMap_archive = true;
4287 lp_ctx->sDefault->iStrictLocking = true;
4288 lp_ctx->sDefault->bOpLocks = true;
4289 lp_ctx->sDefault->iCreate_mask = 0744;
4290 lp_ctx->sDefault->iCreate_force_mode = 0000;
4291 lp_ctx->sDefault->iDir_mask = 0755;
4292 lp_ctx->sDefault->iDir_force_mode = 0000;
4294 DEBUG(3, ("Initialising global parameters\n"));
4296 for (i = 0; parm_table[i].label; i++) {
4297 if ((parm_table[i].type == P_STRING ||
4298 parm_table[i].type == P_USTRING) &&
4299 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
4301 if (parm_table[i].p_class == P_LOCAL) {
4302 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
4304 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
4306 *r = talloc_strdup(lp_ctx, "");
4310 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
4311 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
4312 talloc_free(logfile);
4314 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
4316 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
4318 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
4319 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
4320 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
4322 /* options that can be set on the command line must be initialised via
4323 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
4325 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
4327 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
4328 myname = get_myname(lp_ctx);
4329 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
4330 talloc_free(myname);
4331 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
4333 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
4335 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
4336 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
4338 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
4339 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
4340 /* the winbind method for domain controllers is for both RODC
4341 auth forwarding and for trusted domains */
4342 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
4343 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
4345 /* This hive should be dynamically generated by Samba using
4346 data from the sam, but for the moment leave it in a tdb to
4347 keep regedt32 from popping up an annoying dialog. */
4348 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
4350 /* using UTF8 by default allows us to support all chars */
4351 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
4353 /* Use codepage 850 as a default for the dos character set */
4354 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
4357 * Allow the default PASSWD_CHAT to be overridden in local.h.
4359 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
4361 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
4362 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
4363 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
4364 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
4365 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
4367 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
4368 lpcfg_do_global_parameter_var(lp_ctx, "server string",
4369 "Samba %s", SAMBA_VERSION_STRING);
4371 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
4373 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
4374 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
4375 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
4377 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
4378 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
4379 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
4380 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
4381 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
4382 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
4383 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
4384 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
4385 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
4386 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
4387 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
4388 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
4389 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
4391 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
4392 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
4393 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
4394 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
4395 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
4396 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
4397 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
4398 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
4400 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
4402 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
4403 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
4405 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
4406 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
4408 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
4409 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
4410 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
4411 #if _SAMBA_BUILD_ >= 4
4412 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
4413 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
4414 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
4415 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
4416 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
4417 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
4419 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
4420 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
4422 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
4423 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
4425 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
4427 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
4429 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
4430 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
4431 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
4432 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
4433 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
4434 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
4435 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
4437 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
4439 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
4440 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
4442 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
4443 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
4444 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
4445 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
4446 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
4448 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
4449 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
4451 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
4452 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
4453 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
4455 for (i = 0; parm_table[i].label; i++) {
4456 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
4457 lp_ctx->flags[i] |= FLAG_DEFAULT;
4461 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
4462 if (!(parm->priority & FLAG_CMDLINE)) {
4463 parm->priority |= FLAG_DEFAULT;
4471 * Initialise the global parameter structure.
4473 struct loadparm_context *loadparm_init_global(bool load_default)
4475 if (global_loadparm_context == NULL) {
4476 global_loadparm_context = loadparm_init(NULL);
4478 if (global_loadparm_context == NULL) {
4481 global_loadparm_context->global = true;
4482 if (load_default && !global_loadparm_context->loaded) {
4483 lpcfg_load_default(global_loadparm_context);
4485 global_loadparm_context->refuse_free = true;
4486 return global_loadparm_context;
4490 * Initialise the global parameter structure.
4492 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
4493 const struct loadparm_s3_helpers *s3_fns)
4495 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
4496 if (!loadparm_context) {
4499 loadparm_context->s3_fns = s3_fns;
4500 return loadparm_context;
4503 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
4505 return lp_ctx->szConfigFile;
4508 const char *lp_default_path(void)
4510 if (getenv("SMB_CONF_PATH"))
4511 return getenv("SMB_CONF_PATH");
4513 return dyn_CONFIGFILE;
4517 * Update the internal state of a loadparm context after settings
4520 static bool lpcfg_update(struct loadparm_context *lp_ctx)
4522 struct debug_settings settings;
4523 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
4525 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
4526 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
4529 if (!lp_ctx->global) {
4533 panic_action = lp_ctx->globals->panic_action;
4535 reload_charcnv(lp_ctx);
4537 ZERO_STRUCT(settings);
4538 /* Add any more debug-related smb.conf parameters created in
4540 settings.timestamp_logs = true;
4541 debug_set_settings(&settings);
4543 /* FIXME: This is a bit of a hack, but we can't use a global, since
4544 * not everything that uses lp also uses the socket library */
4545 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
4546 setenv("SOCKET_TESTNONBLOCK", "1", 1);
4548 unsetenv("SOCKET_TESTNONBLOCK");
4554 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
4558 path = lp_default_path();
4560 if (!file_exist(path)) {
4561 /* We allow the default smb.conf file to not exist,
4562 * basically the equivalent of an empty file. */
4563 return lpcfg_update(lp_ctx);
4566 return lpcfg_load(lp_ctx, path);
4570 * Load the services array from the services file.
4572 * Return True on success, False on failure.
4574 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
4579 filename = talloc_strdup(lp_ctx, filename);
4581 lp_ctx->szConfigFile = filename;
4583 if (lp_ctx->s3_fns) {
4584 return lp_ctx->s3_fns->load(filename);
4587 lp_ctx->bInGlobalSection = true;
4588 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
4589 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
4591 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
4593 /* We get sections first, so have to start 'behind' to make up */
4594 lp_ctx->currentService = NULL;
4595 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
4597 /* finish up the last section */
4598 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
4600 if (lp_ctx->currentService != NULL)
4601 bRetval = lpcfg_service_ok(lp_ctx->currentService);
4603 bRetval = bRetval && lpcfg_update(lp_ctx);
4605 /* we do this unconditionally, so that it happens even
4606 for a missing smb.conf */
4607 reload_charcnv(lp_ctx);
4609 if (bRetval == true) {
4610 /* set this up so that any child python tasks will
4611 find the right smb.conf */
4612 setenv("SMB_CONF_PATH", filename, 1);
4614 /* set the context used by the lp_*() function
4616 global_loadparm_context = lp_ctx;
4617 lp_ctx->loaded = true;
4624 * Return the max number of services.
4627 int lpcfg_numservices(struct loadparm_context *lp_ctx)
4629 if (lp_ctx->s3_fns) {
4630 return lp_ctx->s3_fns->get_numservices();
4633 return lp_ctx->iNumServices;
4637 * Display the contents of the services array in human-readable form.
4640 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
4645 if (lp_ctx->s3_fns) {
4646 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
4650 defaults_saved = !show_defaults;
4652 dump_globals(lp_ctx, f, show_defaults);
4654 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
4656 for (iService = 0; iService < maxtoprint; iService++)
4657 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
4661 * Display the contents of one service in human-readable form.
4663 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
4665 if (service != NULL) {
4666 if (service->szService[0] == '\0')
4668 dump_a_service(service, sDefault, f, NULL);
4672 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
4675 if (lp_ctx->s3_fns) {
4676 return lp_ctx->s3_fns->get_servicebynum(snum);
4679 return lp_ctx->services[snum];
4682 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
4683 const char *service_name)
4688 if (lp_ctx->s3_fns) {
4689 return lp_ctx->s3_fns->get_service(service_name);
4692 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
4693 if (lp_ctx->services[iService] &&
4694 lp_ctx->services[iService]->szService) {
4696 * The substitution here is used to support %U is
4699 serviceName = standard_sub_basic(
4700 lp_ctx->services[iService],
4701 lp_ctx->services[iService]->szService);
4702 if (strequal(serviceName, service_name)) {
4703 talloc_free(serviceName);
4704 return lp_ctx->services[iService];
4706 talloc_free(serviceName);
4710 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
4714 const char *lpcfg_servicename(const struct loadparm_service *service)
4716 return lp_string((const char *)service->szService);
4720 * A useful volume label function.
4722 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
4725 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
4726 service->volume : sDefault->volume));
4728 return lpcfg_servicename(service);
4733 * If we are PDC then prefer us as DMB
4735 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
4738 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
4739 service->szPrintername : sDefault->szPrintername));
4740 if (ret == NULL || (ret != NULL && *ret == '\0'))
4741 ret = lpcfg_servicename(service);
4748 * Return the max print jobs per queue.
4750 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
4752 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
4753 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
4754 maxjobs = PRINT_MAX_JOBID - 1;
4759 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
4761 if (lp_ctx == NULL) {
4762 return get_iconv_handle();
4764 return lp_ctx->iconv_handle;
4767 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
4769 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
4770 if (!lp_ctx->global) {
4774 if (old_ic == NULL) {
4775 old_ic = global_iconv_handle;
4777 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
4778 global_iconv_handle = lp_ctx->iconv_handle;
4781 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4783 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
4786 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4788 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
4791 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4793 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
4796 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4798 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
4801 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4803 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
4806 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4808 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
4809 if (settings == NULL)
4811 SMB_ASSERT(lp_ctx != NULL);
4812 settings->lp_ctx = talloc_reference(settings, lp_ctx);
4813 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
4817 int lpcfg_server_role(struct loadparm_context *lp_ctx)
4819 int domain_master = lpcfg__domain_master(lp_ctx);
4821 return lp_find_server_role(lpcfg__server_role(lp_ctx),
4822 lpcfg__security(lp_ctx),
4823 lpcfg__domain_logons(lp_ctx),
4824 (domain_master == true) ||
4825 (domain_master == Auto));
4828 int lpcfg_security(struct loadparm_context *lp_ctx)
4830 return lp_find_security(lpcfg__server_role(lp_ctx),
4831 lpcfg__security(lp_ctx));