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 "param/param.h"
65 #include "param/loadparm.h"
66 #include "libcli/raw/libcliraw.h"
67 #include "rpc_server/common/common.h"
68 #include "lib/socket/socket.h"
69 #include "auth/gensec/gensec.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved
= false;
77 * This structure describes global (ie., server-wide) parameters.
79 struct loadparm_global
81 enum server_role server_role
;
83 const char **smb_ports
;
87 char *display_charset
;
100 char *szWINS_CONFIG_URL
;
103 const char **szPasswordServers
;
104 char *szSocketOptions
;
108 const char **szWINSservers
;
109 const char **szInterfaces
;
110 char *szSocketAddress
;
111 char *szAnnounceVersion
; /* This is initialised in init_globals */
114 const char **szNetbiosAliases
;
115 char *szNetbiosScope
;
116 char *szDomainOtherSIDs
;
117 const char **szNameResolveOrder
;
118 const char **dcerpc_ep_servers
;
119 const char **server_services
;
120 char *ntptr_providor
;
121 char *szWinbindSeparator
;
122 char *szWinbinddPrivilegedSocketDirectory
;
123 char *szWinbinddSocketDirectory
;
124 char *szTemplateShell
;
125 char *szTemplateHomedir
;
126 int bWinbindSealedPipes
;
127 int bIdmapTrustedOnly
;
128 char *swat_directory
;
146 int paranoid_server_security
;
149 int announce_as
; /* This is initialised in init_globals */
156 char *socket_options
;
161 int bPreferredMaster
;
162 int bEncryptPasswords
;
164 int bObeyPamRestrictions
;
169 int bBindInterfacesOnly
;
171 int bNTStatusSupport
;
177 int bClientPlaintextAuth
;
178 int bClientLanManAuth
;
179 int bClientNTLMv2Auth
;
180 int client_use_spnego_principal
;
186 char *szNTPSignDSocketDirectory
;
187 struct parmlist_entry
*param_opt
;
192 * This structure describes a single service.
194 struct loadparm_service
206 char **ntvfs_handler
;
220 int iCreate_force_mode
;
227 struct parmlist_entry
*param_opt
;
229 char dummy
[3]; /* for alignment */
233 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
236 /* prototypes for the special type handlers */
237 static bool handle_include(struct loadparm_context
*lp_ctx
,
238 const char *pszParmValue
, char **ptr
);
239 static bool handle_realm(struct loadparm_context
*lp_ctx
,
240 const char *pszParmValue
, char **ptr
);
241 static bool handle_copy(struct loadparm_context
*lp_ctx
,
242 const char *pszParmValue
, char **ptr
);
243 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
244 const char *pszParmValue
, char **ptr
);
245 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
246 const char *pszParmValue
, char **ptr
);
248 static const struct enum_list enum_protocol
[] = {
249 {PROTOCOL_SMB2
, "SMB2"},
250 {PROTOCOL_NT1
, "NT1"},
251 {PROTOCOL_LANMAN2
, "LANMAN2"},
252 {PROTOCOL_LANMAN1
, "LANMAN1"},
253 {PROTOCOL_CORE
, "CORE"},
254 {PROTOCOL_COREPLUS
, "COREPLUS"},
255 {PROTOCOL_COREPLUS
, "CORE+"},
259 static const struct enum_list enum_security
[] = {
260 {SEC_SHARE
, "SHARE"},
265 static const struct enum_list enum_announce_as
[] = {
266 {ANNOUNCE_AS_NT_SERVER
, "NT"},
267 {ANNOUNCE_AS_NT_SERVER
, "NT Server"},
268 {ANNOUNCE_AS_NT_WORKSTATION
, "NT Workstation"},
269 {ANNOUNCE_AS_WIN95
, "win95"},
270 {ANNOUNCE_AS_WFW
, "WfW"},
274 static const struct enum_list enum_bool_auto
[] = {
285 /* Client-side offline caching policy types */
288 CSC_POLICY_DOCUMENTS
=1,
289 CSC_POLICY_PROGRAMS
=2,
293 static const struct enum_list enum_csc_policy
[] = {
294 {CSC_POLICY_MANUAL
, "manual"},
295 {CSC_POLICY_DOCUMENTS
, "documents"},
296 {CSC_POLICY_PROGRAMS
, "programs"},
297 {CSC_POLICY_DISABLE
, "disable"},
301 /* SMB signing types. */
302 static const struct enum_list enum_smb_signing_vals
[] = {
303 {SMB_SIGNING_OFF
, "No"},
304 {SMB_SIGNING_OFF
, "False"},
305 {SMB_SIGNING_OFF
, "0"},
306 {SMB_SIGNING_OFF
, "Off"},
307 {SMB_SIGNING_OFF
, "disabled"},
308 {SMB_SIGNING_SUPPORTED
, "Yes"},
309 {SMB_SIGNING_SUPPORTED
, "True"},
310 {SMB_SIGNING_SUPPORTED
, "1"},
311 {SMB_SIGNING_SUPPORTED
, "On"},
312 {SMB_SIGNING_SUPPORTED
, "enabled"},
313 {SMB_SIGNING_REQUIRED
, "required"},
314 {SMB_SIGNING_REQUIRED
, "mandatory"},
315 {SMB_SIGNING_REQUIRED
, "force"},
316 {SMB_SIGNING_REQUIRED
, "forced"},
317 {SMB_SIGNING_REQUIRED
, "enforced"},
318 {SMB_SIGNING_AUTO
, "auto"},
322 static const struct enum_list enum_server_role
[] = {
323 {ROLE_STANDALONE
, "standalone"},
324 {ROLE_DOMAIN_MEMBER
, "member server"},
325 {ROLE_DOMAIN_MEMBER
, "member"},
326 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
327 {ROLE_DOMAIN_CONTROLLER
, "dc"},
332 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
333 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
335 static struct parm_struct parm_table
[] = {
336 {"server role", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_role
), NULL
, enum_server_role
},
338 {"dos charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(dos_charset
), NULL
, NULL
},
339 {"unix charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(unix_charset
), NULL
, NULL
},
340 {"ncalrpc dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ncalrpc_dir
), NULL
, NULL
},
341 {"display charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(display_charset
), NULL
, NULL
},
342 {"comment", P_STRING
, P_LOCAL
, LOCAL_VAR(comment
), NULL
, NULL
},
343 {"path", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
344 {"directory", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
345 {"workgroup", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szWorkgroup
), NULL
, NULL
},
346 {"realm", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szRealm
), handle_realm
, NULL
},
347 {"netbios name", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosName
), NULL
, NULL
},
348 {"netbios aliases", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNetbiosAliases
), NULL
, NULL
},
349 {"netbios scope", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosScope
), NULL
, NULL
},
350 {"server string", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szServerString
), NULL
, NULL
},
351 {"interfaces", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szInterfaces
), NULL
, NULL
},
352 {"bind interfaces only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bBindInterfacesOnly
), NULL
, NULL
},
353 {"ntvfs handler", P_LIST
, P_LOCAL
, LOCAL_VAR(ntvfs_handler
), NULL
, NULL
},
354 {"ntptr providor", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ntptr_providor
), NULL
, NULL
},
355 {"dcerpc endpoint servers", P_LIST
, P_GLOBAL
, GLOBAL_VAR(dcerpc_ep_servers
), NULL
, NULL
},
356 {"server services", P_LIST
, P_GLOBAL
, GLOBAL_VAR(server_services
), NULL
, NULL
},
358 {"security", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(security
), NULL
, enum_security
},
359 {"encrypt passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bEncryptPasswords
), NULL
, NULL
},
360 {"null passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNullPasswords
), NULL
, NULL
},
361 {"obey pam restrictions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bObeyPamRestrictions
), NULL
, NULL
},
362 {"password server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szPasswordServers
), NULL
, NULL
},
363 {"sam database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSAM_URL
), NULL
, NULL
},
364 {"idmap database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szIDMAP_URL
), NULL
, NULL
},
365 {"secrets database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSECRETS_URL
), NULL
, NULL
},
366 {"spoolss database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSPOOLSS_URL
), NULL
, NULL
},
367 {"wins config database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_CONFIG_URL
), NULL
, NULL
},
368 {"wins database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_URL
), NULL
, NULL
},
369 {"private dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPrivateDir
), NULL
, NULL
},
370 {"passwd chat", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPasswdChat
), NULL
, NULL
},
371 {"password level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(pwordlevel
), NULL
, NULL
},
372 {"lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLanmanAuth
), NULL
, NULL
},
373 {"ntlm auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTLMAuth
), NULL
, NULL
},
374 {"client NTLMv2 auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientNTLMv2Auth
), NULL
, NULL
},
375 {"client lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientLanManAuth
), NULL
, NULL
},
376 {"client plaintext auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientPlaintextAuth
), NULL
, NULL
},
377 {"client use spnego principal", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(client_use_spnego_principal
), NULL
, NULL
},
379 {"read only", P_BOOL
, P_LOCAL
, LOCAL_VAR(bRead_only
), NULL
, NULL
},
381 {"create mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_mask
), NULL
, NULL
},
382 {"force create mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_force_mode
), NULL
, NULL
},
383 {"directory mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_mask
), NULL
, NULL
},
384 {"force directory mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_force_mode
), NULL
, NULL
},
386 {"hosts allow", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsallow
), NULL
, NULL
},
387 {"hosts deny", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsdeny
), NULL
, NULL
},
389 {"log level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
390 {"debuglevel", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
391 {"log file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(logfile
), handle_logfile
, NULL
},
393 {"smb ports", P_LIST
, P_GLOBAL
, GLOBAL_VAR(smb_ports
), NULL
, NULL
},
394 {"nbt port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(nbt_port
), NULL
, NULL
},
395 {"dgram port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(dgram_port
), NULL
, NULL
},
396 {"cldap port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(cldap_port
), NULL
, NULL
},
397 {"krb5 port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(krb5_port
), NULL
, NULL
},
398 {"kpasswd port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(kpasswd_port
), NULL
, NULL
},
399 {"web port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(web_port
), NULL
, NULL
},
400 {"tls enabled", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(tls_enabled
), NULL
, NULL
},
401 {"tls keyfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_keyfile
), NULL
, NULL
},
402 {"tls certfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_certfile
), NULL
, NULL
},
403 {"tls cafile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_cafile
), NULL
, NULL
},
404 {"tls crlfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_crlfile
), NULL
, NULL
},
405 {"tls dh params file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_dhpfile
), NULL
, NULL
},
406 {"swat directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(swat_directory
), NULL
, NULL
},
407 {"large readwrite", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLargeReadwrite
), NULL
, NULL
},
408 {"server max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_maxprotocol
), NULL
, enum_protocol
},
409 {"server min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_minprotocol
), NULL
, enum_protocol
},
410 {"client max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_maxprotocol
), NULL
, enum_protocol
},
411 {"client min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_minprotocol
), NULL
, enum_protocol
},
412 {"unicode", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnicode
), NULL
, NULL
},
413 {"read raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bReadRaw
), NULL
, NULL
},
414 {"write raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWriteRaw
), NULL
, NULL
},
415 {"disable netbios", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bDisableNetbios
), NULL
, NULL
},
417 {"nt status support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTStatusSupport
), NULL
, NULL
},
419 {"announce version", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAnnounceVersion
), NULL
, NULL
},
420 {"announce as", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(announce_as
), NULL
, enum_announce_as
},
421 {"max mux", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_mux
), NULL
, NULL
},
422 {"max xmit", P_BYTES
, P_GLOBAL
, GLOBAL_VAR(max_xmit
), NULL
, NULL
},
424 {"name resolve order", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNameResolveOrder
), NULL
, NULL
},
425 {"max wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_wins_ttl
), NULL
, NULL
},
426 {"min wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(min_wins_ttl
), NULL
, NULL
},
427 {"time server", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bTimeServer
), NULL
, NULL
},
428 {"unix extensions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnixExtensions
), NULL
, NULL
},
429 {"use spnego", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUseSpnego
), NULL
, NULL
},
430 {"server signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_signing
), NULL
, enum_smb_signing_vals
},
431 {"client signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(client_signing
), NULL
, enum_smb_signing_vals
},
432 {"rpc big endian", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bRpcBigEndian
), NULL
, NULL
},
434 {"max connections", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxConnections
), NULL
, NULL
},
435 {"paranoid server security", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(paranoid_server_security
), NULL
, NULL
},
436 {"socket options", P_STRING
, P_GLOBAL
, GLOBAL_VAR(socket_options
), NULL
, NULL
},
438 {"strict sync", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictSync
), NULL
, NULL
},
439 {"case insensitive filesystem", P_BOOL
, P_LOCAL
, LOCAL_VAR(bCIFileSystem
), NULL
, NULL
},
441 {"max print jobs", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxPrintJobs
), NULL
, NULL
},
442 {"printable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
443 {"print ok", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
445 {"printer name", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
446 {"printer", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
448 {"map system", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_system
), NULL
, NULL
},
449 {"map hidden", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_hidden
), NULL
, NULL
},
450 {"map archive", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_archive
), NULL
, NULL
},
452 {"preferred master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
453 {"prefered master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
454 {"local master", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLocalMaster
), NULL
, NULL
},
455 {"browseable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
456 {"browsable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
458 {"wins server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szWINSservers
), NULL
, NULL
},
459 {"wins support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSsupport
), NULL
, NULL
},
460 {"dns proxy", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSdnsProxy
), NULL
, NULL
},
461 {"wins hook", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINSHook
), NULL
, NULL
},
463 {"csc policy", P_ENUM
, P_LOCAL
, LOCAL_VAR(iCSCPolicy
), NULL
, enum_csc_policy
},
465 {"strict locking", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictLocking
), NULL
, NULL
},
466 {"oplocks", P_BOOL
, P_LOCAL
, LOCAL_VAR(bOplocks
), NULL
, NULL
},
468 {"share backend", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szShareBackend
), NULL
, NULL
},
469 {"preload", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
470 {"auto services", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
471 {"lock dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
472 {"lock directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
473 {"modules dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szModulesDir
), NULL
, NULL
},
474 {"pid directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPidDir
), NULL
, NULL
},
475 {"setup directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSetupDir
), NULL
, NULL
},
477 {"socket address", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSocketAddress
), NULL
, NULL
},
478 {"copy", P_STRING
, P_LOCAL
, LOCAL_VAR(szCopy
), handle_copy
, NULL
},
479 {"include", P_STRING
, P_LOCAL
, LOCAL_VAR(szInclude
), handle_include
, NULL
},
481 {"available", P_BOOL
, P_LOCAL
, LOCAL_VAR(bAvailable
), NULL
, NULL
},
482 {"volume", P_STRING
, P_LOCAL
, LOCAL_VAR(volume
), NULL
, NULL
},
483 {"fstype", P_STRING
, P_LOCAL
, LOCAL_VAR(fstype
), NULL
, NULL
},
485 {"panic action", P_STRING
, P_GLOBAL
, GLOBAL_VAR(panic_action
), NULL
, NULL
},
487 {"msdfs root", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMSDfsRoot
), NULL
, NULL
},
488 {"host msdfs", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bHostMSDfs
), NULL
, NULL
},
489 {"winbind separator", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbindSeparator
), NULL
, NULL
},
490 {"winbindd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddSocketDirectory
), NULL
, NULL
},
491 {"winbindd privileged socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
), NULL
, NULL
},
492 {"winbind sealed pipes", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWinbindSealedPipes
), NULL
, NULL
},
493 {"template shell", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateShell
), NULL
, NULL
},
494 {"template homedir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateHomedir
), NULL
, NULL
},
495 {"idmap trusted only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bIdmapTrustedOnly
), NULL
, NULL
},
497 {"ntp signd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szNTPSignDSocketDirectory
), NULL
, NULL
},
499 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
}
503 /* local variables */
504 struct loadparm_context
{
505 const char *szConfigFile
;
506 struct loadparm_global
*globals
;
507 struct loadparm_service
**services
;
508 struct loadparm_service
*sDefault
;
510 struct loadparm_service
*currentService
;
511 bool bInGlobalSection
;
513 struct file_lists
*next
;
518 unsigned int flags
[NUMPARAMETERS
];
519 struct smb_iconv_convenience
*iconv_convenience
;
523 struct loadparm_service
*lp_default_service(struct loadparm_context
*lp_ctx
)
525 return lp_ctx
->sDefault
;
529 return the parameter table
531 struct parm_struct
*lp_parm_table(void)
537 * Convenience routine to grab string parameters into temporary memory
538 * and run standard_sub_basic on them.
540 * The buffers can be written to by
541 * callers without affecting the source string.
544 static const char *lp_string(const char *s
)
546 #if 0 /* until REWRITE done to make thread-safe */
547 size_t len
= s
? strlen(s
) : 0;
551 /* The follow debug is useful for tracking down memory problems
552 especially if you have an inner loop that is calling a lp_*()
553 function that returns a string. Perhaps this debug should be
554 present all the time? */
557 DEBUG(10, ("lp_string(%s)\n", s
));
560 #if 0 /* until REWRITE done to make thread-safe */
562 lp_talloc
= talloc_init("lp_talloc");
564 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
572 strlcpy(ret
, s
, len
);
574 if (trim_string(ret
, "\"", "\"")) {
575 if (strchr(ret
,'"') != NULL
)
576 strlcpy(ret
, s
, len
);
579 standard_sub_basic(ret
,len
+100);
586 In this section all the functions that are used to access the
587 parameters from the rest of the program are defined
590 #define FN_GLOBAL_STRING(fn_name,var_name) \
591 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) : "";}
592 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
593 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 : "";}
594 #define FN_GLOBAL_LIST(fn_name,var_name) \
595 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
596 #define FN_GLOBAL_BOOL(fn_name,var_name) \
597 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
599 #define FN_GLOBAL_CHAR(fn_name,ptr) \
600 char fn_name(void) {return(*(char *)(ptr));}
602 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
603 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
605 #define FN_LOCAL_STRING(fn_name,val) \
606 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)));}
607 #define FN_LOCAL_LIST(fn_name,val) \
608 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
609 #define FN_LOCAL_BOOL(fn_name,val) \
610 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
611 #define FN_LOCAL_INTEGER(fn_name,val) \
612 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
614 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_role
, server_role
)
615 _PUBLIC_
FN_GLOBAL_LIST(lp_smb_ports
, smb_ports
)
616 _PUBLIC_
FN_GLOBAL_INTEGER(lp_nbt_port
, nbt_port
)
617 _PUBLIC_
FN_GLOBAL_INTEGER(lp_dgram_port
, dgram_port
)
618 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cldap_port
, cldap_port
)
619 _PUBLIC_
FN_GLOBAL_INTEGER(lp_krb5_port
, krb5_port
)
620 _PUBLIC_
FN_GLOBAL_INTEGER(lp_kpasswd_port
, kpasswd_port
)
621 _PUBLIC_
FN_GLOBAL_INTEGER(lp_web_port
, web_port
)
622 _PUBLIC_
FN_GLOBAL_STRING(lp_swat_directory
, swat_directory
)
623 _PUBLIC_
FN_GLOBAL_BOOL(lp_tls_enabled
, tls_enabled
)
624 _PUBLIC_
FN_GLOBAL_STRING(lp_share_backend
, szShareBackend
)
625 _PUBLIC_
FN_GLOBAL_STRING(lp_sam_url
, szSAM_URL
)
626 _PUBLIC_
FN_GLOBAL_STRING(lp_idmap_url
, szIDMAP_URL
)
627 _PUBLIC_
FN_GLOBAL_STRING(lp_secrets_url
, szSECRETS_URL
)
628 _PUBLIC_
FN_GLOBAL_STRING(lp_spoolss_url
, szSPOOLSS_URL
)
629 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_config_url
, szWINS_CONFIG_URL
)
630 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_url
, szWINS_URL
)
631 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbind_separator
, szWinbindSeparator
)
632 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory
, szWinbinddSocketDirectory
)
633 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
634 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_shell
, szTemplateShell
)
635 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_homedir
, szTemplateHomedir
)
636 _PUBLIC_
FN_GLOBAL_BOOL(lp_winbind_sealed_pipes
, bWinbindSealedPipes
)
637 _PUBLIC_
FN_GLOBAL_BOOL(lp_idmap_trusted_only
, bIdmapTrustedOnly
)
638 _PUBLIC_
FN_GLOBAL_STRING(lp_private_dir
, szPrivateDir
)
639 _PUBLIC_
FN_GLOBAL_STRING(lp_serverstring
, szServerString
)
640 _PUBLIC_
FN_GLOBAL_STRING(lp_lockdir
, szLockDir
)
641 _PUBLIC_
FN_GLOBAL_STRING(lp_modulesdir
, szModulesDir
)
642 _PUBLIC_
FN_GLOBAL_STRING(lp_setupdir
, szSetupDir
)
643 _PUBLIC_
FN_GLOBAL_STRING(lp_ncalrpc_dir
, ncalrpc_dir
)
644 _PUBLIC_
FN_GLOBAL_STRING(lp_dos_charset
, dos_charset
)
645 _PUBLIC_
FN_GLOBAL_STRING(lp_unix_charset
, unix_charset
)
646 _PUBLIC_
FN_GLOBAL_STRING(lp_display_charset
, display_charset
)
647 _PUBLIC_
FN_GLOBAL_STRING(lp_piddir
, szPidDir
)
648 _PUBLIC_
FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers
, dcerpc_ep_servers
)
649 _PUBLIC_
FN_GLOBAL_LIST(lp_server_services
, server_services
)
650 _PUBLIC_
FN_GLOBAL_STRING(lp_ntptr_providor
, ntptr_providor
)
651 _PUBLIC_
FN_GLOBAL_STRING(lp_auto_services
, szAutoServices
)
652 _PUBLIC_
FN_GLOBAL_STRING(lp_passwd_chat
, szPasswdChat
)
653 _PUBLIC_
FN_GLOBAL_LIST(lp_passwordserver
, szPasswordServers
)
654 _PUBLIC_
FN_GLOBAL_LIST(lp_name_resolve_order
, szNameResolveOrder
)
655 _PUBLIC_
FN_GLOBAL_STRING(lp_realm
, szRealm_upper
)
656 _PUBLIC_
FN_GLOBAL_STRING(lp_dnsdomain
, szRealm_lower
)
657 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_options
, socket_options
)
658 _PUBLIC_
FN_GLOBAL_STRING(lp_workgroup
, szWorkgroup
)
659 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_name
, szNetbiosName
)
660 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_scope
, szNetbiosScope
)
661 _PUBLIC_
FN_GLOBAL_LIST(lp_wins_server_list
, szWINSservers
)
662 _PUBLIC_
FN_GLOBAL_LIST(lp_interfaces
, szInterfaces
)
663 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_address
, szSocketAddress
)
664 _PUBLIC_
FN_GLOBAL_LIST(lp_netbios_aliases
, szNetbiosAliases
)
665 _PUBLIC_
FN_GLOBAL_BOOL(lp_disable_netbios
, bDisableNetbios
)
666 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_support
, bWINSsupport
)
667 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_dns_proxy
, bWINSdnsProxy
)
668 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_hook
, szWINSHook
)
669 _PUBLIC_
FN_GLOBAL_BOOL(lp_local_master
, bLocalMaster
)
670 _PUBLIC_
FN_GLOBAL_BOOL(lp_readraw
, bReadRaw
)
671 _PUBLIC_
FN_GLOBAL_BOOL(lp_large_readwrite
, bLargeReadwrite
)
672 _PUBLIC_
FN_GLOBAL_BOOL(lp_writeraw
, bWriteRaw
)
673 _PUBLIC_
FN_GLOBAL_BOOL(lp_null_passwords
, bNullPasswords
)
674 _PUBLIC_
FN_GLOBAL_BOOL(lp_obey_pam_restrictions
, bObeyPamRestrictions
)
675 _PUBLIC_
FN_GLOBAL_BOOL(lp_encrypted_passwords
, bEncryptPasswords
)
676 _PUBLIC_
FN_GLOBAL_BOOL(lp_time_server
, bTimeServer
)
677 _PUBLIC_
FN_GLOBAL_BOOL(lp_bind_interfaces_only
, bBindInterfacesOnly
)
678 _PUBLIC_
FN_GLOBAL_BOOL(lp_unicode
, bUnicode
)
679 _PUBLIC_
FN_GLOBAL_BOOL(lp_nt_status_support
, bNTStatusSupport
)
680 _PUBLIC_
FN_GLOBAL_BOOL(lp_lanman_auth
, bLanmanAuth
)
681 _PUBLIC_
FN_GLOBAL_BOOL(lp_ntlm_auth
, bNTLMAuth
)
682 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_plaintext_auth
, bClientPlaintextAuth
)
683 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_lanman_auth
, bClientLanManAuth
)
684 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_ntlmv2_auth
, bClientNTLMv2Auth
)
685 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_use_spnego_principal
, client_use_spnego_principal
)
686 _PUBLIC_
FN_GLOBAL_BOOL(lp_host_msdfs
, bHostMSDfs
)
687 _PUBLIC_
FN_GLOBAL_BOOL(lp_unix_extensions
, bUnixExtensions
)
688 _PUBLIC_
FN_GLOBAL_BOOL(lp_use_spnego
, bUseSpnego
)
689 _PUBLIC_
FN_GLOBAL_BOOL(lp_rpc_big_endian
, bRpcBigEndian
)
690 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_wins_ttl
, max_wins_ttl
)
691 _PUBLIC_
FN_GLOBAL_INTEGER(lp_min_wins_ttl
, min_wins_ttl
)
692 _PUBLIC_
FN_GLOBAL_INTEGER(lp_maxmux
, max_mux
)
693 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_xmit
, max_xmit
)
694 _PUBLIC_
FN_GLOBAL_INTEGER(lp_passwordlevel
, pwordlevel
)
695 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_maxprotocol
, srv_maxprotocol
)
696 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_minprotocol
, srv_minprotocol
)
697 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_maxprotocol
, cli_maxprotocol
)
698 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_minprotocol
, cli_minprotocol
)
699 _PUBLIC_
FN_GLOBAL_INTEGER(lp_security
, security
)
700 _PUBLIC_
FN_GLOBAL_BOOL(lp_paranoid_server_security
, paranoid_server_security
)
701 _PUBLIC_
FN_GLOBAL_INTEGER(lp_announce_as
, announce_as
)
703 const char *lp_servicename(const struct loadparm_service
*service
)
705 return lp_string((const char *)service
->szService
);
708 _PUBLIC_
FN_LOCAL_STRING(lp_pathname
, szPath
)
709 static FN_LOCAL_STRING(_lp_printername
, szPrintername
)
710 _PUBLIC_
FN_LOCAL_LIST(lp_hostsallow
, szHostsallow
)
711 _PUBLIC_
FN_LOCAL_LIST(lp_hostsdeny
, szHostsdeny
)
712 _PUBLIC_
FN_LOCAL_STRING(lp_comment
, comment
)
713 _PUBLIC_
FN_LOCAL_STRING(lp_fstype
, fstype
)
714 static FN_LOCAL_STRING(lp_volume
, volume
)
715 _PUBLIC_
FN_LOCAL_LIST(lp_ntvfs_handler
, ntvfs_handler
)
716 _PUBLIC_
FN_LOCAL_BOOL(lp_msdfs_root
, bMSDfsRoot
)
717 _PUBLIC_
FN_LOCAL_BOOL(lp_browseable
, bBrowseable
)
718 _PUBLIC_
FN_LOCAL_BOOL(lp_readonly
, bRead_only
)
719 _PUBLIC_
FN_LOCAL_BOOL(lp_print_ok
, bPrint_ok
)
720 _PUBLIC_
FN_LOCAL_BOOL(lp_map_hidden
, bMap_hidden
)
721 _PUBLIC_
FN_LOCAL_BOOL(lp_map_archive
, bMap_archive
)
722 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_locking
, bStrictLocking
)
723 _PUBLIC_
FN_LOCAL_BOOL(lp_oplocks
, bOplocks
)
724 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_sync
, bStrictSync
)
725 _PUBLIC_
FN_LOCAL_BOOL(lp_ci_filesystem
, bCIFileSystem
)
726 _PUBLIC_
FN_LOCAL_BOOL(lp_map_system
, bMap_system
)
727 _PUBLIC_
FN_LOCAL_INTEGER(lp_max_connections
, iMaxConnections
)
728 _PUBLIC_
FN_LOCAL_INTEGER(lp_csc_policy
, iCSCPolicy
)
729 _PUBLIC_
FN_LOCAL_INTEGER(lp_create_mask
, iCreate_mask
)
730 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_create_mode
, iCreate_force_mode
)
731 _PUBLIC_
FN_LOCAL_INTEGER(lp_dir_mask
, iDir_mask
)
732 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_dir_mode
, iDir_force_mode
)
733 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_signing
, server_signing
)
734 _PUBLIC_
FN_GLOBAL_INTEGER(lp_client_signing
, client_signing
)
736 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
738 /* local prototypes */
739 static int map_parameter(const char *pszParmName
);
740 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
741 const char *pszServiceName
);
742 static void copy_service(struct loadparm_service
*pserviceDest
,
743 struct loadparm_service
*pserviceSource
,
745 static bool service_ok(struct loadparm_service
*service
);
746 static bool do_section(const char *pszSectionName
, void *);
747 static void init_copymap(struct loadparm_service
*pservice
);
749 /* This is a helper function for parametrical options support. */
750 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
751 /* Actual parametrical functions are quite simple */
752 const char *lp_get_parametric(struct loadparm_context
*lp_ctx
,
753 struct loadparm_service
*service
,
754 const char *type
, const char *option
)
757 struct parmlist_entry
*data
;
762 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
764 asprintf(&vfskey
, "%s:%s", type
, option
);
768 if (strcmp(data
->key
, vfskey
) == 0) {
775 if (service
!= NULL
) {
776 /* Try to fetch the same option but from globals */
777 /* but only if we are not already working with globals */
778 for (data
= lp_ctx
->globals
->param_opt
; data
;
780 if (strcmp(data
->key
, vfskey
) == 0) {
794 * convenience routine to return int parameters.
796 static int lp_int(const char *s
)
800 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
804 return strtol(s
, NULL
, 0);
808 * convenience routine to return unsigned long parameters.
810 static int lp_ulong(const char *s
)
814 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
818 return strtoul(s
, NULL
, 0);
822 * convenience routine to return unsigned long parameters.
824 static double lp_double(const char *s
)
828 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
832 return strtod(s
, NULL
);
836 * convenience routine to return boolean parameters.
838 static bool lp_bool(const char *s
)
843 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
847 if (!set_boolean(s
, &ret
)) {
848 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
857 * Return parametric option from a given service. Type is a part of option before ':'
858 * Parametric option has following syntax: 'Type: option = value'
859 * Returned value is allocated in 'lp_talloc' context
862 const char *lp_parm_string(struct loadparm_context
*lp_ctx
,
863 struct loadparm_service
*service
, const char *type
,
866 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
869 return lp_string(value
);
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_list(TALLOC_CTX
*mem_ctx
,
881 struct loadparm_context
*lp_ctx
,
882 struct loadparm_service
*service
,
884 const char *option
, const char *separator
)
886 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
889 return (const char **)str_list_make(mem_ctx
, value
, separator
);
895 * Return parametric option from a given service. Type is a part of option before ':'
896 * Parametric option has following syntax: 'Type: option = value'
899 int lp_parm_int(struct loadparm_context
*lp_ctx
,
900 struct loadparm_service
*service
, const char *type
,
901 const char *option
, int default_v
)
903 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
906 return lp_int(value
);
912 * Return parametric option from a given service. Type is a part of
914 * Parametric option has following syntax: 'Type: option = value'.
917 int lp_parm_bytes(struct loadparm_context
*lp_ctx
,
918 struct loadparm_service
*service
, const char *type
,
919 const char *option
, int default_v
)
923 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
925 if (value
&& conv_str_size(value
, &bval
)) {
926 if (bval
<= INT_MAX
) {
935 * Return parametric option from a given service.
936 * Type is a part of option before ':'
937 * Parametric option has following syntax: 'Type: option = value'
939 unsigned long lp_parm_ulong(struct loadparm_context
*lp_ctx
,
940 struct loadparm_service
*service
, const char *type
,
941 const char *option
, unsigned long default_v
)
943 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
946 return lp_ulong(value
);
952 double lp_parm_double(struct loadparm_context
*lp_ctx
,
953 struct loadparm_service
*service
, const char *type
,
954 const char *option
, double default_v
)
956 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
959 return lp_double(value
);
965 * Return parametric option from a given service. Type is a part of option before ':'
966 * Parametric option has following syntax: 'Type: option = value'
969 bool lp_parm_bool(struct loadparm_context
*lp_ctx
,
970 struct loadparm_service
*service
, const char *type
,
971 const char *option
, bool default_v
)
973 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
976 return lp_bool(value
);
983 * Initialise a service to the defaults.
986 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
988 struct loadparm_service
*pservice
=
989 talloc_zero(mem_ctx
, struct loadparm_service
);
990 copy_service(pservice
, sDefault
, NULL
);
995 * Set a string value, deallocating any existing space, and allocing the space
998 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1005 *dest
= talloc_strdup(mem_ctx
, src
);
1006 if ((*dest
) == NULL
) {
1007 DEBUG(0,("Out of memory in string_init\n"));
1017 * Add a new service to the services array initialising it with the given
1021 struct loadparm_service
*lp_add_service(struct loadparm_context
*lp_ctx
,
1022 const struct loadparm_service
*pservice
,
1026 struct loadparm_service tservice
;
1027 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1028 struct parmlist_entry
*data
, *pdata
;
1030 tservice
= *pservice
;
1032 /* it might already exist */
1034 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1036 if (service
!= NULL
) {
1037 /* Clean all parametric options for service */
1038 /* They will be added during parsing again */
1039 data
= service
->param_opt
;
1045 service
->param_opt
= NULL
;
1050 /* find an invalid one */
1051 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1052 if (lp_ctx
->services
[i
] == NULL
)
1055 /* if not, then create one */
1056 if (i
== lp_ctx
->iNumServices
) {
1057 struct loadparm_service
**tsp
;
1059 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1062 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1065 lp_ctx
->services
= tsp
;
1066 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1069 lp_ctx
->iNumServices
++;
1072 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1073 if (lp_ctx
->services
[i
] == NULL
) {
1074 DEBUG(0,("lp_add_service: out of memory!\n"));
1077 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1079 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1080 return lp_ctx
->services
[i
];
1084 * Add a new home service, with the specified home directory, defaults coming
1085 * from service ifrom.
1088 bool lp_add_home(struct loadparm_context
*lp_ctx
,
1089 const char *pszHomename
,
1090 struct loadparm_service
*default_service
,
1091 const char *user
, const char *pszHomedir
)
1093 struct loadparm_service
*service
;
1095 service
= lp_add_service(lp_ctx
, default_service
, pszHomename
);
1097 if (service
== NULL
)
1100 if (!(*(default_service
->szPath
))
1101 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1102 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1104 service
->szPath
= string_sub_talloc(service
, lp_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1107 if (!(*(service
->comment
))) {
1108 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1110 service
->bAvailable
= default_service
->bAvailable
;
1111 service
->bBrowseable
= default_service
->bBrowseable
;
1113 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1114 pszHomename
, user
, service
->szPath
));
1120 * Add the IPC service.
1123 static bool lp_add_hidden(struct loadparm_context
*lp_ctx
, const char *name
,
1126 struct loadparm_service
*service
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
, name
);
1128 if (service
== NULL
)
1131 string_set(service
, &service
->szPath
, tmpdir());
1133 service
->comment
= talloc_asprintf(service
, "%s Service (%s)",
1134 fstype
, lp_ctx
->globals
->szServerString
);
1135 string_set(service
, &service
->fstype
, fstype
);
1136 service
->iMaxConnections
= -1;
1137 service
->bAvailable
= true;
1138 service
->bRead_only
= true;
1139 service
->bPrint_ok
= false;
1140 service
->bBrowseable
= false;
1142 if (strcasecmp(fstype
, "IPC") == 0) {
1143 lp_do_service_parameter(lp_ctx
, service
, "ntvfs handler",
1147 DEBUG(3, ("adding hidden service %s\n", name
));
1153 * Add a new printer service, with defaults coming from service iFrom.
1156 bool lp_add_printer(struct loadparm_context
*lp_ctx
,
1157 const char *pszPrintername
,
1158 struct loadparm_service
*default_service
)
1160 const char *comment
= "From Printcap";
1161 struct loadparm_service
*service
;
1162 service
= lp_add_service(lp_ctx
, default_service
, pszPrintername
);
1164 if (service
== NULL
)
1167 /* note that we do NOT default the availability flag to True - */
1168 /* we take it from the default service passed. This allows all */
1169 /* dynamic printers to be disabled by disabling the [printers] */
1170 /* entry (if/when the 'available' keyword is implemented!). */
1172 /* the printer name is set to the service name. */
1173 string_set(service
, &service
->szPrintername
, pszPrintername
);
1174 string_set(service
, &service
->comment
, comment
);
1175 service
->bBrowseable
= default_service
->bBrowseable
;
1176 /* Printers cannot be read_only. */
1177 service
->bRead_only
= false;
1178 /* Printer services must be printable. */
1179 service
->bPrint_ok
= true;
1181 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1187 * Map a parameter's string representation to something we can use.
1188 * Returns False if the parameter string is not recognised, else TRUE.
1191 static int map_parameter(const char *pszParmName
)
1195 if (*pszParmName
== '-')
1198 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1199 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1202 /* Warn only if it isn't parametric option */
1203 if (strchr(pszParmName
, ':') == NULL
)
1204 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
1205 /* We do return 'fail' for parametric options as well because they are
1206 stored in different storage
1213 return the parameter structure for a parameter
1215 struct parm_struct
*lp_parm_struct(const char *name
)
1217 int parmnum
= map_parameter(name
);
1218 if (parmnum
== -1) return NULL
;
1219 return &parm_table
[parmnum
];
1223 return the parameter pointer for a parameter
1225 void *lp_parm_ptr(struct loadparm_context
*lp_ctx
,
1226 struct loadparm_service
*service
, struct parm_struct
*parm
)
1228 if (service
== NULL
) {
1229 if (parm
->pclass
== P_LOCAL
)
1230 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
1231 else if (parm
->pclass
== P_GLOBAL
)
1232 return ((char *)lp_ctx
->globals
)+parm
->offset
;
1235 return ((char *)service
) + parm
->offset
;
1240 * Find a service by name. Otherwise works like get_service.
1243 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1244 const char *pszServiceName
)
1248 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
1249 if (lp_ctx
->services
[iService
] != NULL
&&
1250 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
1251 return lp_ctx
->services
[iService
];
1258 * Copy a service structure to another.
1259 * If pcopymapDest is NULL then copy all fields
1262 static void copy_service(struct loadparm_service
*pserviceDest
,
1263 struct loadparm_service
*pserviceSource
,
1267 bool bcopyall
= (pcopymapDest
== NULL
);
1268 struct parmlist_entry
*data
, *pdata
, *paramo
;
1271 for (i
= 0; parm_table
[i
].label
; i
++)
1272 if (parm_table
[i
].offset
!= -1 && parm_table
[i
].pclass
== P_LOCAL
&&
1273 (bcopyall
|| pcopymapDest
[i
])) {
1275 ((char *)pserviceSource
) + parm_table
[i
].offset
;
1277 ((char *)pserviceDest
) + parm_table
[i
].offset
;
1279 switch (parm_table
[i
].type
) {
1281 *(int *)dest_ptr
= *(int *)src_ptr
;
1287 *(int *)dest_ptr
= *(int *)src_ptr
;
1291 string_set(pserviceDest
,
1297 string_set(pserviceDest
,
1300 strupper(*(char **)dest_ptr
);
1303 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
1304 *(const char ***)src_ptr
);
1312 init_copymap(pserviceDest
);
1313 if (pserviceSource
->copymap
)
1314 memcpy((void *)pserviceDest
->copymap
,
1315 (void *)pserviceSource
->copymap
,
1316 sizeof(int) * NUMPARAMETERS
);
1319 data
= pserviceSource
->param_opt
;
1322 pdata
= pserviceDest
->param_opt
;
1323 /* Traverse destination */
1325 /* If we already have same option, override it */
1326 if (strcmp(pdata
->key
, data
->key
) == 0) {
1327 talloc_free(pdata
->value
);
1328 pdata
->value
= talloc_reference(pdata
,
1333 pdata
= pdata
->next
;
1336 paramo
= talloc(pserviceDest
, struct parmlist_entry
);
1339 paramo
->key
= talloc_reference(paramo
, data
->key
);
1340 paramo
->value
= talloc_reference(paramo
, data
->value
);
1341 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1348 * Check a service for consistency. Return False if the service is in any way
1349 * incomplete or faulty, else True.
1351 static bool service_ok(struct loadparm_service
*service
)
1356 if (service
->szService
[0] == '\0') {
1357 DEBUG(0, ("The following message indicates an internal error:\n"));
1358 DEBUG(0, ("No service name in service entry.\n"));
1362 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1363 /* I can't see why you'd want a non-printable printer service... */
1364 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1365 if (!service
->bPrint_ok
) {
1366 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1367 service
->szService
));
1368 service
->bPrint_ok
= true;
1370 /* [printers] service must also be non-browsable. */
1371 if (service
->bBrowseable
)
1372 service
->bBrowseable
= false;
1375 /* If a service is flagged unavailable, log the fact at level 0. */
1376 if (!service
->bAvailable
)
1377 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1378 service
->szService
));
1384 /*******************************************************************
1385 Keep a linked list of all config files so we know when one has changed
1386 it's date and needs to be reloaded.
1387 ********************************************************************/
1389 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1390 const char *fname
, const char *subfname
)
1392 struct file_lists
*f
= lp_ctx
->file_lists
;
1395 if (f
->name
&& !strcmp(f
->name
, fname
))
1401 f
= talloc(lp_ctx
, struct file_lists
);
1404 f
->next
= lp_ctx
->file_lists
;
1405 f
->name
= talloc_strdup(f
, fname
);
1410 f
->subfname
= talloc_strdup(f
, subfname
);
1415 lp_ctx
->file_lists
= f
;
1416 f
->modtime
= file_modtime(subfname
);
1418 time_t t
= file_modtime(subfname
);
1424 /*******************************************************************
1425 Check if a config file has changed date.
1426 ********************************************************************/
1427 bool lp_file_list_changed(struct loadparm_context
*lp_ctx
)
1429 struct file_lists
*f
;
1430 DEBUG(6, ("lp_file_list_changed()\n"));
1432 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1436 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1438 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1439 f
->name
, n2
, ctime(&f
->modtime
)));
1441 mod_time
= file_modtime(n2
);
1443 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1444 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1446 f
->modtime
= mod_time
;
1447 talloc_free(f
->subfname
);
1448 f
->subfname
= talloc_strdup(f
, n2
);
1455 /***************************************************************************
1456 Handle the "realm" parameter
1457 ***************************************************************************/
1459 static bool handle_realm(struct loadparm_context
*lp_ctx
,
1460 const char *pszParmValue
, char **ptr
)
1462 string_set(lp_ctx
, ptr
, pszParmValue
);
1464 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1465 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1470 /***************************************************************************
1471 Handle the include operation.
1472 ***************************************************************************/
1474 static bool handle_include(struct loadparm_context
*lp_ctx
,
1475 const char *pszParmValue
, char **ptr
)
1477 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1479 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1481 string_set(lp_ctx
, ptr
, fname
);
1483 if (file_exist(fname
))
1484 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1486 DEBUG(2, ("Can't find include file %s\n", fname
));
1491 /***************************************************************************
1492 Handle the interpretation of the copy parameter.
1493 ***************************************************************************/
1495 static bool handle_copy(struct loadparm_context
*lp_ctx
,
1496 const char *pszParmValue
, char **ptr
)
1499 struct loadparm_service
*serviceTemp
;
1501 string_set(lp_ctx
, ptr
, pszParmValue
);
1505 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1507 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1508 if (serviceTemp
== lp_ctx
->currentService
) {
1509 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1511 copy_service(lp_ctx
->currentService
,
1513 lp_ctx
->currentService
->copymap
);
1517 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1525 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
1526 const char *pszParmValue
, char **ptr
)
1528 DEBUGLEVEL
= atoi(pszParmValue
);
1533 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
1534 const char *pszParmValue
, char **ptr
)
1536 logfile
= pszParmValue
;
1540 /***************************************************************************
1541 Initialise a copymap.
1542 ***************************************************************************/
1544 static void init_copymap(struct loadparm_service
*pservice
)
1547 talloc_free(pservice
->copymap
);
1548 pservice
->copymap
= talloc_array(pservice
, int, NUMPARAMETERS
);
1549 if (pservice
->copymap
== NULL
) {
1551 ("Couldn't allocate copymap!! (size %d)\n",
1552 (int)NUMPARAMETERS
));
1555 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1556 pservice
->copymap
[i
] = true;
1560 * Process a parametric option
1562 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1563 struct loadparm_service
*service
,
1564 const char *pszParmName
,
1565 const char *pszParmValue
, int flags
)
1567 struct parmlist_entry
*paramo
, *data
;
1569 TALLOC_CTX
*mem_ctx
;
1571 while (isspace((unsigned char)*pszParmName
)) {
1575 name
= strdup(pszParmName
);
1576 if (!name
) return false;
1580 if (service
== NULL
) {
1581 data
= lp_ctx
->globals
->param_opt
;
1582 mem_ctx
= lp_ctx
->globals
;
1584 data
= service
->param_opt
;
1588 /* Traverse destination */
1589 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1590 /* If we already have the option set, override it unless
1591 it was a command line option and the new one isn't */
1592 if (strcmp(paramo
->key
, name
) == 0) {
1593 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1594 !(flags
& FLAG_CMDLINE
)) {
1598 talloc_free(paramo
->value
);
1599 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1600 paramo
->priority
= flags
;
1606 paramo
= talloc(mem_ctx
, struct parmlist_entry
);
1609 paramo
->key
= talloc_strdup(paramo
, name
);
1610 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1611 paramo
->priority
= flags
;
1612 if (service
== NULL
) {
1613 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1615 DLIST_ADD(service
->param_opt
, paramo
);
1623 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1624 const char *pszParmName
, const char *pszParmValue
,
1625 struct loadparm_context
*lp_ctx
)
1628 /* if it is a special case then go ahead */
1629 if (parm_table
[parmnum
].special
) {
1630 parm_table
[parmnum
].special(lp_ctx
, pszParmValue
,
1635 /* now switch on the type of variable it is */
1636 switch (parm_table
[parmnum
].type
)
1640 if (!set_boolean(pszParmValue
, &b
)) {
1641 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1644 *(int *)parm_ptr
= b
;
1649 *(int *)parm_ptr
= atoi(pszParmValue
);
1653 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1659 if (conv_str_size(pszParmValue
, &val
)) {
1660 if (val
<= INT_MAX
) {
1661 *(int *)parm_ptr
= (int)val
;
1666 DEBUG(0,("lp_do_parameter(%s): value is not "
1667 "a valid size specifier!\n", pszParmValue
));
1672 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1673 pszParmValue
, NULL
);
1677 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1681 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1682 strupper(*(char **)parm_ptr
);
1686 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1689 parm_table
[parmnum
].enum_list
[i
].name
)) {
1691 parm_table
[parmnum
].
1696 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1697 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1698 pszParmValue
, pszParmName
));
1704 if (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
) {
1705 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1706 /* we have to also unset FLAG_DEFAULT on aliases */
1707 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1708 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1710 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1711 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1718 bool lp_do_global_parameter(struct loadparm_context
*lp_ctx
,
1719 const char *pszParmName
, const char *pszParmValue
)
1721 int parmnum
= map_parameter(pszParmName
);
1725 if (strchr(pszParmName
, ':')) {
1726 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1728 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1732 /* if the flag has been set on the command line, then don't allow override,
1733 but don't report an error */
1734 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1738 parm_ptr
= lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1740 return set_variable(lp_ctx
, parmnum
, parm_ptr
,
1741 pszParmName
, pszParmValue
, lp_ctx
);
1744 bool lp_do_service_parameter(struct loadparm_context
*lp_ctx
,
1745 struct loadparm_service
*service
,
1746 const char *pszParmName
, const char *pszParmValue
)
1750 int parmnum
= map_parameter(pszParmName
);
1753 if (strchr(pszParmName
, ':')) {
1754 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1756 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1760 /* if the flag has been set on the command line, then don't allow override,
1761 but don't report an error */
1762 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1766 if (parm_table
[parmnum
].pclass
== P_GLOBAL
) {
1768 ("Global parameter %s found in service section!\n",
1772 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1774 if (!service
->copymap
)
1775 init_copymap(service
);
1777 /* this handles the aliases - set the copymap for other
1778 * entries with the same data pointer */
1779 for (i
= 0; parm_table
[i
].label
; i
++)
1780 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1781 parm_table
[i
].pclass
== parm_table
[parmnum
].pclass
)
1782 service
->copymap
[i
] = false;
1784 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1785 pszParmValue
, lp_ctx
);
1789 * Process a parameter.
1792 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1795 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1797 if (lp_ctx
->bInGlobalSection
)
1798 return lp_do_global_parameter(lp_ctx
, pszParmName
,
1801 return lp_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1802 pszParmName
, pszParmValue
);
1806 variable argument do parameter
1808 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1809 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1810 const char *pszParmName
, const char *fmt
, ...)
1817 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1819 ret
= lp_do_global_parameter(lp_ctx
, pszParmName
, s
);
1826 set a parameter from the commandline - this is called from command line parameter
1827 parsing code. It sets the parameter then marks the parameter as unable to be modified
1828 by smb.conf processing
1830 bool lp_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1831 const char *pszParmValue
)
1833 int parmnum
= map_parameter(pszParmName
);
1836 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1839 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1840 /* set a parametric option */
1841 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1842 pszParmValue
, FLAG_CMDLINE
);
1846 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1850 /* reset the CMDLINE flag in case this has been called before */
1851 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1853 if (!lp_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1857 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1859 /* we have to also set FLAG_CMDLINE on aliases */
1860 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1861 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1863 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1864 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1871 set a option from the commandline in 'a=b' format. Use to support --option
1873 bool lp_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1891 ret
= lp_set_cmdline(lp_ctx
, s
, p
+1);
1897 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1900 * Print a parameter of the specified type.
1903 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1909 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1910 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1912 p
->enum_list
[i
].name
);
1919 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
1924 fprintf(f
, "%d", *(int *)ptr
);
1928 fprintf(f
, "0%o", *(int *)ptr
);
1932 if ((char ***)ptr
&& *(char ***)ptr
) {
1933 char **list
= *(char ***)ptr
;
1935 for (; *list
; list
++)
1936 fprintf(f
, "%s%s", *list
,
1937 ((*(list
+1))?", ":""));
1943 if (*(char **)ptr
) {
1944 fprintf(f
, "%s", *(char **)ptr
);
1951 * Check if two parameters are equal.
1954 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1958 return (*((int *)ptr1
) == *((int *)ptr2
));
1964 return (*((int *)ptr1
) == *((int *)ptr2
));
1967 return str_list_equal((const char **)(*(char ***)ptr1
),
1968 (const char **)(*(char ***)ptr2
));
1973 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1978 return (p1
== p2
|| strequal(p1
, p2
));
1985 * Process a new section (service).
1987 * At this stage all sections are services.
1988 * Later we'll have special sections that permit server parameters to be set.
1989 * Returns True on success, False on failure.
1992 static bool do_section(const char *pszSectionName
, void *userdata
)
1994 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1996 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1997 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2000 /* if we've just struck a global section, note the fact. */
2001 lp_ctx
->bInGlobalSection
= isglobal
;
2003 /* check for multiple global sections */
2004 if (lp_ctx
->bInGlobalSection
) {
2005 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName
));
2009 /* if we have a current service, tidy it up before moving on */
2012 if (lp_ctx
->currentService
!= NULL
)
2013 bRetval
= service_ok(lp_ctx
->currentService
);
2015 /* if all is still well, move to the next record in the services array */
2017 /* We put this here to avoid an odd message order if messages are */
2018 /* issued by the post-processing of a previous section. */
2019 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName
));
2021 if ((lp_ctx
->currentService
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
,
2024 DEBUG(0, ("Failed to add a new service\n"));
2034 * Determine if a particular base parameter is currently set to the default value.
2037 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2039 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2040 if (!defaults_saved
)
2042 switch (parm_table
[i
].type
) {
2044 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2045 (const char **)def_ptr
);
2048 return strequal(parm_table
[i
].def
.svalue
,
2051 return parm_table
[i
].def
.bvalue
==
2057 return parm_table
[i
].def
.ivalue
==
2064 *Display the contents of the global structure.
2067 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2071 struct parmlist_entry
*data
;
2073 fprintf(f
, "# Global parameters\n[global]\n");
2075 for (i
= 0; parm_table
[i
].label
; i
++)
2076 if (parm_table
[i
].pclass
== P_GLOBAL
&&
2077 parm_table
[i
].offset
!= -1 &&
2078 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2079 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2081 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2082 print_parameter(&parm_table
[i
], lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2085 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2086 for (data
= lp_ctx
->globals
->param_opt
; data
;
2087 data
= data
->next
) {
2088 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2095 * Display the contents of a single services record.
2098 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
)
2101 struct parmlist_entry
*data
;
2103 if (pService
!= sDefault
)
2104 fprintf(f
, "\n[%s]\n", pService
->szService
);
2106 for (i
= 0; parm_table
[i
].label
; i
++) {
2107 if (parm_table
[i
].pclass
== P_LOCAL
&&
2108 parm_table
[i
].offset
!= -1 &&
2109 (*parm_table
[i
].label
!= '-') &&
2110 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
2112 if (pService
== sDefault
) {
2113 if (defaults_saved
&& is_default(sDefault
, i
))
2116 if (equal_parameter(parm_table
[i
].type
,
2117 ((char *)pService
) +
2118 parm_table
[i
].offset
,
2119 ((char *)sDefault
) +
2120 parm_table
[i
].offset
))
2124 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2125 print_parameter(&parm_table
[i
],
2126 ((char *)pService
) + parm_table
[i
].offset
, f
);
2130 if (pService
->param_opt
!= NULL
) {
2131 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2132 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2137 bool lp_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2138 struct loadparm_service
*service
,
2139 const char *parm_name
, FILE * f
)
2141 struct parm_struct
*parm
;
2144 parm
= lp_parm_struct(parm_name
);
2149 ptr
= lp_parm_ptr(lp_ctx
, service
,parm
);
2151 print_parameter(parm
, ptr
, f
);
2157 * Return info about the next parameter in a service.
2158 * snum==-1 gives the globals.
2159 * Return NULL when out of parameters.
2162 struct parm_struct
*lp_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
2166 /* do the globals */
2167 for (; parm_table
[*i
].label
; (*i
)++) {
2168 if (parm_table
[*i
].offset
== -1
2169 || (*parm_table
[*i
].label
== '-'))
2173 && (parm_table
[*i
].offset
==
2174 parm_table
[(*i
) - 1].offset
))
2177 return &parm_table
[(*i
)++];
2180 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
2182 for (; parm_table
[*i
].label
; (*i
)++) {
2183 if (parm_table
[*i
].pclass
== P_LOCAL
&&
2184 parm_table
[*i
].offset
!= -1 &&
2185 (*parm_table
[*i
].label
!= '-') &&
2187 (parm_table
[*i
].offset
!=
2188 parm_table
[(*i
) - 1].offset
)))
2190 if (allparameters
||
2191 !equal_parameter(parm_table
[*i
].type
,
2192 ((char *)pService
) +
2193 parm_table
[*i
].offset
,
2194 ((char *)lp_ctx
->sDefault
) +
2195 parm_table
[*i
].offset
))
2197 return &parm_table
[(*i
)++];
2208 * Auto-load some home services.
2210 static void lp_add_auto_services(struct loadparm_context
*lp_ctx
,
2218 * Unload unused services.
2221 void lp_killunused(struct loadparm_context
*lp_ctx
,
2222 struct smbsrv_connection
*smb
,
2223 bool (*snumused
) (struct smbsrv_connection
*, int))
2226 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2227 if (lp_ctx
->services
[i
] == NULL
)
2230 if (!snumused
|| !snumused(smb
, i
)) {
2231 talloc_free(lp_ctx
->services
[i
]);
2232 lp_ctx
->services
[i
] = NULL
;
2238 static int lp_destructor(struct loadparm_context
*lp_ctx
)
2240 struct parmlist_entry
*data
;
2242 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2243 struct parmlist_entry
*next
;
2244 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2246 if (data
->priority
& FLAG_CMDLINE
) continue;
2247 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2256 * Initialise the global parameter structure.
2258 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2262 struct loadparm_context
*lp_ctx
;
2264 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2268 talloc_set_destructor(lp_ctx
, lp_destructor
);
2269 lp_ctx
->bInGlobalSection
= true;
2270 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2271 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2273 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2274 lp_ctx
->sDefault
->bAvailable
= true;
2275 lp_ctx
->sDefault
->bBrowseable
= true;
2276 lp_ctx
->sDefault
->bRead_only
= true;
2277 lp_ctx
->sDefault
->bMap_archive
= true;
2278 lp_ctx
->sDefault
->bStrictLocking
= true;
2279 lp_ctx
->sDefault
->bOplocks
= true;
2280 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2281 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2282 lp_ctx
->sDefault
->iDir_mask
= 0755;
2283 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2285 DEBUG(3, ("Initialising global parameters\n"));
2287 for (i
= 0; parm_table
[i
].label
; i
++) {
2288 if ((parm_table
[i
].type
== P_STRING
||
2289 parm_table
[i
].type
== P_USTRING
) &&
2290 parm_table
[i
].offset
!= -1 &&
2291 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2293 if (parm_table
[i
].pclass
== P_LOCAL
) {
2294 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2296 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2298 *r
= talloc_strdup(lp_ctx
, "");
2302 lp_do_global_parameter(lp_ctx
, "share backend", "classic");
2304 lp_do_global_parameter(lp_ctx
, "server role", "standalone");
2306 /* options that can be set on the command line must be initialised via
2307 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2309 lp_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2311 lp_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2312 myname
= get_myname(lp_ctx
);
2313 lp_do_global_parameter(lp_ctx
, "netbios name", myname
);
2314 talloc_free(myname
);
2315 lp_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2317 lp_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2319 lp_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2320 lp_do_global_parameter(lp_ctx
, "max connections", "-1");
2322 lp_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser");
2323 lp_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc");
2324 lp_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
2325 lp_do_global_parameter(lp_ctx
, "auth methods:domain controller", "anonymous sam_ignoredomain");
2326 lp_do_global_parameter(lp_ctx
, "auth methods:member server", "anonymous sam winbind");
2327 lp_do_global_parameter(lp_ctx
, "auth methods:standalone", "anonymous sam_ignoredomain");
2328 lp_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2329 lp_do_global_parameter(lp_ctx
, "sam database", "sam.ldb");
2330 lp_do_global_parameter(lp_ctx
, "idmap database", "idmap.ldb");
2331 lp_do_global_parameter(lp_ctx
, "secrets database", "secrets.ldb");
2332 lp_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
2333 lp_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
2334 lp_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
2335 lp_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2337 /* This hive should be dynamically generated by Samba using
2338 data from the sam, but for the moment leave it in a tdb to
2339 keep regedt32 from popping up an annoying dialog. */
2340 lp_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2342 /* using UTF8 by default allows us to support all chars */
2343 lp_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2345 /* Use codepage 850 as a default for the dos character set */
2346 lp_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2349 * Allow the default PASSWD_CHAT to be overridden in local.h.
2351 lp_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2353 lp_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2354 lp_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2355 lp_do_global_parameter(lp_ctx
, "modules dir", dyn_MODULESDIR
);
2356 lp_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2358 lp_do_global_parameter(lp_ctx
, "socket address", "0.0.0.0");
2359 lp_do_global_parameter_var(lp_ctx
, "server string",
2360 "Samba %s", SAMBA_VERSION_STRING
);
2362 lp_do_global_parameter_var(lp_ctx
, "announce version", "%d.%d",
2363 DEFAULT_MAJOR_VERSION
,
2364 DEFAULT_MINOR_VERSION
);
2366 lp_do_global_parameter(lp_ctx
, "password server", "*");
2368 lp_do_global_parameter(lp_ctx
, "max mux", "50");
2369 lp_do_global_parameter(lp_ctx
, "max xmit", "12288");
2370 lp_do_global_parameter(lp_ctx
, "password level", "0");
2371 lp_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2372 lp_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2373 lp_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2374 lp_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2375 lp_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2376 lp_do_global_parameter(lp_ctx
, "security", "USER");
2377 lp_do_global_parameter(lp_ctx
, "paranoid server security", "True");
2378 lp_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2379 lp_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2380 lp_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2381 lp_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2382 lp_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2383 lp_do_global_parameter(lp_ctx
, "announce as", "NT SERVER");
2385 lp_do_global_parameter(lp_ctx
, "TimeServer", "False");
2386 lp_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2387 lp_do_global_parameter(lp_ctx
, "Unicode", "True");
2388 lp_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2389 lp_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2390 lp_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2391 lp_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2393 lp_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2395 lp_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2396 lp_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2398 lp_do_global_parameter(lp_ctx
, "wins support", "False");
2399 lp_do_global_parameter(lp_ctx
, "dns proxy", "True");
2401 lp_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2402 lp_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2403 lp_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2404 lp_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2405 lp_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2406 lp_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2407 lp_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
2409 lp_do_global_parameter(lp_ctx
, "client signing", "Yes");
2410 lp_do_global_parameter(lp_ctx
, "server signing", "auto");
2412 lp_do_global_parameter(lp_ctx
, "use spnego", "True");
2414 lp_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2415 lp_do_global_parameter(lp_ctx
, "nbt port", "137");
2416 lp_do_global_parameter(lp_ctx
, "dgram port", "138");
2417 lp_do_global_parameter(lp_ctx
, "cldap port", "389");
2418 lp_do_global_parameter(lp_ctx
, "krb5 port", "88");
2419 lp_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2420 lp_do_global_parameter(lp_ctx
, "web port", "901");
2421 lp_do_global_parameter(lp_ctx
, "swat directory", dyn_SWATDIR
);
2423 lp_do_global_parameter(lp_ctx
, "nt status support", "True");
2425 lp_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2426 lp_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2428 lp_do_global_parameter(lp_ctx
, "tls enabled", "True");
2429 lp_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2430 lp_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2431 lp_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2432 lp_do_global_parameter_var(lp_ctx
, "setup directory", "%s",
2435 lp_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2437 lp_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2439 for (i
= 0; parm_table
[i
].label
; i
++) {
2440 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2441 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2448 const char *lp_configfile(struct loadparm_context
*lp_ctx
)
2450 return lp_ctx
->szConfigFile
;
2453 const char *lp_default_path(void)
2455 if (getenv("SMB_CONF_PATH"))
2456 return getenv("SMB_CONF_PATH");
2458 return dyn_CONFIGFILE
;
2462 * Update the internal state of a loadparm context after settings
2465 static bool lp_update(struct loadparm_context
*lp_ctx
)
2467 lp_add_auto_services(lp_ctx
, lp_auto_services(lp_ctx
));
2469 lp_add_hidden(lp_ctx
, "IPC$", "IPC");
2470 lp_add_hidden(lp_ctx
, "ADMIN$", "DISK");
2472 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2473 lp_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2476 panic_action
= lp_ctx
->globals
->panic_action
;
2478 reload_charcnv(lp_ctx
);
2480 /* FIXME: ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx); */
2482 /* FIXME: This is a bit of a hack, but we can't use a global, since
2483 * not everything that uses lp also uses the socket library */
2484 if (lp_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2485 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2487 unsetenv("SOCKET_TESTNONBLOCK");
2490 /* FIXME: Check locale in environment for this: */
2491 if (strcmp(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)) != 0)
2492 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)));
2494 d_set_iconv((smb_iconv_t
)-1);
2499 bool lp_load_default(struct loadparm_context
*lp_ctx
)
2503 path
= lp_default_path();
2505 if (!file_exist(path
)) {
2506 /* We allow the default smb.conf file to not exist,
2507 * basically the equivalent of an empty file. */
2508 return lp_update(lp_ctx
);
2511 return lp_load(lp_ctx
, path
);
2515 * Load the services array from the services file.
2517 * Return True on success, False on failure.
2519 bool lp_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2524 filename
= talloc_strdup(lp_ctx
, filename
);
2526 lp_ctx
->szConfigFile
= filename
;
2528 lp_ctx
->bInGlobalSection
= true;
2529 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2530 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2
));
2532 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2534 /* We get sections first, so have to start 'behind' to make up */
2535 lp_ctx
->currentService
= NULL
;
2536 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2538 /* finish up the last section */
2539 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2541 if (lp_ctx
->currentService
!= NULL
)
2542 bRetval
= service_ok(lp_ctx
->currentService
);
2544 bRetval
= bRetval
&& lp_update(lp_ctx
);
2550 * Return the max number of services.
2553 int lp_numservices(struct loadparm_context
*lp_ctx
)
2555 return lp_ctx
->iNumServices
;
2559 * Display the contents of the services array in human-readable form.
2562 void lp_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2568 defaults_saved
= false;
2570 dump_globals(lp_ctx
, f
, show_defaults
);
2572 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
);
2574 for (iService
= 0; iService
< maxtoprint
; iService
++)
2575 lp_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2579 * Display the contents of one service in human-readable form.
2581 void lp_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2583 if (service
!= NULL
) {
2584 if (service
->szService
[0] == '\0')
2586 dump_a_service(service
, sDefault
, f
);
2590 struct loadparm_service
*lp_servicebynum(struct loadparm_context
*lp_ctx
,
2593 return lp_ctx
->services
[snum
];
2596 struct loadparm_service
*lp_service(struct loadparm_context
*lp_ctx
,
2597 const char *service_name
)
2602 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2603 if (lp_ctx
->services
[iService
] &&
2604 lp_ctx
->services
[iService
]->szService
) {
2606 * The substitution here is used to support %U is
2609 serviceName
= standard_sub_basic(
2610 lp_ctx
->services
[iService
],
2611 lp_ctx
->services
[iService
]->szService
);
2612 if (strequal(serviceName
, service_name
)) {
2613 talloc_free(serviceName
);
2614 return lp_ctx
->services
[iService
];
2616 talloc_free(serviceName
);
2620 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name
));
2626 * A useful volume label function.
2628 const char *volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2630 const char *ret
= lp_volume(service
, sDefault
);
2632 return lp_servicename(service
);
2638 * If we are PDC then prefer us as DMB
2640 const char *lp_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2642 const char *ret
= _lp_printername(service
, sDefault
);
2643 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2644 ret
= lp_servicename(service
);
2651 * Return the max print jobs per queue.
2653 int lp_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2655 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2656 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2657 maxjobs
= PRINT_MAX_JOBID
- 1;
2662 struct smb_iconv_convenience
*lp_iconv_convenience(struct loadparm_context
*lp_ctx
)
2664 if (lp_ctx
== NULL
) {
2665 static struct smb_iconv_convenience
*fallback_ic
= NULL
;
2666 if (fallback_ic
== NULL
)
2667 fallback_ic
= smb_iconv_convenience_init(talloc_autofree_context(),
2668 "CP850", "UTF8", true);
2671 return lp_ctx
->iconv_convenience
;
2674 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2676 talloc_unlink(lp_ctx
, lp_ctx
->iconv_convenience
);
2677 global_iconv_convenience
= lp_ctx
->iconv_convenience
= smb_iconv_convenience_init_lp(lp_ctx
, lp_ctx
);
2680 void lp_smbcli_options(struct loadparm_context
*lp_ctx
,
2681 struct smbcli_options
*options
)
2683 options
->max_xmit
= lp_max_xmit(lp_ctx
);
2684 options
->max_mux
= lp_maxmux(lp_ctx
);
2685 options
->use_spnego
= lp_nt_status_support(lp_ctx
) && lp_use_spnego(lp_ctx
);
2686 options
->signing
= lp_client_signing(lp_ctx
);
2687 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
2688 options
->ntstatus_support
= lp_nt_status_support(lp_ctx
);
2689 options
->max_protocol
= lp_cli_maxprotocol(lp_ctx
);
2690 options
->unicode
= lp_unicode(lp_ctx
);
2691 options
->use_oplocks
= true;
2692 options
->use_level2_oplocks
= true;
2695 void lp_smbcli_session_options(struct loadparm_context
*lp_ctx
,
2696 struct smbcli_session_options
*options
)
2698 options
->lanman_auth
= lp_client_lanman_auth(lp_ctx
);
2699 options
->ntlmv2_auth
= lp_client_ntlmv2_auth(lp_ctx
);
2700 options
->plaintext_auth
= lp_client_plaintext_auth(lp_ctx
);
2703 _PUBLIC_
char *lp_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2705 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2708 _PUBLIC_
char *lp_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2710 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2713 _PUBLIC_
char *lp_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2715 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2718 _PUBLIC_
char *lp_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2720 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2723 _PUBLIC_
char *lp_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2725 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2728 _PUBLIC_
struct dcerpc_server_info
*lp_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2730 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
2732 ret
->domain_name
= talloc_reference(mem_ctx
, lp_workgroup(lp_ctx
));
2733 ret
->version_major
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
2734 ret
->version_minor
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
2735 ret
->version_build
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
2740 struct gensec_settings
*lp_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2742 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
2743 if (settings
== NULL
)
2745 SMB_ASSERT(lp_ctx
!= NULL
);
2746 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2747 settings
->iconv_convenience
= lp_iconv_convenience(lp_ctx
);
2748 settings
->target_hostname
= lp_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");