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 "smb_server/smb_server.h"
62 #include "libcli/raw/signing.h"
63 #include "../lib/util/dlinklist.h"
64 #include "../lib/util/parmlist.h"
65 #include "param/param.h"
66 #include "param/loadparm.h"
67 #include "libcli/raw/libcliraw.h"
68 #include "rpc_server/common/common.h"
69 #include "lib/socket/socket.h"
70 #include "auth/gensec/gensec.h"
73 #define standard_sub_basic talloc_strdup
75 static bool do_parameter(const char *, const char *, void *);
76 static bool defaults_saved
= false;
79 * This structure describes global (ie., server-wide) parameters.
81 struct loadparm_global
83 enum server_role server_role
;
85 const char **smb_ports
;
89 char *display_charset
;
97 char *szWINS_CONFIG_URL
;
100 const char **szPasswordServers
;
101 char *szSocketOptions
;
105 const char **szWINSservers
;
106 const char **szInterfaces
;
107 char *szSocketAddress
;
108 char *szAnnounceVersion
; /* This is initialised in init_globals */
111 const char **szNetbiosAliases
;
112 char *szNetbiosScope
;
113 char *szDomainOtherSIDs
;
114 const char **szNameResolveOrder
;
115 const char **dcerpc_ep_servers
;
116 const char **server_services
;
117 char *ntptr_providor
;
118 char *szWinbindSeparator
;
119 char *szWinbinddPrivilegedSocketDirectory
;
120 char *szWinbinddSocketDirectory
;
121 char *szTemplateShell
;
122 char *szTemplateHomedir
;
123 int bWinbindSealedPipes
;
124 int bIdmapTrustedOnly
;
143 int paranoid_server_security
;
146 int announce_as
; /* This is initialised in init_globals */
153 char *socket_options
;
158 int bPreferredMaster
;
159 int bEncryptPasswords
;
161 int bObeyPamRestrictions
;
166 int bBindInterfacesOnly
;
168 int bNTStatusSupport
;
174 int bClientPlaintextAuth
;
175 int bClientLanManAuth
;
176 int bClientNTLMv2Auth
;
177 int client_use_spnego_principal
;
183 char *szNTPSignDSocketDirectory
;
184 const char **szRNDCCommand
;
185 const char **szDNSUpdateCommand
;
186 const char **szSPNUpdateCommand
;
187 const char **szNSUpdateCommand
;
188 struct parmlist_entry
*param_opt
;
193 * This structure describes a single service.
195 struct loadparm_service
207 char **ntvfs_handler
;
221 int iCreate_force_mode
;
228 struct parmlist_entry
*param_opt
;
230 char dummy
[3]; /* for alignment */
234 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
237 /* prototypes for the special type handlers */
238 static bool handle_include(struct loadparm_context
*lp_ctx
,
239 const char *pszParmValue
, char **ptr
);
240 static bool handle_realm(struct loadparm_context
*lp_ctx
,
241 const char *pszParmValue
, char **ptr
);
242 static bool handle_copy(struct loadparm_context
*lp_ctx
,
243 const char *pszParmValue
, char **ptr
);
244 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
245 const char *pszParmValue
, char **ptr
);
246 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
247 const char *pszParmValue
, char **ptr
);
249 static const struct enum_list enum_protocol
[] = {
250 {PROTOCOL_SMB2
, "SMB2"},
251 {PROTOCOL_NT1
, "NT1"},
252 {PROTOCOL_LANMAN2
, "LANMAN2"},
253 {PROTOCOL_LANMAN1
, "LANMAN1"},
254 {PROTOCOL_CORE
, "CORE"},
255 {PROTOCOL_COREPLUS
, "COREPLUS"},
256 {PROTOCOL_COREPLUS
, "CORE+"},
260 static const struct enum_list enum_security
[] = {
261 {SEC_SHARE
, "SHARE"},
267 static const struct enum_list enum_announce_as
[] = {
268 {ANNOUNCE_AS_NT_SERVER
, "NT"},
269 {ANNOUNCE_AS_NT_SERVER
, "NT Server"},
270 {ANNOUNCE_AS_NT_WORKSTATION
, "NT Workstation"},
271 {ANNOUNCE_AS_WIN95
, "win95"},
272 {ANNOUNCE_AS_WFW
, "WfW"},
276 static const struct enum_list enum_bool_auto
[] = {
287 /* Client-side offline caching policy types */
290 CSC_POLICY_DOCUMENTS
=1,
291 CSC_POLICY_PROGRAMS
=2,
295 static const struct enum_list enum_csc_policy
[] = {
296 {CSC_POLICY_MANUAL
, "manual"},
297 {CSC_POLICY_DOCUMENTS
, "documents"},
298 {CSC_POLICY_PROGRAMS
, "programs"},
299 {CSC_POLICY_DISABLE
, "disable"},
303 /* SMB signing types. */
304 static const struct enum_list enum_smb_signing_vals
[] = {
305 {SMB_SIGNING_OFF
, "No"},
306 {SMB_SIGNING_OFF
, "False"},
307 {SMB_SIGNING_OFF
, "0"},
308 {SMB_SIGNING_OFF
, "Off"},
309 {SMB_SIGNING_OFF
, "disabled"},
310 {SMB_SIGNING_SUPPORTED
, "Yes"},
311 {SMB_SIGNING_SUPPORTED
, "True"},
312 {SMB_SIGNING_SUPPORTED
, "1"},
313 {SMB_SIGNING_SUPPORTED
, "On"},
314 {SMB_SIGNING_SUPPORTED
, "enabled"},
315 {SMB_SIGNING_REQUIRED
, "required"},
316 {SMB_SIGNING_REQUIRED
, "mandatory"},
317 {SMB_SIGNING_REQUIRED
, "force"},
318 {SMB_SIGNING_REQUIRED
, "forced"},
319 {SMB_SIGNING_REQUIRED
, "enforced"},
320 {SMB_SIGNING_AUTO
, "auto"},
324 static const struct enum_list enum_server_role
[] = {
325 {ROLE_STANDALONE
, "standalone"},
326 {ROLE_DOMAIN_MEMBER
, "member server"},
327 {ROLE_DOMAIN_MEMBER
, "member"},
328 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
329 {ROLE_DOMAIN_CONTROLLER
, "dc"},
333 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
334 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
336 static struct parm_struct parm_table
[] = {
337 {"server role", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_role
), NULL
, enum_server_role
},
338 {"dos charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(dos_charset
), NULL
, NULL
},
339 {"unix charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(unix_charset
), NULL
, NULL
},
340 {"ncalrpc dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ncalrpc_dir
), NULL
, NULL
},
341 {"display charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(display_charset
), NULL
, NULL
},
342 {"comment", P_STRING
, P_LOCAL
, LOCAL_VAR(comment
), NULL
, NULL
},
343 {"path", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
344 {"directory", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
345 {"workgroup", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szWorkgroup
), NULL
, NULL
},
346 {"realm", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szRealm
), handle_realm
, NULL
},
347 {"netbios name", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosName
), NULL
, NULL
},
348 {"netbios aliases", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNetbiosAliases
), NULL
, NULL
},
349 {"netbios scope", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosScope
), NULL
, NULL
},
350 {"server string", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szServerString
), NULL
, NULL
},
351 {"interfaces", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szInterfaces
), NULL
, NULL
},
352 {"bind interfaces only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bBindInterfacesOnly
), NULL
, NULL
},
353 {"ntvfs handler", P_LIST
, P_LOCAL
, LOCAL_VAR(ntvfs_handler
), NULL
, NULL
},
354 {"ntptr providor", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ntptr_providor
), NULL
, NULL
},
355 {"dcerpc endpoint servers", P_LIST
, P_GLOBAL
, GLOBAL_VAR(dcerpc_ep_servers
), NULL
, NULL
},
356 {"server services", P_LIST
, P_GLOBAL
, GLOBAL_VAR(server_services
), NULL
, NULL
},
358 {"security", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(security
), NULL
, enum_security
},
359 {"encrypt passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bEncryptPasswords
), NULL
, NULL
},
360 {"null passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNullPasswords
), NULL
, NULL
},
361 {"obey pam restrictions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bObeyPamRestrictions
), NULL
, NULL
},
362 {"password server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szPasswordServers
), NULL
, NULL
},
363 {"spoolss database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSPOOLSS_URL
), NULL
, NULL
},
364 {"wins config database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_CONFIG_URL
), NULL
, NULL
},
365 {"wins database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_URL
), NULL
, NULL
},
366 {"private dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPrivateDir
), NULL
, NULL
},
367 {"passwd chat", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPasswdChat
), NULL
, NULL
},
368 {"password level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(pwordlevel
), NULL
, NULL
},
369 {"lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLanmanAuth
), NULL
, NULL
},
370 {"ntlm auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTLMAuth
), NULL
, NULL
},
371 {"client NTLMv2 auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientNTLMv2Auth
), NULL
, NULL
},
372 {"client lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientLanManAuth
), NULL
, NULL
},
373 {"client plaintext auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientPlaintextAuth
), NULL
, NULL
},
374 {"client use spnego principal", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(client_use_spnego_principal
), NULL
, NULL
},
376 {"read only", P_BOOL
, P_LOCAL
, LOCAL_VAR(bRead_only
), NULL
, NULL
},
378 {"create mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_mask
), NULL
, NULL
},
379 {"force create mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_force_mode
), NULL
, NULL
},
380 {"directory mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_mask
), NULL
, NULL
},
381 {"force directory mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_force_mode
), NULL
, NULL
},
383 {"hosts allow", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsallow
), NULL
, NULL
},
384 {"hosts deny", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsdeny
), NULL
, NULL
},
386 {"log level", P_STRING
, P_GLOBAL
, GLOBAL_VAR(loglevel
), handle_debuglevel
, NULL
},
387 {"debuglevel", P_STRING
, P_GLOBAL
, GLOBAL_VAR(loglevel
), handle_debuglevel
, NULL
},
388 {"log file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(logfile
), handle_logfile
, NULL
},
390 {"smb ports", P_LIST
, P_GLOBAL
, GLOBAL_VAR(smb_ports
), NULL
, NULL
},
391 {"nbt port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(nbt_port
), NULL
, NULL
},
392 {"dgram port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(dgram_port
), NULL
, NULL
},
393 {"cldap port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(cldap_port
), NULL
, NULL
},
394 {"krb5 port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(krb5_port
), NULL
, NULL
},
395 {"kpasswd port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(kpasswd_port
), NULL
, NULL
},
396 {"web port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(web_port
), NULL
, NULL
},
397 {"tls enabled", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(tls_enabled
), NULL
, NULL
},
398 {"tls keyfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_keyfile
), NULL
, NULL
},
399 {"tls certfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_certfile
), NULL
, NULL
},
400 {"tls cafile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_cafile
), NULL
, NULL
},
401 {"tls crlfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_crlfile
), NULL
, NULL
},
402 {"tls dh params file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_dhpfile
), NULL
, NULL
},
403 {"large readwrite", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLargeReadwrite
), NULL
, NULL
},
404 {"server max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_maxprotocol
), NULL
, enum_protocol
},
405 {"server min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_minprotocol
), NULL
, enum_protocol
},
406 {"client max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_maxprotocol
), NULL
, enum_protocol
},
407 {"client min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_minprotocol
), NULL
, enum_protocol
},
408 {"unicode", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnicode
), NULL
, NULL
},
409 {"read raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bReadRaw
), NULL
, NULL
},
410 {"write raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWriteRaw
), NULL
, NULL
},
411 {"disable netbios", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bDisableNetbios
), NULL
, NULL
},
413 {"nt status support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTStatusSupport
), NULL
, NULL
},
415 {"announce version", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAnnounceVersion
), NULL
, NULL
},
416 {"announce as", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(announce_as
), NULL
, enum_announce_as
},
417 {"max mux", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_mux
), NULL
, NULL
},
418 {"max xmit", P_BYTES
, P_GLOBAL
, GLOBAL_VAR(max_xmit
), NULL
, NULL
},
420 {"name resolve order", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNameResolveOrder
), NULL
, NULL
},
421 {"max wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_wins_ttl
), NULL
, NULL
},
422 {"min wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(min_wins_ttl
), NULL
, NULL
},
423 {"time server", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bTimeServer
), NULL
, NULL
},
424 {"unix extensions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnixExtensions
), NULL
, NULL
},
425 {"use spnego", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUseSpnego
), NULL
, NULL
},
426 {"server signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_signing
), NULL
, enum_smb_signing_vals
},
427 {"client signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(client_signing
), NULL
, enum_smb_signing_vals
},
428 {"rpc big endian", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bRpcBigEndian
), NULL
, NULL
},
430 {"max connections", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxConnections
), NULL
, NULL
},
431 {"paranoid server security", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(paranoid_server_security
), NULL
, NULL
},
432 {"socket options", P_STRING
, P_GLOBAL
, GLOBAL_VAR(socket_options
), NULL
, NULL
},
434 {"strict sync", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictSync
), NULL
, NULL
},
435 {"case insensitive filesystem", P_BOOL
, P_LOCAL
, LOCAL_VAR(bCIFileSystem
), NULL
, NULL
},
437 {"max print jobs", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxPrintJobs
), NULL
, NULL
},
438 {"printable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
439 {"print ok", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
441 {"printer name", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
442 {"printer", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
444 {"map system", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_system
), NULL
, NULL
},
445 {"map hidden", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_hidden
), NULL
, NULL
},
446 {"map archive", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_archive
), NULL
, NULL
},
448 {"preferred master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
449 {"prefered master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
450 {"local master", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLocalMaster
), NULL
, NULL
},
451 {"browseable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
452 {"browsable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
454 {"wins server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szWINSservers
), NULL
, NULL
},
455 {"wins support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSsupport
), NULL
, NULL
},
456 {"dns proxy", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSdnsProxy
), NULL
, NULL
},
457 {"wins hook", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINSHook
), NULL
, NULL
},
459 {"csc policy", P_ENUM
, P_LOCAL
, LOCAL_VAR(iCSCPolicy
), NULL
, enum_csc_policy
},
461 {"strict locking", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictLocking
), NULL
, NULL
},
462 {"oplocks", P_BOOL
, P_LOCAL
, LOCAL_VAR(bOplocks
), NULL
, NULL
},
464 {"share backend", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szShareBackend
), NULL
, NULL
},
465 {"preload", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
466 {"auto services", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
467 {"lock dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
468 {"lock directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
469 {"pid directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPidDir
), NULL
, NULL
},
471 {"socket address", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSocketAddress
), NULL
, NULL
},
472 {"copy", P_STRING
, P_LOCAL
, LOCAL_VAR(szCopy
), handle_copy
, NULL
},
473 {"include", P_STRING
, P_LOCAL
, LOCAL_VAR(szInclude
), handle_include
, NULL
},
475 {"available", P_BOOL
, P_LOCAL
, LOCAL_VAR(bAvailable
), NULL
, NULL
},
476 {"volume", P_STRING
, P_LOCAL
, LOCAL_VAR(volume
), NULL
, NULL
},
477 {"fstype", P_STRING
, P_LOCAL
, LOCAL_VAR(fstype
), NULL
, NULL
},
479 {"panic action", P_STRING
, P_GLOBAL
, GLOBAL_VAR(panic_action
), NULL
, NULL
},
481 {"msdfs root", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMSDfsRoot
), NULL
, NULL
},
482 {"host msdfs", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bHostMSDfs
), NULL
, NULL
},
483 {"winbind separator", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbindSeparator
), NULL
, NULL
},
484 {"winbindd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddSocketDirectory
), NULL
, NULL
},
485 {"winbindd privileged socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
), NULL
, NULL
},
486 {"winbind sealed pipes", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWinbindSealedPipes
), NULL
, NULL
},
487 {"template shell", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateShell
), NULL
, NULL
},
488 {"template homedir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateHomedir
), NULL
, NULL
},
489 {"idmap trusted only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bIdmapTrustedOnly
), NULL
, NULL
},
491 {"ntp signd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szNTPSignDSocketDirectory
), NULL
, NULL
},
492 {"rndc command", P_CMDLIST
, P_GLOBAL
, GLOBAL_VAR(szRNDCCommand
), NULL
, NULL
},
493 {"dns update command", P_CMDLIST
, P_GLOBAL
, GLOBAL_VAR(szDNSUpdateCommand
), NULL
, NULL
},
494 {"spn update command", P_CMDLIST
, P_GLOBAL
, GLOBAL_VAR(szSPNUpdateCommand
), NULL
, NULL
},
495 {"nsupdate command", P_CMDLIST
, P_GLOBAL
, GLOBAL_VAR(szNSUpdateCommand
), NULL
, NULL
},
497 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
}
501 /* local variables */
502 struct loadparm_context
{
503 const char *szConfigFile
;
504 struct loadparm_global
*globals
;
505 struct loadparm_service
**services
;
506 struct loadparm_service
*sDefault
;
507 struct smb_iconv_handle
*iconv_handle
;
509 struct loadparm_service
*currentService
;
510 bool bInGlobalSection
;
512 struct file_lists
*next
;
517 unsigned int flags
[NUMPARAMETERS
];
520 bool global
; /* Is this the global context, which may set
521 * global variables such as debug level etc? */
522 struct loadparm_s3_context
*s3_fns
;
526 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
528 return lp_ctx
->sDefault
;
532 return the parameter table
534 struct parm_struct
*lpcfg_parm_table(void)
540 * Convenience routine to grab string parameters into temporary memory
541 * and run standard_sub_basic on them.
543 * The buffers can be written to by
544 * callers without affecting the source string.
547 static const char *lp_string(const char *s
)
549 #if 0 /* until REWRITE done to make thread-safe */
550 size_t len
= s
? strlen(s
) : 0;
554 /* The follow debug is useful for tracking down memory problems
555 especially if you have an inner loop that is calling a lp_*()
556 function that returns a string. Perhaps this debug should be
557 present all the time? */
560 DEBUG(10, ("lp_string(%s)\n", s
));
563 #if 0 /* until REWRITE done to make thread-safe */
565 lp_talloc
= talloc_init("lp_talloc");
567 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
575 strlcpy(ret
, s
, len
);
577 if (trim_string(ret
, "\"", "\"")) {
578 if (strchr(ret
,'"') != NULL
)
579 strlcpy(ret
, s
, len
);
582 standard_sub_basic(ret
,len
+100);
589 In this section all the functions that are used to access the
590 parameters from the rest of the program are defined
594 * the creation of separate lpcfg_*() and lp_*() functions is to allow
595 * for code compatibility between existing Samba4 and Samba3 code.
598 /* this global context supports the lp_*() function varients */
599 static struct loadparm_context
*global_loadparm_context
;
601 #define lpcfg_default_service global_loadparm_context->sDefault
602 #define lpcfg_global_service(i) global_loadparm_context->services[i]
604 #define FN_GLOBAL_STRING(fn_name,var_name) \
605 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
606 if (lp_ctx == NULL) return NULL; \
607 if (lp_ctx->s3_fns) { \
608 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
609 return lp_ctx->s3_fns->fn_name(); \
611 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
614 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
615 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
616 if (lp_ctx == NULL) return NULL; \
617 if (lp_ctx->s3_fns) { \
618 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
619 return lp_ctx->s3_fns->fn_name(); \
621 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
624 #define FN_GLOBAL_LIST(fn_name,var_name) \
625 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
626 if (lp_ctx == NULL) return NULL; \
627 if (lp_ctx->s3_fns) { \
628 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
629 return lp_ctx->s3_fns->fn_name(); \
631 return lp_ctx->globals->var_name; \
634 #define FN_GLOBAL_BOOL(fn_name,var_name) \
635 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
636 if (lp_ctx == NULL) return false; \
637 if (lp_ctx->s3_fns) { \
638 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
639 return lp_ctx->s3_fns->fn_name(); \
641 return lp_ctx->globals->var_name; \
644 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
645 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
646 if (lp_ctx->s3_fns) { \
647 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
648 return lp_ctx->s3_fns->fn_name(); \
650 return lp_ctx->globals->var_name; \
653 #define FN_LOCAL_STRING(fn_name,val) \
654 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
655 struct loadparm_service *sDefault) { \
656 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
659 #define FN_LOCAL_LIST(fn_name,val) \
660 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
661 struct loadparm_service *sDefault) {\
662 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
665 #define FN_LOCAL_BOOL(fn_name,val) \
666 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
667 struct loadparm_service *sDefault) { \
668 return((service != NULL)? service->val : sDefault->val); \
671 #define FN_LOCAL_INTEGER(fn_name,val) \
672 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
673 struct loadparm_service *sDefault) { \
674 return((service != NULL)? service->val : sDefault->val); \
677 FN_GLOBAL_INTEGER(server_role
, server_role
)
678 FN_GLOBAL_LIST(smb_ports
, smb_ports
)
679 FN_GLOBAL_INTEGER(nbt_port
, nbt_port
)
680 FN_GLOBAL_INTEGER(dgram_port
, dgram_port
)
681 FN_GLOBAL_INTEGER(cldap_port
, cldap_port
)
682 FN_GLOBAL_INTEGER(krb5_port
, krb5_port
)
683 FN_GLOBAL_INTEGER(kpasswd_port
, kpasswd_port
)
684 FN_GLOBAL_INTEGER(web_port
, web_port
)
685 FN_GLOBAL_BOOL(tls_enabled
, tls_enabled
)
686 FN_GLOBAL_STRING(logfile
, logfile
)
687 FN_GLOBAL_STRING(share_backend
, szShareBackend
)
688 FN_GLOBAL_STRING(spoolss_url
, szSPOOLSS_URL
)
689 FN_GLOBAL_STRING(wins_config_url
, szWINS_CONFIG_URL
)
690 FN_GLOBAL_STRING(wins_url
, szWINS_URL
)
691 FN_GLOBAL_CONST_STRING(winbind_separator
, szWinbindSeparator
)
692 FN_GLOBAL_CONST_STRING(winbindd_socket_directory
, szWinbinddSocketDirectory
)
693 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
694 FN_GLOBAL_CONST_STRING(template_shell
, szTemplateShell
)
695 FN_GLOBAL_CONST_STRING(template_homedir
, szTemplateHomedir
)
696 FN_GLOBAL_BOOL(winbind_sealed_pipes
, bWinbindSealedPipes
)
697 FN_GLOBAL_BOOL(idmap_trusted_only
, bIdmapTrustedOnly
)
698 FN_GLOBAL_STRING(private_dir
, szPrivateDir
)
699 FN_GLOBAL_STRING(serverstring
, szServerString
)
700 FN_GLOBAL_STRING(lockdir
, szLockDir
)
701 FN_GLOBAL_STRING(ncalrpc_dir
, ncalrpc_dir
)
702 FN_GLOBAL_STRING(dos_charset
, dos_charset
)
703 FN_GLOBAL_STRING(unix_charset
, unix_charset
)
704 FN_GLOBAL_STRING(display_charset
, display_charset
)
705 FN_GLOBAL_STRING(piddir
, szPidDir
)
706 FN_GLOBAL_LIST(rndc_command
, szRNDCCommand
)
707 FN_GLOBAL_LIST(dns_update_command
, szDNSUpdateCommand
)
708 FN_GLOBAL_LIST(spn_update_command
, szSPNUpdateCommand
)
709 FN_GLOBAL_LIST(nsupdate_command
, szNSUpdateCommand
)
710 FN_GLOBAL_LIST(dcerpc_endpoint_servers
, dcerpc_ep_servers
)
711 FN_GLOBAL_LIST(server_services
, server_services
)
712 FN_GLOBAL_STRING(ntptr_providor
, ntptr_providor
)
713 FN_GLOBAL_STRING(auto_services
, szAutoServices
)
714 FN_GLOBAL_STRING(passwd_chat
, szPasswdChat
)
715 FN_GLOBAL_LIST(passwordserver
, szPasswordServers
)
716 FN_GLOBAL_LIST(name_resolve_order
, szNameResolveOrder
)
717 FN_GLOBAL_STRING(realm
, szRealm_upper
)
718 FN_GLOBAL_STRING(dnsdomain
, szRealm_lower
)
719 FN_GLOBAL_STRING(socket_options
, socket_options
)
720 FN_GLOBAL_STRING(workgroup
, szWorkgroup
)
721 FN_GLOBAL_STRING(netbios_name
, szNetbiosName
)
722 FN_GLOBAL_STRING(netbios_scope
, szNetbiosScope
)
723 FN_GLOBAL_LIST(wins_server_list
, szWINSservers
)
724 FN_GLOBAL_LIST(interfaces
, szInterfaces
)
725 FN_GLOBAL_STRING(socket_address
, szSocketAddress
)
726 FN_GLOBAL_LIST(netbios_aliases
, szNetbiosAliases
)
727 FN_GLOBAL_BOOL(disable_netbios
, bDisableNetbios
)
728 FN_GLOBAL_BOOL(wins_support
, bWINSsupport
)
729 FN_GLOBAL_BOOL(wins_dns_proxy
, bWINSdnsProxy
)
730 FN_GLOBAL_STRING(wins_hook
, szWINSHook
)
731 FN_GLOBAL_BOOL(local_master
, bLocalMaster
)
732 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
733 FN_GLOBAL_BOOL(large_readwrite
, bLargeReadwrite
)
734 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
735 FN_GLOBAL_BOOL(null_passwords
, bNullPasswords
)
736 FN_GLOBAL_BOOL(obey_pam_restrictions
, bObeyPamRestrictions
)
737 FN_GLOBAL_BOOL(encrypted_passwords
, bEncryptPasswords
)
738 FN_GLOBAL_BOOL(time_server
, bTimeServer
)
739 FN_GLOBAL_BOOL(bind_interfaces_only
, bBindInterfacesOnly
)
740 FN_GLOBAL_BOOL(unicode
, bUnicode
)
741 FN_GLOBAL_BOOL(nt_status_support
, bNTStatusSupport
)
742 FN_GLOBAL_BOOL(lanman_auth
, bLanmanAuth
)
743 FN_GLOBAL_BOOL(ntlm_auth
, bNTLMAuth
)
744 FN_GLOBAL_BOOL(client_plaintext_auth
, bClientPlaintextAuth
)
745 FN_GLOBAL_BOOL(client_lanman_auth
, bClientLanManAuth
)
746 FN_GLOBAL_BOOL(client_ntlmv2_auth
, bClientNTLMv2Auth
)
747 FN_GLOBAL_BOOL(client_use_spnego_principal
, client_use_spnego_principal
)
748 FN_GLOBAL_BOOL(host_msdfs
, bHostMSDfs
)
749 FN_GLOBAL_BOOL(unix_extensions
, bUnixExtensions
)
750 FN_GLOBAL_BOOL(use_spnego
, bUseSpnego
)
751 FN_GLOBAL_BOOL(rpc_big_endian
, bRpcBigEndian
)
752 FN_GLOBAL_INTEGER(max_wins_ttl
, max_wins_ttl
)
753 FN_GLOBAL_INTEGER(min_wins_ttl
, min_wins_ttl
)
754 FN_GLOBAL_INTEGER(maxmux
, max_mux
)
755 FN_GLOBAL_INTEGER(max_xmit
, max_xmit
)
756 FN_GLOBAL_INTEGER(passwordlevel
, pwordlevel
)
757 FN_GLOBAL_INTEGER(srv_maxprotocol
, srv_maxprotocol
)
758 FN_GLOBAL_INTEGER(srv_minprotocol
, srv_minprotocol
)
759 FN_GLOBAL_INTEGER(cli_maxprotocol
, cli_maxprotocol
)
760 FN_GLOBAL_INTEGER(cli_minprotocol
, cli_minprotocol
)
761 FN_GLOBAL_INTEGER(security
, security
)
762 FN_GLOBAL_BOOL(paranoid_server_security
, paranoid_server_security
)
763 FN_GLOBAL_INTEGER(announce_as
, announce_as
)
765 FN_LOCAL_STRING(pathname
, szPath
)
766 FN_LOCAL_LIST(hostsallow
, szHostsallow
)
767 FN_LOCAL_LIST(hostsdeny
, szHostsdeny
)
768 FN_LOCAL_STRING(comment
, comment
)
769 FN_LOCAL_STRING(fstype
, fstype
)
770 FN_LOCAL_LIST(ntvfs_handler
, ntvfs_handler
)
771 FN_LOCAL_BOOL(msdfs_root
, bMSDfsRoot
)
772 FN_LOCAL_BOOL(browseable
, bBrowseable
)
773 FN_LOCAL_BOOL(readonly
, bRead_only
)
774 FN_LOCAL_BOOL(print_ok
, bPrint_ok
)
775 FN_LOCAL_BOOL(map_hidden
, bMap_hidden
)
776 FN_LOCAL_BOOL(map_archive
, bMap_archive
)
777 FN_LOCAL_BOOL(strict_locking
, bStrictLocking
)
778 FN_LOCAL_BOOL(oplocks
, bOplocks
)
779 FN_LOCAL_BOOL(strict_sync
, bStrictSync
)
780 FN_LOCAL_BOOL(ci_filesystem
, bCIFileSystem
)
781 FN_LOCAL_BOOL(map_system
, bMap_system
)
782 FN_LOCAL_INTEGER(max_connections
, iMaxConnections
)
783 FN_LOCAL_INTEGER(csc_policy
, iCSCPolicy
)
784 FN_LOCAL_INTEGER(create_mask
, iCreate_mask
)
785 FN_LOCAL_INTEGER(force_create_mode
, iCreate_force_mode
)
786 FN_LOCAL_INTEGER(dir_mask
, iDir_mask
)
787 FN_LOCAL_INTEGER(force_dir_mode
, iDir_force_mode
)
788 FN_GLOBAL_INTEGER(server_signing
, server_signing
)
789 FN_GLOBAL_INTEGER(client_signing
, client_signing
)
791 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
793 /* local prototypes */
794 static int map_parameter(const char *pszParmName
);
795 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
796 const char *pszServiceName
);
797 static void copy_service(struct loadparm_service
*pserviceDest
,
798 struct loadparm_service
*pserviceSource
,
800 static bool service_ok(struct loadparm_service
*service
);
801 static bool do_section(const char *pszSectionName
, void *);
802 static void init_copymap(struct loadparm_service
*pservice
);
804 /* This is a helper function for parametrical options support. */
805 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
806 /* Actual parametrical functions are quite simple */
807 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
808 struct loadparm_service
*service
,
809 const char *type
, const char *option
)
811 char *vfskey_tmp
= NULL
;
813 struct parmlist_entry
*data
;
818 if (lp_ctx
->s3_fns
) {
819 SMB_ASSERT(service
== NULL
);
820 return lp_ctx
->s3_fns
->get_parametric(type
, option
);
823 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
825 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
826 if (vfskey_tmp
== NULL
) return NULL
;
827 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
828 talloc_free(vfskey_tmp
);
831 if (strcmp(data
->key
, vfskey
) == 0) {
838 if (service
!= NULL
) {
839 /* Try to fetch the same option but from globals */
840 /* but only if we are not already working with globals */
841 for (data
= lp_ctx
->globals
->param_opt
; data
;
843 if (strcmp(data
->key
, vfskey
) == 0) {
857 * convenience routine to return int parameters.
859 static int lp_int(const char *s
)
863 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
867 return strtol(s
, NULL
, 0);
871 * convenience routine to return unsigned long parameters.
873 static int lp_ulong(const char *s
)
877 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
881 return strtoul(s
, NULL
, 0);
885 * convenience routine to return unsigned long parameters.
887 static double lp_double(const char *s
)
891 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
895 return strtod(s
, NULL
);
899 * convenience routine to return boolean parameters.
901 static bool lp_bool(const char *s
)
906 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
910 if (!set_boolean(s
, &ret
)) {
911 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
920 * Return parametric option from a given service. Type is a part of option before ':'
921 * Parametric option has following syntax: 'Type: option = value'
922 * Returned value is allocated in 'lp_talloc' context
925 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
926 struct loadparm_service
*service
, const char *type
,
929 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
932 return lp_string(value
);
938 * Return parametric option from a given service. Type is a part of option before ':'
939 * Parametric option has following syntax: 'Type: option = value'
940 * Returned value is allocated in 'lp_talloc' context
943 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
944 struct loadparm_context
*lp_ctx
,
945 struct loadparm_service
*service
,
947 const char *option
, const char *separator
)
949 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
952 return (const char **)str_list_make(mem_ctx
, value
, separator
);
958 * Return parametric option from a given service. Type is a part of option before ':'
959 * Parametric option has following syntax: 'Type: option = value'
962 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
963 struct loadparm_service
*service
, const char *type
,
964 const char *option
, int default_v
)
966 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
969 return lp_int(value
);
975 * Return parametric option from a given service. Type is a part of
977 * Parametric option has following syntax: 'Type: option = value'.
980 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
981 struct loadparm_service
*service
, const char *type
,
982 const char *option
, int default_v
)
986 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
988 if (value
&& conv_str_size_error(value
, &bval
)) {
989 if (bval
<= INT_MAX
) {
998 * Return parametric option from a given service.
999 * Type is a part of option before ':'
1000 * Parametric option has following syntax: 'Type: option = value'
1002 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
1003 struct loadparm_service
*service
, const char *type
,
1004 const char *option
, unsigned long default_v
)
1006 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1009 return lp_ulong(value
);
1015 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
1016 struct loadparm_service
*service
, const char *type
,
1017 const char *option
, double default_v
)
1019 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1022 return lp_double(value
);
1028 * Return parametric option from a given service. Type is a part of option before ':'
1029 * Parametric option has following syntax: 'Type: option = value'
1032 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
1033 struct loadparm_service
*service
, const char *type
,
1034 const char *option
, bool default_v
)
1036 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1039 return lp_bool(value
);
1046 * Initialise a service to the defaults.
1049 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1051 struct loadparm_service
*pservice
=
1052 talloc_zero(mem_ctx
, struct loadparm_service
);
1053 copy_service(pservice
, sDefault
, NULL
);
1058 * Set a string value, deallocating any existing space, and allocing the space
1061 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1068 *dest
= talloc_strdup(mem_ctx
, src
);
1069 if ((*dest
) == NULL
) {
1070 DEBUG(0,("Out of memory in string_set\n"));
1078 * Set a string value, deallocating any existing space, and allocing the space
1081 static bool string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1088 *dest
= strupper_talloc(mem_ctx
, src
);
1089 if ((*dest
) == NULL
) {
1090 DEBUG(0,("Out of memory in string_set_upper\n"));
1100 * Add a new service to the services array initialising it with the given
1104 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
1105 const struct loadparm_service
*pservice
,
1109 struct loadparm_service tservice
;
1110 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1111 struct parmlist_entry
*data
, *pdata
;
1113 if (pservice
== NULL
) {
1114 pservice
= lp_ctx
->sDefault
;
1117 tservice
= *pservice
;
1119 /* it might already exist */
1121 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1123 if (service
!= NULL
) {
1124 /* Clean all parametric options for service */
1125 /* They will be added during parsing again */
1126 data
= service
->param_opt
;
1132 service
->param_opt
= NULL
;
1137 /* find an invalid one */
1138 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1139 if (lp_ctx
->services
[i
] == NULL
)
1142 /* if not, then create one */
1143 if (i
== lp_ctx
->iNumServices
) {
1144 struct loadparm_service
**tsp
;
1146 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1149 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1152 lp_ctx
->services
= tsp
;
1153 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1156 lp_ctx
->iNumServices
++;
1159 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1160 if (lp_ctx
->services
[i
] == NULL
) {
1161 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1164 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1166 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1167 return lp_ctx
->services
[i
];
1171 * Add a new home service, with the specified home directory, defaults coming
1172 * from service ifrom.
1175 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
1176 const char *pszHomename
,
1177 struct loadparm_service
*default_service
,
1178 const char *user
, const char *pszHomedir
)
1180 struct loadparm_service
*service
;
1182 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
1184 if (service
== NULL
)
1187 if (!(*(default_service
->szPath
))
1188 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1189 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1191 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1194 if (!(*(service
->comment
))) {
1195 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1197 service
->bAvailable
= default_service
->bAvailable
;
1198 service
->bBrowseable
= default_service
->bBrowseable
;
1200 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1201 pszHomename
, user
, service
->szPath
));
1207 * Add a new printer service, with defaults coming from service iFrom.
1210 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
1211 const char *pszPrintername
,
1212 struct loadparm_service
*default_service
)
1214 const char *comment
= "From Printcap";
1215 struct loadparm_service
*service
;
1216 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
1218 if (service
== NULL
)
1221 /* note that we do NOT default the availability flag to True - */
1222 /* we take it from the default service passed. This allows all */
1223 /* dynamic printers to be disabled by disabling the [printers] */
1224 /* entry (if/when the 'available' keyword is implemented!). */
1226 /* the printer name is set to the service name. */
1227 string_set(service
, &service
->szPrintername
, pszPrintername
);
1228 string_set(service
, &service
->comment
, comment
);
1229 service
->bBrowseable
= default_service
->bBrowseable
;
1230 /* Printers cannot be read_only. */
1231 service
->bRead_only
= false;
1232 /* Printer services must be printable. */
1233 service
->bPrint_ok
= true;
1235 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1241 * Map a parameter's string representation to something we can use.
1242 * Returns False if the parameter string is not recognised, else TRUE.
1245 static int map_parameter(const char *pszParmName
)
1249 if (*pszParmName
== '-')
1252 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1253 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1256 /* Warn only if it isn't parametric option */
1257 if (strchr(pszParmName
, ':') == NULL
)
1258 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
1259 /* We do return 'fail' for parametric options as well because they are
1260 stored in different storage
1267 return the parameter structure for a parameter
1269 struct parm_struct
*lpcfg_parm_struct(const char *name
)
1271 int parmnum
= map_parameter(name
);
1272 if (parmnum
== -1) return NULL
;
1273 return &parm_table
[parmnum
];
1277 return the parameter pointer for a parameter
1279 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
1280 struct loadparm_service
*service
, struct parm_struct
*parm
)
1282 if (service
== NULL
) {
1283 if (parm
->pclass
== P_LOCAL
)
1284 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
1285 else if (parm
->pclass
== P_GLOBAL
)
1286 return ((char *)lp_ctx
->globals
)+parm
->offset
;
1289 return ((char *)service
) + parm
->offset
;
1294 * Find a service by name. Otherwise works like get_service.
1297 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1298 const char *pszServiceName
)
1302 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
1303 if (lp_ctx
->services
[iService
] != NULL
&&
1304 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
1305 return lp_ctx
->services
[iService
];
1312 * Copy a service structure to another.
1313 * If pcopymapDest is NULL then copy all fields
1316 static void copy_service(struct loadparm_service
*pserviceDest
,
1317 struct loadparm_service
*pserviceSource
,
1321 bool bcopyall
= (pcopymapDest
== NULL
);
1322 struct parmlist_entry
*data
, *pdata
, *paramo
;
1325 for (i
= 0; parm_table
[i
].label
; i
++)
1326 if (parm_table
[i
].offset
!= -1 && parm_table
[i
].pclass
== P_LOCAL
&&
1327 (bcopyall
|| pcopymapDest
[i
])) {
1329 ((char *)pserviceSource
) + parm_table
[i
].offset
;
1331 ((char *)pserviceDest
) + parm_table
[i
].offset
;
1333 switch (parm_table
[i
].type
) {
1335 *(int *)dest_ptr
= *(int *)src_ptr
;
1341 *(int *)dest_ptr
= *(int *)src_ptr
;
1345 string_set(pserviceDest
,
1351 string_set_upper(pserviceDest
,
1356 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
1357 *(const char ***)src_ptr
);
1365 init_copymap(pserviceDest
);
1366 if (pserviceSource
->copymap
)
1367 memcpy((void *)pserviceDest
->copymap
,
1368 (void *)pserviceSource
->copymap
,
1369 sizeof(int) * NUMPARAMETERS
);
1372 data
= pserviceSource
->param_opt
;
1375 pdata
= pserviceDest
->param_opt
;
1376 /* Traverse destination */
1378 /* If we already have same option, override it */
1379 if (strcmp(pdata
->key
, data
->key
) == 0) {
1380 talloc_free(pdata
->value
);
1381 pdata
->value
= talloc_reference(pdata
,
1386 pdata
= pdata
->next
;
1389 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
1392 paramo
->key
= talloc_reference(paramo
, data
->key
);
1393 paramo
->value
= talloc_reference(paramo
, data
->value
);
1394 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1401 * Check a service for consistency. Return False if the service is in any way
1402 * incomplete or faulty, else True.
1404 static bool service_ok(struct loadparm_service
*service
)
1409 if (service
->szService
[0] == '\0') {
1410 DEBUG(0, ("The following message indicates an internal error:\n"));
1411 DEBUG(0, ("No service name in service entry.\n"));
1415 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1416 /* I can't see why you'd want a non-printable printer service... */
1417 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1418 if (!service
->bPrint_ok
) {
1419 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1420 service
->szService
));
1421 service
->bPrint_ok
= true;
1423 /* [printers] service must also be non-browsable. */
1424 if (service
->bBrowseable
)
1425 service
->bBrowseable
= false;
1428 /* If a service is flagged unavailable, log the fact at level 0. */
1429 if (!service
->bAvailable
)
1430 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1431 service
->szService
));
1437 /*******************************************************************
1438 Keep a linked list of all config files so we know when one has changed
1439 it's date and needs to be reloaded.
1440 ********************************************************************/
1442 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1443 const char *fname
, const char *subfname
)
1445 struct file_lists
*f
= lp_ctx
->file_lists
;
1448 if (f
->name
&& !strcmp(f
->name
, fname
))
1454 f
= talloc(lp_ctx
, struct file_lists
);
1457 f
->next
= lp_ctx
->file_lists
;
1458 f
->name
= talloc_strdup(f
, fname
);
1463 f
->subfname
= talloc_strdup(f
, subfname
);
1468 lp_ctx
->file_lists
= f
;
1469 f
->modtime
= file_modtime(subfname
);
1471 time_t t
= file_modtime(subfname
);
1477 /*******************************************************************
1478 Check if a config file has changed date.
1479 ********************************************************************/
1480 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1482 struct file_lists
*f
;
1483 DEBUG(6, ("lp_file_list_changed()\n"));
1485 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1489 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1491 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1492 f
->name
, n2
, ctime(&f
->modtime
)));
1494 mod_time
= file_modtime(n2
);
1496 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1497 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1499 f
->modtime
= mod_time
;
1500 talloc_free(f
->subfname
);
1501 f
->subfname
= talloc_strdup(f
, n2
);
1508 /***************************************************************************
1509 Handle the "realm" parameter
1510 ***************************************************************************/
1512 static bool handle_realm(struct loadparm_context
*lp_ctx
,
1513 const char *pszParmValue
, char **ptr
)
1515 string_set(lp_ctx
, ptr
, pszParmValue
);
1517 talloc_free(lp_ctx
->globals
->szRealm_upper
);
1518 talloc_free(lp_ctx
->globals
->szRealm_lower
);
1520 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1521 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1526 /***************************************************************************
1527 Handle the include operation.
1528 ***************************************************************************/
1530 static bool handle_include(struct loadparm_context
*lp_ctx
,
1531 const char *pszParmValue
, char **ptr
)
1533 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1535 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1537 string_set(lp_ctx
, ptr
, fname
);
1539 if (file_exist(fname
))
1540 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1542 DEBUG(2, ("Can't find include file %s\n", fname
));
1547 /***************************************************************************
1548 Handle the interpretation of the copy parameter.
1549 ***************************************************************************/
1551 static bool handle_copy(struct loadparm_context
*lp_ctx
,
1552 const char *pszParmValue
, char **ptr
)
1555 struct loadparm_service
*serviceTemp
;
1557 string_set(lp_ctx
, ptr
, pszParmValue
);
1561 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1563 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1564 if (serviceTemp
== lp_ctx
->currentService
) {
1565 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1567 copy_service(lp_ctx
->currentService
,
1569 lp_ctx
->currentService
->copymap
);
1573 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1581 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
1582 const char *pszParmValue
, char **ptr
)
1585 string_set(lp_ctx
, ptr
, pszParmValue
);
1586 if (lp_ctx
->global
) {
1587 return debug_parse_levels(pszParmValue
);
1592 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
1593 const char *pszParmValue
, char **ptr
)
1595 debug_set_logfile(pszParmValue
);
1596 if (lp_ctx
->global
) {
1597 string_set(lp_ctx
, ptr
, pszParmValue
);
1602 /***************************************************************************
1603 Initialise a copymap.
1604 ***************************************************************************/
1606 static void init_copymap(struct loadparm_service
*pservice
)
1609 talloc_free(pservice
->copymap
);
1610 pservice
->copymap
= talloc_array(pservice
, int, NUMPARAMETERS
);
1611 if (pservice
->copymap
== NULL
) {
1613 ("Couldn't allocate copymap!! (size %d)\n",
1614 (int)NUMPARAMETERS
));
1617 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1618 pservice
->copymap
[i
] = true;
1622 * Process a parametric option
1624 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1625 struct loadparm_service
*service
,
1626 const char *pszParmName
,
1627 const char *pszParmValue
, int flags
)
1629 struct parmlist_entry
*paramo
, *data
;
1631 TALLOC_CTX
*mem_ctx
;
1633 while (isspace((unsigned char)*pszParmName
)) {
1637 name
= strlower_talloc(lp_ctx
, pszParmName
);
1638 if (!name
) return false;
1640 if (service
== NULL
) {
1641 data
= lp_ctx
->globals
->param_opt
;
1642 mem_ctx
= lp_ctx
->globals
;
1644 data
= service
->param_opt
;
1648 /* Traverse destination */
1649 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1650 /* If we already have the option set, override it unless
1651 it was a command line option and the new one isn't */
1652 if (strcmp(paramo
->key
, name
) == 0) {
1653 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1654 !(flags
& FLAG_CMDLINE
)) {
1659 talloc_free(paramo
->value
);
1660 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1661 paramo
->priority
= flags
;
1667 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
1670 paramo
->key
= talloc_strdup(paramo
, name
);
1671 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1672 paramo
->priority
= flags
;
1673 if (service
== NULL
) {
1674 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1676 DLIST_ADD(service
->param_opt
, paramo
);
1684 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1685 const char *pszParmName
, const char *pszParmValue
,
1686 struct loadparm_context
*lp_ctx
, bool on_globals
)
1689 /* if it is a special case then go ahead */
1690 if (parm_table
[parmnum
].special
) {
1692 ret
= parm_table
[parmnum
].special(lp_ctx
, pszParmValue
,
1697 goto mark_non_default
;
1700 /* now switch on the type of variable it is */
1701 switch (parm_table
[parmnum
].type
)
1705 if (!set_boolean(pszParmValue
, &b
)) {
1706 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1709 *(int *)parm_ptr
= b
;
1714 *(int *)parm_ptr
= atoi(pszParmValue
);
1718 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1724 if (conv_str_size_error(pszParmValue
, &val
)) {
1725 if (val
<= INT_MAX
) {
1726 *(int *)parm_ptr
= (int)val
;
1731 DEBUG(0,("lp_do_parameter(%s): value is not "
1732 "a valid size specifier!\n", pszParmValue
));
1737 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1738 pszParmValue
, NULL
);
1742 char **new_list
= str_list_make(mem_ctx
,
1743 pszParmValue
, NULL
);
1744 for (i
=0; new_list
[i
]; i
++) {
1745 if (new_list
[i
][0] == '+' && new_list
[i
][1] &&
1746 (!str_list_check(*(const char ***)parm_ptr
,
1747 &new_list
[i
][1]))) {
1748 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1750 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
1751 #if 0 /* This is commented out because we sometimes parse the list
1752 * twice, and so we can't assert on this */
1753 if (!str_list_check(*(const char ***)parm_ptr
,
1755 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
1756 pszParmName
, pszParmValue
, new_list
[i
],
1757 str_list_join_shell(mem_ctx
, *(const char ***)parm_ptr
, ' ')));
1762 str_list_remove(*(const char ***)parm_ptr
,
1766 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1767 pszParmName
, pszParmValue
));
1770 *(const char ***)parm_ptr
= (const char **) new_list
;
1777 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1781 string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1785 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1788 parm_table
[parmnum
].enum_list
[i
].name
)) {
1790 parm_table
[parmnum
].
1795 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1796 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1797 pszParmValue
, pszParmName
));
1804 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1805 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1806 /* we have to also unset FLAG_DEFAULT on aliases */
1807 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1808 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1810 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1811 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1818 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1819 const char *pszParmName
, const char *pszParmValue
)
1821 int parmnum
= map_parameter(pszParmName
);
1825 if (strchr(pszParmName
, ':')) {
1826 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1828 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1832 /* if the flag has been set on the command line, then don't allow override,
1833 but don't report an error */
1834 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1838 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1840 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1841 pszParmName
, pszParmValue
, lp_ctx
, true);
1844 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1845 struct loadparm_service
*service
,
1846 const char *pszParmName
, const char *pszParmValue
)
1850 int parmnum
= map_parameter(pszParmName
);
1853 if (strchr(pszParmName
, ':')) {
1854 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1856 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1860 /* if the flag has been set on the command line, then don't allow override,
1861 but don't report an error */
1862 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1866 if (parm_table
[parmnum
].pclass
== P_GLOBAL
) {
1868 ("Global parameter %s found in service section!\n",
1872 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1874 if (!service
->copymap
)
1875 init_copymap(service
);
1877 /* this handles the aliases - set the copymap for other
1878 * entries with the same data pointer */
1879 for (i
= 0; parm_table
[i
].label
; i
++)
1880 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1881 parm_table
[i
].pclass
== parm_table
[parmnum
].pclass
)
1882 service
->copymap
[i
] = false;
1884 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1885 pszParmValue
, lp_ctx
, false);
1889 * Process a parameter.
1892 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1895 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1897 if (lp_ctx
->bInGlobalSection
)
1898 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1901 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1902 pszParmName
, pszParmValue
);
1906 variable argument do parameter
1908 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1909 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1910 const char *pszParmName
, const char *fmt
, ...)
1917 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1919 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1926 set a parameter from the commandline - this is called from command line parameter
1927 parsing code. It sets the parameter then marks the parameter as unable to be modified
1928 by smb.conf processing
1930 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1931 const char *pszParmValue
)
1933 int parmnum
= map_parameter(pszParmName
);
1936 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1939 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1940 /* set a parametric option */
1941 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1942 pszParmValue
, FLAG_CMDLINE
);
1946 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1950 /* reset the CMDLINE flag in case this has been called before */
1951 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1953 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1957 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1959 /* we have to also set FLAG_CMDLINE on aliases */
1960 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1961 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1963 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1964 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1971 set a option from the commandline in 'a=b' format. Use to support --option
1973 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1991 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1997 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2000 * Print a parameter of the specified type.
2003 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2006 const char *list_sep
= ", "; /* For the seperation of lists values that we print below */
2010 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2011 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2013 p
->enum_list
[i
].name
);
2020 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
2025 fprintf(f
, "%d", *(int *)ptr
);
2029 fprintf(f
, "0%o", *(int *)ptr
);
2036 if ((char ***)ptr
&& *(char ***)ptr
) {
2037 char **list
= *(char ***)ptr
;
2039 for (; *list
; list
++) {
2040 if (*(list
+1) == NULL
) {
2041 /* last item, print no extra seperator after */
2044 fprintf(f
, "%s%s", *list
, list_sep
);
2051 if (*(char **)ptr
) {
2052 fprintf(f
, "%s", *(char **)ptr
);
2059 * Check if two parameters are equal.
2062 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2066 return (*((int *)ptr1
) == *((int *)ptr2
));
2072 return (*((int *)ptr1
) == *((int *)ptr2
));
2076 return str_list_equal((const char **)(*(char ***)ptr1
),
2077 (const char **)(*(char ***)ptr2
));
2082 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2087 return (p1
== p2
|| strequal(p1
, p2
));
2094 * Process a new section (service).
2096 * At this stage all sections are services.
2097 * Later we'll have special sections that permit server parameters to be set.
2098 * Returns True on success, False on failure.
2101 static bool do_section(const char *pszSectionName
, void *userdata
)
2103 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2105 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2106 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2109 /* if we've just struck a global section, note the fact. */
2110 lp_ctx
->bInGlobalSection
= isglobal
;
2112 /* check for multiple global sections */
2113 if (lp_ctx
->bInGlobalSection
) {
2114 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2118 /* if we have a current service, tidy it up before moving on */
2121 if (lp_ctx
->currentService
!= NULL
)
2122 bRetval
= service_ok(lp_ctx
->currentService
);
2124 /* if all is still well, move to the next record in the services array */
2126 /* We put this here to avoid an odd message order if messages are */
2127 /* issued by the post-processing of a previous section. */
2128 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2130 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2133 DEBUG(0, ("Failed to add a new service\n"));
2143 * Determine if a particular base parameter is currently set to the default value.
2146 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2148 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2149 if (!defaults_saved
)
2151 switch (parm_table
[i
].type
) {
2154 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2155 (const char **)def_ptr
);
2158 return strequal(parm_table
[i
].def
.svalue
,
2161 return parm_table
[i
].def
.bvalue
==
2167 return parm_table
[i
].def
.ivalue
==
2174 *Display the contents of the global structure.
2177 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2181 struct parmlist_entry
*data
;
2183 fprintf(f
, "# Global parameters\n[global]\n");
2185 for (i
= 0; parm_table
[i
].label
; i
++)
2186 if (parm_table
[i
].pclass
== P_GLOBAL
&&
2187 parm_table
[i
].offset
!= -1 &&
2188 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2189 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2191 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2192 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2195 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2196 for (data
= lp_ctx
->globals
->param_opt
; data
;
2197 data
= data
->next
) {
2198 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2201 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2208 * Display the contents of a single services record.
2211 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
2212 unsigned int *flags
)
2215 struct parmlist_entry
*data
;
2217 if (pService
!= sDefault
)
2218 fprintf(f
, "\n[%s]\n", pService
->szService
);
2220 for (i
= 0; parm_table
[i
].label
; i
++) {
2221 if (parm_table
[i
].pclass
== P_LOCAL
&&
2222 parm_table
[i
].offset
!= -1 &&
2223 (*parm_table
[i
].label
!= '-') &&
2224 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
2226 if (pService
== sDefault
) {
2227 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
2230 if (defaults_saved
) {
2231 if (is_default(sDefault
, i
)) {
2236 if (equal_parameter(parm_table
[i
].type
,
2237 ((char *)pService
) +
2238 parm_table
[i
].offset
,
2239 ((char *)sDefault
) +
2240 parm_table
[i
].offset
))
2244 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2245 print_parameter(&parm_table
[i
],
2246 ((char *)pService
) + parm_table
[i
].offset
, f
);
2250 if (pService
->param_opt
!= NULL
) {
2251 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2252 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2257 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2258 struct loadparm_service
*service
,
2259 const char *parm_name
, FILE * f
)
2261 struct parm_struct
*parm
;
2264 parm
= lpcfg_parm_struct(parm_name
);
2269 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
2271 print_parameter(parm
, ptr
, f
);
2277 * Return info about the next parameter in a service.
2278 * snum==-1 gives the globals.
2279 * Return NULL when out of parameters.
2283 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
2287 /* do the globals */
2288 for (; parm_table
[*i
].label
; (*i
)++) {
2289 if (parm_table
[*i
].offset
== -1
2290 || (*parm_table
[*i
].label
== '-'))
2294 && (parm_table
[*i
].offset
==
2295 parm_table
[(*i
) - 1].offset
))
2298 return &parm_table
[(*i
)++];
2301 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
2303 for (; parm_table
[*i
].label
; (*i
)++) {
2304 if (parm_table
[*i
].pclass
== P_LOCAL
&&
2305 parm_table
[*i
].offset
!= -1 &&
2306 (*parm_table
[*i
].label
!= '-') &&
2308 (parm_table
[*i
].offset
!=
2309 parm_table
[(*i
) - 1].offset
)))
2311 if (allparameters
||
2312 !equal_parameter(parm_table
[*i
].type
,
2313 ((char *)pService
) +
2314 parm_table
[*i
].offset
,
2315 ((char *)lp_ctx
->sDefault
) +
2316 parm_table
[*i
].offset
))
2318 return &parm_table
[(*i
)++];
2329 * Auto-load some home services.
2331 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
2339 * Unload unused services.
2342 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
2343 struct smbsrv_connection
*smb
,
2344 bool (*snumused
) (struct smbsrv_connection
*, int))
2347 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2348 if (lp_ctx
->services
[i
] == NULL
)
2351 if (!snumused
|| !snumused(smb
, i
)) {
2352 talloc_free(lp_ctx
->services
[i
]);
2353 lp_ctx
->services
[i
] = NULL
;
2359 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2361 struct parmlist_entry
*data
;
2363 if (lp_ctx
->refuse_free
) {
2364 /* someone is trying to free the
2365 global_loadparm_context.
2366 We can't allow that. */
2370 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2371 struct parmlist_entry
*next
;
2372 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2374 if (data
->priority
& FLAG_CMDLINE
) continue;
2375 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2384 * Initialise the global parameter structure.
2386 * Note that most callers should use loadparm_init_global() instead
2388 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2392 struct loadparm_context
*lp_ctx
;
2393 struct parmlist_entry
*parm
;
2396 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2400 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2401 lp_ctx
->bInGlobalSection
= true;
2402 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2403 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2405 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2406 lp_ctx
->sDefault
->bAvailable
= true;
2407 lp_ctx
->sDefault
->bBrowseable
= true;
2408 lp_ctx
->sDefault
->bRead_only
= true;
2409 lp_ctx
->sDefault
->bMap_archive
= true;
2410 lp_ctx
->sDefault
->bStrictLocking
= true;
2411 lp_ctx
->sDefault
->bOplocks
= true;
2412 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2413 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2414 lp_ctx
->sDefault
->iDir_mask
= 0755;
2415 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2417 DEBUG(3, ("Initialising global parameters\n"));
2419 for (i
= 0; parm_table
[i
].label
; i
++) {
2420 if ((parm_table
[i
].type
== P_STRING
||
2421 parm_table
[i
].type
== P_USTRING
) &&
2422 parm_table
[i
].offset
!= -1 &&
2423 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2425 if (parm_table
[i
].pclass
== P_LOCAL
) {
2426 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2428 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2430 *r
= talloc_strdup(lp_ctx
, "");
2434 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2435 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2436 talloc_free(logfile
);
2438 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2440 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2442 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2444 lpcfg_do_global_parameter(lp_ctx
, "server role", "standalone");
2446 /* options that can be set on the command line must be initialised via
2447 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2449 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2451 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2452 myname
= get_myname(lp_ctx
);
2453 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2454 talloc_free(myname
);
2455 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2457 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2459 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2460 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
2462 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
2463 lpcfg_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate web");
2464 lpcfg_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
2465 /* the winbind method for domain controllers is for both RODC
2466 auth forwarding and for trusted domains */
2467 lpcfg_do_global_parameter(lp_ctx
, "auth methods:domain controller", "anonymous sam_ignoredomain winbind");
2468 lpcfg_do_global_parameter(lp_ctx
, "auth methods:member server", "anonymous sam winbind");
2469 lpcfg_do_global_parameter(lp_ctx
, "auth methods:standalone", "anonymous sam_ignoredomain");
2470 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2471 lpcfg_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
2472 lpcfg_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
2473 lpcfg_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
2474 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2476 /* This hive should be dynamically generated by Samba using
2477 data from the sam, but for the moment leave it in a tdb to
2478 keep regedt32 from popping up an annoying dialog. */
2479 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2481 /* using UTF8 by default allows us to support all chars */
2482 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2484 /* Use codepage 850 as a default for the dos character set */
2485 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2488 * Allow the default PASSWD_CHAT to be overridden in local.h.
2490 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2492 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2493 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2494 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2496 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
2497 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2498 "Samba %s", SAMBA_VERSION_STRING
);
2500 lpcfg_do_global_parameter_var(lp_ctx
, "announce version", "%d.%d",
2501 DEFAULT_MAJOR_VERSION
,
2502 DEFAULT_MINOR_VERSION
);
2504 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2506 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2507 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
2508 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
2509 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2510 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2511 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2512 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2513 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2514 lpcfg_do_global_parameter(lp_ctx
, "security", "USER");
2515 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
2516 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2517 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2518 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2519 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2520 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2521 lpcfg_do_global_parameter(lp_ctx
, "announce as", "NT SERVER");
2523 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2524 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2525 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2526 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2527 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2528 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2529 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2530 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2532 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2534 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2535 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2537 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2538 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2540 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2541 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2542 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2543 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2544 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2545 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2546 lpcfg_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
2548 lpcfg_do_global_parameter(lp_ctx
, "client signing", "Yes");
2549 lpcfg_do_global_parameter(lp_ctx
, "server signing", "auto");
2551 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2553 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2554 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2555 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2556 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2557 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2558 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2559 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2561 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2563 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2564 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2566 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2567 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2568 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2569 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2570 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2572 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2573 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2574 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2575 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2576 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2578 for (i
= 0; parm_table
[i
].label
; i
++) {
2579 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2580 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2584 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2585 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2586 parm
->priority
|= FLAG_DEFAULT
;
2594 * Initialise the global parameter structure.
2596 struct loadparm_context
*loadparm_init_global(bool load_default
)
2598 if (global_loadparm_context
== NULL
) {
2599 global_loadparm_context
= loadparm_init(NULL
);
2601 if (global_loadparm_context
== NULL
) {
2604 global_loadparm_context
->global
= true;
2605 if (load_default
&& !global_loadparm_context
->loaded
) {
2606 lpcfg_load_default(global_loadparm_context
);
2608 global_loadparm_context
->refuse_free
= true;
2609 return global_loadparm_context
;
2613 * Initialise the global parameter structure.
2615 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2616 struct loadparm_s3_context
*s3_fns
)
2618 struct loadparm_context
*loadparm_context
= loadparm_init(mem_ctx
);
2619 if (!loadparm_context
) {
2622 loadparm_context
->s3_fns
= s3_fns
;
2623 return loadparm_context
;
2626 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2628 return lp_ctx
->szConfigFile
;
2631 const char *lp_default_path(void)
2633 if (getenv("SMB_CONF_PATH"))
2634 return getenv("SMB_CONF_PATH");
2636 return dyn_CONFIGFILE
;
2640 * Update the internal state of a loadparm context after settings
2643 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2645 struct debug_settings settings
;
2646 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
2648 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2649 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2652 if (!lp_ctx
->global
) {
2656 panic_action
= lp_ctx
->globals
->panic_action
;
2658 reload_charcnv(lp_ctx
);
2660 ZERO_STRUCT(settings
);
2661 /* Add any more debug-related smb.conf parameters created in
2663 settings
.timestamp_logs
= true;
2664 debug_set_settings(&settings
);
2666 /* FIXME: This is a bit of a hack, but we can't use a global, since
2667 * not everything that uses lp also uses the socket library */
2668 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2669 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2671 unsetenv("SOCKET_TESTNONBLOCK");
2674 /* FIXME: Check locale in environment for this: */
2675 if (strcmp(lpcfg_display_charset(lp_ctx
), lpcfg_unix_charset(lp_ctx
)) != 0)
2676 d_set_iconv(smb_iconv_open(lpcfg_display_charset(lp_ctx
), lpcfg_unix_charset(lp_ctx
)));
2678 d_set_iconv((smb_iconv_t
)-1);
2683 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2687 path
= lp_default_path();
2689 if (!file_exist(path
)) {
2690 /* We allow the default smb.conf file to not exist,
2691 * basically the equivalent of an empty file. */
2692 return lpcfg_update(lp_ctx
);
2695 return lpcfg_load(lp_ctx
, path
);
2699 * Load the services array from the services file.
2701 * Return True on success, False on failure.
2703 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2708 filename
= talloc_strdup(lp_ctx
, filename
);
2710 lp_ctx
->szConfigFile
= filename
;
2712 lp_ctx
->bInGlobalSection
= true;
2713 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2714 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2716 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2718 /* We get sections first, so have to start 'behind' to make up */
2719 lp_ctx
->currentService
= NULL
;
2720 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2722 /* finish up the last section */
2723 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2725 if (lp_ctx
->currentService
!= NULL
)
2726 bRetval
= service_ok(lp_ctx
->currentService
);
2728 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2730 /* we do this unconditionally, so that it happens even
2731 for a missing smb.conf */
2732 reload_charcnv(lp_ctx
);
2734 if (bRetval
== true) {
2735 /* set this up so that any child python tasks will
2736 find the right smb.conf */
2737 setenv("SMB_CONF_PATH", filename
, 1);
2739 /* set the context used by the lp_*() function
2741 global_loadparm_context
= lp_ctx
;
2742 lp_ctx
->loaded
= true;
2749 * Return the max number of services.
2752 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2754 return lp_ctx
->iNumServices
;
2758 * Display the contents of the services array in human-readable form.
2761 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2766 defaults_saved
= !show_defaults
;
2768 dump_globals(lp_ctx
, f
, show_defaults
);
2770 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
2772 for (iService
= 0; iService
< maxtoprint
; iService
++)
2773 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2777 * Display the contents of one service in human-readable form.
2779 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2781 if (service
!= NULL
) {
2782 if (service
->szService
[0] == '\0')
2784 dump_a_service(service
, sDefault
, f
, NULL
);
2788 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2791 return lp_ctx
->services
[snum
];
2794 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2795 const char *service_name
)
2800 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2801 if (lp_ctx
->services
[iService
] &&
2802 lp_ctx
->services
[iService
]->szService
) {
2804 * The substitution here is used to support %U is
2807 serviceName
= standard_sub_basic(
2808 lp_ctx
->services
[iService
],
2809 lp_ctx
->services
[iService
]->szService
);
2810 if (strequal(serviceName
, service_name
)) {
2811 talloc_free(serviceName
);
2812 return lp_ctx
->services
[iService
];
2814 talloc_free(serviceName
);
2818 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2822 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2824 return lp_string((const char *)service
->szService
);
2828 * A useful volume label function.
2830 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2833 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2834 service
->volume
: sDefault
->volume
));
2836 return lpcfg_servicename(service
);
2841 * If we are PDC then prefer us as DMB
2843 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2846 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
2847 service
->szPrintername
: sDefault
->szPrintername
));
2848 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2849 ret
= lpcfg_servicename(service
);
2856 * Return the max print jobs per queue.
2858 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2860 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2861 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2862 maxjobs
= PRINT_MAX_JOBID
- 1;
2867 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2869 if (lp_ctx
== NULL
) {
2870 return get_iconv_handle();
2872 return lp_ctx
->iconv_handle
;
2875 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2877 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2878 if (!lp_ctx
->global
) {
2882 if (old_ic
== NULL
) {
2883 old_ic
= global_iconv_handle
;
2885 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2886 global_iconv_handle
= lp_ctx
->iconv_handle
;
2889 void lpcfg_smbcli_options(struct loadparm_context
*lp_ctx
,
2890 struct smbcli_options
*options
)
2892 options
->max_xmit
= lpcfg_max_xmit(lp_ctx
);
2893 options
->max_mux
= lpcfg_maxmux(lp_ctx
);
2894 options
->use_spnego
= lpcfg_nt_status_support(lp_ctx
) && lpcfg_use_spnego(lp_ctx
);
2895 options
->signing
= lpcfg_client_signing(lp_ctx
);
2896 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
2897 options
->ntstatus_support
= lpcfg_nt_status_support(lp_ctx
);
2898 options
->max_protocol
= lpcfg_cli_maxprotocol(lp_ctx
);
2899 options
->unicode
= lpcfg_unicode(lp_ctx
);
2900 options
->use_oplocks
= true;
2901 options
->use_level2_oplocks
= true;
2904 void lpcfg_smbcli_session_options(struct loadparm_context
*lp_ctx
,
2905 struct smbcli_session_options
*options
)
2907 options
->lanman_auth
= lpcfg_client_lanman_auth(lp_ctx
);
2908 options
->ntlmv2_auth
= lpcfg_client_ntlmv2_auth(lp_ctx
);
2909 options
->plaintext_auth
= lpcfg_client_plaintext_auth(lp_ctx
);
2912 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2914 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2917 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2919 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2922 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2924 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2927 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2929 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2932 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2934 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2937 _PUBLIC_
struct dcerpc_server_info
*lpcfg_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2939 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
2941 ret
->domain_name
= talloc_reference(mem_ctx
, lpcfg_workgroup(lp_ctx
));
2942 ret
->version_major
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
2943 ret
->version_minor
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
2944 ret
->version_build
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
2949 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2951 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
2952 if (settings
== NULL
)
2954 SMB_ASSERT(lp_ctx
!= NULL
);
2955 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2956 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");