2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * This module provides suitable callback functions for the params
33 * module. It builds the internal table of service details which is
34 * then used by the rest of the server.
38 * 1) add it to the global or service structure definition
39 * 2) add it to the parm_table
40 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
41 * 4) If it's a global then initialise it in init_globals. If a local
42 * (ie. service) parameter then initialise it in the sDefault structure
46 * The configuration file is processed sequentially for speed. It is NOT
47 * accessed randomly as happens in 'real' Windows. For this reason, there
48 * is a fair bit of sequence-dependent code here - ie., code which assumes
49 * that certain things happen before others. In particular, the code which
50 * happens at the boundary between sections is delicately poised, so be
57 #include "dynconfig/dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "../lib/util/dlinklist.h"
62 #include "lib/param/param.h"
63 #include "lib/param/loadparm.h"
64 #include "auth/gensec/gensec.h"
66 #include "lib/util/bitmap.h"
67 #include "libcli/smb/smb_constants.h"
68 #include "source4/dns_server/dns_update.h"
70 #define standard_sub_basic talloc_strdup
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved
= false;
75 #define LOADPARM_EXTRA_GLOBALS \
76 struct parmlist_entry *param_opt; \
91 #include "param_global.h"
93 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
96 /* prototypes for the special type handlers */
97 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
98 const char *pszParmValue
, char **ptr
);
99 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
100 const char *pszParmValue
, char **ptr
);
101 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
102 const char *pszParmValue
, char **ptr
);
103 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
104 const char *pszParmValue
, char **ptr
);
105 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
106 const char *pszParmValue
, char **ptr
);
108 #include "param_enums.c"
110 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
111 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
113 static struct parm_struct parm_table
[] = {
115 .label
= "server role",
118 .offset
= GLOBAL_VAR(server_role
),
120 .enum_list
= enum_server_role
123 .label
= "domain logons",
126 .offset
= GLOBAL_VAR(domain_logons
),
128 .enum_list
= enum_bool_auto
131 .label
= "domain master",
134 .offset
= GLOBAL_VAR(domain_master
),
136 .enum_list
= enum_bool_auto
139 .label
= "dos charset",
142 .offset
= GLOBAL_VAR(dos_charset
),
147 .label
= "unix charset",
150 .offset
= GLOBAL_VAR(unix_charset
),
155 .label
= "ncalrpc dir",
158 .offset
= GLOBAL_VAR(ncalrpc_dir
),
166 .offset
= LOCAL_VAR(comment
),
169 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
175 .offset
= LOCAL_VAR(szPath
),
178 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
,
181 .label
= "directory",
184 .offset
= LOCAL_VAR(szPath
),
190 .label
= "workgroup",
193 .offset
= GLOBAL_VAR(szWorkgroup
),
196 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
202 .offset
= GLOBAL_VAR(szRealm
),
203 .special
= handle_realm
,
205 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
208 .label
= "netbios name",
211 .offset
= GLOBAL_VAR(szNetbiosName
),
214 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
217 .label
= "netbios aliases",
220 .offset
= GLOBAL_VAR(szNetbiosAliases
),
225 .label
= "netbios scope",
228 .offset
= GLOBAL_VAR(szNetbiosScope
),
231 .flags
= FLAG_ADVANCED
,
234 .label
= "server string",
237 .offset
= GLOBAL_VAR(szServerString
),
240 .flags
= FLAG_BASIC
| FLAG_ADVANCED
,
243 .label
= "interfaces",
246 .offset
= GLOBAL_VAR(szInterfaces
),
249 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
252 .label
= "bind interfaces only",
255 .offset
= GLOBAL_VAR(bBindInterfacesOnly
),
258 .flags
= FLAG_ADVANCED
| FLAG_WIZARD
,
261 .label
= "ntvfs handler",
264 .offset
= LOCAL_VAR(ntvfs_handler
),
269 .label
= "ntptr providor",
272 .offset
= GLOBAL_VAR(ntptr_providor
),
277 .label
= "passdb backend",
280 .offset
= GLOBAL_VAR(passdb_backend
),
285 .label
= "dcerpc endpoint servers",
288 .offset
= GLOBAL_VAR(dcerpc_ep_servers
),
293 .label
= "server services",
296 .offset
= GLOBAL_VAR(server_services
),
305 .offset
= GLOBAL_VAR(security
),
307 .enum_list
= enum_security
310 .label
= "encrypt passwords",
313 .offset
= GLOBAL_VAR(bEncryptPasswords
),
318 .label
= "null passwords",
321 .offset
= GLOBAL_VAR(bNullPasswords
),
324 .flags
= FLAG_ADVANCED
| FLAG_DEPRECATED
,
327 .label
= "obey pam restrictions",
330 .offset
= GLOBAL_VAR(bObeyPamRestrictions
),
333 .flags
= FLAG_ADVANCED
,
336 .label
= "password server",
339 .offset
= GLOBAL_VAR(szPasswordServer
),
344 .label
= "private dir",
347 .offset
= GLOBAL_VAR(szPrivateDir
),
352 .label
= "passwd chat",
355 .offset
= GLOBAL_VAR(szPasswdChat
),
360 .label
= "password level",
363 .offset
= GLOBAL_VAR(pwordlevel
),
368 .label
= "lanman auth",
371 .offset
= GLOBAL_VAR(bLanmanAuth
),
374 .flags
= FLAG_ADVANCED
,
377 .label
= "ntlm auth",
380 .offset
= GLOBAL_VAR(bNTLMAuth
),
383 .flags
= FLAG_ADVANCED
,
386 .label
= "client NTLMv2 auth",
389 .offset
= GLOBAL_VAR(bClientNTLMv2Auth
),
392 .flags
= FLAG_ADVANCED
,
395 .label
= "client lanman auth",
398 .offset
= GLOBAL_VAR(bClientLanManAuth
),
401 .flags
= FLAG_ADVANCED
,
404 .label
= "client plaintext auth",
407 .offset
= GLOBAL_VAR(bClientPlaintextAuth
),
410 .flags
= FLAG_ADVANCED
,
413 .label
= "client use spnego principal",
416 .offset
= GLOBAL_VAR(client_use_spnego_principal
),
422 .label
= "read only",
425 .offset
= LOCAL_VAR(bRead_only
),
431 .label
= "create mask",
434 .offset
= LOCAL_VAR(iCreate_mask
),
439 .label
= "force create mode",
442 .offset
= LOCAL_VAR(iCreate_force_mode
),
447 .label
= "directory mask",
450 .offset
= LOCAL_VAR(iDir_mask
),
455 .label
= "force directory mode",
458 .offset
= LOCAL_VAR(iDir_force_mode
),
464 .label
= "hosts allow",
467 .offset
= LOCAL_VAR(szHostsallow
),
472 .label
= "hosts deny",
475 .offset
= LOCAL_VAR(szHostsdeny
),
481 .label
= "log level",
484 .offset
= GLOBAL_VAR(loglevel
),
485 .special
= handle_debuglevel
,
489 .label
= "debuglevel",
492 .offset
= GLOBAL_VAR(loglevel
),
493 .special
= handle_debuglevel
,
500 .offset
= GLOBAL_VAR(logfile
),
501 .special
= handle_logfile
,
503 .flags
= FLAG_ADVANCED
,
507 .label
= "smb ports",
510 .offset
= GLOBAL_VAR(smb_ports
),
518 .offset
= GLOBAL_VAR(nbt_port
),
523 .label
= "dgram port",
526 .offset
= GLOBAL_VAR(dgram_port
),
531 .label
= "cldap port",
534 .offset
= GLOBAL_VAR(cldap_port
),
539 .label
= "krb5 port",
542 .offset
= GLOBAL_VAR(krb5_port
),
547 .label
= "kpasswd port",
550 .offset
= GLOBAL_VAR(kpasswd_port
),
558 .offset
= GLOBAL_VAR(web_port
),
563 .label
= "tls enabled",
566 .offset
= GLOBAL_VAR(tls_enabled
),
571 .label
= "tls keyfile",
574 .offset
= GLOBAL_VAR(tls_keyfile
),
579 .label
= "tls certfile",
582 .offset
= GLOBAL_VAR(tls_certfile
),
587 .label
= "tls cafile",
590 .offset
= GLOBAL_VAR(tls_cafile
),
595 .label
= "tls crlfile",
598 .offset
= GLOBAL_VAR(tls_crlfile
),
603 .label
= "tls dh params file",
606 .offset
= GLOBAL_VAR(tls_dhpfile
),
611 .label
= "large readwrite",
614 .offset
= GLOBAL_VAR(bLargeReadwrite
),
617 .flags
= FLAG_ADVANCED
,
620 .label
= "server max protocol",
623 .offset
= GLOBAL_VAR(srv_maxprotocol
),
625 .enum_list
= enum_protocol
,
626 .flags
= FLAG_ADVANCED
,
629 .label
= "max protocol",
632 .offset
= GLOBAL_VAR(srv_maxprotocol
),
634 .enum_list
= enum_protocol
,
635 .flags
= FLAG_ADVANCED
,
641 .offset
= GLOBAL_VAR(srv_maxprotocol
),
643 .enum_list
= enum_protocol
,
644 .flags
= FLAG_ADVANCED
,
647 .label
= "server min protocol",
650 .offset
= GLOBAL_VAR(srv_minprotocol
),
652 .enum_list
= enum_protocol
,
653 .flags
= FLAG_ADVANCED
,
656 .label
= "min protocol",
659 .offset
= GLOBAL_VAR(srv_minprotocol
),
661 .enum_list
= enum_protocol
,
662 .flags
= FLAG_ADVANCED
,
665 .label
= "client max protocol",
668 .offset
= GLOBAL_VAR(cli_maxprotocol
),
670 .enum_list
= enum_protocol
673 .label
= "client min protocol",
676 .offset
= GLOBAL_VAR(cli_minprotocol
),
678 .enum_list
= enum_protocol
684 .offset
= GLOBAL_VAR(bUnicode
),
692 .offset
= GLOBAL_VAR(bReadRaw
),
697 .label
= "write raw",
700 .offset
= GLOBAL_VAR(bWriteRaw
),
705 .label
= "disable netbios",
708 .offset
= GLOBAL_VAR(bDisableNetbios
),
714 .label
= "nt status support",
717 .offset
= GLOBAL_VAR(bNTStatusSupport
),
726 .offset
= GLOBAL_VAR(max_mux
),
729 .flags
= FLAG_ADVANCED
,
735 .offset
= GLOBAL_VAR(max_xmit
),
738 .flags
= FLAG_ADVANCED
,
742 .label
= "name resolve order",
745 .offset
= GLOBAL_VAR(szNameResolveOrder
),
750 .label
= "max wins ttl",
753 .offset
= GLOBAL_VAR(max_wins_ttl
),
756 .flags
= FLAG_ADVANCED
,
759 .label
= "min wins ttl",
762 .offset
= GLOBAL_VAR(min_wins_ttl
),
765 .flags
= FLAG_ADVANCED
,
768 .label
= "time server",
771 .offset
= GLOBAL_VAR(bTimeServer
),
774 .flags
= FLAG_ADVANCED
,
777 .label
= "unix extensions",
780 .offset
= GLOBAL_VAR(bUnixExtensions
),
783 .flags
= FLAG_ADVANCED
,
786 .label
= "use spnego",
789 .offset
= GLOBAL_VAR(bUseSpnego
),
794 .label
= "server signing",
797 .offset
= GLOBAL_VAR(server_signing
),
799 .enum_list
= enum_smb_signing_vals
,
800 .flags
= FLAG_ADVANCED
,
803 .label
= "client signing",
806 .offset
= GLOBAL_VAR(client_signing
),
808 .enum_list
= enum_smb_signing_vals
811 .label
= "rpc big endian",
814 .offset
= GLOBAL_VAR(bRpcBigEndian
),
820 .label
= "max connections",
823 .offset
= LOCAL_VAR(iMaxConnections
),
826 .flags
= FLAG_ADVANCED
| FLAG_SHARE
,
829 .label
= "paranoid server security",
832 .offset
= GLOBAL_VAR(paranoid_server_security
),
837 .label
= "socket options",
840 .offset
= GLOBAL_VAR(socket_options
),
846 .label
= "strict sync",
849 .offset
= LOCAL_VAR(bStrictSync
),
857 .offset
= GLOBAL_VAR(bUseMmap
),
860 .flags
= FLAG_ADVANCED
,
863 .label
= "case insensitive filesystem",
866 .offset
= LOCAL_VAR(bCIFileSystem
),
872 .label
= "max print jobs",
875 .offset
= LOCAL_VAR(iMaxPrintJobs
),
880 .label
= "printable",
883 .offset
= LOCAL_VAR(bPrint_ok
),
891 .offset
= LOCAL_VAR(bPrint_ok
),
897 .label
= "printer name",
900 .offset
= LOCAL_VAR(szPrintername
),
903 .flags
= FLAG_ADVANCED
| FLAG_PRINT
,
909 .offset
= LOCAL_VAR(szPrintername
),
916 .label
= "map system",
919 .offset
= LOCAL_VAR(bMap_system
),
924 .label
= "map hidden",
927 .offset
= LOCAL_VAR(bMap_hidden
),
932 .label
= "map archive",
935 .offset
= LOCAL_VAR(bMap_archive
),
941 .label
= "preferred master",
944 .offset
= GLOBAL_VAR(bPreferredMaster
),
946 .enum_list
= enum_bool_auto
,
947 .flags
= FLAG_BASIC
| FLAG_ADVANCED
,
950 .label
= "prefered master",
953 .offset
= GLOBAL_VAR(bPreferredMaster
),
955 .enum_list
= enum_bool_auto
,
959 .label
= "local master",
962 .offset
= GLOBAL_VAR(bLocalMaster
),
967 .label
= "browseable",
970 .offset
= LOCAL_VAR(bBrowseable
),
973 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
,
976 .label
= "browsable",
979 .offset
= LOCAL_VAR(bBrowseable
),
985 .label
= "dns proxy",
988 .offset
= GLOBAL_VAR(bWINSdnsProxy
),
993 .label
= "wins server",
996 .offset
= GLOBAL_VAR(szWINSservers
),
999 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
1002 .label
= "wins support",
1004 .p_class
= P_GLOBAL
,
1005 .offset
= GLOBAL_VAR(bWINSsupport
),
1008 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
1011 .label
= "wins hook",
1013 .p_class
= P_GLOBAL
,
1014 .offset
= GLOBAL_VAR(szWINSHook
),
1017 .flags
= FLAG_ADVANCED
,
1021 .label
= "csc policy",
1024 .offset
= LOCAL_VAR(iCSCPolicy
),
1026 .enum_list
= enum_csc_policy
,
1027 .flags
= FLAG_ADVANCED
| FLAG_SHARE
| FLAG_GLOBAL
,
1031 .label
= "strict locking",
1034 .offset
= LOCAL_VAR(iStrictLocking
),
1042 .offset
= LOCAL_VAR(bOpLocks
),
1048 .label
= "share backend",
1050 .p_class
= P_GLOBAL
,
1051 .offset
= GLOBAL_VAR(szShareBackend
),
1058 .p_class
= P_GLOBAL
,
1059 .offset
= GLOBAL_VAR(szAutoServices
),
1062 .flags
= FLAG_ADVANCED
,
1065 .label
= "auto services",
1067 .p_class
= P_GLOBAL
,
1068 .offset
= GLOBAL_VAR(szAutoServices
),
1071 .flags
= FLAG_ADVANCED
,
1074 .label
= "lock directory",
1076 .p_class
= P_GLOBAL
,
1077 .offset
= GLOBAL_VAR(szLockDir
),
1080 .flags
= FLAG_ADVANCED
,
1083 .label
= "lock dir",
1085 .p_class
= P_GLOBAL
,
1086 .offset
= GLOBAL_VAR(szLockDir
),
1092 .label
= "state directory",
1094 .p_class
= P_GLOBAL
,
1095 .offset
= GLOBAL_VAR(szStateDir
),
1098 .flags
= FLAG_ADVANCED
,
1101 .label
= "cache directory",
1103 .p_class
= P_GLOBAL
,
1104 .offset
= GLOBAL_VAR(szCacheDir
),
1107 .flags
= FLAG_ADVANCED
,
1110 .label
= "pid directory",
1112 .p_class
= P_GLOBAL
,
1113 .offset
= GLOBAL_VAR(szPidDir
),
1119 .label
= "socket address",
1121 .p_class
= P_GLOBAL
,
1122 .offset
= GLOBAL_VAR(szSocketAddress
),
1130 .offset
= LOCAL_VAR(szCopy
),
1131 .special
= handle_copy
,
1139 .offset
= LOCAL_VAR(szInclude
),
1140 .special
= handle_include
,
1145 .label
= "available",
1148 .offset
= LOCAL_VAR(bAvailable
),
1156 .offset
= LOCAL_VAR(volume
),
1159 .flags
= FLAG_ADVANCED
| FLAG_SHARE
,
1165 .offset
= LOCAL_VAR(fstype
),
1171 .label
= "panic action",
1173 .p_class
= P_GLOBAL
,
1174 .offset
= GLOBAL_VAR(panic_action
),
1180 .label
= "msdfs root",
1183 .offset
= LOCAL_VAR(bMSDfsRoot
),
1188 .label
= "host msdfs",
1190 .p_class
= P_GLOBAL
,
1191 .offset
= GLOBAL_VAR(bHostMSDfs
),
1194 .flags
= FLAG_ADVANCED
,
1197 .label
= "winbind separator",
1199 .p_class
= P_GLOBAL
,
1200 .offset
= GLOBAL_VAR(szWinbindSeparator
),
1205 .label
= "winbindd socket directory",
1207 .p_class
= P_GLOBAL
,
1208 .offset
= GLOBAL_VAR(szWinbinddSocketDirectory
),
1211 .flags
= FLAG_ADVANCED
,
1214 .label
= "winbindd privileged socket directory",
1216 .p_class
= P_GLOBAL
,
1217 .offset
= GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
),
1220 .flags
= FLAG_ADVANCED
,
1223 .label
= "winbind sealed pipes",
1225 .p_class
= P_GLOBAL
,
1226 .offset
= GLOBAL_VAR(bWinbindSealedPipes
),
1229 .flags
= FLAG_ADVANCED
,
1232 .label
= "template shell",
1234 .p_class
= P_GLOBAL
,
1235 .offset
= GLOBAL_VAR(szTemplateShell
),
1238 .flags
= FLAG_ADVANCED
,
1241 .label
= "template homedir",
1243 .p_class
= P_GLOBAL
,
1244 .offset
= GLOBAL_VAR(szTemplateHomedir
),
1247 .flags
= FLAG_ADVANCED
,
1250 .label
= "idmap trusted only",
1252 .p_class
= P_GLOBAL
,
1253 .offset
= GLOBAL_VAR(bIdmapTrustedOnly
),
1256 .flags
= FLAG_ADVANCED
,
1260 .label
= "ntp signd socket directory",
1262 .p_class
= P_GLOBAL
,
1263 .offset
= GLOBAL_VAR(szNTPSignDSocketDirectory
),
1266 .flags
= FLAG_ADVANCED
,
1269 .label
= "rndc command",
1271 .p_class
= P_GLOBAL
,
1272 .offset
= GLOBAL_VAR(szRNDCCommand
),
1275 .flags
= FLAG_ADVANCED
,
1278 .label
= "dns update command",
1280 .p_class
= P_GLOBAL
,
1281 .offset
= GLOBAL_VAR(szDNSUpdateCommand
),
1284 .flags
= FLAG_ADVANCED
,
1287 .label
= "spn update command",
1289 .p_class
= P_GLOBAL
,
1290 .offset
= GLOBAL_VAR(szSPNUpdateCommand
),
1293 .flags
= FLAG_ADVANCED
,
1296 .label
= "samba kcc command",
1298 .p_class
= P_GLOBAL
,
1299 .offset
= GLOBAL_VAR(szSambaKCCCommand
),
1302 .flags
= FLAG_ADVANCED
,
1305 .label
= "nsupdate command",
1307 .p_class
= P_GLOBAL
,
1308 .offset
= GLOBAL_VAR(szNSUpdateCommand
),
1311 .flags
= FLAG_ADVANCED
,
1314 .label
= "allow dns updates",
1316 .p_class
= P_GLOBAL
,
1317 .offset
= GLOBAL_VAR(allow_dns_updates
),
1319 .enum_list
= enum_dns_update_settings
,
1320 .flags
= FLAG_ADVANCED
,
1323 .label
= "dns forwarder",
1325 .p_class
= P_GLOBAL
,
1326 .offset
= GLOBAL_VAR(dns_forwarder
),
1329 .flags
= FLAG_ADVANCED
,
1332 .label
= "dns recursive queries",
1334 .p_class
= P_GLOBAL
,
1335 .offset
= GLOBAL_VAR(dns_recursive_queries
),
1340 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
, 0}
1344 /* local variables */
1345 struct loadparm_context
{
1346 const char *szConfigFile
;
1347 struct loadparm_global
*globals
;
1348 struct loadparm_service
**services
;
1349 struct loadparm_service
*sDefault
;
1350 struct smb_iconv_handle
*iconv_handle
;
1352 struct loadparm_service
*currentService
;
1353 bool bInGlobalSection
;
1355 struct file_lists
*next
;
1360 unsigned int flags
[NUMPARAMETERS
];
1363 bool global
; /* Is this the global context, which may set
1364 * global variables such as debug level etc? */
1365 const struct loadparm_s3_context
*s3_fns
;
1369 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
1371 if (lp_ctx
->s3_fns
) {
1372 return lp_ctx
->s3_fns
->get_default_loadparm_service();
1374 return lp_ctx
->sDefault
;
1378 * Convenience routine to grab string parameters into temporary memory
1379 * and run standard_sub_basic on them.
1381 * The buffers can be written to by
1382 * callers without affecting the source string.
1385 static const char *lp_string(const char *s
)
1387 #if 0 /* until REWRITE done to make thread-safe */
1388 size_t len
= s
? strlen(s
) : 0;
1392 /* The follow debug is useful for tracking down memory problems
1393 especially if you have an inner loop that is calling a lp_*()
1394 function that returns a string. Perhaps this debug should be
1395 present all the time? */
1398 DEBUG(10, ("lp_string(%s)\n", s
));
1401 #if 0 /* until REWRITE done to make thread-safe */
1403 lp_talloc
= talloc_init("lp_talloc");
1405 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
1413 strlcpy(ret
, s
, len
);
1415 if (trim_string(ret
, "\"", "\"")) {
1416 if (strchr(ret
,'"') != NULL
)
1417 strlcpy(ret
, s
, len
);
1420 standard_sub_basic(ret
,len
+100);
1427 In this section all the functions that are used to access the
1428 parameters from the rest of the program are defined
1432 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1433 * for code compatibility between existing Samba4 and Samba3 code.
1436 /* this global context supports the lp_*() function varients */
1437 static struct loadparm_context
*global_loadparm_context
;
1439 #define lpcfg_default_service global_loadparm_context->sDefault
1440 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1442 #define FN_GLOBAL_STRING(fn_name,var_name) \
1443 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1444 if (lp_ctx == NULL) return NULL; \
1445 if (lp_ctx->s3_fns) { \
1446 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1447 return lp_ctx->s3_fns->fn_name(); \
1449 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1452 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1453 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1454 if (lp_ctx == NULL) return NULL; \
1455 if (lp_ctx->s3_fns) { \
1456 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1457 return lp_ctx->s3_fns->fn_name(); \
1459 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1462 #define FN_GLOBAL_LIST(fn_name,var_name) \
1463 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1464 if (lp_ctx == NULL) return NULL; \
1465 if (lp_ctx->s3_fns) { \
1466 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1467 return lp_ctx->s3_fns->fn_name(); \
1469 return lp_ctx->globals->var_name; \
1472 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1473 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1474 if (lp_ctx == NULL) return false; \
1475 if (lp_ctx->s3_fns) { \
1476 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1477 return lp_ctx->s3_fns->fn_name(); \
1479 return lp_ctx->globals->var_name; \
1482 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1483 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1484 if (lp_ctx->s3_fns) { \
1485 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1486 return lp_ctx->s3_fns->fn_name(); \
1488 return lp_ctx->globals->var_name; \
1491 /* Local parameters don't need the ->s3_fns because the struct
1492 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1494 #define FN_LOCAL_STRING(fn_name,val) \
1495 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1496 struct loadparm_service *sDefault) { \
1497 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1500 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1502 #define FN_LOCAL_LIST(fn_name,val) \
1503 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1504 struct loadparm_service *sDefault) {\
1505 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1508 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1510 #define FN_LOCAL_BOOL(fn_name,val) \
1511 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1512 struct loadparm_service *sDefault) { \
1513 return((service != NULL)? service->val : sDefault->val); \
1516 #define FN_LOCAL_INTEGER(fn_name,val) \
1517 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1518 struct loadparm_service *sDefault) { \
1519 return((service != NULL)? service->val : sDefault->val); \
1522 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1524 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1526 #define FN_LOCAL_CHAR(fn_name,val) \
1527 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1528 struct loadparm_service *sDefault) { \
1529 return((service != NULL)? service->val : sDefault->val); \
1532 #include "lib/param/param_functions.c"
1534 FN_GLOBAL_LIST(smb_ports
, smb_ports
)
1535 FN_GLOBAL_INTEGER(nbt_port
, nbt_port
)
1536 FN_GLOBAL_INTEGER(dgram_port
, dgram_port
)
1537 FN_GLOBAL_INTEGER(cldap_port
, cldap_port
)
1538 FN_GLOBAL_INTEGER(krb5_port
, krb5_port
)
1539 FN_GLOBAL_INTEGER(kpasswd_port
, kpasswd_port
)
1540 FN_GLOBAL_INTEGER(web_port
, web_port
)
1541 FN_GLOBAL_BOOL(tls_enabled
, tls_enabled
)
1542 FN_GLOBAL_STRING(logfile
, logfile
)
1543 FN_GLOBAL_STRING(share_backend
, szShareBackend
)
1544 FN_GLOBAL_CONST_STRING(winbind_separator
, szWinbindSeparator
)
1545 FN_GLOBAL_CONST_STRING(winbindd_socket_directory
, szWinbinddSocketDirectory
)
1546 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
1547 FN_GLOBAL_CONST_STRING(template_shell
, szTemplateShell
)
1548 FN_GLOBAL_CONST_STRING(template_homedir
, szTemplateHomedir
)
1549 FN_GLOBAL_BOOL(winbind_sealed_pipes
, bWinbindSealedPipes
)
1550 FN_GLOBAL_BOOL(idmap_trusted_only
, bIdmapTrustedOnly
)
1551 FN_GLOBAL_STRING(private_dir
, szPrivateDir
)
1552 FN_GLOBAL_STRING(serverstring
, szServerString
)
1553 FN_GLOBAL_STRING(lockdir
, szLockDir
)
1554 FN_GLOBAL_STRING(statedir
, szStateDir
)
1555 FN_GLOBAL_STRING(cachedir
, szCacheDir
)
1556 FN_GLOBAL_STRING(ncalrpc_dir
, ncalrpc_dir
)
1557 FN_GLOBAL_STRING(dos_charset
, dos_charset
)
1558 FN_GLOBAL_STRING(unix_charset
, unix_charset
)
1559 FN_GLOBAL_STRING(piddir
, szPidDir
)
1560 FN_GLOBAL_LIST(rndc_command
, szRNDCCommand
)
1561 FN_GLOBAL_LIST(dns_update_command
, szDNSUpdateCommand
)
1562 FN_GLOBAL_LIST(spn_update_command
, szSPNUpdateCommand
)
1563 FN_GLOBAL_LIST(samba_kcc_command
, szSambaKCCCommand
)
1564 FN_GLOBAL_LIST(nsupdate_command
, szNSUpdateCommand
)
1565 FN_GLOBAL_LIST(dcerpc_endpoint_servers
, dcerpc_ep_servers
)
1566 FN_GLOBAL_LIST(server_services
, server_services
)
1567 FN_GLOBAL_STRING(ntptr_providor
, ntptr_providor
)
1568 FN_GLOBAL_STRING(passdb_backend
, passdb_backend
)
1569 FN_GLOBAL_STRING(auto_services
, szAutoServices
)
1570 FN_GLOBAL_STRING(passwd_chat
, szPasswdChat
)
1571 FN_GLOBAL_CONST_STRING(passwordserver
, szPasswordServer
)
1572 FN_GLOBAL_LIST(name_resolve_order
, szNameResolveOrder
)
1573 FN_GLOBAL_STRING(realm
, szRealm_upper
)
1574 FN_GLOBAL_STRING(dnsdomain
, szRealm_lower
)
1575 FN_GLOBAL_STRING(socket_options
, socket_options
)
1576 FN_GLOBAL_STRING(workgroup
, szWorkgroup
)
1577 FN_GLOBAL_STRING(netbios_name
, szNetbiosName
)
1578 FN_GLOBAL_STRING(netbios_scope
, szNetbiosScope
)
1579 FN_GLOBAL_LIST(wins_server_list
, szWINSservers
)
1580 FN_GLOBAL_LIST(interfaces
, szInterfaces
)
1581 FN_GLOBAL_STRING(socket_address
, szSocketAddress
)
1582 FN_GLOBAL_LIST(netbios_aliases
, szNetbiosAliases
)
1583 FN_GLOBAL_BOOL(disable_netbios
, bDisableNetbios
)
1584 FN_GLOBAL_BOOL(we_are_a_wins_server
, bWINSsupport
)
1585 FN_GLOBAL_BOOL(wins_dns_proxy
, bWINSdnsProxy
)
1586 FN_GLOBAL_STRING(wins_hook
, szWINSHook
)
1587 FN_GLOBAL_BOOL(local_master
, bLocalMaster
)
1588 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
1589 FN_GLOBAL_BOOL(large_readwrite
, bLargeReadwrite
)
1590 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
1591 FN_GLOBAL_BOOL(null_passwords
, bNullPasswords
)
1592 FN_GLOBAL_BOOL(obey_pam_restrictions
, bObeyPamRestrictions
)
1593 FN_GLOBAL_BOOL(encrypted_passwords
, bEncryptPasswords
)
1594 FN_GLOBAL_BOOL(time_server
, bTimeServer
)
1595 FN_GLOBAL_BOOL(bind_interfaces_only
, bBindInterfacesOnly
)
1596 FN_GLOBAL_BOOL(unicode
, bUnicode
)
1597 FN_GLOBAL_BOOL(nt_status_support
, bNTStatusSupport
)
1598 FN_GLOBAL_BOOL(lanman_auth
, bLanmanAuth
)
1599 FN_GLOBAL_BOOL(ntlm_auth
, bNTLMAuth
)
1600 FN_GLOBAL_BOOL(client_plaintext_auth
, bClientPlaintextAuth
)
1601 FN_GLOBAL_BOOL(client_lanman_auth
, bClientLanManAuth
)
1602 FN_GLOBAL_BOOL(client_ntlmv2_auth
, bClientNTLMv2Auth
)
1603 FN_GLOBAL_BOOL(client_use_spnego_principal
, client_use_spnego_principal
)
1604 FN_GLOBAL_BOOL(host_msdfs
, bHostMSDfs
)
1605 FN_GLOBAL_BOOL(unix_extensions
, bUnixExtensions
)
1606 FN_GLOBAL_BOOL(use_spnego
, bUseSpnego
)
1607 FN_GLOBAL_BOOL(use_mmap
, bUseMmap
)
1608 FN_GLOBAL_BOOL(rpc_big_endian
, bRpcBigEndian
)
1609 FN_GLOBAL_INTEGER(max_wins_ttl
, max_wins_ttl
)
1610 FN_GLOBAL_INTEGER(min_wins_ttl
, min_wins_ttl
)
1611 FN_GLOBAL_INTEGER(maxmux
, max_mux
)
1612 FN_GLOBAL_INTEGER(max_xmit
, max_xmit
)
1613 FN_GLOBAL_INTEGER(passwordlevel
, pwordlevel
)
1614 FN_GLOBAL_INTEGER(srv_maxprotocol
, srv_maxprotocol
)
1615 FN_GLOBAL_INTEGER(srv_minprotocol
, srv_minprotocol
)
1616 FN_GLOBAL_INTEGER(cli_maxprotocol
, cli_maxprotocol
)
1617 FN_GLOBAL_INTEGER(cli_minprotocol
, cli_minprotocol
)
1618 FN_GLOBAL_BOOL(paranoid_server_security
, paranoid_server_security
)
1620 FN_GLOBAL_INTEGER(allow_dns_updates
, allow_dns_updates
)
1621 FN_GLOBAL_CONST_STRING(dns_forwarder
, dns_forwarder
)
1622 FN_GLOBAL_BOOL(dns_recursive_queries
, dns_recursive_queries
)
1624 FN_GLOBAL_INTEGER(server_signing
, server_signing
)
1625 FN_GLOBAL_INTEGER(client_signing
, client_signing
)
1627 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
1629 /* local prototypes */
1630 static int map_parameter(const char *pszParmName
);
1631 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1632 const char *pszServiceName
);
1633 static void copy_service(struct loadparm_service
*pserviceDest
,
1634 struct loadparm_service
*pserviceSource
,
1635 struct bitmap
*pcopymapDest
);
1636 static bool lpcfg_service_ok(struct loadparm_service
*service
);
1637 static bool do_section(const char *pszSectionName
, void *);
1638 static void init_copymap(struct loadparm_service
*pservice
);
1640 /* This is a helper function for parametrical options support. */
1641 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1642 /* Actual parametrical functions are quite simple */
1643 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
1644 struct loadparm_service
*service
,
1645 const char *type
, const char *option
)
1647 char *vfskey_tmp
= NULL
;
1648 char *vfskey
= NULL
;
1649 struct parmlist_entry
*data
;
1654 if (lp_ctx
->s3_fns
) {
1655 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
1658 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
1660 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
1661 if (vfskey_tmp
== NULL
) return NULL
;
1662 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
1663 talloc_free(vfskey_tmp
);
1666 if (strcmp(data
->key
, vfskey
) == 0) {
1667 talloc_free(vfskey
);
1673 if (service
!= NULL
) {
1674 /* Try to fetch the same option but from globals */
1675 /* but only if we are not already working with globals */
1676 for (data
= lp_ctx
->globals
->param_opt
; data
;
1677 data
= data
->next
) {
1678 if (strcmp(data
->key
, vfskey
) == 0) {
1679 talloc_free(vfskey
);
1685 talloc_free(vfskey
);
1692 * convenience routine to return int parameters.
1694 static int lp_int(const char *s
)
1698 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1702 return strtol(s
, NULL
, 0);
1706 * convenience routine to return unsigned long parameters.
1708 static unsigned long lp_ulong(const char *s
)
1712 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
1716 return strtoul(s
, NULL
, 0);
1720 * convenience routine to return unsigned long parameters.
1722 static long lp_long(const char *s
)
1726 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
1730 return strtol(s
, NULL
, 0);
1734 * convenience routine to return unsigned long parameters.
1736 static double lp_double(const char *s
)
1740 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
1744 return strtod(s
, NULL
);
1748 * convenience routine to return boolean parameters.
1750 static bool lp_bool(const char *s
)
1755 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
1759 if (!set_boolean(s
, &ret
)) {
1760 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
1769 * Return parametric option from a given service. Type is a part of option before ':'
1770 * Parametric option has following syntax: 'Type: option = value'
1771 * Returned value is allocated in 'lp_talloc' context
1774 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
1775 struct loadparm_service
*service
, const char *type
,
1778 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1781 return lp_string(value
);
1787 * Return parametric option from a given service. Type is a part of option before ':'
1788 * Parametric option has following syntax: 'Type: option = value'
1789 * Returned value is allocated in 'lp_talloc' context
1792 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
1793 struct loadparm_context
*lp_ctx
,
1794 struct loadparm_service
*service
,
1796 const char *option
, const char *separator
)
1798 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1801 return (const char **)str_list_make(mem_ctx
, value
, separator
);
1807 * Return parametric option from a given service. Type is a part of option before ':'
1808 * Parametric option has following syntax: 'Type: option = value'
1811 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
1812 struct loadparm_service
*service
, const char *type
,
1813 const char *option
, int default_v
)
1815 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1818 return lp_int(value
);
1824 * Return parametric option from a given service. Type is a part of
1825 * option before ':'.
1826 * Parametric option has following syntax: 'Type: option = value'.
1829 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
1830 struct loadparm_service
*service
, const char *type
,
1831 const char *option
, int default_v
)
1835 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1837 if (value
&& conv_str_size_error(value
, &bval
)) {
1838 if (bval
<= INT_MAX
) {
1847 * Return parametric option from a given service.
1848 * Type is a part of option before ':'
1849 * Parametric option has following syntax: 'Type: option = value'
1851 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
1852 struct loadparm_service
*service
, const char *type
,
1853 const char *option
, unsigned long default_v
)
1855 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1858 return lp_ulong(value
);
1863 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
1864 struct loadparm_service
*service
, const char *type
,
1865 const char *option
, long default_v
)
1867 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1870 return lp_long(value
);
1875 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
1876 struct loadparm_service
*service
, const char *type
,
1877 const char *option
, double default_v
)
1879 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1882 return lp_double(value
);
1888 * Return parametric option from a given service. Type is a part of option before ':'
1889 * Parametric option has following syntax: 'Type: option = value'
1892 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
1893 struct loadparm_service
*service
, const char *type
,
1894 const char *option
, bool default_v
)
1896 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1899 return lp_bool(value
);
1906 * Initialise a service to the defaults.
1909 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1911 struct loadparm_service
*pservice
=
1912 talloc_zero(mem_ctx
, struct loadparm_service
);
1913 copy_service(pservice
, sDefault
, NULL
);
1918 * Set a string value, deallocating any existing space, and allocing the space
1921 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1928 *dest
= talloc_strdup(mem_ctx
, src
);
1929 if ((*dest
) == NULL
) {
1930 DEBUG(0,("Out of memory in string_set\n"));
1938 * Set a string value, deallocating any existing space, and allocing the space
1941 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1948 *dest
= strupper_talloc(mem_ctx
, src
);
1949 if ((*dest
) == NULL
) {
1950 DEBUG(0,("Out of memory in string_set_upper\n"));
1960 * Add a new service to the services array initialising it with the given
1964 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
1965 const struct loadparm_service
*pservice
,
1969 struct loadparm_service tservice
;
1970 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1971 struct parmlist_entry
*data
, *pdata
;
1973 if (pservice
== NULL
) {
1974 pservice
= lp_ctx
->sDefault
;
1977 tservice
= *pservice
;
1979 /* it might already exist */
1981 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1983 if (service
!= NULL
) {
1984 /* Clean all parametric options for service */
1985 /* They will be added during parsing again */
1986 data
= service
->param_opt
;
1992 service
->param_opt
= NULL
;
1997 /* find an invalid one */
1998 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1999 if (lp_ctx
->services
[i
] == NULL
)
2002 /* if not, then create one */
2003 if (i
== lp_ctx
->iNumServices
) {
2004 struct loadparm_service
**tsp
;
2006 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
2009 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2012 lp_ctx
->services
= tsp
;
2013 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
2016 lp_ctx
->iNumServices
++;
2019 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
2020 if (lp_ctx
->services
[i
] == NULL
) {
2021 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2024 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
2026 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
2027 return lp_ctx
->services
[i
];
2031 * Add a new home service, with the specified home directory, defaults coming
2032 * from service ifrom.
2035 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
2036 const char *pszHomename
,
2037 struct loadparm_service
*default_service
,
2038 const char *user
, const char *pszHomedir
)
2040 struct loadparm_service
*service
;
2042 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
2044 if (service
== NULL
)
2047 if (!(*(default_service
->szPath
))
2048 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
2049 service
->szPath
= talloc_strdup(service
, pszHomedir
);
2051 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
2054 if (!(*(service
->comment
))) {
2055 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
2057 service
->bAvailable
= default_service
->bAvailable
;
2058 service
->bBrowseable
= default_service
->bBrowseable
;
2060 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2061 pszHomename
, user
, service
->szPath
));
2067 * Add a new printer service, with defaults coming from service iFrom.
2070 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
2071 const char *pszPrintername
,
2072 struct loadparm_service
*default_service
)
2074 const char *comment
= "From Printcap";
2075 struct loadparm_service
*service
;
2076 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
2078 if (service
== NULL
)
2081 /* note that we do NOT default the availability flag to True - */
2082 /* we take it from the default service passed. This allows all */
2083 /* dynamic printers to be disabled by disabling the [printers] */
2084 /* entry (if/when the 'available' keyword is implemented!). */
2086 /* the printer name is set to the service name. */
2087 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
2088 lpcfg_string_set(service
, &service
->comment
, comment
);
2089 service
->bBrowseable
= default_service
->bBrowseable
;
2090 /* Printers cannot be read_only. */
2091 service
->bRead_only
= false;
2092 /* Printer services must be printable. */
2093 service
->bPrint_ok
= true;
2095 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
2101 * Map a parameter's string representation to something we can use.
2102 * Returns False if the parameter string is not recognised, else TRUE.
2105 static int map_parameter(const char *pszParmName
)
2109 if (*pszParmName
== '-')
2112 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
2113 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
2116 /* Warn only if it isn't parametric option */
2117 if (strchr(pszParmName
, ':') == NULL
)
2118 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
2119 /* We do return 'fail' for parametric options as well because they are
2120 stored in different storage
2127 return the parameter structure for a parameter
2129 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
2133 if (lp_ctx
->s3_fns
) {
2134 return lp_ctx
->s3_fns
->get_parm_struct(name
);
2137 parmnum
= map_parameter(name
);
2138 if (parmnum
== -1) return NULL
;
2139 return &parm_table
[parmnum
];
2143 return the parameter pointer for a parameter
2145 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
2146 struct loadparm_service
*service
, struct parm_struct
*parm
)
2148 if (lp_ctx
->s3_fns
) {
2149 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
2152 if (service
== NULL
) {
2153 if (parm
->p_class
== P_LOCAL
)
2154 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
2155 else if (parm
->p_class
== P_GLOBAL
)
2156 return ((char *)lp_ctx
->globals
)+parm
->offset
;
2159 return ((char *)service
) + parm
->offset
;
2164 return the parameter pointer for a parameter
2166 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
2170 if (lp_ctx
->s3_fns
) {
2171 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
2173 return parm
->flags
& FLAG_CMDLINE
;
2178 parmnum
= map_parameter(name
);
2179 if (parmnum
== -1) return false;
2181 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
2185 * Find a service by name. Otherwise works like get_service.
2188 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
2189 const char *pszServiceName
)
2193 if (lp_ctx
->s3_fns
) {
2194 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
2197 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
2198 if (lp_ctx
->services
[iService
] != NULL
&&
2199 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
2200 return lp_ctx
->services
[iService
];
2207 * Copy a service structure to another.
2208 * If pcopymapDest is NULL then copy all fields
2211 static void copy_service(struct loadparm_service
*pserviceDest
,
2212 struct loadparm_service
*pserviceSource
,
2213 struct bitmap
*pcopymapDest
)
2216 bool bcopyall
= (pcopymapDest
== NULL
);
2217 struct parmlist_entry
*data
, *pdata
, *paramo
;
2220 for (i
= 0; parm_table
[i
].label
; i
++)
2221 if (parm_table
[i
].p_class
== P_LOCAL
&&
2222 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
2224 ((char *)pserviceSource
) + parm_table
[i
].offset
;
2226 ((char *)pserviceDest
) + parm_table
[i
].offset
;
2228 switch (parm_table
[i
].type
) {
2230 *(bool *)dest_ptr
= *(bool *)src_ptr
;
2237 *(int *)dest_ptr
= *(int *)src_ptr
;
2241 lpcfg_string_set(pserviceDest
,
2247 lpcfg_string_set_upper(pserviceDest
,
2252 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2253 *(const char ***)src_ptr
);
2261 init_copymap(pserviceDest
);
2262 if (pserviceSource
->copymap
)
2263 bitmap_copy(pserviceDest
->copymap
,
2264 pserviceSource
->copymap
);
2267 data
= pserviceSource
->param_opt
;
2270 pdata
= pserviceDest
->param_opt
;
2271 /* Traverse destination */
2273 /* If we already have same option, override it */
2274 if (strcmp(pdata
->key
, data
->key
) == 0) {
2275 talloc_free(pdata
->value
);
2276 pdata
->value
= talloc_strdup(pdata
,
2281 pdata
= pdata
->next
;
2284 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2287 paramo
->key
= talloc_strdup(paramo
, data
->key
);
2288 paramo
->value
= talloc_strdup(paramo
, data
->value
);
2289 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
2296 * Check a service for consistency. Return False if the service is in any way
2297 * incomplete or faulty, else True.
2299 static bool lpcfg_service_ok(struct loadparm_service
*service
)
2304 if (service
->szService
[0] == '\0') {
2305 DEBUG(0, ("The following message indicates an internal error:\n"));
2306 DEBUG(0, ("No service name in service entry.\n"));
2310 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2311 /* I can't see why you'd want a non-printable printer service... */
2312 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
2313 if (!service
->bPrint_ok
) {
2314 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2315 service
->szService
));
2316 service
->bPrint_ok
= true;
2318 /* [printers] service must also be non-browsable. */
2319 if (service
->bBrowseable
)
2320 service
->bBrowseable
= false;
2323 /* If a service is flagged unavailable, log the fact at level 0. */
2324 if (!service
->bAvailable
)
2325 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2326 service
->szService
));
2332 /*******************************************************************
2333 Keep a linked list of all config files so we know when one has changed
2334 it's date and needs to be reloaded.
2335 ********************************************************************/
2337 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
2338 const char *fname
, const char *subfname
)
2340 struct file_lists
*f
= lp_ctx
->file_lists
;
2343 if (f
->name
&& !strcmp(f
->name
, fname
))
2349 f
= talloc(lp_ctx
, struct file_lists
);
2352 f
->next
= lp_ctx
->file_lists
;
2353 f
->name
= talloc_strdup(f
, fname
);
2358 f
->subfname
= talloc_strdup(f
, subfname
);
2363 lp_ctx
->file_lists
= f
;
2364 f
->modtime
= file_modtime(subfname
);
2366 time_t t
= file_modtime(subfname
);
2372 /*******************************************************************
2373 Check if a config file has changed date.
2374 ********************************************************************/
2375 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
2377 struct file_lists
*f
;
2378 DEBUG(6, ("lp_file_list_changed()\n"));
2380 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
2384 n2
= standard_sub_basic(lp_ctx
, f
->name
);
2386 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2387 f
->name
, n2
, ctime(&f
->modtime
)));
2389 mod_time
= file_modtime(n2
);
2391 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
2392 DEBUGADD(6, ("file %s modified: %s\n", n2
,
2394 f
->modtime
= mod_time
;
2395 talloc_free(f
->subfname
);
2396 f
->subfname
= talloc_strdup(f
, n2
);
2403 /***************************************************************************
2404 Handle the "realm" parameter
2405 ***************************************************************************/
2407 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
2408 const char *pszParmValue
, char **ptr
)
2410 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2412 talloc_free(lp_ctx
->globals
->szRealm_upper
);
2413 talloc_free(lp_ctx
->globals
->szRealm_lower
);
2415 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
2416 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
2421 /***************************************************************************
2422 Handle the include operation.
2423 ***************************************************************************/
2425 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
2426 const char *pszParmValue
, char **ptr
)
2428 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
2430 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
2432 lpcfg_string_set(lp_ctx
, ptr
, fname
);
2434 if (file_exist(fname
))
2435 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
2437 DEBUG(2, ("Can't find include file %s\n", fname
));
2442 /***************************************************************************
2443 Handle the interpretation of the copy parameter.
2444 ***************************************************************************/
2446 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
2447 const char *pszParmValue
, char **ptr
)
2450 struct loadparm_service
*serviceTemp
;
2452 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2456 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2458 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
2459 if (serviceTemp
== lp_ctx
->currentService
) {
2460 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2462 copy_service(lp_ctx
->currentService
,
2464 lp_ctx
->currentService
->copymap
);
2468 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2476 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
2477 const char *pszParmValue
, char **ptr
)
2480 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2481 if (lp_ctx
->global
) {
2482 return debug_parse_levels(pszParmValue
);
2487 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
2488 const char *pszParmValue
, char **ptr
)
2490 debug_set_logfile(pszParmValue
);
2491 if (lp_ctx
->global
) {
2492 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2497 /***************************************************************************
2498 Initialise a copymap.
2499 ***************************************************************************/
2501 static void init_copymap(struct loadparm_service
*pservice
)
2505 TALLOC_FREE(pservice
->copymap
);
2507 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2508 if (!pservice
->copymap
)
2510 ("Couldn't allocate copymap!! (size %d)\n",
2511 (int)NUMPARAMETERS
));
2513 for (i
= 0; i
< NUMPARAMETERS
; i
++)
2514 bitmap_set(pservice
->copymap
, i
);
2518 * Process a parametric option
2520 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
2521 struct loadparm_service
*service
,
2522 const char *pszParmName
,
2523 const char *pszParmValue
, int flags
)
2525 struct parmlist_entry
*paramo
, *data
;
2527 TALLOC_CTX
*mem_ctx
;
2529 while (isspace((unsigned char)*pszParmName
)) {
2533 name
= strlower_talloc(lp_ctx
, pszParmName
);
2534 if (!name
) return false;
2536 if (service
== NULL
) {
2537 data
= lp_ctx
->globals
->param_opt
;
2538 mem_ctx
= lp_ctx
->globals
;
2540 data
= service
->param_opt
;
2544 /* Traverse destination */
2545 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
2546 /* If we already have the option set, override it unless
2547 it was a command line option and the new one isn't */
2548 if (strcmp(paramo
->key
, name
) == 0) {
2549 if ((paramo
->priority
& FLAG_CMDLINE
) &&
2550 !(flags
& FLAG_CMDLINE
)) {
2555 talloc_free(paramo
->value
);
2556 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2557 paramo
->priority
= flags
;
2563 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
2566 paramo
->key
= talloc_strdup(paramo
, name
);
2567 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2568 paramo
->priority
= flags
;
2569 if (service
== NULL
) {
2570 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
2572 DLIST_ADD(service
->param_opt
, paramo
);
2580 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
2581 const char *pszParmName
, const char *pszParmValue
,
2582 struct loadparm_context
*lp_ctx
, bool on_globals
)
2585 /* if it is a special case then go ahead */
2586 if (parm_table
[parmnum
].special
) {
2588 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2593 goto mark_non_default
;
2596 /* now switch on the type of variable it is */
2597 switch (parm_table
[parmnum
].type
)
2601 if (!set_boolean(pszParmValue
, &b
)) {
2602 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2605 *(bool *)parm_ptr
= b
;
2611 if (!set_boolean(pszParmValue
, &b
)) {
2612 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2615 *(bool *)parm_ptr
= !b
;
2620 *(int *)parm_ptr
= atoi(pszParmValue
);
2624 *(char *)parm_ptr
= *pszParmValue
;
2628 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2634 if (conv_str_size_error(pszParmValue
, &val
)) {
2635 if (val
<= INT_MAX
) {
2636 *(int *)parm_ptr
= (int)val
;
2641 DEBUG(0,("lp_do_parameter(%s): value is not "
2642 "a valid size specifier!\n", pszParmValue
));
2647 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2648 pszParmValue
, NULL
);
2652 char **new_list
= str_list_make(mem_ctx
,
2653 pszParmValue
, NULL
);
2654 for (i
=0; new_list
[i
]; i
++) {
2655 if (new_list
[i
][0] == '+' && new_list
[i
][1]) {
2656 if (!str_list_check(*(const char ***)parm_ptr
,
2658 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2661 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2662 str_list_remove(*(const char ***)parm_ptr
,
2666 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2667 pszParmName
, pszParmValue
));
2670 *(const char ***)parm_ptr
= (const char **) new_list
;
2677 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2681 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2685 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2688 parm_table
[parmnum
].enum_list
[i
].name
)) {
2690 parm_table
[parmnum
].
2695 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2696 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2697 pszParmValue
, pszParmName
));
2707 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
2708 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
2709 /* we have to also unset FLAG_DEFAULT on aliases */
2710 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2711 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2713 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2714 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2721 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2722 const char *pszParmName
, const char *pszParmValue
)
2724 int parmnum
= map_parameter(pszParmName
);
2728 if (strchr(pszParmName
, ':')) {
2729 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
2731 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2735 /* if the flag has been set on the command line, then don't allow override,
2736 but don't report an error */
2737 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2741 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
2743 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
2744 pszParmName
, pszParmValue
, lp_ctx
, true);
2747 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
2748 struct loadparm_service
*service
,
2749 const char *pszParmName
, const char *pszParmValue
)
2753 int parmnum
= map_parameter(pszParmName
);
2756 if (strchr(pszParmName
, ':')) {
2757 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
2759 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2763 /* if the flag has been set on the command line, then don't allow override,
2764 but don't report an error */
2765 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2769 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2771 ("Global parameter %s found in service section!\n",
2775 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
2777 if (!service
->copymap
)
2778 init_copymap(service
);
2780 /* this handles the aliases - set the copymap for other
2781 * entries with the same data pointer */
2782 for (i
= 0; parm_table
[i
].label
; i
++)
2783 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
2784 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
2785 bitmap_clear(service
->copymap
, i
);
2787 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
2788 pszParmValue
, lp_ctx
, false);
2792 * Process a parameter.
2795 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
2798 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2800 if (lp_ctx
->bInGlobalSection
)
2801 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
2804 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
2805 pszParmName
, pszParmValue
);
2809 variable argument do parameter
2811 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
2812 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
2813 const char *pszParmName
, const char *fmt
, ...)
2820 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2822 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
2829 set a parameter from the commandline - this is called from command line parameter
2830 parsing code. It sets the parameter then marks the parameter as unable to be modified
2831 by smb.conf processing
2833 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
2834 const char *pszParmValue
)
2839 if (lp_ctx
->s3_fns
) {
2840 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
2843 parmnum
= map_parameter(pszParmName
);
2845 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
2848 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
2849 /* set a parametric option */
2850 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
2851 pszParmValue
, FLAG_CMDLINE
);
2855 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
2859 /* reset the CMDLINE flag in case this has been called before */
2860 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
2862 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
2866 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
2868 /* we have to also set FLAG_CMDLINE on aliases */
2869 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2870 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2872 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2873 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2880 set a option from the commandline in 'a=b' format. Use to support --option
2882 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
2887 s
= talloc_strdup(NULL
, option
);
2900 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
2906 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2909 * Print a parameter of the specified type.
2912 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2914 /* For the seperation of lists values that we print below */
2915 const char *list_sep
= ", ";
2920 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2921 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2923 p
->enum_list
[i
].name
);
2930 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
2934 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
2939 fprintf(f
, "%d", *(int *)ptr
);
2943 fprintf(f
, "%c", *(char *)ptr
);
2947 int val
= *(int *)ptr
;
2951 fprintf(f
, "0%o", val
);
2960 if ((char ***)ptr
&& *(char ***)ptr
) {
2961 char **list
= *(char ***)ptr
;
2962 for (; *list
; list
++) {
2963 /* surround strings with whitespace in double quotes */
2964 if (*(list
+1) == NULL
) {
2965 /* last item, no extra separator */
2968 if ( strchr_m( *list
, ' ' ) ) {
2969 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
2971 fprintf(f
, "%s%s", *list
, list_sep
);
2979 if (*(char **)ptr
) {
2980 fprintf(f
, "%s", *(char **)ptr
);
2989 * Check if two parameters are equal.
2992 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2997 return (*((bool *)ptr1
) == *((bool *)ptr2
));
3003 return (*((int *)ptr1
) == *((int *)ptr2
));
3006 return (*((char *)ptr1
) == *((char *)ptr2
));
3010 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
3015 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
3020 return (p1
== p2
|| strequal(p1
, p2
));
3029 * Process a new section (service).
3031 * At this stage all sections are services.
3032 * Later we'll have special sections that permit server parameters to be set.
3033 * Returns True on success, False on failure.
3036 static bool do_section(const char *pszSectionName
, void *userdata
)
3038 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
3040 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
3041 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
3044 /* if we've just struck a global section, note the fact. */
3045 lp_ctx
->bInGlobalSection
= isglobal
;
3047 /* check for multiple global sections */
3048 if (lp_ctx
->bInGlobalSection
) {
3049 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
3053 /* if we have a current service, tidy it up before moving on */
3056 if (lp_ctx
->currentService
!= NULL
)
3057 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3059 /* if all is still well, move to the next record in the services array */
3061 /* We put this here to avoid an odd message order if messages are */
3062 /* issued by the post-processing of a previous section. */
3063 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
3065 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
3068 DEBUG(0, ("Failed to add a new service\n"));
3078 * Determine if a particular base parameter is currently set to the default value.
3081 static bool is_default(struct loadparm_service
*sDefault
, int i
)
3083 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
3084 if (!defaults_saved
)
3086 switch (parm_table
[i
].type
) {
3089 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
3090 (const char **)def_ptr
);
3093 return strequal(parm_table
[i
].def
.svalue
,
3097 return parm_table
[i
].def
.bvalue
==
3104 return parm_table
[i
].def
.ivalue
==
3113 *Display the contents of the global structure.
3116 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
3120 struct parmlist_entry
*data
;
3122 fprintf(f
, "# Global parameters\n[global]\n");
3124 for (i
= 0; parm_table
[i
].label
; i
++)
3125 if (parm_table
[i
].p_class
== P_GLOBAL
&&
3126 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
3127 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
3129 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3130 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
3133 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3134 for (data
= lp_ctx
->globals
->param_opt
; data
;
3135 data
= data
->next
) {
3136 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
3139 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3146 * Display the contents of a single services record.
3149 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
3150 unsigned int *flags
)
3153 struct parmlist_entry
*data
;
3155 if (pService
!= sDefault
)
3156 fprintf(f
, "\n[%s]\n", pService
->szService
);
3158 for (i
= 0; parm_table
[i
].label
; i
++) {
3159 if (parm_table
[i
].p_class
== P_LOCAL
&&
3160 (*parm_table
[i
].label
!= '-') &&
3161 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3163 if (pService
== sDefault
) {
3164 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
3167 if (defaults_saved
) {
3168 if (is_default(sDefault
, i
)) {
3173 if (equal_parameter(parm_table
[i
].type
,
3174 ((char *)pService
) +
3175 parm_table
[i
].offset
,
3176 ((char *)sDefault
) +
3177 parm_table
[i
].offset
))
3181 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3182 print_parameter(&parm_table
[i
],
3183 ((char *)pService
) + parm_table
[i
].offset
, f
);
3187 if (pService
->param_opt
!= NULL
) {
3188 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
3189 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3194 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
3195 struct loadparm_service
*service
,
3196 const char *parm_name
, FILE * f
)
3198 struct parm_struct
*parm
;
3201 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3206 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3208 print_parameter(parm
, ptr
, f
);
3214 * Return info about the next parameter in a service.
3215 * snum==-1 gives the globals.
3216 * Return NULL when out of parameters.
3220 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
3224 /* do the globals */
3225 for (; parm_table
[*i
].label
; (*i
)++) {
3226 if ((*parm_table
[*i
].label
== '-'))
3230 && (parm_table
[*i
].offset
==
3231 parm_table
[(*i
) - 1].offset
)
3232 && (parm_table
[*i
].p_class
==
3233 parm_table
[(*i
) - 1].p_class
))
3236 return &parm_table
[(*i
)++];
3239 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
3241 for (; parm_table
[*i
].label
; (*i
)++) {
3242 if (parm_table
[*i
].p_class
== P_LOCAL
&&
3243 (*parm_table
[*i
].label
!= '-') &&
3245 (parm_table
[*i
].offset
!=
3246 parm_table
[(*i
) - 1].offset
)))
3248 if (allparameters
||
3249 !equal_parameter(parm_table
[*i
].type
,
3250 ((char *)pService
) +
3251 parm_table
[*i
].offset
,
3252 ((char *)lp_ctx
->sDefault
) +
3253 parm_table
[*i
].offset
))
3255 return &parm_table
[(*i
)++];
3266 * Auto-load some home services.
3268 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
3276 * Unload unused services.
3279 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
3280 struct smbsrv_connection
*smb
,
3281 bool (*snumused
) (struct smbsrv_connection
*, int))
3284 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3285 if (lp_ctx
->services
[i
] == NULL
)
3288 if (!snumused
|| !snumused(smb
, i
)) {
3289 talloc_free(lp_ctx
->services
[i
]);
3290 lp_ctx
->services
[i
] = NULL
;
3296 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
3298 struct parmlist_entry
*data
;
3300 if (lp_ctx
->refuse_free
) {
3301 /* someone is trying to free the
3302 global_loadparm_context.
3303 We can't allow that. */
3307 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3308 struct parmlist_entry
*next
;
3309 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3311 if (data
->priority
& FLAG_CMDLINE
) continue;
3312 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
3321 * Initialise the global parameter structure.
3323 * Note that most callers should use loadparm_init_global() instead
3325 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
3329 struct loadparm_context
*lp_ctx
;
3330 struct parmlist_entry
*parm
;
3333 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
3337 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
3338 lp_ctx
->bInGlobalSection
= true;
3339 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
3340 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
3342 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
3343 lp_ctx
->sDefault
->bAvailable
= true;
3344 lp_ctx
->sDefault
->bBrowseable
= true;
3345 lp_ctx
->sDefault
->bRead_only
= true;
3346 lp_ctx
->sDefault
->bMap_archive
= true;
3347 lp_ctx
->sDefault
->iStrictLocking
= true;
3348 lp_ctx
->sDefault
->bOpLocks
= true;
3349 lp_ctx
->sDefault
->iCreate_mask
= 0744;
3350 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
3351 lp_ctx
->sDefault
->iDir_mask
= 0755;
3352 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
3354 DEBUG(3, ("Initialising global parameters\n"));
3356 for (i
= 0; parm_table
[i
].label
; i
++) {
3357 if ((parm_table
[i
].type
== P_STRING
||
3358 parm_table
[i
].type
== P_USTRING
) &&
3359 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3361 if (parm_table
[i
].p_class
== P_LOCAL
) {
3362 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
3364 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
3366 *r
= talloc_strdup(lp_ctx
, "");
3370 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
3371 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
3372 talloc_free(logfile
);
3374 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
3376 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3378 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
3379 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
3380 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
3382 /* options that can be set on the command line must be initialised via
3383 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3385 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
3387 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
3388 myname
= get_myname(lp_ctx
);
3389 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
3390 talloc_free(myname
);
3391 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
3393 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
3395 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
3396 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
3398 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey dnsserver");
3399 lpcfg_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3400 lpcfg_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
3401 /* the winbind method for domain controllers is for both RODC
3402 auth forwarding and for trusted domains */
3403 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
3404 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3406 /* This hive should be dynamically generated by Samba using
3407 data from the sam, but for the moment leave it in a tdb to
3408 keep regedt32 from popping up an annoying dialog. */
3409 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
3411 /* using UTF8 by default allows us to support all chars */
3412 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
3414 /* Use codepage 850 as a default for the dos character set */
3415 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
3418 * Allow the default PASSWD_CHAT to be overridden in local.h.
3420 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
3422 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
3423 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
3424 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
3425 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
3426 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
3428 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
3429 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
3430 "Samba %s", SAMBA_VERSION_STRING
);
3432 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
3434 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
3435 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
3436 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
3438 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
3439 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
3440 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
3441 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
3442 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
3443 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
3444 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
3445 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
3446 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
3447 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
3448 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
3449 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
3450 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
3452 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
3453 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
3454 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
3455 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
3456 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
3457 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
3458 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
3459 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
3461 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
3463 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
3464 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
3466 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
3467 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
3469 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
3470 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
3471 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
3472 #if _SAMBA_BUILD_ >= 4
3473 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
3474 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
3475 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
3476 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
3477 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
3478 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
3480 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
3481 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3482 lpcfg_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
3484 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
3485 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
3487 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
3489 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
3491 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
3492 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
3493 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
3494 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
3495 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
3496 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
3497 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
3499 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
3501 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
3502 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
3504 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
3505 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
3506 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
3507 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
3508 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
3510 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
3511 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
3513 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "False");
3514 lpcfg_do_global_parameter(lp_ctx
, "dns recursive queries", "False");
3515 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
3517 for (i
= 0; parm_table
[i
].label
; i
++) {
3518 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3519 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3523 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3524 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3525 parm
->priority
|= FLAG_DEFAULT
;
3533 * Initialise the global parameter structure.
3535 struct loadparm_context
*loadparm_init_global(bool load_default
)
3537 if (global_loadparm_context
== NULL
) {
3538 global_loadparm_context
= loadparm_init(NULL
);
3540 if (global_loadparm_context
== NULL
) {
3543 global_loadparm_context
->global
= true;
3544 if (load_default
&& !global_loadparm_context
->loaded
) {
3545 lpcfg_load_default(global_loadparm_context
);
3547 global_loadparm_context
->refuse_free
= true;
3548 return global_loadparm_context
;
3552 * Initialise the global parameter structure.
3554 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3555 const struct loadparm_s3_context
*s3_fns
)
3557 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
3558 if (!loadparm_context
) {
3561 loadparm_context
->s3_fns
= s3_fns
;
3562 return loadparm_context
;
3565 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3567 return lp_ctx
->szConfigFile
;
3570 const char *lp_default_path(void)
3572 if (getenv("SMB_CONF_PATH"))
3573 return getenv("SMB_CONF_PATH");
3575 return dyn_CONFIGFILE
;
3579 * Update the internal state of a loadparm context after settings
3582 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3584 struct debug_settings settings
;
3585 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
3587 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
3588 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3591 if (!lp_ctx
->global
) {
3595 panic_action
= lp_ctx
->globals
->panic_action
;
3597 reload_charcnv(lp_ctx
);
3599 ZERO_STRUCT(settings
);
3600 /* Add any more debug-related smb.conf parameters created in
3602 settings
.timestamp_logs
= true;
3603 debug_set_settings(&settings
);
3605 /* FIXME: This is a bit of a hack, but we can't use a global, since
3606 * not everything that uses lp also uses the socket library */
3607 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3608 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3610 unsetenv("SOCKET_TESTNONBLOCK");
3616 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3620 path
= lp_default_path();
3622 if (!file_exist(path
)) {
3623 /* We allow the default smb.conf file to not exist,
3624 * basically the equivalent of an empty file. */
3625 return lpcfg_update(lp_ctx
);
3628 return lpcfg_load(lp_ctx
, path
);
3632 * Load the services array from the services file.
3634 * Return True on success, False on failure.
3636 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3641 filename
= talloc_strdup(lp_ctx
, filename
);
3643 lp_ctx
->szConfigFile
= filename
;
3645 if (lp_ctx
->s3_fns
) {
3646 return lp_ctx
->s3_fns
->load(filename
);
3649 lp_ctx
->bInGlobalSection
= true;
3650 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3651 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3653 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
3655 /* We get sections first, so have to start 'behind' to make up */
3656 lp_ctx
->currentService
= NULL
;
3657 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
3659 /* finish up the last section */
3660 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3662 if (lp_ctx
->currentService
!= NULL
)
3663 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3665 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3667 /* we do this unconditionally, so that it happens even
3668 for a missing smb.conf */
3669 reload_charcnv(lp_ctx
);
3671 if (bRetval
== true) {
3672 /* set this up so that any child python tasks will
3673 find the right smb.conf */
3674 setenv("SMB_CONF_PATH", filename
, 1);
3676 /* set the context used by the lp_*() function
3678 global_loadparm_context
= lp_ctx
;
3679 lp_ctx
->loaded
= true;
3686 * Return the max number of services.
3689 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3691 if (lp_ctx
->s3_fns
) {
3692 return lp_ctx
->s3_fns
->get_numservices();
3695 return lp_ctx
->iNumServices
;
3699 * Display the contents of the services array in human-readable form.
3702 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3707 if (lp_ctx
->s3_fns
) {
3708 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3712 defaults_saved
= !show_defaults
;
3714 dump_globals(lp_ctx
, f
, show_defaults
);
3716 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
3718 for (iService
= 0; iService
< maxtoprint
; iService
++)
3719 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3723 * Display the contents of one service in human-readable form.
3725 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3727 if (service
!= NULL
) {
3728 if (service
->szService
[0] == '\0')
3730 dump_a_service(service
, sDefault
, f
, NULL
);
3734 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3737 if (lp_ctx
->s3_fns
) {
3738 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3741 return lp_ctx
->services
[snum
];
3744 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3745 const char *service_name
)
3750 if (lp_ctx
->s3_fns
) {
3751 return lp_ctx
->s3_fns
->get_service(service_name
);
3754 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3755 if (lp_ctx
->services
[iService
] &&
3756 lp_ctx
->services
[iService
]->szService
) {
3758 * The substitution here is used to support %U is
3761 serviceName
= standard_sub_basic(
3762 lp_ctx
->services
[iService
],
3763 lp_ctx
->services
[iService
]->szService
);
3764 if (strequal(serviceName
, service_name
)) {
3765 talloc_free(serviceName
);
3766 return lp_ctx
->services
[iService
];
3768 talloc_free(serviceName
);
3772 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3776 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3778 return lp_string((const char *)service
->szService
);
3782 * A useful volume label function.
3784 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3787 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3788 service
->volume
: sDefault
->volume
));
3790 return lpcfg_servicename(service
);
3795 * If we are PDC then prefer us as DMB
3797 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3800 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
3801 service
->szPrintername
: sDefault
->szPrintername
));
3802 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3803 ret
= lpcfg_servicename(service
);
3810 * Return the max print jobs per queue.
3812 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3814 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
3815 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3816 maxjobs
= PRINT_MAX_JOBID
- 1;
3821 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3823 if (lp_ctx
== NULL
) {
3824 return get_iconv_handle();
3826 return lp_ctx
->iconv_handle
;
3829 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3831 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3832 if (!lp_ctx
->global
) {
3836 if (old_ic
== NULL
) {
3837 old_ic
= global_iconv_handle
;
3839 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3840 global_iconv_handle
= lp_ctx
->iconv_handle
;
3843 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3845 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
3848 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3850 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
3853 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3855 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
3858 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3860 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
3863 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3865 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
3868 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3870 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
3871 if (settings
== NULL
)
3873 SMB_ASSERT(lp_ctx
!= NULL
);
3874 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3875 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
3879 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
3881 if (lp_ctx
->s3_fns
) {
3882 return lp_ctx
->s3_fns
->server_role();
3885 return lp_find_server_role(lp_ctx
->globals
->server_role
,
3886 lp_ctx
->globals
->security
,
3887 lp_ctx
->globals
->domain_logons
,
3888 (lp_ctx
->globals
->domain_master
== true) ||
3889 (lp_ctx
->globals
->domain_master
== Auto
));
3892 int lpcfg_security(struct loadparm_context
*lp_ctx
)
3894 if (lp_ctx
->s3_fns
) {
3895 return lp_ctx
->s3_fns
->security();
3898 return lp_find_security(lp_ctx
->globals
->server_role
,
3899 lp_ctx
->globals
->security
);