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
;
82 enum sid_generator sid_generator
;
84 const char **smb_ports
;
88 char *display_charset
;
101 char *szWINS_CONFIG_URL
;
104 const char **szPasswordServers
;
105 char *szSocketOptions
;
109 const char **szWINSservers
;
110 const char **szInterfaces
;
111 char *szSocketAddress
;
112 char *szAnnounceVersion
; /* This is initialised in init_globals */
115 const char **szNetbiosAliases
;
116 char *szNetbiosScope
;
117 char *szDomainOtherSIDs
;
118 const char **szNameResolveOrder
;
119 const char **dcerpc_ep_servers
;
120 const char **server_services
;
121 char *ntptr_providor
;
122 char *szWinbindSeparator
;
123 char *szWinbinddPrivilegedSocketDirectory
;
124 char *szWinbinddSocketDirectory
;
125 char *szTemplateShell
;
126 char *szTemplateHomedir
;
127 int bWinbindSealedPipes
;
128 int bIdmapTrustedOnly
;
129 char *swat_directory
;
147 int paranoid_server_security
;
150 int announce_as
; /* This is initialised in init_globals */
157 char *socket_options
;
162 int bPreferredMaster
;
163 int bEncryptPasswords
;
165 int bObeyPamRestrictions
;
170 int bBindInterfacesOnly
;
172 int bNTStatusSupport
;
178 int bClientPlaintextAuth
;
179 int bClientLanManAuth
;
180 int bClientNTLMv2Auth
;
181 int client_use_spnego_principal
;
187 char *szNTPSignDSocketDirectory
;
188 struct parmlist_entry
*param_opt
;
193 * This structure describes a single service.
195 struct loadparm_service
207 char **ntvfs_handler
;
221 int iCreate_force_mode
;
228 struct parmlist_entry
*param_opt
;
230 char dummy
[3]; /* for alignment */
234 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
237 /* prototypes for the special type handlers */
238 static bool handle_include(struct loadparm_context
*lp_ctx
,
239 const char *pszParmValue
, char **ptr
);
240 static bool handle_realm(struct loadparm_context
*lp_ctx
,
241 const char *pszParmValue
, char **ptr
);
242 static bool handle_copy(struct loadparm_context
*lp_ctx
,
243 const char *pszParmValue
, char **ptr
);
244 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
245 const char *pszParmValue
, char **ptr
);
246 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
247 const char *pszParmValue
, char **ptr
);
249 static const struct enum_list enum_protocol
[] = {
250 {PROTOCOL_SMB2
, "SMB2"},
251 {PROTOCOL_NT1
, "NT1"},
252 {PROTOCOL_LANMAN2
, "LANMAN2"},
253 {PROTOCOL_LANMAN1
, "LANMAN1"},
254 {PROTOCOL_CORE
, "CORE"},
255 {PROTOCOL_COREPLUS
, "COREPLUS"},
256 {PROTOCOL_COREPLUS
, "CORE+"},
260 static const struct enum_list enum_security
[] = {
261 {SEC_SHARE
, "SHARE"},
266 static const struct enum_list enum_announce_as
[] = {
267 {ANNOUNCE_AS_NT_SERVER
, "NT"},
268 {ANNOUNCE_AS_NT_SERVER
, "NT Server"},
269 {ANNOUNCE_AS_NT_WORKSTATION
, "NT Workstation"},
270 {ANNOUNCE_AS_WIN95
, "win95"},
271 {ANNOUNCE_AS_WFW
, "WfW"},
275 static const struct enum_list enum_bool_auto
[] = {
286 /* Client-side offline caching policy types */
289 CSC_POLICY_DOCUMENTS
=1,
290 CSC_POLICY_PROGRAMS
=2,
294 static const struct enum_list enum_csc_policy
[] = {
295 {CSC_POLICY_MANUAL
, "manual"},
296 {CSC_POLICY_DOCUMENTS
, "documents"},
297 {CSC_POLICY_PROGRAMS
, "programs"},
298 {CSC_POLICY_DISABLE
, "disable"},
302 /* SMB signing types. */
303 static const struct enum_list enum_smb_signing_vals
[] = {
304 {SMB_SIGNING_OFF
, "No"},
305 {SMB_SIGNING_OFF
, "False"},
306 {SMB_SIGNING_OFF
, "0"},
307 {SMB_SIGNING_OFF
, "Off"},
308 {SMB_SIGNING_OFF
, "disabled"},
309 {SMB_SIGNING_SUPPORTED
, "Yes"},
310 {SMB_SIGNING_SUPPORTED
, "True"},
311 {SMB_SIGNING_SUPPORTED
, "1"},
312 {SMB_SIGNING_SUPPORTED
, "On"},
313 {SMB_SIGNING_SUPPORTED
, "enabled"},
314 {SMB_SIGNING_REQUIRED
, "required"},
315 {SMB_SIGNING_REQUIRED
, "mandatory"},
316 {SMB_SIGNING_REQUIRED
, "force"},
317 {SMB_SIGNING_REQUIRED
, "forced"},
318 {SMB_SIGNING_REQUIRED
, "enforced"},
319 {SMB_SIGNING_AUTO
, "auto"},
323 static const struct enum_list enum_server_role
[] = {
324 {ROLE_STANDALONE
, "standalone"},
325 {ROLE_DOMAIN_MEMBER
, "member server"},
326 {ROLE_DOMAIN_MEMBER
, "member"},
327 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
328 {ROLE_DOMAIN_CONTROLLER
, "dc"},
332 static const struct enum_list enum_sid_generator
[] = {
333 {SID_GENERATOR_INTERNAL
, "internal"},
334 {SID_GENERATOR_BACKEND
, "backend"},
338 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
339 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
341 static struct parm_struct parm_table
[] = {
342 {"server role", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_role
), NULL
, enum_server_role
},
343 {"sid generator", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(sid_generator
), NULL
, enum_sid_generator
},
345 {"dos charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(dos_charset
), NULL
, NULL
},
346 {"unix charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(unix_charset
), NULL
, NULL
},
347 {"ncalrpc dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ncalrpc_dir
), NULL
, NULL
},
348 {"display charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(display_charset
), NULL
, NULL
},
349 {"comment", P_STRING
, P_LOCAL
, LOCAL_VAR(comment
), NULL
, NULL
},
350 {"path", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
351 {"directory", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
352 {"workgroup", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szWorkgroup
), NULL
, NULL
},
353 {"realm", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szRealm
), handle_realm
, NULL
},
354 {"netbios name", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosName
), NULL
, NULL
},
355 {"netbios aliases", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNetbiosAliases
), NULL
, NULL
},
356 {"netbios scope", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosScope
), NULL
, NULL
},
357 {"server string", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szServerString
), NULL
, NULL
},
358 {"interfaces", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szInterfaces
), NULL
, NULL
},
359 {"bind interfaces only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bBindInterfacesOnly
), NULL
, NULL
},
360 {"ntvfs handler", P_LIST
, P_LOCAL
, LOCAL_VAR(ntvfs_handler
), NULL
, NULL
},
361 {"ntptr providor", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ntptr_providor
), NULL
, NULL
},
362 {"dcerpc endpoint servers", P_LIST
, P_GLOBAL
, GLOBAL_VAR(dcerpc_ep_servers
), NULL
, NULL
},
363 {"server services", P_LIST
, P_GLOBAL
, GLOBAL_VAR(server_services
), NULL
, NULL
},
365 {"security", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(security
), NULL
, enum_security
},
366 {"encrypt passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bEncryptPasswords
), NULL
, NULL
},
367 {"null passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNullPasswords
), NULL
, NULL
},
368 {"obey pam restrictions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bObeyPamRestrictions
), NULL
, NULL
},
369 {"password server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szPasswordServers
), NULL
, NULL
},
370 {"sam database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSAM_URL
), NULL
, NULL
},
371 {"idmap database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szIDMAP_URL
), NULL
, NULL
},
372 {"secrets database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSECRETS_URL
), NULL
, NULL
},
373 {"spoolss database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSPOOLSS_URL
), NULL
, NULL
},
374 {"wins config database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_CONFIG_URL
), NULL
, NULL
},
375 {"wins database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_URL
), NULL
, NULL
},
376 {"private dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPrivateDir
), NULL
, NULL
},
377 {"passwd chat", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPasswdChat
), NULL
, NULL
},
378 {"password level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(pwordlevel
), NULL
, NULL
},
379 {"lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLanmanAuth
), NULL
, NULL
},
380 {"ntlm auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTLMAuth
), NULL
, NULL
},
381 {"client NTLMv2 auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientNTLMv2Auth
), NULL
, NULL
},
382 {"client lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientLanManAuth
), NULL
, NULL
},
383 {"client plaintext auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientPlaintextAuth
), NULL
, NULL
},
384 {"client use spnego principal", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(client_use_spnego_principal
), NULL
, NULL
},
386 {"read only", P_BOOL
, P_LOCAL
, LOCAL_VAR(bRead_only
), NULL
, NULL
},
388 {"create mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_mask
), NULL
, NULL
},
389 {"force create mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_force_mode
), NULL
, NULL
},
390 {"directory mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_mask
), NULL
, NULL
},
391 {"force directory mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_force_mode
), NULL
, NULL
},
393 {"hosts allow", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsallow
), NULL
, NULL
},
394 {"hosts deny", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsdeny
), NULL
, NULL
},
396 {"log level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
397 {"debuglevel", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
398 {"log file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(logfile
), handle_logfile
, NULL
},
400 {"smb ports", P_LIST
, P_GLOBAL
, GLOBAL_VAR(smb_ports
), NULL
, NULL
},
401 {"nbt port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(nbt_port
), NULL
, NULL
},
402 {"dgram port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(dgram_port
), NULL
, NULL
},
403 {"cldap port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(cldap_port
), NULL
, NULL
},
404 {"krb5 port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(krb5_port
), NULL
, NULL
},
405 {"kpasswd port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(kpasswd_port
), NULL
, NULL
},
406 {"web port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(web_port
), NULL
, NULL
},
407 {"tls enabled", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(tls_enabled
), NULL
, NULL
},
408 {"tls keyfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_keyfile
), NULL
, NULL
},
409 {"tls certfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_certfile
), NULL
, NULL
},
410 {"tls cafile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_cafile
), NULL
, NULL
},
411 {"tls crlfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_crlfile
), NULL
, NULL
},
412 {"tls dh params file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_dhpfile
), NULL
, NULL
},
413 {"swat directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(swat_directory
), NULL
, NULL
},
414 {"large readwrite", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLargeReadwrite
), NULL
, NULL
},
415 {"server max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_maxprotocol
), NULL
, enum_protocol
},
416 {"server min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_minprotocol
), NULL
, enum_protocol
},
417 {"client max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_maxprotocol
), NULL
, enum_protocol
},
418 {"client min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_minprotocol
), NULL
, enum_protocol
},
419 {"unicode", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnicode
), NULL
, NULL
},
420 {"read raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bReadRaw
), NULL
, NULL
},
421 {"write raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWriteRaw
), NULL
, NULL
},
422 {"disable netbios", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bDisableNetbios
), NULL
, NULL
},
424 {"nt status support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTStatusSupport
), NULL
, NULL
},
426 {"announce version", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAnnounceVersion
), NULL
, NULL
},
427 {"announce as", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(announce_as
), NULL
, enum_announce_as
},
428 {"max mux", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_mux
), NULL
, NULL
},
429 {"max xmit", P_BYTES
, P_GLOBAL
, GLOBAL_VAR(max_xmit
), NULL
, NULL
},
431 {"name resolve order", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNameResolveOrder
), NULL
, NULL
},
432 {"max wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_wins_ttl
), NULL
, NULL
},
433 {"min wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(min_wins_ttl
), NULL
, NULL
},
434 {"time server", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bTimeServer
), NULL
, NULL
},
435 {"unix extensions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnixExtensions
), NULL
, NULL
},
436 {"use spnego", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUseSpnego
), NULL
, NULL
},
437 {"server signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_signing
), NULL
, enum_smb_signing_vals
},
438 {"client signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(client_signing
), NULL
, enum_smb_signing_vals
},
439 {"rpc big endian", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bRpcBigEndian
), NULL
, NULL
},
441 {"max connections", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxConnections
), NULL
, NULL
},
442 {"paranoid server security", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(paranoid_server_security
), NULL
, NULL
},
443 {"socket options", P_STRING
, P_GLOBAL
, GLOBAL_VAR(socket_options
), NULL
, NULL
},
445 {"strict sync", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictSync
), NULL
, NULL
},
446 {"case insensitive filesystem", P_BOOL
, P_LOCAL
, LOCAL_VAR(bCIFileSystem
), NULL
, NULL
},
448 {"max print jobs", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxPrintJobs
), NULL
, NULL
},
449 {"printable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
450 {"print ok", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
452 {"printer name", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
453 {"printer", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
455 {"map system", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_system
), NULL
, NULL
},
456 {"map hidden", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_hidden
), NULL
, NULL
},
457 {"map archive", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_archive
), NULL
, NULL
},
459 {"preferred master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
460 {"prefered master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
461 {"local master", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLocalMaster
), NULL
, NULL
},
462 {"browseable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
463 {"browsable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
465 {"wins server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szWINSservers
), NULL
, NULL
},
466 {"wins support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSsupport
), NULL
, NULL
},
467 {"dns proxy", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSdnsProxy
), NULL
, NULL
},
468 {"wins hook", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINSHook
), NULL
, NULL
},
470 {"csc policy", P_ENUM
, P_LOCAL
, LOCAL_VAR(iCSCPolicy
), NULL
, enum_csc_policy
},
472 {"strict locking", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictLocking
), NULL
, NULL
},
473 {"oplocks", P_BOOL
, P_LOCAL
, LOCAL_VAR(bOplocks
), NULL
, NULL
},
475 {"share backend", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szShareBackend
), NULL
, NULL
},
476 {"preload", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
477 {"auto services", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
478 {"lock dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
479 {"lock directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
480 {"modules dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szModulesDir
), NULL
, NULL
},
481 {"pid directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPidDir
), NULL
, NULL
},
482 {"setup directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSetupDir
), NULL
, NULL
},
484 {"socket address", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSocketAddress
), NULL
, NULL
},
485 {"copy", P_STRING
, P_LOCAL
, LOCAL_VAR(szCopy
), handle_copy
, NULL
},
486 {"include", P_STRING
, P_LOCAL
, LOCAL_VAR(szInclude
), handle_include
, NULL
},
488 {"available", P_BOOL
, P_LOCAL
, LOCAL_VAR(bAvailable
), NULL
, NULL
},
489 {"volume", P_STRING
, P_LOCAL
, LOCAL_VAR(volume
), NULL
, NULL
},
490 {"fstype", P_STRING
, P_LOCAL
, LOCAL_VAR(fstype
), NULL
, NULL
},
492 {"panic action", P_STRING
, P_GLOBAL
, GLOBAL_VAR(panic_action
), NULL
, NULL
},
494 {"msdfs root", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMSDfsRoot
), NULL
, NULL
},
495 {"host msdfs", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bHostMSDfs
), NULL
, NULL
},
496 {"winbind separator", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbindSeparator
), NULL
, NULL
},
497 {"winbindd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddSocketDirectory
), NULL
, NULL
},
498 {"winbindd privileged socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
), NULL
, NULL
},
499 {"winbind sealed pipes", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWinbindSealedPipes
), NULL
, NULL
},
500 {"template shell", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateShell
), NULL
, NULL
},
501 {"template homedir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateHomedir
), NULL
, NULL
},
502 {"idmap trusted only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bIdmapTrustedOnly
), NULL
, NULL
},
504 {"ntp signd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szNTPSignDSocketDirectory
), NULL
, NULL
},
506 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
}
510 /* local variables */
511 struct loadparm_context
{
512 const char *szConfigFile
;
513 struct loadparm_global
*globals
;
514 struct loadparm_service
**services
;
515 struct loadparm_service
*sDefault
;
517 struct loadparm_service
*currentService
;
518 bool bInGlobalSection
;
520 struct file_lists
*next
;
525 unsigned int flags
[NUMPARAMETERS
];
526 struct smb_iconv_convenience
*iconv_convenience
;
530 struct loadparm_service
*lp_default_service(struct loadparm_context
*lp_ctx
)
532 return lp_ctx
->sDefault
;
536 return the parameter table
538 struct parm_struct
*lp_parm_table(void)
544 * Convenience routine to grab string parameters into temporary memory
545 * and run standard_sub_basic on them.
547 * The buffers can be written to by
548 * callers without affecting the source string.
551 static const char *lp_string(const char *s
)
553 #if 0 /* until REWRITE done to make thread-safe */
554 size_t len
= s
? strlen(s
) : 0;
558 /* The follow debug is useful for tracking down memory problems
559 especially if you have an inner loop that is calling a lp_*()
560 function that returns a string. Perhaps this debug should be
561 present all the time? */
564 DEBUG(10, ("lp_string(%s)\n", s
));
567 #if 0 /* until REWRITE done to make thread-safe */
569 lp_talloc
= talloc_init("lp_talloc");
571 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
579 strlcpy(ret
, s
, len
);
581 if (trim_string(ret
, "\"", "\"")) {
582 if (strchr(ret
,'"') != NULL
)
583 strlcpy(ret
, s
, len
);
586 standard_sub_basic(ret
,len
+100);
593 In this section all the functions that are used to access the
594 parameters from the rest of the program are defined
597 #define FN_GLOBAL_STRING(fn_name,var_name) \
598 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) : "";}
599 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
600 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 : "";}
601 #define FN_GLOBAL_LIST(fn_name,var_name) \
602 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
603 #define FN_GLOBAL_BOOL(fn_name,var_name) \
604 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
606 #define FN_GLOBAL_CHAR(fn_name,ptr) \
607 char fn_name(void) {return(*(char *)(ptr));}
609 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
610 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
612 #define FN_LOCAL_STRING(fn_name,val) \
613 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)));}
614 #define FN_LOCAL_LIST(fn_name,val) \
615 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
616 #define FN_LOCAL_BOOL(fn_name,val) \
617 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
618 #define FN_LOCAL_INTEGER(fn_name,val) \
619 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
621 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_role
, server_role
)
622 _PUBLIC_
FN_GLOBAL_INTEGER(lp_sid_generator
, sid_generator
)
623 _PUBLIC_
FN_GLOBAL_LIST(lp_smb_ports
, smb_ports
)
624 _PUBLIC_
FN_GLOBAL_INTEGER(lp_nbt_port
, nbt_port
)
625 _PUBLIC_
FN_GLOBAL_INTEGER(lp_dgram_port
, dgram_port
)
626 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cldap_port
, cldap_port
)
627 _PUBLIC_
FN_GLOBAL_INTEGER(lp_krb5_port
, krb5_port
)
628 _PUBLIC_
FN_GLOBAL_INTEGER(lp_kpasswd_port
, kpasswd_port
)
629 _PUBLIC_
FN_GLOBAL_INTEGER(lp_web_port
, web_port
)
630 _PUBLIC_
FN_GLOBAL_STRING(lp_swat_directory
, swat_directory
)
631 _PUBLIC_
FN_GLOBAL_BOOL(lp_tls_enabled
, tls_enabled
)
632 _PUBLIC_
FN_GLOBAL_STRING(lp_share_backend
, szShareBackend
)
633 _PUBLIC_
FN_GLOBAL_STRING(lp_sam_url
, szSAM_URL
)
634 _PUBLIC_
FN_GLOBAL_STRING(lp_idmap_url
, szIDMAP_URL
)
635 _PUBLIC_
FN_GLOBAL_STRING(lp_secrets_url
, szSECRETS_URL
)
636 _PUBLIC_
FN_GLOBAL_STRING(lp_spoolss_url
, szSPOOLSS_URL
)
637 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_config_url
, szWINS_CONFIG_URL
)
638 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_url
, szWINS_URL
)
639 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbind_separator
, szWinbindSeparator
)
640 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory
, szWinbinddSocketDirectory
)
641 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
642 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_shell
, szTemplateShell
)
643 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_homedir
, szTemplateHomedir
)
644 _PUBLIC_
FN_GLOBAL_BOOL(lp_winbind_sealed_pipes
, bWinbindSealedPipes
)
645 _PUBLIC_
FN_GLOBAL_BOOL(lp_idmap_trusted_only
, bIdmapTrustedOnly
)
646 _PUBLIC_
FN_GLOBAL_STRING(lp_private_dir
, szPrivateDir
)
647 _PUBLIC_
FN_GLOBAL_STRING(lp_serverstring
, szServerString
)
648 _PUBLIC_
FN_GLOBAL_STRING(lp_lockdir
, szLockDir
)
649 _PUBLIC_
FN_GLOBAL_STRING(lp_modulesdir
, szModulesDir
)
650 _PUBLIC_
FN_GLOBAL_STRING(lp_setupdir
, szSetupDir
)
651 _PUBLIC_
FN_GLOBAL_STRING(lp_ncalrpc_dir
, ncalrpc_dir
)
652 _PUBLIC_
FN_GLOBAL_STRING(lp_dos_charset
, dos_charset
)
653 _PUBLIC_
FN_GLOBAL_STRING(lp_unix_charset
, unix_charset
)
654 _PUBLIC_
FN_GLOBAL_STRING(lp_display_charset
, display_charset
)
655 _PUBLIC_
FN_GLOBAL_STRING(lp_piddir
, szPidDir
)
656 _PUBLIC_
FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers
, dcerpc_ep_servers
)
657 _PUBLIC_
FN_GLOBAL_LIST(lp_server_services
, server_services
)
658 _PUBLIC_
FN_GLOBAL_STRING(lp_ntptr_providor
, ntptr_providor
)
659 _PUBLIC_
FN_GLOBAL_STRING(lp_auto_services
, szAutoServices
)
660 _PUBLIC_
FN_GLOBAL_STRING(lp_passwd_chat
, szPasswdChat
)
661 _PUBLIC_
FN_GLOBAL_LIST(lp_passwordserver
, szPasswordServers
)
662 _PUBLIC_
FN_GLOBAL_LIST(lp_name_resolve_order
, szNameResolveOrder
)
663 _PUBLIC_
FN_GLOBAL_STRING(lp_realm
, szRealm_upper
)
664 _PUBLIC_
FN_GLOBAL_STRING(lp_dnsdomain
, szRealm_lower
)
665 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_options
, socket_options
)
666 _PUBLIC_
FN_GLOBAL_STRING(lp_workgroup
, szWorkgroup
)
667 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_name
, szNetbiosName
)
668 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_scope
, szNetbiosScope
)
669 _PUBLIC_
FN_GLOBAL_LIST(lp_wins_server_list
, szWINSservers
)
670 _PUBLIC_
FN_GLOBAL_LIST(lp_interfaces
, szInterfaces
)
671 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_address
, szSocketAddress
)
672 _PUBLIC_
FN_GLOBAL_LIST(lp_netbios_aliases
, szNetbiosAliases
)
673 _PUBLIC_
FN_GLOBAL_BOOL(lp_disable_netbios
, bDisableNetbios
)
674 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_support
, bWINSsupport
)
675 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_dns_proxy
, bWINSdnsProxy
)
676 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_hook
, szWINSHook
)
677 _PUBLIC_
FN_GLOBAL_BOOL(lp_local_master
, bLocalMaster
)
678 _PUBLIC_
FN_GLOBAL_BOOL(lp_readraw
, bReadRaw
)
679 _PUBLIC_
FN_GLOBAL_BOOL(lp_large_readwrite
, bLargeReadwrite
)
680 _PUBLIC_
FN_GLOBAL_BOOL(lp_writeraw
, bWriteRaw
)
681 _PUBLIC_
FN_GLOBAL_BOOL(lp_null_passwords
, bNullPasswords
)
682 _PUBLIC_
FN_GLOBAL_BOOL(lp_obey_pam_restrictions
, bObeyPamRestrictions
)
683 _PUBLIC_
FN_GLOBAL_BOOL(lp_encrypted_passwords
, bEncryptPasswords
)
684 _PUBLIC_
FN_GLOBAL_BOOL(lp_time_server
, bTimeServer
)
685 _PUBLIC_
FN_GLOBAL_BOOL(lp_bind_interfaces_only
, bBindInterfacesOnly
)
686 _PUBLIC_
FN_GLOBAL_BOOL(lp_unicode
, bUnicode
)
687 _PUBLIC_
FN_GLOBAL_BOOL(lp_nt_status_support
, bNTStatusSupport
)
688 _PUBLIC_
FN_GLOBAL_BOOL(lp_lanman_auth
, bLanmanAuth
)
689 _PUBLIC_
FN_GLOBAL_BOOL(lp_ntlm_auth
, bNTLMAuth
)
690 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_plaintext_auth
, bClientPlaintextAuth
)
691 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_lanman_auth
, bClientLanManAuth
)
692 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_ntlmv2_auth
, bClientNTLMv2Auth
)
693 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_use_spnego_principal
, client_use_spnego_principal
)
694 _PUBLIC_
FN_GLOBAL_BOOL(lp_host_msdfs
, bHostMSDfs
)
695 _PUBLIC_
FN_GLOBAL_BOOL(lp_unix_extensions
, bUnixExtensions
)
696 _PUBLIC_
FN_GLOBAL_BOOL(lp_use_spnego
, bUseSpnego
)
697 _PUBLIC_
FN_GLOBAL_BOOL(lp_rpc_big_endian
, bRpcBigEndian
)
698 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_wins_ttl
, max_wins_ttl
)
699 _PUBLIC_
FN_GLOBAL_INTEGER(lp_min_wins_ttl
, min_wins_ttl
)
700 _PUBLIC_
FN_GLOBAL_INTEGER(lp_maxmux
, max_mux
)
701 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_xmit
, max_xmit
)
702 _PUBLIC_
FN_GLOBAL_INTEGER(lp_passwordlevel
, pwordlevel
)
703 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_maxprotocol
, srv_maxprotocol
)
704 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_minprotocol
, srv_minprotocol
)
705 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_maxprotocol
, cli_maxprotocol
)
706 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_minprotocol
, cli_minprotocol
)
707 _PUBLIC_
FN_GLOBAL_INTEGER(lp_security
, security
)
708 _PUBLIC_
FN_GLOBAL_BOOL(lp_paranoid_server_security
, paranoid_server_security
)
709 _PUBLIC_
FN_GLOBAL_INTEGER(lp_announce_as
, announce_as
)
711 const char *lp_servicename(const struct loadparm_service
*service
)
713 return lp_string((const char *)service
->szService
);
716 _PUBLIC_
FN_LOCAL_STRING(lp_pathname
, szPath
)
717 static FN_LOCAL_STRING(_lp_printername
, szPrintername
)
718 _PUBLIC_
FN_LOCAL_LIST(lp_hostsallow
, szHostsallow
)
719 _PUBLIC_
FN_LOCAL_LIST(lp_hostsdeny
, szHostsdeny
)
720 _PUBLIC_
FN_LOCAL_STRING(lp_comment
, comment
)
721 _PUBLIC_
FN_LOCAL_STRING(lp_fstype
, fstype
)
722 static FN_LOCAL_STRING(lp_volume
, volume
)
723 _PUBLIC_
FN_LOCAL_LIST(lp_ntvfs_handler
, ntvfs_handler
)
724 _PUBLIC_
FN_LOCAL_BOOL(lp_msdfs_root
, bMSDfsRoot
)
725 _PUBLIC_
FN_LOCAL_BOOL(lp_browseable
, bBrowseable
)
726 _PUBLIC_
FN_LOCAL_BOOL(lp_readonly
, bRead_only
)
727 _PUBLIC_
FN_LOCAL_BOOL(lp_print_ok
, bPrint_ok
)
728 _PUBLIC_
FN_LOCAL_BOOL(lp_map_hidden
, bMap_hidden
)
729 _PUBLIC_
FN_LOCAL_BOOL(lp_map_archive
, bMap_archive
)
730 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_locking
, bStrictLocking
)
731 _PUBLIC_
FN_LOCAL_BOOL(lp_oplocks
, bOplocks
)
732 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_sync
, bStrictSync
)
733 _PUBLIC_
FN_LOCAL_BOOL(lp_ci_filesystem
, bCIFileSystem
)
734 _PUBLIC_
FN_LOCAL_BOOL(lp_map_system
, bMap_system
)
735 _PUBLIC_
FN_LOCAL_INTEGER(lp_max_connections
, iMaxConnections
)
736 _PUBLIC_
FN_LOCAL_INTEGER(lp_csc_policy
, iCSCPolicy
)
737 _PUBLIC_
FN_LOCAL_INTEGER(lp_create_mask
, iCreate_mask
)
738 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_create_mode
, iCreate_force_mode
)
739 _PUBLIC_
FN_LOCAL_INTEGER(lp_dir_mask
, iDir_mask
)
740 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_dir_mode
, iDir_force_mode
)
741 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_signing
, server_signing
)
742 _PUBLIC_
FN_GLOBAL_INTEGER(lp_client_signing
, client_signing
)
744 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
746 /* local prototypes */
747 static int map_parameter(const char *pszParmName
);
748 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
749 const char *pszServiceName
);
750 static void copy_service(struct loadparm_service
*pserviceDest
,
751 struct loadparm_service
*pserviceSource
,
753 static bool service_ok(struct loadparm_service
*service
);
754 static bool do_section(const char *pszSectionName
, void *);
755 static void init_copymap(struct loadparm_service
*pservice
);
757 /* This is a helper function for parametrical options support. */
758 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
759 /* Actual parametrical functions are quite simple */
760 const char *lp_get_parametric(struct loadparm_context
*lp_ctx
,
761 struct loadparm_service
*service
,
762 const char *type
, const char *option
)
765 struct parmlist_entry
*data
;
770 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
772 asprintf(&vfskey
, "%s:%s", type
, option
);
776 if (strcmp(data
->key
, vfskey
) == 0) {
783 if (service
!= NULL
) {
784 /* Try to fetch the same option but from globals */
785 /* but only if we are not already working with globals */
786 for (data
= lp_ctx
->globals
->param_opt
; data
;
788 if (strcmp(data
->key
, vfskey
) == 0) {
802 * convenience routine to return int parameters.
804 static int lp_int(const char *s
)
808 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
812 return strtol(s
, NULL
, 0);
816 * convenience routine to return unsigned long parameters.
818 static int lp_ulong(const char *s
)
822 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
826 return strtoul(s
, NULL
, 0);
830 * convenience routine to return unsigned long parameters.
832 static double lp_double(const char *s
)
836 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
840 return strtod(s
, NULL
);
844 * convenience routine to return boolean parameters.
846 static bool lp_bool(const char *s
)
851 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
855 if (!set_boolean(s
, &ret
)) {
856 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
865 * Return parametric option from a given service. Type is a part of option before ':'
866 * Parametric option has following syntax: 'Type: option = value'
867 * Returned value is allocated in 'lp_talloc' context
870 const char *lp_parm_string(struct loadparm_context
*lp_ctx
,
871 struct loadparm_service
*service
, const char *type
,
874 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
877 return lp_string(value
);
883 * Return parametric option from a given service. Type is a part of option before ':'
884 * Parametric option has following syntax: 'Type: option = value'
885 * Returned value is allocated in 'lp_talloc' context
888 const char **lp_parm_string_list(TALLOC_CTX
*mem_ctx
,
889 struct loadparm_context
*lp_ctx
,
890 struct loadparm_service
*service
,
892 const char *option
, const char *separator
)
894 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
897 return (const char **)str_list_make(mem_ctx
, value
, separator
);
903 * Return parametric option from a given service. Type is a part of option before ':'
904 * Parametric option has following syntax: 'Type: option = value'
907 int lp_parm_int(struct loadparm_context
*lp_ctx
,
908 struct loadparm_service
*service
, const char *type
,
909 const char *option
, int default_v
)
911 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
914 return lp_int(value
);
920 * Return parametric option from a given service. Type is a part of
922 * Parametric option has following syntax: 'Type: option = value'.
925 int lp_parm_bytes(struct loadparm_context
*lp_ctx
,
926 struct loadparm_service
*service
, const char *type
,
927 const char *option
, int default_v
)
931 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
933 if (value
&& conv_str_size(value
, &bval
)) {
934 if (bval
<= INT_MAX
) {
943 * Return parametric option from a given service.
944 * Type is a part of option before ':'
945 * Parametric option has following syntax: 'Type: option = value'
947 unsigned long lp_parm_ulong(struct loadparm_context
*lp_ctx
,
948 struct loadparm_service
*service
, const char *type
,
949 const char *option
, unsigned long default_v
)
951 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
954 return lp_ulong(value
);
960 double lp_parm_double(struct loadparm_context
*lp_ctx
,
961 struct loadparm_service
*service
, const char *type
,
962 const char *option
, double default_v
)
964 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
967 return lp_double(value
);
973 * Return parametric option from a given service. Type is a part of option before ':'
974 * Parametric option has following syntax: 'Type: option = value'
977 bool lp_parm_bool(struct loadparm_context
*lp_ctx
,
978 struct loadparm_service
*service
, const char *type
,
979 const char *option
, bool default_v
)
981 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
984 return lp_bool(value
);
991 * Initialise a service to the defaults.
994 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
996 struct loadparm_service
*pservice
=
997 talloc_zero(mem_ctx
, struct loadparm_service
);
998 copy_service(pservice
, sDefault
, NULL
);
1003 * Set a string value, deallocating any existing space, and allocing the space
1006 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1013 *dest
= talloc_strdup(mem_ctx
, src
);
1014 if ((*dest
) == NULL
) {
1015 DEBUG(0,("Out of memory in string_init\n"));
1025 * Add a new service to the services array initialising it with the given
1029 struct loadparm_service
*lp_add_service(struct loadparm_context
*lp_ctx
,
1030 const struct loadparm_service
*pservice
,
1034 struct loadparm_service tservice
;
1035 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1036 struct parmlist_entry
*data
, *pdata
;
1038 tservice
= *pservice
;
1040 /* it might already exist */
1042 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1044 if (service
!= NULL
) {
1045 /* Clean all parametric options for service */
1046 /* They will be added during parsing again */
1047 data
= service
->param_opt
;
1053 service
->param_opt
= NULL
;
1058 /* find an invalid one */
1059 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1060 if (lp_ctx
->services
[i
] == NULL
)
1063 /* if not, then create one */
1064 if (i
== lp_ctx
->iNumServices
) {
1065 struct loadparm_service
**tsp
;
1067 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1070 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1073 lp_ctx
->services
= tsp
;
1074 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1077 lp_ctx
->iNumServices
++;
1080 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1081 if (lp_ctx
->services
[i
] == NULL
) {
1082 DEBUG(0,("lp_add_service: out of memory!\n"));
1085 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1087 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1088 return lp_ctx
->services
[i
];
1092 * Add a new home service, with the specified home directory, defaults coming
1093 * from service ifrom.
1096 bool lp_add_home(struct loadparm_context
*lp_ctx
,
1097 const char *pszHomename
,
1098 struct loadparm_service
*default_service
,
1099 const char *user
, const char *pszHomedir
)
1101 struct loadparm_service
*service
;
1103 service
= lp_add_service(lp_ctx
, default_service
, pszHomename
);
1105 if (service
== NULL
)
1108 if (!(*(default_service
->szPath
))
1109 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1110 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1112 service
->szPath
= string_sub_talloc(service
, lp_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1115 if (!(*(service
->comment
))) {
1116 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1118 service
->bAvailable
= default_service
->bAvailable
;
1119 service
->bBrowseable
= default_service
->bBrowseable
;
1121 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1122 pszHomename
, user
, service
->szPath
));
1128 * Add the IPC service.
1131 static bool lp_add_hidden(struct loadparm_context
*lp_ctx
, const char *name
,
1134 struct loadparm_service
*service
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
, name
);
1136 if (service
== NULL
)
1139 string_set(service
, &service
->szPath
, tmpdir());
1141 service
->comment
= talloc_asprintf(service
, "%s Service (%s)",
1142 fstype
, lp_ctx
->globals
->szServerString
);
1143 string_set(service
, &service
->fstype
, fstype
);
1144 service
->iMaxConnections
= -1;
1145 service
->bAvailable
= true;
1146 service
->bRead_only
= true;
1147 service
->bPrint_ok
= false;
1148 service
->bBrowseable
= false;
1150 if (strcasecmp(fstype
, "IPC") == 0) {
1151 lp_do_service_parameter(lp_ctx
, service
, "ntvfs handler",
1155 DEBUG(3, ("adding hidden service %s\n", name
));
1161 * Add a new printer service, with defaults coming from service iFrom.
1164 bool lp_add_printer(struct loadparm_context
*lp_ctx
,
1165 const char *pszPrintername
,
1166 struct loadparm_service
*default_service
)
1168 const char *comment
= "From Printcap";
1169 struct loadparm_service
*service
;
1170 service
= lp_add_service(lp_ctx
, default_service
, pszPrintername
);
1172 if (service
== NULL
)
1175 /* note that we do NOT default the availability flag to True - */
1176 /* we take it from the default service passed. This allows all */
1177 /* dynamic printers to be disabled by disabling the [printers] */
1178 /* entry (if/when the 'available' keyword is implemented!). */
1180 /* the printer name is set to the service name. */
1181 string_set(service
, &service
->szPrintername
, pszPrintername
);
1182 string_set(service
, &service
->comment
, comment
);
1183 service
->bBrowseable
= default_service
->bBrowseable
;
1184 /* Printers cannot be read_only. */
1185 service
->bRead_only
= false;
1186 /* Printer services must be printable. */
1187 service
->bPrint_ok
= true;
1189 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1195 * Map a parameter's string representation to something we can use.
1196 * Returns False if the parameter string is not recognised, else TRUE.
1199 static int map_parameter(const char *pszParmName
)
1203 if (*pszParmName
== '-')
1206 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1207 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1210 /* Warn only if it isn't parametric option */
1211 if (strchr(pszParmName
, ':') == NULL
)
1212 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
1213 /* We do return 'fail' for parametric options as well because they are
1214 stored in different storage
1221 return the parameter structure for a parameter
1223 struct parm_struct
*lp_parm_struct(const char *name
)
1225 int parmnum
= map_parameter(name
);
1226 if (parmnum
== -1) return NULL
;
1227 return &parm_table
[parmnum
];
1231 return the parameter pointer for a parameter
1233 void *lp_parm_ptr(struct loadparm_context
*lp_ctx
,
1234 struct loadparm_service
*service
, struct parm_struct
*parm
)
1236 if (service
== NULL
) {
1237 if (parm
->pclass
== P_LOCAL
)
1238 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
1239 else if (parm
->pclass
== P_GLOBAL
)
1240 return ((char *)lp_ctx
->globals
)+parm
->offset
;
1243 return ((char *)service
) + parm
->offset
;
1248 * Find a service by name. Otherwise works like get_service.
1251 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1252 const char *pszServiceName
)
1256 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
1257 if (lp_ctx
->services
[iService
] != NULL
&&
1258 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
1259 return lp_ctx
->services
[iService
];
1266 * Copy a service structure to another.
1267 * If pcopymapDest is NULL then copy all fields
1270 static void copy_service(struct loadparm_service
*pserviceDest
,
1271 struct loadparm_service
*pserviceSource
,
1275 bool bcopyall
= (pcopymapDest
== NULL
);
1276 struct parmlist_entry
*data
, *pdata
, *paramo
;
1279 for (i
= 0; parm_table
[i
].label
; i
++)
1280 if (parm_table
[i
].offset
!= -1 && parm_table
[i
].pclass
== P_LOCAL
&&
1281 (bcopyall
|| pcopymapDest
[i
])) {
1283 ((char *)pserviceSource
) + parm_table
[i
].offset
;
1285 ((char *)pserviceDest
) + parm_table
[i
].offset
;
1287 switch (parm_table
[i
].type
) {
1289 *(int *)dest_ptr
= *(int *)src_ptr
;
1295 *(int *)dest_ptr
= *(int *)src_ptr
;
1299 string_set(pserviceDest
,
1305 string_set(pserviceDest
,
1308 strupper(*(char **)dest_ptr
);
1311 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
1312 *(const char ***)src_ptr
);
1320 init_copymap(pserviceDest
);
1321 if (pserviceSource
->copymap
)
1322 memcpy((void *)pserviceDest
->copymap
,
1323 (void *)pserviceSource
->copymap
,
1324 sizeof(int) * NUMPARAMETERS
);
1327 data
= pserviceSource
->param_opt
;
1330 pdata
= pserviceDest
->param_opt
;
1331 /* Traverse destination */
1333 /* If we already have same option, override it */
1334 if (strcmp(pdata
->key
, data
->key
) == 0) {
1335 talloc_free(pdata
->value
);
1336 pdata
->value
= talloc_reference(pdata
,
1341 pdata
= pdata
->next
;
1344 paramo
= talloc(pserviceDest
, struct parmlist_entry
);
1347 paramo
->key
= talloc_reference(paramo
, data
->key
);
1348 paramo
->value
= talloc_reference(paramo
, data
->value
);
1349 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1356 * Check a service for consistency. Return False if the service is in any way
1357 * incomplete or faulty, else True.
1359 static bool service_ok(struct loadparm_service
*service
)
1364 if (service
->szService
[0] == '\0') {
1365 DEBUG(0, ("The following message indicates an internal error:\n"));
1366 DEBUG(0, ("No service name in service entry.\n"));
1370 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1371 /* I can't see why you'd want a non-printable printer service... */
1372 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1373 if (!service
->bPrint_ok
) {
1374 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1375 service
->szService
));
1376 service
->bPrint_ok
= true;
1378 /* [printers] service must also be non-browsable. */
1379 if (service
->bBrowseable
)
1380 service
->bBrowseable
= false;
1383 /* If a service is flagged unavailable, log the fact at level 0. */
1384 if (!service
->bAvailable
)
1385 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1386 service
->szService
));
1392 /*******************************************************************
1393 Keep a linked list of all config files so we know when one has changed
1394 it's date and needs to be reloaded.
1395 ********************************************************************/
1397 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1398 const char *fname
, const char *subfname
)
1400 struct file_lists
*f
= lp_ctx
->file_lists
;
1403 if (f
->name
&& !strcmp(f
->name
, fname
))
1409 f
= talloc(lp_ctx
, struct file_lists
);
1412 f
->next
= lp_ctx
->file_lists
;
1413 f
->name
= talloc_strdup(f
, fname
);
1418 f
->subfname
= talloc_strdup(f
, subfname
);
1423 lp_ctx
->file_lists
= f
;
1424 f
->modtime
= file_modtime(subfname
);
1426 time_t t
= file_modtime(subfname
);
1432 /*******************************************************************
1433 Check if a config file has changed date.
1434 ********************************************************************/
1435 bool lp_file_list_changed(struct loadparm_context
*lp_ctx
)
1437 struct file_lists
*f
;
1438 DEBUG(6, ("lp_file_list_changed()\n"));
1440 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1444 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1446 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1447 f
->name
, n2
, ctime(&f
->modtime
)));
1449 mod_time
= file_modtime(n2
);
1451 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1452 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1454 f
->modtime
= mod_time
;
1455 talloc_free(f
->subfname
);
1456 f
->subfname
= talloc_strdup(f
, n2
);
1463 /***************************************************************************
1464 Handle the "realm" parameter
1465 ***************************************************************************/
1467 static bool handle_realm(struct loadparm_context
*lp_ctx
,
1468 const char *pszParmValue
, char **ptr
)
1470 string_set(lp_ctx
, ptr
, pszParmValue
);
1472 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1473 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1478 /***************************************************************************
1479 Handle the include operation.
1480 ***************************************************************************/
1482 static bool handle_include(struct loadparm_context
*lp_ctx
,
1483 const char *pszParmValue
, char **ptr
)
1485 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1487 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1489 string_set(lp_ctx
, ptr
, fname
);
1491 if (file_exist(fname
))
1492 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1494 DEBUG(2, ("Can't find include file %s\n", fname
));
1499 /***************************************************************************
1500 Handle the interpretation of the copy parameter.
1501 ***************************************************************************/
1503 static bool handle_copy(struct loadparm_context
*lp_ctx
,
1504 const char *pszParmValue
, char **ptr
)
1507 struct loadparm_service
*serviceTemp
;
1509 string_set(lp_ctx
, ptr
, pszParmValue
);
1513 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1515 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1516 if (serviceTemp
== lp_ctx
->currentService
) {
1517 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1519 copy_service(lp_ctx
->currentService
,
1521 lp_ctx
->currentService
->copymap
);
1525 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1533 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
1534 const char *pszParmValue
, char **ptr
)
1536 DEBUGLEVEL
= atoi(pszParmValue
);
1541 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
1542 const char *pszParmValue
, char **ptr
)
1544 logfile
= pszParmValue
;
1548 /***************************************************************************
1549 Initialise a copymap.
1550 ***************************************************************************/
1552 static void init_copymap(struct loadparm_service
*pservice
)
1555 talloc_free(pservice
->copymap
);
1556 pservice
->copymap
= talloc_array(pservice
, int, NUMPARAMETERS
);
1557 if (pservice
->copymap
== NULL
) {
1559 ("Couldn't allocate copymap!! (size %d)\n",
1560 (int)NUMPARAMETERS
));
1563 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1564 pservice
->copymap
[i
] = true;
1568 * Process a parametric option
1570 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1571 struct loadparm_service
*service
,
1572 const char *pszParmName
,
1573 const char *pszParmValue
, int flags
)
1575 struct parmlist_entry
*paramo
, *data
;
1577 TALLOC_CTX
*mem_ctx
;
1579 while (isspace((unsigned char)*pszParmName
)) {
1583 name
= strdup(pszParmName
);
1584 if (!name
) return false;
1588 if (service
== NULL
) {
1589 data
= lp_ctx
->globals
->param_opt
;
1590 mem_ctx
= lp_ctx
->globals
;
1592 data
= service
->param_opt
;
1596 /* Traverse destination */
1597 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1598 /* If we already have the option set, override it unless
1599 it was a command line option and the new one isn't */
1600 if (strcmp(paramo
->key
, name
) == 0) {
1601 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1602 !(flags
& FLAG_CMDLINE
)) {
1606 talloc_free(paramo
->value
);
1607 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1608 paramo
->priority
= flags
;
1614 paramo
= talloc(mem_ctx
, struct parmlist_entry
);
1617 paramo
->key
= talloc_strdup(paramo
, name
);
1618 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1619 paramo
->priority
= flags
;
1620 if (service
== NULL
) {
1621 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1623 DLIST_ADD(service
->param_opt
, paramo
);
1631 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1632 const char *pszParmName
, const char *pszParmValue
,
1633 struct loadparm_context
*lp_ctx
)
1636 /* if it is a special case then go ahead */
1637 if (parm_table
[parmnum
].special
) {
1638 parm_table
[parmnum
].special(lp_ctx
, pszParmValue
,
1643 /* now switch on the type of variable it is */
1644 switch (parm_table
[parmnum
].type
)
1648 if (!set_boolean(pszParmValue
, &b
)) {
1649 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1652 *(int *)parm_ptr
= b
;
1657 *(int *)parm_ptr
= atoi(pszParmValue
);
1661 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1667 if (conv_str_size(pszParmValue
, &val
)) {
1668 if (val
<= INT_MAX
) {
1669 *(int *)parm_ptr
= (int)val
;
1674 DEBUG(0,("lp_do_parameter(%s): value is not "
1675 "a valid size specifier!\n", pszParmValue
));
1680 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1681 pszParmValue
, NULL
);
1685 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1689 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1690 strupper(*(char **)parm_ptr
);
1694 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1697 parm_table
[parmnum
].enum_list
[i
].name
)) {
1699 parm_table
[parmnum
].
1704 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1705 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1706 pszParmValue
, pszParmName
));
1712 if (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
) {
1713 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1714 /* we have to also unset FLAG_DEFAULT on aliases */
1715 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1716 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1718 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1719 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1726 bool lp_do_global_parameter(struct loadparm_context
*lp_ctx
,
1727 const char *pszParmName
, const char *pszParmValue
)
1729 int parmnum
= map_parameter(pszParmName
);
1733 if (strchr(pszParmName
, ':')) {
1734 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1736 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1740 /* if the flag has been set on the command line, then don't allow override,
1741 but don't report an error */
1742 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1746 parm_ptr
= lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1748 return set_variable(lp_ctx
, parmnum
, parm_ptr
,
1749 pszParmName
, pszParmValue
, lp_ctx
);
1752 bool lp_do_service_parameter(struct loadparm_context
*lp_ctx
,
1753 struct loadparm_service
*service
,
1754 const char *pszParmName
, const char *pszParmValue
)
1758 int parmnum
= map_parameter(pszParmName
);
1761 if (strchr(pszParmName
, ':')) {
1762 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1764 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1768 /* if the flag has been set on the command line, then don't allow override,
1769 but don't report an error */
1770 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1774 if (parm_table
[parmnum
].pclass
== P_GLOBAL
) {
1776 ("Global parameter %s found in service section!\n",
1780 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1782 if (!service
->copymap
)
1783 init_copymap(service
);
1785 /* this handles the aliases - set the copymap for other
1786 * entries with the same data pointer */
1787 for (i
= 0; parm_table
[i
].label
; i
++)
1788 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1789 parm_table
[i
].pclass
== parm_table
[parmnum
].pclass
)
1790 service
->copymap
[i
] = false;
1792 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1793 pszParmValue
, lp_ctx
);
1797 * Process a parameter.
1800 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1803 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1805 if (lp_ctx
->bInGlobalSection
)
1806 return lp_do_global_parameter(lp_ctx
, pszParmName
,
1809 return lp_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1810 pszParmName
, pszParmValue
);
1814 variable argument do parameter
1816 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1817 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1818 const char *pszParmName
, const char *fmt
, ...)
1825 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1827 ret
= lp_do_global_parameter(lp_ctx
, pszParmName
, s
);
1834 set a parameter from the commandline - this is called from command line parameter
1835 parsing code. It sets the parameter then marks the parameter as unable to be modified
1836 by smb.conf processing
1838 bool lp_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1839 const char *pszParmValue
)
1841 int parmnum
= map_parameter(pszParmName
);
1844 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1847 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1848 /* set a parametric option */
1849 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1850 pszParmValue
, FLAG_CMDLINE
);
1854 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1858 /* reset the CMDLINE flag in case this has been called before */
1859 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1861 if (!lp_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1865 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1867 /* we have to also set FLAG_CMDLINE on aliases */
1868 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1869 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1871 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1872 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1879 set a option from the commandline in 'a=b' format. Use to support --option
1881 bool lp_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1899 ret
= lp_set_cmdline(lp_ctx
, s
, p
+1);
1905 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1908 * Print a parameter of the specified type.
1911 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1917 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1918 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1920 p
->enum_list
[i
].name
);
1927 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
1932 fprintf(f
, "%d", *(int *)ptr
);
1936 fprintf(f
, "0%o", *(int *)ptr
);
1940 if ((char ***)ptr
&& *(char ***)ptr
) {
1941 char **list
= *(char ***)ptr
;
1943 for (; *list
; list
++)
1944 fprintf(f
, "%s%s", *list
,
1945 ((*(list
+1))?", ":""));
1951 if (*(char **)ptr
) {
1952 fprintf(f
, "%s", *(char **)ptr
);
1959 * Check if two parameters are equal.
1962 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1966 return (*((int *)ptr1
) == *((int *)ptr2
));
1972 return (*((int *)ptr1
) == *((int *)ptr2
));
1975 return str_list_equal((const char **)(*(char ***)ptr1
),
1976 (const char **)(*(char ***)ptr2
));
1981 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1986 return (p1
== p2
|| strequal(p1
, p2
));
1993 * Process a new section (service).
1995 * At this stage all sections are services.
1996 * Later we'll have special sections that permit server parameters to be set.
1997 * Returns True on success, False on failure.
2000 static bool do_section(const char *pszSectionName
, void *userdata
)
2002 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2004 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2005 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2008 /* if we've just struck a global section, note the fact. */
2009 lp_ctx
->bInGlobalSection
= isglobal
;
2011 /* check for multiple global sections */
2012 if (lp_ctx
->bInGlobalSection
) {
2013 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName
));
2017 /* if we have a current service, tidy it up before moving on */
2020 if (lp_ctx
->currentService
!= NULL
)
2021 bRetval
= service_ok(lp_ctx
->currentService
);
2023 /* if all is still well, move to the next record in the services array */
2025 /* We put this here to avoid an odd message order if messages are */
2026 /* issued by the post-processing of a previous section. */
2027 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName
));
2029 if ((lp_ctx
->currentService
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
,
2032 DEBUG(0, ("Failed to add a new service\n"));
2042 * Determine if a particular base parameter is currently set to the default value.
2045 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2047 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2048 if (!defaults_saved
)
2050 switch (parm_table
[i
].type
) {
2052 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2053 (const char **)def_ptr
);
2056 return strequal(parm_table
[i
].def
.svalue
,
2059 return parm_table
[i
].def
.bvalue
==
2065 return parm_table
[i
].def
.ivalue
==
2072 *Display the contents of the global structure.
2075 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2079 struct parmlist_entry
*data
;
2081 fprintf(f
, "# Global parameters\n[global]\n");
2083 for (i
= 0; parm_table
[i
].label
; i
++)
2084 if (parm_table
[i
].pclass
== P_GLOBAL
&&
2085 parm_table
[i
].offset
!= -1 &&
2086 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2087 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2089 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2090 print_parameter(&parm_table
[i
], lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2093 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2094 for (data
= lp_ctx
->globals
->param_opt
; data
;
2095 data
= data
->next
) {
2096 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2103 * Display the contents of a single services record.
2106 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
)
2109 struct parmlist_entry
*data
;
2111 if (pService
!= sDefault
)
2112 fprintf(f
, "\n[%s]\n", pService
->szService
);
2114 for (i
= 0; parm_table
[i
].label
; i
++) {
2115 if (parm_table
[i
].pclass
== P_LOCAL
&&
2116 parm_table
[i
].offset
!= -1 &&
2117 (*parm_table
[i
].label
!= '-') &&
2118 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
2120 if (pService
== sDefault
) {
2121 if (defaults_saved
&& is_default(sDefault
, i
))
2124 if (equal_parameter(parm_table
[i
].type
,
2125 ((char *)pService
) +
2126 parm_table
[i
].offset
,
2127 ((char *)sDefault
) +
2128 parm_table
[i
].offset
))
2132 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2133 print_parameter(&parm_table
[i
],
2134 ((char *)pService
) + parm_table
[i
].offset
, f
);
2138 if (pService
->param_opt
!= NULL
) {
2139 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2140 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2145 bool lp_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2146 struct loadparm_service
*service
,
2147 const char *parm_name
, FILE * f
)
2149 struct parm_struct
*parm
;
2152 parm
= lp_parm_struct(parm_name
);
2157 ptr
= lp_parm_ptr(lp_ctx
, service
,parm
);
2159 print_parameter(parm
, ptr
, f
);
2165 * Return info about the next parameter in a service.
2166 * snum==-1 gives the globals.
2167 * Return NULL when out of parameters.
2170 struct parm_struct
*lp_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
2174 /* do the globals */
2175 for (; parm_table
[*i
].label
; (*i
)++) {
2176 if (parm_table
[*i
].offset
== -1
2177 || (*parm_table
[*i
].label
== '-'))
2181 && (parm_table
[*i
].offset
==
2182 parm_table
[(*i
) - 1].offset
))
2185 return &parm_table
[(*i
)++];
2188 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
2190 for (; parm_table
[*i
].label
; (*i
)++) {
2191 if (parm_table
[*i
].pclass
== P_LOCAL
&&
2192 parm_table
[*i
].offset
!= -1 &&
2193 (*parm_table
[*i
].label
!= '-') &&
2195 (parm_table
[*i
].offset
!=
2196 parm_table
[(*i
) - 1].offset
)))
2198 if (allparameters
||
2199 !equal_parameter(parm_table
[*i
].type
,
2200 ((char *)pService
) +
2201 parm_table
[*i
].offset
,
2202 ((char *)lp_ctx
->sDefault
) +
2203 parm_table
[*i
].offset
))
2205 return &parm_table
[(*i
)++];
2216 * Auto-load some home services.
2218 static void lp_add_auto_services(struct loadparm_context
*lp_ctx
,
2226 * Unload unused services.
2229 void lp_killunused(struct loadparm_context
*lp_ctx
,
2230 struct smbsrv_connection
*smb
,
2231 bool (*snumused
) (struct smbsrv_connection
*, int))
2234 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2235 if (lp_ctx
->services
[i
] == NULL
)
2238 if (!snumused
|| !snumused(smb
, i
)) {
2239 talloc_free(lp_ctx
->services
[i
]);
2240 lp_ctx
->services
[i
] = NULL
;
2246 static int lp_destructor(struct loadparm_context
*lp_ctx
)
2248 struct parmlist_entry
*data
;
2250 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2251 struct parmlist_entry
*next
;
2252 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2254 if (data
->priority
& FLAG_CMDLINE
) continue;
2255 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2264 * Initialise the global parameter structure.
2266 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2270 struct loadparm_context
*lp_ctx
;
2272 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2276 talloc_set_destructor(lp_ctx
, lp_destructor
);
2277 lp_ctx
->bInGlobalSection
= true;
2278 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2279 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2281 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2282 lp_ctx
->sDefault
->bAvailable
= true;
2283 lp_ctx
->sDefault
->bBrowseable
= true;
2284 lp_ctx
->sDefault
->bRead_only
= true;
2285 lp_ctx
->sDefault
->bMap_archive
= true;
2286 lp_ctx
->sDefault
->bStrictLocking
= true;
2287 lp_ctx
->sDefault
->bOplocks
= true;
2288 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2289 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2290 lp_ctx
->sDefault
->iDir_mask
= 0755;
2291 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2293 DEBUG(3, ("Initialising global parameters\n"));
2295 for (i
= 0; parm_table
[i
].label
; i
++) {
2296 if ((parm_table
[i
].type
== P_STRING
||
2297 parm_table
[i
].type
== P_USTRING
) &&
2298 parm_table
[i
].offset
!= -1 &&
2299 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2301 if (parm_table
[i
].pclass
== P_LOCAL
) {
2302 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2304 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2306 *r
= talloc_strdup(lp_ctx
, "");
2310 lp_do_global_parameter(lp_ctx
, "share backend", "classic");
2312 lp_do_global_parameter(lp_ctx
, "server role", "standalone");
2314 /* options that can be set on the command line must be initialised via
2315 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2317 lp_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2319 lp_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2320 myname
= get_myname(lp_ctx
);
2321 lp_do_global_parameter(lp_ctx
, "netbios name", myname
);
2322 talloc_free(myname
);
2323 lp_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2325 lp_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2327 lp_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2328 lp_do_global_parameter(lp_ctx
, "max connections", "-1");
2330 lp_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser");
2331 lp_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc");
2332 lp_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
2333 lp_do_global_parameter(lp_ctx
, "auth methods:domain controller", "anonymous sam_ignoredomain");
2334 lp_do_global_parameter(lp_ctx
, "auth methods:member server", "anonymous sam winbind");
2335 lp_do_global_parameter(lp_ctx
, "auth methods:standalone", "anonymous sam_ignoredomain");
2336 lp_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2337 lp_do_global_parameter(lp_ctx
, "sam database", "sam.ldb");
2338 lp_do_global_parameter(lp_ctx
, "idmap database", "idmap.ldb");
2339 lp_do_global_parameter(lp_ctx
, "secrets database", "secrets.ldb");
2340 lp_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
2341 lp_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
2342 lp_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
2343 lp_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2345 /* This hive should be dynamically generated by Samba using
2346 data from the sam, but for the moment leave it in a tdb to
2347 keep regedt32 from popping up an annoying dialog. */
2348 lp_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2350 /* using UTF8 by default allows us to support all chars */
2351 lp_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2353 /* Use codepage 850 as a default for the dos character set */
2354 lp_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2357 * Allow the default PASSWD_CHAT to be overridden in local.h.
2359 lp_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2361 lp_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2362 lp_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2363 lp_do_global_parameter(lp_ctx
, "modules dir", dyn_MODULESDIR
);
2364 lp_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2366 lp_do_global_parameter(lp_ctx
, "socket address", "0.0.0.0");
2367 lp_do_global_parameter_var(lp_ctx
, "server string",
2368 "Samba %s", SAMBA_VERSION_STRING
);
2370 lp_do_global_parameter_var(lp_ctx
, "announce version", "%d.%d",
2371 DEFAULT_MAJOR_VERSION
,
2372 DEFAULT_MINOR_VERSION
);
2374 lp_do_global_parameter(lp_ctx
, "password server", "*");
2376 lp_do_global_parameter(lp_ctx
, "max mux", "50");
2377 lp_do_global_parameter(lp_ctx
, "max xmit", "12288");
2378 lp_do_global_parameter(lp_ctx
, "password level", "0");
2379 lp_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2380 lp_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2381 lp_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2382 lp_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2383 lp_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2384 lp_do_global_parameter(lp_ctx
, "security", "USER");
2385 lp_do_global_parameter(lp_ctx
, "paranoid server security", "True");
2386 lp_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2387 lp_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2388 lp_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2389 lp_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2390 lp_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2391 lp_do_global_parameter(lp_ctx
, "announce as", "NT SERVER");
2393 lp_do_global_parameter(lp_ctx
, "TimeServer", "False");
2394 lp_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2395 lp_do_global_parameter(lp_ctx
, "Unicode", "True");
2396 lp_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2397 lp_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2398 lp_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2399 lp_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2401 lp_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2403 lp_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2404 lp_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2406 lp_do_global_parameter(lp_ctx
, "wins support", "False");
2407 lp_do_global_parameter(lp_ctx
, "dns proxy", "True");
2409 lp_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2410 lp_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2411 lp_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2412 lp_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2413 lp_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2414 lp_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2415 lp_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
2417 lp_do_global_parameter(lp_ctx
, "client signing", "Yes");
2418 lp_do_global_parameter(lp_ctx
, "server signing", "auto");
2420 lp_do_global_parameter(lp_ctx
, "use spnego", "True");
2422 lp_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2423 lp_do_global_parameter(lp_ctx
, "nbt port", "137");
2424 lp_do_global_parameter(lp_ctx
, "dgram port", "138");
2425 lp_do_global_parameter(lp_ctx
, "cldap port", "389");
2426 lp_do_global_parameter(lp_ctx
, "krb5 port", "88");
2427 lp_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2428 lp_do_global_parameter(lp_ctx
, "web port", "901");
2429 lp_do_global_parameter(lp_ctx
, "swat directory", dyn_SWATDIR
);
2431 lp_do_global_parameter(lp_ctx
, "nt status support", "True");
2433 lp_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2434 lp_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2436 lp_do_global_parameter(lp_ctx
, "tls enabled", "True");
2437 lp_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2438 lp_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2439 lp_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2440 lp_do_global_parameter_var(lp_ctx
, "setup directory", "%s",
2443 lp_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2445 lp_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2447 for (i
= 0; parm_table
[i
].label
; i
++) {
2448 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2449 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2456 const char *lp_configfile(struct loadparm_context
*lp_ctx
)
2458 return lp_ctx
->szConfigFile
;
2461 const char *lp_default_path(void)
2463 if (getenv("SMB_CONF_PATH"))
2464 return getenv("SMB_CONF_PATH");
2466 return dyn_CONFIGFILE
;
2470 * Update the internal state of a loadparm context after settings
2473 static bool lp_update(struct loadparm_context
*lp_ctx
)
2475 lp_add_auto_services(lp_ctx
, lp_auto_services(lp_ctx
));
2477 lp_add_hidden(lp_ctx
, "IPC$", "IPC");
2478 lp_add_hidden(lp_ctx
, "ADMIN$", "DISK");
2480 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2481 lp_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2484 panic_action
= lp_ctx
->globals
->panic_action
;
2486 reload_charcnv(lp_ctx
);
2488 /* FIXME: ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx); */
2490 /* FIXME: This is a bit of a hack, but we can't use a global, since
2491 * not everything that uses lp also uses the socket library */
2492 if (lp_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2493 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2495 unsetenv("SOCKET_TESTNONBLOCK");
2498 /* FIXME: Check locale in environment for this: */
2499 if (strcmp(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)) != 0)
2500 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)));
2502 d_set_iconv((smb_iconv_t
)-1);
2507 bool lp_load_default(struct loadparm_context
*lp_ctx
)
2511 path
= lp_default_path();
2513 if (!file_exist(path
)) {
2514 /* We allow the default smb.conf file to not exist,
2515 * basically the equivalent of an empty file. */
2516 return lp_update(lp_ctx
);
2519 return lp_load(lp_ctx
, path
);
2523 * Load the services array from the services file.
2525 * Return True on success, False on failure.
2527 bool lp_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2532 filename
= talloc_strdup(lp_ctx
, filename
);
2534 lp_ctx
->szConfigFile
= filename
;
2536 lp_ctx
->bInGlobalSection
= true;
2537 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2538 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2
));
2540 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2542 /* We get sections first, so have to start 'behind' to make up */
2543 lp_ctx
->currentService
= NULL
;
2544 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2546 /* finish up the last section */
2547 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2549 if (lp_ctx
->currentService
!= NULL
)
2550 bRetval
= service_ok(lp_ctx
->currentService
);
2552 bRetval
= bRetval
&& lp_update(lp_ctx
);
2558 * Return the max number of services.
2561 int lp_numservices(struct loadparm_context
*lp_ctx
)
2563 return lp_ctx
->iNumServices
;
2567 * Display the contents of the services array in human-readable form.
2570 void lp_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2576 defaults_saved
= false;
2578 dump_globals(lp_ctx
, f
, show_defaults
);
2580 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
);
2582 for (iService
= 0; iService
< maxtoprint
; iService
++)
2583 lp_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2587 * Display the contents of one service in human-readable form.
2589 void lp_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2591 if (service
!= NULL
) {
2592 if (service
->szService
[0] == '\0')
2594 dump_a_service(service
, sDefault
, f
);
2598 struct loadparm_service
*lp_servicebynum(struct loadparm_context
*lp_ctx
,
2601 return lp_ctx
->services
[snum
];
2604 struct loadparm_service
*lp_service(struct loadparm_context
*lp_ctx
,
2605 const char *service_name
)
2610 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2611 if (lp_ctx
->services
[iService
] &&
2612 lp_ctx
->services
[iService
]->szService
) {
2614 * The substitution here is used to support %U is
2617 serviceName
= standard_sub_basic(
2618 lp_ctx
->services
[iService
],
2619 lp_ctx
->services
[iService
]->szService
);
2620 if (strequal(serviceName
, service_name
)) {
2621 talloc_free(serviceName
);
2622 return lp_ctx
->services
[iService
];
2624 talloc_free(serviceName
);
2628 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name
));
2634 * A useful volume label function.
2636 const char *volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2638 const char *ret
= lp_volume(service
, sDefault
);
2640 return lp_servicename(service
);
2646 * If we are PDC then prefer us as DMB
2648 const char *lp_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2650 const char *ret
= _lp_printername(service
, sDefault
);
2651 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2652 ret
= lp_servicename(service
);
2659 * Return the max print jobs per queue.
2661 int lp_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2663 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2664 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2665 maxjobs
= PRINT_MAX_JOBID
- 1;
2670 struct smb_iconv_convenience
*lp_iconv_convenience(struct loadparm_context
*lp_ctx
)
2672 if (lp_ctx
== NULL
) {
2673 static struct smb_iconv_convenience
*fallback_ic
= NULL
;
2674 if (fallback_ic
== NULL
)
2675 fallback_ic
= smb_iconv_convenience_init(talloc_autofree_context(),
2676 "CP850", "UTF8", true);
2679 return lp_ctx
->iconv_convenience
;
2682 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2684 talloc_unlink(lp_ctx
, lp_ctx
->iconv_convenience
);
2685 global_iconv_convenience
= lp_ctx
->iconv_convenience
= smb_iconv_convenience_init_lp(lp_ctx
, lp_ctx
);
2688 void lp_smbcli_options(struct loadparm_context
*lp_ctx
,
2689 struct smbcli_options
*options
)
2691 options
->max_xmit
= lp_max_xmit(lp_ctx
);
2692 options
->max_mux
= lp_maxmux(lp_ctx
);
2693 options
->use_spnego
= lp_nt_status_support(lp_ctx
) && lp_use_spnego(lp_ctx
);
2694 options
->signing
= lp_client_signing(lp_ctx
);
2695 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
2696 options
->ntstatus_support
= lp_nt_status_support(lp_ctx
);
2697 options
->max_protocol
= lp_cli_maxprotocol(lp_ctx
);
2698 options
->unicode
= lp_unicode(lp_ctx
);
2699 options
->use_oplocks
= true;
2700 options
->use_level2_oplocks
= true;
2703 void lp_smbcli_session_options(struct loadparm_context
*lp_ctx
,
2704 struct smbcli_session_options
*options
)
2706 options
->lanman_auth
= lp_client_lanman_auth(lp_ctx
);
2707 options
->ntlmv2_auth
= lp_client_ntlmv2_auth(lp_ctx
);
2708 options
->plaintext_auth
= lp_client_plaintext_auth(lp_ctx
);
2711 _PUBLIC_
char *lp_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2713 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2716 _PUBLIC_
char *lp_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2718 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2721 _PUBLIC_
char *lp_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2723 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2726 _PUBLIC_
char *lp_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2728 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2731 _PUBLIC_
char *lp_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2733 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2736 _PUBLIC_
struct dcerpc_server_info
*lp_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2738 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
2740 ret
->domain_name
= talloc_reference(mem_ctx
, lp_workgroup(lp_ctx
));
2741 ret
->version_major
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
2742 ret
->version_minor
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
2743 ret
->version_build
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
2748 struct gensec_settings
*lp_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2750 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
2751 if (settings
== NULL
)
2753 SMB_ASSERT(lp_ctx
!= NULL
);
2754 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2755 settings
->iconv_convenience
= lp_iconv_convenience(lp_ctx
);
2756 settings
->target_hostname
= lp_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");