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.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"
68 #define standard_sub_basic talloc_strdup
70 static bool do_parameter(const char *, const char *, void *);
71 static bool defaults_saved = false;
74 * This structure describes global (ie., server-wide) parameters.
76 struct loadparm_global
78 enum server_role server_role;
80 const char **smb_ports;
84 char *display_charset;
97 char *szWINS_CONFIG_URL;
100 const char **jsInclude;
101 char *jsonrpcServicesDir;
102 const char **szPasswordServers;
103 char *szSocketOptions;
105 const char **szWINSservers;
106 const char **szInterfaces;
107 char *szSocketAddress;
108 char *szAnnounceVersion; /* This is initialised in init_globals */
111 const char **szNetbiosAliases;
112 char *szNetbiosScope;
113 char *szDomainOtherSIDs;
114 const char **szNameResolveOrder;
115 const char **dcerpc_ep_servers;
116 const char **server_services;
117 char *ntptr_providor;
118 char *szWinbindSeparator;
119 char *szWinbinddSocketDirectory;
120 char *szTemplateShell;
121 char *szTemplateHomedir;
122 int bWinbindSealedPipes;
123 int bIdmapTrustedOnly;
124 char *swat_directory;
142 int paranoid_server_security;
145 int announce_as; /* This is initialised in init_globals */
152 char *socket_options;
157 int bPreferredMaster;
158 int bEncryptPasswords;
160 int bObeyPamRestrictions;
165 int bBindInterfacesOnly;
167 int bNTStatusSupport;
173 int bClientPlaintextAuth;
174 int bClientLanManAuth;
175 int bClientNTLMv2Auth;
176 int client_use_spnego_principal;
182 struct param_opt *param_opt;
187 * This structure describes a single service.
189 struct loadparm_service
201 char **ntvfs_handler;
214 int iCreate_force_mode;
221 struct param_opt *param_opt;
223 char dummy[3]; /* for alignment */
227 struct loadparm_context *global_loadparm = NULL;
229 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
232 /* prototypes for the special type handlers */
233 static bool handle_include(struct loadparm_context *lp_ctx,
234 const char *pszParmValue, char **ptr);
235 static bool handle_copy(struct loadparm_context *lp_ctx,
236 const char *pszParmValue, char **ptr);
237 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
238 const char *pszParmValue, char **ptr);
239 static bool handle_logfile(struct loadparm_context *lp_ctx,
240 const char *pszParmValue, char **ptr);
242 static const struct enum_list enum_protocol[] = {
243 {PROTOCOL_SMB2, "SMB2"},
244 {PROTOCOL_NT1, "NT1"},
245 {PROTOCOL_LANMAN2, "LANMAN2"},
246 {PROTOCOL_LANMAN1, "LANMAN1"},
247 {PROTOCOL_CORE, "CORE"},
248 {PROTOCOL_COREPLUS, "COREPLUS"},
249 {PROTOCOL_COREPLUS, "CORE+"},
253 static const struct enum_list enum_security[] = {
254 {SEC_SHARE, "SHARE"},
259 static const struct enum_list enum_announce_as[] = {
260 {ANNOUNCE_AS_NT_SERVER, "NT"},
261 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
262 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
263 {ANNOUNCE_AS_WIN95, "win95"},
264 {ANNOUNCE_AS_WFW, "WfW"},
268 static const struct enum_list enum_bool_auto[] = {
279 /* Client-side offline caching policy types */
282 CSC_POLICY_DOCUMENTS=1,
283 CSC_POLICY_PROGRAMS=2,
287 static const struct enum_list enum_csc_policy[] = {
288 {CSC_POLICY_MANUAL, "manual"},
289 {CSC_POLICY_DOCUMENTS, "documents"},
290 {CSC_POLICY_PROGRAMS, "programs"},
291 {CSC_POLICY_DISABLE, "disable"},
295 /* SMB signing types. */
296 static const struct enum_list enum_smb_signing_vals[] = {
297 {SMB_SIGNING_OFF, "No"},
298 {SMB_SIGNING_OFF, "False"},
299 {SMB_SIGNING_OFF, "0"},
300 {SMB_SIGNING_OFF, "Off"},
301 {SMB_SIGNING_OFF, "disabled"},
302 {SMB_SIGNING_SUPPORTED, "Yes"},
303 {SMB_SIGNING_SUPPORTED, "True"},
304 {SMB_SIGNING_SUPPORTED, "1"},
305 {SMB_SIGNING_SUPPORTED, "On"},
306 {SMB_SIGNING_SUPPORTED, "enabled"},
307 {SMB_SIGNING_REQUIRED, "required"},
308 {SMB_SIGNING_REQUIRED, "mandatory"},
309 {SMB_SIGNING_REQUIRED, "force"},
310 {SMB_SIGNING_REQUIRED, "forced"},
311 {SMB_SIGNING_REQUIRED, "enforced"},
312 {SMB_SIGNING_AUTO, "auto"},
316 static const struct enum_list enum_server_role[] = {
317 {ROLE_STANDALONE, "standalone"},
318 {ROLE_DOMAIN_MEMBER, "member server"},
319 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
324 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
325 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
327 static struct parm_struct parm_table[] = {
328 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
330 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
331 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
332 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
333 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
334 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
335 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
336 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
337 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
338 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), NULL, NULL},
339 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
340 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
341 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
342 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
343 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
344 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
345 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
346 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
347 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
348 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
350 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
351 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
352 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
353 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
354 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
355 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
356 {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
357 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
358 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
359 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
360 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
361 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
362 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
363 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
364 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
365 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
366 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
367 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
368 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
369 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
371 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
373 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
374 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
375 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
376 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
378 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
379 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
381 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
382 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
383 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
385 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
386 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
387 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
388 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
389 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
390 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
391 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
392 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
393 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
394 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
395 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
396 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
397 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
398 {"swat directory", P_STRING, P_GLOBAL, GLOBAL_VAR(swat_directory), NULL, NULL},
399 {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
400 {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
401 {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
402 {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
403 {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
404 {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
405 {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
406 {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
407 {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
409 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
411 {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
412 {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
413 {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
414 {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
416 {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
417 {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
418 {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
419 {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
420 {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
421 {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
422 {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals},
423 {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals},
424 {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
426 {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
427 {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
428 {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
430 {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
431 {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL},
433 {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
434 {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
435 {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
437 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
438 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
440 {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
441 {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
442 {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
444 {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
445 {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
446 {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
447 {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
448 {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
450 {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
451 {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
452 {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
453 {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL},
455 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
457 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
459 {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
460 {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
461 {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
462 {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
463 {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
464 {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
465 {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL},
466 {"js include", P_LIST, P_GLOBAL, GLOBAL_VAR(jsInclude), NULL, NULL},
467 {"setup directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szSetupDir), NULL, NULL},
469 {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
470 {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
471 {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
473 {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
474 {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
475 {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
477 {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
479 {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
480 {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
481 {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
482 {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
483 {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
484 {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
485 {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
486 {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
488 {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
492 /* local variables */
493 struct loadparm_context {
494 const char *szConfigFile;
495 struct loadparm_global *globals;
496 struct loadparm_service **services;
497 struct loadparm_service *sDefault;
499 struct loadparm_service *currentService;
500 bool bInGlobalSection;
502 struct file_lists *next;
507 unsigned int flags[NUMPARAMETERS];
508 struct smb_iconv_convenience *iconv_convenience;
512 struct loadparm_service *lp_default_service(struct loadparm_context *lp_ctx)
514 return lp_ctx->sDefault;
518 return the parameter table
520 struct parm_struct *lp_parm_table(void)
526 * Convenience routine to grab string parameters into temporary memory
527 * and run standard_sub_basic on them.
529 * The buffers can be written to by
530 * callers without affecting the source string.
533 static const char *lp_string(const char *s)
535 #if 0 /* until REWRITE done to make thread-safe */
536 size_t len = s ? strlen(s) : 0;
540 /* The follow debug is useful for tracking down memory problems
541 especially if you have an inner loop that is calling a lp_*()
542 function that returns a string. Perhaps this debug should be
543 present all the time? */
546 DEBUG(10, ("lp_string(%s)\n", s));
549 #if 0 /* until REWRITE done to make thread-safe */
551 lp_talloc = talloc_init("lp_talloc");
553 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
561 strlcpy(ret, s, len);
563 if (trim_string(ret, "\"", "\"")) {
564 if (strchr(ret,'"') != NULL)
565 strlcpy(ret, s, len);
568 standard_sub_basic(ret,len+100);
575 In this section all the functions that are used to access the
576 parameters from the rest of the program are defined
579 #define FN_GLOBAL_STRING(fn_name,var_name) \
580 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) : "";}
581 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
582 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 : "";}
583 #define FN_GLOBAL_LIST(fn_name,var_name) \
584 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
585 #define FN_GLOBAL_BOOL(fn_name,var_name) \
586 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
588 #define FN_GLOBAL_CHAR(fn_name,ptr) \
589 char fn_name(void) {return(*(char *)(ptr));}
591 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
592 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
594 #define FN_LOCAL_STRING(fn_name,val) \
595 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)));}
596 #define FN_LOCAL_LIST(fn_name,val) \
597 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
598 #define FN_LOCAL_BOOL(fn_name,val) \
599 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
600 #define FN_LOCAL_INTEGER(fn_name,val) \
601 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
603 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, server_role)
604 _PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, smb_ports)
605 _PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, nbt_port)
606 _PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, dgram_port)
607 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, cldap_port)
608 _PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, krb5_port)
609 _PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, kpasswd_port)
610 _PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, web_port)
611 _PUBLIC_ FN_GLOBAL_STRING(lp_swat_directory, swat_directory)
612 _PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, tls_enabled)
613 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_keyfile, tls_keyfile)
614 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_certfile, tls_certfile)
615 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, tls_cafile)
616 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, tls_crlfile)
617 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_dhpfile, tls_dhpfile)
618 _PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
619 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
620 _PUBLIC_ FN_GLOBAL_STRING(lp_idmap_url, szIDMAP_URL)
621 _PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
622 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
623 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
624 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
625 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
626 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
627 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
628 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
629 _PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
630 _PUBLIC_ FN_GLOBAL_BOOL(lp_idmap_trusted_only, bIdmapTrustedOnly)
631 _PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
632 _PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
633 _PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
634 _PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
635 _PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
636 _PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
637 _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
638 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
639 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
640 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
641 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
642 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
643 _PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
644 _PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
645 _PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
646 _PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
647 _PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
648 _PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm)
649 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
650 _PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
651 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
652 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
653 _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
654 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
655 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
656 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
658 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
659 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
660 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
661 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
662 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
663 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
664 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
665 _PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
666 _PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
667 _PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
668 _PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
669 _PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
670 _PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
671 _PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
672 _PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
673 _PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
674 _PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
675 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
676 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
677 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
678 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
679 _PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
680 _PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
681 _PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
682 _PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
683 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
684 _PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
685 _PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
686 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
687 _PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
688 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
689 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
690 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
691 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
692 _PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
693 _PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
694 _PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
695 _PUBLIC_ FN_GLOBAL_LIST(lp_js_include, jsInclude)
696 const char *lp_servicename(const struct loadparm_service *service)
698 return lp_string((const char *)service->szService);
701 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
702 static FN_LOCAL_STRING(_lp_printername, szPrintername)
703 _PUBLIC_ FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
704 _PUBLIC_ FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
705 _PUBLIC_ FN_LOCAL_STRING(lp_comment, comment)
706 _PUBLIC_ FN_LOCAL_STRING(lp_fstype, fstype)
707 static FN_LOCAL_STRING(lp_volume, volume)
708 _PUBLIC_ FN_LOCAL_LIST(lp_ntvfs_handler, ntvfs_handler)
709 _PUBLIC_ FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
710 _PUBLIC_ FN_LOCAL_BOOL(lp_browseable, bBrowseable)
711 _PUBLIC_ FN_LOCAL_BOOL(lp_readonly, bRead_only)
712 _PUBLIC_ FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
713 _PUBLIC_ FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
714 _PUBLIC_ FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
715 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
716 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
717 _PUBLIC_ FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
718 _PUBLIC_ FN_LOCAL_BOOL(lp_map_system, bMap_system)
719 _PUBLIC_ FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
720 _PUBLIC_ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
721 _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
722 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
723 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
724 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
725 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
726 _PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
728 /* local prototypes */
729 static int map_parameter(const char *pszParmName);
730 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
731 const char *pszServiceName);
732 static void copy_service(struct loadparm_service *pserviceDest,
733 struct loadparm_service *pserviceSource,
735 static bool service_ok(struct loadparm_service *service);
736 static bool do_section(const char *pszSectionName, void *);
737 static void init_copymap(struct loadparm_service *pservice);
739 /* This is a helper function for parametrical options support. */
740 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
741 /* Actual parametrical functions are quite simple */
742 const char *lp_get_parametric(struct loadparm_context *lp_ctx,
743 struct loadparm_service *service,
744 const char *type, const char *option)
747 struct param_opt *data;
752 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
754 asprintf(&vfskey, "%s:%s", type, option);
758 if (strcmp(data->key, vfskey) == 0) {
765 if (service != NULL) {
766 /* Try to fetch the same option but from globals */
767 /* but only if we are not already working with globals */
768 for (data = lp_ctx->globals->param_opt; data;
770 if (strcmp(data->key, vfskey) == 0) {
784 * convenience routine to return int parameters.
786 static int lp_int(const char *s)
790 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
794 return strtol(s, NULL, 0);
798 * convenience routine to return unsigned long parameters.
800 static int lp_ulong(const char *s)
804 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
808 return strtoul(s, NULL, 0);
812 * convenience routine to return unsigned long parameters.
814 static double lp_double(const char *s)
818 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
822 return strtod(s, NULL);
826 * convenience routine to return boolean parameters.
828 static bool lp_bool(const char *s)
833 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
837 if (!set_boolean(s, &ret)) {
838 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
847 * Return parametric option from a given service. Type is a part of option before ':'
848 * Parametric option has following syntax: 'Type: option = value'
849 * Returned value is allocated in 'lp_talloc' context
852 const char *lp_parm_string(struct loadparm_context *lp_ctx,
853 struct loadparm_service *service, const char *type,
856 const char *value = lp_get_parametric(lp_ctx, service, type, option);
859 return lp_string(value);
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_list(TALLOC_CTX *mem_ctx,
871 struct loadparm_context *lp_ctx,
872 struct loadparm_service *service,
874 const char *option, const char *separator)
876 const char *value = lp_get_parametric(lp_ctx, service, type, option);
879 return str_list_make(mem_ctx, value, separator);
885 * Return parametric option from a given service. Type is a part of option before ':'
886 * Parametric option has following syntax: 'Type: option = value'
889 int lp_parm_int(struct loadparm_context *lp_ctx,
890 struct loadparm_service *service, const char *type,
891 const char *option, int default_v)
893 const char *value = lp_get_parametric(lp_ctx, service, type, option);
896 return lp_int(value);
902 * Return parametric option from a given service. Type is a part of
904 * Parametric option has following syntax: 'Type: option = value'.
907 int lp_parm_bytes(struct loadparm_context *lp_ctx,
908 struct loadparm_service *service, const char *type,
909 const char *option, int default_v)
913 const char *value = lp_get_parametric(lp_ctx, service, type, option);
915 if (value && conv_str_size(value, &bval)) {
916 if (bval <= INT_MAX) {
925 * Return parametric option from a given service.
926 * Type is a part of option before ':'
927 * Parametric option has following syntax: 'Type: option = value'
929 unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,
930 struct loadparm_service *service, const char *type,
931 const char *option, unsigned long default_v)
933 const char *value = lp_get_parametric(lp_ctx, service, type, option);
936 return lp_ulong(value);
942 double lp_parm_double(struct loadparm_context *lp_ctx,
943 struct loadparm_service *service, const char *type,
944 const char *option, double default_v)
946 const char *value = lp_get_parametric(lp_ctx, service, type, option);
949 return lp_double(value);
955 * Return parametric option from a given service. Type is a part of option before ':'
956 * Parametric option has following syntax: 'Type: option = value'
959 bool lp_parm_bool(struct loadparm_context *lp_ctx,
960 struct loadparm_service *service, const char *type,
961 const char *option, bool default_v)
963 const char *value = lp_get_parametric(lp_ctx, service, type, option);
966 return lp_bool(value);
973 * Initialise a service to the defaults.
976 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
978 struct loadparm_service *pservice =
979 talloc_zero(mem_ctx, struct loadparm_service);
980 copy_service(pservice, sDefault, NULL);
985 * Set a string value, deallocating any existing space, and allocing the space
988 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
995 *dest = talloc_strdup(mem_ctx, src);
996 if ((*dest) == NULL) {
997 DEBUG(0,("Out of memory in string_init\n"));
1007 * Add a new service to the services array initialising it with the given
1011 struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
1012 const struct loadparm_service *pservice,
1016 struct loadparm_service tservice;
1017 int num_to_alloc = lp_ctx->iNumServices + 1;
1018 struct param_opt *data, *pdata;
1020 tservice = *pservice;
1022 /* it might already exist */
1024 struct loadparm_service *service = getservicebyname(lp_ctx,
1026 if (service != NULL) {
1027 /* Clean all parametric options for service */
1028 /* They will be added during parsing again */
1029 data = service->param_opt;
1035 service->param_opt = NULL;
1040 /* find an invalid one */
1041 for (i = 0; i < lp_ctx->iNumServices; i++)
1042 if (lp_ctx->services[i] == NULL)
1045 /* if not, then create one */
1046 if (i == lp_ctx->iNumServices) {
1047 struct loadparm_service **tsp;
1049 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1052 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1055 lp_ctx->services = tsp;
1056 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1059 lp_ctx->iNumServices++;
1062 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1063 if (lp_ctx->services[i] == NULL) {
1064 DEBUG(0,("lp_add_service: out of memory!\n"));
1067 copy_service(lp_ctx->services[i], &tservice, NULL);
1069 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1070 return lp_ctx->services[i];
1074 * Add a new home service, with the specified home directory, defaults coming
1075 * from service ifrom.
1078 bool lp_add_home(struct loadparm_context *lp_ctx,
1079 const char *pszHomename,
1080 struct loadparm_service *default_service,
1081 const char *user, const char *pszHomedir)
1083 struct loadparm_service *service;
1085 service = lp_add_service(lp_ctx, default_service, pszHomename);
1087 if (service == NULL)
1090 if (!(*(default_service->szPath))
1091 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1092 service->szPath = talloc_strdup(service, pszHomedir);
1094 service->szPath = string_sub_talloc(service, lp_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1097 if (!(*(service->comment))) {
1098 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1100 service->bAvailable = default_service->bAvailable;
1101 service->bBrowseable = default_service->bBrowseable;
1103 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1104 pszHomename, user, service->szPath));
1110 * Add the IPC service.
1113 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,
1116 struct loadparm_service *service = lp_add_service(lp_ctx, lp_ctx->sDefault, name);
1118 if (service == NULL)
1121 string_set(service, &service->szPath, tmpdir());
1123 service->comment = talloc_asprintf(service, "%s Service (%s)",
1124 fstype, lp_ctx->globals->szServerString);
1125 string_set(service, &service->fstype, fstype);
1126 service->iMaxConnections = -1;
1127 service->bAvailable = true;
1128 service->bRead_only = true;
1129 service->bPrint_ok = false;
1130 service->bBrowseable = false;
1132 if (strcasecmp(fstype, "IPC") == 0) {
1133 lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
1137 DEBUG(3, ("adding hidden service %s\n", name));
1143 * Add a new printer service, with defaults coming from service iFrom.
1146 bool lp_add_printer(struct loadparm_context *lp_ctx,
1147 const char *pszPrintername,
1148 struct loadparm_service *default_service)
1150 const char *comment = "From Printcap";
1151 struct loadparm_service *service;
1152 service = lp_add_service(lp_ctx, default_service, pszPrintername);
1154 if (service == NULL)
1157 /* note that we do NOT default the availability flag to True - */
1158 /* we take it from the default service passed. This allows all */
1159 /* dynamic printers to be disabled by disabling the [printers] */
1160 /* entry (if/when the 'available' keyword is implemented!). */
1162 /* the printer name is set to the service name. */
1163 string_set(service, &service->szPrintername, pszPrintername);
1164 string_set(service, &service->comment, comment);
1165 service->bBrowseable = default_service->bBrowseable;
1166 /* Printers cannot be read_only. */
1167 service->bRead_only = false;
1168 /* Printer services must be printable. */
1169 service->bPrint_ok = true;
1171 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1177 * Map a parameter's string representation to something we can use.
1178 * Returns False if the parameter string is not recognised, else TRUE.
1181 static int map_parameter(const char *pszParmName)
1185 if (*pszParmName == '-')
1188 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1189 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1192 /* Warn only if it isn't parametric option */
1193 if (strchr(pszParmName, ':') == NULL)
1194 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1195 /* We do return 'fail' for parametric options as well because they are
1196 stored in different storage
1203 return the parameter structure for a parameter
1205 struct parm_struct *lp_parm_struct(const char *name)
1207 int parmnum = map_parameter(name);
1208 if (parmnum == -1) return NULL;
1209 return &parm_table[parmnum];
1213 return the parameter pointer for a parameter
1215 void *lp_parm_ptr(struct loadparm_context *lp_ctx,
1216 struct loadparm_service *service, struct parm_struct *parm)
1218 if (service == NULL) {
1219 if (parm->class == P_LOCAL)
1220 return ((char *)lp_ctx->sDefault)+parm->offset;
1221 else if (parm->class == P_GLOBAL)
1222 return ((char *)lp_ctx->globals)+parm->offset;
1225 return ((char *)service) + parm->offset;
1230 * Find a service by name. Otherwise works like get_service.
1233 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1234 const char *pszServiceName)
1238 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1239 if (lp_ctx->services[iService] != NULL &&
1240 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1241 return lp_ctx->services[iService];
1248 * Copy a service structure to another.
1249 * If pcopymapDest is NULL then copy all fields
1252 static void copy_service(struct loadparm_service *pserviceDest,
1253 struct loadparm_service *pserviceSource,
1257 bool bcopyall = (pcopymapDest == NULL);
1258 struct param_opt *data, *pdata, *paramo;
1261 for (i = 0; parm_table[i].label; i++)
1262 if (parm_table[i].offset != -1 && parm_table[i].class == P_LOCAL &&
1263 (bcopyall || pcopymapDest[i])) {
1265 ((char *)pserviceSource) + parm_table[i].offset;
1267 ((char *)pserviceDest) + parm_table[i].offset;
1269 switch (parm_table[i].type) {
1271 *(int *)dest_ptr = *(int *)src_ptr;
1277 *(int *)dest_ptr = *(int *)src_ptr;
1281 string_set(pserviceDest,
1287 string_set(pserviceDest,
1290 strupper(*(char **)dest_ptr);
1293 *(const char ***)dest_ptr = str_list_copy(pserviceDest,
1294 *(const char ***)src_ptr);
1302 init_copymap(pserviceDest);
1303 if (pserviceSource->copymap)
1304 memcpy((void *)pserviceDest->copymap,
1305 (void *)pserviceSource->copymap,
1306 sizeof(int) * NUMPARAMETERS);
1309 data = pserviceSource->param_opt;
1312 pdata = pserviceDest->param_opt;
1313 /* Traverse destination */
1315 /* If we already have same option, override it */
1316 if (strcmp(pdata->key, data->key) == 0) {
1317 talloc_free(pdata->value);
1318 pdata->value = talloc_reference(pdata,
1323 pdata = pdata->next;
1326 paramo = talloc(pserviceDest, struct param_opt);
1329 paramo->key = talloc_reference(paramo, data->key);
1330 paramo->value = talloc_reference(paramo, data->value);
1331 DLIST_ADD(pserviceDest->param_opt, paramo);
1338 * Check a service for consistency. Return False if the service is in any way
1339 * incomplete or faulty, else True.
1341 static bool service_ok(struct loadparm_service *service)
1346 if (service->szService[0] == '\0') {
1347 DEBUG(0, ("The following message indicates an internal error:\n"));
1348 DEBUG(0, ("No service name in service entry.\n"));
1352 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1353 /* I can't see why you'd want a non-printable printer service... */
1354 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1355 if (!service->bPrint_ok) {
1356 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1357 service->szService));
1358 service->bPrint_ok = true;
1360 /* [printers] service must also be non-browsable. */
1361 if (service->bBrowseable)
1362 service->bBrowseable = false;
1365 /* If a service is flagged unavailable, log the fact at level 0. */
1366 if (!service->bAvailable)
1367 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1368 service->szService));
1374 /*******************************************************************
1375 Keep a linked list of all config files so we know when one has changed
1376 it's date and needs to be reloaded.
1377 ********************************************************************/
1379 static void add_to_file_list(struct loadparm_context *lp_ctx,
1380 const char *fname, const char *subfname)
1382 struct file_lists *f = lp_ctx->file_lists;
1385 if (f->name && !strcmp(f->name, fname))
1391 f = talloc(lp_ctx, struct file_lists);
1394 f->next = lp_ctx->file_lists;
1395 f->name = talloc_strdup(f, fname);
1400 f->subfname = talloc_strdup(f, subfname);
1405 lp_ctx->file_lists = f;
1406 f->modtime = file_modtime(subfname);
1408 time_t t = file_modtime(subfname);
1414 /*******************************************************************
1415 Check if a config file has changed date.
1416 ********************************************************************/
1417 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1419 struct file_lists *f;
1420 DEBUG(6, ("lp_file_list_changed()\n"));
1422 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1426 n2 = standard_sub_basic(lp_ctx, f->name);
1428 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1429 f->name, n2, ctime(&f->modtime)));
1431 mod_time = file_modtime(n2);
1433 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1434 DEBUGADD(6, ("file %s modified: %s\n", n2,
1436 f->modtime = mod_time;
1437 talloc_free(f->subfname);
1438 f->subfname = talloc_strdup(f, n2);
1445 /***************************************************************************
1446 Handle the include operation.
1447 ***************************************************************************/
1449 static bool handle_include(struct loadparm_context *lp_ctx,
1450 const char *pszParmValue, char **ptr)
1452 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1454 add_to_file_list(lp_ctx, pszParmValue, fname);
1456 string_set(lp_ctx, ptr, fname);
1458 if (file_exist(fname))
1459 return pm_process(fname, do_section, do_parameter, lp_ctx);
1461 DEBUG(2, ("Can't find include file %s\n", fname));
1466 /***************************************************************************
1467 Handle the interpretation of the copy parameter.
1468 ***************************************************************************/
1470 static bool handle_copy(struct loadparm_context *lp_ctx,
1471 const char *pszParmValue, char **ptr)
1474 struct loadparm_service *serviceTemp;
1476 string_set(lp_ctx, ptr, pszParmValue);
1480 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1482 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1483 if (serviceTemp == lp_ctx->currentService) {
1484 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1486 copy_service(lp_ctx->currentService,
1488 lp_ctx->currentService->copymap);
1492 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1500 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1501 const char *pszParmValue, char **ptr)
1503 DEBUGLEVEL = atoi(pszParmValue);
1508 static bool handle_logfile(struct loadparm_context *lp_ctx,
1509 const char *pszParmValue, char **ptr)
1511 logfile = pszParmValue;
1515 /***************************************************************************
1516 Initialise a copymap.
1517 ***************************************************************************/
1519 static void init_copymap(struct loadparm_service *pservice)
1522 talloc_free(pservice->copymap);
1523 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1524 if (pservice->copymap == NULL) {
1526 ("Couldn't allocate copymap!! (size %d)\n",
1527 (int)NUMPARAMETERS));
1530 for (i = 0; i < NUMPARAMETERS; i++)
1531 pservice->copymap[i] = true;
1535 * Process a parametric option
1537 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1538 struct loadparm_service *service,
1539 const char *pszParmName,
1540 const char *pszParmValue, int flags)
1542 struct param_opt *paramo, *data;
1544 TALLOC_CTX *mem_ctx;
1546 while (isspace((unsigned char)*pszParmName)) {
1550 name = strdup(pszParmName);
1551 if (!name) return false;
1555 if (service == NULL) {
1556 data = lp_ctx->globals->param_opt;
1557 mem_ctx = lp_ctx->globals;
1559 data = service->param_opt;
1563 /* Traverse destination */
1564 for (paramo=data; paramo; paramo=paramo->next) {
1565 /* If we already have the option set, override it unless
1566 it was a command line option and the new one isn't */
1567 if (strcmp(paramo->key, name) == 0) {
1568 if ((paramo->flags & FLAG_CMDLINE) &&
1569 !(flags & FLAG_CMDLINE)) {
1573 talloc_free(paramo->value);
1574 paramo->value = talloc_strdup(paramo, pszParmValue);
1575 paramo->flags = flags;
1581 paramo = talloc(mem_ctx, struct param_opt);
1584 paramo->key = talloc_strdup(paramo, name);
1585 paramo->value = talloc_strdup(paramo, pszParmValue);
1586 paramo->flags = flags;
1587 if (service == NULL) {
1588 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1590 DLIST_ADD(service->param_opt, paramo);
1598 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1599 const char *pszParmName, const char *pszParmValue,
1600 struct loadparm_context *lp_ctx)
1603 /* if it is a special case then go ahead */
1604 if (parm_table[parmnum].special) {
1605 parm_table[parmnum].special(lp_ctx, pszParmValue,
1610 /* now switch on the type of variable it is */
1611 switch (parm_table[parmnum].type)
1615 if (!set_boolean(pszParmValue, &b)) {
1616 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1619 *(int *)parm_ptr = b;
1624 *(int *)parm_ptr = atoi(pszParmValue);
1628 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1634 if (conv_str_size(pszParmValue, &val)) {
1635 if (val <= INT_MAX) {
1636 *(int *)parm_ptr = (int)val;
1641 DEBUG(0,("lp_do_parameter(%s): value is not "
1642 "a valid size specifier!\n", pszParmValue));
1647 *(const char ***)parm_ptr = str_list_make(mem_ctx,
1648 pszParmValue, NULL);
1652 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1656 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1657 strupper(*(char **)parm_ptr);
1661 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1664 parm_table[parmnum].enum_list[i].name)) {
1666 parm_table[parmnum].
1671 if (!parm_table[parmnum].enum_list[i].name) {
1672 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1673 pszParmValue, pszParmName));
1679 if (lp_ctx->flags[parmnum] & FLAG_DEFAULT) {
1680 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1681 /* we have to also unset FLAG_DEFAULT on aliases */
1682 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1683 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1685 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1686 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1693 bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
1694 const char *pszParmName, const char *pszParmValue)
1696 int parmnum = map_parameter(pszParmName);
1700 if (strchr(pszParmName, ':')) {
1701 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1703 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1707 /* if the flag has been set on the command line, then don't allow override,
1708 but don't report an error */
1709 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1713 parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1715 return set_variable(lp_ctx, parmnum, parm_ptr,
1716 pszParmName, pszParmValue, lp_ctx);
1719 bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
1720 struct loadparm_service *service,
1721 const char *pszParmName, const char *pszParmValue)
1725 int parmnum = map_parameter(pszParmName);
1728 if (strchr(pszParmName, ':')) {
1729 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1731 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1735 /* if the flag has been set on the command line, then don't allow override,
1736 but don't report an error */
1737 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1741 if (parm_table[parmnum].class == P_GLOBAL) {
1743 ("Global parameter %s found in service section!\n",
1747 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1749 if (!service->copymap)
1750 init_copymap(service);
1752 /* this handles the aliases - set the copymap for other
1753 * entries with the same data pointer */
1754 for (i = 0; parm_table[i].label; i++)
1755 if (parm_table[i].offset == parm_table[parmnum].offset &&
1756 parm_table[i].class == parm_table[parmnum].class)
1757 service->copymap[i] = false;
1759 return set_variable(service, parmnum, parm_ptr, pszParmName,
1760 pszParmValue, lp_ctx);
1764 * Process a parameter.
1767 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1770 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1772 if (lp_ctx->bInGlobalSection)
1773 return lp_do_global_parameter(lp_ctx, pszParmName,
1776 return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
1777 pszParmName, pszParmValue);
1781 variable argument do parameter
1783 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1784 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
1785 const char *pszParmName, const char *fmt, ...)
1792 s = talloc_vasprintf(NULL, fmt, ap);
1794 ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
1801 set a parameter from the commandline - this is called from command line parameter
1802 parsing code. It sets the parameter then marks the parameter as unable to be modified
1803 by smb.conf processing
1805 bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1806 const char *pszParmValue)
1808 int parmnum = map_parameter(pszParmName);
1811 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1814 if (parmnum < 0 && strchr(pszParmName, ':')) {
1815 /* set a parametric option */
1816 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1817 pszParmValue, FLAG_CMDLINE);
1821 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1825 /* reset the CMDLINE flag in case this has been called before */
1826 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1828 if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1832 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1834 /* we have to also set FLAG_CMDLINE on aliases */
1835 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1836 lp_ctx->flags[i] |= FLAG_CMDLINE;
1838 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1839 lp_ctx->flags[i] |= FLAG_CMDLINE;
1846 set a option from the commandline in 'a=b' format. Use to support --option
1848 bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
1866 ret = lp_set_cmdline(lp_ctx, s, p+1);
1872 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1875 * Print a parameter of the specified type.
1878 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1884 for (i = 0; p->enum_list[i].name; i++) {
1885 if (*(int *)ptr == p->enum_list[i].value) {
1887 p->enum_list[i].name);
1894 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1899 fprintf(f, "%d", *(int *)ptr);
1903 fprintf(f, "0%o", *(int *)ptr);
1907 if ((char ***)ptr && *(char ***)ptr) {
1908 char **list = *(char ***)ptr;
1910 for (; *list; list++)
1911 fprintf(f, "%s%s", *list,
1912 ((*(list+1))?", ":""));
1918 if (*(char **)ptr) {
1919 fprintf(f, "%s", *(char **)ptr);
1926 * Check if two parameters are equal.
1929 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1933 return (*((int *)ptr1) == *((int *)ptr2));
1939 return (*((int *)ptr1) == *((int *)ptr2));
1942 return str_list_equal((const char **)(*(char ***)ptr1),
1943 (const char **)(*(char ***)ptr2));
1948 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1953 return (p1 == p2 || strequal(p1, p2));
1960 * Process a new section (service).
1962 * At this stage all sections are services.
1963 * Later we'll have special sections that permit server parameters to be set.
1964 * Returns True on success, False on failure.
1967 static bool do_section(const char *pszSectionName, void *userdata)
1969 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1971 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1972 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1975 /* if we've just struck a global section, note the fact. */
1976 lp_ctx->bInGlobalSection = isglobal;
1978 /* check for multiple global sections */
1979 if (lp_ctx->bInGlobalSection) {
1980 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
1984 /* if we have a current service, tidy it up before moving on */
1987 if (lp_ctx->currentService != NULL)
1988 bRetval = service_ok(lp_ctx->currentService);
1990 /* if all is still well, move to the next record in the services array */
1992 /* We put this here to avoid an odd message order if messages are */
1993 /* issued by the post-processing of a previous section. */
1994 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
1996 if ((lp_ctx->currentService = lp_add_service(lp_ctx, lp_ctx->sDefault,
1999 DEBUG(0, ("Failed to add a new service\n"));
2009 * Determine if a particular base parameter is currently set to the default value.
2012 static bool is_default(struct loadparm_service *sDefault, int i)
2014 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2015 if (!defaults_saved)
2017 switch (parm_table[i].type) {
2019 return str_list_equal((const char **)parm_table[i].def.lvalue,
2020 (const char **)def_ptr);
2023 return strequal(parm_table[i].def.svalue,
2026 return parm_table[i].def.bvalue ==
2032 return parm_table[i].def.ivalue ==
2039 *Display the contents of the global structure.
2042 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2046 struct param_opt *data;
2048 fprintf(f, "# Global parameters\n[global]\n");
2050 for (i = 0; parm_table[i].label; i++)
2051 if (parm_table[i].class == P_GLOBAL &&
2052 parm_table[i].offset != -1 &&
2053 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2054 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2056 fprintf(f, "\t%s = ", parm_table[i].label);
2057 print_parameter(&parm_table[i], lp_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2060 if (lp_ctx->globals->param_opt != NULL) {
2061 for (data = lp_ctx->globals->param_opt; data;
2062 data = data->next) {
2063 fprintf(f, "\t%s = %s\n", data->key, data->value);
2070 * Display the contents of a single services record.
2073 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f)
2076 struct param_opt *data;
2078 if (pService != sDefault)
2079 fprintf(f, "\n[%s]\n", pService->szService);
2081 for (i = 0; parm_table[i].label; i++)
2082 if (parm_table[i].class == P_LOCAL &&
2083 parm_table[i].offset != -1 &&
2084 (*parm_table[i].label != '-') &&
2085 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2086 if (pService == sDefault) {
2087 if (defaults_saved && is_default(sDefault, i))
2090 if (equal_parameter(parm_table[i].type,
2091 ((char *)pService) +
2092 parm_table[i].offset,
2093 ((char *)sDefault) +
2094 parm_table[i].offset))
2098 fprintf(f, "\t%s = ", parm_table[i].label);
2099 print_parameter(&parm_table[i],
2100 ((char *)pService) + parm_table[i].offset, f);
2103 if (pService->param_opt != NULL) {
2104 for (data = pService->param_opt; data; data = data->next) {
2105 fprintf(f, "\t%s = %s\n", data->key, data->value);
2110 bool lp_dump_a_parameter(struct loadparm_context *lp_ctx,
2111 struct loadparm_service *service,
2112 const char *parm_name, FILE * f)
2114 struct parm_struct *parm;
2117 parm = lp_parm_struct(parm_name);
2122 ptr = lp_parm_ptr(lp_ctx, service,parm);
2124 print_parameter(parm, ptr, f);
2130 * Return info about the next service in a service. snum==-1 gives the globals.
2131 * Return NULL when out of parameters.
2134 struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2138 /* do the globals */
2139 for (; parm_table[*i].label; (*i)++) {
2140 if (parm_table[*i].offset == -1
2141 || (*parm_table[*i].label == '-'))
2145 && (parm_table[*i].offset ==
2146 parm_table[(*i) - 1].offset))
2149 return &parm_table[(*i)++];
2152 struct loadparm_service *pService = lp_ctx->services[snum];
2154 for (; parm_table[*i].label; (*i)++) {
2155 if (parm_table[*i].class == P_LOCAL &&
2156 parm_table[*i].offset != -1 &&
2157 (*parm_table[*i].label != '-') &&
2159 (parm_table[*i].offset !=
2160 parm_table[(*i) - 1].offset)))
2162 if (allparameters ||
2163 !equal_parameter(parm_table[*i].type,
2164 ((char *)pService) +
2165 parm_table[*i].offset,
2166 ((char *)lp_ctx->sDefault) +
2167 parm_table[*i].offset))
2169 return &parm_table[(*i)++];
2180 * Auto-load some home services.
2182 static void lp_add_auto_services(struct loadparm_context *lp_ctx,
2190 * Unload unused services.
2193 void lp_killunused(struct loadparm_context *lp_ctx,
2194 struct smbsrv_connection *smb,
2195 bool (*snumused) (struct smbsrv_connection *, int))
2198 for (i = 0; i < lp_ctx->iNumServices; i++) {
2199 if (lp_ctx->services[i] == NULL)
2202 if (!snumused || !snumused(smb, i)) {
2203 talloc_free(lp_ctx->services[i]);
2204 lp_ctx->services[i] = NULL;
2210 static int lp_destructor(struct loadparm_context *lp_ctx)
2212 struct param_opt *data;
2214 if (lp_ctx->globals->param_opt != NULL) {
2215 struct param_opt *next;
2216 for (data = lp_ctx->globals->param_opt; data; data=next) {
2218 if (data->flags & FLAG_CMDLINE) continue;
2219 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2228 * Initialise the global parameter structure.
2230 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2234 struct loadparm_context *lp_ctx;
2236 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2240 talloc_set_destructor(lp_ctx, lp_destructor);
2241 lp_ctx->bInGlobalSection = true;
2242 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2243 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2245 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2246 lp_ctx->sDefault->bAvailable = true;
2247 lp_ctx->sDefault->bBrowseable = true;
2248 lp_ctx->sDefault->bRead_only = true;
2249 lp_ctx->sDefault->bMap_archive = true;
2250 lp_ctx->sDefault->bStrictLocking = true;
2251 lp_ctx->sDefault->iCreate_mask = 0744;
2252 lp_ctx->sDefault->iCreate_force_mode = 0000;
2253 lp_ctx->sDefault->iDir_mask = 0755;
2254 lp_ctx->sDefault->iDir_force_mode = 0000;
2256 DEBUG(3, ("Initialising global parameters\n"));
2258 for (i = 0; parm_table[i].label; i++) {
2259 if ((parm_table[i].type == P_STRING ||
2260 parm_table[i].type == P_USTRING) &&
2261 parm_table[i].offset != -1 &&
2262 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2264 if (parm_table[i].class == P_LOCAL) {
2265 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2267 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2269 *r = talloc_strdup(lp_ctx, "");
2273 lp_do_global_parameter(lp_ctx, "share backend", "classic");
2275 lp_do_global_parameter(lp_ctx, "server role", "standalone");
2277 /* options that can be set on the command line must be initialised via
2278 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2280 lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2282 lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2283 myname = get_myname();
2284 lp_do_global_parameter(lp_ctx, "netbios name", myname);
2286 lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2288 lp_do_global_parameter(lp_ctx, "fstype", FSTYPE_STRING);
2289 lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2290 lp_do_global_parameter(lp_ctx, "max connections", "-1");
2292 lp_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo");
2293 lp_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap web kdc drepl winbind");
2294 lp_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2295 lp_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain");
2296 lp_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2297 lp_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2298 lp_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2299 lp_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
2300 lp_do_global_parameter(lp_ctx, "idmap database", "idmap.ldb");
2301 lp_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
2302 lp_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2303 lp_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2304 lp_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2305 lp_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2307 /* This hive should be dynamically generated by Samba using
2308 data from the sam, but for the moment leave it in a tdb to
2309 keep regedt32 from popping up an annoying dialog. */
2310 lp_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2312 /* using UTF8 by default allows us to support all chars */
2313 lp_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2315 /* Use codepage 850 as a default for the dos character set */
2316 lp_do_global_parameter(lp_ctx, "dos charset", "CP850");
2319 * Allow the default PASSWD_CHAT to be overridden in local.h.
2321 lp_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2323 lp_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2324 lp_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2325 lp_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2326 lp_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2328 lp_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
2329 lp_do_global_parameter_var(lp_ctx, "server string",
2330 "Samba %s", SAMBA_VERSION_STRING);
2332 lp_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2333 DEFAULT_MAJOR_VERSION,
2334 DEFAULT_MINOR_VERSION);
2336 lp_do_global_parameter(lp_ctx, "password server", "*");
2338 lp_do_global_parameter(lp_ctx, "max mux", "50");
2339 lp_do_global_parameter(lp_ctx, "max xmit", "12288");
2340 lp_do_global_parameter(lp_ctx, "password level", "0");
2341 lp_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2342 lp_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2343 lp_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2344 lp_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2345 lp_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2346 lp_do_global_parameter(lp_ctx, "security", "USER");
2347 lp_do_global_parameter(lp_ctx, "paranoid server security", "True");
2348 lp_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2349 lp_do_global_parameter(lp_ctx, "ReadRaw", "True");
2350 lp_do_global_parameter(lp_ctx, "WriteRaw", "True");
2351 lp_do_global_parameter(lp_ctx, "NullPasswords", "False");
2352 lp_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2353 lp_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2355 lp_do_global_parameter(lp_ctx, "TimeServer", "False");
2356 lp_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2357 lp_do_global_parameter(lp_ctx, "Unicode", "True");
2358 lp_do_global_parameter(lp_ctx, "ClientLanManAuth", "True");
2359 lp_do_global_parameter(lp_ctx, "LanmanAuth", "True");
2360 lp_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2361 lp_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2363 lp_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2365 lp_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2366 lp_do_global_parameter(lp_ctx, "LocalMaster", "True");
2368 lp_do_global_parameter(lp_ctx, "wins support", "False");
2369 lp_do_global_parameter(lp_ctx, "dns proxy", "True");
2371 lp_do_global_parameter(lp_ctx, "winbind separator", "\\");
2372 lp_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2373 lp_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2374 lp_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2375 lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2376 lp_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2378 lp_do_global_parameter(lp_ctx, "client signing", "Yes");
2379 lp_do_global_parameter(lp_ctx, "server signing", "auto");
2381 lp_do_global_parameter(lp_ctx, "use spnego", "True");
2383 lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
2384 lp_do_global_parameter(lp_ctx, "nbt port", "137");
2385 lp_do_global_parameter(lp_ctx, "dgram port", "138");
2386 lp_do_global_parameter(lp_ctx, "cldap port", "389");
2387 lp_do_global_parameter(lp_ctx, "krb5 port", "88");
2388 lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
2389 lp_do_global_parameter(lp_ctx, "web port", "901");
2390 lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
2392 lp_do_global_parameter(lp_ctx, "nt status support", "True");
2394 lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2395 lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
2397 lp_do_global_parameter(lp_ctx, "tls enabled", "True");
2398 lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2399 lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2400 lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2401 lp_do_global_parameter_var(lp_ctx, "js include", "%s", dyn_JSDIR);
2402 lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2405 lp_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2407 for (i = 0; parm_table[i].label; i++) {
2408 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2409 lp_ctx->flags[i] |= FLAG_DEFAULT;
2416 const char *lp_configfile(struct loadparm_context *lp_ctx)
2418 return lp_ctx->szConfigFile;
2421 bool lp_load_default(struct loadparm_context *lp_ctx)
2423 return lp_load(lp_ctx, dyn_CONFIGFILE);
2427 * Load the services array from the services file.
2429 * Return True on success, False on failure.
2431 bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
2436 filename = talloc_strdup(lp_ctx, filename);
2438 lp_ctx->szConfigFile = filename;
2440 lp_ctx->bInGlobalSection = true;
2441 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2442 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
2444 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2446 /* We get sections first, so have to start 'behind' to make up */
2447 lp_ctx->currentService = NULL;
2448 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2450 /* finish up the last section */
2451 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2453 if (lp_ctx->currentService != NULL)
2454 bRetval = service_ok(lp_ctx->currentService);
2456 lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
2458 lp_add_hidden(lp_ctx, "IPC$", "IPC");
2459 lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
2461 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2462 lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2465 panic_action = lp_ctx->globals->panic_action;
2467 reload_charcnv(lp_ctx);
2469 /* FIXME: Check locale in environment for this: */
2470 if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
2471 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
2473 d_set_iconv((smb_iconv_t)-1);
2479 * Return the max number of services.
2482 int lp_numservices(struct loadparm_context *lp_ctx)
2484 return lp_ctx->iNumServices;
2488 * Display the contents of the services array in human-readable form.
2491 void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2497 defaults_saved = false;
2499 dump_globals(lp_ctx, f, show_defaults);
2501 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f);
2503 for (iService = 0; iService < maxtoprint; iService++)
2504 lp_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2508 * Display the contents of one service in human-readable form.
2510 void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2512 if (service != NULL) {
2513 if (service->szService[0] == '\0')
2515 dump_a_service(service, sDefault, f);
2519 struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
2522 return lp_ctx->services[snum];
2525 struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
2526 const char *service_name)
2531 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2532 if (lp_ctx->services[iService] &&
2533 lp_ctx->services[iService]->szService) {
2535 * The substitution here is used to support %U is
2538 serviceName = standard_sub_basic(
2539 lp_ctx->services[iService],
2540 lp_ctx->services[iService]->szService);
2541 if (strequal(serviceName, service_name))
2542 return lp_ctx->services[iService];
2546 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
2552 * A useful volume label function.
2554 const char *volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2556 const char *ret = lp_volume(service, sDefault);
2558 return lp_servicename(service);
2564 * If we are PDC then prefer us as DMB
2566 const char *lp_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2568 const char *ret = _lp_printername(service, sDefault);
2569 if (ret == NULL || (ret != NULL && *ret == '\0'))
2570 ret = lp_servicename(service);
2577 * Return the max print jobs per queue.
2579 int lp_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2581 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2582 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2583 maxjobs = PRINT_MAX_JOBID - 1;
2588 struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx)
2590 if (lp_ctx == NULL) {
2591 static struct smb_iconv_convenience *fallback_ic = NULL;
2592 if (fallback_ic == NULL)
2593 fallback_ic = smb_iconv_convenience_init(talloc_autofree_context(),
2594 "CP850", "UTF8", true);
2597 return lp_ctx->iconv_convenience;
2600 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2602 talloc_free(lp_ctx->iconv_convenience);
2603 lp_ctx->iconv_convenience = smb_iconv_convenience_init_lp(lp_ctx, lp_ctx);
2606 void lp_smbcli_options(struct loadparm_context *lp_ctx,
2607 struct smbcli_options *options)
2609 options->max_xmit = lp_max_xmit(lp_ctx);
2610 options->max_mux = lp_maxmux(lp_ctx);
2611 options->use_spnego = lp_nt_status_support(lp_ctx) && lp_use_spnego(lp_ctx);
2612 options->signing = lp_client_signing(lp_ctx);
2613 options->request_timeout = SMB_REQUEST_TIMEOUT;
2614 options->ntstatus_support = lp_nt_status_support(lp_ctx);
2615 options->max_protocol = lp_cli_maxprotocol(lp_ctx);
2616 options->unicode = lp_unicode(lp_ctx);
2617 options->use_oplocks = true;
2618 options->use_level2_oplocks = true;