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"
72 #define standard_sub_basic talloc_strdup
74 static bool do_parameter(const char *, const char *, void *);
75 static bool defaults_saved
= false;
78 * This structure describes global (ie., server-wide) parameters.
80 struct loadparm_global
82 enum server_role server_role
;
83 enum sid_generator sid_generator
;
85 const char **smb_ports
;
89 char *display_charset
;
102 char *szWINS_CONFIG_URL
;
105 const char **szPasswordServers
;
106 char *szSocketOptions
;
110 const char **szWINSservers
;
111 const char **szInterfaces
;
112 char *szSocketAddress
;
113 char *szAnnounceVersion
; /* This is initialised in init_globals */
116 const char **szNetbiosAliases
;
117 char *szNetbiosScope
;
118 char *szDomainOtherSIDs
;
119 const char **szNameResolveOrder
;
120 const char **dcerpc_ep_servers
;
121 const char **server_services
;
122 char *ntptr_providor
;
123 char *szWinbindSeparator
;
124 char *szWinbinddPrivilegedSocketDirectory
;
125 char *szWinbinddSocketDirectory
;
126 char *szTemplateShell
;
127 char *szTemplateHomedir
;
128 int bWinbindSealedPipes
;
129 int bIdmapTrustedOnly
;
147 int paranoid_server_security
;
150 int announce_as
; /* This is initialised in init_globals */
157 char *socket_options
;
162 int bPreferredMaster
;
163 int bEncryptPasswords
;
165 int bObeyPamRestrictions
;
170 int bBindInterfacesOnly
;
172 int bNTStatusSupport
;
178 int bClientPlaintextAuth
;
179 int bClientLanManAuth
;
180 int bClientNTLMv2Auth
;
181 int client_use_spnego_principal
;
187 char *szNTPSignDSocketDirectory
;
188 const char **szRNDCCommand
;
189 const char **szDNSUpdateCommand
;
190 const char **szSPNUpdateCommand
;
191 char *szNSUpdateCommand
;
192 struct parmlist_entry
*param_opt
;
197 * This structure describes a single service.
199 struct loadparm_service
211 char **ntvfs_handler
;
225 int iCreate_force_mode
;
232 struct parmlist_entry
*param_opt
;
234 char dummy
[3]; /* for alignment */
238 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
241 /* prototypes for the special type handlers */
242 static bool handle_include(struct loadparm_context
*lp_ctx
,
243 const char *pszParmValue
, char **ptr
);
244 static bool handle_realm(struct loadparm_context
*lp_ctx
,
245 const char *pszParmValue
, char **ptr
);
246 static bool handle_copy(struct loadparm_context
*lp_ctx
,
247 const char *pszParmValue
, char **ptr
);
248 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
249 const char *pszParmValue
, char **ptr
);
250 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
251 const char *pszParmValue
, char **ptr
);
253 static const struct enum_list enum_protocol
[] = {
254 {PROTOCOL_SMB2
, "SMB2"},
255 {PROTOCOL_NT1
, "NT1"},
256 {PROTOCOL_LANMAN2
, "LANMAN2"},
257 {PROTOCOL_LANMAN1
, "LANMAN1"},
258 {PROTOCOL_CORE
, "CORE"},
259 {PROTOCOL_COREPLUS
, "COREPLUS"},
260 {PROTOCOL_COREPLUS
, "CORE+"},
264 static const struct enum_list enum_security
[] = {
265 {SEC_SHARE
, "SHARE"},
270 static const struct enum_list enum_announce_as
[] = {
271 {ANNOUNCE_AS_NT_SERVER
, "NT"},
272 {ANNOUNCE_AS_NT_SERVER
, "NT Server"},
273 {ANNOUNCE_AS_NT_WORKSTATION
, "NT Workstation"},
274 {ANNOUNCE_AS_WIN95
, "win95"},
275 {ANNOUNCE_AS_WFW
, "WfW"},
279 static const struct enum_list enum_bool_auto
[] = {
290 /* Client-side offline caching policy types */
293 CSC_POLICY_DOCUMENTS
=1,
294 CSC_POLICY_PROGRAMS
=2,
298 static const struct enum_list enum_csc_policy
[] = {
299 {CSC_POLICY_MANUAL
, "manual"},
300 {CSC_POLICY_DOCUMENTS
, "documents"},
301 {CSC_POLICY_PROGRAMS
, "programs"},
302 {CSC_POLICY_DISABLE
, "disable"},
306 /* SMB signing types. */
307 static const struct enum_list enum_smb_signing_vals
[] = {
308 {SMB_SIGNING_OFF
, "No"},
309 {SMB_SIGNING_OFF
, "False"},
310 {SMB_SIGNING_OFF
, "0"},
311 {SMB_SIGNING_OFF
, "Off"},
312 {SMB_SIGNING_OFF
, "disabled"},
313 {SMB_SIGNING_SUPPORTED
, "Yes"},
314 {SMB_SIGNING_SUPPORTED
, "True"},
315 {SMB_SIGNING_SUPPORTED
, "1"},
316 {SMB_SIGNING_SUPPORTED
, "On"},
317 {SMB_SIGNING_SUPPORTED
, "enabled"},
318 {SMB_SIGNING_REQUIRED
, "required"},
319 {SMB_SIGNING_REQUIRED
, "mandatory"},
320 {SMB_SIGNING_REQUIRED
, "force"},
321 {SMB_SIGNING_REQUIRED
, "forced"},
322 {SMB_SIGNING_REQUIRED
, "enforced"},
323 {SMB_SIGNING_AUTO
, "auto"},
327 static const struct enum_list enum_server_role
[] = {
328 {ROLE_STANDALONE
, "standalone"},
329 {ROLE_DOMAIN_MEMBER
, "member server"},
330 {ROLE_DOMAIN_MEMBER
, "member"},
331 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
332 {ROLE_DOMAIN_CONTROLLER
, "dc"},
336 static const struct enum_list enum_sid_generator
[] = {
337 {SID_GENERATOR_INTERNAL
, "internal"},
338 {SID_GENERATOR_BACKEND
, "backend"},
342 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
343 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
345 static struct parm_struct parm_table
[] = {
346 {"server role", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_role
), NULL
, enum_server_role
},
347 {"sid generator", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(sid_generator
), NULL
, enum_sid_generator
},
349 {"dos charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(dos_charset
), NULL
, NULL
},
350 {"unix charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(unix_charset
), NULL
, NULL
},
351 {"ncalrpc dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ncalrpc_dir
), NULL
, NULL
},
352 {"display charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(display_charset
), NULL
, NULL
},
353 {"comment", P_STRING
, P_LOCAL
, LOCAL_VAR(comment
), NULL
, NULL
},
354 {"path", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
355 {"directory", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
356 {"workgroup", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szWorkgroup
), NULL
, NULL
},
357 {"realm", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szRealm
), handle_realm
, NULL
},
358 {"netbios name", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosName
), NULL
, NULL
},
359 {"netbios aliases", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNetbiosAliases
), NULL
, NULL
},
360 {"netbios scope", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosScope
), NULL
, NULL
},
361 {"server string", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szServerString
), NULL
, NULL
},
362 {"interfaces", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szInterfaces
), NULL
, NULL
},
363 {"bind interfaces only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bBindInterfacesOnly
), NULL
, NULL
},
364 {"ntvfs handler", P_LIST
, P_LOCAL
, LOCAL_VAR(ntvfs_handler
), NULL
, NULL
},
365 {"ntptr providor", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ntptr_providor
), NULL
, NULL
},
366 {"dcerpc endpoint servers", P_LIST
, P_GLOBAL
, GLOBAL_VAR(dcerpc_ep_servers
), NULL
, NULL
},
367 {"server services", P_LIST
, P_GLOBAL
, GLOBAL_VAR(server_services
), NULL
, NULL
},
369 {"security", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(security
), NULL
, enum_security
},
370 {"encrypt passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bEncryptPasswords
), NULL
, NULL
},
371 {"null passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNullPasswords
), NULL
, NULL
},
372 {"obey pam restrictions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bObeyPamRestrictions
), NULL
, NULL
},
373 {"password server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szPasswordServers
), NULL
, NULL
},
374 {"sam database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSAM_URL
), NULL
, NULL
},
375 {"idmap database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szIDMAP_URL
), NULL
, NULL
},
376 {"secrets database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSECRETS_URL
), NULL
, NULL
},
377 {"spoolss database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSPOOLSS_URL
), NULL
, NULL
},
378 {"wins config database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_CONFIG_URL
), NULL
, NULL
},
379 {"wins database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_URL
), NULL
, NULL
},
380 {"private dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPrivateDir
), NULL
, NULL
},
381 {"passwd chat", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPasswdChat
), NULL
, NULL
},
382 {"password level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(pwordlevel
), NULL
, NULL
},
383 {"lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLanmanAuth
), NULL
, NULL
},
384 {"ntlm auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTLMAuth
), NULL
, NULL
},
385 {"client NTLMv2 auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientNTLMv2Auth
), NULL
, NULL
},
386 {"client lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientLanManAuth
), NULL
, NULL
},
387 {"client plaintext auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientPlaintextAuth
), NULL
, NULL
},
388 {"client use spnego principal", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(client_use_spnego_principal
), NULL
, NULL
},
390 {"read only", P_BOOL
, P_LOCAL
, LOCAL_VAR(bRead_only
), NULL
, NULL
},
392 {"create mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_mask
), NULL
, NULL
},
393 {"force create mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_force_mode
), NULL
, NULL
},
394 {"directory mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_mask
), NULL
, NULL
},
395 {"force directory mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_force_mode
), NULL
, NULL
},
397 {"hosts allow", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsallow
), NULL
, NULL
},
398 {"hosts deny", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsdeny
), NULL
, NULL
},
400 {"log level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
401 {"debuglevel", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
402 {"log file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(logfile
), handle_logfile
, NULL
},
404 {"smb ports", P_LIST
, P_GLOBAL
, GLOBAL_VAR(smb_ports
), NULL
, NULL
},
405 {"nbt port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(nbt_port
), NULL
, NULL
},
406 {"dgram port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(dgram_port
), NULL
, NULL
},
407 {"cldap port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(cldap_port
), NULL
, NULL
},
408 {"krb5 port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(krb5_port
), NULL
, NULL
},
409 {"kpasswd port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(kpasswd_port
), NULL
, NULL
},
410 {"web port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(web_port
), NULL
, NULL
},
411 {"tls enabled", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(tls_enabled
), NULL
, NULL
},
412 {"tls keyfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_keyfile
), NULL
, NULL
},
413 {"tls certfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_certfile
), NULL
, NULL
},
414 {"tls cafile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_cafile
), NULL
, NULL
},
415 {"tls crlfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_crlfile
), NULL
, NULL
},
416 {"tls dh params file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_dhpfile
), NULL
, NULL
},
417 {"large readwrite", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLargeReadwrite
), NULL
, NULL
},
418 {"server max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_maxprotocol
), NULL
, enum_protocol
},
419 {"server min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_minprotocol
), NULL
, enum_protocol
},
420 {"client max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_maxprotocol
), NULL
, enum_protocol
},
421 {"client min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_minprotocol
), NULL
, enum_protocol
},
422 {"unicode", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnicode
), NULL
, NULL
},
423 {"read raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bReadRaw
), NULL
, NULL
},
424 {"write raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWriteRaw
), NULL
, NULL
},
425 {"disable netbios", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bDisableNetbios
), NULL
, NULL
},
427 {"nt status support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTStatusSupport
), NULL
, NULL
},
429 {"announce version", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAnnounceVersion
), NULL
, NULL
},
430 {"announce as", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(announce_as
), NULL
, enum_announce_as
},
431 {"max mux", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_mux
), NULL
, NULL
},
432 {"max xmit", P_BYTES
, P_GLOBAL
, GLOBAL_VAR(max_xmit
), NULL
, NULL
},
434 {"name resolve order", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNameResolveOrder
), NULL
, NULL
},
435 {"max wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_wins_ttl
), NULL
, NULL
},
436 {"min wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(min_wins_ttl
), NULL
, NULL
},
437 {"time server", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bTimeServer
), NULL
, NULL
},
438 {"unix extensions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnixExtensions
), NULL
, NULL
},
439 {"use spnego", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUseSpnego
), NULL
, NULL
},
440 {"server signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_signing
), NULL
, enum_smb_signing_vals
},
441 {"client signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(client_signing
), NULL
, enum_smb_signing_vals
},
442 {"rpc big endian", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bRpcBigEndian
), NULL
, NULL
},
444 {"max connections", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxConnections
), NULL
, NULL
},
445 {"paranoid server security", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(paranoid_server_security
), NULL
, NULL
},
446 {"socket options", P_STRING
, P_GLOBAL
, GLOBAL_VAR(socket_options
), NULL
, NULL
},
448 {"strict sync", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictSync
), NULL
, NULL
},
449 {"case insensitive filesystem", P_BOOL
, P_LOCAL
, LOCAL_VAR(bCIFileSystem
), NULL
, NULL
},
451 {"max print jobs", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxPrintJobs
), NULL
, NULL
},
452 {"printable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
453 {"print ok", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
455 {"printer name", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
456 {"printer", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
458 {"map system", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_system
), NULL
, NULL
},
459 {"map hidden", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_hidden
), NULL
, NULL
},
460 {"map archive", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_archive
), NULL
, NULL
},
462 {"preferred master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
463 {"prefered master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
464 {"local master", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLocalMaster
), NULL
, NULL
},
465 {"browseable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
466 {"browsable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
468 {"wins server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szWINSservers
), NULL
, NULL
},
469 {"wins support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSsupport
), NULL
, NULL
},
470 {"dns proxy", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSdnsProxy
), NULL
, NULL
},
471 {"wins hook", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINSHook
), NULL
, NULL
},
473 {"csc policy", P_ENUM
, P_LOCAL
, LOCAL_VAR(iCSCPolicy
), NULL
, enum_csc_policy
},
475 {"strict locking", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictLocking
), NULL
, NULL
},
476 {"oplocks", P_BOOL
, P_LOCAL
, LOCAL_VAR(bOplocks
), NULL
, NULL
},
478 {"share backend", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szShareBackend
), NULL
, NULL
},
479 {"preload", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
480 {"auto services", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
481 {"lock dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
482 {"lock directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
483 {"modules dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szModulesDir
), NULL
, NULL
},
484 {"pid directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPidDir
), NULL
, NULL
},
485 {"setup directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSetupDir
), NULL
, NULL
},
487 {"socket address", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSocketAddress
), NULL
, NULL
},
488 {"copy", P_STRING
, P_LOCAL
, LOCAL_VAR(szCopy
), handle_copy
, NULL
},
489 {"include", P_STRING
, P_LOCAL
, LOCAL_VAR(szInclude
), handle_include
, NULL
},
491 {"available", P_BOOL
, P_LOCAL
, LOCAL_VAR(bAvailable
), NULL
, NULL
},
492 {"volume", P_STRING
, P_LOCAL
, LOCAL_VAR(volume
), NULL
, NULL
},
493 {"fstype", P_STRING
, P_LOCAL
, LOCAL_VAR(fstype
), NULL
, NULL
},
495 {"panic action", P_STRING
, P_GLOBAL
, GLOBAL_VAR(panic_action
), NULL
, NULL
},
497 {"msdfs root", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMSDfsRoot
), NULL
, NULL
},
498 {"host msdfs", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bHostMSDfs
), NULL
, NULL
},
499 {"winbind separator", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbindSeparator
), NULL
, NULL
},
500 {"winbindd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddSocketDirectory
), NULL
, NULL
},
501 {"winbindd privileged socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
), NULL
, NULL
},
502 {"winbind sealed pipes", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWinbindSealedPipes
), NULL
, NULL
},
503 {"template shell", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateShell
), NULL
, NULL
},
504 {"template homedir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateHomedir
), NULL
, NULL
},
505 {"idmap trusted only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bIdmapTrustedOnly
), NULL
, NULL
},
507 {"ntp signd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szNTPSignDSocketDirectory
), NULL
, NULL
},
508 {"rndc command", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szRNDCCommand
), NULL
, NULL
},
509 {"dns update command", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szDNSUpdateCommand
), NULL
, NULL
},
510 {"spn update command", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szSPNUpdateCommand
), NULL
, NULL
},
511 {"nsupdate command", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szNSUpdateCommand
), NULL
, NULL
},
513 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
}
517 /* local variables */
518 struct loadparm_context
{
519 const char *szConfigFile
;
520 struct loadparm_global
*globals
;
521 struct loadparm_service
**services
;
522 struct loadparm_service
*sDefault
;
523 struct smb_iconv_convenience
*iconv_convenience
;
525 struct loadparm_service
*currentService
;
526 bool bInGlobalSection
;
528 struct file_lists
*next
;
533 unsigned int flags
[NUMPARAMETERS
];
537 struct loadparm_service
*lp_default_service(struct loadparm_context
*lp_ctx
)
539 return lp_ctx
->sDefault
;
543 return the parameter table
545 struct parm_struct
*lp_parm_table(void)
551 * Convenience routine to grab string parameters into temporary memory
552 * and run standard_sub_basic on them.
554 * The buffers can be written to by
555 * callers without affecting the source string.
558 static const char *lp_string(const char *s
)
560 #if 0 /* until REWRITE done to make thread-safe */
561 size_t len
= s
? strlen(s
) : 0;
565 /* The follow debug is useful for tracking down memory problems
566 especially if you have an inner loop that is calling a lp_*()
567 function that returns a string. Perhaps this debug should be
568 present all the time? */
571 DEBUG(10, ("lp_string(%s)\n", s
));
574 #if 0 /* until REWRITE done to make thread-safe */
576 lp_talloc
= talloc_init("lp_talloc");
578 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
586 strlcpy(ret
, s
, len
);
588 if (trim_string(ret
, "\"", "\"")) {
589 if (strchr(ret
,'"') != NULL
)
590 strlcpy(ret
, s
, len
);
593 standard_sub_basic(ret
,len
+100);
600 In this section all the functions that are used to access the
601 parameters from the rest of the program are defined
604 #define FN_GLOBAL_STRING(fn_name,var_name) \
605 const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : "";}
606 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
607 const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name ? lp_ctx->globals->var_name : "";}
608 #define FN_GLOBAL_LIST(fn_name,var_name) \
609 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
610 #define FN_GLOBAL_BOOL(fn_name,var_name) \
611 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
613 #define FN_GLOBAL_CHAR(fn_name,ptr) \
614 char fn_name(void) {return(*(char *)(ptr));}
616 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
617 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
619 #define FN_LOCAL_STRING(fn_name,val) \
620 const char *fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)));}
621 #define FN_LOCAL_LIST(fn_name,val) \
622 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
623 #define FN_LOCAL_BOOL(fn_name,val) \
624 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
625 #define FN_LOCAL_INTEGER(fn_name,val) \
626 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
628 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_role
, server_role
)
629 _PUBLIC_
FN_GLOBAL_INTEGER(lp_sid_generator
, sid_generator
)
630 _PUBLIC_
FN_GLOBAL_LIST(lp_smb_ports
, smb_ports
)
631 _PUBLIC_
FN_GLOBAL_INTEGER(lp_nbt_port
, nbt_port
)
632 _PUBLIC_
FN_GLOBAL_INTEGER(lp_dgram_port
, dgram_port
)
633 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cldap_port
, cldap_port
)
634 _PUBLIC_
FN_GLOBAL_INTEGER(lp_krb5_port
, krb5_port
)
635 _PUBLIC_
FN_GLOBAL_INTEGER(lp_kpasswd_port
, kpasswd_port
)
636 _PUBLIC_
FN_GLOBAL_INTEGER(lp_web_port
, web_port
)
637 _PUBLIC_
FN_GLOBAL_BOOL(lp_tls_enabled
, tls_enabled
)
638 _PUBLIC_
FN_GLOBAL_STRING(lp_share_backend
, szShareBackend
)
639 _PUBLIC_
FN_GLOBAL_STRING(lp_sam_url
, szSAM_URL
)
640 _PUBLIC_
FN_GLOBAL_STRING(lp_idmap_url
, szIDMAP_URL
)
641 _PUBLIC_
FN_GLOBAL_STRING(lp_secrets_url
, szSECRETS_URL
)
642 _PUBLIC_
FN_GLOBAL_STRING(lp_spoolss_url
, szSPOOLSS_URL
)
643 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_config_url
, szWINS_CONFIG_URL
)
644 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_url
, szWINS_URL
)
645 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbind_separator
, szWinbindSeparator
)
646 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory
, szWinbinddSocketDirectory
)
647 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
648 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_shell
, szTemplateShell
)
649 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_homedir
, szTemplateHomedir
)
650 _PUBLIC_
FN_GLOBAL_BOOL(lp_winbind_sealed_pipes
, bWinbindSealedPipes
)
651 _PUBLIC_
FN_GLOBAL_BOOL(lp_idmap_trusted_only
, bIdmapTrustedOnly
)
652 _PUBLIC_
FN_GLOBAL_STRING(lp_private_dir
, szPrivateDir
)
653 _PUBLIC_
FN_GLOBAL_STRING(lp_serverstring
, szServerString
)
654 _PUBLIC_
FN_GLOBAL_STRING(lp_lockdir
, szLockDir
)
655 _PUBLIC_
FN_GLOBAL_STRING(lp_modulesdir
, szModulesDir
)
656 _PUBLIC_
FN_GLOBAL_STRING(lp_setupdir
, szSetupDir
)
657 _PUBLIC_
FN_GLOBAL_STRING(lp_ncalrpc_dir
, ncalrpc_dir
)
658 _PUBLIC_
FN_GLOBAL_STRING(lp_dos_charset
, dos_charset
)
659 _PUBLIC_
FN_GLOBAL_STRING(lp_unix_charset
, unix_charset
)
660 _PUBLIC_
FN_GLOBAL_STRING(lp_display_charset
, display_charset
)
661 _PUBLIC_
FN_GLOBAL_STRING(lp_piddir
, szPidDir
)
662 _PUBLIC_
FN_GLOBAL_LIST(lp_rndc_command
, szRNDCCommand
)
663 _PUBLIC_
FN_GLOBAL_LIST(lp_dns_update_command
, szDNSUpdateCommand
)
664 _PUBLIC_
FN_GLOBAL_LIST(lp_spn_update_command
, szSPNUpdateCommand
)
665 _PUBLIC_
FN_GLOBAL_STRING(lp_nsupdate_command
, szNSUpdateCommand
)
666 _PUBLIC_
FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers
, dcerpc_ep_servers
)
667 _PUBLIC_
FN_GLOBAL_LIST(lp_server_services
, server_services
)
668 _PUBLIC_
FN_GLOBAL_STRING(lp_ntptr_providor
, ntptr_providor
)
669 _PUBLIC_
FN_GLOBAL_STRING(lp_auto_services
, szAutoServices
)
670 _PUBLIC_
FN_GLOBAL_STRING(lp_passwd_chat
, szPasswdChat
)
671 _PUBLIC_
FN_GLOBAL_LIST(lp_passwordserver
, szPasswordServers
)
672 _PUBLIC_
FN_GLOBAL_LIST(lp_name_resolve_order
, szNameResolveOrder
)
673 _PUBLIC_
FN_GLOBAL_STRING(lp_realm
, szRealm_upper
)
674 _PUBLIC_
FN_GLOBAL_STRING(lp_dnsdomain
, szRealm_lower
)
675 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_options
, socket_options
)
676 _PUBLIC_
FN_GLOBAL_STRING(lp_workgroup
, szWorkgroup
)
677 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_name
, szNetbiosName
)
678 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_scope
, szNetbiosScope
)
679 _PUBLIC_
FN_GLOBAL_LIST(lp_wins_server_list
, szWINSservers
)
680 _PUBLIC_
FN_GLOBAL_LIST(lp_interfaces
, szInterfaces
)
681 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_address
, szSocketAddress
)
682 _PUBLIC_
FN_GLOBAL_LIST(lp_netbios_aliases
, szNetbiosAliases
)
683 _PUBLIC_
FN_GLOBAL_BOOL(lp_disable_netbios
, bDisableNetbios
)
684 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_support
, bWINSsupport
)
685 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_dns_proxy
, bWINSdnsProxy
)
686 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_hook
, szWINSHook
)
687 _PUBLIC_
FN_GLOBAL_BOOL(lp_local_master
, bLocalMaster
)
688 _PUBLIC_
FN_GLOBAL_BOOL(lp_readraw
, bReadRaw
)
689 _PUBLIC_
FN_GLOBAL_BOOL(lp_large_readwrite
, bLargeReadwrite
)
690 _PUBLIC_
FN_GLOBAL_BOOL(lp_writeraw
, bWriteRaw
)
691 _PUBLIC_
FN_GLOBAL_BOOL(lp_null_passwords
, bNullPasswords
)
692 _PUBLIC_
FN_GLOBAL_BOOL(lp_obey_pam_restrictions
, bObeyPamRestrictions
)
693 _PUBLIC_
FN_GLOBAL_BOOL(lp_encrypted_passwords
, bEncryptPasswords
)
694 _PUBLIC_
FN_GLOBAL_BOOL(lp_time_server
, bTimeServer
)
695 _PUBLIC_
FN_GLOBAL_BOOL(lp_bind_interfaces_only
, bBindInterfacesOnly
)
696 _PUBLIC_
FN_GLOBAL_BOOL(lp_unicode
, bUnicode
)
697 _PUBLIC_
FN_GLOBAL_BOOL(lp_nt_status_support
, bNTStatusSupport
)
698 _PUBLIC_
FN_GLOBAL_BOOL(lp_lanman_auth
, bLanmanAuth
)
699 _PUBLIC_
FN_GLOBAL_BOOL(lp_ntlm_auth
, bNTLMAuth
)
700 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_plaintext_auth
, bClientPlaintextAuth
)
701 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_lanman_auth
, bClientLanManAuth
)
702 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_ntlmv2_auth
, bClientNTLMv2Auth
)
703 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_use_spnego_principal
, client_use_spnego_principal
)
704 _PUBLIC_
FN_GLOBAL_BOOL(lp_host_msdfs
, bHostMSDfs
)
705 _PUBLIC_
FN_GLOBAL_BOOL(lp_unix_extensions
, bUnixExtensions
)
706 _PUBLIC_
FN_GLOBAL_BOOL(lp_use_spnego
, bUseSpnego
)
707 _PUBLIC_
FN_GLOBAL_BOOL(lp_rpc_big_endian
, bRpcBigEndian
)
708 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_wins_ttl
, max_wins_ttl
)
709 _PUBLIC_
FN_GLOBAL_INTEGER(lp_min_wins_ttl
, min_wins_ttl
)
710 _PUBLIC_
FN_GLOBAL_INTEGER(lp_maxmux
, max_mux
)
711 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_xmit
, max_xmit
)
712 _PUBLIC_
FN_GLOBAL_INTEGER(lp_passwordlevel
, pwordlevel
)
713 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_maxprotocol
, srv_maxprotocol
)
714 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_minprotocol
, srv_minprotocol
)
715 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_maxprotocol
, cli_maxprotocol
)
716 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_minprotocol
, cli_minprotocol
)
717 _PUBLIC_
FN_GLOBAL_INTEGER(lp_security
, security
)
718 _PUBLIC_
FN_GLOBAL_BOOL(lp_paranoid_server_security
, paranoid_server_security
)
719 _PUBLIC_
FN_GLOBAL_INTEGER(lp_announce_as
, announce_as
)
721 const char *lp_servicename(const struct loadparm_service
*service
)
723 return lp_string((const char *)service
->szService
);
726 _PUBLIC_
FN_LOCAL_STRING(lp_pathname
, szPath
)
727 static FN_LOCAL_STRING(_lp_printername
, szPrintername
)
728 _PUBLIC_
FN_LOCAL_LIST(lp_hostsallow
, szHostsallow
)
729 _PUBLIC_
FN_LOCAL_LIST(lp_hostsdeny
, szHostsdeny
)
730 _PUBLIC_
FN_LOCAL_STRING(lp_comment
, comment
)
731 _PUBLIC_
FN_LOCAL_STRING(lp_fstype
, fstype
)
732 static FN_LOCAL_STRING(lp_volume
, volume
)
733 _PUBLIC_
FN_LOCAL_LIST(lp_ntvfs_handler
, ntvfs_handler
)
734 _PUBLIC_
FN_LOCAL_BOOL(lp_msdfs_root
, bMSDfsRoot
)
735 _PUBLIC_
FN_LOCAL_BOOL(lp_browseable
, bBrowseable
)
736 _PUBLIC_
FN_LOCAL_BOOL(lp_readonly
, bRead_only
)
737 _PUBLIC_
FN_LOCAL_BOOL(lp_print_ok
, bPrint_ok
)
738 _PUBLIC_
FN_LOCAL_BOOL(lp_map_hidden
, bMap_hidden
)
739 _PUBLIC_
FN_LOCAL_BOOL(lp_map_archive
, bMap_archive
)
740 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_locking
, bStrictLocking
)
741 _PUBLIC_
FN_LOCAL_BOOL(lp_oplocks
, bOplocks
)
742 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_sync
, bStrictSync
)
743 _PUBLIC_
FN_LOCAL_BOOL(lp_ci_filesystem
, bCIFileSystem
)
744 _PUBLIC_
FN_LOCAL_BOOL(lp_map_system
, bMap_system
)
745 _PUBLIC_
FN_LOCAL_INTEGER(lp_max_connections
, iMaxConnections
)
746 _PUBLIC_
FN_LOCAL_INTEGER(lp_csc_policy
, iCSCPolicy
)
747 _PUBLIC_
FN_LOCAL_INTEGER(lp_create_mask
, iCreate_mask
)
748 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_create_mode
, iCreate_force_mode
)
749 _PUBLIC_
FN_LOCAL_INTEGER(lp_dir_mask
, iDir_mask
)
750 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_dir_mode
, iDir_force_mode
)
751 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_signing
, server_signing
)
752 _PUBLIC_
FN_GLOBAL_INTEGER(lp_client_signing
, client_signing
)
754 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
756 /* local prototypes */
757 static int map_parameter(const char *pszParmName
);
758 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
759 const char *pszServiceName
);
760 static void copy_service(struct loadparm_service
*pserviceDest
,
761 struct loadparm_service
*pserviceSource
,
763 static bool service_ok(struct loadparm_service
*service
);
764 static bool do_section(const char *pszSectionName
, void *);
765 static void init_copymap(struct loadparm_service
*pservice
);
767 /* This is a helper function for parametrical options support. */
768 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
769 /* Actual parametrical functions are quite simple */
770 const char *lp_get_parametric(struct loadparm_context
*lp_ctx
,
771 struct loadparm_service
*service
,
772 const char *type
, const char *option
)
775 struct parmlist_entry
*data
;
780 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
782 asprintf(&vfskey
, "%s:%s", type
, option
);
783 if (vfskey
== NULL
) return NULL
;
787 if (strcmp(data
->key
, vfskey
) == 0) {
794 if (service
!= NULL
) {
795 /* Try to fetch the same option but from globals */
796 /* but only if we are not already working with globals */
797 for (data
= lp_ctx
->globals
->param_opt
; data
;
799 if (strcmp(data
->key
, vfskey
) == 0) {
813 * convenience routine to return int parameters.
815 static int lp_int(const char *s
)
819 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
823 return strtol(s
, NULL
, 0);
827 * convenience routine to return unsigned long parameters.
829 static int lp_ulong(const char *s
)
833 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
837 return strtoul(s
, NULL
, 0);
841 * convenience routine to return unsigned long parameters.
843 static double lp_double(const char *s
)
847 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
851 return strtod(s
, NULL
);
855 * convenience routine to return boolean parameters.
857 static bool lp_bool(const char *s
)
862 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
866 if (!set_boolean(s
, &ret
)) {
867 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
876 * Return parametric option from a given service. Type is a part of option before ':'
877 * Parametric option has following syntax: 'Type: option = value'
878 * Returned value is allocated in 'lp_talloc' context
881 const char *lp_parm_string(struct loadparm_context
*lp_ctx
,
882 struct loadparm_service
*service
, const char *type
,
885 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
888 return lp_string(value
);
894 * Return parametric option from a given service. Type is a part of option before ':'
895 * Parametric option has following syntax: 'Type: option = value'
896 * Returned value is allocated in 'lp_talloc' context
899 const char **lp_parm_string_list(TALLOC_CTX
*mem_ctx
,
900 struct loadparm_context
*lp_ctx
,
901 struct loadparm_service
*service
,
903 const char *option
, const char *separator
)
905 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
908 return (const char **)str_list_make(mem_ctx
, value
, separator
);
914 * Return parametric option from a given service. Type is a part of option before ':'
915 * Parametric option has following syntax: 'Type: option = value'
918 int lp_parm_int(struct loadparm_context
*lp_ctx
,
919 struct loadparm_service
*service
, const char *type
,
920 const char *option
, int default_v
)
922 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
925 return lp_int(value
);
931 * Return parametric option from a given service. Type is a part of
933 * Parametric option has following syntax: 'Type: option = value'.
936 int lp_parm_bytes(struct loadparm_context
*lp_ctx
,
937 struct loadparm_service
*service
, const char *type
,
938 const char *option
, int default_v
)
942 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
944 if (value
&& conv_str_size(value
, &bval
)) {
945 if (bval
<= INT_MAX
) {
954 * Return parametric option from a given service.
955 * Type is a part of option before ':'
956 * Parametric option has following syntax: 'Type: option = value'
958 unsigned long lp_parm_ulong(struct loadparm_context
*lp_ctx
,
959 struct loadparm_service
*service
, const char *type
,
960 const char *option
, unsigned long default_v
)
962 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
965 return lp_ulong(value
);
971 double lp_parm_double(struct loadparm_context
*lp_ctx
,
972 struct loadparm_service
*service
, const char *type
,
973 const char *option
, double default_v
)
975 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
978 return lp_double(value
);
984 * Return parametric option from a given service. Type is a part of option before ':'
985 * Parametric option has following syntax: 'Type: option = value'
988 bool lp_parm_bool(struct loadparm_context
*lp_ctx
,
989 struct loadparm_service
*service
, const char *type
,
990 const char *option
, bool default_v
)
992 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
995 return lp_bool(value
);
1002 * Initialise a service to the defaults.
1005 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1007 struct loadparm_service
*pservice
=
1008 talloc_zero(mem_ctx
, struct loadparm_service
);
1009 copy_service(pservice
, sDefault
, NULL
);
1014 * Set a string value, deallocating any existing space, and allocing the space
1017 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1024 *dest
= talloc_strdup(mem_ctx
, src
);
1025 if ((*dest
) == NULL
) {
1026 DEBUG(0,("Out of memory in string_init\n"));
1036 * Add a new service to the services array initialising it with the given
1040 struct loadparm_service
*lp_add_service(struct loadparm_context
*lp_ctx
,
1041 const struct loadparm_service
*pservice
,
1045 struct loadparm_service tservice
;
1046 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1047 struct parmlist_entry
*data
, *pdata
;
1049 tservice
= *pservice
;
1051 /* it might already exist */
1053 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1055 if (service
!= NULL
) {
1056 /* Clean all parametric options for service */
1057 /* They will be added during parsing again */
1058 data
= service
->param_opt
;
1064 service
->param_opt
= NULL
;
1069 /* find an invalid one */
1070 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1071 if (lp_ctx
->services
[i
] == NULL
)
1074 /* if not, then create one */
1075 if (i
== lp_ctx
->iNumServices
) {
1076 struct loadparm_service
**tsp
;
1078 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1081 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1084 lp_ctx
->services
= tsp
;
1085 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1088 lp_ctx
->iNumServices
++;
1091 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1092 if (lp_ctx
->services
[i
] == NULL
) {
1093 DEBUG(0,("lp_add_service: out of memory!\n"));
1096 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1098 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1099 return lp_ctx
->services
[i
];
1103 * Add a new home service, with the specified home directory, defaults coming
1104 * from service ifrom.
1107 bool lp_add_home(struct loadparm_context
*lp_ctx
,
1108 const char *pszHomename
,
1109 struct loadparm_service
*default_service
,
1110 const char *user
, const char *pszHomedir
)
1112 struct loadparm_service
*service
;
1114 service
= lp_add_service(lp_ctx
, default_service
, pszHomename
);
1116 if (service
== NULL
)
1119 if (!(*(default_service
->szPath
))
1120 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1121 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1123 service
->szPath
= string_sub_talloc(service
, lp_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1126 if (!(*(service
->comment
))) {
1127 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1129 service
->bAvailable
= default_service
->bAvailable
;
1130 service
->bBrowseable
= default_service
->bBrowseable
;
1132 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1133 pszHomename
, user
, service
->szPath
));
1139 * Add the IPC service.
1142 static bool lp_add_hidden(struct loadparm_context
*lp_ctx
, const char *name
,
1145 struct loadparm_service
*service
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
, name
);
1147 if (service
== NULL
)
1150 string_set(service
, &service
->szPath
, tmpdir());
1152 service
->comment
= talloc_asprintf(service
, "%s Service (%s)",
1153 fstype
, lp_ctx
->globals
->szServerString
);
1154 string_set(service
, &service
->fstype
, fstype
);
1155 service
->iMaxConnections
= -1;
1156 service
->bAvailable
= true;
1157 service
->bRead_only
= true;
1158 service
->bPrint_ok
= false;
1159 service
->bBrowseable
= false;
1161 if (strcasecmp(fstype
, "IPC") == 0) {
1162 lp_do_service_parameter(lp_ctx
, service
, "ntvfs handler",
1166 DEBUG(3, ("adding hidden service %s\n", name
));
1172 * Add a new printer service, with defaults coming from service iFrom.
1175 bool lp_add_printer(struct loadparm_context
*lp_ctx
,
1176 const char *pszPrintername
,
1177 struct loadparm_service
*default_service
)
1179 const char *comment
= "From Printcap";
1180 struct loadparm_service
*service
;
1181 service
= lp_add_service(lp_ctx
, default_service
, pszPrintername
);
1183 if (service
== NULL
)
1186 /* note that we do NOT default the availability flag to True - */
1187 /* we take it from the default service passed. This allows all */
1188 /* dynamic printers to be disabled by disabling the [printers] */
1189 /* entry (if/when the 'available' keyword is implemented!). */
1191 /* the printer name is set to the service name. */
1192 string_set(service
, &service
->szPrintername
, pszPrintername
);
1193 string_set(service
, &service
->comment
, comment
);
1194 service
->bBrowseable
= default_service
->bBrowseable
;
1195 /* Printers cannot be read_only. */
1196 service
->bRead_only
= false;
1197 /* Printer services must be printable. */
1198 service
->bPrint_ok
= true;
1200 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1206 * Map a parameter's string representation to something we can use.
1207 * Returns False if the parameter string is not recognised, else TRUE.
1210 static int map_parameter(const char *pszParmName
)
1214 if (*pszParmName
== '-')
1217 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1218 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1221 /* Warn only if it isn't parametric option */
1222 if (strchr(pszParmName
, ':') == NULL
)
1223 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
1224 /* We do return 'fail' for parametric options as well because they are
1225 stored in different storage
1232 return the parameter structure for a parameter
1234 struct parm_struct
*lp_parm_struct(const char *name
)
1236 int parmnum
= map_parameter(name
);
1237 if (parmnum
== -1) return NULL
;
1238 return &parm_table
[parmnum
];
1242 return the parameter pointer for a parameter
1244 void *lp_parm_ptr(struct loadparm_context
*lp_ctx
,
1245 struct loadparm_service
*service
, struct parm_struct
*parm
)
1247 if (service
== NULL
) {
1248 if (parm
->pclass
== P_LOCAL
)
1249 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
1250 else if (parm
->pclass
== P_GLOBAL
)
1251 return ((char *)lp_ctx
->globals
)+parm
->offset
;
1254 return ((char *)service
) + parm
->offset
;
1259 * Find a service by name. Otherwise works like get_service.
1262 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1263 const char *pszServiceName
)
1267 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
1268 if (lp_ctx
->services
[iService
] != NULL
&&
1269 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
1270 return lp_ctx
->services
[iService
];
1277 * Copy a service structure to another.
1278 * If pcopymapDest is NULL then copy all fields
1281 static void copy_service(struct loadparm_service
*pserviceDest
,
1282 struct loadparm_service
*pserviceSource
,
1286 bool bcopyall
= (pcopymapDest
== NULL
);
1287 struct parmlist_entry
*data
, *pdata
, *paramo
;
1290 for (i
= 0; parm_table
[i
].label
; i
++)
1291 if (parm_table
[i
].offset
!= -1 && parm_table
[i
].pclass
== P_LOCAL
&&
1292 (bcopyall
|| pcopymapDest
[i
])) {
1294 ((char *)pserviceSource
) + parm_table
[i
].offset
;
1296 ((char *)pserviceDest
) + parm_table
[i
].offset
;
1298 switch (parm_table
[i
].type
) {
1300 *(int *)dest_ptr
= *(int *)src_ptr
;
1306 *(int *)dest_ptr
= *(int *)src_ptr
;
1310 string_set(pserviceDest
,
1316 string_set(pserviceDest
,
1319 strupper(*(char **)dest_ptr
);
1322 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
1323 *(const char ***)src_ptr
);
1331 init_copymap(pserviceDest
);
1332 if (pserviceSource
->copymap
)
1333 memcpy((void *)pserviceDest
->copymap
,
1334 (void *)pserviceSource
->copymap
,
1335 sizeof(int) * NUMPARAMETERS
);
1338 data
= pserviceSource
->param_opt
;
1341 pdata
= pserviceDest
->param_opt
;
1342 /* Traverse destination */
1344 /* If we already have same option, override it */
1345 if (strcmp(pdata
->key
, data
->key
) == 0) {
1346 talloc_free(pdata
->value
);
1347 pdata
->value
= talloc_reference(pdata
,
1352 pdata
= pdata
->next
;
1355 paramo
= talloc(pserviceDest
, struct parmlist_entry
);
1358 paramo
->key
= talloc_reference(paramo
, data
->key
);
1359 paramo
->value
= talloc_reference(paramo
, data
->value
);
1360 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1367 * Check a service for consistency. Return False if the service is in any way
1368 * incomplete or faulty, else True.
1370 static bool service_ok(struct loadparm_service
*service
)
1375 if (service
->szService
[0] == '\0') {
1376 DEBUG(0, ("The following message indicates an internal error:\n"));
1377 DEBUG(0, ("No service name in service entry.\n"));
1381 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1382 /* I can't see why you'd want a non-printable printer service... */
1383 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1384 if (!service
->bPrint_ok
) {
1385 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1386 service
->szService
));
1387 service
->bPrint_ok
= true;
1389 /* [printers] service must also be non-browsable. */
1390 if (service
->bBrowseable
)
1391 service
->bBrowseable
= false;
1394 /* If a service is flagged unavailable, log the fact at level 0. */
1395 if (!service
->bAvailable
)
1396 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1397 service
->szService
));
1403 /*******************************************************************
1404 Keep a linked list of all config files so we know when one has changed
1405 it's date and needs to be reloaded.
1406 ********************************************************************/
1408 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1409 const char *fname
, const char *subfname
)
1411 struct file_lists
*f
= lp_ctx
->file_lists
;
1414 if (f
->name
&& !strcmp(f
->name
, fname
))
1420 f
= talloc(lp_ctx
, struct file_lists
);
1423 f
->next
= lp_ctx
->file_lists
;
1424 f
->name
= talloc_strdup(f
, fname
);
1429 f
->subfname
= talloc_strdup(f
, subfname
);
1434 lp_ctx
->file_lists
= f
;
1435 f
->modtime
= file_modtime(subfname
);
1437 time_t t
= file_modtime(subfname
);
1443 /*******************************************************************
1444 Check if a config file has changed date.
1445 ********************************************************************/
1446 bool lp_file_list_changed(struct loadparm_context
*lp_ctx
)
1448 struct file_lists
*f
;
1449 DEBUG(6, ("lp_file_list_changed()\n"));
1451 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1455 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1457 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1458 f
->name
, n2
, ctime(&f
->modtime
)));
1460 mod_time
= file_modtime(n2
);
1462 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1463 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1465 f
->modtime
= mod_time
;
1466 talloc_free(f
->subfname
);
1467 f
->subfname
= talloc_strdup(f
, n2
);
1474 /***************************************************************************
1475 Handle the "realm" parameter
1476 ***************************************************************************/
1478 static bool handle_realm(struct loadparm_context
*lp_ctx
,
1479 const char *pszParmValue
, char **ptr
)
1481 string_set(lp_ctx
, ptr
, pszParmValue
);
1483 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1484 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1489 /***************************************************************************
1490 Handle the include operation.
1491 ***************************************************************************/
1493 static bool handle_include(struct loadparm_context
*lp_ctx
,
1494 const char *pszParmValue
, char **ptr
)
1496 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1498 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1500 string_set(lp_ctx
, ptr
, fname
);
1502 if (file_exist(fname
))
1503 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1505 DEBUG(2, ("Can't find include file %s\n", fname
));
1510 /***************************************************************************
1511 Handle the interpretation of the copy parameter.
1512 ***************************************************************************/
1514 static bool handle_copy(struct loadparm_context
*lp_ctx
,
1515 const char *pszParmValue
, char **ptr
)
1518 struct loadparm_service
*serviceTemp
;
1520 string_set(lp_ctx
, ptr
, pszParmValue
);
1524 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1526 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1527 if (serviceTemp
== lp_ctx
->currentService
) {
1528 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1530 copy_service(lp_ctx
->currentService
,
1532 lp_ctx
->currentService
->copymap
);
1536 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1544 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
1545 const char *pszParmValue
, char **ptr
)
1547 DEBUGLEVEL
= atoi(pszParmValue
);
1552 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
1553 const char *pszParmValue
, char **ptr
)
1555 if (logfile
!= NULL
) {
1556 free(discard_const_p(char, logfile
));
1558 logfile
= strdup(pszParmValue
);
1562 /***************************************************************************
1563 Initialise a copymap.
1564 ***************************************************************************/
1566 static void init_copymap(struct loadparm_service
*pservice
)
1569 talloc_free(pservice
->copymap
);
1570 pservice
->copymap
= talloc_array(pservice
, int, NUMPARAMETERS
);
1571 if (pservice
->copymap
== NULL
) {
1573 ("Couldn't allocate copymap!! (size %d)\n",
1574 (int)NUMPARAMETERS
));
1577 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1578 pservice
->copymap
[i
] = true;
1582 * Process a parametric option
1584 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1585 struct loadparm_service
*service
,
1586 const char *pszParmName
,
1587 const char *pszParmValue
, int flags
)
1589 struct parmlist_entry
*paramo
, *data
;
1591 TALLOC_CTX
*mem_ctx
;
1593 while (isspace((unsigned char)*pszParmName
)) {
1597 name
= strdup(pszParmName
);
1598 if (!name
) return false;
1602 if (service
== NULL
) {
1603 data
= lp_ctx
->globals
->param_opt
;
1604 mem_ctx
= lp_ctx
->globals
;
1606 data
= service
->param_opt
;
1610 /* Traverse destination */
1611 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1612 /* If we already have the option set, override it unless
1613 it was a command line option and the new one isn't */
1614 if (strcmp(paramo
->key
, name
) == 0) {
1615 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1616 !(flags
& FLAG_CMDLINE
)) {
1620 talloc_free(paramo
->value
);
1621 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1622 paramo
->priority
= flags
;
1628 paramo
= talloc(mem_ctx
, struct parmlist_entry
);
1631 paramo
->key
= talloc_strdup(paramo
, name
);
1632 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1633 paramo
->priority
= flags
;
1634 if (service
== NULL
) {
1635 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1637 DLIST_ADD(service
->param_opt
, paramo
);
1645 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1646 const char *pszParmName
, const char *pszParmValue
,
1647 struct loadparm_context
*lp_ctx
)
1650 /* if it is a special case then go ahead */
1651 if (parm_table
[parmnum
].special
) {
1652 parm_table
[parmnum
].special(lp_ctx
, pszParmValue
,
1657 /* now switch on the type of variable it is */
1658 switch (parm_table
[parmnum
].type
)
1662 if (!set_boolean(pszParmValue
, &b
)) {
1663 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1666 *(int *)parm_ptr
= b
;
1671 *(int *)parm_ptr
= atoi(pszParmValue
);
1675 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1681 if (conv_str_size(pszParmValue
, &val
)) {
1682 if (val
<= INT_MAX
) {
1683 *(int *)parm_ptr
= (int)val
;
1688 DEBUG(0,("lp_do_parameter(%s): value is not "
1689 "a valid size specifier!\n", pszParmValue
));
1694 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1695 pszParmValue
, NULL
);
1699 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1703 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1704 strupper(*(char **)parm_ptr
);
1708 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1711 parm_table
[parmnum
].enum_list
[i
].name
)) {
1713 parm_table
[parmnum
].
1718 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1719 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1720 pszParmValue
, pszParmName
));
1726 if (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
) {
1727 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1728 /* we have to also unset FLAG_DEFAULT on aliases */
1729 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1730 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1732 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1733 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1740 bool lp_do_global_parameter(struct loadparm_context
*lp_ctx
,
1741 const char *pszParmName
, const char *pszParmValue
)
1743 int parmnum
= map_parameter(pszParmName
);
1747 if (strchr(pszParmName
, ':')) {
1748 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1750 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1754 /* if the flag has been set on the command line, then don't allow override,
1755 but don't report an error */
1756 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1760 parm_ptr
= lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1762 return set_variable(lp_ctx
, parmnum
, parm_ptr
,
1763 pszParmName
, pszParmValue
, lp_ctx
);
1766 bool lp_do_service_parameter(struct loadparm_context
*lp_ctx
,
1767 struct loadparm_service
*service
,
1768 const char *pszParmName
, const char *pszParmValue
)
1772 int parmnum
= map_parameter(pszParmName
);
1775 if (strchr(pszParmName
, ':')) {
1776 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1778 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1782 /* if the flag has been set on the command line, then don't allow override,
1783 but don't report an error */
1784 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1788 if (parm_table
[parmnum
].pclass
== P_GLOBAL
) {
1790 ("Global parameter %s found in service section!\n",
1794 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1796 if (!service
->copymap
)
1797 init_copymap(service
);
1799 /* this handles the aliases - set the copymap for other
1800 * entries with the same data pointer */
1801 for (i
= 0; parm_table
[i
].label
; i
++)
1802 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1803 parm_table
[i
].pclass
== parm_table
[parmnum
].pclass
)
1804 service
->copymap
[i
] = false;
1806 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1807 pszParmValue
, lp_ctx
);
1811 * Process a parameter.
1814 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1817 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1819 if (lp_ctx
->bInGlobalSection
)
1820 return lp_do_global_parameter(lp_ctx
, pszParmName
,
1823 return lp_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1824 pszParmName
, pszParmValue
);
1828 variable argument do parameter
1830 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1831 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1832 const char *pszParmName
, const char *fmt
, ...)
1839 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1841 ret
= lp_do_global_parameter(lp_ctx
, pszParmName
, s
);
1848 set a parameter from the commandline - this is called from command line parameter
1849 parsing code. It sets the parameter then marks the parameter as unable to be modified
1850 by smb.conf processing
1852 bool lp_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1853 const char *pszParmValue
)
1855 int parmnum
= map_parameter(pszParmName
);
1858 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1861 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1862 /* set a parametric option */
1863 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1864 pszParmValue
, FLAG_CMDLINE
);
1868 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1872 /* reset the CMDLINE flag in case this has been called before */
1873 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1875 if (!lp_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1879 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1881 /* we have to also set FLAG_CMDLINE on aliases */
1882 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1883 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1885 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1886 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1893 set a option from the commandline in 'a=b' format. Use to support --option
1895 bool lp_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1913 ret
= lp_set_cmdline(lp_ctx
, s
, p
+1);
1919 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1922 * Print a parameter of the specified type.
1925 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1931 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1932 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1934 p
->enum_list
[i
].name
);
1941 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
1946 fprintf(f
, "%d", *(int *)ptr
);
1950 fprintf(f
, "0%o", *(int *)ptr
);
1954 if ((char ***)ptr
&& *(char ***)ptr
) {
1955 char **list
= *(char ***)ptr
;
1957 for (; *list
; list
++)
1958 fprintf(f
, "%s%s", *list
,
1959 ((*(list
+1))?", ":""));
1965 if (*(char **)ptr
) {
1966 fprintf(f
, "%s", *(char **)ptr
);
1973 * Check if two parameters are equal.
1976 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1980 return (*((int *)ptr1
) == *((int *)ptr2
));
1986 return (*((int *)ptr1
) == *((int *)ptr2
));
1989 return str_list_equal((const char **)(*(char ***)ptr1
),
1990 (const char **)(*(char ***)ptr2
));
1995 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2000 return (p1
== p2
|| strequal(p1
, p2
));
2007 * Process a new section (service).
2009 * At this stage all sections are services.
2010 * Later we'll have special sections that permit server parameters to be set.
2011 * Returns True on success, False on failure.
2014 static bool do_section(const char *pszSectionName
, void *userdata
)
2016 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2018 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2019 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2022 /* if we've just struck a global section, note the fact. */
2023 lp_ctx
->bInGlobalSection
= isglobal
;
2025 /* check for multiple global sections */
2026 if (lp_ctx
->bInGlobalSection
) {
2027 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName
));
2031 /* if we have a current service, tidy it up before moving on */
2034 if (lp_ctx
->currentService
!= NULL
)
2035 bRetval
= service_ok(lp_ctx
->currentService
);
2037 /* if all is still well, move to the next record in the services array */
2039 /* We put this here to avoid an odd message order if messages are */
2040 /* issued by the post-processing of a previous section. */
2041 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName
));
2043 if ((lp_ctx
->currentService
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
,
2046 DEBUG(0, ("Failed to add a new service\n"));
2056 * Determine if a particular base parameter is currently set to the default value.
2059 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2061 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2062 if (!defaults_saved
)
2064 switch (parm_table
[i
].type
) {
2066 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2067 (const char **)def_ptr
);
2070 return strequal(parm_table
[i
].def
.svalue
,
2073 return parm_table
[i
].def
.bvalue
==
2079 return parm_table
[i
].def
.ivalue
==
2086 *Display the contents of the global structure.
2089 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2093 struct parmlist_entry
*data
;
2095 fprintf(f
, "# Global parameters\n[global]\n");
2097 for (i
= 0; parm_table
[i
].label
; i
++)
2098 if (parm_table
[i
].pclass
== P_GLOBAL
&&
2099 parm_table
[i
].offset
!= -1 &&
2100 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2101 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2103 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2104 print_parameter(&parm_table
[i
], lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2107 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2108 for (data
= lp_ctx
->globals
->param_opt
; data
;
2109 data
= data
->next
) {
2110 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2117 * Display the contents of a single services record.
2120 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
)
2123 struct parmlist_entry
*data
;
2125 if (pService
!= sDefault
)
2126 fprintf(f
, "\n[%s]\n", pService
->szService
);
2128 for (i
= 0; parm_table
[i
].label
; i
++) {
2129 if (parm_table
[i
].pclass
== P_LOCAL
&&
2130 parm_table
[i
].offset
!= -1 &&
2131 (*parm_table
[i
].label
!= '-') &&
2132 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
2134 if (pService
== sDefault
) {
2135 if (defaults_saved
&& is_default(sDefault
, i
))
2138 if (equal_parameter(parm_table
[i
].type
,
2139 ((char *)pService
) +
2140 parm_table
[i
].offset
,
2141 ((char *)sDefault
) +
2142 parm_table
[i
].offset
))
2146 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2147 print_parameter(&parm_table
[i
],
2148 ((char *)pService
) + parm_table
[i
].offset
, f
);
2152 if (pService
->param_opt
!= NULL
) {
2153 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2154 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2159 bool lp_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2160 struct loadparm_service
*service
,
2161 const char *parm_name
, FILE * f
)
2163 struct parm_struct
*parm
;
2166 parm
= lp_parm_struct(parm_name
);
2171 ptr
= lp_parm_ptr(lp_ctx
, service
,parm
);
2173 print_parameter(parm
, ptr
, f
);
2179 * Return info about the next parameter in a service.
2180 * snum==-1 gives the globals.
2181 * Return NULL when out of parameters.
2184 struct parm_struct
*lp_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
2188 /* do the globals */
2189 for (; parm_table
[*i
].label
; (*i
)++) {
2190 if (parm_table
[*i
].offset
== -1
2191 || (*parm_table
[*i
].label
== '-'))
2195 && (parm_table
[*i
].offset
==
2196 parm_table
[(*i
) - 1].offset
))
2199 return &parm_table
[(*i
)++];
2202 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
2204 for (; parm_table
[*i
].label
; (*i
)++) {
2205 if (parm_table
[*i
].pclass
== P_LOCAL
&&
2206 parm_table
[*i
].offset
!= -1 &&
2207 (*parm_table
[*i
].label
!= '-') &&
2209 (parm_table
[*i
].offset
!=
2210 parm_table
[(*i
) - 1].offset
)))
2212 if (allparameters
||
2213 !equal_parameter(parm_table
[*i
].type
,
2214 ((char *)pService
) +
2215 parm_table
[*i
].offset
,
2216 ((char *)lp_ctx
->sDefault
) +
2217 parm_table
[*i
].offset
))
2219 return &parm_table
[(*i
)++];
2230 * Auto-load some home services.
2232 static void lp_add_auto_services(struct loadparm_context
*lp_ctx
,
2240 * Unload unused services.
2243 void lp_killunused(struct loadparm_context
*lp_ctx
,
2244 struct smbsrv_connection
*smb
,
2245 bool (*snumused
) (struct smbsrv_connection
*, int))
2248 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2249 if (lp_ctx
->services
[i
] == NULL
)
2252 if (!snumused
|| !snumused(smb
, i
)) {
2253 talloc_free(lp_ctx
->services
[i
]);
2254 lp_ctx
->services
[i
] = NULL
;
2260 static int lp_destructor(struct loadparm_context
*lp_ctx
)
2262 struct parmlist_entry
*data
;
2264 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2265 struct parmlist_entry
*next
;
2266 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2268 if (data
->priority
& FLAG_CMDLINE
) continue;
2269 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2278 * Initialise the global parameter structure.
2280 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2284 struct loadparm_context
*lp_ctx
;
2286 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2290 talloc_set_destructor(lp_ctx
, lp_destructor
);
2291 lp_ctx
->bInGlobalSection
= true;
2292 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2293 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2295 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2296 lp_ctx
->sDefault
->bAvailable
= true;
2297 lp_ctx
->sDefault
->bBrowseable
= true;
2298 lp_ctx
->sDefault
->bRead_only
= true;
2299 lp_ctx
->sDefault
->bMap_archive
= true;
2300 lp_ctx
->sDefault
->bStrictLocking
= true;
2301 lp_ctx
->sDefault
->bOplocks
= true;
2302 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2303 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2304 lp_ctx
->sDefault
->iDir_mask
= 0755;
2305 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2307 DEBUG(3, ("Initialising global parameters\n"));
2309 for (i
= 0; parm_table
[i
].label
; i
++) {
2310 if ((parm_table
[i
].type
== P_STRING
||
2311 parm_table
[i
].type
== P_USTRING
) &&
2312 parm_table
[i
].offset
!= -1 &&
2313 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2315 if (parm_table
[i
].pclass
== P_LOCAL
) {
2316 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2318 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2320 *r
= talloc_strdup(lp_ctx
, "");
2324 lp_do_global_parameter(lp_ctx
, "share backend", "classic");
2326 lp_do_global_parameter(lp_ctx
, "server role", "standalone");
2328 /* options that can be set on the command line must be initialised via
2329 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2331 lp_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2333 lp_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2334 myname
= get_myname(lp_ctx
);
2335 lp_do_global_parameter(lp_ctx
, "netbios name", myname
);
2336 talloc_free(myname
);
2337 lp_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2339 lp_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2341 lp_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2342 lp_do_global_parameter(lp_ctx
, "max connections", "-1");
2344 lp_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser");
2345 lp_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
2346 lp_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
2347 lp_do_global_parameter(lp_ctx
, "auth methods:domain controller", "anonymous sam_ignoredomain");
2348 lp_do_global_parameter(lp_ctx
, "auth methods:member server", "anonymous sam winbind");
2349 lp_do_global_parameter(lp_ctx
, "auth methods:standalone", "anonymous sam_ignoredomain");
2350 lp_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2351 lp_do_global_parameter(lp_ctx
, "sam database", "sam.ldb");
2352 lp_do_global_parameter(lp_ctx
, "idmap database", "idmap.ldb");
2353 lp_do_global_parameter(lp_ctx
, "secrets database", "secrets.ldb");
2354 lp_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
2355 lp_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
2356 lp_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
2357 lp_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2359 /* This hive should be dynamically generated by Samba using
2360 data from the sam, but for the moment leave it in a tdb to
2361 keep regedt32 from popping up an annoying dialog. */
2362 lp_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2364 /* using UTF8 by default allows us to support all chars */
2365 lp_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2367 /* Use codepage 850 as a default for the dos character set */
2368 lp_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2371 * Allow the default PASSWD_CHAT to be overridden in local.h.
2373 lp_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2375 lp_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2376 lp_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2377 lp_do_global_parameter(lp_ctx
, "modules dir", dyn_MODULESDIR
);
2378 lp_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2380 lp_do_global_parameter(lp_ctx
, "socket address", "0.0.0.0");
2381 lp_do_global_parameter_var(lp_ctx
, "server string",
2382 "Samba %s", SAMBA_VERSION_STRING
);
2384 lp_do_global_parameter_var(lp_ctx
, "announce version", "%d.%d",
2385 DEFAULT_MAJOR_VERSION
,
2386 DEFAULT_MINOR_VERSION
);
2388 lp_do_global_parameter(lp_ctx
, "password server", "*");
2390 lp_do_global_parameter(lp_ctx
, "max mux", "50");
2391 lp_do_global_parameter(lp_ctx
, "max xmit", "12288");
2392 lp_do_global_parameter(lp_ctx
, "password level", "0");
2393 lp_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2394 lp_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2395 lp_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2396 lp_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2397 lp_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2398 lp_do_global_parameter(lp_ctx
, "security", "USER");
2399 lp_do_global_parameter(lp_ctx
, "paranoid server security", "True");
2400 lp_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2401 lp_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2402 lp_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2403 lp_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2404 lp_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2405 lp_do_global_parameter(lp_ctx
, "announce as", "NT SERVER");
2407 lp_do_global_parameter(lp_ctx
, "TimeServer", "False");
2408 lp_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2409 lp_do_global_parameter(lp_ctx
, "Unicode", "True");
2410 lp_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2411 lp_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2412 lp_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2413 lp_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2415 lp_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2417 lp_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2418 lp_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2420 lp_do_global_parameter(lp_ctx
, "wins support", "False");
2421 lp_do_global_parameter(lp_ctx
, "dns proxy", "True");
2423 lp_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2424 lp_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2425 lp_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2426 lp_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2427 lp_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2428 lp_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2429 lp_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
2431 lp_do_global_parameter(lp_ctx
, "client signing", "Yes");
2432 lp_do_global_parameter(lp_ctx
, "server signing", "auto");
2434 lp_do_global_parameter(lp_ctx
, "use spnego", "True");
2436 lp_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2437 lp_do_global_parameter(lp_ctx
, "nbt port", "137");
2438 lp_do_global_parameter(lp_ctx
, "dgram port", "138");
2439 lp_do_global_parameter(lp_ctx
, "cldap port", "389");
2440 lp_do_global_parameter(lp_ctx
, "krb5 port", "88");
2441 lp_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2442 lp_do_global_parameter(lp_ctx
, "web port", "901");
2444 lp_do_global_parameter(lp_ctx
, "nt status support", "True");
2446 lp_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2447 lp_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2449 lp_do_global_parameter(lp_ctx
, "tls enabled", "True");
2450 lp_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2451 lp_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2452 lp_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2453 lp_do_global_parameter_var(lp_ctx
, "setup directory", "%s",
2456 lp_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2458 lp_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2459 lp_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2460 lp_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SBINDIR
);
2461 lp_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SBINDIR
);
2462 lp_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2464 for (i
= 0; parm_table
[i
].label
; i
++) {
2465 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2466 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2473 const char *lp_configfile(struct loadparm_context
*lp_ctx
)
2475 return lp_ctx
->szConfigFile
;
2478 const char *lp_default_path(void)
2480 if (getenv("SMB_CONF_PATH"))
2481 return getenv("SMB_CONF_PATH");
2483 return dyn_CONFIGFILE
;
2487 * Update the internal state of a loadparm context after settings
2490 static bool lp_update(struct loadparm_context
*lp_ctx
)
2492 lp_add_auto_services(lp_ctx
, lp_auto_services(lp_ctx
));
2494 lp_add_hidden(lp_ctx
, "IPC$", "IPC");
2495 lp_add_hidden(lp_ctx
, "ADMIN$", "DISK");
2497 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2498 lp_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2501 panic_action
= lp_ctx
->globals
->panic_action
;
2503 reload_charcnv(lp_ctx
);
2505 /* FIXME: ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx); */
2507 /* FIXME: This is a bit of a hack, but we can't use a global, since
2508 * not everything that uses lp also uses the socket library */
2509 if (lp_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2510 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2512 unsetenv("SOCKET_TESTNONBLOCK");
2515 /* FIXME: Check locale in environment for this: */
2516 if (strcmp(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)) != 0)
2517 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)));
2519 d_set_iconv((smb_iconv_t
)-1);
2524 bool lp_load_default(struct loadparm_context
*lp_ctx
)
2528 path
= lp_default_path();
2530 if (!file_exist(path
)) {
2531 /* We allow the default smb.conf file to not exist,
2532 * basically the equivalent of an empty file. */
2533 return lp_update(lp_ctx
);
2536 return lp_load(lp_ctx
, path
);
2540 * Load the services array from the services file.
2542 * Return True on success, False on failure.
2544 bool lp_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2549 filename
= talloc_strdup(lp_ctx
, filename
);
2551 lp_ctx
->szConfigFile
= filename
;
2553 lp_ctx
->bInGlobalSection
= true;
2554 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2555 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2
));
2557 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2559 /* We get sections first, so have to start 'behind' to make up */
2560 lp_ctx
->currentService
= NULL
;
2561 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2563 /* finish up the last section */
2564 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2566 if (lp_ctx
->currentService
!= NULL
)
2567 bRetval
= service_ok(lp_ctx
->currentService
);
2569 bRetval
= bRetval
&& lp_update(lp_ctx
);
2571 /* we do this unconditionally, so that it happens even
2572 for a missing smb.conf */
2573 reload_charcnv(lp_ctx
);
2575 if (bRetval
== true) {
2576 /* set this up so that any child python tasks will
2577 find the right smb.conf */
2578 setenv("SMB_CONF_PATH", filename
, 1);
2585 * Return the max number of services.
2588 int lp_numservices(struct loadparm_context
*lp_ctx
)
2590 return lp_ctx
->iNumServices
;
2594 * Display the contents of the services array in human-readable form.
2597 void lp_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2603 defaults_saved
= false;
2605 dump_globals(lp_ctx
, f
, show_defaults
);
2607 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
);
2609 for (iService
= 0; iService
< maxtoprint
; iService
++)
2610 lp_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2614 * Display the contents of one service in human-readable form.
2616 void lp_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2618 if (service
!= NULL
) {
2619 if (service
->szService
[0] == '\0')
2621 dump_a_service(service
, sDefault
, f
);
2625 struct loadparm_service
*lp_servicebynum(struct loadparm_context
*lp_ctx
,
2628 return lp_ctx
->services
[snum
];
2631 struct loadparm_service
*lp_service(struct loadparm_context
*lp_ctx
,
2632 const char *service_name
)
2637 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2638 if (lp_ctx
->services
[iService
] &&
2639 lp_ctx
->services
[iService
]->szService
) {
2641 * The substitution here is used to support %U is
2644 serviceName
= standard_sub_basic(
2645 lp_ctx
->services
[iService
],
2646 lp_ctx
->services
[iService
]->szService
);
2647 if (strequal(serviceName
, service_name
)) {
2648 talloc_free(serviceName
);
2649 return lp_ctx
->services
[iService
];
2651 talloc_free(serviceName
);
2655 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name
));
2661 * A useful volume label function.
2663 const char *volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2665 const char *ret
= lp_volume(service
, sDefault
);
2667 return lp_servicename(service
);
2673 * If we are PDC then prefer us as DMB
2675 const char *lp_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2677 const char *ret
= _lp_printername(service
, sDefault
);
2678 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2679 ret
= lp_servicename(service
);
2686 * Return the max print jobs per queue.
2688 int lp_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2690 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2691 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2692 maxjobs
= PRINT_MAX_JOBID
- 1;
2697 struct smb_iconv_convenience
*lp_iconv_convenience(struct loadparm_context
*lp_ctx
)
2699 if (lp_ctx
== NULL
) {
2700 static struct smb_iconv_convenience
*fallback_ic
= NULL
;
2701 if (fallback_ic
== NULL
)
2702 fallback_ic
= smb_iconv_convenience_reinit(talloc_autofree_context(),
2703 "CP850", "UTF8", true, NULL
);
2706 return lp_ctx
->iconv_convenience
;
2709 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2711 struct smb_iconv_convenience
*old_ic
= lp_ctx
->iconv_convenience
;
2712 if (old_ic
== NULL
) {
2713 old_ic
= global_iconv_convenience
;
2715 lp_ctx
->iconv_convenience
= smb_iconv_convenience_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2716 global_iconv_convenience
= lp_ctx
->iconv_convenience
;
2719 void lp_smbcli_options(struct loadparm_context
*lp_ctx
,
2720 struct smbcli_options
*options
)
2722 options
->max_xmit
= lp_max_xmit(lp_ctx
);
2723 options
->max_mux
= lp_maxmux(lp_ctx
);
2724 options
->use_spnego
= lp_nt_status_support(lp_ctx
) && lp_use_spnego(lp_ctx
);
2725 options
->signing
= lp_client_signing(lp_ctx
);
2726 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
2727 options
->ntstatus_support
= lp_nt_status_support(lp_ctx
);
2728 options
->max_protocol
= lp_cli_maxprotocol(lp_ctx
);
2729 options
->unicode
= lp_unicode(lp_ctx
);
2730 options
->use_oplocks
= true;
2731 options
->use_level2_oplocks
= true;
2734 void lp_smbcli_session_options(struct loadparm_context
*lp_ctx
,
2735 struct smbcli_session_options
*options
)
2737 options
->lanman_auth
= lp_client_lanman_auth(lp_ctx
);
2738 options
->ntlmv2_auth
= lp_client_ntlmv2_auth(lp_ctx
);
2739 options
->plaintext_auth
= lp_client_plaintext_auth(lp_ctx
);
2742 _PUBLIC_
char *lp_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2744 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2747 _PUBLIC_
char *lp_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2749 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2752 _PUBLIC_
char *lp_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2754 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2757 _PUBLIC_
char *lp_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2759 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2762 _PUBLIC_
char *lp_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2764 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2767 _PUBLIC_
struct dcerpc_server_info
*lp_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2769 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
2771 ret
->domain_name
= talloc_reference(mem_ctx
, lp_workgroup(lp_ctx
));
2772 ret
->version_major
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
2773 ret
->version_minor
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
2774 ret
->version_build
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
2779 struct gensec_settings
*lp_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2781 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
2782 if (settings
== NULL
)
2784 SMB_ASSERT(lp_ctx
!= NULL
);
2785 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2786 settings
->target_hostname
= lp_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");