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
;
106 const char **szWINSservers
;
107 const char **szInterfaces
;
108 char *szSocketAddress
;
109 char *szAnnounceVersion
; /* This is initialised in init_globals */
112 const char **szNetbiosAliases
;
113 char *szNetbiosScope
;
114 char *szDomainOtherSIDs
;
115 const char **szNameResolveOrder
;
116 const char **dcerpc_ep_servers
;
117 const char **server_services
;
118 char *ntptr_providor
;
119 char *szWinbindSeparator
;
120 char *szWinbinddPrivilegedSocketDirectory
;
121 char *szWinbinddSocketDirectory
;
122 char *szTemplateShell
;
123 char *szTemplateHomedir
;
124 int bWinbindSealedPipes
;
125 int bIdmapTrustedOnly
;
126 char *swat_directory
;
144 int paranoid_server_security
;
147 int announce_as
; /* This is initialised in init_globals */
154 char *socket_options
;
159 int bPreferredMaster
;
160 int bEncryptPasswords
;
162 int bObeyPamRestrictions
;
167 int bBindInterfacesOnly
;
169 int bNTStatusSupport
;
175 int bClientPlaintextAuth
;
176 int bClientLanManAuth
;
177 int bClientNTLMv2Auth
;
178 int client_use_spnego_principal
;
184 char *szNTPSignDSocketDirectory
;
185 struct param_opt
*param_opt
;
190 * This structure describes a single service.
192 struct loadparm_service
204 char **ntvfs_handler
;
218 int iCreate_force_mode
;
225 struct param_opt
*param_opt
;
227 char dummy
[3]; /* for alignment */
231 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
234 /* prototypes for the special type handlers */
235 static bool handle_include(struct loadparm_context
*lp_ctx
,
236 const char *pszParmValue
, char **ptr
);
237 static bool handle_copy(struct loadparm_context
*lp_ctx
,
238 const char *pszParmValue
, char **ptr
);
239 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
240 const char *pszParmValue
, char **ptr
);
241 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
242 const char *pszParmValue
, char **ptr
);
244 static const struct enum_list enum_protocol
[] = {
245 {PROTOCOL_SMB2
, "SMB2"},
246 {PROTOCOL_NT1
, "NT1"},
247 {PROTOCOL_LANMAN2
, "LANMAN2"},
248 {PROTOCOL_LANMAN1
, "LANMAN1"},
249 {PROTOCOL_CORE
, "CORE"},
250 {PROTOCOL_COREPLUS
, "COREPLUS"},
251 {PROTOCOL_COREPLUS
, "CORE+"},
255 static const struct enum_list enum_security
[] = {
256 {SEC_SHARE
, "SHARE"},
261 static const struct enum_list enum_announce_as
[] = {
262 {ANNOUNCE_AS_NT_SERVER
, "NT"},
263 {ANNOUNCE_AS_NT_SERVER
, "NT Server"},
264 {ANNOUNCE_AS_NT_WORKSTATION
, "NT Workstation"},
265 {ANNOUNCE_AS_WIN95
, "win95"},
266 {ANNOUNCE_AS_WFW
, "WfW"},
270 static const struct enum_list enum_bool_auto
[] = {
281 /* Client-side offline caching policy types */
284 CSC_POLICY_DOCUMENTS
=1,
285 CSC_POLICY_PROGRAMS
=2,
289 static const struct enum_list enum_csc_policy
[] = {
290 {CSC_POLICY_MANUAL
, "manual"},
291 {CSC_POLICY_DOCUMENTS
, "documents"},
292 {CSC_POLICY_PROGRAMS
, "programs"},
293 {CSC_POLICY_DISABLE
, "disable"},
297 /* SMB signing types. */
298 static const struct enum_list enum_smb_signing_vals
[] = {
299 {SMB_SIGNING_OFF
, "No"},
300 {SMB_SIGNING_OFF
, "False"},
301 {SMB_SIGNING_OFF
, "0"},
302 {SMB_SIGNING_OFF
, "Off"},
303 {SMB_SIGNING_OFF
, "disabled"},
304 {SMB_SIGNING_SUPPORTED
, "Yes"},
305 {SMB_SIGNING_SUPPORTED
, "True"},
306 {SMB_SIGNING_SUPPORTED
, "1"},
307 {SMB_SIGNING_SUPPORTED
, "On"},
308 {SMB_SIGNING_SUPPORTED
, "enabled"},
309 {SMB_SIGNING_REQUIRED
, "required"},
310 {SMB_SIGNING_REQUIRED
, "mandatory"},
311 {SMB_SIGNING_REQUIRED
, "force"},
312 {SMB_SIGNING_REQUIRED
, "forced"},
313 {SMB_SIGNING_REQUIRED
, "enforced"},
314 {SMB_SIGNING_AUTO
, "auto"},
318 static const struct enum_list enum_server_role
[] = {
319 {ROLE_STANDALONE
, "standalone"},
320 {ROLE_DOMAIN_MEMBER
, "member server"},
321 {ROLE_DOMAIN_MEMBER
, "member"},
322 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
323 {ROLE_DOMAIN_CONTROLLER
, "dc"},
328 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
329 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
331 static struct parm_struct parm_table
[] = {
332 {"server role", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_role
), NULL
, enum_server_role
},
334 {"dos charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(dos_charset
), NULL
, NULL
},
335 {"unix charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(unix_charset
), NULL
, NULL
},
336 {"ncalrpc dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ncalrpc_dir
), NULL
, NULL
},
337 {"display charset", P_STRING
, P_GLOBAL
, GLOBAL_VAR(display_charset
), NULL
, NULL
},
338 {"comment", P_STRING
, P_LOCAL
, LOCAL_VAR(comment
), NULL
, NULL
},
339 {"path", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
340 {"directory", P_STRING
, P_LOCAL
, LOCAL_VAR(szPath
), NULL
, NULL
},
341 {"workgroup", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szWorkgroup
), NULL
, NULL
},
342 {"realm", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szRealm
), NULL
, NULL
},
343 {"netbios name", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosName
), NULL
, NULL
},
344 {"netbios aliases", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNetbiosAliases
), NULL
, NULL
},
345 {"netbios scope", P_USTRING
, P_GLOBAL
, GLOBAL_VAR(szNetbiosScope
), NULL
, NULL
},
346 {"server string", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szServerString
), NULL
, NULL
},
347 {"interfaces", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szInterfaces
), NULL
, NULL
},
348 {"bind interfaces only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bBindInterfacesOnly
), NULL
, NULL
},
349 {"ntvfs handler", P_LIST
, P_LOCAL
, LOCAL_VAR(ntvfs_handler
), NULL
, NULL
},
350 {"ntptr providor", P_STRING
, P_GLOBAL
, GLOBAL_VAR(ntptr_providor
), NULL
, NULL
},
351 {"dcerpc endpoint servers", P_LIST
, P_GLOBAL
, GLOBAL_VAR(dcerpc_ep_servers
), NULL
, NULL
},
352 {"server services", P_LIST
, P_GLOBAL
, GLOBAL_VAR(server_services
), NULL
, NULL
},
354 {"security", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(security
), NULL
, enum_security
},
355 {"encrypt passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bEncryptPasswords
), NULL
, NULL
},
356 {"null passwords", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNullPasswords
), NULL
, NULL
},
357 {"obey pam restrictions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bObeyPamRestrictions
), NULL
, NULL
},
358 {"password server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szPasswordServers
), NULL
, NULL
},
359 {"sam database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSAM_URL
), NULL
, NULL
},
360 {"idmap database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szIDMAP_URL
), NULL
, NULL
},
361 {"secrets database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSECRETS_URL
), NULL
, NULL
},
362 {"spoolss database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSPOOLSS_URL
), NULL
, NULL
},
363 {"wins config database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_CONFIG_URL
), NULL
, NULL
},
364 {"wins database", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINS_URL
), NULL
, NULL
},
365 {"private dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPrivateDir
), NULL
, NULL
},
366 {"passwd chat", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPasswdChat
), NULL
, NULL
},
367 {"password level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(pwordlevel
), NULL
, NULL
},
368 {"lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLanmanAuth
), NULL
, NULL
},
369 {"ntlm auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTLMAuth
), NULL
, NULL
},
370 {"client NTLMv2 auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientNTLMv2Auth
), NULL
, NULL
},
371 {"client lanman auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientLanManAuth
), NULL
, NULL
},
372 {"client plaintext auth", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bClientPlaintextAuth
), NULL
, NULL
},
373 {"client use spnego principal", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(client_use_spnego_principal
), NULL
, NULL
},
375 {"read only", P_BOOL
, P_LOCAL
, LOCAL_VAR(bRead_only
), NULL
, NULL
},
377 {"create mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_mask
), NULL
, NULL
},
378 {"force create mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iCreate_force_mode
), NULL
, NULL
},
379 {"directory mask", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_mask
), NULL
, NULL
},
380 {"force directory mode", P_OCTAL
, P_LOCAL
, LOCAL_VAR(iDir_force_mode
), NULL
, NULL
},
382 {"hosts allow", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsallow
), NULL
, NULL
},
383 {"hosts deny", P_LIST
, P_LOCAL
, LOCAL_VAR(szHostsdeny
), NULL
, NULL
},
385 {"log level", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
386 {"debuglevel", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(debuglevel
), handle_debuglevel
, NULL
},
387 {"log file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(logfile
), handle_logfile
, NULL
},
389 {"smb ports", P_LIST
, P_GLOBAL
, GLOBAL_VAR(smb_ports
), NULL
, NULL
},
390 {"nbt port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(nbt_port
), NULL
, NULL
},
391 {"dgram port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(dgram_port
), NULL
, NULL
},
392 {"cldap port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(cldap_port
), NULL
, NULL
},
393 {"krb5 port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(krb5_port
), NULL
, NULL
},
394 {"kpasswd port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(kpasswd_port
), NULL
, NULL
},
395 {"web port", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(web_port
), NULL
, NULL
},
396 {"tls enabled", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(tls_enabled
), NULL
, NULL
},
397 {"tls keyfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_keyfile
), NULL
, NULL
},
398 {"tls certfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_certfile
), NULL
, NULL
},
399 {"tls cafile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_cafile
), NULL
, NULL
},
400 {"tls crlfile", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_crlfile
), NULL
, NULL
},
401 {"tls dh params file", P_STRING
, P_GLOBAL
, GLOBAL_VAR(tls_dhpfile
), NULL
, NULL
},
402 {"swat directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(swat_directory
), NULL
, NULL
},
403 {"large readwrite", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLargeReadwrite
), NULL
, NULL
},
404 {"server max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_maxprotocol
), NULL
, enum_protocol
},
405 {"server min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(srv_minprotocol
), NULL
, enum_protocol
},
406 {"client max protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_maxprotocol
), NULL
, enum_protocol
},
407 {"client min protocol", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(cli_minprotocol
), NULL
, enum_protocol
},
408 {"unicode", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnicode
), NULL
, NULL
},
409 {"read raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bReadRaw
), NULL
, NULL
},
410 {"write raw", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWriteRaw
), NULL
, NULL
},
411 {"disable netbios", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bDisableNetbios
), NULL
, NULL
},
413 {"nt status support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bNTStatusSupport
), NULL
, NULL
},
415 {"announce version", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAnnounceVersion
), NULL
, NULL
},
416 {"announce as", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(announce_as
), NULL
, enum_announce_as
},
417 {"max mux", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_mux
), NULL
, NULL
},
418 {"max xmit", P_BYTES
, P_GLOBAL
, GLOBAL_VAR(max_xmit
), NULL
, NULL
},
420 {"name resolve order", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szNameResolveOrder
), NULL
, NULL
},
421 {"max wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(max_wins_ttl
), NULL
, NULL
},
422 {"min wins ttl", P_INTEGER
, P_GLOBAL
, GLOBAL_VAR(min_wins_ttl
), NULL
, NULL
},
423 {"time server", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bTimeServer
), NULL
, NULL
},
424 {"unix extensions", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUnixExtensions
), NULL
, NULL
},
425 {"use spnego", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bUseSpnego
), NULL
, NULL
},
426 {"server signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(server_signing
), NULL
, enum_smb_signing_vals
},
427 {"client signing", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(client_signing
), NULL
, enum_smb_signing_vals
},
428 {"rpc big endian", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bRpcBigEndian
), NULL
, NULL
},
430 {"max connections", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxConnections
), NULL
, NULL
},
431 {"paranoid server security", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(paranoid_server_security
), NULL
, NULL
},
432 {"socket options", P_STRING
, P_GLOBAL
, GLOBAL_VAR(socket_options
), NULL
, NULL
},
434 {"strict sync", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictSync
), NULL
, NULL
},
435 {"case insensitive filesystem", P_BOOL
, P_LOCAL
, LOCAL_VAR(bCIFileSystem
), NULL
, NULL
},
437 {"max print jobs", P_INTEGER
, P_LOCAL
, LOCAL_VAR(iMaxPrintJobs
), NULL
, NULL
},
438 {"printable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
439 {"print ok", P_BOOL
, P_LOCAL
, LOCAL_VAR(bPrint_ok
), NULL
, NULL
},
441 {"printer name", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
442 {"printer", P_STRING
, P_LOCAL
, LOCAL_VAR(szPrintername
), NULL
, NULL
},
444 {"map system", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_system
), NULL
, NULL
},
445 {"map hidden", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_hidden
), NULL
, NULL
},
446 {"map archive", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMap_archive
), NULL
, NULL
},
448 {"preferred master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
449 {"prefered master", P_ENUM
, P_GLOBAL
, GLOBAL_VAR(bPreferredMaster
), NULL
, enum_bool_auto
},
450 {"local master", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bLocalMaster
), NULL
, NULL
},
451 {"browseable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
452 {"browsable", P_BOOL
, P_LOCAL
, LOCAL_VAR(bBrowseable
), NULL
, NULL
},
454 {"wins server", P_LIST
, P_GLOBAL
, GLOBAL_VAR(szWINSservers
), NULL
, NULL
},
455 {"wins support", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSsupport
), NULL
, NULL
},
456 {"dns proxy", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWINSdnsProxy
), NULL
, NULL
},
457 {"wins hook", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWINSHook
), NULL
, NULL
},
459 {"csc policy", P_ENUM
, P_LOCAL
, LOCAL_VAR(iCSCPolicy
), NULL
, enum_csc_policy
},
461 {"strict locking", P_BOOL
, P_LOCAL
, LOCAL_VAR(bStrictLocking
), NULL
, NULL
},
462 {"oplocks", P_BOOL
, P_LOCAL
, LOCAL_VAR(bOplocks
), NULL
, NULL
},
464 {"share backend", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szShareBackend
), NULL
, NULL
},
465 {"preload", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
466 {"auto services", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szAutoServices
), NULL
, NULL
},
467 {"lock dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
468 {"lock directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szLockDir
), NULL
, NULL
},
469 {"modules dir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szModulesDir
), NULL
, NULL
},
470 {"pid directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szPidDir
), NULL
, NULL
},
471 {"setup directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSetupDir
), NULL
, NULL
},
473 {"socket address", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szSocketAddress
), NULL
, NULL
},
474 {"copy", P_STRING
, P_LOCAL
, LOCAL_VAR(szCopy
), handle_copy
, NULL
},
475 {"include", P_STRING
, P_LOCAL
, LOCAL_VAR(szInclude
), handle_include
, NULL
},
477 {"available", P_BOOL
, P_LOCAL
, LOCAL_VAR(bAvailable
), NULL
, NULL
},
478 {"volume", P_STRING
, P_LOCAL
, LOCAL_VAR(volume
), NULL
, NULL
},
479 {"fstype", P_STRING
, P_LOCAL
, LOCAL_VAR(fstype
), NULL
, NULL
},
481 {"panic action", P_STRING
, P_GLOBAL
, GLOBAL_VAR(panic_action
), NULL
, NULL
},
483 {"msdfs root", P_BOOL
, P_LOCAL
, LOCAL_VAR(bMSDfsRoot
), NULL
, NULL
},
484 {"host msdfs", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bHostMSDfs
), NULL
, NULL
},
485 {"winbind separator", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbindSeparator
), NULL
, NULL
},
486 {"winbindd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddSocketDirectory
), NULL
, NULL
},
487 {"winbindd privileged socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
), NULL
, NULL
},
488 {"winbind sealed pipes", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bWinbindSealedPipes
), NULL
, NULL
},
489 {"template shell", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateShell
), NULL
, NULL
},
490 {"template homedir", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szTemplateHomedir
), NULL
, NULL
},
491 {"idmap trusted only", P_BOOL
, P_GLOBAL
, GLOBAL_VAR(bIdmapTrustedOnly
), NULL
, NULL
},
493 {"ntp signd socket directory", P_STRING
, P_GLOBAL
, GLOBAL_VAR(szNTPSignDSocketDirectory
), NULL
, NULL
},
495 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
}
499 /* local variables */
500 struct loadparm_context
{
501 const char *szConfigFile
;
502 struct loadparm_global
*globals
;
503 struct loadparm_service
**services
;
504 struct loadparm_service
*sDefault
;
506 struct loadparm_service
*currentService
;
507 bool bInGlobalSection
;
509 struct file_lists
*next
;
514 unsigned int flags
[NUMPARAMETERS
];
515 struct smb_iconv_convenience
*iconv_convenience
;
519 struct loadparm_service
*lp_default_service(struct loadparm_context
*lp_ctx
)
521 return lp_ctx
->sDefault
;
525 return the parameter table
527 struct parm_struct
*lp_parm_table(void)
533 * Convenience routine to grab string parameters into temporary memory
534 * and run standard_sub_basic on them.
536 * The buffers can be written to by
537 * callers without affecting the source string.
540 static const char *lp_string(const char *s
)
542 #if 0 /* until REWRITE done to make thread-safe */
543 size_t len
= s
? strlen(s
) : 0;
547 /* The follow debug is useful for tracking down memory problems
548 especially if you have an inner loop that is calling a lp_*()
549 function that returns a string. Perhaps this debug should be
550 present all the time? */
553 DEBUG(10, ("lp_string(%s)\n", s
));
556 #if 0 /* until REWRITE done to make thread-safe */
558 lp_talloc
= talloc_init("lp_talloc");
560 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
568 strlcpy(ret
, s
, len
);
570 if (trim_string(ret
, "\"", "\"")) {
571 if (strchr(ret
,'"') != NULL
)
572 strlcpy(ret
, s
, len
);
575 standard_sub_basic(ret
,len
+100);
582 In this section all the functions that are used to access the
583 parameters from the rest of the program are defined
586 #define FN_GLOBAL_STRING(fn_name,var_name) \
587 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) : "";}
588 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
589 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 : "";}
590 #define FN_GLOBAL_LIST(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;}
592 #define FN_GLOBAL_BOOL(fn_name,var_name) \
593 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
595 #define FN_GLOBAL_CHAR(fn_name,ptr) \
596 char fn_name(void) {return(*(char *)(ptr));}
598 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
599 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
601 #define FN_LOCAL_STRING(fn_name,val) \
602 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)));}
603 #define FN_LOCAL_LIST(fn_name,val) \
604 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
605 #define FN_LOCAL_BOOL(fn_name,val) \
606 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
607 #define FN_LOCAL_INTEGER(fn_name,val) \
608 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
610 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_role
, server_role
)
611 _PUBLIC_
FN_GLOBAL_LIST(lp_smb_ports
, smb_ports
)
612 _PUBLIC_
FN_GLOBAL_INTEGER(lp_nbt_port
, nbt_port
)
613 _PUBLIC_
FN_GLOBAL_INTEGER(lp_dgram_port
, dgram_port
)
614 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cldap_port
, cldap_port
)
615 _PUBLIC_
FN_GLOBAL_INTEGER(lp_krb5_port
, krb5_port
)
616 _PUBLIC_
FN_GLOBAL_INTEGER(lp_kpasswd_port
, kpasswd_port
)
617 _PUBLIC_
FN_GLOBAL_INTEGER(lp_web_port
, web_port
)
618 _PUBLIC_
FN_GLOBAL_STRING(lp_swat_directory
, swat_directory
)
619 _PUBLIC_
FN_GLOBAL_BOOL(lp_tls_enabled
, tls_enabled
)
620 _PUBLIC_
FN_GLOBAL_STRING(lp_share_backend
, szShareBackend
)
621 _PUBLIC_
FN_GLOBAL_STRING(lp_sam_url
, szSAM_URL
)
622 _PUBLIC_
FN_GLOBAL_STRING(lp_idmap_url
, szIDMAP_URL
)
623 _PUBLIC_
FN_GLOBAL_STRING(lp_secrets_url
, szSECRETS_URL
)
624 _PUBLIC_
FN_GLOBAL_STRING(lp_spoolss_url
, szSPOOLSS_URL
)
625 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_config_url
, szWINS_CONFIG_URL
)
626 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_url
, szWINS_URL
)
627 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbind_separator
, szWinbindSeparator
)
628 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory
, szWinbinddSocketDirectory
)
629 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
630 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_shell
, szTemplateShell
)
631 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_template_homedir
, szTemplateHomedir
)
632 _PUBLIC_
FN_GLOBAL_BOOL(lp_winbind_sealed_pipes
, bWinbindSealedPipes
)
633 _PUBLIC_
FN_GLOBAL_BOOL(lp_idmap_trusted_only
, bIdmapTrustedOnly
)
634 _PUBLIC_
FN_GLOBAL_STRING(lp_private_dir
, szPrivateDir
)
635 _PUBLIC_
FN_GLOBAL_STRING(lp_serverstring
, szServerString
)
636 _PUBLIC_
FN_GLOBAL_STRING(lp_lockdir
, szLockDir
)
637 _PUBLIC_
FN_GLOBAL_STRING(lp_modulesdir
, szModulesDir
)
638 _PUBLIC_
FN_GLOBAL_STRING(lp_setupdir
, szSetupDir
)
639 _PUBLIC_
FN_GLOBAL_STRING(lp_ncalrpc_dir
, ncalrpc_dir
)
640 _PUBLIC_
FN_GLOBAL_STRING(lp_dos_charset
, dos_charset
)
641 _PUBLIC_
FN_GLOBAL_STRING(lp_unix_charset
, unix_charset
)
642 _PUBLIC_
FN_GLOBAL_STRING(lp_display_charset
, display_charset
)
643 _PUBLIC_
FN_GLOBAL_STRING(lp_piddir
, szPidDir
)
644 _PUBLIC_
FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers
, dcerpc_ep_servers
)
645 _PUBLIC_
FN_GLOBAL_LIST(lp_server_services
, server_services
)
646 _PUBLIC_
FN_GLOBAL_STRING(lp_ntptr_providor
, ntptr_providor
)
647 _PUBLIC_
FN_GLOBAL_STRING(lp_auto_services
, szAutoServices
)
648 _PUBLIC_
FN_GLOBAL_STRING(lp_passwd_chat
, szPasswdChat
)
649 _PUBLIC_
FN_GLOBAL_LIST(lp_passwordserver
, szPasswordServers
)
650 _PUBLIC_
FN_GLOBAL_LIST(lp_name_resolve_order
, szNameResolveOrder
)
651 _PUBLIC_
FN_GLOBAL_STRING(lp_realm
, szRealm
)
652 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_options
, socket_options
)
653 _PUBLIC_
FN_GLOBAL_STRING(lp_workgroup
, szWorkgroup
)
654 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_name
, szNetbiosName
)
655 _PUBLIC_
FN_GLOBAL_STRING(lp_netbios_scope
, szNetbiosScope
)
656 _PUBLIC_
FN_GLOBAL_LIST(lp_wins_server_list
, szWINSservers
)
657 _PUBLIC_
FN_GLOBAL_LIST(lp_interfaces
, szInterfaces
)
658 _PUBLIC_
FN_GLOBAL_STRING(lp_socket_address
, szSocketAddress
)
659 _PUBLIC_
FN_GLOBAL_LIST(lp_netbios_aliases
, szNetbiosAliases
)
661 _PUBLIC_
FN_GLOBAL_BOOL(lp_disable_netbios
, bDisableNetbios
)
662 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_support
, bWINSsupport
)
663 _PUBLIC_
FN_GLOBAL_BOOL(lp_wins_dns_proxy
, bWINSdnsProxy
)
664 _PUBLIC_
FN_GLOBAL_STRING(lp_wins_hook
, szWINSHook
)
665 _PUBLIC_
FN_GLOBAL_BOOL(lp_local_master
, bLocalMaster
)
666 _PUBLIC_
FN_GLOBAL_BOOL(lp_readraw
, bReadRaw
)
667 _PUBLIC_
FN_GLOBAL_BOOL(lp_large_readwrite
, bLargeReadwrite
)
668 _PUBLIC_
FN_GLOBAL_BOOL(lp_writeraw
, bWriteRaw
)
669 _PUBLIC_
FN_GLOBAL_BOOL(lp_null_passwords
, bNullPasswords
)
670 _PUBLIC_
FN_GLOBAL_BOOL(lp_obey_pam_restrictions
, bObeyPamRestrictions
)
671 _PUBLIC_
FN_GLOBAL_BOOL(lp_encrypted_passwords
, bEncryptPasswords
)
672 _PUBLIC_
FN_GLOBAL_BOOL(lp_time_server
, bTimeServer
)
673 _PUBLIC_
FN_GLOBAL_BOOL(lp_bind_interfaces_only
, bBindInterfacesOnly
)
674 _PUBLIC_
FN_GLOBAL_BOOL(lp_unicode
, bUnicode
)
675 _PUBLIC_
FN_GLOBAL_BOOL(lp_nt_status_support
, bNTStatusSupport
)
676 _PUBLIC_
FN_GLOBAL_BOOL(lp_lanman_auth
, bLanmanAuth
)
677 _PUBLIC_
FN_GLOBAL_BOOL(lp_ntlm_auth
, bNTLMAuth
)
678 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_plaintext_auth
, bClientPlaintextAuth
)
679 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_lanman_auth
, bClientLanManAuth
)
680 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_ntlmv2_auth
, bClientNTLMv2Auth
)
681 _PUBLIC_
FN_GLOBAL_BOOL(lp_client_use_spnego_principal
, client_use_spnego_principal
)
682 _PUBLIC_
FN_GLOBAL_BOOL(lp_host_msdfs
, bHostMSDfs
)
683 _PUBLIC_
FN_GLOBAL_BOOL(lp_unix_extensions
, bUnixExtensions
)
684 _PUBLIC_
FN_GLOBAL_BOOL(lp_use_spnego
, bUseSpnego
)
685 _PUBLIC_
FN_GLOBAL_BOOL(lp_rpc_big_endian
, bRpcBigEndian
)
686 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_wins_ttl
, max_wins_ttl
)
687 _PUBLIC_
FN_GLOBAL_INTEGER(lp_min_wins_ttl
, min_wins_ttl
)
688 _PUBLIC_
FN_GLOBAL_INTEGER(lp_maxmux
, max_mux
)
689 _PUBLIC_
FN_GLOBAL_INTEGER(lp_max_xmit
, max_xmit
)
690 _PUBLIC_
FN_GLOBAL_INTEGER(lp_passwordlevel
, pwordlevel
)
691 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_maxprotocol
, srv_maxprotocol
)
692 _PUBLIC_
FN_GLOBAL_INTEGER(lp_srv_minprotocol
, srv_minprotocol
)
693 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_maxprotocol
, cli_maxprotocol
)
694 _PUBLIC_
FN_GLOBAL_INTEGER(lp_cli_minprotocol
, cli_minprotocol
)
695 _PUBLIC_
FN_GLOBAL_INTEGER(lp_security
, security
)
696 _PUBLIC_
FN_GLOBAL_BOOL(lp_paranoid_server_security
, paranoid_server_security
)
697 _PUBLIC_
FN_GLOBAL_INTEGER(lp_announce_as
, announce_as
)
698 const char *lp_servicename(const struct loadparm_service
*service
)
700 return lp_string((const char *)service
->szService
);
703 _PUBLIC_
FN_LOCAL_STRING(lp_pathname
, szPath
)
704 static FN_LOCAL_STRING(_lp_printername
, szPrintername
)
705 _PUBLIC_
FN_LOCAL_LIST(lp_hostsallow
, szHostsallow
)
706 _PUBLIC_
FN_LOCAL_LIST(lp_hostsdeny
, szHostsdeny
)
707 _PUBLIC_
FN_LOCAL_STRING(lp_comment
, comment
)
708 _PUBLIC_
FN_LOCAL_STRING(lp_fstype
, fstype
)
709 static FN_LOCAL_STRING(lp_volume
, volume
)
710 _PUBLIC_
FN_LOCAL_LIST(lp_ntvfs_handler
, ntvfs_handler
)
711 _PUBLIC_
FN_LOCAL_BOOL(lp_msdfs_root
, bMSDfsRoot
)
712 _PUBLIC_
FN_LOCAL_BOOL(lp_browseable
, bBrowseable
)
713 _PUBLIC_
FN_LOCAL_BOOL(lp_readonly
, bRead_only
)
714 _PUBLIC_
FN_LOCAL_BOOL(lp_print_ok
, bPrint_ok
)
715 _PUBLIC_
FN_LOCAL_BOOL(lp_map_hidden
, bMap_hidden
)
716 _PUBLIC_
FN_LOCAL_BOOL(lp_map_archive
, bMap_archive
)
717 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_locking
, bStrictLocking
)
718 _PUBLIC_
FN_LOCAL_BOOL(lp_oplocks
, bOplocks
)
719 _PUBLIC_
FN_LOCAL_BOOL(lp_strict_sync
, bStrictSync
)
720 _PUBLIC_
FN_LOCAL_BOOL(lp_ci_filesystem
, bCIFileSystem
)
721 _PUBLIC_
FN_LOCAL_BOOL(lp_map_system
, bMap_system
)
722 _PUBLIC_
FN_LOCAL_INTEGER(lp_max_connections
, iMaxConnections
)
723 _PUBLIC_
FN_LOCAL_INTEGER(lp_csc_policy
, iCSCPolicy
)
724 _PUBLIC_
FN_LOCAL_INTEGER(lp_create_mask
, iCreate_mask
)
725 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_create_mode
, iCreate_force_mode
)
726 _PUBLIC_
FN_LOCAL_INTEGER(lp_dir_mask
, iDir_mask
)
727 _PUBLIC_
FN_LOCAL_INTEGER(lp_force_dir_mode
, iDir_force_mode
)
728 _PUBLIC_
FN_GLOBAL_INTEGER(lp_server_signing
, server_signing
)
729 _PUBLIC_
FN_GLOBAL_INTEGER(lp_client_signing
, client_signing
)
731 _PUBLIC_
FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
733 /* local prototypes */
734 static int map_parameter(const char *pszParmName
);
735 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
736 const char *pszServiceName
);
737 static void copy_service(struct loadparm_service
*pserviceDest
,
738 struct loadparm_service
*pserviceSource
,
740 static bool service_ok(struct loadparm_service
*service
);
741 static bool do_section(const char *pszSectionName
, void *);
742 static void init_copymap(struct loadparm_service
*pservice
);
744 /* This is a helper function for parametrical options support. */
745 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
746 /* Actual parametrical functions are quite simple */
747 const char *lp_get_parametric(struct loadparm_context
*lp_ctx
,
748 struct loadparm_service
*service
,
749 const char *type
, const char *option
)
752 struct param_opt
*data
;
757 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
759 asprintf(&vfskey
, "%s:%s", type
, option
);
763 if (strcmp(data
->key
, vfskey
) == 0) {
770 if (service
!= NULL
) {
771 /* Try to fetch the same option but from globals */
772 /* but only if we are not already working with globals */
773 for (data
= lp_ctx
->globals
->param_opt
; data
;
775 if (strcmp(data
->key
, vfskey
) == 0) {
789 * convenience routine to return int parameters.
791 static int lp_int(const char *s
)
795 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
799 return strtol(s
, NULL
, 0);
803 * convenience routine to return unsigned long parameters.
805 static int lp_ulong(const char *s
)
809 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
813 return strtoul(s
, NULL
, 0);
817 * convenience routine to return unsigned long parameters.
819 static double lp_double(const char *s
)
823 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
827 return strtod(s
, NULL
);
831 * convenience routine to return boolean parameters.
833 static bool lp_bool(const char *s
)
838 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
842 if (!set_boolean(s
, &ret
)) {
843 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
852 * Return parametric option from a given service. Type is a part of option before ':'
853 * Parametric option has following syntax: 'Type: option = value'
854 * Returned value is allocated in 'lp_talloc' context
857 const char *lp_parm_string(struct loadparm_context
*lp_ctx
,
858 struct loadparm_service
*service
, const char *type
,
861 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
864 return lp_string(value
);
870 * Return parametric option from a given service. Type is a part of option before ':'
871 * Parametric option has following syntax: 'Type: option = value'
872 * Returned value is allocated in 'lp_talloc' context
875 const char **lp_parm_string_list(TALLOC_CTX
*mem_ctx
,
876 struct loadparm_context
*lp_ctx
,
877 struct loadparm_service
*service
,
879 const char *option
, const char *separator
)
881 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
884 return (const char **)str_list_make(mem_ctx
, value
, separator
);
890 * Return parametric option from a given service. Type is a part of option before ':'
891 * Parametric option has following syntax: 'Type: option = value'
894 int lp_parm_int(struct loadparm_context
*lp_ctx
,
895 struct loadparm_service
*service
, const char *type
,
896 const char *option
, int default_v
)
898 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
901 return lp_int(value
);
907 * Return parametric option from a given service. Type is a part of
909 * Parametric option has following syntax: 'Type: option = value'.
912 int lp_parm_bytes(struct loadparm_context
*lp_ctx
,
913 struct loadparm_service
*service
, const char *type
,
914 const char *option
, int default_v
)
918 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
920 if (value
&& conv_str_size(value
, &bval
)) {
921 if (bval
<= INT_MAX
) {
930 * Return parametric option from a given service.
931 * Type is a part of option before ':'
932 * Parametric option has following syntax: 'Type: option = value'
934 unsigned long lp_parm_ulong(struct loadparm_context
*lp_ctx
,
935 struct loadparm_service
*service
, const char *type
,
936 const char *option
, unsigned long default_v
)
938 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
941 return lp_ulong(value
);
947 double lp_parm_double(struct loadparm_context
*lp_ctx
,
948 struct loadparm_service
*service
, const char *type
,
949 const char *option
, double default_v
)
951 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
954 return lp_double(value
);
960 * Return parametric option from a given service. Type is a part of option before ':'
961 * Parametric option has following syntax: 'Type: option = value'
964 bool lp_parm_bool(struct loadparm_context
*lp_ctx
,
965 struct loadparm_service
*service
, const char *type
,
966 const char *option
, bool default_v
)
968 const char *value
= lp_get_parametric(lp_ctx
, service
, type
, option
);
971 return lp_bool(value
);
978 * Initialise a service to the defaults.
981 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
983 struct loadparm_service
*pservice
=
984 talloc_zero(mem_ctx
, struct loadparm_service
);
985 copy_service(pservice
, sDefault
, NULL
);
990 * Set a string value, deallocating any existing space, and allocing the space
993 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1000 *dest
= talloc_strdup(mem_ctx
, src
);
1001 if ((*dest
) == NULL
) {
1002 DEBUG(0,("Out of memory in string_init\n"));
1012 * Add a new service to the services array initialising it with the given
1016 struct loadparm_service
*lp_add_service(struct loadparm_context
*lp_ctx
,
1017 const struct loadparm_service
*pservice
,
1021 struct loadparm_service tservice
;
1022 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1023 struct param_opt
*data
, *pdata
;
1025 tservice
= *pservice
;
1027 /* it might already exist */
1029 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1031 if (service
!= NULL
) {
1032 /* Clean all parametric options for service */
1033 /* They will be added during parsing again */
1034 data
= service
->param_opt
;
1040 service
->param_opt
= NULL
;
1045 /* find an invalid one */
1046 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1047 if (lp_ctx
->services
[i
] == NULL
)
1050 /* if not, then create one */
1051 if (i
== lp_ctx
->iNumServices
) {
1052 struct loadparm_service
**tsp
;
1054 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1057 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1060 lp_ctx
->services
= tsp
;
1061 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1064 lp_ctx
->iNumServices
++;
1067 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1068 if (lp_ctx
->services
[i
] == NULL
) {
1069 DEBUG(0,("lp_add_service: out of memory!\n"));
1072 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1074 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1075 return lp_ctx
->services
[i
];
1079 * Add a new home service, with the specified home directory, defaults coming
1080 * from service ifrom.
1083 bool lp_add_home(struct loadparm_context
*lp_ctx
,
1084 const char *pszHomename
,
1085 struct loadparm_service
*default_service
,
1086 const char *user
, const char *pszHomedir
)
1088 struct loadparm_service
*service
;
1090 service
= lp_add_service(lp_ctx
, default_service
, pszHomename
);
1092 if (service
== NULL
)
1095 if (!(*(default_service
->szPath
))
1096 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1097 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1099 service
->szPath
= string_sub_talloc(service
, lp_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1102 if (!(*(service
->comment
))) {
1103 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1105 service
->bAvailable
= default_service
->bAvailable
;
1106 service
->bBrowseable
= default_service
->bBrowseable
;
1108 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1109 pszHomename
, user
, service
->szPath
));
1115 * Add the IPC service.
1118 static bool lp_add_hidden(struct loadparm_context
*lp_ctx
, const char *name
,
1121 struct loadparm_service
*service
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
, name
);
1123 if (service
== NULL
)
1126 string_set(service
, &service
->szPath
, tmpdir());
1128 service
->comment
= talloc_asprintf(service
, "%s Service (%s)",
1129 fstype
, lp_ctx
->globals
->szServerString
);
1130 string_set(service
, &service
->fstype
, fstype
);
1131 service
->iMaxConnections
= -1;
1132 service
->bAvailable
= true;
1133 service
->bRead_only
= true;
1134 service
->bPrint_ok
= false;
1135 service
->bBrowseable
= false;
1137 if (strcasecmp(fstype
, "IPC") == 0) {
1138 lp_do_service_parameter(lp_ctx
, service
, "ntvfs handler",
1142 DEBUG(3, ("adding hidden service %s\n", name
));
1148 * Add a new printer service, with defaults coming from service iFrom.
1151 bool lp_add_printer(struct loadparm_context
*lp_ctx
,
1152 const char *pszPrintername
,
1153 struct loadparm_service
*default_service
)
1155 const char *comment
= "From Printcap";
1156 struct loadparm_service
*service
;
1157 service
= lp_add_service(lp_ctx
, default_service
, pszPrintername
);
1159 if (service
== NULL
)
1162 /* note that we do NOT default the availability flag to True - */
1163 /* we take it from the default service passed. This allows all */
1164 /* dynamic printers to be disabled by disabling the [printers] */
1165 /* entry (if/when the 'available' keyword is implemented!). */
1167 /* the printer name is set to the service name. */
1168 string_set(service
, &service
->szPrintername
, pszPrintername
);
1169 string_set(service
, &service
->comment
, comment
);
1170 service
->bBrowseable
= default_service
->bBrowseable
;
1171 /* Printers cannot be read_only. */
1172 service
->bRead_only
= false;
1173 /* Printer services must be printable. */
1174 service
->bPrint_ok
= true;
1176 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1182 * Map a parameter's string representation to something we can use.
1183 * Returns False if the parameter string is not recognised, else TRUE.
1186 static int map_parameter(const char *pszParmName
)
1190 if (*pszParmName
== '-')
1193 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1194 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1197 /* Warn only if it isn't parametric option */
1198 if (strchr(pszParmName
, ':') == NULL
)
1199 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
1200 /* We do return 'fail' for parametric options as well because they are
1201 stored in different storage
1208 return the parameter structure for a parameter
1210 struct parm_struct
*lp_parm_struct(const char *name
)
1212 int parmnum
= map_parameter(name
);
1213 if (parmnum
== -1) return NULL
;
1214 return &parm_table
[parmnum
];
1218 return the parameter pointer for a parameter
1220 void *lp_parm_ptr(struct loadparm_context
*lp_ctx
,
1221 struct loadparm_service
*service
, struct parm_struct
*parm
)
1223 if (service
== NULL
) {
1224 if (parm
->pclass
== P_LOCAL
)
1225 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
1226 else if (parm
->pclass
== P_GLOBAL
)
1227 return ((char *)lp_ctx
->globals
)+parm
->offset
;
1230 return ((char *)service
) + parm
->offset
;
1235 * Find a service by name. Otherwise works like get_service.
1238 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1239 const char *pszServiceName
)
1243 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
1244 if (lp_ctx
->services
[iService
] != NULL
&&
1245 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
1246 return lp_ctx
->services
[iService
];
1253 * Copy a service structure to another.
1254 * If pcopymapDest is NULL then copy all fields
1257 static void copy_service(struct loadparm_service
*pserviceDest
,
1258 struct loadparm_service
*pserviceSource
,
1262 bool bcopyall
= (pcopymapDest
== NULL
);
1263 struct param_opt
*data
, *pdata
, *paramo
;
1266 for (i
= 0; parm_table
[i
].label
; i
++)
1267 if (parm_table
[i
].offset
!= -1 && parm_table
[i
].pclass
== P_LOCAL
&&
1268 (bcopyall
|| pcopymapDest
[i
])) {
1270 ((char *)pserviceSource
) + parm_table
[i
].offset
;
1272 ((char *)pserviceDest
) + parm_table
[i
].offset
;
1274 switch (parm_table
[i
].type
) {
1276 *(int *)dest_ptr
= *(int *)src_ptr
;
1282 *(int *)dest_ptr
= *(int *)src_ptr
;
1286 string_set(pserviceDest
,
1292 string_set(pserviceDest
,
1295 strupper(*(char **)dest_ptr
);
1298 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
1299 *(const char ***)src_ptr
);
1307 init_copymap(pserviceDest
);
1308 if (pserviceSource
->copymap
)
1309 memcpy((void *)pserviceDest
->copymap
,
1310 (void *)pserviceSource
->copymap
,
1311 sizeof(int) * NUMPARAMETERS
);
1314 data
= pserviceSource
->param_opt
;
1317 pdata
= pserviceDest
->param_opt
;
1318 /* Traverse destination */
1320 /* If we already have same option, override it */
1321 if (strcmp(pdata
->key
, data
->key
) == 0) {
1322 talloc_free(pdata
->value
);
1323 pdata
->value
= talloc_reference(pdata
,
1328 pdata
= pdata
->next
;
1331 paramo
= talloc(pserviceDest
, struct param_opt
);
1334 paramo
->key
= talloc_reference(paramo
, data
->key
);
1335 paramo
->value
= talloc_reference(paramo
, data
->value
);
1336 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1343 * Check a service for consistency. Return False if the service is in any way
1344 * incomplete or faulty, else True.
1346 static bool service_ok(struct loadparm_service
*service
)
1351 if (service
->szService
[0] == '\0') {
1352 DEBUG(0, ("The following message indicates an internal error:\n"));
1353 DEBUG(0, ("No service name in service entry.\n"));
1357 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1358 /* I can't see why you'd want a non-printable printer service... */
1359 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1360 if (!service
->bPrint_ok
) {
1361 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1362 service
->szService
));
1363 service
->bPrint_ok
= true;
1365 /* [printers] service must also be non-browsable. */
1366 if (service
->bBrowseable
)
1367 service
->bBrowseable
= false;
1370 /* If a service is flagged unavailable, log the fact at level 0. */
1371 if (!service
->bAvailable
)
1372 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1373 service
->szService
));
1379 /*******************************************************************
1380 Keep a linked list of all config files so we know when one has changed
1381 it's date and needs to be reloaded.
1382 ********************************************************************/
1384 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1385 const char *fname
, const char *subfname
)
1387 struct file_lists
*f
= lp_ctx
->file_lists
;
1390 if (f
->name
&& !strcmp(f
->name
, fname
))
1396 f
= talloc(lp_ctx
, struct file_lists
);
1399 f
->next
= lp_ctx
->file_lists
;
1400 f
->name
= talloc_strdup(f
, fname
);
1405 f
->subfname
= talloc_strdup(f
, subfname
);
1410 lp_ctx
->file_lists
= f
;
1411 f
->modtime
= file_modtime(subfname
);
1413 time_t t
= file_modtime(subfname
);
1419 /*******************************************************************
1420 Check if a config file has changed date.
1421 ********************************************************************/
1422 bool lp_file_list_changed(struct loadparm_context
*lp_ctx
)
1424 struct file_lists
*f
;
1425 DEBUG(6, ("lp_file_list_changed()\n"));
1427 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1431 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1433 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1434 f
->name
, n2
, ctime(&f
->modtime
)));
1436 mod_time
= file_modtime(n2
);
1438 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1439 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1441 f
->modtime
= mod_time
;
1442 talloc_free(f
->subfname
);
1443 f
->subfname
= talloc_strdup(f
, n2
);
1450 /***************************************************************************
1451 Handle the include operation.
1452 ***************************************************************************/
1454 static bool handle_include(struct loadparm_context
*lp_ctx
,
1455 const char *pszParmValue
, char **ptr
)
1457 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1459 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1461 string_set(lp_ctx
, ptr
, fname
);
1463 if (file_exist(fname
))
1464 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1466 DEBUG(2, ("Can't find include file %s\n", fname
));
1471 /***************************************************************************
1472 Handle the interpretation of the copy parameter.
1473 ***************************************************************************/
1475 static bool handle_copy(struct loadparm_context
*lp_ctx
,
1476 const char *pszParmValue
, char **ptr
)
1479 struct loadparm_service
*serviceTemp
;
1481 string_set(lp_ctx
, ptr
, pszParmValue
);
1485 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1487 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1488 if (serviceTemp
== lp_ctx
->currentService
) {
1489 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1491 copy_service(lp_ctx
->currentService
,
1493 lp_ctx
->currentService
->copymap
);
1497 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1505 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
,
1506 const char *pszParmValue
, char **ptr
)
1508 DEBUGLEVEL
= atoi(pszParmValue
);
1513 static bool handle_logfile(struct loadparm_context
*lp_ctx
,
1514 const char *pszParmValue
, char **ptr
)
1516 logfile
= pszParmValue
;
1520 /***************************************************************************
1521 Initialise a copymap.
1522 ***************************************************************************/
1524 static void init_copymap(struct loadparm_service
*pservice
)
1527 talloc_free(pservice
->copymap
);
1528 pservice
->copymap
= talloc_array(pservice
, int, NUMPARAMETERS
);
1529 if (pservice
->copymap
== NULL
) {
1531 ("Couldn't allocate copymap!! (size %d)\n",
1532 (int)NUMPARAMETERS
));
1535 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1536 pservice
->copymap
[i
] = true;
1540 * Process a parametric option
1542 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1543 struct loadparm_service
*service
,
1544 const char *pszParmName
,
1545 const char *pszParmValue
, int flags
)
1547 struct param_opt
*paramo
, *data
;
1549 TALLOC_CTX
*mem_ctx
;
1551 while (isspace((unsigned char)*pszParmName
)) {
1555 name
= strdup(pszParmName
);
1556 if (!name
) return false;
1560 if (service
== NULL
) {
1561 data
= lp_ctx
->globals
->param_opt
;
1562 mem_ctx
= lp_ctx
->globals
;
1564 data
= service
->param_opt
;
1568 /* Traverse destination */
1569 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1570 /* If we already have the option set, override it unless
1571 it was a command line option and the new one isn't */
1572 if (strcmp(paramo
->key
, name
) == 0) {
1573 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1574 !(flags
& FLAG_CMDLINE
)) {
1578 talloc_free(paramo
->value
);
1579 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1580 paramo
->priority
= flags
;
1586 paramo
= talloc(mem_ctx
, struct param_opt
);
1589 paramo
->key
= talloc_strdup(paramo
, name
);
1590 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1591 paramo
->priority
= flags
;
1592 if (service
== NULL
) {
1593 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1595 DLIST_ADD(service
->param_opt
, paramo
);
1603 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1604 const char *pszParmName
, const char *pszParmValue
,
1605 struct loadparm_context
*lp_ctx
)
1608 /* if it is a special case then go ahead */
1609 if (parm_table
[parmnum
].special
) {
1610 parm_table
[parmnum
].special(lp_ctx
, pszParmValue
,
1615 /* now switch on the type of variable it is */
1616 switch (parm_table
[parmnum
].type
)
1620 if (!set_boolean(pszParmValue
, &b
)) {
1621 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1624 *(int *)parm_ptr
= b
;
1629 *(int *)parm_ptr
= atoi(pszParmValue
);
1633 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1639 if (conv_str_size(pszParmValue
, &val
)) {
1640 if (val
<= INT_MAX
) {
1641 *(int *)parm_ptr
= (int)val
;
1646 DEBUG(0,("lp_do_parameter(%s): value is not "
1647 "a valid size specifier!\n", pszParmValue
));
1652 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1653 pszParmValue
, NULL
);
1657 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1661 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1662 strupper(*(char **)parm_ptr
);
1666 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1669 parm_table
[parmnum
].enum_list
[i
].name
)) {
1671 parm_table
[parmnum
].
1676 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1677 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1678 pszParmValue
, pszParmName
));
1684 if (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
) {
1685 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1686 /* we have to also unset FLAG_DEFAULT on aliases */
1687 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1688 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1690 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1691 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1698 bool lp_do_global_parameter(struct loadparm_context
*lp_ctx
,
1699 const char *pszParmName
, const char *pszParmValue
)
1701 int parmnum
= map_parameter(pszParmName
);
1705 if (strchr(pszParmName
, ':')) {
1706 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1708 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1712 /* if the flag has been set on the command line, then don't allow override,
1713 but don't report an error */
1714 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1718 parm_ptr
= lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1720 return set_variable(lp_ctx
, parmnum
, parm_ptr
,
1721 pszParmName
, pszParmValue
, lp_ctx
);
1724 bool lp_do_service_parameter(struct loadparm_context
*lp_ctx
,
1725 struct loadparm_service
*service
,
1726 const char *pszParmName
, const char *pszParmValue
)
1730 int parmnum
= map_parameter(pszParmName
);
1733 if (strchr(pszParmName
, ':')) {
1734 return lp_do_parameter_parametric(lp_ctx
, service
, 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 if (parm_table
[parmnum
].pclass
== P_GLOBAL
) {
1748 ("Global parameter %s found in service section!\n",
1752 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1754 if (!service
->copymap
)
1755 init_copymap(service
);
1757 /* this handles the aliases - set the copymap for other
1758 * entries with the same data pointer */
1759 for (i
= 0; parm_table
[i
].label
; i
++)
1760 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1761 parm_table
[i
].pclass
== parm_table
[parmnum
].pclass
)
1762 service
->copymap
[i
] = false;
1764 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1765 pszParmValue
, lp_ctx
);
1769 * Process a parameter.
1772 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1775 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1777 if (lp_ctx
->bInGlobalSection
)
1778 return lp_do_global_parameter(lp_ctx
, pszParmName
,
1781 return lp_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1782 pszParmName
, pszParmValue
);
1786 variable argument do parameter
1788 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1789 bool lp_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1790 const char *pszParmName
, const char *fmt
, ...)
1797 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1799 ret
= lp_do_global_parameter(lp_ctx
, pszParmName
, s
);
1806 set a parameter from the commandline - this is called from command line parameter
1807 parsing code. It sets the parameter then marks the parameter as unable to be modified
1808 by smb.conf processing
1810 bool lp_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1811 const char *pszParmValue
)
1813 int parmnum
= map_parameter(pszParmName
);
1816 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1819 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1820 /* set a parametric option */
1821 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1822 pszParmValue
, FLAG_CMDLINE
);
1826 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1830 /* reset the CMDLINE flag in case this has been called before */
1831 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1833 if (!lp_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1837 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1839 /* we have to also set FLAG_CMDLINE on aliases */
1840 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1841 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1843 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1844 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1851 set a option from the commandline in 'a=b' format. Use to support --option
1853 bool lp_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1871 ret
= lp_set_cmdline(lp_ctx
, s
, p
+1);
1877 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1880 * Print a parameter of the specified type.
1883 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1889 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1890 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1892 p
->enum_list
[i
].name
);
1899 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
1904 fprintf(f
, "%d", *(int *)ptr
);
1908 fprintf(f
, "0%o", *(int *)ptr
);
1912 if ((char ***)ptr
&& *(char ***)ptr
) {
1913 char **list
= *(char ***)ptr
;
1915 for (; *list
; list
++)
1916 fprintf(f
, "%s%s", *list
,
1917 ((*(list
+1))?", ":""));
1923 if (*(char **)ptr
) {
1924 fprintf(f
, "%s", *(char **)ptr
);
1931 * Check if two parameters are equal.
1934 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1938 return (*((int *)ptr1
) == *((int *)ptr2
));
1944 return (*((int *)ptr1
) == *((int *)ptr2
));
1947 return str_list_equal((const char **)(*(char ***)ptr1
),
1948 (const char **)(*(char ***)ptr2
));
1953 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1958 return (p1
== p2
|| strequal(p1
, p2
));
1965 * Process a new section (service).
1967 * At this stage all sections are services.
1968 * Later we'll have special sections that permit server parameters to be set.
1969 * Returns True on success, False on failure.
1972 static bool do_section(const char *pszSectionName
, void *userdata
)
1974 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1976 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1977 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1980 /* if we've just struck a global section, note the fact. */
1981 lp_ctx
->bInGlobalSection
= isglobal
;
1983 /* check for multiple global sections */
1984 if (lp_ctx
->bInGlobalSection
) {
1985 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName
));
1989 /* if we have a current service, tidy it up before moving on */
1992 if (lp_ctx
->currentService
!= NULL
)
1993 bRetval
= service_ok(lp_ctx
->currentService
);
1995 /* if all is still well, move to the next record in the services array */
1997 /* We put this here to avoid an odd message order if messages are */
1998 /* issued by the post-processing of a previous section. */
1999 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName
));
2001 if ((lp_ctx
->currentService
= lp_add_service(lp_ctx
, lp_ctx
->sDefault
,
2004 DEBUG(0, ("Failed to add a new service\n"));
2014 * Determine if a particular base parameter is currently set to the default value.
2017 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2019 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2020 if (!defaults_saved
)
2022 switch (parm_table
[i
].type
) {
2024 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2025 (const char **)def_ptr
);
2028 return strequal(parm_table
[i
].def
.svalue
,
2031 return parm_table
[i
].def
.bvalue
==
2037 return parm_table
[i
].def
.ivalue
==
2044 *Display the contents of the global structure.
2047 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2051 struct param_opt
*data
;
2053 fprintf(f
, "# Global parameters\n[global]\n");
2055 for (i
= 0; parm_table
[i
].label
; i
++)
2056 if (parm_table
[i
].pclass
== P_GLOBAL
&&
2057 parm_table
[i
].offset
!= -1 &&
2058 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2059 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2061 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2062 print_parameter(&parm_table
[i
], lp_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2065 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2066 for (data
= lp_ctx
->globals
->param_opt
; data
;
2067 data
= data
->next
) {
2068 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2075 * Display the contents of a single services record.
2078 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
)
2081 struct param_opt
*data
;
2083 if (pService
!= sDefault
)
2084 fprintf(f
, "\n[%s]\n", pService
->szService
);
2086 for (i
= 0; parm_table
[i
].label
; i
++) {
2087 if (parm_table
[i
].pclass
== P_LOCAL
&&
2088 parm_table
[i
].offset
!= -1 &&
2089 (*parm_table
[i
].label
!= '-') &&
2090 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
2092 if (pService
== sDefault
) {
2093 if (defaults_saved
&& is_default(sDefault
, i
))
2096 if (equal_parameter(parm_table
[i
].type
,
2097 ((char *)pService
) +
2098 parm_table
[i
].offset
,
2099 ((char *)sDefault
) +
2100 parm_table
[i
].offset
))
2104 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2105 print_parameter(&parm_table
[i
],
2106 ((char *)pService
) + parm_table
[i
].offset
, f
);
2110 if (pService
->param_opt
!= NULL
) {
2111 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2112 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2117 bool lp_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2118 struct loadparm_service
*service
,
2119 const char *parm_name
, FILE * f
)
2121 struct parm_struct
*parm
;
2124 parm
= lp_parm_struct(parm_name
);
2129 ptr
= lp_parm_ptr(lp_ctx
, service
,parm
);
2131 print_parameter(parm
, ptr
, f
);
2137 * Return info about the next parameter in a service.
2138 * snum==-1 gives the globals.
2139 * Return NULL when out of parameters.
2142 struct parm_struct
*lp_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
2146 /* do the globals */
2147 for (; parm_table
[*i
].label
; (*i
)++) {
2148 if (parm_table
[*i
].offset
== -1
2149 || (*parm_table
[*i
].label
== '-'))
2153 && (parm_table
[*i
].offset
==
2154 parm_table
[(*i
) - 1].offset
))
2157 return &parm_table
[(*i
)++];
2160 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
2162 for (; parm_table
[*i
].label
; (*i
)++) {
2163 if (parm_table
[*i
].pclass
== P_LOCAL
&&
2164 parm_table
[*i
].offset
!= -1 &&
2165 (*parm_table
[*i
].label
!= '-') &&
2167 (parm_table
[*i
].offset
!=
2168 parm_table
[(*i
) - 1].offset
)))
2170 if (allparameters
||
2171 !equal_parameter(parm_table
[*i
].type
,
2172 ((char *)pService
) +
2173 parm_table
[*i
].offset
,
2174 ((char *)lp_ctx
->sDefault
) +
2175 parm_table
[*i
].offset
))
2177 return &parm_table
[(*i
)++];
2188 * Auto-load some home services.
2190 static void lp_add_auto_services(struct loadparm_context
*lp_ctx
,
2198 * Unload unused services.
2201 void lp_killunused(struct loadparm_context
*lp_ctx
,
2202 struct smbsrv_connection
*smb
,
2203 bool (*snumused
) (struct smbsrv_connection
*, int))
2206 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2207 if (lp_ctx
->services
[i
] == NULL
)
2210 if (!snumused
|| !snumused(smb
, i
)) {
2211 talloc_free(lp_ctx
->services
[i
]);
2212 lp_ctx
->services
[i
] = NULL
;
2218 static int lp_destructor(struct loadparm_context
*lp_ctx
)
2220 struct param_opt
*data
;
2222 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2223 struct param_opt
*next
;
2224 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2226 if (data
->priority
& FLAG_CMDLINE
) continue;
2227 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2236 * Initialise the global parameter structure.
2238 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2242 struct loadparm_context
*lp_ctx
;
2244 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2248 talloc_set_destructor(lp_ctx
, lp_destructor
);
2249 lp_ctx
->bInGlobalSection
= true;
2250 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2251 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2253 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2254 lp_ctx
->sDefault
->bAvailable
= true;
2255 lp_ctx
->sDefault
->bBrowseable
= true;
2256 lp_ctx
->sDefault
->bRead_only
= true;
2257 lp_ctx
->sDefault
->bMap_archive
= true;
2258 lp_ctx
->sDefault
->bStrictLocking
= true;
2259 lp_ctx
->sDefault
->bOplocks
= true;
2260 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2261 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2262 lp_ctx
->sDefault
->iDir_mask
= 0755;
2263 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2265 DEBUG(3, ("Initialising global parameters\n"));
2267 for (i
= 0; parm_table
[i
].label
; i
++) {
2268 if ((parm_table
[i
].type
== P_STRING
||
2269 parm_table
[i
].type
== P_USTRING
) &&
2270 parm_table
[i
].offset
!= -1 &&
2271 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2273 if (parm_table
[i
].pclass
== P_LOCAL
) {
2274 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2276 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2278 *r
= talloc_strdup(lp_ctx
, "");
2282 lp_do_global_parameter(lp_ctx
, "share backend", "classic");
2284 lp_do_global_parameter(lp_ctx
, "server role", "standalone");
2286 /* options that can be set on the command line must be initialised via
2287 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2289 lp_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2291 lp_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2292 myname
= get_myname(lp_ctx
);
2293 lp_do_global_parameter(lp_ctx
, "netbios name", myname
);
2294 talloc_free(myname
);
2295 lp_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2297 lp_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2299 lp_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2300 lp_do_global_parameter(lp_ctx
, "max connections", "-1");
2302 lp_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser");
2303 lp_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd");
2304 lp_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
2305 lp_do_global_parameter(lp_ctx
, "auth methods:domain controller", "anonymous sam_ignoredomain");
2306 lp_do_global_parameter(lp_ctx
, "auth methods:member server", "anonymous sam winbind");
2307 lp_do_global_parameter(lp_ctx
, "auth methods:standalone", "anonymous sam_ignoredomain");
2308 lp_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2309 lp_do_global_parameter(lp_ctx
, "sam database", "sam.ldb");
2310 lp_do_global_parameter(lp_ctx
, "idmap database", "idmap.ldb");
2311 lp_do_global_parameter(lp_ctx
, "secrets database", "secrets.ldb");
2312 lp_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
2313 lp_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
2314 lp_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
2315 lp_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2317 /* This hive should be dynamically generated by Samba using
2318 data from the sam, but for the moment leave it in a tdb to
2319 keep regedt32 from popping up an annoying dialog. */
2320 lp_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2322 /* using UTF8 by default allows us to support all chars */
2323 lp_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2325 /* Use codepage 850 as a default for the dos character set */
2326 lp_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2329 * Allow the default PASSWD_CHAT to be overridden in local.h.
2331 lp_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2333 lp_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2334 lp_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2335 lp_do_global_parameter(lp_ctx
, "modules dir", dyn_MODULESDIR
);
2336 lp_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2338 lp_do_global_parameter(lp_ctx
, "socket address", "0.0.0.0");
2339 lp_do_global_parameter_var(lp_ctx
, "server string",
2340 "Samba %s", SAMBA_VERSION_STRING
);
2342 lp_do_global_parameter_var(lp_ctx
, "announce version", "%d.%d",
2343 DEFAULT_MAJOR_VERSION
,
2344 DEFAULT_MINOR_VERSION
);
2346 lp_do_global_parameter(lp_ctx
, "password server", "*");
2348 lp_do_global_parameter(lp_ctx
, "max mux", "50");
2349 lp_do_global_parameter(lp_ctx
, "max xmit", "12288");
2350 lp_do_global_parameter(lp_ctx
, "password level", "0");
2351 lp_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2352 lp_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2353 lp_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2354 lp_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2355 lp_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2356 lp_do_global_parameter(lp_ctx
, "security", "USER");
2357 lp_do_global_parameter(lp_ctx
, "paranoid server security", "True");
2358 lp_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2359 lp_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2360 lp_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2361 lp_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2362 lp_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2363 lp_do_global_parameter(lp_ctx
, "announce as", "NT SERVER");
2365 lp_do_global_parameter(lp_ctx
, "TimeServer", "False");
2366 lp_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2367 lp_do_global_parameter(lp_ctx
, "Unicode", "True");
2368 lp_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2369 lp_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2370 lp_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2371 lp_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2373 lp_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2375 lp_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2376 lp_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2378 lp_do_global_parameter(lp_ctx
, "wins support", "False");
2379 lp_do_global_parameter(lp_ctx
, "dns proxy", "True");
2381 lp_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2382 lp_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2383 lp_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2384 lp_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2385 lp_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2386 lp_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2387 lp_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
2389 lp_do_global_parameter(lp_ctx
, "client signing", "Yes");
2390 lp_do_global_parameter(lp_ctx
, "server signing", "auto");
2392 lp_do_global_parameter(lp_ctx
, "use spnego", "True");
2394 lp_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2395 lp_do_global_parameter(lp_ctx
, "nbt port", "137");
2396 lp_do_global_parameter(lp_ctx
, "dgram port", "138");
2397 lp_do_global_parameter(lp_ctx
, "cldap port", "389");
2398 lp_do_global_parameter(lp_ctx
, "krb5 port", "88");
2399 lp_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2400 lp_do_global_parameter(lp_ctx
, "web port", "901");
2401 lp_do_global_parameter(lp_ctx
, "swat directory", dyn_SWATDIR
);
2403 lp_do_global_parameter(lp_ctx
, "nt status support", "True");
2405 lp_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2406 lp_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2408 lp_do_global_parameter(lp_ctx
, "tls enabled", "True");
2409 lp_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2410 lp_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2411 lp_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2412 lp_do_global_parameter_var(lp_ctx
, "setup directory", "%s",
2415 lp_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2417 lp_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2419 for (i
= 0; parm_table
[i
].label
; i
++) {
2420 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2421 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2428 const char *lp_configfile(struct loadparm_context
*lp_ctx
)
2430 return lp_ctx
->szConfigFile
;
2433 const char *lp_default_path(void)
2435 if (getenv("SMB_CONF_PATH"))
2436 return getenv("SMB_CONF_PATH");
2438 return dyn_CONFIGFILE
;
2442 * Update the internal state of a loadparm context after settings
2445 static bool lp_update(struct loadparm_context
*lp_ctx
)
2447 lp_add_auto_services(lp_ctx
, lp_auto_services(lp_ctx
));
2449 lp_add_hidden(lp_ctx
, "IPC$", "IPC");
2450 lp_add_hidden(lp_ctx
, "ADMIN$", "DISK");
2452 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2453 lp_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2456 panic_action
= lp_ctx
->globals
->panic_action
;
2458 reload_charcnv(lp_ctx
);
2460 /* FIXME: ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx); */
2462 /* FIXME: This is a bit of a hack, but we can't use a global, since
2463 * not everything that uses lp also uses the socket library */
2464 if (lp_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2465 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2467 unsetenv("SOCKET_TESTNONBLOCK");
2470 /* FIXME: Check locale in environment for this: */
2471 if (strcmp(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)) != 0)
2472 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx
), lp_unix_charset(lp_ctx
)));
2474 d_set_iconv((smb_iconv_t
)-1);
2479 bool lp_load_default(struct loadparm_context
*lp_ctx
)
2483 path
= lp_default_path();
2485 if (!file_exist(path
)) {
2486 /* We allow the default smb.conf file to not exist,
2487 * basically the equivalent of an empty file. */
2488 return lp_update(lp_ctx
);
2491 return lp_load(lp_ctx
, path
);
2495 * Load the services array from the services file.
2497 * Return True on success, False on failure.
2499 bool lp_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2504 filename
= talloc_strdup(lp_ctx
, filename
);
2506 lp_ctx
->szConfigFile
= filename
;
2508 lp_ctx
->bInGlobalSection
= true;
2509 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2510 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2
));
2512 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2514 /* We get sections first, so have to start 'behind' to make up */
2515 lp_ctx
->currentService
= NULL
;
2516 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2518 /* finish up the last section */
2519 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2521 if (lp_ctx
->currentService
!= NULL
)
2522 bRetval
= service_ok(lp_ctx
->currentService
);
2524 bRetval
= bRetval
&& lp_update(lp_ctx
);
2530 * Return the max number of services.
2533 int lp_numservices(struct loadparm_context
*lp_ctx
)
2535 return lp_ctx
->iNumServices
;
2539 * Display the contents of the services array in human-readable form.
2542 void lp_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2548 defaults_saved
= false;
2550 dump_globals(lp_ctx
, f
, show_defaults
);
2552 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
);
2554 for (iService
= 0; iService
< maxtoprint
; iService
++)
2555 lp_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2559 * Display the contents of one service in human-readable form.
2561 void lp_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2563 if (service
!= NULL
) {
2564 if (service
->szService
[0] == '\0')
2566 dump_a_service(service
, sDefault
, f
);
2570 struct loadparm_service
*lp_servicebynum(struct loadparm_context
*lp_ctx
,
2573 return lp_ctx
->services
[snum
];
2576 struct loadparm_service
*lp_service(struct loadparm_context
*lp_ctx
,
2577 const char *service_name
)
2582 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2583 if (lp_ctx
->services
[iService
] &&
2584 lp_ctx
->services
[iService
]->szService
) {
2586 * The substitution here is used to support %U is
2589 serviceName
= standard_sub_basic(
2590 lp_ctx
->services
[iService
],
2591 lp_ctx
->services
[iService
]->szService
);
2592 if (strequal(serviceName
, service_name
))
2593 return lp_ctx
->services
[iService
];
2597 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name
));
2603 * A useful volume label function.
2605 const char *volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2607 const char *ret
= lp_volume(service
, sDefault
);
2609 return lp_servicename(service
);
2615 * If we are PDC then prefer us as DMB
2617 const char *lp_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2619 const char *ret
= _lp_printername(service
, sDefault
);
2620 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2621 ret
= lp_servicename(service
);
2628 * Return the max print jobs per queue.
2630 int lp_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2632 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2633 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2634 maxjobs
= PRINT_MAX_JOBID
- 1;
2639 struct smb_iconv_convenience
*lp_iconv_convenience(struct loadparm_context
*lp_ctx
)
2641 if (lp_ctx
== NULL
) {
2642 static struct smb_iconv_convenience
*fallback_ic
= NULL
;
2643 if (fallback_ic
== NULL
)
2644 fallback_ic
= smb_iconv_convenience_init(talloc_autofree_context(),
2645 "CP850", "UTF8", true);
2648 return lp_ctx
->iconv_convenience
;
2651 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2653 talloc_free(lp_ctx
->iconv_convenience
);
2654 global_iconv_convenience
= lp_ctx
->iconv_convenience
= smb_iconv_convenience_init_lp(lp_ctx
, lp_ctx
);
2657 void lp_smbcli_options(struct loadparm_context
*lp_ctx
,
2658 struct smbcli_options
*options
)
2660 options
->max_xmit
= lp_max_xmit(lp_ctx
);
2661 options
->max_mux
= lp_maxmux(lp_ctx
);
2662 options
->use_spnego
= lp_nt_status_support(lp_ctx
) && lp_use_spnego(lp_ctx
);
2663 options
->signing
= lp_client_signing(lp_ctx
);
2664 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
2665 options
->ntstatus_support
= lp_nt_status_support(lp_ctx
);
2666 options
->max_protocol
= lp_cli_maxprotocol(lp_ctx
);
2667 options
->unicode
= lp_unicode(lp_ctx
);
2668 options
->use_oplocks
= true;
2669 options
->use_level2_oplocks
= true;
2672 void lp_smbcli_session_options(struct loadparm_context
*lp_ctx
,
2673 struct smbcli_session_options
*options
)
2675 options
->lanman_auth
= lp_client_lanman_auth(lp_ctx
);
2676 options
->ntlmv2_auth
= lp_client_ntlmv2_auth(lp_ctx
);
2677 options
->plaintext_auth
= lp_client_plaintext_auth(lp_ctx
);
2680 _PUBLIC_
char *lp_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2682 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2685 _PUBLIC_
char *lp_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2687 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2690 _PUBLIC_
char *lp_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2692 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2695 _PUBLIC_
char *lp_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2697 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2700 _PUBLIC_
char *lp_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2702 return private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2705 _PUBLIC_
struct dcerpc_server_info
*lp_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2707 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
2709 ret
->domain_name
= talloc_reference(mem_ctx
, lp_workgroup(lp_ctx
));
2710 ret
->version_major
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
2711 ret
->version_minor
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
2712 ret
->version_build
= lp_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
2717 struct gensec_settings
*lp_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2719 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
2720 if (settings
== NULL
)
2722 SMB_ASSERT(lp_ctx
!= NULL
);
2723 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2724 settings
->iconv_convenience
= lp_iconv_convenience(lp_ctx
);
2725 settings
->target_hostname
= lp_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");