2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * This module provides suitable callback functions for the params
33 * module. It builds the internal table of service details which is
34 * then used by the rest of the server.
38 * 1) add it to the global or service structure definition
39 * 2) add it to the parm_table
40 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
41 * 4) If it's a global then initialise it in init_globals. If a local
42 * (ie. service) parameter then initialise it in the sDefault structure
46 * The configuration file is processed sequentially for speed. It is NOT
47 * accessed randomly as happens in 'real' Windows. For this reason, there
48 * is a fair bit of sequence-dependent code here - ie., code which assumes
49 * that certain things happen before others. In particular, the code which
50 * happens at the boundary between sections is delicately poised, so be
57 #include "dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "smb_server/smb_server.h"
62 #include "libcli/raw/signing.h"
63 #include "lib/util/dlinklist.h"
64 #include "param/param.h"
65 #include "param/loadparm.h"
67 #define standard_sub_basic talloc_strdup
69 static bool do_parameter(const char *, const char *, void *);
70 static bool defaults_saved = false;
73 * This structure describes global (ie., server-wide) parameters.
75 struct loadparm_global
77 enum server_role server_role;
79 const char **smb_ports;
83 char *display_charset;
95 char *szWINS_CONFIG_URL;
98 const char **jsInclude;
99 char *jsonrpcServicesDir;
100 const char **szPasswordServers;
101 char *szSocketOptions;
103 const char **szWINSservers;
104 const char **szInterfaces;
105 char *szSocketAddress;
106 char *szAnnounceVersion; /* This is initialised in init_globals */
109 const char **szNetbiosAliases;
110 char *szNetbiosScope;
111 char *szDomainOtherSIDs;
112 const char **szNameResolveOrder;
113 const char **dcerpc_ep_servers;
114 const char **server_services;
115 char *ntptr_providor;
116 char *szWinbindSeparator;
117 char *szWinbinddSocketDirectory;
118 char *szTemplateShell;
119 char *szTemplateHomedir;
120 int bWinbindSealedPipes;
121 char *swat_directory;
139 int paranoid_server_security;
142 int announce_as; /* This is initialised in init_globals */
149 char *socket_options;
154 int bPreferredMaster;
155 int bEncryptPasswords;
157 int bObeyPamRestrictions;
162 int bBindInterfacesOnly;
164 int bNTStatusSupport;
170 int bClientPlaintextAuth;
171 int bClientLanManAuth;
172 int bClientNTLMv2Auth;
173 int client_use_spnego_principal;
179 struct param_opt *param_opt;
184 * This structure describes a single service.
186 struct loadparm_service
198 char **ntvfs_handler;
211 int iCreate_force_mode;
218 struct param_opt *param_opt;
220 char dummy[3]; /* for alignment */
224 /* This is a default service used to prime a services structure */
225 struct loadparm_service sDefault = {
230 .szPrintername = NULL,
231 .szHostsallow = NULL,
236 .ntvfs_handler = NULL,
237 .iMaxPrintJobs = 1000,
238 .iMaxConnections = 0,
244 .bMap_system = false,
245 .bMap_hidden = false,
246 .bMap_archive = true,
247 .bStrictLocking = true,
248 .iCreate_mask = 0744,
249 .iCreate_force_mode = 0000,
251 .iDir_force_mode = 0000,
254 .bStrictSync = false,
255 .bCIFileSystem = false,
258 struct loadparm_context *global_loadparm = NULL;
260 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
262 /* prototypes for the special type handlers */
263 static bool handle_include(struct loadparm_context *lp_ctx,
264 const char *pszParmValue, char **ptr);
265 static bool handle_copy(struct loadparm_context *lp_ctx,
266 const char *pszParmValue, char **ptr);
267 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
268 const char *pszParmValue, char **ptr);
269 static bool handle_logfile(struct loadparm_context *lp_ctx,
270 const char *pszParmValue, char **ptr);
272 static const struct enum_list enum_protocol[] = {
273 {PROTOCOL_SMB2, "SMB2"},
274 {PROTOCOL_NT1, "NT1"},
275 {PROTOCOL_LANMAN2, "LANMAN2"},
276 {PROTOCOL_LANMAN1, "LANMAN1"},
277 {PROTOCOL_CORE, "CORE"},
278 {PROTOCOL_COREPLUS, "COREPLUS"},
279 {PROTOCOL_COREPLUS, "CORE+"},
283 static const struct enum_list enum_security[] = {
284 {SEC_SHARE, "SHARE"},
289 static const struct enum_list enum_announce_as[] = {
290 {ANNOUNCE_AS_NT_SERVER, "NT"},
291 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
292 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
293 {ANNOUNCE_AS_WIN95, "win95"},
294 {ANNOUNCE_AS_WFW, "WfW"},
298 static const struct enum_list enum_bool_auto[] = {
309 /* Client-side offline caching policy types */
312 CSC_POLICY_DOCUMENTS=1,
313 CSC_POLICY_PROGRAMS=2,
317 static const struct enum_list enum_csc_policy[] = {
318 {CSC_POLICY_MANUAL, "manual"},
319 {CSC_POLICY_DOCUMENTS, "documents"},
320 {CSC_POLICY_PROGRAMS, "programs"},
321 {CSC_POLICY_DISABLE, "disable"},
325 /* SMB signing types. */
326 static const struct enum_list enum_smb_signing_vals[] = {
327 {SMB_SIGNING_OFF, "No"},
328 {SMB_SIGNING_OFF, "False"},
329 {SMB_SIGNING_OFF, "0"},
330 {SMB_SIGNING_OFF, "Off"},
331 {SMB_SIGNING_OFF, "disabled"},
332 {SMB_SIGNING_SUPPORTED, "Yes"},
333 {SMB_SIGNING_SUPPORTED, "True"},
334 {SMB_SIGNING_SUPPORTED, "1"},
335 {SMB_SIGNING_SUPPORTED, "On"},
336 {SMB_SIGNING_SUPPORTED, "enabled"},
337 {SMB_SIGNING_REQUIRED, "required"},
338 {SMB_SIGNING_REQUIRED, "mandatory"},
339 {SMB_SIGNING_REQUIRED, "force"},
340 {SMB_SIGNING_REQUIRED, "forced"},
341 {SMB_SIGNING_REQUIRED, "enforced"},
342 {SMB_SIGNING_AUTO, "auto"},
346 static const struct enum_list enum_server_role[] = {
347 {ROLE_STANDALONE, "standalone"},
348 {ROLE_DOMAIN_MEMBER, "member server"},
349 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
354 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
355 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
357 static struct parm_struct parm_table[] = {
358 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
360 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
361 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
362 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
363 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
364 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
365 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
366 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
367 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
368 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), NULL, NULL},
369 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
370 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
371 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
372 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
373 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
374 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
375 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
376 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
377 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
378 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
380 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
381 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
382 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
383 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
384 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
385 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
386 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
387 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
388 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
389 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
390 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
391 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
392 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
393 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
394 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
395 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
396 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
397 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
398 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
400 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
402 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
403 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
404 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
405 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
407 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
408 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
410 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
411 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
412 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
414 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
415 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
416 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
417 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
418 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
419 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
420 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
421 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
422 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
423 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
424 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
425 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
426 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
427 {"swat directory", P_STRING, P_GLOBAL, GLOBAL_VAR(swat_directory), NULL, NULL},
428 {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
429 {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
430 {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
431 {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
432 {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
433 {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
434 {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
435 {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
436 {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
438 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
440 {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
441 {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
442 {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
443 {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
445 {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
446 {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
447 {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
448 {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
449 {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
450 {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
451 {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals},
452 {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals},
453 {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
455 {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
456 {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
457 {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
459 {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
460 {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL},
462 {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
463 {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
464 {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
466 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
467 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
469 {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
470 {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
471 {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
473 {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
474 {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
475 {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
476 {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
477 {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
479 {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
480 {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
481 {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
482 {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL},
484 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
486 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
488 {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
489 {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
490 {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
491 {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
492 {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
493 {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
494 {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL},
495 {"js include", P_LIST, P_GLOBAL, GLOBAL_VAR(jsInclude), NULL, NULL},
496 {"setup directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szSetupDir), NULL, NULL},
498 {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
499 {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
500 {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
502 {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
503 {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
504 {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
506 {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
508 {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
509 {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
510 {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
511 {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
512 {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
513 {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
514 {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
516 {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
519 /* local variables */
520 struct loadparm_context {
521 const char *szConfigFile;
522 struct loadparm_global *globals;
523 struct loadparm_service **services;
525 struct loadparm_service *currentService;
526 bool bInGlobalSection;
528 struct file_lists *next;
533 unsigned int flags[NUMPARAMETERS];
534 struct smb_iconv_convenience *iconv_convenience;
540 return the parameter table
542 struct parm_struct *lp_parm_table(void)
548 * Convenience routine to grab string parameters into temporary memory
549 * and run standard_sub_basic on them.
551 * The buffers can be written to by
552 * callers without affecting the source string.
555 static const char *lp_string(const char *s)
557 #if 0 /* until REWRITE done to make thread-safe */
558 size_t len = s ? strlen(s) : 0;
562 /* The follow debug is useful for tracking down memory problems
563 especially if you have an inner loop that is calling a lp_*()
564 function that returns a string. Perhaps this debug should be
565 present all the time? */
568 DEBUG(10, ("lp_string(%s)\n", s));
571 #if 0 /* until REWRITE done to make thread-safe */
573 lp_talloc = talloc_init("lp_talloc");
575 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
583 strlcpy(ret, s, len);
585 if (trim_string(ret, "\"", "\"")) {
586 if (strchr(ret,'"') != NULL)
587 strlcpy(ret, s, len);
590 standard_sub_basic(ret,len+100);
597 In this section all the functions that are used to access the
598 parameters from the rest of the program are defined
601 #define FN_GLOBAL_STRING(fn_name,var_name) \
602 const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : "";}
603 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
604 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 : "";}
605 #define FN_GLOBAL_LIST(fn_name,var_name) \
606 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
607 #define FN_GLOBAL_BOOL(fn_name,var_name) \
608 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
610 #define FN_GLOBAL_CHAR(fn_name,ptr) \
611 char fn_name(void) {return(*(char *)(ptr));}
613 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
614 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
616 #define FN_LOCAL_STRING(fn_name,val) \
617 const char *fn_name(struct loadparm_service *service) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault.val)));}
618 #define FN_LOCAL_CONST_STRING(fn_name,val) \
619 const char *fn_name(struct loadparm_service *service) {return (const char *)(service != NULL && service->val != NULL) ? service->val : sDefault.val;}
620 #define FN_LOCAL_LIST(fn_name,val) \
621 const char **fn_name(struct loadparm_service *service) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault.val);}
622 #define FN_LOCAL_BOOL(fn_name,val) \
623 bool fn_name(struct loadparm_service *service) {return((service != NULL)? service->val : sDefault.val);}
624 #define FN_LOCAL_INTEGER(fn_name,val) \
625 int fn_name(struct loadparm_service *service) {return((service != NULL)? service->val : sDefault.val);}
627 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, server_role)
628 _PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, smb_ports)
629 _PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, nbt_port)
630 _PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, dgram_port)
631 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, cldap_port)
632 _PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, krb5_port)
633 _PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, kpasswd_port)
634 _PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, web_port)
635 _PUBLIC_ FN_GLOBAL_STRING(lp_swat_directory, swat_directory)
636 _PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, tls_enabled)
637 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_keyfile, tls_keyfile)
638 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_certfile, tls_certfile)
639 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, tls_cafile)
640 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, tls_crlfile)
641 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_dhpfile, tls_dhpfile)
642 _PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
643 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
644 _PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
645 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
646 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
647 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
648 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
649 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
650 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
651 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
652 _PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
653 _PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
654 _PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
655 _PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
656 _PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
657 _PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
658 _PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
659 _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
660 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
661 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
662 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
663 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
664 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
665 _PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
666 _PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
667 _PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
668 _PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
669 _PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
670 _PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm)
671 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
672 _PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
673 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
674 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
675 _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
676 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
677 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
678 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
680 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
681 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
682 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
683 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
684 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
685 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
686 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
687 _PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
688 _PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
689 _PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
690 _PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
691 _PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
692 _PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
693 _PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
694 _PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
695 _PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
696 _PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
697 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
698 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
699 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
700 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
701 _PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
702 _PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
703 _PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
704 _PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
705 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
706 _PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
707 _PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
708 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
709 _PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
710 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
711 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
712 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
713 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
714 _PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
715 _PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
716 _PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
717 _PUBLIC_ FN_GLOBAL_LIST(lp_js_include, jsInclude)
718 _PUBLIC_ FN_LOCAL_STRING(lp_servicename, szService)
719 _PUBLIC_ FN_LOCAL_CONST_STRING(lp_const_servicename, szService)
720 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
721 static FN_LOCAL_STRING(_lp_printername, szPrintername)
722 _PUBLIC_ FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
723 _PUBLIC_ FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
724 _PUBLIC_ FN_LOCAL_STRING(lp_comment, comment)
725 _PUBLIC_ FN_LOCAL_STRING(lp_fstype, fstype)
726 static FN_LOCAL_STRING(lp_volume, volume)
727 _PUBLIC_ FN_LOCAL_LIST(lp_ntvfs_handler, ntvfs_handler)
728 _PUBLIC_ FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
729 _PUBLIC_ FN_LOCAL_BOOL(lp_browseable, bBrowseable)
730 _PUBLIC_ FN_LOCAL_BOOL(lp_readonly, bRead_only)
731 _PUBLIC_ FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
732 _PUBLIC_ FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
733 _PUBLIC_ FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
734 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
735 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
736 _PUBLIC_ FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
737 _PUBLIC_ FN_LOCAL_BOOL(lp_map_system, bMap_system)
738 _PUBLIC_ FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
739 _PUBLIC_ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
740 _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
741 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
742 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
743 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
744 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
745 _PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
747 /* local prototypes */
748 static int map_parameter(const char *pszParmName);
749 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
750 const char *pszServiceName);
751 static void copy_service(struct loadparm_service *pserviceDest,
752 struct loadparm_service *pserviceSource,
754 static bool service_ok(struct loadparm_service *service);
755 static bool do_section(const char *pszSectionName, void *);
756 static void init_copymap(struct loadparm_service *pservice);
758 /* This is a helper function for parametrical options support. */
759 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
760 /* Actual parametrical functions are quite simple */
761 const char *lp_get_parametric(struct loadparm_context *lp_ctx,
762 struct loadparm_service *service,
763 const char *type, const char *option)
766 struct param_opt *data;
771 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
773 asprintf(&vfskey, "%s:%s", type, option);
777 if (strcmp(data->key, vfskey) == 0) {
784 if (service != NULL) {
785 /* Try to fetch the same option but from globals */
786 /* but only if we are not already working with globals */
787 for (data = lp_ctx->globals->param_opt; data;
789 if (strcmp(data->key, vfskey) == 0) {
803 * convenience routine to return int parameters.
805 static int lp_int(const char *s)
809 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
813 return strtol(s, NULL, 0);
817 * convenience routine to return unsigned long parameters.
819 static int lp_ulong(const char *s)
823 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
827 return strtoul(s, NULL, 0);
831 * convenience routine to return unsigned long parameters.
833 static double lp_double(const char *s)
837 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
841 return strtod(s, NULL);
845 * convenience routine to return boolean parameters.
847 static bool lp_bool(const char *s)
852 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
856 if (!set_boolean(s, &ret)) {
857 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
866 * Return parametric option from a given service. Type is a part of option before ':'
867 * Parametric option has following syntax: 'Type: option = value'
868 * Returned value is allocated in 'lp_talloc' context
871 const char *lp_parm_string(struct loadparm_context *lp_ctx,
872 struct loadparm_service *service, const char *type,
875 const char *value = lp_get_parametric(lp_ctx, service, type, option);
878 return lp_string(value);
884 * Return parametric option from a given service. Type is a part of option before ':'
885 * Parametric option has following syntax: 'Type: option = value'
886 * Returned value is allocated in 'lp_talloc' context
889 const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,
890 struct loadparm_context *lp_ctx,
891 struct loadparm_service *service,
893 const char *option, const char *separator)
895 const char *value = lp_get_parametric(lp_ctx, service, type, option);
898 return str_list_make(mem_ctx, value, separator);
904 * Return parametric option from a given service. Type is a part of option before ':'
905 * Parametric option has following syntax: 'Type: option = value'
908 int lp_parm_int(struct loadparm_context *lp_ctx,
909 struct loadparm_service *service, const char *type,
910 const char *option, int default_v)
912 const char *value = lp_get_parametric(lp_ctx, service, type, option);
915 return lp_int(value);
921 * Return parametric option from a given service. Type is a part of
923 * Parametric option has following syntax: 'Type: option = value'.
926 int lp_parm_bytes(struct loadparm_context *lp_ctx,
927 struct loadparm_service *service, const char *type,
928 const char *option, int default_v)
932 const char *value = lp_get_parametric(lp_ctx, service, type, option);
934 if (value && conv_str_size(value, &bval)) {
935 if (bval <= INT_MAX) {
944 * Return parametric option from a given service.
945 * Type is a part of option before ':'
946 * Parametric option has following syntax: 'Type: option = value'
948 unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,
949 struct loadparm_service *service, const char *type,
950 const char *option, unsigned long default_v)
952 const char *value = lp_get_parametric(lp_ctx, service, type, option);
955 return lp_ulong(value);
961 double lp_parm_double(struct loadparm_context *lp_ctx,
962 struct loadparm_service *service, const char *type,
963 const char *option, double default_v)
965 const char *value = lp_get_parametric(lp_ctx, service, type, option);
968 return lp_double(value);
974 * Return parametric option from a given service. Type is a part of option before ':'
975 * Parametric option has following syntax: 'Type: option = value'
978 bool lp_parm_bool(struct loadparm_context *lp_ctx,
979 struct loadparm_service *service, const char *type,
980 const char *option, bool default_v)
982 const char *value = lp_get_parametric(lp_ctx, service, type, option);
985 return lp_bool(value);
992 * Initialise a service to the defaults.
995 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx)
997 struct loadparm_service *pservice =
998 talloc_zero(mem_ctx, struct loadparm_service);
999 copy_service(pservice, &sDefault, NULL);
1004 * Set a string value, deallocating any existing space, and allocing the space
1007 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1014 *dest = talloc_strdup(mem_ctx, src);
1015 if ((*dest) == NULL) {
1016 DEBUG(0,("Out of memory in string_init\n"));
1026 * Add a new service to the services array initialising it with the given
1030 struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
1031 const struct loadparm_service *pservice,
1035 struct loadparm_service tservice;
1036 int num_to_alloc = lp_ctx->iNumServices + 1;
1037 struct param_opt *data, *pdata;
1039 tservice = *pservice;
1041 /* it might already exist */
1043 struct loadparm_service *service = getservicebyname(lp_ctx,
1045 if (service != NULL) {
1046 /* Clean all parametric options for service */
1047 /* They will be added during parsing again */
1048 data = service->param_opt;
1054 service->param_opt = NULL;
1059 /* find an invalid one */
1060 for (i = 0; i < lp_ctx->iNumServices; i++)
1061 if (lp_ctx->services[i] == NULL)
1064 /* if not, then create one */
1065 if (i == lp_ctx->iNumServices) {
1066 struct loadparm_service **tsp;
1068 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1071 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1074 lp_ctx->services = tsp;
1075 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1078 lp_ctx->iNumServices++;
1081 lp_ctx->services[i] = init_service(lp_ctx->services);
1082 if (lp_ctx->services[i] == NULL) {
1083 DEBUG(0,("lp_add_service: out of memory!\n"));
1086 copy_service(lp_ctx->services[i], &tservice, NULL);
1088 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1089 return lp_ctx->services[i];
1093 * Add a new home service, with the specified home directory, defaults coming
1094 * from service ifrom.
1097 bool lp_add_home(struct loadparm_context *lp_ctx,
1098 const char *pszHomename,
1099 struct loadparm_service *default_service,
1100 const char *user, const char *pszHomedir)
1102 struct loadparm_service *service;
1104 service = lp_add_service(lp_ctx, default_service, pszHomename);
1106 if (service == NULL)
1109 if (!(*(default_service->szPath))
1110 || strequal(default_service->szPath, sDefault.szPath)) {
1111 service->szPath = talloc_strdup(service, pszHomedir);
1113 service->szPath = string_sub_talloc(service, lp_pathname(default_service),"%H", pszHomedir);
1116 if (!(*(service->comment))) {
1117 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1119 service->bAvailable = default_service->bAvailable;
1120 service->bBrowseable = default_service->bBrowseable;
1122 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1123 pszHomename, user, service->szPath));
1129 * Add the IPC service.
1132 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,
1135 struct loadparm_service *service = lp_add_service(lp_ctx, &sDefault, name);
1137 if (service == NULL)
1140 string_set(service, &service->szPath, tmpdir());
1142 service->comment = talloc_asprintf(service, "%s Service (%s)",
1143 fstype, lp_ctx->globals->szServerString);
1144 string_set(service, &service->fstype, fstype);
1145 service->iMaxConnections = -1;
1146 service->bAvailable = true;
1147 service->bRead_only = true;
1148 service->bPrint_ok = false;
1149 service->bBrowseable = false;
1151 if (strcasecmp(fstype, "IPC") == 0) {
1152 lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
1156 DEBUG(3, ("adding hidden service %s\n", name));
1162 * Add a new printer service, with defaults coming from service iFrom.
1165 bool lp_add_printer(struct loadparm_context *lp_ctx,
1166 const char *pszPrintername,
1167 struct loadparm_service *default_service)
1169 const char *comment = "From Printcap";
1170 struct loadparm_service *service;
1171 service = lp_add_service(lp_ctx, default_service, pszPrintername);
1173 if (service == NULL)
1176 /* note that we do NOT default the availability flag to True - */
1177 /* we take it from the default service passed. This allows all */
1178 /* dynamic printers to be disabled by disabling the [printers] */
1179 /* entry (if/when the 'available' keyword is implemented!). */
1181 /* the printer name is set to the service name. */
1182 string_set(service, &service->szPrintername, pszPrintername);
1183 string_set(service, &service->comment, comment);
1184 service->bBrowseable = default_service->bBrowseable;
1185 /* Printers cannot be read_only. */
1186 service->bRead_only = false;
1187 /* Printer services must be printable. */
1188 service->bPrint_ok = true;
1190 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1196 * Map a parameter's string representation to something we can use.
1197 * Returns False if the parameter string is not recognised, else TRUE.
1200 static int map_parameter(const char *pszParmName)
1204 if (*pszParmName == '-')
1207 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1208 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1211 /* Warn only if it isn't parametric option */
1212 if (strchr(pszParmName, ':') == NULL)
1213 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1214 /* We do return 'fail' for parametric options as well because they are
1215 stored in different storage
1222 return the parameter structure for a parameter
1224 struct parm_struct *lp_parm_struct(const char *name)
1226 int parmnum = map_parameter(name);
1227 if (parmnum == -1) return NULL;
1228 return &parm_table[parmnum];
1232 return the parameter pointer for a parameter
1234 void *lp_parm_ptr(struct loadparm_context *lp_ctx,
1235 struct loadparm_service *service, struct parm_struct *parm)
1237 if (service == NULL) {
1238 if (parm->class == P_LOCAL)
1239 return ((char *)&sDefault)+parm->offset;
1240 else if (parm->class == P_GLOBAL)
1241 return ((char *)lp_ctx->globals)+parm->offset;
1244 return ((char *)service) + parm->offset;
1249 * Find a service by name. Otherwise works like get_service.
1252 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1253 const char *pszServiceName)
1257 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1258 if (lp_ctx->services[iService] != NULL &&
1259 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1260 return lp_ctx->services[iService];
1267 * Copy a service structure to another.
1268 * If pcopymapDest is NULL then copy all fields
1271 static void copy_service(struct loadparm_service *pserviceDest,
1272 struct loadparm_service *pserviceSource,
1276 bool bcopyall = (pcopymapDest == NULL);
1277 struct param_opt *data, *pdata, *paramo;
1280 for (i = 0; parm_table[i].label; i++)
1281 if (parm_table[i].offset != -1 && parm_table[i].class == P_LOCAL &&
1282 (bcopyall || pcopymapDest[i])) {
1284 ((char *)pserviceSource) + parm_table[i].offset;
1286 ((char *)pserviceDest) + parm_table[i].offset;
1288 switch (parm_table[i].type) {
1290 *(int *)dest_ptr = *(int *)src_ptr;
1296 *(int *)dest_ptr = *(int *)src_ptr;
1300 string_set(pserviceDest,
1306 string_set(pserviceDest,
1309 strupper(*(char **)dest_ptr);
1312 *(const char ***)dest_ptr = str_list_copy(pserviceDest,
1313 *(const char ***)src_ptr);
1321 init_copymap(pserviceDest);
1322 if (pserviceSource->copymap)
1323 memcpy((void *)pserviceDest->copymap,
1324 (void *)pserviceSource->copymap,
1325 sizeof(int) * NUMPARAMETERS);
1328 data = pserviceSource->param_opt;
1331 pdata = pserviceDest->param_opt;
1332 /* Traverse destination */
1334 /* If we already have same option, override it */
1335 if (strcmp(pdata->key, data->key) == 0) {
1336 talloc_free(pdata->value);
1337 pdata->value = talloc_reference(pdata,
1342 pdata = pdata->next;
1345 paramo = talloc(pserviceDest, struct param_opt);
1348 paramo->key = talloc_reference(paramo, data->key);
1349 paramo->value = talloc_reference(paramo, data->value);
1350 DLIST_ADD(pserviceDest->param_opt, paramo);
1357 * Check a service for consistency. Return False if the service is in any way
1358 * incomplete or faulty, else True.
1360 static bool service_ok(struct loadparm_service *service)
1365 if (service->szService[0] == '\0') {
1366 DEBUG(0, ("The following message indicates an internal error:\n"));
1367 DEBUG(0, ("No service name in service entry.\n"));
1371 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1372 /* I can't see why you'd want a non-printable printer service... */
1373 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1374 if (!service->bPrint_ok) {
1375 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1376 service->szService));
1377 service->bPrint_ok = true;
1379 /* [printers] service must also be non-browsable. */
1380 if (service->bBrowseable)
1381 service->bBrowseable = false;
1384 /* If a service is flagged unavailable, log the fact at level 0. */
1385 if (!service->bAvailable)
1386 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1387 service->szService));
1393 /*******************************************************************
1394 Keep a linked list of all config files so we know when one has changed
1395 it's date and needs to be reloaded.
1396 ********************************************************************/
1398 static void add_to_file_list(struct loadparm_context *lp_ctx,
1399 const char *fname, const char *subfname)
1401 struct file_lists *f = lp_ctx->file_lists;
1404 if (f->name && !strcmp(f->name, fname))
1410 f = talloc(lp_ctx, struct file_lists);
1413 f->next = lp_ctx->file_lists;
1414 f->name = talloc_strdup(f, fname);
1419 f->subfname = talloc_strdup(f, subfname);
1424 lp_ctx->file_lists = f;
1425 f->modtime = file_modtime(subfname);
1427 time_t t = file_modtime(subfname);
1433 /*******************************************************************
1434 Check if a config file has changed date.
1435 ********************************************************************/
1436 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1438 struct file_lists *f;
1439 DEBUG(6, ("lp_file_list_changed()\n"));
1441 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1445 n2 = standard_sub_basic(lp_ctx, f->name);
1447 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1448 f->name, n2, ctime(&f->modtime)));
1450 mod_time = file_modtime(n2);
1452 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1453 DEBUGADD(6, ("file %s modified: %s\n", n2,
1455 f->modtime = mod_time;
1456 talloc_free(f->subfname);
1457 f->subfname = talloc_strdup(f, n2);
1464 /***************************************************************************
1465 Handle the include operation.
1466 ***************************************************************************/
1468 static bool handle_include(struct loadparm_context *lp_ctx,
1469 const char *pszParmValue, char **ptr)
1471 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1473 add_to_file_list(lp_ctx, pszParmValue, fname);
1475 string_set(lp_ctx, ptr, fname);
1477 if (file_exist(fname))
1478 return pm_process(fname, do_section, do_parameter, lp_ctx);
1480 DEBUG(2, ("Can't find include file %s\n", fname));
1485 /***************************************************************************
1486 Handle the interpretation of the copy parameter.
1487 ***************************************************************************/
1489 static bool handle_copy(struct loadparm_context *lp_ctx,
1490 const char *pszParmValue, char **ptr)
1493 struct loadparm_service *serviceTemp;
1495 string_set(lp_ctx, ptr, pszParmValue);
1499 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1501 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1502 if (serviceTemp == lp_ctx->currentService) {
1503 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1505 copy_service(lp_ctx->currentService,
1507 lp_ctx->currentService->copymap);
1511 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1519 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1520 const char *pszParmValue, char **ptr)
1522 DEBUGLEVEL = atoi(pszParmValue);
1527 static bool handle_logfile(struct loadparm_context *lp_ctx,
1528 const char *pszParmValue, char **ptr)
1530 logfile = pszParmValue;
1534 /***************************************************************************
1535 Initialise a copymap.
1536 ***************************************************************************/
1538 static void init_copymap(struct loadparm_service *pservice)
1541 talloc_free(pservice->copymap);
1542 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1543 if (pservice->copymap == NULL) {
1545 ("Couldn't allocate copymap!! (size %d)\n",
1546 (int)NUMPARAMETERS));
1549 for (i = 0; i < NUMPARAMETERS; i++)
1550 pservice->copymap[i] = true;
1554 * Process a parametric option
1556 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1557 struct loadparm_service *service,
1558 const char *pszParmName,
1559 const char *pszParmValue, int flags)
1561 struct param_opt *paramo, *data;
1563 TALLOC_CTX *mem_ctx;
1565 while (isspace((unsigned char)*pszParmName)) {
1569 name = strdup(pszParmName);
1570 if (!name) return false;
1574 if (service == NULL) {
1575 data = lp_ctx->globals->param_opt;
1576 mem_ctx = lp_ctx->globals;
1578 data = service->param_opt;
1582 /* Traverse destination */
1583 for (paramo=data; paramo; paramo=paramo->next) {
1584 /* If we already have the option set, override it unless
1585 it was a command line option and the new one isn't */
1586 if (strcmp(paramo->key, name) == 0) {
1587 if ((paramo->flags & FLAG_CMDLINE) &&
1588 !(flags & FLAG_CMDLINE)) {
1592 talloc_free(paramo->value);
1593 paramo->value = talloc_strdup(paramo, pszParmValue);
1594 paramo->flags = flags;
1600 paramo = talloc(mem_ctx, struct param_opt);
1603 paramo->key = talloc_strdup(paramo, name);
1604 paramo->value = talloc_strdup(paramo, pszParmValue);
1605 paramo->flags = flags;
1606 if (service == NULL) {
1607 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1609 DLIST_ADD(service->param_opt, paramo);
1617 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1618 const char *pszParmName, const char *pszParmValue,
1619 struct loadparm_context *lp_ctx)
1622 /* if it is a special case then go ahead */
1623 if (parm_table[parmnum].special) {
1624 parm_table[parmnum].special(lp_ctx, pszParmValue,
1629 /* now switch on the type of variable it is */
1630 switch (parm_table[parmnum].type)
1634 if (!set_boolean(pszParmValue, &b)) {
1635 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1638 *(int *)parm_ptr = b;
1643 *(int *)parm_ptr = atoi(pszParmValue);
1647 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1653 if (conv_str_size(pszParmValue, &val)) {
1654 if (val <= INT_MAX) {
1655 *(int *)parm_ptr = (int)val;
1660 DEBUG(0,("lp_do_parameter(%s): value is not "
1661 "a valid size specifier!\n", pszParmValue));
1666 *(const char ***)parm_ptr = str_list_make(mem_ctx,
1667 pszParmValue, NULL);
1671 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1675 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1676 strupper(*(char **)parm_ptr);
1680 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1683 parm_table[parmnum].enum_list[i].name)) {
1685 parm_table[parmnum].
1690 if (!parm_table[parmnum].enum_list[i].name) {
1691 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1692 pszParmValue, pszParmName));
1698 if (lp_ctx->flags[parmnum] & FLAG_DEFAULT) {
1699 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1700 /* we have to also unset FLAG_DEFAULT on aliases */
1701 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1702 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1704 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1705 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1712 bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
1713 const char *pszParmName, const char *pszParmValue)
1715 int parmnum = map_parameter(pszParmName);
1719 if (strchr(pszParmName, ':')) {
1720 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1722 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1726 /* if the flag has been set on the command line, then don't allow override,
1727 but don't report an error */
1728 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1732 parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1734 return set_variable(lp_ctx, parmnum, parm_ptr,
1735 pszParmName, pszParmValue, lp_ctx);
1738 bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
1739 struct loadparm_service *service,
1740 const char *pszParmName, const char *pszParmValue)
1744 int parmnum = map_parameter(pszParmName);
1747 if (strchr(pszParmName, ':')) {
1748 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1750 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1754 /* if the flag has been set on the command line, then don't allow override,
1755 but don't report an error */
1756 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1760 if (parm_table[parmnum].class == P_GLOBAL) {
1762 ("Global parameter %s found in service section!\n",
1766 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1768 if (!service->copymap)
1769 init_copymap(service);
1771 /* this handles the aliases - set the copymap for other
1772 * entries with the same data pointer */
1773 for (i = 0; parm_table[i].label; i++)
1774 if (parm_table[i].offset == parm_table[parmnum].offset &&
1775 parm_table[i].class == parm_table[parmnum].class)
1776 service->copymap[i] = false;
1778 return set_variable(service, parmnum, parm_ptr, pszParmName,
1779 pszParmValue, lp_ctx);
1783 * Process a parameter.
1786 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1789 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1791 if (lp_ctx->bInGlobalSection)
1792 return lp_do_global_parameter(lp_ctx, pszParmName,
1795 return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
1796 pszParmName, pszParmValue);
1800 variable argument do parameter
1802 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1803 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
1804 const char *pszParmName, const char *fmt, ...)
1811 s = talloc_vasprintf(NULL, fmt, ap);
1813 ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
1820 set a parameter from the commandline - this is called from command line parameter
1821 parsing code. It sets the parameter then marks the parameter as unable to be modified
1822 by smb.conf processing
1824 bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1825 const char *pszParmValue)
1827 int parmnum = map_parameter(pszParmName);
1830 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1833 if (parmnum < 0 && strchr(pszParmName, ':')) {
1834 /* set a parametric option */
1835 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1836 pszParmValue, FLAG_CMDLINE);
1840 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1844 /* reset the CMDLINE flag in case this has been called before */
1845 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1847 if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1851 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1853 /* we have to also set FLAG_CMDLINE on aliases */
1854 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1855 lp_ctx->flags[i] |= FLAG_CMDLINE;
1857 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1858 lp_ctx->flags[i] |= FLAG_CMDLINE;
1865 set a option from the commandline in 'a=b' format. Use to support --option
1867 bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
1885 ret = lp_set_cmdline(lp_ctx, s, p+1);
1891 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1894 * Print a parameter of the specified type.
1897 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1903 for (i = 0; p->enum_list[i].name; i++) {
1904 if (*(int *)ptr == p->enum_list[i].value) {
1906 p->enum_list[i].name);
1913 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1918 fprintf(f, "%d", *(int *)ptr);
1922 fprintf(f, "0%o", *(int *)ptr);
1926 if ((char ***)ptr && *(char ***)ptr) {
1927 char **list = *(char ***)ptr;
1929 for (; *list; list++)
1930 fprintf(f, "%s%s", *list,
1931 ((*(list+1))?", ":""));
1937 if (*(char **)ptr) {
1938 fprintf(f, "%s", *(char **)ptr);
1945 * Check if two parameters are equal.
1948 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1952 return (*((int *)ptr1) == *((int *)ptr2));
1958 return (*((int *)ptr1) == *((int *)ptr2));
1961 return str_list_equal((const char **)(*(char ***)ptr1),
1962 (const char **)(*(char ***)ptr2));
1967 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1972 return (p1 == p2 || strequal(p1, p2));
1979 * Process a new section (service).
1981 * At this stage all sections are services.
1982 * Later we'll have special sections that permit server parameters to be set.
1983 * Returns True on success, False on failure.
1986 static bool do_section(const char *pszSectionName, void *userdata)
1988 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1990 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1991 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1994 /* if we've just struck a global section, note the fact. */
1995 lp_ctx->bInGlobalSection = isglobal;
1997 /* check for multiple global sections */
1998 if (lp_ctx->bInGlobalSection) {
1999 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
2003 /* if we have a current service, tidy it up before moving on */
2006 if (lp_ctx->currentService != NULL)
2007 bRetval = service_ok(lp_ctx->currentService);
2009 /* if all is still well, move to the next record in the services array */
2011 /* We put this here to avoid an odd message order if messages are */
2012 /* issued by the post-processing of a previous section. */
2013 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2015 if ((lp_ctx->currentService = lp_add_service(lp_ctx, &sDefault,
2018 DEBUG(0, ("Failed to add a new service\n"));
2028 * Determine if a partcular base parameter is currentl set to the default value.
2031 static bool is_default(int i)
2033 void *def_ptr = ((char *)&sDefault) + parm_table[i].offset;
2034 if (!defaults_saved)
2036 switch (parm_table[i].type) {
2038 return str_list_equal((const char **)parm_table[i].def.lvalue,
2039 (const char **)def_ptr);
2042 return strequal(parm_table[i].def.svalue,
2045 return parm_table[i].def.bvalue ==
2051 return parm_table[i].def.ivalue ==
2058 *Display the contents of the global structure.
2061 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2065 struct param_opt *data;
2067 fprintf(f, "# Global parameters\n[global]\n");
2069 for (i = 0; parm_table[i].label; i++)
2070 if (parm_table[i].class == P_GLOBAL &&
2071 parm_table[i].offset != -1 &&
2072 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2073 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2075 fprintf(f, "\t%s = ", parm_table[i].label);
2076 print_parameter(&parm_table[i], lp_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2079 if (lp_ctx->globals->param_opt != NULL) {
2080 for (data = lp_ctx->globals->param_opt; data;
2081 data = data->next) {
2082 fprintf(f, "\t%s = %s\n", data->key, data->value);
2089 * Display the contents of a single services record.
2092 static void dump_a_service(struct loadparm_service * pService, FILE * f)
2095 struct param_opt *data;
2097 if (pService != &sDefault)
2098 fprintf(f, "\n[%s]\n", pService->szService);
2100 for (i = 0; parm_table[i].label; i++)
2101 if (parm_table[i].class == P_LOCAL &&
2102 parm_table[i].offset != -1 &&
2103 (*parm_table[i].label != '-') &&
2104 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2105 if (pService == &sDefault) {
2106 if (defaults_saved && is_default(i))
2109 if (equal_parameter(parm_table[i].type,
2110 ((char *)pService) +
2111 parm_table[i].offset,
2112 ((char *)&sDefault) +
2113 parm_table[i].offset))
2117 fprintf(f, "\t%s = ", parm_table[i].label);
2118 print_parameter(&parm_table[i],
2119 ((char *)pService) + parm_table[i].offset, f);
2122 if (pService->param_opt != NULL) {
2123 for (data = pService->param_opt; data; data = data->next) {
2124 fprintf(f, "\t%s = %s\n", data->key, data->value);
2129 bool lp_dump_a_parameter(struct loadparm_context *lp_ctx,
2130 struct loadparm_service *service,
2131 const char *parm_name, FILE * f)
2133 struct parm_struct *parm;
2136 parm = lp_parm_struct(parm_name);
2141 ptr = lp_parm_ptr(lp_ctx, service,parm);
2143 print_parameter(parm, ptr, f);
2149 * Return info about the next service in a service. snum==-1 gives the globals.
2150 * Return NULL when out of parameters.
2153 struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2157 /* do the globals */
2158 for (; parm_table[*i].label; (*i)++) {
2159 if (parm_table[*i].offset == -1
2160 || (*parm_table[*i].label == '-'))
2164 && (parm_table[*i].offset ==
2165 parm_table[(*i) - 1].offset))
2168 return &parm_table[(*i)++];
2171 struct loadparm_service *pService = lp_ctx->services[snum];
2173 for (; parm_table[*i].label; (*i)++) {
2174 if (parm_table[*i].class == P_LOCAL &&
2175 parm_table[*i].offset != -1 &&
2176 (*parm_table[*i].label != '-') &&
2178 (parm_table[*i].offset !=
2179 parm_table[(*i) - 1].offset)))
2181 if (allparameters ||
2182 !equal_parameter(parm_table[*i].type,
2183 ((char *)pService) +
2184 parm_table[*i].offset,
2185 ((char *)&sDefault) +
2186 parm_table[*i].offset))
2188 return &parm_table[(*i)++];
2199 * Auto-load some home services.
2201 static void lp_add_auto_services(struct loadparm_context *lp_ctx,
2209 * Unload unused services.
2212 void lp_killunused(struct loadparm_context *lp_ctx,
2213 struct smbsrv_connection *smb,
2214 bool (*snumused) (struct smbsrv_connection *, int))
2217 for (i = 0; i < lp_ctx->iNumServices; i++) {
2218 if (lp_ctx->services[i] == NULL)
2221 if (!snumused || !snumused(smb, i)) {
2222 talloc_free(lp_ctx->services[i]);
2223 lp_ctx->services[i] = NULL;
2229 static int lp_destructor(struct loadparm_context *lp_ctx)
2231 struct param_opt *data;
2233 if (lp_ctx->globals->param_opt != NULL) {
2234 struct param_opt *next;
2235 for (data = lp_ctx->globals->param_opt; data; data=next) {
2237 if (data->flags & FLAG_CMDLINE) continue;
2238 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2247 * Initialise the global parameter structure.
2249 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2253 struct loadparm_context *lp_ctx;
2255 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2259 talloc_set_destructor(lp_ctx, lp_destructor);
2260 lp_ctx->bInGlobalSection = true;
2261 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2263 DEBUG(3, ("Initialising global parameters\n"));
2265 for (i = 0; parm_table[i].label; i++) {
2266 if ((parm_table[i].type == P_STRING ||
2267 parm_table[i].type == P_USTRING) &&
2268 parm_table[i].offset != -1 &&
2269 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2271 if (parm_table[i].class == P_LOCAL) {
2272 r = (char **)(((char *)&sDefault) + parm_table[i].offset);
2274 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2276 *r = talloc_strdup(lp_ctx, "");
2280 lp_do_global_parameter(lp_ctx, "share backend", "classic");
2282 lp_do_global_parameter(lp_ctx, "server role", "standalone");
2284 /* options that can be set on the command line must be initialised via
2285 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2287 lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2289 lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2290 myname = get_myname();
2291 lp_do_global_parameter(lp_ctx, "netbios name", myname);
2293 lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2295 lp_do_global_parameter(lp_ctx, "fstype", FSTYPE_STRING);
2296 lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2297 lp_do_global_parameter(lp_ctx, "max connections", "-1");
2299 lp_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo");
2300 lp_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap web kdc drepl winbind");
2301 lp_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2302 lp_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain");
2303 lp_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2304 lp_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2305 lp_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2306 lp_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
2307 lp_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
2308 lp_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2309 lp_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2310 lp_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2311 lp_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2313 /* This hive should be dynamically generated by Samba using
2314 data from the sam, but for the moment leave it in a tdb to
2315 keep regedt32 from popping up an annoying dialog. */
2316 lp_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2318 /* using UTF8 by default allows us to support all chars */
2319 lp_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2321 /* Use codepage 850 as a default for the dos character set */
2322 lp_do_global_parameter(lp_ctx, "dos charset", "CP850");
2325 * Allow the default PASSWD_CHAT to be overridden in local.h.
2327 lp_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2329 lp_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2330 lp_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2331 lp_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2332 lp_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2334 lp_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
2335 lp_do_global_parameter_var(lp_ctx, "server string",
2336 "Samba %s", SAMBA_VERSION_STRING);
2338 lp_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2339 DEFAULT_MAJOR_VERSION,
2340 DEFAULT_MINOR_VERSION);
2342 lp_do_global_parameter(lp_ctx, "password server", "*");
2344 lp_do_global_parameter(lp_ctx, "max mux", "50");
2345 lp_do_global_parameter(lp_ctx, "max xmit", "12288");
2346 lp_do_global_parameter(lp_ctx, "password level", "0");
2347 lp_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2348 lp_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2349 lp_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2350 lp_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2351 lp_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2352 lp_do_global_parameter(lp_ctx, "security", "USER");
2353 lp_do_global_parameter(lp_ctx, "paranoid server security", "True");
2354 lp_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2355 lp_do_global_parameter(lp_ctx, "ReadRaw", "True");
2356 lp_do_global_parameter(lp_ctx, "WriteRaw", "True");
2357 lp_do_global_parameter(lp_ctx, "NullPasswords", "False");
2358 lp_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2359 lp_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2361 lp_do_global_parameter(lp_ctx, "TimeServer", "False");
2362 lp_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2363 lp_do_global_parameter(lp_ctx, "Unicode", "True");
2364 lp_do_global_parameter(lp_ctx, "ClientLanManAuth", "True");
2365 lp_do_global_parameter(lp_ctx, "LanmanAuth", "True");
2366 lp_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2367 lp_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2369 lp_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2371 lp_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2372 lp_do_global_parameter(lp_ctx, "LocalMaster", "True");
2374 lp_do_global_parameter(lp_ctx, "wins support", "False");
2375 lp_do_global_parameter(lp_ctx, "dns proxy", "True");
2377 lp_do_global_parameter(lp_ctx, "winbind separator", "\\");
2378 lp_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2379 lp_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2380 lp_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2381 lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2383 lp_do_global_parameter(lp_ctx, "client signing", "Yes");
2384 lp_do_global_parameter(lp_ctx, "server signing", "auto");
2386 lp_do_global_parameter(lp_ctx, "use spnego", "True");
2388 lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
2389 lp_do_global_parameter(lp_ctx, "nbt port", "137");
2390 lp_do_global_parameter(lp_ctx, "dgram port", "138");
2391 lp_do_global_parameter(lp_ctx, "cldap port", "389");
2392 lp_do_global_parameter(lp_ctx, "krb5 port", "88");
2393 lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
2394 lp_do_global_parameter(lp_ctx, "web port", "901");
2395 lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
2397 lp_do_global_parameter(lp_ctx, "nt status support", "True");
2399 lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2400 lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
2402 lp_do_global_parameter(lp_ctx, "tls enabled", "True");
2403 lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2404 lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2405 lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2406 lp_do_global_parameter_var(lp_ctx, "js include", "%s", dyn_JSDIR);
2407 lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2410 for (i = 0; parm_table[i].label; i++) {
2411 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2412 lp_ctx->flags[i] |= FLAG_DEFAULT;
2419 const char *lp_configfile(struct loadparm_context *lp_ctx)
2421 return lp_ctx->szConfigFile;
2425 * Load the services array from the services file.
2427 * Return True on success, False on failure.
2429 bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
2434 filename = talloc_strdup(lp_ctx, filename);
2436 lp_ctx->szConfigFile = filename;
2438 lp_ctx->bInGlobalSection = true;
2439 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2440 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
2442 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2444 /* We get sections first, so have to start 'behind' to make up */
2445 lp_ctx->currentService = NULL;
2446 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2448 /* finish up the last section */
2449 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2451 if (lp_ctx->currentService != NULL)
2452 bRetval = service_ok(lp_ctx->currentService);
2454 lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
2456 lp_add_hidden(lp_ctx, "IPC$", "IPC");
2457 lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
2459 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2460 lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2463 panic_action = lp_ctx->globals->panic_action;
2465 reload_charcnv(lp_ctx);
2467 /* FIXME: Check locale in environment for this: */
2468 if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
2469 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
2471 d_set_iconv((smb_iconv_t)-1);
2477 * Return the max number of services.
2480 int lp_numservices(struct loadparm_context *lp_ctx)
2482 return lp_ctx->iNumServices;
2486 * Display the contents of the services array in human-readable form.
2489 void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2495 defaults_saved = false;
2497 dump_globals(lp_ctx, f, show_defaults);
2499 dump_a_service(&sDefault, f);
2501 for (iService = 0; iService < maxtoprint; iService++)
2502 lp_dump_one(f, show_defaults, lp_ctx->services[iService]);
2506 * Display the contents of one service in human-readable form.
2508 void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service)
2510 if (service != NULL) {
2511 if (service->szService[0] == '\0')
2513 dump_a_service(service, f);
2517 struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
2520 return lp_ctx->services[snum];
2523 struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
2524 const char *service_name)
2529 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2530 if (lp_ctx->services[iService] &&
2531 lp_ctx->services[iService]->szService) {
2533 * The substitution here is used to support %U is
2536 serviceName = standard_sub_basic(
2537 lp_ctx->services[iService],
2538 lp_ctx->services[iService]->szService);
2539 if (strequal(serviceName, service_name))
2540 return lp_ctx->services[iService];
2544 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
2550 * A useful volume label function.
2552 const char *volume_label(struct loadparm_service *service)
2554 const char *ret = lp_volume(service);
2556 return lp_servicename(service);
2562 * If we are PDC then prefer us as DMB
2564 const char *lp_printername(struct loadparm_service *service)
2566 const char *ret = _lp_printername(service);
2567 if (ret == NULL || (ret != NULL && *ret == '\0'))
2568 ret = lp_const_servicename(service);
2575 * Return the max print jobs per queue.
2577 int lp_maxprintjobs(struct loadparm_service *service)
2579 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault.iMaxPrintJobs;
2580 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2581 maxjobs = PRINT_MAX_JOBID - 1;
2586 struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx)
2588 if (lp_ctx == NULL) {
2589 static struct smb_iconv_convenience *fallback_ic = NULL;
2590 if (fallback_ic == NULL)
2591 fallback_ic = smb_iconv_convenience_init(talloc_autofree_context(),
2592 "CP850", "UTF8", true);
2595 return lp_ctx->iconv_convenience;
2598 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2600 talloc_free(lp_ctx->iconv_convenience);
2601 lp_ctx->iconv_convenience = smb_iconv_convenience_init_lp(lp_ctx, lp_ctx);