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; \
81 int winbindMaxDomainConnections; \
91 #include "lib/param/param_global.h"
93 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
95 /* we don't need a special handler for "dos charset" and "unix charset" */
96 #define handle_dos_charset NULL
97 #define handle_charset NULL
99 /* these are parameter handlers which are not needed in the
102 #define handle_netbios_aliases NULL
103 #define handle_debug_list NULL
104 #define handle_printing NULL
105 #define handle_ldap_debug_level NULL
106 #define handle_idmap_backend NULL
107 #define handle_idmap_uid NULL
108 #define handle_idmap_gid NULL
114 /* prototypes for the special type handlers */
115 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
116 const char *pszParmValue
, char **ptr
);
117 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
118 const char *pszParmValue
, char **ptr
);
119 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
120 const char *pszParmValue
, char **ptr
);
121 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
122 const char *pszParmValue
, char **ptr
);
123 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
124 const char *pszParmValue
, char **ptr
);
126 #include "lib/param/param_table.c"
128 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
129 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
131 static struct parm_struct parm_table
[] = {
133 .label
= "server role",
136 .offset
= GLOBAL_VAR(server_role
),
138 .enum_list
= enum_server_role
141 .label
= "domain logons",
144 .offset
= GLOBAL_VAR(bDomainLogons
),
146 .enum_list
= enum_bool_auto
149 .label
= "domain master",
152 .offset
= GLOBAL_VAR(domain_master
),
154 .enum_list
= enum_bool_auto
157 .label
= "dos charset",
160 .offset
= GLOBAL_VAR(dos_charset
),
165 .label
= "unix charset",
168 .offset
= GLOBAL_VAR(unix_charset
),
176 .offset
= LOCAL_VAR(comment
),
179 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
185 .offset
= LOCAL_VAR(szPath
),
188 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
,
191 .label
= "directory",
194 .offset
= LOCAL_VAR(szPath
),
200 .label
= "workgroup",
203 .offset
= GLOBAL_VAR(szWorkgroup
),
206 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
212 .offset
= GLOBAL_VAR(szRealm
),
213 .special
= handle_realm
,
215 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
218 .label
= "netbios name",
221 .offset
= GLOBAL_VAR(szNetbiosName
),
224 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
227 .label
= "netbios aliases",
230 .offset
= GLOBAL_VAR(szNetbiosAliases
),
235 .label
= "netbios scope",
238 .offset
= GLOBAL_VAR(szNetbiosScope
),
241 .flags
= FLAG_ADVANCED
,
244 .label
= "server string",
247 .offset
= GLOBAL_VAR(szServerString
),
250 .flags
= FLAG_BASIC
| FLAG_ADVANCED
,
253 .label
= "interfaces",
256 .offset
= GLOBAL_VAR(szInterfaces
),
259 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
262 .label
= "bind interfaces only",
265 .offset
= GLOBAL_VAR(bBindInterfacesOnly
),
268 .flags
= FLAG_ADVANCED
| FLAG_WIZARD
,
271 .label
= "passdb backend",
274 .offset
= GLOBAL_VAR(passdb_backend
),
283 .offset
= GLOBAL_VAR(security
),
285 .enum_list
= enum_security
288 .label
= "encrypt passwords",
291 .offset
= GLOBAL_VAR(bEncryptPasswords
),
296 .label
= "null passwords",
299 .offset
= GLOBAL_VAR(bNullPasswords
),
302 .flags
= FLAG_ADVANCED
| FLAG_DEPRECATED
,
305 .label
= "obey pam restrictions",
308 .offset
= GLOBAL_VAR(bObeyPamRestrictions
),
311 .flags
= FLAG_ADVANCED
,
314 .label
= "password server",
317 .offset
= GLOBAL_VAR(szPasswordServer
),
322 .label
= "private dir",
325 .offset
= GLOBAL_VAR(szPrivateDir
),
330 .label
= "passwd chat",
333 .offset
= GLOBAL_VAR(szPasswdChat
),
338 .label
= "password level",
341 .offset
= GLOBAL_VAR(pwordlevel
),
346 .label
= "lanman auth",
349 .offset
= GLOBAL_VAR(bLanmanAuth
),
352 .flags
= FLAG_ADVANCED
,
355 .label
= "ntlm auth",
358 .offset
= GLOBAL_VAR(bNTLMAuth
),
361 .flags
= FLAG_ADVANCED
,
364 .label
= "client NTLMv2 auth",
367 .offset
= GLOBAL_VAR(bClientNTLMv2Auth
),
370 .flags
= FLAG_ADVANCED
,
373 .label
= "client lanman auth",
376 .offset
= GLOBAL_VAR(bClientLanManAuth
),
379 .flags
= FLAG_ADVANCED
,
382 .label
= "client plaintext auth",
385 .offset
= GLOBAL_VAR(bClientPlaintextAuth
),
388 .flags
= FLAG_ADVANCED
,
391 .label
= "client use spnego principal",
394 .offset
= GLOBAL_VAR(client_use_spnego_principal
),
400 .label
= "read only",
403 .offset
= LOCAL_VAR(bRead_only
),
409 .label
= "create mask",
412 .offset
= LOCAL_VAR(iCreate_mask
),
417 .label
= "force create mode",
420 .offset
= LOCAL_VAR(iCreate_force_mode
),
425 .label
= "directory mask",
428 .offset
= LOCAL_VAR(iDir_mask
),
433 .label
= "force directory mode",
436 .offset
= LOCAL_VAR(iDir_force_mode
),
442 .label
= "hosts allow",
445 .offset
= LOCAL_VAR(szHostsallow
),
450 .label
= "hosts deny",
453 .offset
= LOCAL_VAR(szHostsdeny
),
459 .label
= "log level",
462 .offset
= GLOBAL_VAR(loglevel
),
463 .special
= handle_debuglevel
,
467 .label
= "debuglevel",
470 .offset
= GLOBAL_VAR(loglevel
),
471 .special
= handle_debuglevel
,
478 .offset
= GLOBAL_VAR(logfile
),
479 .special
= handle_logfile
,
481 .flags
= FLAG_ADVANCED
,
485 .label
= "smb ports",
488 .offset
= GLOBAL_VAR(smb_ports
),
496 .offset
= GLOBAL_VAR(nbt_port
),
501 .label
= "dgram port",
504 .offset
= GLOBAL_VAR(dgram_port
),
509 .label
= "cldap port",
512 .offset
= GLOBAL_VAR(cldap_port
),
517 .label
= "krb5 port",
520 .offset
= GLOBAL_VAR(krb5_port
),
525 .label
= "kpasswd port",
528 .offset
= GLOBAL_VAR(kpasswd_port
),
536 .offset
= GLOBAL_VAR(web_port
),
541 .label
= "large readwrite",
544 .offset
= GLOBAL_VAR(bLargeReadwrite
),
547 .flags
= FLAG_ADVANCED
,
550 .label
= "server max protocol",
553 .offset
= GLOBAL_VAR(srv_maxprotocol
),
555 .enum_list
= enum_protocol
,
556 .flags
= FLAG_ADVANCED
,
559 .label
= "max protocol",
562 .offset
= GLOBAL_VAR(srv_maxprotocol
),
564 .enum_list
= enum_protocol
,
565 .flags
= FLAG_ADVANCED
,
571 .offset
= GLOBAL_VAR(srv_maxprotocol
),
573 .enum_list
= enum_protocol
,
574 .flags
= FLAG_ADVANCED
,
577 .label
= "server min protocol",
580 .offset
= GLOBAL_VAR(srv_minprotocol
),
582 .enum_list
= enum_protocol
,
583 .flags
= FLAG_ADVANCED
,
586 .label
= "min protocol",
589 .offset
= GLOBAL_VAR(srv_minprotocol
),
591 .enum_list
= enum_protocol
,
592 .flags
= FLAG_ADVANCED
,
595 .label
= "client max protocol",
598 .offset
= GLOBAL_VAR(cli_maxprotocol
),
600 .enum_list
= enum_protocol
603 .label
= "client min protocol",
606 .offset
= GLOBAL_VAR(cli_minprotocol
),
608 .enum_list
= enum_protocol
614 .offset
= GLOBAL_VAR(bUnicode
),
622 .offset
= GLOBAL_VAR(bReadRaw
),
627 .label
= "write raw",
630 .offset
= GLOBAL_VAR(bWriteRaw
),
635 .label
= "disable netbios",
638 .offset
= GLOBAL_VAR(bDisableNetbios
),
644 .label
= "nt status support",
647 .offset
= GLOBAL_VAR(bNTStatusSupport
),
656 .offset
= GLOBAL_VAR(max_mux
),
659 .flags
= FLAG_ADVANCED
,
665 .offset
= GLOBAL_VAR(max_xmit
),
668 .flags
= FLAG_ADVANCED
,
672 .label
= "name resolve order",
675 .offset
= GLOBAL_VAR(szNameResolveOrder
),
680 .label
= "max wins ttl",
683 .offset
= GLOBAL_VAR(max_wins_ttl
),
686 .flags
= FLAG_ADVANCED
,
689 .label
= "min wins ttl",
692 .offset
= GLOBAL_VAR(min_wins_ttl
),
695 .flags
= FLAG_ADVANCED
,
698 .label
= "time server",
701 .offset
= GLOBAL_VAR(bTimeServer
),
704 .flags
= FLAG_ADVANCED
,
707 .label
= "unix extensions",
710 .offset
= GLOBAL_VAR(bUnixExtensions
),
713 .flags
= FLAG_ADVANCED
,
716 .label
= "use spnego",
719 .offset
= GLOBAL_VAR(bUseSpnego
),
724 .label
= "server signing",
727 .offset
= GLOBAL_VAR(server_signing
),
729 .enum_list
= enum_smb_signing_vals
,
730 .flags
= FLAG_ADVANCED
,
733 .label
= "client signing",
736 .offset
= GLOBAL_VAR(client_signing
),
738 .enum_list
= enum_smb_signing_vals
741 .label
= "rpc big endian",
744 .offset
= GLOBAL_VAR(bRpcBigEndian
),
750 .label
= "max connections",
753 .offset
= LOCAL_VAR(iMaxConnections
),
756 .flags
= FLAG_ADVANCED
| FLAG_SHARE
,
759 .label
= "paranoid server security",
762 .offset
= GLOBAL_VAR(paranoid_server_security
),
767 .label
= "socket options",
770 .offset
= GLOBAL_VAR(socket_options
),
776 .label
= "strict sync",
779 .offset
= LOCAL_VAR(bStrictSync
),
787 .offset
= GLOBAL_VAR(bUseMmap
),
790 .flags
= FLAG_ADVANCED
,
794 .label
= "max print jobs",
797 .offset
= LOCAL_VAR(iMaxPrintJobs
),
802 .label
= "printable",
805 .offset
= LOCAL_VAR(bPrint_ok
),
813 .offset
= LOCAL_VAR(bPrint_ok
),
819 .label
= "printer name",
822 .offset
= LOCAL_VAR(szPrintername
),
825 .flags
= FLAG_ADVANCED
| FLAG_PRINT
,
831 .offset
= LOCAL_VAR(szPrintername
),
838 .label
= "map system",
841 .offset
= LOCAL_VAR(bMap_system
),
846 .label
= "map hidden",
849 .offset
= LOCAL_VAR(bMap_hidden
),
854 .label
= "map archive",
857 .offset
= LOCAL_VAR(bMap_archive
),
863 .label
= "preferred master",
866 .offset
= GLOBAL_VAR(bPreferredMaster
),
868 .enum_list
= enum_bool_auto
,
869 .flags
= FLAG_BASIC
| FLAG_ADVANCED
,
872 .label
= "prefered master",
875 .offset
= GLOBAL_VAR(bPreferredMaster
),
877 .enum_list
= enum_bool_auto
,
881 .label
= "local master",
884 .offset
= GLOBAL_VAR(bLocalMaster
),
889 .label
= "browseable",
892 .offset
= LOCAL_VAR(bBrowseable
),
895 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
,
898 .label
= "browsable",
901 .offset
= LOCAL_VAR(bBrowseable
),
907 .label
= "dns proxy",
910 .offset
= GLOBAL_VAR(bWINSdnsProxy
),
915 .label
= "wins server",
918 .offset
= GLOBAL_VAR(szWINSservers
),
921 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
924 .label
= "wins support",
927 .offset
= GLOBAL_VAR(bWINSsupport
),
930 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
933 .label
= "wins hook",
936 .offset
= GLOBAL_VAR(szWINSHook
),
939 .flags
= FLAG_ADVANCED
,
943 .label
= "csc policy",
946 .offset
= LOCAL_VAR(iCSCPolicy
),
948 .enum_list
= enum_csc_policy
,
949 .flags
= FLAG_ADVANCED
| FLAG_SHARE
| FLAG_GLOBAL
,
953 .label
= "strict locking",
956 .offset
= LOCAL_VAR(iStrictLocking
),
964 .offset
= LOCAL_VAR(bOpLocks
),
973 .offset
= GLOBAL_VAR(szAutoServices
),
976 .flags
= FLAG_ADVANCED
,
979 .label
= "auto services",
982 .offset
= GLOBAL_VAR(szAutoServices
),
985 .flags
= FLAG_ADVANCED
,
988 .label
= "lock directory",
991 .offset
= GLOBAL_VAR(szLockDir
),
994 .flags
= FLAG_ADVANCED
,
1000 .offset
= GLOBAL_VAR(szLockDir
),
1006 .label
= "state directory",
1008 .p_class
= P_GLOBAL
,
1009 .offset
= GLOBAL_VAR(szStateDir
),
1012 .flags
= FLAG_ADVANCED
,
1015 .label
= "cache directory",
1017 .p_class
= P_GLOBAL
,
1018 .offset
= GLOBAL_VAR(szCacheDir
),
1021 .flags
= FLAG_ADVANCED
,
1024 .label
= "pid directory",
1026 .p_class
= P_GLOBAL
,
1027 .offset
= GLOBAL_VAR(szPidDir
),
1033 .label
= "socket address",
1035 .p_class
= P_GLOBAL
,
1036 .offset
= GLOBAL_VAR(szSocketAddress
),
1044 .offset
= LOCAL_VAR(szCopy
),
1045 .special
= handle_copy
,
1053 .offset
= LOCAL_VAR(szInclude
),
1054 .special
= handle_include
,
1059 .label
= "available",
1062 .offset
= LOCAL_VAR(bAvailable
),
1070 .offset
= LOCAL_VAR(volume
),
1073 .flags
= FLAG_ADVANCED
| FLAG_SHARE
,
1079 .offset
= LOCAL_VAR(fstype
),
1085 .label
= "panic action",
1087 .p_class
= P_GLOBAL
,
1088 .offset
= GLOBAL_VAR(panic_action
),
1094 .label
= "msdfs root",
1097 .offset
= LOCAL_VAR(bMSDfsRoot
),
1102 .label
= "host msdfs",
1104 .p_class
= P_GLOBAL
,
1105 .offset
= GLOBAL_VAR(bHostMSDfs
),
1108 .flags
= FLAG_ADVANCED
,
1111 .label
= "ntp signd socket directory",
1113 .p_class
= P_GLOBAL
,
1114 .offset
= GLOBAL_VAR(szNTPSignDSocketDirectory
),
1117 .flags
= FLAG_ADVANCED
,
1120 {N_("Winbind options"), P_SEP
, P_SEPARATOR
},
1123 .label
= "passdb expand explicit",
1125 .p_class
= P_GLOBAL
,
1126 .offset
= GLOBAL_VAR(bPassdbExpandExplicit
),
1129 .flags
= FLAG_ADVANCED
,
1132 .label
= "idmap backend",
1134 .p_class
= P_GLOBAL
,
1135 .offset
= GLOBAL_VAR(szIdmapBackend
),
1136 .special
= handle_idmap_backend
,
1138 .flags
= FLAG_ADVANCED
| FLAG_DEPRECATED
,
1141 .label
= "idmap cache time",
1143 .p_class
= P_GLOBAL
,
1144 .offset
= GLOBAL_VAR(iIdmapCacheTime
),
1147 .flags
= FLAG_ADVANCED
,
1150 .label
= "idmap negative cache time",
1152 .p_class
= P_GLOBAL
,
1153 .offset
= GLOBAL_VAR(iIdmapNegativeCacheTime
),
1156 .flags
= FLAG_ADVANCED
,
1159 .label
= "idmap uid",
1161 .p_class
= P_GLOBAL
,
1162 .offset
= GLOBAL_VAR(szIdmapUID
),
1163 .special
= handle_idmap_uid
,
1165 .flags
= FLAG_ADVANCED
| FLAG_DEPRECATED
,
1168 .label
= "winbind uid",
1170 .p_class
= P_GLOBAL
,
1171 .offset
= GLOBAL_VAR(szIdmapUID
),
1172 .special
= handle_idmap_uid
,
1177 .label
= "idmap gid",
1179 .p_class
= P_GLOBAL
,
1180 .offset
= GLOBAL_VAR(szIdmapGID
),
1181 .special
= handle_idmap_gid
,
1183 .flags
= FLAG_ADVANCED
| FLAG_DEPRECATED
,
1186 .label
= "winbind gid",
1188 .p_class
= P_GLOBAL
,
1189 .offset
= GLOBAL_VAR(szIdmapGID
),
1190 .special
= handle_idmap_gid
,
1195 .label
= "template homedir",
1197 .p_class
= P_GLOBAL
,
1198 .offset
= GLOBAL_VAR(szTemplateHomedir
),
1201 .flags
= FLAG_ADVANCED
,
1204 .label
= "template shell",
1206 .p_class
= P_GLOBAL
,
1207 .offset
= GLOBAL_VAR(szTemplateShell
),
1210 .flags
= FLAG_ADVANCED
,
1213 .label
= "winbind separator",
1215 .p_class
= P_GLOBAL
,
1216 .offset
= GLOBAL_VAR(szWinbindSeparator
),
1219 .flags
= FLAG_ADVANCED
,
1222 .label
= "winbind cache time",
1224 .p_class
= P_GLOBAL
,
1225 .offset
= GLOBAL_VAR(winbind_cache_time
),
1228 .flags
= FLAG_ADVANCED
,
1231 .label
= "winbind reconnect delay",
1233 .p_class
= P_GLOBAL
,
1234 .offset
= GLOBAL_VAR(winbind_reconnect_delay
),
1237 .flags
= FLAG_ADVANCED
,
1240 .label
= "winbind max clients",
1242 .p_class
= P_GLOBAL
,
1243 .offset
= GLOBAL_VAR(winbind_max_clients
),
1246 .flags
= FLAG_ADVANCED
,
1249 .label
= "winbind enum users",
1251 .p_class
= P_GLOBAL
,
1252 .offset
= GLOBAL_VAR(bWinbindEnumUsers
),
1255 .flags
= FLAG_ADVANCED
,
1258 .label
= "winbind enum groups",
1260 .p_class
= P_GLOBAL
,
1261 .offset
= GLOBAL_VAR(bWinbindEnumGroups
),
1264 .flags
= FLAG_ADVANCED
,
1267 .label
= "winbind use default domain",
1269 .p_class
= P_GLOBAL
,
1270 .offset
= GLOBAL_VAR(bWinbindUseDefaultDomain
),
1273 .flags
= FLAG_ADVANCED
,
1276 .label
= "winbind trusted domains only",
1278 .p_class
= P_GLOBAL
,
1279 .offset
= GLOBAL_VAR(bWinbindTrustedDomainsOnly
),
1282 .flags
= FLAG_ADVANCED
,
1285 .label
= "winbind nested groups",
1287 .p_class
= P_GLOBAL
,
1288 .offset
= GLOBAL_VAR(bWinbindNestedGroups
),
1291 .flags
= FLAG_ADVANCED
,
1294 .label
= "winbind expand groups",
1296 .p_class
= P_GLOBAL
,
1297 .offset
= GLOBAL_VAR(winbind_expand_groups
),
1300 .flags
= FLAG_ADVANCED
,
1303 .label
= "winbind nss info",
1305 .p_class
= P_GLOBAL
,
1306 .offset
= GLOBAL_VAR(szWinbindNssInfo
),
1309 .flags
= FLAG_ADVANCED
,
1312 .label
= "winbind refresh tickets",
1314 .p_class
= P_GLOBAL
,
1315 .offset
= GLOBAL_VAR(bWinbindRefreshTickets
),
1318 .flags
= FLAG_ADVANCED
,
1321 .label
= "winbind offline logon",
1323 .p_class
= P_GLOBAL
,
1324 .offset
= GLOBAL_VAR(bWinbindOfflineLogon
),
1327 .flags
= FLAG_ADVANCED
,
1330 .label
= "winbind normalize names",
1332 .p_class
= P_GLOBAL
,
1333 .offset
= GLOBAL_VAR(bWinbindNormalizeNames
),
1336 .flags
= FLAG_ADVANCED
,
1339 .label
= "winbind rpc only",
1341 .p_class
= P_GLOBAL
,
1342 .offset
= GLOBAL_VAR(bWinbindRpcOnly
),
1345 .flags
= FLAG_ADVANCED
,
1348 .label
= "create krb5 conf",
1350 .p_class
= P_GLOBAL
,
1351 .offset
= GLOBAL_VAR(bCreateKrb5Conf
),
1354 .flags
= FLAG_ADVANCED
,
1357 .label
= "ncalrpc dir",
1359 .p_class
= P_GLOBAL
,
1360 .offset
= GLOBAL_VAR(ncalrpc_dir
),
1363 .flags
= FLAG_ADVANCED
,
1366 .label
= "winbind max domain connections",
1368 .p_class
= P_GLOBAL
,
1369 .offset
= GLOBAL_VAR(winbindMaxDomainConnections
),
1372 .flags
= FLAG_ADVANCED
,
1375 .label
= "winbindd socket directory",
1377 .p_class
= P_GLOBAL
,
1378 .offset
= GLOBAL_VAR(szWinbinddSocketDirectory
),
1381 .flags
= FLAG_ADVANCED
,
1384 .label
= "winbindd privileged socket directory",
1386 .p_class
= P_GLOBAL
,
1387 .offset
= GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
),
1390 .flags
= FLAG_ADVANCED
,
1393 .label
= "winbind sealed pipes",
1395 .p_class
= P_GLOBAL
,
1396 .offset
= GLOBAL_VAR(bWinbindSealedPipes
),
1399 .flags
= FLAG_ADVANCED
,
1402 {N_("DNS options"), P_SEP
, P_SEPARATOR
},
1404 .label
= "allow dns updates",
1406 .p_class
= P_GLOBAL
,
1407 .offset
= GLOBAL_VAR(allow_dns_updates
),
1409 .enum_list
= enum_dns_update_settings
,
1410 .flags
= FLAG_ADVANCED
,
1413 .label
= "dns forwarder",
1415 .p_class
= P_GLOBAL
,
1416 .offset
= GLOBAL_VAR(dns_forwarder
),
1419 .flags
= FLAG_ADVANCED
,
1422 .label
= "dns recursive queries",
1424 .p_class
= P_GLOBAL
,
1425 .offset
= GLOBAL_VAR(dns_recursive_queries
),
1430 .label
= "dns update command",
1432 .p_class
= P_GLOBAL
,
1433 .offset
= GLOBAL_VAR(szDNSUpdateCommand
),
1436 .flags
= FLAG_ADVANCED
,
1439 .label
= "nsupdate command",
1441 .p_class
= P_GLOBAL
,
1442 .offset
= GLOBAL_VAR(szNSUpdateCommand
),
1445 .flags
= FLAG_ADVANCED
,
1448 .label
= "rndc command",
1450 .p_class
= P_GLOBAL
,
1451 .offset
= GLOBAL_VAR(szRNDCCommand
),
1454 .flags
= FLAG_ADVANCED
,
1457 .label
= "multicast dns register",
1459 .p_class
= P_GLOBAL
,
1460 .offset
= GLOBAL_VAR(bMulticastDnsRegister
),
1463 .flags
= FLAG_ADVANCED
| FLAG_GLOBAL
,
1466 {N_("AD DC options"), P_SEP
, P_SEPARATOR
},
1469 .label
= "samba kcc command",
1471 .p_class
= P_GLOBAL
,
1472 .offset
= GLOBAL_VAR(szSambaKCCCommand
),
1475 .flags
= FLAG_ADVANCED
,
1478 .label
= "server services",
1480 .p_class
= P_GLOBAL
,
1481 .offset
= GLOBAL_VAR(server_services
),
1486 .label
= "dcerpc endpoint servers",
1488 .p_class
= P_GLOBAL
,
1489 .offset
= GLOBAL_VAR(dcerpc_ep_servers
),
1494 .label
= "spn update command",
1496 .p_class
= P_GLOBAL
,
1497 .offset
= GLOBAL_VAR(szSPNUpdateCommand
),
1500 .flags
= FLAG_ADVANCED
,
1503 .label
= "share backend",
1505 .p_class
= P_GLOBAL
,
1506 .offset
= GLOBAL_VAR(szShareBackend
),
1511 .label
= "ntvfs handler",
1514 .offset
= LOCAL_VAR(ntvfs_handler
),
1519 {N_("TLS options"), P_SEP
, P_SEPARATOR
},
1522 .label
= "tls enabled",
1524 .p_class
= P_GLOBAL
,
1525 .offset
= GLOBAL_VAR(tls_enabled
),
1530 .label
= "tls keyfile",
1532 .p_class
= P_GLOBAL
,
1533 .offset
= GLOBAL_VAR(tls_keyfile
),
1538 .label
= "tls certfile",
1540 .p_class
= P_GLOBAL
,
1541 .offset
= GLOBAL_VAR(tls_certfile
),
1546 .label
= "tls cafile",
1548 .p_class
= P_GLOBAL
,
1549 .offset
= GLOBAL_VAR(tls_cafile
),
1554 .label
= "tls crlfile",
1556 .p_class
= P_GLOBAL
,
1557 .offset
= GLOBAL_VAR(tls_crlfile
),
1562 .label
= "tls dh params file",
1564 .p_class
= P_GLOBAL
,
1565 .offset
= GLOBAL_VAR(tls_dhpfile
),
1570 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
, 0}
1574 /* local variables */
1575 struct loadparm_context
{
1576 const char *szConfigFile
;
1577 struct loadparm_global
*globals
;
1578 struct loadparm_service
**services
;
1579 struct loadparm_service
*sDefault
;
1580 struct smb_iconv_handle
*iconv_handle
;
1582 struct loadparm_service
*currentService
;
1583 bool bInGlobalSection
;
1585 struct file_lists
*next
;
1590 unsigned int flags
[NUMPARAMETERS
];
1593 bool global
; /* Is this the global context, which may set
1594 * global variables such as debug level etc? */
1595 const struct loadparm_s3_helpers
*s3_fns
;
1599 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
1601 if (lp_ctx
->s3_fns
) {
1602 return lp_ctx
->s3_fns
->get_default_loadparm_service();
1604 return lp_ctx
->sDefault
;
1608 * Convenience routine to grab string parameters into temporary memory
1609 * and run standard_sub_basic on them.
1611 * The buffers can be written to by
1612 * callers without affecting the source string.
1615 static const char *lp_string(const char *s
)
1617 #if 0 /* until REWRITE done to make thread-safe */
1618 size_t len
= s
? strlen(s
) : 0;
1622 /* The follow debug is useful for tracking down memory problems
1623 especially if you have an inner loop that is calling a lp_*()
1624 function that returns a string. Perhaps this debug should be
1625 present all the time? */
1628 DEBUG(10, ("lp_string(%s)\n", s
));
1631 #if 0 /* until REWRITE done to make thread-safe */
1633 lp_talloc
= talloc_init("lp_talloc");
1635 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
1643 strlcpy(ret
, s
, len
);
1645 if (trim_string(ret
, "\"", "\"")) {
1646 if (strchr(ret
,'"') != NULL
)
1647 strlcpy(ret
, s
, len
);
1650 standard_sub_basic(ret
,len
+100);
1657 In this section all the functions that are used to access the
1658 parameters from the rest of the program are defined
1662 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1663 * for code compatibility between existing Samba4 and Samba3 code.
1666 /* this global context supports the lp_*() function varients */
1667 static struct loadparm_context
*global_loadparm_context
;
1669 #define lpcfg_default_service global_loadparm_context->sDefault
1670 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1672 #define FN_GLOBAL_STRING(fn_name,var_name) \
1673 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1674 if (lp_ctx == NULL) return NULL; \
1675 if (lp_ctx->s3_fns) { \
1676 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1677 return lp_ctx->s3_fns->fn_name(); \
1679 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1682 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1683 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1684 if (lp_ctx == NULL) return NULL; \
1685 if (lp_ctx->s3_fns) { \
1686 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1687 return lp_ctx->s3_fns->fn_name(); \
1689 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1692 #define FN_GLOBAL_LIST(fn_name,var_name) \
1693 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1694 if (lp_ctx == NULL) return NULL; \
1695 if (lp_ctx->s3_fns) { \
1696 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1697 return lp_ctx->s3_fns->fn_name(); \
1699 return lp_ctx->globals->var_name; \
1702 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1703 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1704 if (lp_ctx == NULL) return false; \
1705 if (lp_ctx->s3_fns) { \
1706 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1707 return lp_ctx->s3_fns->fn_name(); \
1709 return lp_ctx->globals->var_name; \
1712 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1713 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1714 if (lp_ctx->s3_fns) { \
1715 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1716 return lp_ctx->s3_fns->fn_name(); \
1718 return lp_ctx->globals->var_name; \
1721 /* Local parameters don't need the ->s3_fns because the struct
1722 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1724 #define FN_LOCAL_STRING(fn_name,val) \
1725 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1726 struct loadparm_service *sDefault) { \
1727 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1730 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1732 #define FN_LOCAL_LIST(fn_name,val) \
1733 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1734 struct loadparm_service *sDefault) {\
1735 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1738 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1740 #define FN_LOCAL_BOOL(fn_name,val) \
1741 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1742 struct loadparm_service *sDefault) { \
1743 return((service != NULL)? service->val : sDefault->val); \
1746 #define FN_LOCAL_INTEGER(fn_name,val) \
1747 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1748 struct loadparm_service *sDefault) { \
1749 return((service != NULL)? service->val : sDefault->val); \
1752 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1754 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1756 #define FN_LOCAL_CHAR(fn_name,val) \
1757 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1758 struct loadparm_service *sDefault) { \
1759 return((service != NULL)? service->val : sDefault->val); \
1762 #include "lib/param/param_functions.c"
1764 /* These functions remain only in lib/param for now */
1765 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
1766 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
1767 FN_GLOBAL_STRING(cachedir
, szCacheDir
)
1768 FN_GLOBAL_STRING(socket_address
, szSocketAddress
)
1769 FN_GLOBAL_STRING(statedir
, szStateDir
)
1771 /* local prototypes */
1772 static int map_parameter(const char *pszParmName
);
1773 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1774 const char *pszServiceName
);
1775 static void copy_service(struct loadparm_service
*pserviceDest
,
1776 struct loadparm_service
*pserviceSource
,
1777 struct bitmap
*pcopymapDest
);
1778 static bool lpcfg_service_ok(struct loadparm_service
*service
);
1779 static bool do_section(const char *pszSectionName
, void *);
1780 static void init_copymap(struct loadparm_service
*pservice
);
1782 /* This is a helper function for parametrical options support. */
1783 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1784 /* Actual parametrical functions are quite simple */
1785 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
1786 struct loadparm_service
*service
,
1787 const char *type
, const char *option
)
1789 char *vfskey_tmp
= NULL
;
1790 char *vfskey
= NULL
;
1791 struct parmlist_entry
*data
;
1796 if (lp_ctx
->s3_fns
) {
1797 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
1800 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
1802 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
1803 if (vfskey_tmp
== NULL
) return NULL
;
1804 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
1805 talloc_free(vfskey_tmp
);
1808 if (strcmp(data
->key
, vfskey
) == 0) {
1809 talloc_free(vfskey
);
1815 if (service
!= NULL
) {
1816 /* Try to fetch the same option but from globals */
1817 /* but only if we are not already working with globals */
1818 for (data
= lp_ctx
->globals
->param_opt
; data
;
1819 data
= data
->next
) {
1820 if (strcmp(data
->key
, vfskey
) == 0) {
1821 talloc_free(vfskey
);
1827 talloc_free(vfskey
);
1834 * convenience routine to return int parameters.
1836 static int lp_int(const char *s
)
1840 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1844 return strtol(s
, NULL
, 0);
1848 * convenience routine to return unsigned long parameters.
1850 static unsigned long lp_ulong(const char *s
)
1854 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
1858 return strtoul(s
, NULL
, 0);
1862 * convenience routine to return unsigned long parameters.
1864 static long lp_long(const char *s
)
1868 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
1872 return strtol(s
, NULL
, 0);
1876 * convenience routine to return unsigned long parameters.
1878 static double lp_double(const char *s
)
1882 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
1886 return strtod(s
, NULL
);
1890 * convenience routine to return boolean parameters.
1892 static bool lp_bool(const char *s
)
1897 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
1901 if (!set_boolean(s
, &ret
)) {
1902 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
1911 * Return parametric option from a given service. Type is a part of option before ':'
1912 * Parametric option has following syntax: 'Type: option = value'
1913 * Returned value is allocated in 'lp_talloc' context
1916 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
1917 struct loadparm_service
*service
, const char *type
,
1920 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1923 return lp_string(value
);
1929 * Return parametric option from a given service. Type is a part of option before ':'
1930 * Parametric option has following syntax: 'Type: option = value'
1931 * Returned value is allocated in 'lp_talloc' context
1934 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
1935 struct loadparm_context
*lp_ctx
,
1936 struct loadparm_service
*service
,
1938 const char *option
, const char *separator
)
1940 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1943 return (const char **)str_list_make(mem_ctx
, value
, separator
);
1949 * Return parametric option from a given service. Type is a part of option before ':'
1950 * Parametric option has following syntax: 'Type: option = value'
1953 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
1954 struct loadparm_service
*service
, const char *type
,
1955 const char *option
, int default_v
)
1957 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1960 return lp_int(value
);
1966 * Return parametric option from a given service. Type is a part of
1967 * option before ':'.
1968 * Parametric option has following syntax: 'Type: option = value'.
1971 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
1972 struct loadparm_service
*service
, const char *type
,
1973 const char *option
, int default_v
)
1977 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1979 if (value
&& conv_str_size_error(value
, &bval
)) {
1980 if (bval
<= INT_MAX
) {
1989 * Return parametric option from a given service.
1990 * Type is a part of option before ':'
1991 * Parametric option has following syntax: 'Type: option = value'
1993 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
1994 struct loadparm_service
*service
, const char *type
,
1995 const char *option
, unsigned long default_v
)
1997 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
2000 return lp_ulong(value
);
2005 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
2006 struct loadparm_service
*service
, const char *type
,
2007 const char *option
, long default_v
)
2009 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
2012 return lp_long(value
);
2017 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
2018 struct loadparm_service
*service
, const char *type
,
2019 const char *option
, double default_v
)
2021 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
2024 return lp_double(value
);
2030 * Return parametric option from a given service. Type is a part of option before ':'
2031 * Parametric option has following syntax: 'Type: option = value'
2034 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
2035 struct loadparm_service
*service
, const char *type
,
2036 const char *option
, bool default_v
)
2038 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
2041 return lp_bool(value
);
2048 * Initialise a service to the defaults.
2051 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
2053 struct loadparm_service
*pservice
=
2054 talloc_zero(mem_ctx
, struct loadparm_service
);
2055 copy_service(pservice
, sDefault
, NULL
);
2060 * Set a string value, deallocating any existing space, and allocing the space
2063 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
2070 *dest
= talloc_strdup(mem_ctx
, src
);
2071 if ((*dest
) == NULL
) {
2072 DEBUG(0,("Out of memory in string_set\n"));
2080 * Set a string value, deallocating any existing space, and allocing the space
2083 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
2090 *dest
= strupper_talloc(mem_ctx
, src
);
2091 if ((*dest
) == NULL
) {
2092 DEBUG(0,("Out of memory in string_set_upper\n"));
2102 * Add a new service to the services array initialising it with the given
2106 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
2107 const struct loadparm_service
*pservice
,
2111 struct loadparm_service tservice
;
2112 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
2113 struct parmlist_entry
*data
, *pdata
;
2115 if (pservice
== NULL
) {
2116 pservice
= lp_ctx
->sDefault
;
2119 tservice
= *pservice
;
2121 /* it might already exist */
2123 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
2125 if (service
!= NULL
) {
2126 /* Clean all parametric options for service */
2127 /* They will be added during parsing again */
2128 data
= service
->param_opt
;
2134 service
->param_opt
= NULL
;
2139 /* find an invalid one */
2140 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
2141 if (lp_ctx
->services
[i
] == NULL
)
2144 /* if not, then create one */
2145 if (i
== lp_ctx
->iNumServices
) {
2146 struct loadparm_service
**tsp
;
2148 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
2151 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2154 lp_ctx
->services
= tsp
;
2155 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
2158 lp_ctx
->iNumServices
++;
2161 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
2162 if (lp_ctx
->services
[i
] == NULL
) {
2163 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2166 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
2168 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
2169 return lp_ctx
->services
[i
];
2173 * Add a new home service, with the specified home directory, defaults coming
2174 * from service ifrom.
2177 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
2178 const char *pszHomename
,
2179 struct loadparm_service
*default_service
,
2180 const char *user
, const char *pszHomedir
)
2182 struct loadparm_service
*service
;
2184 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
2186 if (service
== NULL
)
2189 if (!(*(default_service
->szPath
))
2190 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
2191 service
->szPath
= talloc_strdup(service
, pszHomedir
);
2193 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
2196 if (!(*(service
->comment
))) {
2197 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
2199 service
->bAvailable
= default_service
->bAvailable
;
2200 service
->bBrowseable
= default_service
->bBrowseable
;
2202 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2203 pszHomename
, user
, service
->szPath
));
2209 * Add a new printer service, with defaults coming from service iFrom.
2212 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
2213 const char *pszPrintername
,
2214 struct loadparm_service
*default_service
)
2216 const char *comment
= "From Printcap";
2217 struct loadparm_service
*service
;
2218 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
2220 if (service
== NULL
)
2223 /* note that we do NOT default the availability flag to True - */
2224 /* we take it from the default service passed. This allows all */
2225 /* dynamic printers to be disabled by disabling the [printers] */
2226 /* entry (if/when the 'available' keyword is implemented!). */
2228 /* the printer name is set to the service name. */
2229 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
2230 lpcfg_string_set(service
, &service
->comment
, comment
);
2231 service
->bBrowseable
= default_service
->bBrowseable
;
2232 /* Printers cannot be read_only. */
2233 service
->bRead_only
= false;
2234 /* Printer services must be printable. */
2235 service
->bPrint_ok
= true;
2237 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
2243 * Map a parameter's string representation to something we can use.
2244 * Returns False if the parameter string is not recognised, else TRUE.
2247 static int map_parameter(const char *pszParmName
)
2251 if (*pszParmName
== '-')
2254 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
2255 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
2258 /* Warn only if it isn't parametric option */
2259 if (strchr(pszParmName
, ':') == NULL
)
2260 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
2261 /* We do return 'fail' for parametric options as well because they are
2262 stored in different storage
2269 return the parameter structure for a parameter
2271 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
2275 if (lp_ctx
->s3_fns
) {
2276 return lp_ctx
->s3_fns
->get_parm_struct(name
);
2279 parmnum
= map_parameter(name
);
2280 if (parmnum
== -1) return NULL
;
2281 return &parm_table
[parmnum
];
2285 return the parameter pointer for a parameter
2287 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
2288 struct loadparm_service
*service
, struct parm_struct
*parm
)
2290 if (lp_ctx
->s3_fns
) {
2291 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
2294 if (service
== NULL
) {
2295 if (parm
->p_class
== P_LOCAL
)
2296 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
2297 else if (parm
->p_class
== P_GLOBAL
)
2298 return ((char *)lp_ctx
->globals
)+parm
->offset
;
2301 return ((char *)service
) + parm
->offset
;
2306 return the parameter pointer for a parameter
2308 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
2312 if (lp_ctx
->s3_fns
) {
2313 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
2315 return parm
->flags
& FLAG_CMDLINE
;
2320 parmnum
= map_parameter(name
);
2321 if (parmnum
== -1) return false;
2323 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
2327 * Find a service by name. Otherwise works like get_service.
2330 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
2331 const char *pszServiceName
)
2335 if (lp_ctx
->s3_fns
) {
2336 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
2339 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
2340 if (lp_ctx
->services
[iService
] != NULL
&&
2341 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
2342 return lp_ctx
->services
[iService
];
2349 * Copy a service structure to another.
2350 * If pcopymapDest is NULL then copy all fields
2353 static void copy_service(struct loadparm_service
*pserviceDest
,
2354 struct loadparm_service
*pserviceSource
,
2355 struct bitmap
*pcopymapDest
)
2358 bool bcopyall
= (pcopymapDest
== NULL
);
2359 struct parmlist_entry
*data
, *pdata
, *paramo
;
2362 for (i
= 0; parm_table
[i
].label
; i
++)
2363 if (parm_table
[i
].p_class
== P_LOCAL
&&
2364 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
2366 ((char *)pserviceSource
) + parm_table
[i
].offset
;
2368 ((char *)pserviceDest
) + parm_table
[i
].offset
;
2370 switch (parm_table
[i
].type
) {
2372 *(bool *)dest_ptr
= *(bool *)src_ptr
;
2379 *(int *)dest_ptr
= *(int *)src_ptr
;
2383 lpcfg_string_set(pserviceDest
,
2389 lpcfg_string_set_upper(pserviceDest
,
2394 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2395 *(const char ***)src_ptr
);
2403 init_copymap(pserviceDest
);
2404 if (pserviceSource
->copymap
)
2405 bitmap_copy(pserviceDest
->copymap
,
2406 pserviceSource
->copymap
);
2409 data
= pserviceSource
->param_opt
;
2412 pdata
= pserviceDest
->param_opt
;
2413 /* Traverse destination */
2415 /* If we already have same option, override it */
2416 if (strcmp(pdata
->key
, data
->key
) == 0) {
2417 talloc_free(pdata
->value
);
2418 pdata
->value
= talloc_strdup(pdata
,
2423 pdata
= pdata
->next
;
2426 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2429 paramo
->key
= talloc_strdup(paramo
, data
->key
);
2430 paramo
->value
= talloc_strdup(paramo
, data
->value
);
2431 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
2438 * Check a service for consistency. Return False if the service is in any way
2439 * incomplete or faulty, else True.
2441 static bool lpcfg_service_ok(struct loadparm_service
*service
)
2446 if (service
->szService
[0] == '\0') {
2447 DEBUG(0, ("The following message indicates an internal error:\n"));
2448 DEBUG(0, ("No service name in service entry.\n"));
2452 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2453 /* I can't see why you'd want a non-printable printer service... */
2454 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
2455 if (!service
->bPrint_ok
) {
2456 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2457 service
->szService
));
2458 service
->bPrint_ok
= true;
2460 /* [printers] service must also be non-browsable. */
2461 if (service
->bBrowseable
)
2462 service
->bBrowseable
= false;
2465 /* If a service is flagged unavailable, log the fact at level 0. */
2466 if (!service
->bAvailable
)
2467 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2468 service
->szService
));
2474 /*******************************************************************
2475 Keep a linked list of all config files so we know when one has changed
2476 it's date and needs to be reloaded.
2477 ********************************************************************/
2479 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
2480 const char *fname
, const char *subfname
)
2482 struct file_lists
*f
= lp_ctx
->file_lists
;
2485 if (f
->name
&& !strcmp(f
->name
, fname
))
2491 f
= talloc(lp_ctx
, struct file_lists
);
2494 f
->next
= lp_ctx
->file_lists
;
2495 f
->name
= talloc_strdup(f
, fname
);
2500 f
->subfname
= talloc_strdup(f
, subfname
);
2505 lp_ctx
->file_lists
= f
;
2506 f
->modtime
= file_modtime(subfname
);
2508 time_t t
= file_modtime(subfname
);
2514 /*******************************************************************
2515 Check if a config file has changed date.
2516 ********************************************************************/
2517 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
2519 struct file_lists
*f
;
2520 DEBUG(6, ("lp_file_list_changed()\n"));
2522 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
2526 n2
= standard_sub_basic(lp_ctx
, f
->name
);
2528 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2529 f
->name
, n2
, ctime(&f
->modtime
)));
2531 mod_time
= file_modtime(n2
);
2533 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
2534 DEBUGADD(6, ("file %s modified: %s\n", n2
,
2536 f
->modtime
= mod_time
;
2537 talloc_free(f
->subfname
);
2538 f
->subfname
= talloc_strdup(f
, n2
);
2545 /***************************************************************************
2546 Handle the "realm" parameter
2547 ***************************************************************************/
2549 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
2550 const char *pszParmValue
, char **ptr
)
2552 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2554 talloc_free(lp_ctx
->globals
->szRealm_upper
);
2555 talloc_free(lp_ctx
->globals
->szRealm_lower
);
2557 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
2558 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
2563 /***************************************************************************
2564 Handle the include operation.
2565 ***************************************************************************/
2567 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
2568 const char *pszParmValue
, char **ptr
)
2570 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
2572 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
2574 lpcfg_string_set(lp_ctx
, ptr
, fname
);
2576 if (file_exist(fname
))
2577 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
2579 DEBUG(2, ("Can't find include file %s\n", fname
));
2584 /***************************************************************************
2585 Handle the interpretation of the copy parameter.
2586 ***************************************************************************/
2588 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
2589 const char *pszParmValue
, char **ptr
)
2592 struct loadparm_service
*serviceTemp
;
2594 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2598 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2600 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
2601 if (serviceTemp
== lp_ctx
->currentService
) {
2602 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2604 copy_service(lp_ctx
->currentService
,
2606 lp_ctx
->currentService
->copymap
);
2610 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2618 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
2619 const char *pszParmValue
, char **ptr
)
2622 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2623 if (lp_ctx
->global
) {
2624 return debug_parse_levels(pszParmValue
);
2629 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
2630 const char *pszParmValue
, char **ptr
)
2632 debug_set_logfile(pszParmValue
);
2633 if (lp_ctx
->global
) {
2634 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2639 /***************************************************************************
2640 Initialise a copymap.
2641 ***************************************************************************/
2643 static void init_copymap(struct loadparm_service
*pservice
)
2647 TALLOC_FREE(pservice
->copymap
);
2649 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2650 if (!pservice
->copymap
)
2652 ("Couldn't allocate copymap!! (size %d)\n",
2653 (int)NUMPARAMETERS
));
2655 for (i
= 0; i
< NUMPARAMETERS
; i
++)
2656 bitmap_set(pservice
->copymap
, i
);
2660 * Process a parametric option
2662 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
2663 struct loadparm_service
*service
,
2664 const char *pszParmName
,
2665 const char *pszParmValue
, int flags
)
2667 struct parmlist_entry
*paramo
, *data
;
2669 TALLOC_CTX
*mem_ctx
;
2671 while (isspace((unsigned char)*pszParmName
)) {
2675 name
= strlower_talloc(lp_ctx
, pszParmName
);
2676 if (!name
) return false;
2678 if (service
== NULL
) {
2679 data
= lp_ctx
->globals
->param_opt
;
2680 mem_ctx
= lp_ctx
->globals
;
2682 data
= service
->param_opt
;
2686 /* Traverse destination */
2687 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
2688 /* If we already have the option set, override it unless
2689 it was a command line option and the new one isn't */
2690 if (strcmp(paramo
->key
, name
) == 0) {
2691 if ((paramo
->priority
& FLAG_CMDLINE
) &&
2692 !(flags
& FLAG_CMDLINE
)) {
2697 talloc_free(paramo
->value
);
2698 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2699 paramo
->priority
= flags
;
2705 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
2708 paramo
->key
= talloc_strdup(paramo
, name
);
2709 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2710 paramo
->priority
= flags
;
2711 if (service
== NULL
) {
2712 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
2714 DLIST_ADD(service
->param_opt
, paramo
);
2722 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
2723 const char *pszParmName
, const char *pszParmValue
,
2724 struct loadparm_context
*lp_ctx
, bool on_globals
)
2727 /* if it is a special case then go ahead */
2728 if (parm_table
[parmnum
].special
) {
2730 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2735 goto mark_non_default
;
2738 /* now switch on the type of variable it is */
2739 switch (parm_table
[parmnum
].type
)
2743 if (!set_boolean(pszParmValue
, &b
)) {
2744 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2747 *(bool *)parm_ptr
= b
;
2753 if (!set_boolean(pszParmValue
, &b
)) {
2754 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2757 *(bool *)parm_ptr
= !b
;
2762 *(int *)parm_ptr
= atoi(pszParmValue
);
2766 *(char *)parm_ptr
= *pszParmValue
;
2770 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2776 if (conv_str_size_error(pszParmValue
, &val
)) {
2777 if (val
<= INT_MAX
) {
2778 *(int *)parm_ptr
= (int)val
;
2783 DEBUG(0,("lp_do_parameter(%s): value is not "
2784 "a valid size specifier!\n", pszParmValue
));
2789 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2790 pszParmValue
, NULL
);
2794 char **new_list
= str_list_make(mem_ctx
,
2795 pszParmValue
, NULL
);
2796 for (i
=0; new_list
[i
]; i
++) {
2797 if (new_list
[i
][0] == '+' && new_list
[i
][1]) {
2798 if (!str_list_check(*(const char ***)parm_ptr
,
2800 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2803 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2804 str_list_remove(*(const char ***)parm_ptr
,
2808 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2809 pszParmName
, pszParmValue
));
2812 *(const char ***)parm_ptr
= (const char **) new_list
;
2819 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2823 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2827 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2830 parm_table
[parmnum
].enum_list
[i
].name
)) {
2832 parm_table
[parmnum
].
2837 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2838 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2839 pszParmValue
, pszParmName
));
2849 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
2850 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
2851 /* we have to also unset FLAG_DEFAULT on aliases */
2852 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2853 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2855 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2856 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2863 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2864 const char *pszParmName
, const char *pszParmValue
)
2866 int parmnum
= map_parameter(pszParmName
);
2870 if (strchr(pszParmName
, ':')) {
2871 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
2873 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2877 /* if the flag has been set on the command line, then don't allow override,
2878 but don't report an error */
2879 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2883 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
2885 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
2886 pszParmName
, pszParmValue
, lp_ctx
, true);
2889 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
2890 struct loadparm_service
*service
,
2891 const char *pszParmName
, const char *pszParmValue
)
2895 int parmnum
= map_parameter(pszParmName
);
2898 if (strchr(pszParmName
, ':')) {
2899 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
2901 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2905 /* if the flag has been set on the command line, then don't allow override,
2906 but don't report an error */
2907 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2911 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2913 ("Global parameter %s found in service section!\n",
2917 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
2919 if (!service
->copymap
)
2920 init_copymap(service
);
2922 /* this handles the aliases - set the copymap for other
2923 * entries with the same data pointer */
2924 for (i
= 0; parm_table
[i
].label
; i
++)
2925 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
2926 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
2927 bitmap_clear(service
->copymap
, i
);
2929 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
2930 pszParmValue
, lp_ctx
, false);
2934 * Process a parameter.
2937 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
2940 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2942 if (lp_ctx
->bInGlobalSection
)
2943 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
2946 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
2947 pszParmName
, pszParmValue
);
2951 variable argument do parameter
2953 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
2954 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
2955 const char *pszParmName
, const char *fmt
, ...)
2962 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2964 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
2971 set a parameter from the commandline - this is called from command line parameter
2972 parsing code. It sets the parameter then marks the parameter as unable to be modified
2973 by smb.conf processing
2975 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
2976 const char *pszParmValue
)
2981 if (lp_ctx
->s3_fns
) {
2982 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
2985 parmnum
= map_parameter(pszParmName
);
2987 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
2990 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
2991 /* set a parametric option */
2992 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
2993 pszParmValue
, FLAG_CMDLINE
);
2997 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
3001 /* reset the CMDLINE flag in case this has been called before */
3002 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
3004 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
3008 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
3010 /* we have to also set FLAG_CMDLINE on aliases */
3011 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
3012 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
3014 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
3015 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
3022 set a option from the commandline in 'a=b' format. Use to support --option
3024 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
3029 s
= talloc_strdup(NULL
, option
);
3042 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
3048 #define BOOLSTR(b) ((b) ? "Yes" : "No")
3051 * Print a parameter of the specified type.
3054 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
3056 /* For the seperation of lists values that we print below */
3057 const char *list_sep
= ", ";
3062 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
3063 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
3065 p
->enum_list
[i
].name
);
3072 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
3076 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
3081 fprintf(f
, "%d", *(int *)ptr
);
3085 fprintf(f
, "%c", *(char *)ptr
);
3089 int val
= *(int *)ptr
;
3093 fprintf(f
, "0%o", val
);
3102 if ((char ***)ptr
&& *(char ***)ptr
) {
3103 char **list
= *(char ***)ptr
;
3104 for (; *list
; list
++) {
3105 /* surround strings with whitespace in double quotes */
3106 if (*(list
+1) == NULL
) {
3107 /* last item, no extra separator */
3110 if ( strchr_m( *list
, ' ' ) ) {
3111 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
3113 fprintf(f
, "%s%s", *list
, list_sep
);
3121 if (*(char **)ptr
) {
3122 fprintf(f
, "%s", *(char **)ptr
);
3131 * Check if two parameters are equal.
3134 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
3139 return (*((bool *)ptr1
) == *((bool *)ptr2
));
3145 return (*((int *)ptr1
) == *((int *)ptr2
));
3148 return (*((char *)ptr1
) == *((char *)ptr2
));
3152 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
3157 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
3162 return (p1
== p2
|| strequal(p1
, p2
));
3171 * Process a new section (service).
3173 * At this stage all sections are services.
3174 * Later we'll have special sections that permit server parameters to be set.
3175 * Returns True on success, False on failure.
3178 static bool do_section(const char *pszSectionName
, void *userdata
)
3180 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
3182 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
3183 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
3186 /* if we've just struck a global section, note the fact. */
3187 lp_ctx
->bInGlobalSection
= isglobal
;
3189 /* check for multiple global sections */
3190 if (lp_ctx
->bInGlobalSection
) {
3191 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
3195 /* if we have a current service, tidy it up before moving on */
3198 if (lp_ctx
->currentService
!= NULL
)
3199 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3201 /* if all is still well, move to the next record in the services array */
3203 /* We put this here to avoid an odd message order if messages are */
3204 /* issued by the post-processing of a previous section. */
3205 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
3207 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
3210 DEBUG(0, ("Failed to add a new service\n"));
3220 * Determine if a particular base parameter is currently set to the default value.
3223 static bool is_default(struct loadparm_service
*sDefault
, int i
)
3225 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
3226 if (!defaults_saved
)
3228 switch (parm_table
[i
].type
) {
3231 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
3232 (const char **)def_ptr
);
3235 return strequal(parm_table
[i
].def
.svalue
,
3239 return parm_table
[i
].def
.bvalue
==
3246 return parm_table
[i
].def
.ivalue
==
3255 *Display the contents of the global structure.
3258 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
3262 struct parmlist_entry
*data
;
3264 fprintf(f
, "# Global parameters\n[global]\n");
3266 for (i
= 0; parm_table
[i
].label
; i
++)
3267 if (parm_table
[i
].p_class
== P_GLOBAL
&&
3268 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
3269 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
3271 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3272 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
3275 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3276 for (data
= lp_ctx
->globals
->param_opt
; data
;
3277 data
= data
->next
) {
3278 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
3281 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3288 * Display the contents of a single services record.
3291 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
3292 unsigned int *flags
)
3295 struct parmlist_entry
*data
;
3297 if (pService
!= sDefault
)
3298 fprintf(f
, "\n[%s]\n", pService
->szService
);
3300 for (i
= 0; parm_table
[i
].label
; i
++) {
3301 if (parm_table
[i
].p_class
== P_LOCAL
&&
3302 (*parm_table
[i
].label
!= '-') &&
3303 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3305 if (pService
== sDefault
) {
3306 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
3309 if (defaults_saved
) {
3310 if (is_default(sDefault
, i
)) {
3315 if (equal_parameter(parm_table
[i
].type
,
3316 ((char *)pService
) +
3317 parm_table
[i
].offset
,
3318 ((char *)sDefault
) +
3319 parm_table
[i
].offset
))
3323 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3324 print_parameter(&parm_table
[i
],
3325 ((char *)pService
) + parm_table
[i
].offset
, f
);
3329 if (pService
->param_opt
!= NULL
) {
3330 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
3331 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3336 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
3337 struct loadparm_service
*service
,
3338 const char *parm_name
, FILE * f
)
3340 struct parm_struct
*parm
;
3343 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3348 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3350 print_parameter(parm
, ptr
, f
);
3356 * Return info about the next parameter in a service.
3357 * snum==-1 gives the globals.
3358 * Return NULL when out of parameters.
3362 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
3366 /* do the globals */
3367 for (; parm_table
[*i
].label
; (*i
)++) {
3368 if ((*parm_table
[*i
].label
== '-'))
3372 && (parm_table
[*i
].offset
==
3373 parm_table
[(*i
) - 1].offset
)
3374 && (parm_table
[*i
].p_class
==
3375 parm_table
[(*i
) - 1].p_class
))
3378 return &parm_table
[(*i
)++];
3381 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
3383 for (; parm_table
[*i
].label
; (*i
)++) {
3384 if (parm_table
[*i
].p_class
== P_LOCAL
&&
3385 (*parm_table
[*i
].label
!= '-') &&
3387 (parm_table
[*i
].offset
!=
3388 parm_table
[(*i
) - 1].offset
)))
3390 if (allparameters
||
3391 !equal_parameter(parm_table
[*i
].type
,
3392 ((char *)pService
) +
3393 parm_table
[*i
].offset
,
3394 ((char *)lp_ctx
->sDefault
) +
3395 parm_table
[*i
].offset
))
3397 return &parm_table
[(*i
)++];
3408 * Auto-load some home services.
3410 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
3418 * Unload unused services.
3421 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
3422 struct smbsrv_connection
*smb
,
3423 bool (*snumused
) (struct smbsrv_connection
*, int))
3426 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3427 if (lp_ctx
->services
[i
] == NULL
)
3430 if (!snumused
|| !snumused(smb
, i
)) {
3431 talloc_free(lp_ctx
->services
[i
]);
3432 lp_ctx
->services
[i
] = NULL
;
3438 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
3440 struct parmlist_entry
*data
;
3442 if (lp_ctx
->refuse_free
) {
3443 /* someone is trying to free the
3444 global_loadparm_context.
3445 We can't allow that. */
3449 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3450 struct parmlist_entry
*next
;
3451 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3453 if (data
->priority
& FLAG_CMDLINE
) continue;
3454 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
3463 * Initialise the global parameter structure.
3465 * Note that most callers should use loadparm_init_global() instead
3467 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
3471 struct loadparm_context
*lp_ctx
;
3472 struct parmlist_entry
*parm
;
3475 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
3479 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
3480 lp_ctx
->bInGlobalSection
= true;
3481 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
3482 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
3484 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
3485 lp_ctx
->sDefault
->bAvailable
= true;
3486 lp_ctx
->sDefault
->bBrowseable
= true;
3487 lp_ctx
->sDefault
->bRead_only
= true;
3488 lp_ctx
->sDefault
->bMap_archive
= true;
3489 lp_ctx
->sDefault
->iStrictLocking
= true;
3490 lp_ctx
->sDefault
->bOpLocks
= true;
3491 lp_ctx
->sDefault
->iCreate_mask
= 0744;
3492 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
3493 lp_ctx
->sDefault
->iDir_mask
= 0755;
3494 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
3496 DEBUG(3, ("Initialising global parameters\n"));
3498 for (i
= 0; parm_table
[i
].label
; i
++) {
3499 if ((parm_table
[i
].type
== P_STRING
||
3500 parm_table
[i
].type
== P_USTRING
) &&
3501 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3503 if (parm_table
[i
].p_class
== P_LOCAL
) {
3504 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
3506 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
3508 *r
= talloc_strdup(lp_ctx
, "");
3512 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
3513 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
3514 talloc_free(logfile
);
3516 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
3518 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3520 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
3521 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
3522 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
3524 /* options that can be set on the command line must be initialised via
3525 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3527 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
3529 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
3530 myname
= get_myname(lp_ctx
);
3531 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
3532 talloc_free(myname
);
3533 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
3535 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
3537 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
3538 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
3540 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
3541 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3542 /* the winbind method for domain controllers is for both RODC
3543 auth forwarding and for trusted domains */
3544 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
3545 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3547 /* This hive should be dynamically generated by Samba using
3548 data from the sam, but for the moment leave it in a tdb to
3549 keep regedt32 from popping up an annoying dialog. */
3550 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
3552 /* using UTF8 by default allows us to support all chars */
3553 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
3555 /* Use codepage 850 as a default for the dos character set */
3556 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
3559 * Allow the default PASSWD_CHAT to be overridden in local.h.
3561 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
3563 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
3564 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
3565 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
3566 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
3567 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
3569 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
3570 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
3571 "Samba %s", SAMBA_VERSION_STRING
);
3573 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
3575 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
3576 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
3577 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
3579 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
3580 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
3581 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
3582 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
3583 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
3584 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
3585 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
3586 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
3587 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
3588 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
3589 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
3590 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
3591 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
3593 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
3594 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
3595 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
3596 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
3597 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
3598 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
3599 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
3600 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
3602 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
3604 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
3605 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
3607 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
3608 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
3610 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
3611 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
3612 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
3613 #if _SAMBA_BUILD_ >= 4
3614 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
3615 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
3616 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
3617 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
3618 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
3619 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
3621 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
3622 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3624 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
3625 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
3627 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
3629 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
3631 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
3632 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
3633 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
3634 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
3635 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
3636 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
3637 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
3639 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
3641 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
3642 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
3644 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
3645 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
3646 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
3647 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
3648 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
3650 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
3651 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
3653 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "False");
3654 lpcfg_do_global_parameter(lp_ctx
, "dns recursive queries", "False");
3655 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
3657 for (i
= 0; parm_table
[i
].label
; i
++) {
3658 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3659 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3663 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3664 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3665 parm
->priority
|= FLAG_DEFAULT
;
3673 * Initialise the global parameter structure.
3675 struct loadparm_context
*loadparm_init_global(bool load_default
)
3677 if (global_loadparm_context
== NULL
) {
3678 global_loadparm_context
= loadparm_init(NULL
);
3680 if (global_loadparm_context
== NULL
) {
3683 global_loadparm_context
->global
= true;
3684 if (load_default
&& !global_loadparm_context
->loaded
) {
3685 lpcfg_load_default(global_loadparm_context
);
3687 global_loadparm_context
->refuse_free
= true;
3688 return global_loadparm_context
;
3692 * Initialise the global parameter structure.
3694 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3695 const struct loadparm_s3_helpers
*s3_fns
)
3697 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
3698 if (!loadparm_context
) {
3701 loadparm_context
->s3_fns
= s3_fns
;
3702 return loadparm_context
;
3705 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3707 return lp_ctx
->szConfigFile
;
3710 const char *lp_default_path(void)
3712 if (getenv("SMB_CONF_PATH"))
3713 return getenv("SMB_CONF_PATH");
3715 return dyn_CONFIGFILE
;
3719 * Update the internal state of a loadparm context after settings
3722 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3724 struct debug_settings settings
;
3725 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
3727 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
3728 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3731 if (!lp_ctx
->global
) {
3735 panic_action
= lp_ctx
->globals
->panic_action
;
3737 reload_charcnv(lp_ctx
);
3739 ZERO_STRUCT(settings
);
3740 /* Add any more debug-related smb.conf parameters created in
3742 settings
.timestamp_logs
= true;
3743 debug_set_settings(&settings
);
3745 /* FIXME: This is a bit of a hack, but we can't use a global, since
3746 * not everything that uses lp also uses the socket library */
3747 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3748 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3750 unsetenv("SOCKET_TESTNONBLOCK");
3756 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3760 path
= lp_default_path();
3762 if (!file_exist(path
)) {
3763 /* We allow the default smb.conf file to not exist,
3764 * basically the equivalent of an empty file. */
3765 return lpcfg_update(lp_ctx
);
3768 return lpcfg_load(lp_ctx
, path
);
3772 * Load the services array from the services file.
3774 * Return True on success, False on failure.
3776 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3781 filename
= talloc_strdup(lp_ctx
, filename
);
3783 lp_ctx
->szConfigFile
= filename
;
3785 if (lp_ctx
->s3_fns
) {
3786 return lp_ctx
->s3_fns
->load(filename
);
3789 lp_ctx
->bInGlobalSection
= true;
3790 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3791 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3793 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
3795 /* We get sections first, so have to start 'behind' to make up */
3796 lp_ctx
->currentService
= NULL
;
3797 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
3799 /* finish up the last section */
3800 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3802 if (lp_ctx
->currentService
!= NULL
)
3803 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3805 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3807 /* we do this unconditionally, so that it happens even
3808 for a missing smb.conf */
3809 reload_charcnv(lp_ctx
);
3811 if (bRetval
== true) {
3812 /* set this up so that any child python tasks will
3813 find the right smb.conf */
3814 setenv("SMB_CONF_PATH", filename
, 1);
3816 /* set the context used by the lp_*() function
3818 global_loadparm_context
= lp_ctx
;
3819 lp_ctx
->loaded
= true;
3826 * Return the max number of services.
3829 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3831 if (lp_ctx
->s3_fns
) {
3832 return lp_ctx
->s3_fns
->get_numservices();
3835 return lp_ctx
->iNumServices
;
3839 * Display the contents of the services array in human-readable form.
3842 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3847 if (lp_ctx
->s3_fns
) {
3848 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3852 defaults_saved
= !show_defaults
;
3854 dump_globals(lp_ctx
, f
, show_defaults
);
3856 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
3858 for (iService
= 0; iService
< maxtoprint
; iService
++)
3859 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3863 * Display the contents of one service in human-readable form.
3865 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3867 if (service
!= NULL
) {
3868 if (service
->szService
[0] == '\0')
3870 dump_a_service(service
, sDefault
, f
, NULL
);
3874 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3877 if (lp_ctx
->s3_fns
) {
3878 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3881 return lp_ctx
->services
[snum
];
3884 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3885 const char *service_name
)
3890 if (lp_ctx
->s3_fns
) {
3891 return lp_ctx
->s3_fns
->get_service(service_name
);
3894 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3895 if (lp_ctx
->services
[iService
] &&
3896 lp_ctx
->services
[iService
]->szService
) {
3898 * The substitution here is used to support %U is
3901 serviceName
= standard_sub_basic(
3902 lp_ctx
->services
[iService
],
3903 lp_ctx
->services
[iService
]->szService
);
3904 if (strequal(serviceName
, service_name
)) {
3905 talloc_free(serviceName
);
3906 return lp_ctx
->services
[iService
];
3908 talloc_free(serviceName
);
3912 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3916 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3918 return lp_string((const char *)service
->szService
);
3922 * A useful volume label function.
3924 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3927 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3928 service
->volume
: sDefault
->volume
));
3930 return lpcfg_servicename(service
);
3935 * If we are PDC then prefer us as DMB
3937 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3940 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
3941 service
->szPrintername
: sDefault
->szPrintername
));
3942 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3943 ret
= lpcfg_servicename(service
);
3950 * Return the max print jobs per queue.
3952 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3954 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
3955 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3956 maxjobs
= PRINT_MAX_JOBID
- 1;
3961 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3963 if (lp_ctx
== NULL
) {
3964 return get_iconv_handle();
3966 return lp_ctx
->iconv_handle
;
3969 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3971 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3972 if (!lp_ctx
->global
) {
3976 if (old_ic
== NULL
) {
3977 old_ic
= global_iconv_handle
;
3979 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3980 global_iconv_handle
= lp_ctx
->iconv_handle
;
3983 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3985 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
3988 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3990 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
3993 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3995 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
3998 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
4000 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
4003 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
4005 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
4008 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
4010 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
4011 if (settings
== NULL
)
4013 SMB_ASSERT(lp_ctx
!= NULL
);
4014 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
4015 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
4019 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
4021 int domain_master
= lpcfg__domain_master(lp_ctx
);
4023 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
4024 lpcfg__security(lp_ctx
),
4025 lpcfg__domain_logons(lp_ctx
),
4026 (domain_master
== true) ||
4027 (domain_master
== Auto
));
4030 int lpcfg_security(struct loadparm_context
*lp_ctx
)
4032 return lp_find_security(lpcfg__server_role(lp_ctx
),
4033 lpcfg__security(lp_ctx
));