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
;
130 char *swat_directory
;
148 int paranoid_server_security
;
151 int announce_as
; /* This is initialised in init_globals */
158 char *socket_options
;
163 int bPreferredMaster
;
164 int bEncryptPasswords
;
166 int bObeyPamRestrictions
;
171 int bBindInterfacesOnly
;
173 int bNTStatusSupport
;
179 int bClientPlaintextAuth
;
180 int bClientLanManAuth
;
181 int bClientNTLMv2Auth
;
182 int client_use_spnego_principal
;
188 char *szNTPSignDSocketDirectory
;
190 char *szDNSUpdateCommand
;
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 {"swat directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(swat_directory
), NULL
, NULL
},
418 {"large readwrite", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLargeReadwrite
), NULL
, NULL
},
419 {"server max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_maxprotocol
), NULL
, enum_protocol
},
420 {"server min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_minprotocol
), NULL
, enum_protocol
},
421 {"client max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_maxprotocol
), NULL
, enum_protocol
},
422 {"client min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_minprotocol
), NULL
, enum_protocol
},
423 {"unicode", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnicode
), NULL
, NULL
},
424 {"read raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bReadRaw
), NULL
, NULL
},
425 {"write raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWriteRaw
), NULL
, NULL
},
426 {"disable netbios", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bDisableNetbios
), NULL
, NULL
},
428 {"nt status support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTStatusSupport
), NULL
, NULL
},
430 {"announce version", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAnnounceVersion
), NULL
, NULL
},
431 {"announce as", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(announce_as
), NULL
, enum_announce_as
},
432 {"max mux", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_mux
), NULL
, NULL
},
433 {"max xmit", P_BYTES
, P_GLOBAL
, GLOBAL_VAR(max_xmit
), NULL
, NULL
},
435 {"name resolve order", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNameResolveOrder
), NULL
, NULL
},
436 {"max wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_wins_ttl
), NULL
, NULL
},
437 {"min wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(min_wins_ttl
), NULL
, NULL
},
438 {"time server", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bTimeServer
), NULL
, NULL
},
439 {"unix extensions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnixExtensions
), NULL
, NULL
},
440 {"use spnego", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUseSpnego
), NULL
, NULL
},
441 {"server signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_signing
), NULL
, enum_smb_signing_vals
},
442 {"client signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(client_signing
), NULL
, enum_smb_signing_vals
},
443 {"rpc big endian", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bRpcBigEndian
), NULL
, NULL
},
445 {"max connections", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxConnections
), NULL
, NULL
},
446 {"paranoid server security", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(paranoid_server_security
), NULL
, NULL
},
447 {"socket options", P_STRING
, P_GLOBAL
, GLOBAL_VAR(socket_options
), NULL
, NULL
},
449 {"strict sync", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictSync
), NULL
, NULL
},
450 {"case insensitive filesystem", P_BOOL
, P_LOCAL
, LOCAL_VAR(bCIFileSystem
), NULL
, NULL
},
452 {"max print jobs", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxPrintJobs
), NULL
, NULL
},
453 {"printable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
454 {"print ok", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
456 {"printer name", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
457 {"printer", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
459 {"map system", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_system
), NULL
, NULL
},
460 {"map hidden", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_hidden
), NULL
, NULL
},
461 {"map archive", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_archive
), NULL
, NULL
},
463 {"preferred master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
464 {"prefered master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
465 {"local master", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLocalMaster
), NULL
, NULL
},
466 {"browseable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
467 {"browsable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
469 {"wins server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szWINSservers
), NULL
, NULL
},
470 {"wins support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSsupport
), NULL
, NULL
},
471 {"dns proxy", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSdnsProxy
), NULL
, NULL
},
472 {"wins hook", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINSHook
), NULL
, NULL
},
474 {"csc policy", P_ENUM
, P_LOCAL
, LOCAL_VAR(iCSCPolicy
), NULL
, enum_csc_policy
},
476 {"strict locking", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictLocking
), NULL
, NULL
},
477 {"oplocks", P_BOOL
, P_LOCAL
, LOCAL_VAR(bOplocks
), NULL
, NULL
},
479 {"share backend", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szShareBackend
), NULL
, NULL
},
480 {"preload", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
481 {"auto services", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
482 {"lock dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
483 {"lock directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
484 {"modules dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szModulesDir
), NULL
, NULL
},
485 {"pid directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPidDir
), NULL
, NULL
},
486 {"setup directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSetupDir
), NULL
, NULL
},
488 {"socket address", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSocketAddress
), NULL
, NULL
},
489 {"copy", P_STRING
, P_LOCAL
, LOCAL_VAR(szCopy
), handle_copy
, NULL
},
490 {"include", P_STRING
, P_LOCAL
, LOCAL_VAR(szInclude
), handle_include
, NULL
},
492 {"available", P_BOOL
, P_LOCAL
, LOCAL_VAR(bAvailable
), NULL
, NULL
},
493 {"volume", P_STRING
, P_LOCAL
, LOCAL_VAR(volume
), NULL
, NULL
},
494 {"fstype", P_STRING
, P_LOCAL
, LOCAL_VAR(fstype
), NULL
, NULL
},
496 {"panic action", P_STRING
, P_GLOBAL
, GLOBAL_VAR(panic_action
), NULL
, NULL
},
498 {"msdfs root", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMSDfsRoot
), NULL
, NULL
},
499 {"host msdfs", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bHostMSDfs
), NULL
, NULL
},
500 {"winbind separator", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbindSeparator
), NULL
, NULL
},
501 {"winbindd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddSocketDirectory
), NULL
, NULL
},
502 {"winbindd privileged socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
), NULL
, NULL
},
503 {"winbind sealed pipes", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWinbindSealedPipes
), NULL
, NULL
},
504 {"template shell", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateShell
), NULL
, NULL
},
505 {"template homedir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateHomedir
), NULL
, NULL
},
506 {"idmap trusted only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bIdmapTrustedOnly
), NULL
, NULL
},
508 {"ntp signd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szNTPSignDSocketDirectory
), NULL
, NULL
},
509 {"rndc command", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szRNDCCommand
), NULL
, NULL
},
510 {"dns update command", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szDNSUpdateCommand
), 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
;
524 struct loadparm_service
*currentService
;
525 bool bInGlobalSection
;
527 struct file_lists
*next
;
532 unsigned int flags
[NUMPARAMETERS
];
533 struct smb_iconv_convenience
*iconv_convenience
;
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_STRING(lp_swat_directory
, swat_directory
)
638 _PUBLIC_
FN_GLOBAL_BOOL(lp_tls_enabled
, tls_enabled
)
639 _PUBLIC_
FN_GLOBAL_STRING(lp_share_backend
, szShareBackend
)
640 _PUBLIC_
FN_GLOBAL_STRING(lp_sam_url
, szSAM_URL
)
641 _PUBLIC_
FN_GLOBAL_STRING(lp_idmap_url
, szIDMAP_URL
)
642 _PUBLIC_
FN_GLOBAL_STRING(lp_secrets_url
, szSECRETS_URL
)
643 _PUBLIC_
FN_GLOBAL_STRING(lp_spoolss_url
, szSPOOLSS_URL
)
644 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_config_url
, szWINS_CONFIG_URL
)
645 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_url
, szWINS_URL
)
646 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbind_separator
, szWinbindSeparator
)
647 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory
, szWinbinddSocketDirectory
)
648 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
649 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_shell
, szTemplateShell
)
650 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_homedir
, szTemplateHomedir
)
651 _PUBLIC_
FN_GLOBAL_BOOL(lp_winbind_sealed_pipes
, bWinbindSealedPipes
)
652 _PUBLIC_
FN_GLOBAL_BOOL(lp_idmap_trusted_only
, bIdmapTrustedOnly
)
653 _PUBLIC_
FN_GLOBAL_STRING(lp_private_dir
, szPrivateDir
)
654 _PUBLIC_
FN_GLOBAL_STRING(lp_serverstring
, szServerString
)
655 _PUBLIC_
FN_GLOBAL_STRING(lp_lockdir
, szLockDir
)
656 _PUBLIC_
FN_GLOBAL_STRING(lp_modulesdir
, szModulesDir
)
657 _PUBLIC_
FN_GLOBAL_STRING(lp_setupdir
, szSetupDir
)
658 _PUBLIC_
FN_GLOBAL_STRING(lp_ncalrpc_dir
, ncalrpc_dir
)
659 _PUBLIC_
FN_GLOBAL_STRING(lp_dos_charset
, dos_charset
)
660 _PUBLIC_
FN_GLOBAL_STRING(lp_unix_charset
, unix_charset
)
661 _PUBLIC_
FN_GLOBAL_STRING(lp_display_charset
, display_charset
)
662 _PUBLIC_
FN_GLOBAL_STRING(lp_piddir
, szPidDir
)
663 _PUBLIC_
FN_GLOBAL_STRING(lp_rndc_command
, szRNDCCommand
)
664 _PUBLIC_
FN_GLOBAL_STRING(lp_dns_update_command
, szDNSUpdateCommand
)
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
);
786 if (strcmp(data
->key
, vfskey
) == 0) {
793 if (service
!= NULL
) {
794 /* Try to fetch the same option but from globals */
795 /* but only if we are not already working with globals */
796 for (data
= lp_ctx
->globals
->param_opt
; data
;
798 if (strcmp(data
->key
, vfskey
) == 0) {
812 * convenience routine to return int parameters.
814 static int lp_int(const char *s
)
818 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
822 return strtol(s
, NULL
, 0);
826 * convenience routine to return unsigned long parameters.
828 static int lp_ulong(const char *s
)
832 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
836 return strtoul(s
, NULL
, 0);
840 * convenience routine to return unsigned long parameters.
842 static double lp_double(const char *s
)
846 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
850 return strtod(s
, NULL
);
854 * convenience routine to return boolean parameters.
856 static bool lp_bool(const char *s
)
861 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
865 if (!set_boolean(s
, &ret
)) {
866 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
875 * Return parametric option from a given service. Type is a part of option before ':'
876 * Parametric option has following syntax: 'Type: option = value'
877 * Returned value is allocated in 'lp_talloc' context
880 const char *lp_parm_string(struct loadparm_context
*lp_ctx
,
881 struct loadparm_service
*service
, const char *type
,
884 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
887 return lp_string(value
);
893 * Return parametric option from a given service. Type is a part of option before ':'
894 * Parametric option has following syntax: 'Type: option = value'
895 * Returned value is allocated in 'lp_talloc' context
898 const char **lp_parm_string_list(TALLOC_CTX
*mem_ctx
,
899 struct loadparm_context
*lp_ctx
,
900 struct loadparm_service
*service
,
902 const char *option
, const char *separator
)
904 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
907 return (const char **)str_list_make(mem_ctx
, value
, separator
);
913 * Return parametric option from a given service. Type is a part of option before ':'
914 * Parametric option has following syntax: 'Type: option = value'
917 int lp_parm_int(struct loadparm_context
*lp_ctx
,
918 struct loadparm_service
*service
, const char *type
,
919 const char *option
, int default_v
)
921 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
924 return lp_int(value
);
930 * Return parametric option from a given service. Type is a part of
932 * Parametric option has following syntax: 'Type: option = value'.
935 int lp_parm_bytes(struct loadparm_context
*lp_ctx
,
936 struct loadparm_service
*service
, const char *type
,
937 const char *option
, int default_v
)
941 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
943 if (value
&& conv_str_size(value
, &bval
)) {
944 if (bval
<= INT_MAX
) {
953 * Return parametric option from a given service.
954 * Type is a part of option before ':'
955 * Parametric option has following syntax: 'Type: option = value'
957 unsigned long lp_parm_ulong(struct loadparm_context
*lp_ctx
,
958 struct loadparm_service
*service
, const char *type
,
959 const char *option
, unsigned long default_v
)
961 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
964 return lp_ulong(value
);
970 double lp_parm_double(struct loadparm_context
*lp_ctx
,
971 struct loadparm_service
*service
, const char *type
,
972 const char *option
, double default_v
)
974 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
977 return lp_double(value
);
983 * Return parametric option from a given service. Type is a part of option before ':'
984 * Parametric option has following syntax: 'Type: option = value'
987 bool lp_parm_bool(struct loadparm_context
*lp_ctx
,
988 struct loadparm_service
*service
, const char *type
,
989 const char *option
, bool default_v
)
991 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
994 return lp_bool(value
);
1001 * Initialise a service to the defaults.
1004 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1006 struct loadparm_service
*pservice
=
1007 talloc_zero(mem_ctx
, struct loadparm_service
);
1008 copy_service(pservice
, sDefault
, NULL
);
1013 * Set a string value, deallocating any existing space, and allocing the space
1016 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1023 *dest
= talloc_strdup(mem_ctx
, src
);
1024 if ((*dest
) == NULL
) {
1025 DEBUG(0,("Out of memory in string_init\n"));
1035 * Add a new service to the services array initialising it with the given
1039 struct loadparm_service
*lp_add_service(struct loadparm_context
*lp_ctx
,
1040 const struct loadparm_service
*pservice
,
1044 struct loadparm_service tservice
;
1045 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1046 struct parmlist_entry
*data
, *pdata
;
1048 tservice
= *pservice
;
1050 /* it might already exist */
1052 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1054 if (service
!= NULL
) {
1055 /* Clean all parametric options for service */
1056 /* They will be added during parsing again */
1057 data
= service
->param_opt
;
1063 service
->param_opt
= NULL
;
1068 /* find an invalid one */
1069 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1070 if (lp_ctx
->services
[i
] == NULL
)
1073 /* if not, then create one */
1074 if (i
== lp_ctx
->iNumServices
) {
1075 struct loadparm_service
**tsp
;
1077 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1080 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1083 lp_ctx
->services
= tsp
;
1084 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1087 lp_ctx
->iNumServices
++;
1090 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1091 if (lp_ctx
->services
[i
] == NULL
) {
1092 DEBUG(0,("lp_add_service: out of memory!\n"));
1095 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1097 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1098 return lp_ctx
->services
[i
];
1102 * Add a new home service, with the specified home directory, defaults coming
1103 * from service ifrom.
1106 bool lp_add_home(struct loadparm_context
*lp_ctx
,
1107 const char *pszHomename
,
1108 struct loadparm_service
*default_service
,
1109 const char *user
, const char *pszHomedir
)
1111 struct loadparm_service
*service
;
1113 service
= lp_add_service(lp_ctx
, default_service
, pszHomename
);
1115 if (service
== NULL
)
1118 if (!(*(default_service
->szPath
))
1119 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1120 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1122 service
->szPath
= string_sub_talloc(service
, lp_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1125 if (!(*(service
->comment
))) {
1126 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1128 service
->bAvailable
= default_service
->bAvailable
;
1129 service
->bBrowseable
= default_service
->bBrowseable
;
1131 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1132 pszHomename
, user
, service
->szPath
));
1138 * Add the IPC service.
1141 static bool lp_add_hidden(struct loadparm_context
*lp_ctx
, const char *name
,
1144 struct loadparm_service
*service
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
, name
);
1146 if (service
== NULL
)
1149 string_set(service
, &service
->szPath
, tmpdir());
1151 service
->comment
= talloc_asprintf(service
, "%s Service (%s)",
1152 fstype
, lp_ctx
->globals
->szServerString
);
1153 string_set(service
, &service
->fstype
, fstype
);
1154 service
->iMaxConnections
= -1;
1155 service
->bAvailable
= true;
1156 service
->bRead_only
= true;
1157 service
->bPrint_ok
= false;
1158 service
->bBrowseable
= false;
1160 if (strcasecmp(fstype
, "IPC") == 0) {
1161 lp_do_service_parameter(lp_ctx
, service
, "ntvfs handler",
1165 DEBUG(3, ("adding hidden service %s\n", name
));
1171 * Add a new printer service, with defaults coming from service iFrom.
1174 bool lp_add_printer(struct loadparm_context
*lp_ctx
,
1175 const char *pszPrintername
,
1176 struct loadparm_service
*default_service
)
1178 const char *comment
= "From Printcap";
1179 struct loadparm_service
*service
;
1180 service
= lp_add_service(lp_ctx
, default_service
, pszPrintername
);
1182 if (service
== NULL
)
1185 /* note that we do NOT default the availability flag to True - */
1186 /* we take it from the default service passed. This allows all */
1187 /* dynamic printers to be disabled by disabling the [printers] */
1188 /* entry (if/when the 'available' keyword is implemented!). */
1190 /* the printer name is set to the service name. */
1191 string_set(service
, &service
->szPrintername
, pszPrintername
);
1192 string_set(service
, &service
->comment
, comment
);
1193 service
->bBrowseable
= default_service
->bBrowseable
;
1194 /* Printers cannot be read_only. */
1195 service
->bRead_only
= false;
1196 /* Printer services must be printable. */
1197 service
->bPrint_ok
= true;
1199 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1205 * Map a parameter's string representation to something we can use.
1206 * Returns False if the parameter string is not recognised, else TRUE.
1209 static int map_parameter(const char *pszParmName
)
1213 if (*pszParmName
== '-')
1216 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1217 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1220 /* Warn only if it isn't parametric option */
1221 if (strchr(pszParmName
, ':') == NULL
)
1222 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
1223 /* We do return 'fail' for parametric options as well because they are
1224 stored in different storage
1231 return the parameter structure for a parameter
1233 struct parm_struct
*lp_parm_struct(const char *name
)
1235 int parmnum
= map_parameter(name
);
1236 if (parmnum
== -1) return NULL
;
1237 return &parm_table
[parmnum
];
1241 return the parameter pointer for a parameter
1243 void *lp_parm_ptr(struct loadparm_context
*lp_ctx
,
1244 struct loadparm_service
*service
, struct parm_struct
*parm
)
1246 if (service
== NULL
) {
1247 if (parm
->pclass
== P_LOCAL
)
1248 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
1249 else if (parm
->pclass
== P_GLOBAL
)
1250 return ((char *)lp_ctx
->globals
)+parm
->offset
;
1253 return ((char *)service
) + parm
->offset
;
1258 * Find a service by name. Otherwise works like get_service.
1261 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1262 const char *pszServiceName
)
1266 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
1267 if (lp_ctx
->services
[iService
] != NULL
&&
1268 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
1269 return lp_ctx
->services
[iService
];
1276 * Copy a service structure to another.
1277 * If pcopymapDest is NULL then copy all fields
1280 static void copy_service(struct loadparm_service
*pserviceDest
,
1281 struct loadparm_service
*pserviceSource
,
1285 bool bcopyall
= (pcopymapDest
== NULL
);
1286 struct parmlist_entry
*data
, *pdata
, *paramo
;
1289 for (i
= 0; parm_table
[i
].label
; i
++)
1290 if (parm_table
[i
].offset
!= -1 && parm_table
[i
].pclass
== P_LOCAL
&&
1291 (bcopyall
|| pcopymapDest
[i
])) {
1293 ((char *)pserviceSource
) + parm_table
[i
].offset
;
1295 ((char *)pserviceDest
) + parm_table
[i
].offset
;
1297 switch (parm_table
[i
].type
) {
1299 *(int *)dest_ptr
= *(int *)src_ptr
;
1305 *(int *)dest_ptr
= *(int *)src_ptr
;
1309 string_set(pserviceDest
,
1315 string_set(pserviceDest
,
1318 strupper(*(char **)dest_ptr
);
1321 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
1322 *(const char ***)src_ptr
);
1330 init_copymap(pserviceDest
);
1331 if (pserviceSource
->copymap
)
1332 memcpy((void *)pserviceDest
->copymap
,
1333 (void *)pserviceSource
->copymap
,
1334 sizeof(int) * NUMPARAMETERS
);
1337 data
= pserviceSource
->param_opt
;
1340 pdata
= pserviceDest
->param_opt
;
1341 /* Traverse destination */
1343 /* If we already have same option, override it */
1344 if (strcmp(pdata
->key
, data
->key
) == 0) {
1345 talloc_free(pdata
->value
);
1346 pdata
->value
= talloc_reference(pdata
,
1351 pdata
= pdata
->next
;
1354 paramo
= talloc(pserviceDest
, struct parmlist_entry
);
1357 paramo
->key
= talloc_reference(paramo
, data
->key
);
1358 paramo
->value
= talloc_reference(paramo
, data
->value
);
1359 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1366 * Check a service for consistency. Return False if the service is in any way
1367 * incomplete or faulty, else True.
1369 static bool service_ok(struct loadparm_service
*service
)
1374 if (service
->szService
[0] == '\0') {
1375 DEBUG(0, ("The following message indicates an internal error:\n"));
1376 DEBUG(0, ("No service name in service entry.\n"));
1380 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1381 /* I can't see why you'd want a non-printable printer service... */
1382 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1383 if (!service
->bPrint_ok
) {
1384 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1385 service
->szService
));
1386 service
->bPrint_ok
= true;
1388 /* [printers] service must also be non-browsable. */
1389 if (service
->bBrowseable
)
1390 service
->bBrowseable
= false;
1393 /* If a service is flagged unavailable, log the fact at level 0. */
1394 if (!service
->bAvailable
)
1395 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1396 service
->szService
));
1402 /*******************************************************************
1403 Keep a linked list of all config files so we know when one has changed
1404 it's date and needs to be reloaded.
1405 ********************************************************************/
1407 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1408 const char *fname
, const char *subfname
)
1410 struct file_lists
*f
= lp_ctx
->file_lists
;
1413 if (f
->name
&& !strcmp(f
->name
, fname
))
1419 f
= talloc(lp_ctx
, struct file_lists
);
1422 f
->next
= lp_ctx
->file_lists
;
1423 f
->name
= talloc_strdup(f
, fname
);
1428 f
->subfname
= talloc_strdup(f
, subfname
);
1433 lp_ctx
->file_lists
= f
;
1434 f
->modtime
= file_modtime(subfname
);
1436 time_t t
= file_modtime(subfname
);
1442 /*******************************************************************
1443 Check if a config file has changed date.
1444 ********************************************************************/
1445 bool lp_file_list_changed(struct loadparm_context
*lp_ctx
)
1447 struct file_lists
*f
;
1448 DEBUG(6, ("lp_file_list_changed()\n"));
1450 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1454 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1456 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1457 f
->name
, n2
, ctime(&f
->modtime
)));
1459 mod_time
= file_modtime(n2
);
1461 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1462 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1464 f
->modtime
= mod_time
;
1465 talloc_free(f
->subfname
);
1466 f
->subfname
= talloc_strdup(f
, n2
);
1473 /***************************************************************************
1474 Handle the "realm" parameter
1475 ***************************************************************************/
1477 static bool handle_realm(struct loadparm_context
*lp_ctx
,
1478 const char *pszParmValue
, char **ptr
)
1480 string_set(lp_ctx
, ptr
, pszParmValue
);
1482 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1483 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1488 /***************************************************************************
1489 Handle the include operation.
1490 ***************************************************************************/
1492 static bool handle_include(struct loadparm_context
*lp_ctx
,
1493 const char *pszParmValue
, char **ptr
)
1495 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1497 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1499 string_set(lp_ctx
, ptr
, fname
);
1501 if (file_exist(fname
))
1502 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1504 DEBUG(2, ("Can't find include file %s\n", fname
));
1509 /***************************************************************************
1510 Handle the interpretation of the copy parameter.
1511 ***************************************************************************/
1513 static bool handle_copy(struct loadparm_context
*lp_ctx
,
1514 const char *pszParmValue
, char **ptr
)
1517 struct loadparm_service
*serviceTemp
;
1519 string_set(lp_ctx
, ptr
, pszParmValue
);
1523 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1525 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1526 if (serviceTemp
== lp_ctx
->currentService
) {
1527 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1529 copy_service(lp_ctx
->currentService
,
1531 lp_ctx
->currentService
->copymap
);
1535 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1543 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
1544 const char *pszParmValue
, char **ptr
)
1546 DEBUGLEVEL
= atoi(pszParmValue
);
1551 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
1552 const char *pszParmValue
, char **ptr
)
1554 if (logfile
!= NULL
) {
1555 free(discard_const_p(char, logfile
));
1557 logfile
= strdup(pszParmValue
);
1561 /***************************************************************************
1562 Initialise a copymap.
1563 ***************************************************************************/
1565 static void init_copymap(struct loadparm_service
*pservice
)
1568 talloc_free(pservice
->copymap
);
1569 pservice
->copymap
= talloc_array(pservice
, int, NUMPARAMETERS
);
1570 if (pservice
->copymap
== NULL
) {
1572 ("Couldn't allocate copymap!! (size %d)\n",
1573 (int)NUMPARAMETERS
));
1576 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1577 pservice
->copymap
[i
] = true;
1581 * Process a parametric option
1583 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1584 struct loadparm_service
*service
,
1585 const char *pszParmName
,
1586 const char *pszParmValue
, int flags
)
1588 struct parmlist_entry
*paramo
, *data
;
1590 TALLOC_CTX
*mem_ctx
;
1592 while (isspace((unsigned char)*pszParmName
)) {
1596 name
= strdup(pszParmName
);
1597 if (!name
) return false;
1601 if (service
== NULL
) {
1602 data
= lp_ctx
->globals
->param_opt
;
1603 mem_ctx
= lp_ctx
->globals
;
1605 data
= service
->param_opt
;
1609 /* Traverse destination */
1610 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1611 /* If we already have the option set, override it unless
1612 it was a command line option and the new one isn't */
1613 if (strcmp(paramo
->key
, name
) == 0) {
1614 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1615 !(flags
& FLAG_CMDLINE
)) {
1619 talloc_free(paramo
->value
);
1620 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1621 paramo
->priority
= flags
;
1627 paramo
= talloc(mem_ctx
, struct parmlist_entry
);
1630 paramo
->key
= talloc_strdup(paramo
, name
);
1631 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1632 paramo
->priority
= flags
;
1633 if (service
== NULL
) {
1634 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1636 DLIST_ADD(service
->param_opt
, paramo
);
1644 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1645 const char *pszParmName
, const char *pszParmValue
,
1646 struct loadparm_context
*lp_ctx
)
1649 /* if it is a special case then go ahead */
1650 if (parm_table
[parmnum
].special
) {
1651 parm_table
[parmnum
].special(lp_ctx
, pszParmValue
,
1656 /* now switch on the type of variable it is */
1657 switch (parm_table
[parmnum
].type
)
1661 if (!set_boolean(pszParmValue
, &b
)) {
1662 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1665 *(int *)parm_ptr
= b
;
1670 *(int *)parm_ptr
= atoi(pszParmValue
);
1674 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1680 if (conv_str_size(pszParmValue
, &val
)) {
1681 if (val
<= INT_MAX
) {
1682 *(int *)parm_ptr
= (int)val
;
1687 DEBUG(0,("lp_do_parameter(%s): value is not "
1688 "a valid size specifier!\n", pszParmValue
));
1693 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1694 pszParmValue
, NULL
);
1698 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1702 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1703 strupper(*(char **)parm_ptr
);
1707 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1710 parm_table
[parmnum
].enum_list
[i
].name
)) {
1712 parm_table
[parmnum
].
1717 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1718 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1719 pszParmValue
, pszParmName
));
1725 if (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
) {
1726 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1727 /* we have to also unset FLAG_DEFAULT on aliases */
1728 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1729 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1731 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1732 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1739 bool lp_do_global_parameter(struct loadparm_context
*lp_ctx
,
1740 const char *pszParmName
, const char *pszParmValue
)
1742 int parmnum
= map_parameter(pszParmName
);
1746 if (strchr(pszParmName
, ':')) {
1747 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1749 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1753 /* if the flag has been set on the command line, then don't allow override,
1754 but don't report an error */
1755 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1759 parm_ptr
= lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1761 return set_variable(lp_ctx
, parmnum
, parm_ptr
,
1762 pszParmName
, pszParmValue
, lp_ctx
);
1765 bool lp_do_service_parameter(struct loadparm_context
*lp_ctx
,
1766 struct loadparm_service
*service
,
1767 const char *pszParmName
, const char *pszParmValue
)
1771 int parmnum
= map_parameter(pszParmName
);
1774 if (strchr(pszParmName
, ':')) {
1775 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1777 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1781 /* if the flag has been set on the command line, then don't allow override,
1782 but don't report an error */
1783 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1787 if (parm_table
[parmnum
].pclass
== P_GLOBAL
) {
1789 ("Global parameter %s found in service section!\n",
1793 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1795 if (!service
->copymap
)
1796 init_copymap(service
);
1798 /* this handles the aliases - set the copymap for other
1799 * entries with the same data pointer */
1800 for (i
= 0; parm_table
[i
].label
; i
++)
1801 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1802 parm_table
[i
].pclass
== parm_table
[parmnum
].pclass
)
1803 service
->copymap
[i
] = false;
1805 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1806 pszParmValue
, lp_ctx
);
1810 * Process a parameter.
1813 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1816 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1818 if (lp_ctx
->bInGlobalSection
)
1819 return lp_do_global_parameter(lp_ctx
, pszParmName
,
1822 return lp_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1823 pszParmName
, pszParmValue
);
1827 variable argument do parameter
1829 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1830 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1831 const char *pszParmName
, const char *fmt
, ...)
1838 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1840 ret
= lp_do_global_parameter(lp_ctx
, pszParmName
, s
);
1847 set a parameter from the commandline - this is called from command line parameter
1848 parsing code. It sets the parameter then marks the parameter as unable to be modified
1849 by smb.conf processing
1851 bool lp_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1852 const char *pszParmValue
)
1854 int parmnum
= map_parameter(pszParmName
);
1857 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1860 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1861 /* set a parametric option */
1862 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1863 pszParmValue
, FLAG_CMDLINE
);
1867 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1871 /* reset the CMDLINE flag in case this has been called before */
1872 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1874 if (!lp_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1878 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1880 /* we have to also set FLAG_CMDLINE on aliases */
1881 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1882 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1884 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1885 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1892 set a option from the commandline in 'a=b' format. Use to support --option
1894 bool lp_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1912 ret
= lp_set_cmdline(lp_ctx
, s
, p
+1);
1918 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1921 * Print a parameter of the specified type.
1924 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1930 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1931 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1933 p
->enum_list
[i
].name
);
1940 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
1945 fprintf(f
, "%d", *(int *)ptr
);
1949 fprintf(f
, "0%o", *(int *)ptr
);
1953 if ((char ***)ptr
&& *(char ***)ptr
) {
1954 char **list
= *(char ***)ptr
;
1956 for (; *list
; list
++)
1957 fprintf(f
, "%s%s", *list
,
1958 ((*(list
+1))?", ":""));
1964 if (*(char **)ptr
) {
1965 fprintf(f
, "%s", *(char **)ptr
);
1972 * Check if two parameters are equal.
1975 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1979 return (*((int *)ptr1
) == *((int *)ptr2
));
1985 return (*((int *)ptr1
) == *((int *)ptr2
));
1988 return str_list_equal((const char **)(*(char ***)ptr1
),
1989 (const char **)(*(char ***)ptr2
));
1994 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1999 return (p1
== p2
|| strequal(p1
, p2
));
2006 * Process a new section (service).
2008 * At this stage all sections are services.
2009 * Later we'll have special sections that permit server parameters to be set.
2010 * Returns True on success, False on failure.
2013 static bool do_section(const char *pszSectionName
, void *userdata
)
2015 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2017 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2018 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2021 /* if we've just struck a global section, note the fact. */
2022 lp_ctx
->bInGlobalSection
= isglobal
;
2024 /* check for multiple global sections */
2025 if (lp_ctx
->bInGlobalSection
) {
2026 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName
));
2030 /* if we have a current service, tidy it up before moving on */
2033 if (lp_ctx
->currentService
!= NULL
)
2034 bRetval
= service_ok(lp_ctx
->currentService
);
2036 /* if all is still well, move to the next record in the services array */
2038 /* We put this here to avoid an odd message order if messages are */
2039 /* issued by the post-processing of a previous section. */
2040 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName
));
2042 if ((lp_ctx
->currentService
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
,
2045 DEBUG(0, ("Failed to add a new service\n"));
2055 * Determine if a particular base parameter is currently set to the default value.
2058 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2060 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2061 if (!defaults_saved
)
2063 switch (parm_table
[i
].type
) {
2065 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2066 (const char **)def_ptr
);
2069 return strequal(parm_table
[i
].def
.svalue
,
2072 return parm_table
[i
].def
.bvalue
==
2078 return parm_table
[i
].def
.ivalue
==
2085 *Display the contents of the global structure.
2088 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2092 struct parmlist_entry
*data
;
2094 fprintf(f
, "# Global parameters\n[global]\n");
2096 for (i
= 0; parm_table
[i
].label
; i
++)
2097 if (parm_table
[i
].pclass
== P_GLOBAL
&&
2098 parm_table
[i
].offset
!= -1 &&
2099 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2100 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2102 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2103 print_parameter(&parm_table
[i
], lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2106 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2107 for (data
= lp_ctx
->globals
->param_opt
; data
;
2108 data
= data
->next
) {
2109 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2116 * Display the contents of a single services record.
2119 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
)
2122 struct parmlist_entry
*data
;
2124 if (pService
!= sDefault
)
2125 fprintf(f
, "\n[%s]\n", pService
->szService
);
2127 for (i
= 0; parm_table
[i
].label
; i
++) {
2128 if (parm_table
[i
].pclass
== P_LOCAL
&&
2129 parm_table
[i
].offset
!= -1 &&
2130 (*parm_table
[i
].label
!= '-') &&
2131 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
2133 if (pService
== sDefault
) {
2134 if (defaults_saved
&& is_default(sDefault
, i
))
2137 if (equal_parameter(parm_table
[i
].type
,
2138 ((char *)pService
) +
2139 parm_table
[i
].offset
,
2140 ((char *)sDefault
) +
2141 parm_table
[i
].offset
))
2145 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2146 print_parameter(&parm_table
[i
],
2147 ((char *)pService
) + parm_table
[i
].offset
, f
);
2151 if (pService
->param_opt
!= NULL
) {
2152 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2153 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2158 bool lp_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2159 struct loadparm_service
*service
,
2160 const char *parm_name
, FILE * f
)
2162 struct parm_struct
*parm
;
2165 parm
= lp_parm_struct(parm_name
);
2170 ptr
= lp_parm_ptr(lp_ctx
, service
,parm
);
2172 print_parameter(parm
, ptr
, f
);
2178 * Return info about the next parameter in a service.
2179 * snum==-1 gives the globals.
2180 * Return NULL when out of parameters.
2183 struct parm_struct
*lp_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
2187 /* do the globals */
2188 for (; parm_table
[*i
].label
; (*i
)++) {
2189 if (parm_table
[*i
].offset
== -1
2190 || (*parm_table
[*i
].label
== '-'))
2194 && (parm_table
[*i
].offset
==
2195 parm_table
[(*i
) - 1].offset
))
2198 return &parm_table
[(*i
)++];
2201 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
2203 for (; parm_table
[*i
].label
; (*i
)++) {
2204 if (parm_table
[*i
].pclass
== P_LOCAL
&&
2205 parm_table
[*i
].offset
!= -1 &&
2206 (*parm_table
[*i
].label
!= '-') &&
2208 (parm_table
[*i
].offset
!=
2209 parm_table
[(*i
) - 1].offset
)))
2211 if (allparameters
||
2212 !equal_parameter(parm_table
[*i
].type
,
2213 ((char *)pService
) +
2214 parm_table
[*i
].offset
,
2215 ((char *)lp_ctx
->sDefault
) +
2216 parm_table
[*i
].offset
))
2218 return &parm_table
[(*i
)++];
2229 * Auto-load some home services.
2231 static void lp_add_auto_services(struct loadparm_context
*lp_ctx
,
2239 * Unload unused services.
2242 void lp_killunused(struct loadparm_context
*lp_ctx
,
2243 struct smbsrv_connection
*smb
,
2244 bool (*snumused
) (struct smbsrv_connection
*, int))
2247 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2248 if (lp_ctx
->services
[i
] == NULL
)
2251 if (!snumused
|| !snumused(smb
, i
)) {
2252 talloc_free(lp_ctx
->services
[i
]);
2253 lp_ctx
->services
[i
] = NULL
;
2259 static int lp_destructor(struct loadparm_context
*lp_ctx
)
2261 struct parmlist_entry
*data
;
2263 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2264 struct parmlist_entry
*next
;
2265 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2267 if (data
->priority
& FLAG_CMDLINE
) continue;
2268 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2277 * Initialise the global parameter structure.
2279 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2283 struct loadparm_context
*lp_ctx
;
2285 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2289 talloc_set_destructor(lp_ctx
, lp_destructor
);
2290 lp_ctx
->bInGlobalSection
= true;
2291 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2292 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2294 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2295 lp_ctx
->sDefault
->bAvailable
= true;
2296 lp_ctx
->sDefault
->bBrowseable
= true;
2297 lp_ctx
->sDefault
->bRead_only
= true;
2298 lp_ctx
->sDefault
->bMap_archive
= true;
2299 lp_ctx
->sDefault
->bStrictLocking
= true;
2300 lp_ctx
->sDefault
->bOplocks
= true;
2301 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2302 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2303 lp_ctx
->sDefault
->iDir_mask
= 0755;
2304 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2306 DEBUG(3, ("Initialising global parameters\n"));
2308 for (i
= 0; parm_table
[i
].label
; i
++) {
2309 if ((parm_table
[i
].type
== P_STRING
||
2310 parm_table
[i
].type
== P_USTRING
) &&
2311 parm_table
[i
].offset
!= -1 &&
2312 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2314 if (parm_table
[i
].pclass
== P_LOCAL
) {
2315 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2317 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2319 *r
= talloc_strdup(lp_ctx
, "");
2323 lp_do_global_parameter(lp_ctx
, "share backend", "classic");
2325 lp_do_global_parameter(lp_ctx
, "server role", "standalone");
2327 /* options that can be set on the command line must be initialised via
2328 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2330 lp_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2332 lp_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2333 myname
= get_myname(lp_ctx
);
2334 lp_do_global_parameter(lp_ctx
, "netbios name", myname
);
2335 talloc_free(myname
);
2336 lp_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2338 lp_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2340 lp_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2341 lp_do_global_parameter(lp_ctx
, "max connections", "-1");
2343 lp_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser");
2344 lp_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
2345 lp_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
2346 lp_do_global_parameter(lp_ctx
, "auth methods:domain controller", "anonymous sam_ignoredomain");
2347 lp_do_global_parameter(lp_ctx
, "auth methods:member server", "anonymous sam winbind");
2348 lp_do_global_parameter(lp_ctx
, "auth methods:standalone", "anonymous sam_ignoredomain");
2349 lp_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2350 lp_do_global_parameter(lp_ctx
, "sam database", "sam.ldb");
2351 lp_do_global_parameter(lp_ctx
, "idmap database", "idmap.ldb");
2352 lp_do_global_parameter(lp_ctx
, "secrets database", "secrets.ldb");
2353 lp_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
2354 lp_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
2355 lp_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
2356 lp_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2358 /* This hive should be dynamically generated by Samba using
2359 data from the sam, but for the moment leave it in a tdb to
2360 keep regedt32 from popping up an annoying dialog. */
2361 lp_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2363 /* using UTF8 by default allows us to support all chars */
2364 lp_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2366 /* Use codepage 850 as a default for the dos character set */
2367 lp_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2370 * Allow the default PASSWD_CHAT to be overridden in local.h.
2372 lp_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2374 lp_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2375 lp_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2376 lp_do_global_parameter(lp_ctx
, "modules dir", dyn_MODULESDIR
);
2377 lp_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2379 lp_do_global_parameter(lp_ctx
, "socket address", "0.0.0.0");
2380 lp_do_global_parameter_var(lp_ctx
, "server string",
2381 "Samba %s", SAMBA_VERSION_STRING
);
2383 lp_do_global_parameter_var(lp_ctx
, "announce version", "%d.%d",
2384 DEFAULT_MAJOR_VERSION
,
2385 DEFAULT_MINOR_VERSION
);
2387 lp_do_global_parameter(lp_ctx
, "password server", "*");
2389 lp_do_global_parameter(lp_ctx
, "max mux", "50");
2390 lp_do_global_parameter(lp_ctx
, "max xmit", "12288");
2391 lp_do_global_parameter(lp_ctx
, "password level", "0");
2392 lp_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2393 lp_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2394 lp_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2395 lp_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2396 lp_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2397 lp_do_global_parameter(lp_ctx
, "security", "USER");
2398 lp_do_global_parameter(lp_ctx
, "paranoid server security", "True");
2399 lp_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2400 lp_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2401 lp_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2402 lp_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2403 lp_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2404 lp_do_global_parameter(lp_ctx
, "announce as", "NT SERVER");
2406 lp_do_global_parameter(lp_ctx
, "TimeServer", "False");
2407 lp_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2408 lp_do_global_parameter(lp_ctx
, "Unicode", "True");
2409 lp_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2410 lp_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2411 lp_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2412 lp_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2414 lp_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2416 lp_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2417 lp_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2419 lp_do_global_parameter(lp_ctx
, "wins support", "False");
2420 lp_do_global_parameter(lp_ctx
, "dns proxy", "True");
2422 lp_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2423 lp_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2424 lp_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2425 lp_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2426 lp_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2427 lp_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2428 lp_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
2430 lp_do_global_parameter(lp_ctx
, "client signing", "Yes");
2431 lp_do_global_parameter(lp_ctx
, "server signing", "auto");
2433 lp_do_global_parameter(lp_ctx
, "use spnego", "True");
2435 lp_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2436 lp_do_global_parameter(lp_ctx
, "nbt port", "137");
2437 lp_do_global_parameter(lp_ctx
, "dgram port", "138");
2438 lp_do_global_parameter(lp_ctx
, "cldap port", "389");
2439 lp_do_global_parameter(lp_ctx
, "krb5 port", "88");
2440 lp_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2441 lp_do_global_parameter(lp_ctx
, "web port", "901");
2442 lp_do_global_parameter(lp_ctx
, "swat directory", dyn_SWATDIR
);
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(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2463 for (i
= 0; parm_table
[i
].label
; i
++) {
2464 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2465 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2472 const char *lp_configfile(struct loadparm_context
*lp_ctx
)
2474 return lp_ctx
->szConfigFile
;
2477 const char *lp_default_path(void)
2479 if (getenv("SMB_CONF_PATH"))
2480 return getenv("SMB_CONF_PATH");
2482 return dyn_CONFIGFILE
;
2486 * Update the internal state of a loadparm context after settings
2489 static bool lp_update(struct loadparm_context
*lp_ctx
)
2491 lp_add_auto_services(lp_ctx
, lp_auto_services(lp_ctx
));
2493 lp_add_hidden(lp_ctx
, "IPC$", "IPC");
2494 lp_add_hidden(lp_ctx
, "ADMIN$", "DISK");
2496 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2497 lp_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2500 panic_action
= lp_ctx
->globals
->panic_action
;
2502 reload_charcnv(lp_ctx
);
2504 /* FIXME: ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx); */
2506 /* FIXME: This is a bit of a hack, but we can't use a global, since
2507 * not everything that uses lp also uses the socket library */
2508 if (lp_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2509 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2511 unsetenv("SOCKET_TESTNONBLOCK");
2514 /* FIXME: Check locale in environment for this: */
2515 if (strcmp(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)) != 0)
2516 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)));
2518 d_set_iconv((smb_iconv_t
)-1);
2523 bool lp_load_default(struct loadparm_context
*lp_ctx
)
2527 path
= lp_default_path();
2529 if (!file_exist(path
)) {
2530 /* We allow the default smb.conf file to not exist,
2531 * basically the equivalent of an empty file. */
2532 return lp_update(lp_ctx
);
2535 return lp_load(lp_ctx
, path
);
2539 * Load the services array from the services file.
2541 * Return True on success, False on failure.
2543 bool lp_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2548 filename
= talloc_strdup(lp_ctx
, filename
);
2550 lp_ctx
->szConfigFile
= filename
;
2552 lp_ctx
->bInGlobalSection
= true;
2553 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2554 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2
));
2556 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2558 /* We get sections first, so have to start 'behind' to make up */
2559 lp_ctx
->currentService
= NULL
;
2560 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2562 /* finish up the last section */
2563 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2565 if (lp_ctx
->currentService
!= NULL
)
2566 bRetval
= service_ok(lp_ctx
->currentService
);
2568 bRetval
= bRetval
&& lp_update(lp_ctx
);
2570 /* we do this unconditionally, so that it happens even
2571 for a missing smb.conf */
2572 reload_charcnv(lp_ctx
);
2578 * Return the max number of services.
2581 int lp_numservices(struct loadparm_context
*lp_ctx
)
2583 return lp_ctx
->iNumServices
;
2587 * Display the contents of the services array in human-readable form.
2590 void lp_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2596 defaults_saved
= false;
2598 dump_globals(lp_ctx
, f
, show_defaults
);
2600 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
);
2602 for (iService
= 0; iService
< maxtoprint
; iService
++)
2603 lp_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2607 * Display the contents of one service in human-readable form.
2609 void lp_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2611 if (service
!= NULL
) {
2612 if (service
->szService
[0] == '\0')
2614 dump_a_service(service
, sDefault
, f
);
2618 struct loadparm_service
*lp_servicebynum(struct loadparm_context
*lp_ctx
,
2621 return lp_ctx
->services
[snum
];
2624 struct loadparm_service
*lp_service(struct loadparm_context
*lp_ctx
,
2625 const char *service_name
)
2630 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2631 if (lp_ctx
->services
[iService
] &&
2632 lp_ctx
->services
[iService
]->szService
) {
2634 * The substitution here is used to support %U is
2637 serviceName
= standard_sub_basic(
2638 lp_ctx
->services
[iService
],
2639 lp_ctx
->services
[iService
]->szService
);
2640 if (strequal(serviceName
, service_name
)) {
2641 talloc_free(serviceName
);
2642 return lp_ctx
->services
[iService
];
2644 talloc_free(serviceName
);
2648 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name
));
2654 * A useful volume label function.
2656 const char *volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2658 const char *ret
= lp_volume(service
, sDefault
);
2660 return lp_servicename(service
);
2666 * If we are PDC then prefer us as DMB
2668 const char *lp_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2670 const char *ret
= _lp_printername(service
, sDefault
);
2671 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2672 ret
= lp_servicename(service
);
2679 * Return the max print jobs per queue.
2681 int lp_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2683 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2684 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2685 maxjobs
= PRINT_MAX_JOBID
- 1;
2690 struct smb_iconv_convenience
*lp_iconv_convenience(struct loadparm_context
*lp_ctx
)
2692 if (lp_ctx
== NULL
) {
2693 static struct smb_iconv_convenience
*fallback_ic
= NULL
;
2694 if (fallback_ic
== NULL
)
2695 fallback_ic
= smb_iconv_convenience_init(talloc_autofree_context(),
2696 "CP850", "UTF8", true);
2699 return lp_ctx
->iconv_convenience
;
2702 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2704 talloc_unlink(lp_ctx
, lp_ctx
->iconv_convenience
);
2705 global_iconv_convenience
= lp_ctx
->iconv_convenience
= smb_iconv_convenience_init_lp(lp_ctx
, lp_ctx
);
2708 void lp_smbcli_options(struct loadparm_context
*lp_ctx
,
2709 struct smbcli_options
*options
)
2711 options
->max_xmit
= lp_max_xmit(lp_ctx
);
2712 options
->max_mux
= lp_maxmux(lp_ctx
);
2713 options
->use_spnego
= lp_nt_status_support(lp_ctx
) && lp_use_spnego(lp_ctx
);
2714 options
->signing
= lp_client_signing(lp_ctx
);
2715 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
2716 options
->ntstatus_support
= lp_nt_status_support(lp_ctx
);
2717 options
->max_protocol
= lp_cli_maxprotocol(lp_ctx
);
2718 options
->unicode
= lp_unicode(lp_ctx
);
2719 options
->use_oplocks
= true;
2720 options
->use_level2_oplocks
= true;
2723 void lp_smbcli_session_options(struct loadparm_context
*lp_ctx
,
2724 struct smbcli_session_options
*options
)
2726 options
->lanman_auth
= lp_client_lanman_auth(lp_ctx
);
2727 options
->ntlmv2_auth
= lp_client_ntlmv2_auth(lp_ctx
);
2728 options
->plaintext_auth
= lp_client_plaintext_auth(lp_ctx
);
2731 _PUBLIC_
char *lp_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2733 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2736 _PUBLIC_
char *lp_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2738 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2741 _PUBLIC_
char *lp_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2743 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2746 _PUBLIC_
char *lp_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2748 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2751 _PUBLIC_
char *lp_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2753 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2756 _PUBLIC_
struct dcerpc_server_info
*lp_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2758 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
2760 ret
->domain_name
= talloc_reference(mem_ctx
, lp_workgroup(lp_ctx
));
2761 ret
->version_major
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
2762 ret
->version_minor
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
2763 ret
->version_build
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
2768 struct gensec_settings
*lp_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2770 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
2771 if (settings
== NULL
)
2773 SMB_ASSERT(lp_ctx
!= NULL
);
2774 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2775 settings
->iconv_convenience
= lp_iconv_convenience(lp_ctx
);
2776 settings
->target_hostname
= lp_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");