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"
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 *szWinbinddPrivilegedSocketDirectory;
120 char *szWinbinddSocketDirectory;
121 char *szTemplateShell;
122 char *szTemplateHomedir;
123 int bWinbindSealedPipes;
124 int bIdmapTrustedOnly;
125 char *swat_directory;
143 int paranoid_server_security;
146 int announce_as; /* This is initialised in init_globals */
153 char *socket_options;
158 int bPreferredMaster;
159 int bEncryptPasswords;
161 int bObeyPamRestrictions;
166 int bBindInterfacesOnly;
168 int bNTStatusSupport;
174 int bClientPlaintextAuth;
175 int bClientLanManAuth;
176 int bClientNTLMv2Auth;
177 int client_use_spnego_principal;
183 char *szNTPSignDSocketDirectory;
184 struct param_opt *param_opt;
189 * This structure describes a single service.
191 struct loadparm_service
203 char **ntvfs_handler;
217 int iCreate_force_mode;
224 struct param_opt *param_opt;
226 char dummy[3]; /* for alignment */
230 struct loadparm_context *global_loadparm = NULL;
232 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
235 /* prototypes for the special type handlers */
236 static bool handle_include(struct loadparm_context *lp_ctx,
237 const char *pszParmValue, char **ptr);
238 static bool handle_copy(struct loadparm_context *lp_ctx,
239 const char *pszParmValue, char **ptr);
240 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
241 const char *pszParmValue, char **ptr);
242 static bool handle_logfile(struct loadparm_context *lp_ctx,
243 const char *pszParmValue, char **ptr);
245 static const struct enum_list enum_protocol[] = {
246 {PROTOCOL_SMB2, "SMB2"},
247 {PROTOCOL_NT1, "NT1"},
248 {PROTOCOL_LANMAN2, "LANMAN2"},
249 {PROTOCOL_LANMAN1, "LANMAN1"},
250 {PROTOCOL_CORE, "CORE"},
251 {PROTOCOL_COREPLUS, "COREPLUS"},
252 {PROTOCOL_COREPLUS, "CORE+"},
256 static const struct enum_list enum_security[] = {
257 {SEC_SHARE, "SHARE"},
262 static const struct enum_list enum_announce_as[] = {
263 {ANNOUNCE_AS_NT_SERVER, "NT"},
264 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
265 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
266 {ANNOUNCE_AS_WIN95, "win95"},
267 {ANNOUNCE_AS_WFW, "WfW"},
271 static const struct enum_list enum_bool_auto[] = {
282 /* Client-side offline caching policy types */
285 CSC_POLICY_DOCUMENTS=1,
286 CSC_POLICY_PROGRAMS=2,
290 static const struct enum_list enum_csc_policy[] = {
291 {CSC_POLICY_MANUAL, "manual"},
292 {CSC_POLICY_DOCUMENTS, "documents"},
293 {CSC_POLICY_PROGRAMS, "programs"},
294 {CSC_POLICY_DISABLE, "disable"},
298 /* SMB signing types. */
299 static const struct enum_list enum_smb_signing_vals[] = {
300 {SMB_SIGNING_OFF, "No"},
301 {SMB_SIGNING_OFF, "False"},
302 {SMB_SIGNING_OFF, "0"},
303 {SMB_SIGNING_OFF, "Off"},
304 {SMB_SIGNING_OFF, "disabled"},
305 {SMB_SIGNING_SUPPORTED, "Yes"},
306 {SMB_SIGNING_SUPPORTED, "True"},
307 {SMB_SIGNING_SUPPORTED, "1"},
308 {SMB_SIGNING_SUPPORTED, "On"},
309 {SMB_SIGNING_SUPPORTED, "enabled"},
310 {SMB_SIGNING_REQUIRED, "required"},
311 {SMB_SIGNING_REQUIRED, "mandatory"},
312 {SMB_SIGNING_REQUIRED, "force"},
313 {SMB_SIGNING_REQUIRED, "forced"},
314 {SMB_SIGNING_REQUIRED, "enforced"},
315 {SMB_SIGNING_AUTO, "auto"},
319 static const struct enum_list enum_server_role[] = {
320 {ROLE_STANDALONE, "standalone"},
321 {ROLE_DOMAIN_MEMBER, "member server"},
322 {ROLE_DOMAIN_MEMBER, "member"},
323 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
324 {ROLE_DOMAIN_CONTROLLER, "dc"},
329 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
330 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
332 static struct parm_struct parm_table[] = {
333 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
335 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
336 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
337 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
338 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
339 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
340 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
341 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
342 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
343 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), NULL, NULL},
344 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
345 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
346 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
347 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
348 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
349 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
350 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
351 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
352 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
353 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
355 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
356 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
357 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
358 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
359 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
360 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
361 {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
362 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
363 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
364 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
365 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
366 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
367 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
368 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
369 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
370 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
371 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
372 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
373 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
374 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
376 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
378 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
379 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
380 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
381 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
383 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
384 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
386 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
387 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
388 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
390 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
391 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
392 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
393 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
394 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
395 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
396 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
397 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
398 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
399 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
400 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
401 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
402 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
403 {"swat directory", P_STRING, P_GLOBAL, GLOBAL_VAR(swat_directory), NULL, NULL},
404 {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
405 {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
406 {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
407 {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
408 {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
409 {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
410 {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
411 {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
412 {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
414 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
416 {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
417 {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
418 {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
419 {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
421 {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
422 {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
423 {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
424 {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
425 {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
426 {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
427 {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals},
428 {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals},
429 {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
431 {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
432 {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
433 {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
435 {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
436 {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL},
438 {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
439 {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
440 {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
442 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
443 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
445 {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
446 {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
447 {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
449 {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
450 {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
451 {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
452 {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
453 {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
455 {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
456 {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
457 {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
458 {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL},
460 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
462 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
463 {"oplocks", P_BOOL, P_LOCAL, LOCAL_VAR(bOplocks), NULL, NULL},
465 {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
466 {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
467 {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
468 {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
469 {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
470 {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
471 {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL},
472 {"js include", P_LIST, P_GLOBAL, GLOBAL_VAR(jsInclude), 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_tls_keyfile, tls_keyfile)
623 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_certfile, tls_certfile)
624 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, tls_cafile)
625 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, tls_crlfile)
626 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_dhpfile, tls_dhpfile)
627 _PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
628 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
629 _PUBLIC_ FN_GLOBAL_STRING(lp_idmap_url, szIDMAP_URL)
630 _PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
631 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
632 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
633 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
634 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
635 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
636 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
637 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
638 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
639 _PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
640 _PUBLIC_ FN_GLOBAL_BOOL(lp_idmap_trusted_only, bIdmapTrustedOnly)
641 _PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
642 _PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
643 _PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
644 _PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
645 _PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
646 _PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
647 _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
648 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
649 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
650 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
651 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
652 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
653 _PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
654 _PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
655 _PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
656 _PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
657 _PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
658 _PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm)
659 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
660 _PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
661 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
662 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
663 _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
664 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
665 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
666 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
668 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
669 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
670 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
671 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
672 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
673 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
674 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
675 _PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
676 _PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
677 _PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
678 _PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
679 _PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
680 _PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
681 _PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
682 _PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
683 _PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
684 _PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
685 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
686 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
687 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
688 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
689 _PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
690 _PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
691 _PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
692 _PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
693 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
694 _PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
695 _PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
696 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
697 _PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
698 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
699 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
700 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
701 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
702 _PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
703 _PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
704 _PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
705 _PUBLIC_ FN_GLOBAL_LIST(lp_js_include, jsInclude)
706 const char *lp_servicename(const struct loadparm_service *service)
708 return lp_string((const char *)service->szService);
711 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
712 static FN_LOCAL_STRING(_lp_printername, szPrintername)
713 _PUBLIC_ FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
714 _PUBLIC_ FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
715 _PUBLIC_ FN_LOCAL_STRING(lp_comment, comment)
716 _PUBLIC_ FN_LOCAL_STRING(lp_fstype, fstype)
717 static FN_LOCAL_STRING(lp_volume, volume)
718 _PUBLIC_ FN_LOCAL_LIST(lp_ntvfs_handler, ntvfs_handler)
719 _PUBLIC_ FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
720 _PUBLIC_ FN_LOCAL_BOOL(lp_browseable, bBrowseable)
721 _PUBLIC_ FN_LOCAL_BOOL(lp_readonly, bRead_only)
722 _PUBLIC_ FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
723 _PUBLIC_ FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
724 _PUBLIC_ FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
725 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
726 _PUBLIC_ FN_LOCAL_BOOL(lp_oplocks, bOplocks)
727 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
728 _PUBLIC_ FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
729 _PUBLIC_ FN_LOCAL_BOOL(lp_map_system, bMap_system)
730 _PUBLIC_ FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
731 _PUBLIC_ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
732 _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
733 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
734 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
735 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
736 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
737 _PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
739 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory, szNTPSignDSocketDirectory)
741 /* local prototypes */
742 static int map_parameter(const char *pszParmName);
743 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
744 const char *pszServiceName);
745 static void copy_service(struct loadparm_service *pserviceDest,
746 struct loadparm_service *pserviceSource,
748 static bool service_ok(struct loadparm_service *service);
749 static bool do_section(const char *pszSectionName, void *);
750 static void init_copymap(struct loadparm_service *pservice);
752 /* This is a helper function for parametrical options support. */
753 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
754 /* Actual parametrical functions are quite simple */
755 const char *lp_get_parametric(struct loadparm_context *lp_ctx,
756 struct loadparm_service *service,
757 const char *type, const char *option)
760 struct param_opt *data;
765 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
767 asprintf(&vfskey, "%s:%s", type, option);
771 if (strcmp(data->key, vfskey) == 0) {
778 if (service != NULL) {
779 /* Try to fetch the same option but from globals */
780 /* but only if we are not already working with globals */
781 for (data = lp_ctx->globals->param_opt; data;
783 if (strcmp(data->key, vfskey) == 0) {
797 * convenience routine to return int parameters.
799 static int lp_int(const char *s)
803 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
807 return strtol(s, NULL, 0);
811 * convenience routine to return unsigned long parameters.
813 static int lp_ulong(const char *s)
817 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
821 return strtoul(s, NULL, 0);
825 * convenience routine to return unsigned long parameters.
827 static double lp_double(const char *s)
831 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
835 return strtod(s, NULL);
839 * convenience routine to return boolean parameters.
841 static bool lp_bool(const char *s)
846 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
850 if (!set_boolean(s, &ret)) {
851 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
860 * Return parametric option from a given service. Type is a part of option before ':'
861 * Parametric option has following syntax: 'Type: option = value'
862 * Returned value is allocated in 'lp_talloc' context
865 const char *lp_parm_string(struct loadparm_context *lp_ctx,
866 struct loadparm_service *service, const char *type,
869 const char *value = lp_get_parametric(lp_ctx, service, type, option);
872 return lp_string(value);
878 * Return parametric option from a given service. Type is a part of option before ':'
879 * Parametric option has following syntax: 'Type: option = value'
880 * Returned value is allocated in 'lp_talloc' context
883 const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,
884 struct loadparm_context *lp_ctx,
885 struct loadparm_service *service,
887 const char *option, const char *separator)
889 const char *value = lp_get_parametric(lp_ctx, service, type, option);
892 return str_list_make(mem_ctx, value, separator);
898 * Return parametric option from a given service. Type is a part of option before ':'
899 * Parametric option has following syntax: 'Type: option = value'
902 int lp_parm_int(struct loadparm_context *lp_ctx,
903 struct loadparm_service *service, const char *type,
904 const char *option, int default_v)
906 const char *value = lp_get_parametric(lp_ctx, service, type, option);
909 return lp_int(value);
915 * Return parametric option from a given service. Type is a part of
917 * Parametric option has following syntax: 'Type: option = value'.
920 int lp_parm_bytes(struct loadparm_context *lp_ctx,
921 struct loadparm_service *service, const char *type,
922 const char *option, int default_v)
926 const char *value = lp_get_parametric(lp_ctx, service, type, option);
928 if (value && conv_str_size(value, &bval)) {
929 if (bval <= INT_MAX) {
938 * Return parametric option from a given service.
939 * Type is a part of option before ':'
940 * Parametric option has following syntax: 'Type: option = value'
942 unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,
943 struct loadparm_service *service, const char *type,
944 const char *option, unsigned long default_v)
946 const char *value = lp_get_parametric(lp_ctx, service, type, option);
949 return lp_ulong(value);
955 double lp_parm_double(struct loadparm_context *lp_ctx,
956 struct loadparm_service *service, const char *type,
957 const char *option, double default_v)
959 const char *value = lp_get_parametric(lp_ctx, service, type, option);
962 return lp_double(value);
968 * Return parametric option from a given service. Type is a part of option before ':'
969 * Parametric option has following syntax: 'Type: option = value'
972 bool lp_parm_bool(struct loadparm_context *lp_ctx,
973 struct loadparm_service *service, const char *type,
974 const char *option, bool default_v)
976 const char *value = lp_get_parametric(lp_ctx, service, type, option);
979 return lp_bool(value);
986 * Initialise a service to the defaults.
989 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
991 struct loadparm_service *pservice =
992 talloc_zero(mem_ctx, struct loadparm_service);
993 copy_service(pservice, sDefault, NULL);
998 * Set a string value, deallocating any existing space, and allocing the space
1001 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1008 *dest = talloc_strdup(mem_ctx, src);
1009 if ((*dest) == NULL) {
1010 DEBUG(0,("Out of memory in string_init\n"));
1020 * Add a new service to the services array initialising it with the given
1024 struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
1025 const struct loadparm_service *pservice,
1029 struct loadparm_service tservice;
1030 int num_to_alloc = lp_ctx->iNumServices + 1;
1031 struct param_opt *data, *pdata;
1033 tservice = *pservice;
1035 /* it might already exist */
1037 struct loadparm_service *service = getservicebyname(lp_ctx,
1039 if (service != NULL) {
1040 /* Clean all parametric options for service */
1041 /* They will be added during parsing again */
1042 data = service->param_opt;
1048 service->param_opt = NULL;
1053 /* find an invalid one */
1054 for (i = 0; i < lp_ctx->iNumServices; i++)
1055 if (lp_ctx->services[i] == NULL)
1058 /* if not, then create one */
1059 if (i == lp_ctx->iNumServices) {
1060 struct loadparm_service **tsp;
1062 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1065 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1068 lp_ctx->services = tsp;
1069 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1072 lp_ctx->iNumServices++;
1075 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1076 if (lp_ctx->services[i] == NULL) {
1077 DEBUG(0,("lp_add_service: out of memory!\n"));
1080 copy_service(lp_ctx->services[i], &tservice, NULL);
1082 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1083 return lp_ctx->services[i];
1087 * Add a new home service, with the specified home directory, defaults coming
1088 * from service ifrom.
1091 bool lp_add_home(struct loadparm_context *lp_ctx,
1092 const char *pszHomename,
1093 struct loadparm_service *default_service,
1094 const char *user, const char *pszHomedir)
1096 struct loadparm_service *service;
1098 service = lp_add_service(lp_ctx, default_service, pszHomename);
1100 if (service == NULL)
1103 if (!(*(default_service->szPath))
1104 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1105 service->szPath = talloc_strdup(service, pszHomedir);
1107 service->szPath = string_sub_talloc(service, lp_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1110 if (!(*(service->comment))) {
1111 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1113 service->bAvailable = default_service->bAvailable;
1114 service->bBrowseable = default_service->bBrowseable;
1116 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1117 pszHomename, user, service->szPath));
1123 * Add the IPC service.
1126 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,
1129 struct loadparm_service *service = lp_add_service(lp_ctx, lp_ctx->sDefault, name);
1131 if (service == NULL)
1134 string_set(service, &service->szPath, tmpdir());
1136 service->comment = talloc_asprintf(service, "%s Service (%s)",
1137 fstype, lp_ctx->globals->szServerString);
1138 string_set(service, &service->fstype, fstype);
1139 service->iMaxConnections = -1;
1140 service->bAvailable = true;
1141 service->bRead_only = true;
1142 service->bPrint_ok = false;
1143 service->bBrowseable = false;
1145 if (strcasecmp(fstype, "IPC") == 0) {
1146 lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
1150 DEBUG(3, ("adding hidden service %s\n", name));
1156 * Add a new printer service, with defaults coming from service iFrom.
1159 bool lp_add_printer(struct loadparm_context *lp_ctx,
1160 const char *pszPrintername,
1161 struct loadparm_service *default_service)
1163 const char *comment = "From Printcap";
1164 struct loadparm_service *service;
1165 service = lp_add_service(lp_ctx, default_service, pszPrintername);
1167 if (service == NULL)
1170 /* note that we do NOT default the availability flag to True - */
1171 /* we take it from the default service passed. This allows all */
1172 /* dynamic printers to be disabled by disabling the [printers] */
1173 /* entry (if/when the 'available' keyword is implemented!). */
1175 /* the printer name is set to the service name. */
1176 string_set(service, &service->szPrintername, pszPrintername);
1177 string_set(service, &service->comment, comment);
1178 service->bBrowseable = default_service->bBrowseable;
1179 /* Printers cannot be read_only. */
1180 service->bRead_only = false;
1181 /* Printer services must be printable. */
1182 service->bPrint_ok = true;
1184 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1190 * Map a parameter's string representation to something we can use.
1191 * Returns False if the parameter string is not recognised, else TRUE.
1194 static int map_parameter(const char *pszParmName)
1198 if (*pszParmName == '-')
1201 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1202 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1205 /* Warn only if it isn't parametric option */
1206 if (strchr(pszParmName, ':') == NULL)
1207 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1208 /* We do return 'fail' for parametric options as well because they are
1209 stored in different storage
1216 return the parameter structure for a parameter
1218 struct parm_struct *lp_parm_struct(const char *name)
1220 int parmnum = map_parameter(name);
1221 if (parmnum == -1) return NULL;
1222 return &parm_table[parmnum];
1226 return the parameter pointer for a parameter
1228 void *lp_parm_ptr(struct loadparm_context *lp_ctx,
1229 struct loadparm_service *service, struct parm_struct *parm)
1231 if (service == NULL) {
1232 if (parm->class == P_LOCAL)
1233 return ((char *)lp_ctx->sDefault)+parm->offset;
1234 else if (parm->class == P_GLOBAL)
1235 return ((char *)lp_ctx->globals)+parm->offset;
1238 return ((char *)service) + parm->offset;
1243 * Find a service by name. Otherwise works like get_service.
1246 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1247 const char *pszServiceName)
1251 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1252 if (lp_ctx->services[iService] != NULL &&
1253 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1254 return lp_ctx->services[iService];
1261 * Copy a service structure to another.
1262 * If pcopymapDest is NULL then copy all fields
1265 static void copy_service(struct loadparm_service *pserviceDest,
1266 struct loadparm_service *pserviceSource,
1270 bool bcopyall = (pcopymapDest == NULL);
1271 struct param_opt *data, *pdata, *paramo;
1274 for (i = 0; parm_table[i].label; i++)
1275 if (parm_table[i].offset != -1 && parm_table[i].class == P_LOCAL &&
1276 (bcopyall || pcopymapDest[i])) {
1278 ((char *)pserviceSource) + parm_table[i].offset;
1280 ((char *)pserviceDest) + parm_table[i].offset;
1282 switch (parm_table[i].type) {
1284 *(int *)dest_ptr = *(int *)src_ptr;
1290 *(int *)dest_ptr = *(int *)src_ptr;
1294 string_set(pserviceDest,
1300 string_set(pserviceDest,
1303 strupper(*(char **)dest_ptr);
1306 *(const char ***)dest_ptr = str_list_copy(pserviceDest,
1307 *(const char ***)src_ptr);
1315 init_copymap(pserviceDest);
1316 if (pserviceSource->copymap)
1317 memcpy((void *)pserviceDest->copymap,
1318 (void *)pserviceSource->copymap,
1319 sizeof(int) * NUMPARAMETERS);
1322 data = pserviceSource->param_opt;
1325 pdata = pserviceDest->param_opt;
1326 /* Traverse destination */
1328 /* If we already have same option, override it */
1329 if (strcmp(pdata->key, data->key) == 0) {
1330 talloc_free(pdata->value);
1331 pdata->value = talloc_reference(pdata,
1336 pdata = pdata->next;
1339 paramo = talloc(pserviceDest, struct param_opt);
1342 paramo->key = talloc_reference(paramo, data->key);
1343 paramo->value = talloc_reference(paramo, data->value);
1344 DLIST_ADD(pserviceDest->param_opt, paramo);
1351 * Check a service for consistency. Return False if the service is in any way
1352 * incomplete or faulty, else True.
1354 static bool service_ok(struct loadparm_service *service)
1359 if (service->szService[0] == '\0') {
1360 DEBUG(0, ("The following message indicates an internal error:\n"));
1361 DEBUG(0, ("No service name in service entry.\n"));
1365 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1366 /* I can't see why you'd want a non-printable printer service... */
1367 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1368 if (!service->bPrint_ok) {
1369 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1370 service->szService));
1371 service->bPrint_ok = true;
1373 /* [printers] service must also be non-browsable. */
1374 if (service->bBrowseable)
1375 service->bBrowseable = false;
1378 /* If a service is flagged unavailable, log the fact at level 0. */
1379 if (!service->bAvailable)
1380 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1381 service->szService));
1387 /*******************************************************************
1388 Keep a linked list of all config files so we know when one has changed
1389 it's date and needs to be reloaded.
1390 ********************************************************************/
1392 static void add_to_file_list(struct loadparm_context *lp_ctx,
1393 const char *fname, const char *subfname)
1395 struct file_lists *f = lp_ctx->file_lists;
1398 if (f->name && !strcmp(f->name, fname))
1404 f = talloc(lp_ctx, struct file_lists);
1407 f->next = lp_ctx->file_lists;
1408 f->name = talloc_strdup(f, fname);
1413 f->subfname = talloc_strdup(f, subfname);
1418 lp_ctx->file_lists = f;
1419 f->modtime = file_modtime(subfname);
1421 time_t t = file_modtime(subfname);
1427 /*******************************************************************
1428 Check if a config file has changed date.
1429 ********************************************************************/
1430 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1432 struct file_lists *f;
1433 DEBUG(6, ("lp_file_list_changed()\n"));
1435 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1439 n2 = standard_sub_basic(lp_ctx, f->name);
1441 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1442 f->name, n2, ctime(&f->modtime)));
1444 mod_time = file_modtime(n2);
1446 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1447 DEBUGADD(6, ("file %s modified: %s\n", n2,
1449 f->modtime = mod_time;
1450 talloc_free(f->subfname);
1451 f->subfname = talloc_strdup(f, n2);
1458 /***************************************************************************
1459 Handle the include operation.
1460 ***************************************************************************/
1462 static bool handle_include(struct loadparm_context *lp_ctx,
1463 const char *pszParmValue, char **ptr)
1465 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1467 add_to_file_list(lp_ctx, pszParmValue, fname);
1469 string_set(lp_ctx, ptr, fname);
1471 if (file_exist(fname))
1472 return pm_process(fname, do_section, do_parameter, lp_ctx);
1474 DEBUG(2, ("Can't find include file %s\n", fname));
1479 /***************************************************************************
1480 Handle the interpretation of the copy parameter.
1481 ***************************************************************************/
1483 static bool handle_copy(struct loadparm_context *lp_ctx,
1484 const char *pszParmValue, char **ptr)
1487 struct loadparm_service *serviceTemp;
1489 string_set(lp_ctx, ptr, pszParmValue);
1493 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1495 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1496 if (serviceTemp == lp_ctx->currentService) {
1497 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1499 copy_service(lp_ctx->currentService,
1501 lp_ctx->currentService->copymap);
1505 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1513 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1514 const char *pszParmValue, char **ptr)
1516 DEBUGLEVEL = atoi(pszParmValue);
1521 static bool handle_logfile(struct loadparm_context *lp_ctx,
1522 const char *pszParmValue, char **ptr)
1524 logfile = pszParmValue;
1528 /***************************************************************************
1529 Initialise a copymap.
1530 ***************************************************************************/
1532 static void init_copymap(struct loadparm_service *pservice)
1535 talloc_free(pservice->copymap);
1536 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1537 if (pservice->copymap == NULL) {
1539 ("Couldn't allocate copymap!! (size %d)\n",
1540 (int)NUMPARAMETERS));
1543 for (i = 0; i < NUMPARAMETERS; i++)
1544 pservice->copymap[i] = true;
1548 * Process a parametric option
1550 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1551 struct loadparm_service *service,
1552 const char *pszParmName,
1553 const char *pszParmValue, int flags)
1555 struct param_opt *paramo, *data;
1557 TALLOC_CTX *mem_ctx;
1559 while (isspace((unsigned char)*pszParmName)) {
1563 name = strdup(pszParmName);
1564 if (!name) return false;
1568 if (service == NULL) {
1569 data = lp_ctx->globals->param_opt;
1570 mem_ctx = lp_ctx->globals;
1572 data = service->param_opt;
1576 /* Traverse destination */
1577 for (paramo=data; paramo; paramo=paramo->next) {
1578 /* If we already have the option set, override it unless
1579 it was a command line option and the new one isn't */
1580 if (strcmp(paramo->key, name) == 0) {
1581 if ((paramo->flags & FLAG_CMDLINE) &&
1582 !(flags & FLAG_CMDLINE)) {
1586 talloc_free(paramo->value);
1587 paramo->value = talloc_strdup(paramo, pszParmValue);
1588 paramo->flags = flags;
1594 paramo = talloc(mem_ctx, struct param_opt);
1597 paramo->key = talloc_strdup(paramo, name);
1598 paramo->value = talloc_strdup(paramo, pszParmValue);
1599 paramo->flags = flags;
1600 if (service == NULL) {
1601 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1603 DLIST_ADD(service->param_opt, paramo);
1611 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1612 const char *pszParmName, const char *pszParmValue,
1613 struct loadparm_context *lp_ctx)
1616 /* if it is a special case then go ahead */
1617 if (parm_table[parmnum].special) {
1618 parm_table[parmnum].special(lp_ctx, pszParmValue,
1623 /* now switch on the type of variable it is */
1624 switch (parm_table[parmnum].type)
1628 if (!set_boolean(pszParmValue, &b)) {
1629 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1632 *(int *)parm_ptr = b;
1637 *(int *)parm_ptr = atoi(pszParmValue);
1641 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1647 if (conv_str_size(pszParmValue, &val)) {
1648 if (val <= INT_MAX) {
1649 *(int *)parm_ptr = (int)val;
1654 DEBUG(0,("lp_do_parameter(%s): value is not "
1655 "a valid size specifier!\n", pszParmValue));
1660 *(const char ***)parm_ptr = str_list_make(mem_ctx,
1661 pszParmValue, NULL);
1665 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1669 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1670 strupper(*(char **)parm_ptr);
1674 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1677 parm_table[parmnum].enum_list[i].name)) {
1679 parm_table[parmnum].
1684 if (!parm_table[parmnum].enum_list[i].name) {
1685 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1686 pszParmValue, pszParmName));
1692 if (lp_ctx->flags[parmnum] & FLAG_DEFAULT) {
1693 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1694 /* we have to also unset FLAG_DEFAULT on aliases */
1695 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1696 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1698 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1699 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1706 bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
1707 const char *pszParmName, const char *pszParmValue)
1709 int parmnum = map_parameter(pszParmName);
1713 if (strchr(pszParmName, ':')) {
1714 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1716 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1720 /* if the flag has been set on the command line, then don't allow override,
1721 but don't report an error */
1722 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1726 parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1728 return set_variable(lp_ctx, parmnum, parm_ptr,
1729 pszParmName, pszParmValue, lp_ctx);
1732 bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
1733 struct loadparm_service *service,
1734 const char *pszParmName, const char *pszParmValue)
1738 int parmnum = map_parameter(pszParmName);
1741 if (strchr(pszParmName, ':')) {
1742 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1744 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1748 /* if the flag has been set on the command line, then don't allow override,
1749 but don't report an error */
1750 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1754 if (parm_table[parmnum].class == P_GLOBAL) {
1756 ("Global parameter %s found in service section!\n",
1760 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1762 if (!service->copymap)
1763 init_copymap(service);
1765 /* this handles the aliases - set the copymap for other
1766 * entries with the same data pointer */
1767 for (i = 0; parm_table[i].label; i++)
1768 if (parm_table[i].offset == parm_table[parmnum].offset &&
1769 parm_table[i].class == parm_table[parmnum].class)
1770 service->copymap[i] = false;
1772 return set_variable(service, parmnum, parm_ptr, pszParmName,
1773 pszParmValue, lp_ctx);
1777 * Process a parameter.
1780 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1783 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1785 if (lp_ctx->bInGlobalSection)
1786 return lp_do_global_parameter(lp_ctx, pszParmName,
1789 return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
1790 pszParmName, pszParmValue);
1794 variable argument do parameter
1796 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1797 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
1798 const char *pszParmName, const char *fmt, ...)
1805 s = talloc_vasprintf(NULL, fmt, ap);
1807 ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
1814 set a parameter from the commandline - this is called from command line parameter
1815 parsing code. It sets the parameter then marks the parameter as unable to be modified
1816 by smb.conf processing
1818 bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1819 const char *pszParmValue)
1821 int parmnum = map_parameter(pszParmName);
1824 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1827 if (parmnum < 0 && strchr(pszParmName, ':')) {
1828 /* set a parametric option */
1829 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1830 pszParmValue, FLAG_CMDLINE);
1834 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1838 /* reset the CMDLINE flag in case this has been called before */
1839 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1841 if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1845 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1847 /* we have to also set FLAG_CMDLINE on aliases */
1848 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1849 lp_ctx->flags[i] |= FLAG_CMDLINE;
1851 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1852 lp_ctx->flags[i] |= FLAG_CMDLINE;
1859 set a option from the commandline in 'a=b' format. Use to support --option
1861 bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
1879 ret = lp_set_cmdline(lp_ctx, s, p+1);
1885 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1888 * Print a parameter of the specified type.
1891 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1897 for (i = 0; p->enum_list[i].name; i++) {
1898 if (*(int *)ptr == p->enum_list[i].value) {
1900 p->enum_list[i].name);
1907 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1912 fprintf(f, "%d", *(int *)ptr);
1916 fprintf(f, "0%o", *(int *)ptr);
1920 if ((char ***)ptr && *(char ***)ptr) {
1921 char **list = *(char ***)ptr;
1923 for (; *list; list++)
1924 fprintf(f, "%s%s", *list,
1925 ((*(list+1))?", ":""));
1931 if (*(char **)ptr) {
1932 fprintf(f, "%s", *(char **)ptr);
1939 * Check if two parameters are equal.
1942 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1946 return (*((int *)ptr1) == *((int *)ptr2));
1952 return (*((int *)ptr1) == *((int *)ptr2));
1955 return str_list_equal((const char **)(*(char ***)ptr1),
1956 (const char **)(*(char ***)ptr2));
1961 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1966 return (p1 == p2 || strequal(p1, p2));
1973 * Process a new section (service).
1975 * At this stage all sections are services.
1976 * Later we'll have special sections that permit server parameters to be set.
1977 * Returns True on success, False on failure.
1980 static bool do_section(const char *pszSectionName, void *userdata)
1982 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1984 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1985 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1988 /* if we've just struck a global section, note the fact. */
1989 lp_ctx->bInGlobalSection = isglobal;
1991 /* check for multiple global sections */
1992 if (lp_ctx->bInGlobalSection) {
1993 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
1997 /* if we have a current service, tidy it up before moving on */
2000 if (lp_ctx->currentService != NULL)
2001 bRetval = service_ok(lp_ctx->currentService);
2003 /* if all is still well, move to the next record in the services array */
2005 /* We put this here to avoid an odd message order if messages are */
2006 /* issued by the post-processing of a previous section. */
2007 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2009 if ((lp_ctx->currentService = lp_add_service(lp_ctx, lp_ctx->sDefault,
2012 DEBUG(0, ("Failed to add a new service\n"));
2022 * Determine if a particular base parameter is currently set to the default value.
2025 static bool is_default(struct loadparm_service *sDefault, int i)
2027 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2028 if (!defaults_saved)
2030 switch (parm_table[i].type) {
2032 return str_list_equal((const char **)parm_table[i].def.lvalue,
2033 (const char **)def_ptr);
2036 return strequal(parm_table[i].def.svalue,
2039 return parm_table[i].def.bvalue ==
2045 return parm_table[i].def.ivalue ==
2052 *Display the contents of the global structure.
2055 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2059 struct param_opt *data;
2061 fprintf(f, "# Global parameters\n[global]\n");
2063 for (i = 0; parm_table[i].label; i++)
2064 if (parm_table[i].class == P_GLOBAL &&
2065 parm_table[i].offset != -1 &&
2066 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2067 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2069 fprintf(f, "\t%s = ", parm_table[i].label);
2070 print_parameter(&parm_table[i], lp_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2073 if (lp_ctx->globals->param_opt != NULL) {
2074 for (data = lp_ctx->globals->param_opt; data;
2075 data = data->next) {
2076 fprintf(f, "\t%s = %s\n", data->key, data->value);
2083 * Display the contents of a single services record.
2086 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f)
2089 struct param_opt *data;
2091 if (pService != sDefault)
2092 fprintf(f, "\n[%s]\n", pService->szService);
2094 for (i = 0; parm_table[i].label; i++)
2095 if (parm_table[i].class == P_LOCAL &&
2096 parm_table[i].offset != -1 &&
2097 (*parm_table[i].label != '-') &&
2098 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2099 if (pService == sDefault) {
2100 if (defaults_saved && is_default(sDefault, i))
2103 if (equal_parameter(parm_table[i].type,
2104 ((char *)pService) +
2105 parm_table[i].offset,
2106 ((char *)sDefault) +
2107 parm_table[i].offset))
2111 fprintf(f, "\t%s = ", parm_table[i].label);
2112 print_parameter(&parm_table[i],
2113 ((char *)pService) + parm_table[i].offset, f);
2116 if (pService->param_opt != NULL) {
2117 for (data = pService->param_opt; data; data = data->next) {
2118 fprintf(f, "\t%s = %s\n", data->key, data->value);
2123 bool lp_dump_a_parameter(struct loadparm_context *lp_ctx,
2124 struct loadparm_service *service,
2125 const char *parm_name, FILE * f)
2127 struct parm_struct *parm;
2130 parm = lp_parm_struct(parm_name);
2135 ptr = lp_parm_ptr(lp_ctx, service,parm);
2137 print_parameter(parm, ptr, f);
2143 * Return info about the next service in a service. snum==-1 gives the globals.
2144 * Return NULL when out of parameters.
2147 struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2151 /* do the globals */
2152 for (; parm_table[*i].label; (*i)++) {
2153 if (parm_table[*i].offset == -1
2154 || (*parm_table[*i].label == '-'))
2158 && (parm_table[*i].offset ==
2159 parm_table[(*i) - 1].offset))
2162 return &parm_table[(*i)++];
2165 struct loadparm_service *pService = lp_ctx->services[snum];
2167 for (; parm_table[*i].label; (*i)++) {
2168 if (parm_table[*i].class == P_LOCAL &&
2169 parm_table[*i].offset != -1 &&
2170 (*parm_table[*i].label != '-') &&
2172 (parm_table[*i].offset !=
2173 parm_table[(*i) - 1].offset)))
2175 if (allparameters ||
2176 !equal_parameter(parm_table[*i].type,
2177 ((char *)pService) +
2178 parm_table[*i].offset,
2179 ((char *)lp_ctx->sDefault) +
2180 parm_table[*i].offset))
2182 return &parm_table[(*i)++];
2193 * Auto-load some home services.
2195 static void lp_add_auto_services(struct loadparm_context *lp_ctx,
2203 * Unload unused services.
2206 void lp_killunused(struct loadparm_context *lp_ctx,
2207 struct smbsrv_connection *smb,
2208 bool (*snumused) (struct smbsrv_connection *, int))
2211 for (i = 0; i < lp_ctx->iNumServices; i++) {
2212 if (lp_ctx->services[i] == NULL)
2215 if (!snumused || !snumused(smb, i)) {
2216 talloc_free(lp_ctx->services[i]);
2217 lp_ctx->services[i] = NULL;
2223 static int lp_destructor(struct loadparm_context *lp_ctx)
2225 struct param_opt *data;
2227 if (lp_ctx->globals->param_opt != NULL) {
2228 struct param_opt *next;
2229 for (data = lp_ctx->globals->param_opt; data; data=next) {
2231 if (data->flags & FLAG_CMDLINE) continue;
2232 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2241 * Initialise the global parameter structure.
2243 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2247 struct loadparm_context *lp_ctx;
2249 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2253 talloc_set_destructor(lp_ctx, lp_destructor);
2254 lp_ctx->bInGlobalSection = true;
2255 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2256 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2258 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2259 lp_ctx->sDefault->bAvailable = true;
2260 lp_ctx->sDefault->bBrowseable = true;
2261 lp_ctx->sDefault->bRead_only = true;
2262 lp_ctx->sDefault->bMap_archive = true;
2263 lp_ctx->sDefault->bStrictLocking = true;
2264 lp_ctx->sDefault->bOplocks = true;
2265 lp_ctx->sDefault->iCreate_mask = 0744;
2266 lp_ctx->sDefault->iCreate_force_mode = 0000;
2267 lp_ctx->sDefault->iDir_mask = 0755;
2268 lp_ctx->sDefault->iDir_force_mode = 0000;
2270 DEBUG(3, ("Initialising global parameters\n"));
2272 for (i = 0; parm_table[i].label; i++) {
2273 if ((parm_table[i].type == P_STRING ||
2274 parm_table[i].type == P_USTRING) &&
2275 parm_table[i].offset != -1 &&
2276 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2278 if (parm_table[i].class == P_LOCAL) {
2279 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2281 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2283 *r = talloc_strdup(lp_ctx, "");
2287 lp_do_global_parameter(lp_ctx, "share backend", "classic");
2289 lp_do_global_parameter(lp_ctx, "server role", "standalone");
2291 /* options that can be set on the command line must be initialised via
2292 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2294 lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2296 lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2297 myname = get_myname();
2298 lp_do_global_parameter(lp_ctx, "netbios name", myname);
2300 lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2302 lp_do_global_parameter(lp_ctx, "fstype", FSTYPE_STRING);
2303 lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2304 lp_do_global_parameter(lp_ctx, "max connections", "-1");
2306 lp_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo");
2307 lp_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd");
2308 lp_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2309 lp_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain");
2310 lp_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2311 lp_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2312 lp_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2313 lp_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
2314 lp_do_global_parameter(lp_ctx, "idmap database", "idmap.ldb");
2315 lp_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
2316 lp_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2317 lp_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2318 lp_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2319 lp_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2321 /* This hive should be dynamically generated by Samba using
2322 data from the sam, but for the moment leave it in a tdb to
2323 keep regedt32 from popping up an annoying dialog. */
2324 lp_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2326 /* using UTF8 by default allows us to support all chars */
2327 lp_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2329 /* Use codepage 850 as a default for the dos character set */
2330 lp_do_global_parameter(lp_ctx, "dos charset", "CP850");
2333 * Allow the default PASSWD_CHAT to be overridden in local.h.
2335 lp_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2337 lp_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2338 lp_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2339 lp_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2340 lp_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2342 lp_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
2343 lp_do_global_parameter_var(lp_ctx, "server string",
2344 "Samba %s", SAMBA_VERSION_STRING);
2346 lp_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2347 DEFAULT_MAJOR_VERSION,
2348 DEFAULT_MINOR_VERSION);
2350 lp_do_global_parameter(lp_ctx, "password server", "*");
2352 lp_do_global_parameter(lp_ctx, "max mux", "50");
2353 lp_do_global_parameter(lp_ctx, "max xmit", "12288");
2354 lp_do_global_parameter(lp_ctx, "password level", "0");
2355 lp_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2356 lp_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2357 lp_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2358 lp_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2359 lp_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2360 lp_do_global_parameter(lp_ctx, "security", "USER");
2361 lp_do_global_parameter(lp_ctx, "paranoid server security", "True");
2362 lp_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2363 lp_do_global_parameter(lp_ctx, "ReadRaw", "True");
2364 lp_do_global_parameter(lp_ctx, "WriteRaw", "True");
2365 lp_do_global_parameter(lp_ctx, "NullPasswords", "False");
2366 lp_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2367 lp_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2369 lp_do_global_parameter(lp_ctx, "TimeServer", "False");
2370 lp_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2371 lp_do_global_parameter(lp_ctx, "Unicode", "True");
2372 lp_do_global_parameter(lp_ctx, "ClientLanManAuth", "True");
2373 lp_do_global_parameter(lp_ctx, "LanmanAuth", "True");
2374 lp_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2375 lp_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2377 lp_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2379 lp_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2380 lp_do_global_parameter(lp_ctx, "LocalMaster", "True");
2382 lp_do_global_parameter(lp_ctx, "wins support", "False");
2383 lp_do_global_parameter(lp_ctx, "dns proxy", "True");
2385 lp_do_global_parameter(lp_ctx, "winbind separator", "\\");
2386 lp_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2387 lp_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2388 lp_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2389 lp_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2390 lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2391 lp_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2393 lp_do_global_parameter(lp_ctx, "client signing", "Yes");
2394 lp_do_global_parameter(lp_ctx, "server signing", "auto");
2396 lp_do_global_parameter(lp_ctx, "use spnego", "True");
2398 lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
2399 lp_do_global_parameter(lp_ctx, "nbt port", "137");
2400 lp_do_global_parameter(lp_ctx, "dgram port", "138");
2401 lp_do_global_parameter(lp_ctx, "cldap port", "389");
2402 lp_do_global_parameter(lp_ctx, "krb5 port", "88");
2403 lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
2404 lp_do_global_parameter(lp_ctx, "web port", "901");
2405 lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
2407 lp_do_global_parameter(lp_ctx, "nt status support", "True");
2409 lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2410 lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
2412 lp_do_global_parameter(lp_ctx, "tls enabled", "True");
2413 lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2414 lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2415 lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2416 lp_do_global_parameter_var(lp_ctx, "js include", "%s", dyn_JSDIR);
2417 lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2420 lp_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2422 lp_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2424 for (i = 0; parm_table[i].label; i++) {
2425 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2426 lp_ctx->flags[i] |= FLAG_DEFAULT;
2433 const char *lp_configfile(struct loadparm_context *lp_ctx)
2435 return lp_ctx->szConfigFile;
2438 bool lp_load_default(struct loadparm_context *lp_ctx)
2440 return lp_load(lp_ctx, dyn_CONFIGFILE);
2444 * Load the services array from the services file.
2446 * Return True on success, False on failure.
2448 bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
2453 filename = talloc_strdup(lp_ctx, filename);
2455 lp_ctx->szConfigFile = filename;
2457 lp_ctx->bInGlobalSection = true;
2458 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2459 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
2461 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2463 /* We get sections first, so have to start 'behind' to make up */
2464 lp_ctx->currentService = NULL;
2465 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2467 /* finish up the last section */
2468 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2470 if (lp_ctx->currentService != NULL)
2471 bRetval = service_ok(lp_ctx->currentService);
2473 lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
2475 lp_add_hidden(lp_ctx, "IPC$", "IPC");
2476 lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
2478 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2479 lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2482 panic_action = lp_ctx->globals->panic_action;
2484 reload_charcnv(lp_ctx);
2486 /* FIXME: Check locale in environment for this: */
2487 if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
2488 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
2490 d_set_iconv((smb_iconv_t)-1);
2496 * Return the max number of services.
2499 int lp_numservices(struct loadparm_context *lp_ctx)
2501 return lp_ctx->iNumServices;
2505 * Display the contents of the services array in human-readable form.
2508 void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2514 defaults_saved = false;
2516 dump_globals(lp_ctx, f, show_defaults);
2518 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f);
2520 for (iService = 0; iService < maxtoprint; iService++)
2521 lp_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2525 * Display the contents of one service in human-readable form.
2527 void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2529 if (service != NULL) {
2530 if (service->szService[0] == '\0')
2532 dump_a_service(service, sDefault, f);
2536 struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
2539 return lp_ctx->services[snum];
2542 struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
2543 const char *service_name)
2548 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2549 if (lp_ctx->services[iService] &&
2550 lp_ctx->services[iService]->szService) {
2552 * The substitution here is used to support %U is
2555 serviceName = standard_sub_basic(
2556 lp_ctx->services[iService],
2557 lp_ctx->services[iService]->szService);
2558 if (strequal(serviceName, service_name))
2559 return lp_ctx->services[iService];
2563 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
2569 * A useful volume label function.
2571 const char *volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2573 const char *ret = lp_volume(service, sDefault);
2575 return lp_servicename(service);
2581 * If we are PDC then prefer us as DMB
2583 const char *lp_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2585 const char *ret = _lp_printername(service, sDefault);
2586 if (ret == NULL || (ret != NULL && *ret == '\0'))
2587 ret = lp_servicename(service);
2594 * Return the max print jobs per queue.
2596 int lp_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2598 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2599 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2600 maxjobs = PRINT_MAX_JOBID - 1;
2605 struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx)
2607 if (lp_ctx == NULL) {
2608 static struct smb_iconv_convenience *fallback_ic = NULL;
2609 if (fallback_ic == NULL)
2610 fallback_ic = smb_iconv_convenience_init(talloc_autofree_context(),
2611 "CP850", "UTF8", true);
2614 return lp_ctx->iconv_convenience;
2617 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2619 talloc_free(lp_ctx->iconv_convenience);
2620 lp_ctx->iconv_convenience = smb_iconv_convenience_init_lp(lp_ctx, lp_ctx);
2623 void lp_smbcli_options(struct loadparm_context *lp_ctx,
2624 struct smbcli_options *options)
2626 options->max_xmit = lp_max_xmit(lp_ctx);
2627 options->max_mux = lp_maxmux(lp_ctx);
2628 options->use_spnego = lp_nt_status_support(lp_ctx) && lp_use_spnego(lp_ctx);
2629 options->signing = lp_client_signing(lp_ctx);
2630 options->request_timeout = SMB_REQUEST_TIMEOUT;
2631 options->ntstatus_support = lp_nt_status_support(lp_ctx);
2632 options->max_protocol = lp_cli_maxprotocol(lp_ctx);
2633 options->unicode = lp_unicode(lp_ctx);
2634 options->use_oplocks = true;
2635 options->use_level2_oplocks = true;