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 struct loadparm_context *global_loadparm = NULL;
233 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
236 /* prototypes for the special type handlers */
237 static bool handle_include(struct loadparm_context *lp_ctx,
238 const char *pszParmValue, char **ptr);
239 static bool handle_copy(struct loadparm_context *lp_ctx,
240 const char *pszParmValue, char **ptr);
241 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
242 const char *pszParmValue, char **ptr);
243 static bool handle_logfile(struct loadparm_context *lp_ctx,
244 const char *pszParmValue, char **ptr);
246 static const struct enum_list enum_protocol[] = {
247 {PROTOCOL_SMB2, "SMB2"},
248 {PROTOCOL_NT1, "NT1"},
249 {PROTOCOL_LANMAN2, "LANMAN2"},
250 {PROTOCOL_LANMAN1, "LANMAN1"},
251 {PROTOCOL_CORE, "CORE"},
252 {PROTOCOL_COREPLUS, "COREPLUS"},
253 {PROTOCOL_COREPLUS, "CORE+"},
257 static const struct enum_list enum_security[] = {
258 {SEC_SHARE, "SHARE"},
263 static const struct enum_list enum_announce_as[] = {
264 {ANNOUNCE_AS_NT_SERVER, "NT"},
265 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
266 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
267 {ANNOUNCE_AS_WIN95, "win95"},
268 {ANNOUNCE_AS_WFW, "WfW"},
272 static const struct enum_list enum_bool_auto[] = {
283 /* Client-side offline caching policy types */
286 CSC_POLICY_DOCUMENTS=1,
287 CSC_POLICY_PROGRAMS=2,
291 static const struct enum_list enum_csc_policy[] = {
292 {CSC_POLICY_MANUAL, "manual"},
293 {CSC_POLICY_DOCUMENTS, "documents"},
294 {CSC_POLICY_PROGRAMS, "programs"},
295 {CSC_POLICY_DISABLE, "disable"},
299 /* SMB signing types. */
300 static const struct enum_list enum_smb_signing_vals[] = {
301 {SMB_SIGNING_OFF, "No"},
302 {SMB_SIGNING_OFF, "False"},
303 {SMB_SIGNING_OFF, "0"},
304 {SMB_SIGNING_OFF, "Off"},
305 {SMB_SIGNING_OFF, "disabled"},
306 {SMB_SIGNING_SUPPORTED, "Yes"},
307 {SMB_SIGNING_SUPPORTED, "True"},
308 {SMB_SIGNING_SUPPORTED, "1"},
309 {SMB_SIGNING_SUPPORTED, "On"},
310 {SMB_SIGNING_SUPPORTED, "enabled"},
311 {SMB_SIGNING_REQUIRED, "required"},
312 {SMB_SIGNING_REQUIRED, "mandatory"},
313 {SMB_SIGNING_REQUIRED, "force"},
314 {SMB_SIGNING_REQUIRED, "forced"},
315 {SMB_SIGNING_REQUIRED, "enforced"},
316 {SMB_SIGNING_AUTO, "auto"},
320 static const struct enum_list enum_server_role[] = {
321 {ROLE_STANDALONE, "standalone"},
322 {ROLE_DOMAIN_MEMBER, "member server"},
323 {ROLE_DOMAIN_MEMBER, "member"},
324 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
325 {ROLE_DOMAIN_CONTROLLER, "dc"},
330 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
331 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
333 static struct parm_struct parm_table[] = {
334 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
336 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
337 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
338 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
339 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
340 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
341 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
342 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
343 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
344 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), NULL, NULL},
345 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
346 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
347 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
348 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
349 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
350 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
351 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
352 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
353 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
354 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
356 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
357 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
358 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
359 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
360 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
361 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
362 {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
363 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
364 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
365 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
366 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
367 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
368 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
369 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
370 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
371 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
372 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
373 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
374 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
375 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
377 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
379 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
380 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
381 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
382 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
384 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
385 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
387 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
388 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
389 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
391 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
392 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
393 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
394 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
395 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
396 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
397 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
398 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
399 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
400 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
401 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
402 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
403 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
404 {"swat directory", P_STRING, P_GLOBAL, GLOBAL_VAR(swat_directory), NULL, NULL},
405 {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
406 {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
407 {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
408 {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
409 {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
410 {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
411 {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
412 {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
413 {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
415 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
417 {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
418 {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
419 {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
420 {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
422 {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
423 {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
424 {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
425 {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
426 {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
427 {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
428 {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals},
429 {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals},
430 {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
432 {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
433 {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
434 {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
436 {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
437 {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL},
439 {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
440 {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
441 {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
443 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
444 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
446 {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
447 {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
448 {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
450 {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
451 {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
452 {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
453 {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
454 {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
456 {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
457 {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
458 {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
459 {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL},
461 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
463 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
464 {"oplocks", P_BOOL, P_LOCAL, LOCAL_VAR(bOplocks), NULL, NULL},
466 {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
467 {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
468 {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
469 {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
470 {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
471 {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
472 {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL},
473 {"setup directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szSetupDir), NULL, NULL},
475 {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
476 {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
477 {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
479 {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
480 {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
481 {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
483 {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
485 {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
486 {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
487 {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
488 {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
489 {"winbindd privileged socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory), NULL, NULL },
490 {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
491 {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
492 {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
493 {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
495 {"ntp signd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szNTPSignDSocketDirectory), NULL, NULL },
497 {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
501 /* local variables */
502 struct loadparm_context {
503 const char *szConfigFile;
504 struct loadparm_global *globals;
505 struct loadparm_service **services;
506 struct loadparm_service *sDefault;
508 struct loadparm_service *currentService;
509 bool bInGlobalSection;
511 struct file_lists *next;
516 unsigned int flags[NUMPARAMETERS];
517 struct smb_iconv_convenience *iconv_convenience;
521 struct loadparm_service *lp_default_service(struct loadparm_context *lp_ctx)
523 return lp_ctx->sDefault;
527 return the parameter table
529 struct parm_struct *lp_parm_table(void)
535 * Convenience routine to grab string parameters into temporary memory
536 * and run standard_sub_basic on them.
538 * The buffers can be written to by
539 * callers without affecting the source string.
542 static const char *lp_string(const char *s)
544 #if 0 /* until REWRITE done to make thread-safe */
545 size_t len = s ? strlen(s) : 0;
549 /* The follow debug is useful for tracking down memory problems
550 especially if you have an inner loop that is calling a lp_*()
551 function that returns a string. Perhaps this debug should be
552 present all the time? */
555 DEBUG(10, ("lp_string(%s)\n", s));
558 #if 0 /* until REWRITE done to make thread-safe */
560 lp_talloc = talloc_init("lp_talloc");
562 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
570 strlcpy(ret, s, len);
572 if (trim_string(ret, "\"", "\"")) {
573 if (strchr(ret,'"') != NULL)
574 strlcpy(ret, s, len);
577 standard_sub_basic(ret,len+100);
584 In this section all the functions that are used to access the
585 parameters from the rest of the program are defined
588 #define FN_GLOBAL_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_string(lp_ctx->globals->var_name) : "";}
590 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
591 const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name ? lp_ctx->globals->var_name : "";}
592 #define FN_GLOBAL_LIST(fn_name,var_name) \
593 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
594 #define FN_GLOBAL_BOOL(fn_name,var_name) \
595 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
597 #define FN_GLOBAL_CHAR(fn_name,ptr) \
598 char fn_name(void) {return(*(char *)(ptr));}
600 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
601 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
603 #define FN_LOCAL_STRING(fn_name,val) \
604 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)));}
605 #define FN_LOCAL_LIST(fn_name,val) \
606 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
607 #define FN_LOCAL_BOOL(fn_name,val) \
608 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
609 #define FN_LOCAL_INTEGER(fn_name,val) \
610 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
612 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, server_role)
613 _PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, smb_ports)
614 _PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, nbt_port)
615 _PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, dgram_port)
616 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, cldap_port)
617 _PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, krb5_port)
618 _PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, kpasswd_port)
619 _PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, web_port)
620 _PUBLIC_ FN_GLOBAL_STRING(lp_swat_directory, swat_directory)
621 _PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, tls_enabled)
622 _PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
623 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
624 _PUBLIC_ FN_GLOBAL_STRING(lp_idmap_url, szIDMAP_URL)
625 _PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
626 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
627 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
628 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
629 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
630 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
631 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
632 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
633 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
634 _PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
635 _PUBLIC_ FN_GLOBAL_BOOL(lp_idmap_trusted_only, bIdmapTrustedOnly)
636 _PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
637 _PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
638 _PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
639 _PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
640 _PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
641 _PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
642 _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
643 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
644 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
645 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
646 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
647 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
648 _PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
649 _PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
650 _PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
651 _PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
652 _PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
653 _PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm)
654 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
655 _PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
656 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
657 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
658 _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
659 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
660 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
661 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
663 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
664 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
665 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
666 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
667 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
668 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
669 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
670 _PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
671 _PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
672 _PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
673 _PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
674 _PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
675 _PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
676 _PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
677 _PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
678 _PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
679 _PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
680 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
681 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
682 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
683 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
684 _PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
685 _PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
686 _PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
687 _PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
688 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
689 _PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
690 _PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
691 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
692 _PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
693 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
694 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
695 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
696 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
697 _PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
698 _PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
699 _PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
700 const char *lp_servicename(const struct loadparm_service *service)
702 return lp_string((const char *)service->szService);
705 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
706 static FN_LOCAL_STRING(_lp_printername, szPrintername)
707 _PUBLIC_ FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
708 _PUBLIC_ FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
709 _PUBLIC_ FN_LOCAL_STRING(lp_comment, comment)
710 _PUBLIC_ FN_LOCAL_STRING(lp_fstype, fstype)
711 static FN_LOCAL_STRING(lp_volume, volume)
712 _PUBLIC_ FN_LOCAL_LIST(lp_ntvfs_handler, ntvfs_handler)
713 _PUBLIC_ FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
714 _PUBLIC_ FN_LOCAL_BOOL(lp_browseable, bBrowseable)
715 _PUBLIC_ FN_LOCAL_BOOL(lp_readonly, bRead_only)
716 _PUBLIC_ FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
717 _PUBLIC_ FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
718 _PUBLIC_ FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
719 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
720 _PUBLIC_ FN_LOCAL_BOOL(lp_oplocks, bOplocks)
721 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
722 _PUBLIC_ FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
723 _PUBLIC_ FN_LOCAL_BOOL(lp_map_system, bMap_system)
724 _PUBLIC_ FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
725 _PUBLIC_ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
726 _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
727 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
728 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
729 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
730 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
731 _PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
733 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory, szNTPSignDSocketDirectory)
735 /* local prototypes */
736 static int map_parameter(const char *pszParmName);
737 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
738 const char *pszServiceName);
739 static void copy_service(struct loadparm_service *pserviceDest,
740 struct loadparm_service *pserviceSource,
742 static bool service_ok(struct loadparm_service *service);
743 static bool do_section(const char *pszSectionName, void *);
744 static void init_copymap(struct loadparm_service *pservice);
746 /* This is a helper function for parametrical options support. */
747 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
748 /* Actual parametrical functions are quite simple */
749 const char *lp_get_parametric(struct loadparm_context *lp_ctx,
750 struct loadparm_service *service,
751 const char *type, const char *option)
754 struct param_opt *data;
759 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
761 asprintf(&vfskey, "%s:%s", type, option);
765 if (strcmp(data->key, vfskey) == 0) {
772 if (service != NULL) {
773 /* Try to fetch the same option but from globals */
774 /* but only if we are not already working with globals */
775 for (data = lp_ctx->globals->param_opt; data;
777 if (strcmp(data->key, vfskey) == 0) {
791 * convenience routine to return int parameters.
793 static int lp_int(const char *s)
797 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
801 return strtol(s, NULL, 0);
805 * convenience routine to return unsigned long parameters.
807 static int lp_ulong(const char *s)
811 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
815 return strtoul(s, NULL, 0);
819 * convenience routine to return unsigned long parameters.
821 static double lp_double(const char *s)
825 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
829 return strtod(s, NULL);
833 * convenience routine to return boolean parameters.
835 static bool lp_bool(const char *s)
840 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
844 if (!set_boolean(s, &ret)) {
845 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
854 * Return parametric option from a given service. Type is a part of option before ':'
855 * Parametric option has following syntax: 'Type: option = value'
856 * Returned value is allocated in 'lp_talloc' context
859 const char *lp_parm_string(struct loadparm_context *lp_ctx,
860 struct loadparm_service *service, const char *type,
863 const char *value = lp_get_parametric(lp_ctx, service, type, option);
866 return lp_string(value);
872 * Return parametric option from a given service. Type is a part of option before ':'
873 * Parametric option has following syntax: 'Type: option = value'
874 * Returned value is allocated in 'lp_talloc' context
877 const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,
878 struct loadparm_context *lp_ctx,
879 struct loadparm_service *service,
881 const char *option, const char *separator)
883 const char *value = lp_get_parametric(lp_ctx, service, type, option);
886 return (const char **)str_list_make(mem_ctx, value, separator);
892 * Return parametric option from a given service. Type is a part of option before ':'
893 * Parametric option has following syntax: 'Type: option = value'
896 int lp_parm_int(struct loadparm_context *lp_ctx,
897 struct loadparm_service *service, const char *type,
898 const char *option, int default_v)
900 const char *value = lp_get_parametric(lp_ctx, service, type, option);
903 return lp_int(value);
909 * Return parametric option from a given service. Type is a part of
911 * Parametric option has following syntax: 'Type: option = value'.
914 int lp_parm_bytes(struct loadparm_context *lp_ctx,
915 struct loadparm_service *service, const char *type,
916 const char *option, int default_v)
920 const char *value = lp_get_parametric(lp_ctx, service, type, option);
922 if (value && conv_str_size(value, &bval)) {
923 if (bval <= INT_MAX) {
932 * Return parametric option from a given service.
933 * Type is a part of option before ':'
934 * Parametric option has following syntax: 'Type: option = value'
936 unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,
937 struct loadparm_service *service, const char *type,
938 const char *option, unsigned long default_v)
940 const char *value = lp_get_parametric(lp_ctx, service, type, option);
943 return lp_ulong(value);
949 double lp_parm_double(struct loadparm_context *lp_ctx,
950 struct loadparm_service *service, const char *type,
951 const char *option, double default_v)
953 const char *value = lp_get_parametric(lp_ctx, service, type, option);
956 return lp_double(value);
962 * Return parametric option from a given service. Type is a part of option before ':'
963 * Parametric option has following syntax: 'Type: option = value'
966 bool lp_parm_bool(struct loadparm_context *lp_ctx,
967 struct loadparm_service *service, const char *type,
968 const char *option, bool default_v)
970 const char *value = lp_get_parametric(lp_ctx, service, type, option);
973 return lp_bool(value);
980 * Initialise a service to the defaults.
983 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
985 struct loadparm_service *pservice =
986 talloc_zero(mem_ctx, struct loadparm_service);
987 copy_service(pservice, sDefault, NULL);
992 * Set a string value, deallocating any existing space, and allocing the space
995 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1002 *dest = talloc_strdup(mem_ctx, src);
1003 if ((*dest) == NULL) {
1004 DEBUG(0,("Out of memory in string_init\n"));
1014 * Add a new service to the services array initialising it with the given
1018 struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
1019 const struct loadparm_service *pservice,
1023 struct loadparm_service tservice;
1024 int num_to_alloc = lp_ctx->iNumServices + 1;
1025 struct param_opt *data, *pdata;
1027 tservice = *pservice;
1029 /* it might already exist */
1031 struct loadparm_service *service = getservicebyname(lp_ctx,
1033 if (service != NULL) {
1034 /* Clean all parametric options for service */
1035 /* They will be added during parsing again */
1036 data = service->param_opt;
1042 service->param_opt = NULL;
1047 /* find an invalid one */
1048 for (i = 0; i < lp_ctx->iNumServices; i++)
1049 if (lp_ctx->services[i] == NULL)
1052 /* if not, then create one */
1053 if (i == lp_ctx->iNumServices) {
1054 struct loadparm_service **tsp;
1056 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1059 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1062 lp_ctx->services = tsp;
1063 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1066 lp_ctx->iNumServices++;
1069 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1070 if (lp_ctx->services[i] == NULL) {
1071 DEBUG(0,("lp_add_service: out of memory!\n"));
1074 copy_service(lp_ctx->services[i], &tservice, NULL);
1076 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1077 return lp_ctx->services[i];
1081 * Add a new home service, with the specified home directory, defaults coming
1082 * from service ifrom.
1085 bool lp_add_home(struct loadparm_context *lp_ctx,
1086 const char *pszHomename,
1087 struct loadparm_service *default_service,
1088 const char *user, const char *pszHomedir)
1090 struct loadparm_service *service;
1092 service = lp_add_service(lp_ctx, default_service, pszHomename);
1094 if (service == NULL)
1097 if (!(*(default_service->szPath))
1098 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1099 service->szPath = talloc_strdup(service, pszHomedir);
1101 service->szPath = string_sub_talloc(service, lp_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1104 if (!(*(service->comment))) {
1105 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1107 service->bAvailable = default_service->bAvailable;
1108 service->bBrowseable = default_service->bBrowseable;
1110 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1111 pszHomename, user, service->szPath));
1117 * Add the IPC service.
1120 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,
1123 struct loadparm_service *service = lp_add_service(lp_ctx, lp_ctx->sDefault, name);
1125 if (service == NULL)
1128 string_set(service, &service->szPath, tmpdir());
1130 service->comment = talloc_asprintf(service, "%s Service (%s)",
1131 fstype, lp_ctx->globals->szServerString);
1132 string_set(service, &service->fstype, fstype);
1133 service->iMaxConnections = -1;
1134 service->bAvailable = true;
1135 service->bRead_only = true;
1136 service->bPrint_ok = false;
1137 service->bBrowseable = false;
1139 if (strcasecmp(fstype, "IPC") == 0) {
1140 lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
1144 DEBUG(3, ("adding hidden service %s\n", name));
1150 * Add a new printer service, with defaults coming from service iFrom.
1153 bool lp_add_printer(struct loadparm_context *lp_ctx,
1154 const char *pszPrintername,
1155 struct loadparm_service *default_service)
1157 const char *comment = "From Printcap";
1158 struct loadparm_service *service;
1159 service = lp_add_service(lp_ctx, default_service, pszPrintername);
1161 if (service == NULL)
1164 /* note that we do NOT default the availability flag to True - */
1165 /* we take it from the default service passed. This allows all */
1166 /* dynamic printers to be disabled by disabling the [printers] */
1167 /* entry (if/when the 'available' keyword is implemented!). */
1169 /* the printer name is set to the service name. */
1170 string_set(service, &service->szPrintername, pszPrintername);
1171 string_set(service, &service->comment, comment);
1172 service->bBrowseable = default_service->bBrowseable;
1173 /* Printers cannot be read_only. */
1174 service->bRead_only = false;
1175 /* Printer services must be printable. */
1176 service->bPrint_ok = true;
1178 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1184 * Map a parameter's string representation to something we can use.
1185 * Returns False if the parameter string is not recognised, else TRUE.
1188 static int map_parameter(const char *pszParmName)
1192 if (*pszParmName == '-')
1195 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1196 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1199 /* Warn only if it isn't parametric option */
1200 if (strchr(pszParmName, ':') == NULL)
1201 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1202 /* We do return 'fail' for parametric options as well because they are
1203 stored in different storage
1210 return the parameter structure for a parameter
1212 struct parm_struct *lp_parm_struct(const char *name)
1214 int parmnum = map_parameter(name);
1215 if (parmnum == -1) return NULL;
1216 return &parm_table[parmnum];
1220 return the parameter pointer for a parameter
1222 void *lp_parm_ptr(struct loadparm_context *lp_ctx,
1223 struct loadparm_service *service, struct parm_struct *parm)
1225 if (service == NULL) {
1226 if (parm->class == P_LOCAL)
1227 return ((char *)lp_ctx->sDefault)+parm->offset;
1228 else if (parm->class == P_GLOBAL)
1229 return ((char *)lp_ctx->globals)+parm->offset;
1232 return ((char *)service) + parm->offset;
1237 * Find a service by name. Otherwise works like get_service.
1240 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1241 const char *pszServiceName)
1245 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1246 if (lp_ctx->services[iService] != NULL &&
1247 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1248 return lp_ctx->services[iService];
1255 * Copy a service structure to another.
1256 * If pcopymapDest is NULL then copy all fields
1259 static void copy_service(struct loadparm_service *pserviceDest,
1260 struct loadparm_service *pserviceSource,
1264 bool bcopyall = (pcopymapDest == NULL);
1265 struct param_opt *data, *pdata, *paramo;
1268 for (i = 0; parm_table[i].label; i++)
1269 if (parm_table[i].offset != -1 && parm_table[i].class == P_LOCAL &&
1270 (bcopyall || pcopymapDest[i])) {
1272 ((char *)pserviceSource) + parm_table[i].offset;
1274 ((char *)pserviceDest) + parm_table[i].offset;
1276 switch (parm_table[i].type) {
1278 *(int *)dest_ptr = *(int *)src_ptr;
1284 *(int *)dest_ptr = *(int *)src_ptr;
1288 string_set(pserviceDest,
1294 string_set(pserviceDest,
1297 strupper(*(char **)dest_ptr);
1300 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
1301 *(const char ***)src_ptr);
1309 init_copymap(pserviceDest);
1310 if (pserviceSource->copymap)
1311 memcpy((void *)pserviceDest->copymap,
1312 (void *)pserviceSource->copymap,
1313 sizeof(int) * NUMPARAMETERS);
1316 data = pserviceSource->param_opt;
1319 pdata = pserviceDest->param_opt;
1320 /* Traverse destination */
1322 /* If we already have same option, override it */
1323 if (strcmp(pdata->key, data->key) == 0) {
1324 talloc_free(pdata->value);
1325 pdata->value = talloc_reference(pdata,
1330 pdata = pdata->next;
1333 paramo = talloc(pserviceDest, struct param_opt);
1336 paramo->key = talloc_reference(paramo, data->key);
1337 paramo->value = talloc_reference(paramo, data->value);
1338 DLIST_ADD(pserviceDest->param_opt, paramo);
1345 * Check a service for consistency. Return False if the service is in any way
1346 * incomplete or faulty, else True.
1348 static bool service_ok(struct loadparm_service *service)
1353 if (service->szService[0] == '\0') {
1354 DEBUG(0, ("The following message indicates an internal error:\n"));
1355 DEBUG(0, ("No service name in service entry.\n"));
1359 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1360 /* I can't see why you'd want a non-printable printer service... */
1361 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1362 if (!service->bPrint_ok) {
1363 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1364 service->szService));
1365 service->bPrint_ok = true;
1367 /* [printers] service must also be non-browsable. */
1368 if (service->bBrowseable)
1369 service->bBrowseable = false;
1372 /* If a service is flagged unavailable, log the fact at level 0. */
1373 if (!service->bAvailable)
1374 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1375 service->szService));
1381 /*******************************************************************
1382 Keep a linked list of all config files so we know when one has changed
1383 it's date and needs to be reloaded.
1384 ********************************************************************/
1386 static void add_to_file_list(struct loadparm_context *lp_ctx,
1387 const char *fname, const char *subfname)
1389 struct file_lists *f = lp_ctx->file_lists;
1392 if (f->name && !strcmp(f->name, fname))
1398 f = talloc(lp_ctx, struct file_lists);
1401 f->next = lp_ctx->file_lists;
1402 f->name = talloc_strdup(f, fname);
1407 f->subfname = talloc_strdup(f, subfname);
1412 lp_ctx->file_lists = f;
1413 f->modtime = file_modtime(subfname);
1415 time_t t = file_modtime(subfname);
1421 /*******************************************************************
1422 Check if a config file has changed date.
1423 ********************************************************************/
1424 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1426 struct file_lists *f;
1427 DEBUG(6, ("lp_file_list_changed()\n"));
1429 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1433 n2 = standard_sub_basic(lp_ctx, f->name);
1435 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1436 f->name, n2, ctime(&f->modtime)));
1438 mod_time = file_modtime(n2);
1440 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1441 DEBUGADD(6, ("file %s modified: %s\n", n2,
1443 f->modtime = mod_time;
1444 talloc_free(f->subfname);
1445 f->subfname = talloc_strdup(f, n2);
1452 /***************************************************************************
1453 Handle the include operation.
1454 ***************************************************************************/
1456 static bool handle_include(struct loadparm_context *lp_ctx,
1457 const char *pszParmValue, char **ptr)
1459 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1461 add_to_file_list(lp_ctx, pszParmValue, fname);
1463 string_set(lp_ctx, ptr, fname);
1465 if (file_exist(fname))
1466 return pm_process(fname, do_section, do_parameter, lp_ctx);
1468 DEBUG(2, ("Can't find include file %s\n", fname));
1473 /***************************************************************************
1474 Handle the interpretation of the copy parameter.
1475 ***************************************************************************/
1477 static bool handle_copy(struct loadparm_context *lp_ctx,
1478 const char *pszParmValue, char **ptr)
1481 struct loadparm_service *serviceTemp;
1483 string_set(lp_ctx, ptr, pszParmValue);
1487 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1489 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1490 if (serviceTemp == lp_ctx->currentService) {
1491 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1493 copy_service(lp_ctx->currentService,
1495 lp_ctx->currentService->copymap);
1499 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1507 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1508 const char *pszParmValue, char **ptr)
1510 DEBUGLEVEL = atoi(pszParmValue);
1515 static bool handle_logfile(struct loadparm_context *lp_ctx,
1516 const char *pszParmValue, char **ptr)
1518 logfile = pszParmValue;
1522 /***************************************************************************
1523 Initialise a copymap.
1524 ***************************************************************************/
1526 static void init_copymap(struct loadparm_service *pservice)
1529 talloc_free(pservice->copymap);
1530 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1531 if (pservice->copymap == NULL) {
1533 ("Couldn't allocate copymap!! (size %d)\n",
1534 (int)NUMPARAMETERS));
1537 for (i = 0; i < NUMPARAMETERS; i++)
1538 pservice->copymap[i] = true;
1542 * Process a parametric option
1544 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1545 struct loadparm_service *service,
1546 const char *pszParmName,
1547 const char *pszParmValue, int flags)
1549 struct param_opt *paramo, *data;
1551 TALLOC_CTX *mem_ctx;
1553 while (isspace((unsigned char)*pszParmName)) {
1557 name = strdup(pszParmName);
1558 if (!name) return false;
1562 if (service == NULL) {
1563 data = lp_ctx->globals->param_opt;
1564 mem_ctx = lp_ctx->globals;
1566 data = service->param_opt;
1570 /* Traverse destination */
1571 for (paramo=data; paramo; paramo=paramo->next) {
1572 /* If we already have the option set, override it unless
1573 it was a command line option and the new one isn't */
1574 if (strcmp(paramo->key, name) == 0) {
1575 if ((paramo->priority & FLAG_CMDLINE) &&
1576 !(flags & FLAG_CMDLINE)) {
1580 talloc_free(paramo->value);
1581 paramo->value = talloc_strdup(paramo, pszParmValue);
1582 paramo->priority = flags;
1588 paramo = talloc(mem_ctx, struct param_opt);
1591 paramo->key = talloc_strdup(paramo, name);
1592 paramo->value = talloc_strdup(paramo, pszParmValue);
1593 paramo->priority = flags;
1594 if (service == NULL) {
1595 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1597 DLIST_ADD(service->param_opt, paramo);
1605 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1606 const char *pszParmName, const char *pszParmValue,
1607 struct loadparm_context *lp_ctx)
1610 /* if it is a special case then go ahead */
1611 if (parm_table[parmnum].special) {
1612 parm_table[parmnum].special(lp_ctx, pszParmValue,
1617 /* now switch on the type of variable it is */
1618 switch (parm_table[parmnum].type)
1622 if (!set_boolean(pszParmValue, &b)) {
1623 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1626 *(int *)parm_ptr = b;
1631 *(int *)parm_ptr = atoi(pszParmValue);
1635 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1641 if (conv_str_size(pszParmValue, &val)) {
1642 if (val <= INT_MAX) {
1643 *(int *)parm_ptr = (int)val;
1648 DEBUG(0,("lp_do_parameter(%s): value is not "
1649 "a valid size specifier!\n", pszParmValue));
1654 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1655 pszParmValue, NULL);
1659 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1663 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1664 strupper(*(char **)parm_ptr);
1668 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1671 parm_table[parmnum].enum_list[i].name)) {
1673 parm_table[parmnum].
1678 if (!parm_table[parmnum].enum_list[i].name) {
1679 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1680 pszParmValue, pszParmName));
1686 if (lp_ctx->flags[parmnum] & FLAG_DEFAULT) {
1687 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1688 /* we have to also unset FLAG_DEFAULT on aliases */
1689 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1690 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1692 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1693 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1700 bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
1701 const char *pszParmName, const char *pszParmValue)
1703 int parmnum = map_parameter(pszParmName);
1707 if (strchr(pszParmName, ':')) {
1708 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1710 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1714 /* if the flag has been set on the command line, then don't allow override,
1715 but don't report an error */
1716 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1720 parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1722 return set_variable(lp_ctx, parmnum, parm_ptr,
1723 pszParmName, pszParmValue, lp_ctx);
1726 bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
1727 struct loadparm_service *service,
1728 const char *pszParmName, const char *pszParmValue)
1732 int parmnum = map_parameter(pszParmName);
1735 if (strchr(pszParmName, ':')) {
1736 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1738 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1742 /* if the flag has been set on the command line, then don't allow override,
1743 but don't report an error */
1744 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1748 if (parm_table[parmnum].class == P_GLOBAL) {
1750 ("Global parameter %s found in service section!\n",
1754 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1756 if (!service->copymap)
1757 init_copymap(service);
1759 /* this handles the aliases - set the copymap for other
1760 * entries with the same data pointer */
1761 for (i = 0; parm_table[i].label; i++)
1762 if (parm_table[i].offset == parm_table[parmnum].offset &&
1763 parm_table[i].class == parm_table[parmnum].class)
1764 service->copymap[i] = false;
1766 return set_variable(service, parmnum, parm_ptr, pszParmName,
1767 pszParmValue, lp_ctx);
1771 * Process a parameter.
1774 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1777 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1779 if (lp_ctx->bInGlobalSection)
1780 return lp_do_global_parameter(lp_ctx, pszParmName,
1783 return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
1784 pszParmName, pszParmValue);
1788 variable argument do parameter
1790 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1791 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
1792 const char *pszParmName, const char *fmt, ...)
1799 s = talloc_vasprintf(NULL, fmt, ap);
1801 ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
1808 set a parameter from the commandline - this is called from command line parameter
1809 parsing code. It sets the parameter then marks the parameter as unable to be modified
1810 by smb.conf processing
1812 bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1813 const char *pszParmValue)
1815 int parmnum = map_parameter(pszParmName);
1818 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1821 if (parmnum < 0 && strchr(pszParmName, ':')) {
1822 /* set a parametric option */
1823 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1824 pszParmValue, FLAG_CMDLINE);
1828 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1832 /* reset the CMDLINE flag in case this has been called before */
1833 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1835 if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1839 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1841 /* we have to also set FLAG_CMDLINE on aliases */
1842 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1843 lp_ctx->flags[i] |= FLAG_CMDLINE;
1845 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1846 lp_ctx->flags[i] |= FLAG_CMDLINE;
1853 set a option from the commandline in 'a=b' format. Use to support --option
1855 bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
1873 ret = lp_set_cmdline(lp_ctx, s, p+1);
1879 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1882 * Print a parameter of the specified type.
1885 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1891 for (i = 0; p->enum_list[i].name; i++) {
1892 if (*(int *)ptr == p->enum_list[i].value) {
1894 p->enum_list[i].name);
1901 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1906 fprintf(f, "%d", *(int *)ptr);
1910 fprintf(f, "0%o", *(int *)ptr);
1914 if ((char ***)ptr && *(char ***)ptr) {
1915 char **list = *(char ***)ptr;
1917 for (; *list; list++)
1918 fprintf(f, "%s%s", *list,
1919 ((*(list+1))?", ":""));
1925 if (*(char **)ptr) {
1926 fprintf(f, "%s", *(char **)ptr);
1933 * Check if two parameters are equal.
1936 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1940 return (*((int *)ptr1) == *((int *)ptr2));
1946 return (*((int *)ptr1) == *((int *)ptr2));
1949 return str_list_equal((const char **)(*(char ***)ptr1),
1950 (const char **)(*(char ***)ptr2));
1955 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1960 return (p1 == p2 || strequal(p1, p2));
1967 * Process a new section (service).
1969 * At this stage all sections are services.
1970 * Later we'll have special sections that permit server parameters to be set.
1971 * Returns True on success, False on failure.
1974 static bool do_section(const char *pszSectionName, void *userdata)
1976 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1978 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1979 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1982 /* if we've just struck a global section, note the fact. */
1983 lp_ctx->bInGlobalSection = isglobal;
1985 /* check for multiple global sections */
1986 if (lp_ctx->bInGlobalSection) {
1987 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
1991 /* if we have a current service, tidy it up before moving on */
1994 if (lp_ctx->currentService != NULL)
1995 bRetval = service_ok(lp_ctx->currentService);
1997 /* if all is still well, move to the next record in the services array */
1999 /* We put this here to avoid an odd message order if messages are */
2000 /* issued by the post-processing of a previous section. */
2001 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2003 if ((lp_ctx->currentService = lp_add_service(lp_ctx, lp_ctx->sDefault,
2006 DEBUG(0, ("Failed to add a new service\n"));
2016 * Determine if a particular base parameter is currently set to the default value.
2019 static bool is_default(struct loadparm_service *sDefault, int i)
2021 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2022 if (!defaults_saved)
2024 switch (parm_table[i].type) {
2026 return str_list_equal((const char **)parm_table[i].def.lvalue,
2027 (const char **)def_ptr);
2030 return strequal(parm_table[i].def.svalue,
2033 return parm_table[i].def.bvalue ==
2039 return parm_table[i].def.ivalue ==
2046 *Display the contents of the global structure.
2049 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2053 struct param_opt *data;
2055 fprintf(f, "# Global parameters\n[global]\n");
2057 for (i = 0; parm_table[i].label; i++)
2058 if (parm_table[i].class == P_GLOBAL &&
2059 parm_table[i].offset != -1 &&
2060 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2061 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2063 fprintf(f, "\t%s = ", parm_table[i].label);
2064 print_parameter(&parm_table[i], lp_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2067 if (lp_ctx->globals->param_opt != NULL) {
2068 for (data = lp_ctx->globals->param_opt; data;
2069 data = data->next) {
2070 fprintf(f, "\t%s = %s\n", data->key, data->value);
2077 * Display the contents of a single services record.
2080 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f)
2083 struct param_opt *data;
2085 if (pService != sDefault)
2086 fprintf(f, "\n[%s]\n", pService->szService);
2088 for (i = 0; parm_table[i].label; i++)
2089 if (parm_table[i].class == P_LOCAL &&
2090 parm_table[i].offset != -1 &&
2091 (*parm_table[i].label != '-') &&
2092 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2093 if (pService == sDefault) {
2094 if (defaults_saved && is_default(sDefault, i))
2097 if (equal_parameter(parm_table[i].type,
2098 ((char *)pService) +
2099 parm_table[i].offset,
2100 ((char *)sDefault) +
2101 parm_table[i].offset))
2105 fprintf(f, "\t%s = ", parm_table[i].label);
2106 print_parameter(&parm_table[i],
2107 ((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 service in a service. snum==-1 gives the globals.
2138 * Return NULL when out of parameters.
2141 struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2145 /* do the globals */
2146 for (; parm_table[*i].label; (*i)++) {
2147 if (parm_table[*i].offset == -1
2148 || (*parm_table[*i].label == '-'))
2152 && (parm_table[*i].offset ==
2153 parm_table[(*i) - 1].offset))
2156 return &parm_table[(*i)++];
2159 struct loadparm_service *pService = lp_ctx->services[snum];
2161 for (; parm_table[*i].label; (*i)++) {
2162 if (parm_table[*i].class == P_LOCAL &&
2163 parm_table[*i].offset != -1 &&
2164 (*parm_table[*i].label != '-') &&
2166 (parm_table[*i].offset !=
2167 parm_table[(*i) - 1].offset)))
2169 if (allparameters ||
2170 !equal_parameter(parm_table[*i].type,
2171 ((char *)pService) +
2172 parm_table[*i].offset,
2173 ((char *)lp_ctx->sDefault) +
2174 parm_table[*i].offset))
2176 return &parm_table[(*i)++];
2187 * Auto-load some home services.
2189 static void lp_add_auto_services(struct loadparm_context *lp_ctx,
2197 * Unload unused services.
2200 void lp_killunused(struct loadparm_context *lp_ctx,
2201 struct smbsrv_connection *smb,
2202 bool (*snumused) (struct smbsrv_connection *, int))
2205 for (i = 0; i < lp_ctx->iNumServices; i++) {
2206 if (lp_ctx->services[i] == NULL)
2209 if (!snumused || !snumused(smb, i)) {
2210 talloc_free(lp_ctx->services[i]);
2211 lp_ctx->services[i] = NULL;
2217 static int lp_destructor(struct loadparm_context *lp_ctx)
2219 struct param_opt *data;
2221 if (lp_ctx->globals->param_opt != NULL) {
2222 struct param_opt *next;
2223 for (data = lp_ctx->globals->param_opt; data; data=next) {
2225 if (data->priority & FLAG_CMDLINE) continue;
2226 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2235 * Initialise the global parameter structure.
2237 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2241 struct loadparm_context *lp_ctx;
2243 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2247 talloc_set_destructor(lp_ctx, lp_destructor);
2248 lp_ctx->bInGlobalSection = true;
2249 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2250 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2252 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2253 lp_ctx->sDefault->bAvailable = true;
2254 lp_ctx->sDefault->bBrowseable = true;
2255 lp_ctx->sDefault->bRead_only = true;
2256 lp_ctx->sDefault->bMap_archive = true;
2257 lp_ctx->sDefault->bStrictLocking = true;
2258 lp_ctx->sDefault->bOplocks = true;
2259 lp_ctx->sDefault->iCreate_mask = 0744;
2260 lp_ctx->sDefault->iCreate_force_mode = 0000;
2261 lp_ctx->sDefault->iDir_mask = 0755;
2262 lp_ctx->sDefault->iDir_force_mode = 0000;
2264 DEBUG(3, ("Initialising global parameters\n"));
2266 for (i = 0; parm_table[i].label; i++) {
2267 if ((parm_table[i].type == P_STRING ||
2268 parm_table[i].type == P_USTRING) &&
2269 parm_table[i].offset != -1 &&
2270 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2272 if (parm_table[i].class == P_LOCAL) {
2273 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2275 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2277 *r = talloc_strdup(lp_ctx, "");
2281 lp_do_global_parameter(lp_ctx, "share backend", "classic");
2283 lp_do_global_parameter(lp_ctx, "server role", "standalone");
2285 /* options that can be set on the command line must be initialised via
2286 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2288 lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2290 lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2291 myname = get_myname();
2292 lp_do_global_parameter(lp_ctx, "netbios name", myname);
2294 lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2296 lp_do_global_parameter(lp_ctx, "fstype", "NTFS");
2298 lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2299 lp_do_global_parameter(lp_ctx, "max connections", "-1");
2301 lp_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo");
2302 lp_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd");
2303 lp_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2304 lp_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain");
2305 lp_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2306 lp_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2307 lp_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2308 lp_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
2309 lp_do_global_parameter(lp_ctx, "idmap database", "idmap.ldb");
2310 lp_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
2311 lp_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2312 lp_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2313 lp_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2314 lp_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2316 /* This hive should be dynamically generated by Samba using
2317 data from the sam, but for the moment leave it in a tdb to
2318 keep regedt32 from popping up an annoying dialog. */
2319 lp_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2321 /* using UTF8 by default allows us to support all chars */
2322 lp_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2324 /* Use codepage 850 as a default for the dos character set */
2325 lp_do_global_parameter(lp_ctx, "dos charset", "CP850");
2328 * Allow the default PASSWD_CHAT to be overridden in local.h.
2330 lp_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2332 lp_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2333 lp_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2334 lp_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2335 lp_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2337 lp_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
2338 lp_do_global_parameter_var(lp_ctx, "server string",
2339 "Samba %s", SAMBA_VERSION_STRING);
2341 lp_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2342 DEFAULT_MAJOR_VERSION,
2343 DEFAULT_MINOR_VERSION);
2345 lp_do_global_parameter(lp_ctx, "password server", "*");
2347 lp_do_global_parameter(lp_ctx, "max mux", "50");
2348 lp_do_global_parameter(lp_ctx, "max xmit", "12288");
2349 lp_do_global_parameter(lp_ctx, "password level", "0");
2350 lp_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2351 lp_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2352 lp_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2353 lp_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2354 lp_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2355 lp_do_global_parameter(lp_ctx, "security", "USER");
2356 lp_do_global_parameter(lp_ctx, "paranoid server security", "True");
2357 lp_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2358 lp_do_global_parameter(lp_ctx, "ReadRaw", "True");
2359 lp_do_global_parameter(lp_ctx, "WriteRaw", "True");
2360 lp_do_global_parameter(lp_ctx, "NullPasswords", "False");
2361 lp_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2362 lp_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2364 lp_do_global_parameter(lp_ctx, "TimeServer", "False");
2365 lp_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2366 lp_do_global_parameter(lp_ctx, "Unicode", "True");
2367 lp_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2368 lp_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2369 lp_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2370 lp_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2372 lp_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2374 lp_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2375 lp_do_global_parameter(lp_ctx, "LocalMaster", "True");
2377 lp_do_global_parameter(lp_ctx, "wins support", "False");
2378 lp_do_global_parameter(lp_ctx, "dns proxy", "True");
2380 lp_do_global_parameter(lp_ctx, "winbind separator", "\\");
2381 lp_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2382 lp_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2383 lp_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2384 lp_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2385 lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2386 lp_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2388 lp_do_global_parameter(lp_ctx, "client signing", "Yes");
2389 lp_do_global_parameter(lp_ctx, "server signing", "auto");
2391 lp_do_global_parameter(lp_ctx, "use spnego", "True");
2393 lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
2394 lp_do_global_parameter(lp_ctx, "nbt port", "137");
2395 lp_do_global_parameter(lp_ctx, "dgram port", "138");
2396 lp_do_global_parameter(lp_ctx, "cldap port", "389");
2397 lp_do_global_parameter(lp_ctx, "krb5 port", "88");
2398 lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
2399 lp_do_global_parameter(lp_ctx, "web port", "901");
2400 lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
2402 lp_do_global_parameter(lp_ctx, "nt status support", "True");
2404 lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2405 lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
2407 lp_do_global_parameter(lp_ctx, "tls enabled", "True");
2408 lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2409 lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2410 lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2411 lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2414 lp_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2416 lp_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2418 for (i = 0; parm_table[i].label; i++) {
2419 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2420 lp_ctx->flags[i] |= FLAG_DEFAULT;
2427 const char *lp_configfile(struct loadparm_context *lp_ctx)
2429 return lp_ctx->szConfigFile;
2432 bool lp_load_default(struct loadparm_context *lp_ctx)
2434 if (getenv("SMB_CONF_PATH"))
2435 return lp_load(lp_ctx, getenv("SMB_CONF_PATH"));
2437 return lp_load(lp_ctx, dyn_CONFIGFILE);
2441 * Load the services array from the services file.
2443 * Return True on success, False on failure.
2445 bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
2450 filename = talloc_strdup(lp_ctx, filename);
2452 lp_ctx->szConfigFile = filename;
2454 lp_ctx->bInGlobalSection = true;
2455 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2456 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
2458 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2460 /* We get sections first, so have to start 'behind' to make up */
2461 lp_ctx->currentService = NULL;
2462 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2464 /* finish up the last section */
2465 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2467 if (lp_ctx->currentService != NULL)
2468 bRetval = service_ok(lp_ctx->currentService);
2470 lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
2472 lp_add_hidden(lp_ctx, "IPC$", "IPC");
2473 lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
2475 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2476 lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2479 panic_action = lp_ctx->globals->panic_action;
2481 reload_charcnv(lp_ctx);
2483 ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx);
2485 /* FIXME: This is a bit of a hack, but we can't use a global, since
2486 * not everything that uses lp also uses the socket library */
2487 if (lp_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2488 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2490 unsetenv("SOCKET_TESTNONBLOCK");
2493 /* FIXME: Check locale in environment for this: */
2494 if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
2495 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
2497 d_set_iconv((smb_iconv_t)-1);
2503 * Return the max number of services.
2506 int lp_numservices(struct loadparm_context *lp_ctx)
2508 return lp_ctx->iNumServices;
2512 * Display the contents of the services array in human-readable form.
2515 void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2521 defaults_saved = false;
2523 dump_globals(lp_ctx, f, show_defaults);
2525 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f);
2527 for (iService = 0; iService < maxtoprint; iService++)
2528 lp_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2532 * Display the contents of one service in human-readable form.
2534 void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2536 if (service != NULL) {
2537 if (service->szService[0] == '\0')
2539 dump_a_service(service, sDefault, f);
2543 struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
2546 return lp_ctx->services[snum];
2549 struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
2550 const char *service_name)
2555 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2556 if (lp_ctx->services[iService] &&
2557 lp_ctx->services[iService]->szService) {
2559 * The substitution here is used to support %U is
2562 serviceName = standard_sub_basic(
2563 lp_ctx->services[iService],
2564 lp_ctx->services[iService]->szService);
2565 if (strequal(serviceName, service_name))
2566 return lp_ctx->services[iService];
2570 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
2576 * A useful volume label function.
2578 const char *volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2580 const char *ret = lp_volume(service, sDefault);
2582 return lp_servicename(service);
2588 * If we are PDC then prefer us as DMB
2590 const char *lp_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2592 const char *ret = _lp_printername(service, sDefault);
2593 if (ret == NULL || (ret != NULL && *ret == '\0'))
2594 ret = lp_servicename(service);
2601 * Return the max print jobs per queue.
2603 int lp_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2605 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2606 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2607 maxjobs = PRINT_MAX_JOBID - 1;
2612 struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx)
2614 if (lp_ctx == NULL) {
2615 static struct smb_iconv_convenience *fallback_ic = NULL;
2616 if (fallback_ic == NULL)
2617 fallback_ic = smb_iconv_convenience_init(talloc_autofree_context(),
2618 "CP850", "UTF8", true);
2621 return lp_ctx->iconv_convenience;
2624 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2626 talloc_free(lp_ctx->iconv_convenience);
2627 global_iconv_convenience = lp_ctx->iconv_convenience = smb_iconv_convenience_init_lp(lp_ctx, lp_ctx);
2630 void lp_smbcli_options(struct loadparm_context *lp_ctx,
2631 struct smbcli_options *options)
2633 options->max_xmit = lp_max_xmit(lp_ctx);
2634 options->max_mux = lp_maxmux(lp_ctx);
2635 options->use_spnego = lp_nt_status_support(lp_ctx) && lp_use_spnego(lp_ctx);
2636 options->signing = lp_client_signing(lp_ctx);
2637 options->request_timeout = SMB_REQUEST_TIMEOUT;
2638 options->ntstatus_support = lp_nt_status_support(lp_ctx);
2639 options->max_protocol = lp_cli_maxprotocol(lp_ctx);
2640 options->unicode = lp_unicode(lp_ctx);
2641 options->use_oplocks = true;
2642 options->use_level2_oplocks = true;
2645 void lp_smbcli_session_options(struct loadparm_context *lp_ctx,
2646 struct smbcli_session_options *options)
2648 options->lanman_auth = lp_client_lanman_auth(lp_ctx);
2649 options->ntlmv2_auth = lp_client_ntlmv2_auth(lp_ctx);
2650 options->plaintext_auth = lp_client_plaintext_auth(lp_ctx);
2653 _PUBLIC_ char *lp_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2655 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
2658 _PUBLIC_ char *lp_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2660 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
2663 _PUBLIC_ char *lp_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2665 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
2668 _PUBLIC_ char *lp_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2670 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
2673 _PUBLIC_ char *lp_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2675 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
2678 _PUBLIC_ struct dcerpc_server_info *lp_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2680 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
2682 ret->domain_name = talloc_reference(mem_ctx, lp_workgroup(lp_ctx));
2683 ret->version_major = lp_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
2684 ret->version_minor = lp_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
2685 ret->version_build = lp_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
2690 struct gensec_settings *lp_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2692 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
2693 if (settings == NULL)
2695 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2696 settings->iconv_convenience = lp_iconv_convenience(lp_ctx);
2697 settings->target_hostname = lp_parm_string(lp_ctx, NULL, "gensec", "target_hostname");