2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * This module provides suitable callback functions for the params
33 * module. It builds the internal table of service details which is
34 * then used by the rest of the server.
38 * 1) add it to the global or service structure definition
39 * 2) add it to the parm_table
40 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
41 * 4) If it's a global then initialise it in init_globals. If a local
42 * (ie. service) parameter then initialise it in the sDefault structure
46 * The configuration file is processed sequentially for speed. It is NOT
47 * accessed randomly as happens in 'real' Windows. For this reason, there
48 * is a fair bit of sequence-dependent code here - ie., code which assumes
49 * that certain things happen before others. In particular, the code which
50 * happens at the boundary between sections is delicately poised, so be
57 #include "dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "smb_server/smb_server.h"
62 #include "libcli/raw/signing.h"
63 #include "lib/util/dlinklist.h"
64 #include "param/param.h"
65 #include "param/loadparm.h"
66 #include "libcli/raw/libcliraw.h"
68 #define standard_sub_basic talloc_strdup
70 static bool do_parameter(const char *, const char *, void *);
71 static bool defaults_saved = false;
74 * This structure describes global (ie., server-wide) parameters.
76 struct loadparm_global
78 enum server_role server_role;
80 const char **smb_ports;
84 char *display_charset;
97 char *szWINS_CONFIG_URL;
100 const char **jsInclude;
101 char *jsonrpcServicesDir;
102 const char **szPasswordServers;
103 char *szSocketOptions;
105 const char **szWINSservers;
106 const char **szInterfaces;
107 char *szSocketAddress;
108 char *szAnnounceVersion; /* This is initialised in init_globals */
111 const char **szNetbiosAliases;
112 char *szNetbiosScope;
113 char *szDomainOtherSIDs;
114 const char **szNameResolveOrder;
115 const char **dcerpc_ep_servers;
116 const char **server_services;
117 char *ntptr_providor;
118 char *szWinbindSeparator;
119 char *szWinbinddSocketDirectory;
120 char *szTemplateShell;
121 char *szTemplateHomedir;
122 int bWinbindSealedPipes;
123 int bIdmapTrustedOnly;
124 char *swat_directory;
142 int paranoid_server_security;
145 int announce_as; /* This is initialised in init_globals */
152 char *socket_options;
157 int bPreferredMaster;
158 int bEncryptPasswords;
160 int bObeyPamRestrictions;
165 int bBindInterfacesOnly;
167 int bNTStatusSupport;
173 int bClientPlaintextAuth;
174 int bClientLanManAuth;
175 int bClientNTLMv2Auth;
176 int client_use_spnego_principal;
182 struct param_opt *param_opt;
187 * This structure describes a single service.
189 struct loadparm_service
201 char **ntvfs_handler;
214 int iCreate_force_mode;
221 struct param_opt *param_opt;
223 char dummy[3]; /* for alignment */
227 /* This is a default service used to prime a services structure */
228 struct loadparm_service sDefault = {
233 .szPrintername = NULL,
234 .szHostsallow = NULL,
239 .ntvfs_handler = NULL,
240 .iMaxPrintJobs = 1000,
241 .iMaxConnections = 0,
247 .bMap_system = false,
248 .bMap_hidden = false,
249 .bMap_archive = true,
250 .bStrictLocking = true,
251 .iCreate_mask = 0744,
252 .iCreate_force_mode = 0000,
254 .iDir_force_mode = 0000,
257 .bStrictSync = false,
258 .bCIFileSystem = false,
261 struct loadparm_context *global_loadparm = NULL;
263 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
265 /* prototypes for the special type handlers */
266 static bool handle_include(struct loadparm_context *lp_ctx,
267 const char *pszParmValue, char **ptr);
268 static bool handle_copy(struct loadparm_context *lp_ctx,
269 const char *pszParmValue, char **ptr);
270 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
271 const char *pszParmValue, char **ptr);
272 static bool handle_logfile(struct loadparm_context *lp_ctx,
273 const char *pszParmValue, char **ptr);
275 static const struct enum_list enum_protocol[] = {
276 {PROTOCOL_SMB2, "SMB2"},
277 {PROTOCOL_NT1, "NT1"},
278 {PROTOCOL_LANMAN2, "LANMAN2"},
279 {PROTOCOL_LANMAN1, "LANMAN1"},
280 {PROTOCOL_CORE, "CORE"},
281 {PROTOCOL_COREPLUS, "COREPLUS"},
282 {PROTOCOL_COREPLUS, "CORE+"},
286 static const struct enum_list enum_security[] = {
287 {SEC_SHARE, "SHARE"},
292 static const struct enum_list enum_announce_as[] = {
293 {ANNOUNCE_AS_NT_SERVER, "NT"},
294 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
295 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
296 {ANNOUNCE_AS_WIN95, "win95"},
297 {ANNOUNCE_AS_WFW, "WfW"},
301 static const struct enum_list enum_bool_auto[] = {
312 /* Client-side offline caching policy types */
315 CSC_POLICY_DOCUMENTS=1,
316 CSC_POLICY_PROGRAMS=2,
320 static const struct enum_list enum_csc_policy[] = {
321 {CSC_POLICY_MANUAL, "manual"},
322 {CSC_POLICY_DOCUMENTS, "documents"},
323 {CSC_POLICY_PROGRAMS, "programs"},
324 {CSC_POLICY_DISABLE, "disable"},
328 /* SMB signing types. */
329 static const struct enum_list enum_smb_signing_vals[] = {
330 {SMB_SIGNING_OFF, "No"},
331 {SMB_SIGNING_OFF, "False"},
332 {SMB_SIGNING_OFF, "0"},
333 {SMB_SIGNING_OFF, "Off"},
334 {SMB_SIGNING_OFF, "disabled"},
335 {SMB_SIGNING_SUPPORTED, "Yes"},
336 {SMB_SIGNING_SUPPORTED, "True"},
337 {SMB_SIGNING_SUPPORTED, "1"},
338 {SMB_SIGNING_SUPPORTED, "On"},
339 {SMB_SIGNING_SUPPORTED, "enabled"},
340 {SMB_SIGNING_REQUIRED, "required"},
341 {SMB_SIGNING_REQUIRED, "mandatory"},
342 {SMB_SIGNING_REQUIRED, "force"},
343 {SMB_SIGNING_REQUIRED, "forced"},
344 {SMB_SIGNING_REQUIRED, "enforced"},
345 {SMB_SIGNING_AUTO, "auto"},
349 static const struct enum_list enum_server_role[] = {
350 {ROLE_STANDALONE, "standalone"},
351 {ROLE_DOMAIN_MEMBER, "member server"},
352 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
357 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
358 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
360 static struct parm_struct parm_table[] = {
361 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
363 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
364 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
365 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
366 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
367 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
368 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
369 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
370 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
371 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), NULL, NULL},
372 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
373 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
374 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
375 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
376 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
377 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
378 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
379 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
380 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
381 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
383 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
384 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
385 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
386 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
387 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
388 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
389 {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
390 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
391 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
392 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
393 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
394 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
395 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
396 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
397 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
398 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
399 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
400 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
401 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
402 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
404 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
406 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
407 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
408 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
409 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
411 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
412 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
414 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
415 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
416 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
418 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
419 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
420 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
421 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
422 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
423 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
424 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
425 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
426 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
427 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
428 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
429 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
430 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
431 {"swat directory", P_STRING, P_GLOBAL, GLOBAL_VAR(swat_directory), NULL, NULL},
432 {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
433 {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
434 {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
435 {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
436 {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
437 {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
438 {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
439 {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
440 {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
442 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
444 {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
445 {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
446 {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
447 {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
449 {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
450 {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
451 {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
452 {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
453 {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
454 {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
455 {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals},
456 {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals},
457 {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
459 {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
460 {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
461 {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
463 {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
464 {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL},
466 {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
467 {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
468 {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
470 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
471 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
473 {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
474 {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
475 {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
477 {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
478 {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
479 {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
480 {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
481 {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
483 {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
484 {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
485 {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
486 {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL},
488 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
490 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
492 {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
493 {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
494 {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
495 {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
496 {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
497 {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
498 {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL},
499 {"js include", P_LIST, P_GLOBAL, GLOBAL_VAR(jsInclude), NULL, NULL},
500 {"setup directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szSetupDir), NULL, NULL},
502 {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
503 {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
504 {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
506 {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
507 {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
508 {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
510 {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
512 {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
513 {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
514 {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
515 {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
516 {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
517 {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
518 {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
519 {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
521 {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
524 /* local variables */
525 struct loadparm_context {
526 const char *szConfigFile;
527 struct loadparm_global *globals;
528 struct loadparm_service **services;
530 struct loadparm_service *currentService;
531 bool bInGlobalSection;
533 struct file_lists *next;
538 unsigned int flags[NUMPARAMETERS];
539 struct smb_iconv_convenience *iconv_convenience;
545 return the parameter table
547 struct parm_struct *lp_parm_table(void)
553 * Convenience routine to grab string parameters into temporary memory
554 * and run standard_sub_basic on them.
556 * The buffers can be written to by
557 * callers without affecting the source string.
560 static const char *lp_string(const char *s)
562 #if 0 /* until REWRITE done to make thread-safe */
563 size_t len = s ? strlen(s) : 0;
567 /* The follow debug is useful for tracking down memory problems
568 especially if you have an inner loop that is calling a lp_*()
569 function that returns a string. Perhaps this debug should be
570 present all the time? */
573 DEBUG(10, ("lp_string(%s)\n", s));
576 #if 0 /* until REWRITE done to make thread-safe */
578 lp_talloc = talloc_init("lp_talloc");
580 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
588 strlcpy(ret, s, len);
590 if (trim_string(ret, "\"", "\"")) {
591 if (strchr(ret,'"') != NULL)
592 strlcpy(ret, s, len);
595 standard_sub_basic(ret,len+100);
602 In this section all the functions that are used to access the
603 parameters from the rest of the program are defined
606 #define FN_GLOBAL_STRING(fn_name,var_name) \
607 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) : "";}
608 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
609 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 : "";}
610 #define FN_GLOBAL_LIST(fn_name,var_name) \
611 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
612 #define FN_GLOBAL_BOOL(fn_name,var_name) \
613 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
615 #define FN_GLOBAL_CHAR(fn_name,ptr) \
616 char fn_name(void) {return(*(char *)(ptr));}
618 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
619 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
621 #define FN_LOCAL_STRING(fn_name,val) \
622 const char *fn_name(struct loadparm_service *service) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault.val)));}
623 #define FN_LOCAL_CONST_STRING(fn_name,val) \
624 const char *fn_name(struct loadparm_service *service) {return (const char *)(service != NULL && service->val != NULL) ? service->val : sDefault.val;}
625 #define FN_LOCAL_LIST(fn_name,val) \
626 const char **fn_name(struct loadparm_service *service) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault.val);}
627 #define FN_LOCAL_BOOL(fn_name,val) \
628 bool fn_name(struct loadparm_service *service) {return((service != NULL)? service->val : sDefault.val);}
629 #define FN_LOCAL_INTEGER(fn_name,val) \
630 int fn_name(struct loadparm_service *service) {return((service != NULL)? service->val : sDefault.val);}
632 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, server_role)
633 _PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, smb_ports)
634 _PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, nbt_port)
635 _PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, dgram_port)
636 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, cldap_port)
637 _PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, krb5_port)
638 _PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, kpasswd_port)
639 _PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, web_port)
640 _PUBLIC_ FN_GLOBAL_STRING(lp_swat_directory, swat_directory)
641 _PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, tls_enabled)
642 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_keyfile, tls_keyfile)
643 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_certfile, tls_certfile)
644 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, tls_cafile)
645 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, tls_crlfile)
646 _PUBLIC_ FN_GLOBAL_STRING(lp_tls_dhpfile, tls_dhpfile)
647 _PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
648 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
649 _PUBLIC_ FN_GLOBAL_STRING(lp_idmap_url, szIDMAP_URL)
650 _PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
651 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
652 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
653 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
654 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
655 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
656 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
657 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
658 _PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
659 _PUBLIC_ FN_GLOBAL_BOOL(lp_idmap_trusted_only, bIdmapTrustedOnly)
660 _PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
661 _PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
662 _PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
663 _PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
664 _PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
665 _PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
666 _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
667 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
668 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
669 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
670 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
671 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
672 _PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
673 _PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
674 _PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
675 _PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
676 _PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
677 _PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm)
678 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
679 _PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
680 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
681 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
682 _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
683 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
684 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
685 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
687 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
688 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
689 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
690 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
691 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
692 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
693 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
694 _PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
695 _PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
696 _PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
697 _PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
698 _PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
699 _PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
700 _PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
701 _PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
702 _PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
703 _PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
704 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
705 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
706 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
707 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
708 _PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
709 _PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
710 _PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
711 _PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
712 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
713 _PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
714 _PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
715 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
716 _PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
717 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
718 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
719 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
720 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
721 _PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
722 _PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
723 _PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
724 _PUBLIC_ FN_GLOBAL_LIST(lp_js_include, jsInclude)
725 _PUBLIC_ FN_LOCAL_STRING(lp_servicename, szService)
726 _PUBLIC_ FN_LOCAL_CONST_STRING(lp_const_servicename, szService)
727 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
728 static FN_LOCAL_STRING(_lp_printername, szPrintername)
729 _PUBLIC_ FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
730 _PUBLIC_ FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
731 _PUBLIC_ FN_LOCAL_STRING(lp_comment, comment)
732 _PUBLIC_ FN_LOCAL_STRING(lp_fstype, fstype)
733 static FN_LOCAL_STRING(lp_volume, volume)
734 _PUBLIC_ FN_LOCAL_LIST(lp_ntvfs_handler, ntvfs_handler)
735 _PUBLIC_ FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
736 _PUBLIC_ FN_LOCAL_BOOL(lp_browseable, bBrowseable)
737 _PUBLIC_ FN_LOCAL_BOOL(lp_readonly, bRead_only)
738 _PUBLIC_ FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
739 _PUBLIC_ FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
740 _PUBLIC_ FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
741 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
742 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
743 _PUBLIC_ FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
744 _PUBLIC_ FN_LOCAL_BOOL(lp_map_system, bMap_system)
745 _PUBLIC_ FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
746 _PUBLIC_ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
747 _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
748 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
749 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
750 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
751 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
752 _PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
754 /* local prototypes */
755 static int map_parameter(const char *pszParmName);
756 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
757 const char *pszServiceName);
758 static void copy_service(struct loadparm_service *pserviceDest,
759 struct loadparm_service *pserviceSource,
761 static bool service_ok(struct loadparm_service *service);
762 static bool do_section(const char *pszSectionName, void *);
763 static void init_copymap(struct loadparm_service *pservice);
765 /* This is a helper function for parametrical options support. */
766 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
767 /* Actual parametrical functions are quite simple */
768 const char *lp_get_parametric(struct loadparm_context *lp_ctx,
769 struct loadparm_service *service,
770 const char *type, const char *option)
773 struct param_opt *data;
778 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
780 asprintf(&vfskey, "%s:%s", type, option);
784 if (strcmp(data->key, vfskey) == 0) {
791 if (service != NULL) {
792 /* Try to fetch the same option but from globals */
793 /* but only if we are not already working with globals */
794 for (data = lp_ctx->globals->param_opt; data;
796 if (strcmp(data->key, vfskey) == 0) {
810 * convenience routine to return int parameters.
812 static int lp_int(const char *s)
816 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
820 return strtol(s, NULL, 0);
824 * convenience routine to return unsigned long parameters.
826 static int lp_ulong(const char *s)
830 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
834 return strtoul(s, NULL, 0);
838 * convenience routine to return unsigned long parameters.
840 static double lp_double(const char *s)
844 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
848 return strtod(s, NULL);
852 * convenience routine to return boolean parameters.
854 static bool lp_bool(const char *s)
859 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
863 if (!set_boolean(s, &ret)) {
864 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
873 * Return parametric option from a given service. Type is a part of option before ':'
874 * Parametric option has following syntax: 'Type: option = value'
875 * Returned value is allocated in 'lp_talloc' context
878 const char *lp_parm_string(struct loadparm_context *lp_ctx,
879 struct loadparm_service *service, const char *type,
882 const char *value = lp_get_parametric(lp_ctx, service, type, option);
885 return lp_string(value);
891 * Return parametric option from a given service. Type is a part of option before ':'
892 * Parametric option has following syntax: 'Type: option = value'
893 * Returned value is allocated in 'lp_talloc' context
896 const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,
897 struct loadparm_context *lp_ctx,
898 struct loadparm_service *service,
900 const char *option, const char *separator)
902 const char *value = lp_get_parametric(lp_ctx, service, type, option);
905 return str_list_make(mem_ctx, value, separator);
911 * Return parametric option from a given service. Type is a part of option before ':'
912 * Parametric option has following syntax: 'Type: option = value'
915 int lp_parm_int(struct loadparm_context *lp_ctx,
916 struct loadparm_service *service, const char *type,
917 const char *option, int default_v)
919 const char *value = lp_get_parametric(lp_ctx, service, type, option);
922 return lp_int(value);
928 * Return parametric option from a given service. Type is a part of
930 * Parametric option has following syntax: 'Type: option = value'.
933 int lp_parm_bytes(struct loadparm_context *lp_ctx,
934 struct loadparm_service *service, const char *type,
935 const char *option, int default_v)
939 const char *value = lp_get_parametric(lp_ctx, service, type, option);
941 if (value && conv_str_size(value, &bval)) {
942 if (bval <= INT_MAX) {
951 * Return parametric option from a given service.
952 * Type is a part of option before ':'
953 * Parametric option has following syntax: 'Type: option = value'
955 unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,
956 struct loadparm_service *service, const char *type,
957 const char *option, unsigned long default_v)
959 const char *value = lp_get_parametric(lp_ctx, service, type, option);
962 return lp_ulong(value);
968 double lp_parm_double(struct loadparm_context *lp_ctx,
969 struct loadparm_service *service, const char *type,
970 const char *option, double default_v)
972 const char *value = lp_get_parametric(lp_ctx, service, type, option);
975 return lp_double(value);
981 * Return parametric option from a given service. Type is a part of option before ':'
982 * Parametric option has following syntax: 'Type: option = value'
985 bool lp_parm_bool(struct loadparm_context *lp_ctx,
986 struct loadparm_service *service, const char *type,
987 const char *option, bool default_v)
989 const char *value = lp_get_parametric(lp_ctx, service, type, option);
992 return lp_bool(value);
999 * Initialise a service to the defaults.
1002 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx)
1004 struct loadparm_service *pservice =
1005 talloc_zero(mem_ctx, struct loadparm_service);
1006 copy_service(pservice, &sDefault, NULL);
1011 * Set a string value, deallocating any existing space, and allocing the space
1014 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1021 *dest = talloc_strdup(mem_ctx, src);
1022 if ((*dest) == NULL) {
1023 DEBUG(0,("Out of memory in string_init\n"));
1033 * Add a new service to the services array initialising it with the given
1037 struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
1038 const struct loadparm_service *pservice,
1042 struct loadparm_service tservice;
1043 int num_to_alloc = lp_ctx->iNumServices + 1;
1044 struct param_opt *data, *pdata;
1046 tservice = *pservice;
1048 /* it might already exist */
1050 struct loadparm_service *service = getservicebyname(lp_ctx,
1052 if (service != NULL) {
1053 /* Clean all parametric options for service */
1054 /* They will be added during parsing again */
1055 data = service->param_opt;
1061 service->param_opt = NULL;
1066 /* find an invalid one */
1067 for (i = 0; i < lp_ctx->iNumServices; i++)
1068 if (lp_ctx->services[i] == NULL)
1071 /* if not, then create one */
1072 if (i == lp_ctx->iNumServices) {
1073 struct loadparm_service **tsp;
1075 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1078 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1081 lp_ctx->services = tsp;
1082 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1085 lp_ctx->iNumServices++;
1088 lp_ctx->services[i] = init_service(lp_ctx->services);
1089 if (lp_ctx->services[i] == NULL) {
1090 DEBUG(0,("lp_add_service: out of memory!\n"));
1093 copy_service(lp_ctx->services[i], &tservice, NULL);
1095 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1096 return lp_ctx->services[i];
1100 * Add a new home service, with the specified home directory, defaults coming
1101 * from service ifrom.
1104 bool lp_add_home(struct loadparm_context *lp_ctx,
1105 const char *pszHomename,
1106 struct loadparm_service *default_service,
1107 const char *user, const char *pszHomedir)
1109 struct loadparm_service *service;
1111 service = lp_add_service(lp_ctx, default_service, pszHomename);
1113 if (service == NULL)
1116 if (!(*(default_service->szPath))
1117 || strequal(default_service->szPath, sDefault.szPath)) {
1118 service->szPath = talloc_strdup(service, pszHomedir);
1120 service->szPath = string_sub_talloc(service, lp_pathname(default_service),"%H", pszHomedir);
1123 if (!(*(service->comment))) {
1124 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1126 service->bAvailable = default_service->bAvailable;
1127 service->bBrowseable = default_service->bBrowseable;
1129 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1130 pszHomename, user, service->szPath));
1136 * Add the IPC service.
1139 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,
1142 struct loadparm_service *service = lp_add_service(lp_ctx, &sDefault, name);
1144 if (service == NULL)
1147 string_set(service, &service->szPath, tmpdir());
1149 service->comment = talloc_asprintf(service, "%s Service (%s)",
1150 fstype, lp_ctx->globals->szServerString);
1151 string_set(service, &service->fstype, fstype);
1152 service->iMaxConnections = -1;
1153 service->bAvailable = true;
1154 service->bRead_only = true;
1155 service->bPrint_ok = false;
1156 service->bBrowseable = false;
1158 if (strcasecmp(fstype, "IPC") == 0) {
1159 lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
1163 DEBUG(3, ("adding hidden service %s\n", name));
1169 * Add a new printer service, with defaults coming from service iFrom.
1172 bool lp_add_printer(struct loadparm_context *lp_ctx,
1173 const char *pszPrintername,
1174 struct loadparm_service *default_service)
1176 const char *comment = "From Printcap";
1177 struct loadparm_service *service;
1178 service = lp_add_service(lp_ctx, default_service, pszPrintername);
1180 if (service == NULL)
1183 /* note that we do NOT default the availability flag to True - */
1184 /* we take it from the default service passed. This allows all */
1185 /* dynamic printers to be disabled by disabling the [printers] */
1186 /* entry (if/when the 'available' keyword is implemented!). */
1188 /* the printer name is set to the service name. */
1189 string_set(service, &service->szPrintername, pszPrintername);
1190 string_set(service, &service->comment, comment);
1191 service->bBrowseable = default_service->bBrowseable;
1192 /* Printers cannot be read_only. */
1193 service->bRead_only = false;
1194 /* Printer services must be printable. */
1195 service->bPrint_ok = true;
1197 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1203 * Map a parameter's string representation to something we can use.
1204 * Returns False if the parameter string is not recognised, else TRUE.
1207 static int map_parameter(const char *pszParmName)
1211 if (*pszParmName == '-')
1214 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1215 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1218 /* Warn only if it isn't parametric option */
1219 if (strchr(pszParmName, ':') == NULL)
1220 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1221 /* We do return 'fail' for parametric options as well because they are
1222 stored in different storage
1229 return the parameter structure for a parameter
1231 struct parm_struct *lp_parm_struct(const char *name)
1233 int parmnum = map_parameter(name);
1234 if (parmnum == -1) return NULL;
1235 return &parm_table[parmnum];
1239 return the parameter pointer for a parameter
1241 void *lp_parm_ptr(struct loadparm_context *lp_ctx,
1242 struct loadparm_service *service, struct parm_struct *parm)
1244 if (service == NULL) {
1245 if (parm->class == P_LOCAL)
1246 return ((char *)&sDefault)+parm->offset;
1247 else if (parm->class == P_GLOBAL)
1248 return ((char *)lp_ctx->globals)+parm->offset;
1251 return ((char *)service) + parm->offset;
1256 * Find a service by name. Otherwise works like get_service.
1259 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1260 const char *pszServiceName)
1264 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1265 if (lp_ctx->services[iService] != NULL &&
1266 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1267 return lp_ctx->services[iService];
1274 * Copy a service structure to another.
1275 * If pcopymapDest is NULL then copy all fields
1278 static void copy_service(struct loadparm_service *pserviceDest,
1279 struct loadparm_service *pserviceSource,
1283 bool bcopyall = (pcopymapDest == NULL);
1284 struct param_opt *data, *pdata, *paramo;
1287 for (i = 0; parm_table[i].label; i++)
1288 if (parm_table[i].offset != -1 && parm_table[i].class == P_LOCAL &&
1289 (bcopyall || pcopymapDest[i])) {
1291 ((char *)pserviceSource) + parm_table[i].offset;
1293 ((char *)pserviceDest) + parm_table[i].offset;
1295 switch (parm_table[i].type) {
1297 *(int *)dest_ptr = *(int *)src_ptr;
1303 *(int *)dest_ptr = *(int *)src_ptr;
1307 string_set(pserviceDest,
1313 string_set(pserviceDest,
1316 strupper(*(char **)dest_ptr);
1319 *(const char ***)dest_ptr = str_list_copy(pserviceDest,
1320 *(const char ***)src_ptr);
1328 init_copymap(pserviceDest);
1329 if (pserviceSource->copymap)
1330 memcpy((void *)pserviceDest->copymap,
1331 (void *)pserviceSource->copymap,
1332 sizeof(int) * NUMPARAMETERS);
1335 data = pserviceSource->param_opt;
1338 pdata = pserviceDest->param_opt;
1339 /* Traverse destination */
1341 /* If we already have same option, override it */
1342 if (strcmp(pdata->key, data->key) == 0) {
1343 talloc_free(pdata->value);
1344 pdata->value = talloc_reference(pdata,
1349 pdata = pdata->next;
1352 paramo = talloc(pserviceDest, struct param_opt);
1355 paramo->key = talloc_reference(paramo, data->key);
1356 paramo->value = talloc_reference(paramo, data->value);
1357 DLIST_ADD(pserviceDest->param_opt, paramo);
1364 * Check a service for consistency. Return False if the service is in any way
1365 * incomplete or faulty, else True.
1367 static bool service_ok(struct loadparm_service *service)
1372 if (service->szService[0] == '\0') {
1373 DEBUG(0, ("The following message indicates an internal error:\n"));
1374 DEBUG(0, ("No service name in service entry.\n"));
1378 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1379 /* I can't see why you'd want a non-printable printer service... */
1380 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1381 if (!service->bPrint_ok) {
1382 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1383 service->szService));
1384 service->bPrint_ok = true;
1386 /* [printers] service must also be non-browsable. */
1387 if (service->bBrowseable)
1388 service->bBrowseable = false;
1391 /* If a service is flagged unavailable, log the fact at level 0. */
1392 if (!service->bAvailable)
1393 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1394 service->szService));
1400 /*******************************************************************
1401 Keep a linked list of all config files so we know when one has changed
1402 it's date and needs to be reloaded.
1403 ********************************************************************/
1405 static void add_to_file_list(struct loadparm_context *lp_ctx,
1406 const char *fname, const char *subfname)
1408 struct file_lists *f = lp_ctx->file_lists;
1411 if (f->name && !strcmp(f->name, fname))
1417 f = talloc(lp_ctx, struct file_lists);
1420 f->next = lp_ctx->file_lists;
1421 f->name = talloc_strdup(f, fname);
1426 f->subfname = talloc_strdup(f, subfname);
1431 lp_ctx->file_lists = f;
1432 f->modtime = file_modtime(subfname);
1434 time_t t = file_modtime(subfname);
1440 /*******************************************************************
1441 Check if a config file has changed date.
1442 ********************************************************************/
1443 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1445 struct file_lists *f;
1446 DEBUG(6, ("lp_file_list_changed()\n"));
1448 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1452 n2 = standard_sub_basic(lp_ctx, f->name);
1454 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1455 f->name, n2, ctime(&f->modtime)));
1457 mod_time = file_modtime(n2);
1459 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1460 DEBUGADD(6, ("file %s modified: %s\n", n2,
1462 f->modtime = mod_time;
1463 talloc_free(f->subfname);
1464 f->subfname = talloc_strdup(f, n2);
1471 /***************************************************************************
1472 Handle the include operation.
1473 ***************************************************************************/
1475 static bool handle_include(struct loadparm_context *lp_ctx,
1476 const char *pszParmValue, char **ptr)
1478 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1480 add_to_file_list(lp_ctx, pszParmValue, fname);
1482 string_set(lp_ctx, ptr, fname);
1484 if (file_exist(fname))
1485 return pm_process(fname, do_section, do_parameter, lp_ctx);
1487 DEBUG(2, ("Can't find include file %s\n", fname));
1492 /***************************************************************************
1493 Handle the interpretation of the copy parameter.
1494 ***************************************************************************/
1496 static bool handle_copy(struct loadparm_context *lp_ctx,
1497 const char *pszParmValue, char **ptr)
1500 struct loadparm_service *serviceTemp;
1502 string_set(lp_ctx, ptr, pszParmValue);
1506 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1508 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1509 if (serviceTemp == lp_ctx->currentService) {
1510 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1512 copy_service(lp_ctx->currentService,
1514 lp_ctx->currentService->copymap);
1518 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1526 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1527 const char *pszParmValue, char **ptr)
1529 DEBUGLEVEL = atoi(pszParmValue);
1534 static bool handle_logfile(struct loadparm_context *lp_ctx,
1535 const char *pszParmValue, char **ptr)
1537 logfile = pszParmValue;
1541 /***************************************************************************
1542 Initialise a copymap.
1543 ***************************************************************************/
1545 static void init_copymap(struct loadparm_service *pservice)
1548 talloc_free(pservice->copymap);
1549 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1550 if (pservice->copymap == NULL) {
1552 ("Couldn't allocate copymap!! (size %d)\n",
1553 (int)NUMPARAMETERS));
1556 for (i = 0; i < NUMPARAMETERS; i++)
1557 pservice->copymap[i] = true;
1561 * Process a parametric option
1563 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1564 struct loadparm_service *service,
1565 const char *pszParmName,
1566 const char *pszParmValue, int flags)
1568 struct param_opt *paramo, *data;
1570 TALLOC_CTX *mem_ctx;
1572 while (isspace((unsigned char)*pszParmName)) {
1576 name = strdup(pszParmName);
1577 if (!name) return false;
1581 if (service == NULL) {
1582 data = lp_ctx->globals->param_opt;
1583 mem_ctx = lp_ctx->globals;
1585 data = service->param_opt;
1589 /* Traverse destination */
1590 for (paramo=data; paramo; paramo=paramo->next) {
1591 /* If we already have the option set, override it unless
1592 it was a command line option and the new one isn't */
1593 if (strcmp(paramo->key, name) == 0) {
1594 if ((paramo->flags & FLAG_CMDLINE) &&
1595 !(flags & FLAG_CMDLINE)) {
1599 talloc_free(paramo->value);
1600 paramo->value = talloc_strdup(paramo, pszParmValue);
1601 paramo->flags = flags;
1607 paramo = talloc(mem_ctx, struct param_opt);
1610 paramo->key = talloc_strdup(paramo, name);
1611 paramo->value = talloc_strdup(paramo, pszParmValue);
1612 paramo->flags = flags;
1613 if (service == NULL) {
1614 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1616 DLIST_ADD(service->param_opt, paramo);
1624 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1625 const char *pszParmName, const char *pszParmValue,
1626 struct loadparm_context *lp_ctx)
1629 /* if it is a special case then go ahead */
1630 if (parm_table[parmnum].special) {
1631 parm_table[parmnum].special(lp_ctx, pszParmValue,
1636 /* now switch on the type of variable it is */
1637 switch (parm_table[parmnum].type)
1641 if (!set_boolean(pszParmValue, &b)) {
1642 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1645 *(int *)parm_ptr = b;
1650 *(int *)parm_ptr = atoi(pszParmValue);
1654 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1660 if (conv_str_size(pszParmValue, &val)) {
1661 if (val <= INT_MAX) {
1662 *(int *)parm_ptr = (int)val;
1667 DEBUG(0,("lp_do_parameter(%s): value is not "
1668 "a valid size specifier!\n", pszParmValue));
1673 *(const char ***)parm_ptr = str_list_make(mem_ctx,
1674 pszParmValue, NULL);
1678 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1682 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1683 strupper(*(char **)parm_ptr);
1687 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1690 parm_table[parmnum].enum_list[i].name)) {
1692 parm_table[parmnum].
1697 if (!parm_table[parmnum].enum_list[i].name) {
1698 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1699 pszParmValue, pszParmName));
1705 if (lp_ctx->flags[parmnum] & FLAG_DEFAULT) {
1706 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1707 /* we have to also unset FLAG_DEFAULT on aliases */
1708 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1709 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1711 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1712 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1719 bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
1720 const char *pszParmName, const char *pszParmValue)
1722 int parmnum = map_parameter(pszParmName);
1726 if (strchr(pszParmName, ':')) {
1727 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1729 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1733 /* if the flag has been set on the command line, then don't allow override,
1734 but don't report an error */
1735 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1739 parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1741 return set_variable(lp_ctx, parmnum, parm_ptr,
1742 pszParmName, pszParmValue, lp_ctx);
1745 bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
1746 struct loadparm_service *service,
1747 const char *pszParmName, const char *pszParmValue)
1751 int parmnum = map_parameter(pszParmName);
1754 if (strchr(pszParmName, ':')) {
1755 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1757 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1761 /* if the flag has been set on the command line, then don't allow override,
1762 but don't report an error */
1763 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1767 if (parm_table[parmnum].class == P_GLOBAL) {
1769 ("Global parameter %s found in service section!\n",
1773 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1775 if (!service->copymap)
1776 init_copymap(service);
1778 /* this handles the aliases - set the copymap for other
1779 * entries with the same data pointer */
1780 for (i = 0; parm_table[i].label; i++)
1781 if (parm_table[i].offset == parm_table[parmnum].offset &&
1782 parm_table[i].class == parm_table[parmnum].class)
1783 service->copymap[i] = false;
1785 return set_variable(service, parmnum, parm_ptr, pszParmName,
1786 pszParmValue, lp_ctx);
1790 * Process a parameter.
1793 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1796 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1798 if (lp_ctx->bInGlobalSection)
1799 return lp_do_global_parameter(lp_ctx, pszParmName,
1802 return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
1803 pszParmName, pszParmValue);
1807 variable argument do parameter
1809 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1810 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
1811 const char *pszParmName, const char *fmt, ...)
1818 s = talloc_vasprintf(NULL, fmt, ap);
1820 ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
1827 set a parameter from the commandline - this is called from command line parameter
1828 parsing code. It sets the parameter then marks the parameter as unable to be modified
1829 by smb.conf processing
1831 bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1832 const char *pszParmValue)
1834 int parmnum = map_parameter(pszParmName);
1837 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1840 if (parmnum < 0 && strchr(pszParmName, ':')) {
1841 /* set a parametric option */
1842 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1843 pszParmValue, FLAG_CMDLINE);
1847 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1851 /* reset the CMDLINE flag in case this has been called before */
1852 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1854 if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1858 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1860 /* we have to also set FLAG_CMDLINE on aliases */
1861 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1862 lp_ctx->flags[i] |= FLAG_CMDLINE;
1864 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1865 lp_ctx->flags[i] |= FLAG_CMDLINE;
1872 set a option from the commandline in 'a=b' format. Use to support --option
1874 bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
1892 ret = lp_set_cmdline(lp_ctx, s, p+1);
1898 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1901 * Print a parameter of the specified type.
1904 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1910 for (i = 0; p->enum_list[i].name; i++) {
1911 if (*(int *)ptr == p->enum_list[i].value) {
1913 p->enum_list[i].name);
1920 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1925 fprintf(f, "%d", *(int *)ptr);
1929 fprintf(f, "0%o", *(int *)ptr);
1933 if ((char ***)ptr && *(char ***)ptr) {
1934 char **list = *(char ***)ptr;
1936 for (; *list; list++)
1937 fprintf(f, "%s%s", *list,
1938 ((*(list+1))?", ":""));
1944 if (*(char **)ptr) {
1945 fprintf(f, "%s", *(char **)ptr);
1952 * Check if two parameters are equal.
1955 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1959 return (*((int *)ptr1) == *((int *)ptr2));
1965 return (*((int *)ptr1) == *((int *)ptr2));
1968 return str_list_equal((const char **)(*(char ***)ptr1),
1969 (const char **)(*(char ***)ptr2));
1974 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1979 return (p1 == p2 || strequal(p1, p2));
1986 * Process a new section (service).
1988 * At this stage all sections are services.
1989 * Later we'll have special sections that permit server parameters to be set.
1990 * Returns True on success, False on failure.
1993 static bool do_section(const char *pszSectionName, void *userdata)
1995 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1997 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1998 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2001 /* if we've just struck a global section, note the fact. */
2002 lp_ctx->bInGlobalSection = isglobal;
2004 /* check for multiple global sections */
2005 if (lp_ctx->bInGlobalSection) {
2006 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
2010 /* if we have a current service, tidy it up before moving on */
2013 if (lp_ctx->currentService != NULL)
2014 bRetval = service_ok(lp_ctx->currentService);
2016 /* if all is still well, move to the next record in the services array */
2018 /* We put this here to avoid an odd message order if messages are */
2019 /* issued by the post-processing of a previous section. */
2020 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2022 if ((lp_ctx->currentService = lp_add_service(lp_ctx, &sDefault,
2025 DEBUG(0, ("Failed to add a new service\n"));
2035 * Determine if a partcular base parameter is currentl set to the default value.
2038 static bool is_default(int i)
2040 void *def_ptr = ((char *)&sDefault) + parm_table[i].offset;
2041 if (!defaults_saved)
2043 switch (parm_table[i].type) {
2045 return str_list_equal((const char **)parm_table[i].def.lvalue,
2046 (const char **)def_ptr);
2049 return strequal(parm_table[i].def.svalue,
2052 return parm_table[i].def.bvalue ==
2058 return parm_table[i].def.ivalue ==
2065 *Display the contents of the global structure.
2068 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2072 struct param_opt *data;
2074 fprintf(f, "# Global parameters\n[global]\n");
2076 for (i = 0; parm_table[i].label; i++)
2077 if (parm_table[i].class == P_GLOBAL &&
2078 parm_table[i].offset != -1 &&
2079 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2080 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2082 fprintf(f, "\t%s = ", parm_table[i].label);
2083 print_parameter(&parm_table[i], lp_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2086 if (lp_ctx->globals->param_opt != NULL) {
2087 for (data = lp_ctx->globals->param_opt; data;
2088 data = data->next) {
2089 fprintf(f, "\t%s = %s\n", data->key, data->value);
2096 * Display the contents of a single services record.
2099 static void dump_a_service(struct loadparm_service * pService, FILE * f)
2102 struct param_opt *data;
2104 if (pService != &sDefault)
2105 fprintf(f, "\n[%s]\n", pService->szService);
2107 for (i = 0; parm_table[i].label; i++)
2108 if (parm_table[i].class == P_LOCAL &&
2109 parm_table[i].offset != -1 &&
2110 (*parm_table[i].label != '-') &&
2111 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2112 if (pService == &sDefault) {
2113 if (defaults_saved && is_default(i))
2116 if (equal_parameter(parm_table[i].type,
2117 ((char *)pService) +
2118 parm_table[i].offset,
2119 ((char *)&sDefault) +
2120 parm_table[i].offset))
2124 fprintf(f, "\t%s = ", parm_table[i].label);
2125 print_parameter(&parm_table[i],
2126 ((char *)pService) + parm_table[i].offset, f);
2129 if (pService->param_opt != NULL) {
2130 for (data = pService->param_opt; data; data = data->next) {
2131 fprintf(f, "\t%s = %s\n", data->key, data->value);
2136 bool lp_dump_a_parameter(struct loadparm_context *lp_ctx,
2137 struct loadparm_service *service,
2138 const char *parm_name, FILE * f)
2140 struct parm_struct *parm;
2143 parm = lp_parm_struct(parm_name);
2148 ptr = lp_parm_ptr(lp_ctx, service,parm);
2150 print_parameter(parm, ptr, f);
2156 * Return info about the next service in a service. snum==-1 gives the globals.
2157 * Return NULL when out of parameters.
2160 struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2164 /* do the globals */
2165 for (; parm_table[*i].label; (*i)++) {
2166 if (parm_table[*i].offset == -1
2167 || (*parm_table[*i].label == '-'))
2171 && (parm_table[*i].offset ==
2172 parm_table[(*i) - 1].offset))
2175 return &parm_table[(*i)++];
2178 struct loadparm_service *pService = lp_ctx->services[snum];
2180 for (; parm_table[*i].label; (*i)++) {
2181 if (parm_table[*i].class == P_LOCAL &&
2182 parm_table[*i].offset != -1 &&
2183 (*parm_table[*i].label != '-') &&
2185 (parm_table[*i].offset !=
2186 parm_table[(*i) - 1].offset)))
2188 if (allparameters ||
2189 !equal_parameter(parm_table[*i].type,
2190 ((char *)pService) +
2191 parm_table[*i].offset,
2192 ((char *)&sDefault) +
2193 parm_table[*i].offset))
2195 return &parm_table[(*i)++];
2206 * Auto-load some home services.
2208 static void lp_add_auto_services(struct loadparm_context *lp_ctx,
2216 * Unload unused services.
2219 void lp_killunused(struct loadparm_context *lp_ctx,
2220 struct smbsrv_connection *smb,
2221 bool (*snumused) (struct smbsrv_connection *, int))
2224 for (i = 0; i < lp_ctx->iNumServices; i++) {
2225 if (lp_ctx->services[i] == NULL)
2228 if (!snumused || !snumused(smb, i)) {
2229 talloc_free(lp_ctx->services[i]);
2230 lp_ctx->services[i] = NULL;
2236 static int lp_destructor(struct loadparm_context *lp_ctx)
2238 struct param_opt *data;
2240 if (lp_ctx->globals->param_opt != NULL) {
2241 struct param_opt *next;
2242 for (data = lp_ctx->globals->param_opt; data; data=next) {
2244 if (data->flags & FLAG_CMDLINE) continue;
2245 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2254 * Initialise the global parameter structure.
2256 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2260 struct loadparm_context *lp_ctx;
2262 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2266 talloc_set_destructor(lp_ctx, lp_destructor);
2267 lp_ctx->bInGlobalSection = true;
2268 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
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 *)&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 web kdc drepl winbind");
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, "template shell", "/bin/false");
2389 lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2390 lp_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2392 lp_do_global_parameter(lp_ctx, "client signing", "Yes");
2393 lp_do_global_parameter(lp_ctx, "server signing", "auto");
2395 lp_do_global_parameter(lp_ctx, "use spnego", "True");
2397 lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
2398 lp_do_global_parameter(lp_ctx, "nbt port", "137");
2399 lp_do_global_parameter(lp_ctx, "dgram port", "138");
2400 lp_do_global_parameter(lp_ctx, "cldap port", "389");
2401 lp_do_global_parameter(lp_ctx, "krb5 port", "88");
2402 lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
2403 lp_do_global_parameter(lp_ctx, "web port", "901");
2404 lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
2406 lp_do_global_parameter(lp_ctx, "nt status support", "True");
2408 lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2409 lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
2411 lp_do_global_parameter(lp_ctx, "tls enabled", "True");
2412 lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2413 lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2414 lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2415 lp_do_global_parameter_var(lp_ctx, "js include", "%s", dyn_JSDIR);
2416 lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2419 lp_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2421 for (i = 0; parm_table[i].label; i++) {
2422 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2423 lp_ctx->flags[i] |= FLAG_DEFAULT;
2430 const char *lp_configfile(struct loadparm_context *lp_ctx)
2432 return lp_ctx->szConfigFile;
2435 bool lp_load_default(struct loadparm_context *lp_ctx)
2437 return lp_load(lp_ctx, dyn_CONFIGFILE);
2441 * Load the services array from the services file.
2443 * Return True on success, False on failure.
2445 bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
2450 filename = talloc_strdup(lp_ctx, filename);
2452 lp_ctx->szConfigFile = filename;
2454 lp_ctx->bInGlobalSection = true;
2455 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2456 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
2458 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2460 /* We get sections first, so have to start 'behind' to make up */
2461 lp_ctx->currentService = NULL;
2462 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2464 /* finish up the last section */
2465 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2467 if (lp_ctx->currentService != NULL)
2468 bRetval = service_ok(lp_ctx->currentService);
2470 lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
2472 lp_add_hidden(lp_ctx, "IPC$", "IPC");
2473 lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
2475 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2476 lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2479 panic_action = lp_ctx->globals->panic_action;
2481 reload_charcnv(lp_ctx);
2483 /* FIXME: Check locale in environment for this: */
2484 if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
2485 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
2487 d_set_iconv((smb_iconv_t)-1);
2493 * Return the max number of services.
2496 int lp_numservices(struct loadparm_context *lp_ctx)
2498 return lp_ctx->iNumServices;
2502 * Display the contents of the services array in human-readable form.
2505 void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2511 defaults_saved = false;
2513 dump_globals(lp_ctx, f, show_defaults);
2515 dump_a_service(&sDefault, f);
2517 for (iService = 0; iService < maxtoprint; iService++)
2518 lp_dump_one(f, show_defaults, lp_ctx->services[iService]);
2522 * Display the contents of one service in human-readable form.
2524 void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service)
2526 if (service != NULL) {
2527 if (service->szService[0] == '\0')
2529 dump_a_service(service, f);
2533 struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
2536 return lp_ctx->services[snum];
2539 struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
2540 const char *service_name)
2545 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2546 if (lp_ctx->services[iService] &&
2547 lp_ctx->services[iService]->szService) {
2549 * The substitution here is used to support %U is
2552 serviceName = standard_sub_basic(
2553 lp_ctx->services[iService],
2554 lp_ctx->services[iService]->szService);
2555 if (strequal(serviceName, service_name))
2556 return lp_ctx->services[iService];
2560 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
2566 * A useful volume label function.
2568 const char *volume_label(struct loadparm_service *service)
2570 const char *ret = lp_volume(service);
2572 return lp_servicename(service);
2578 * If we are PDC then prefer us as DMB
2580 const char *lp_printername(struct loadparm_service *service)
2582 const char *ret = _lp_printername(service);
2583 if (ret == NULL || (ret != NULL && *ret == '\0'))
2584 ret = lp_const_servicename(service);
2591 * Return the max print jobs per queue.
2593 int lp_maxprintjobs(struct loadparm_service *service)
2595 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault.iMaxPrintJobs;
2596 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2597 maxjobs = PRINT_MAX_JOBID - 1;
2602 struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx)
2604 if (lp_ctx == NULL) {
2605 static struct smb_iconv_convenience *fallback_ic = NULL;
2606 if (fallback_ic == NULL)
2607 fallback_ic = smb_iconv_convenience_init(talloc_autofree_context(),
2608 "CP850", "UTF8", true);
2611 return lp_ctx->iconv_convenience;
2614 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2616 talloc_free(lp_ctx->iconv_convenience);
2617 lp_ctx->iconv_convenience = smb_iconv_convenience_init_lp(lp_ctx, lp_ctx);
2620 void lp_smbcli_options(struct loadparm_context *lp_ctx,
2621 struct smbcli_options *options)
2623 options->max_xmit = lp_max_xmit(lp_ctx);
2624 options->max_mux = lp_maxmux(lp_ctx);
2625 options->use_spnego = lp_nt_status_support(lp_ctx) && lp_use_spnego(lp_ctx);
2626 options->signing = lp_client_signing(lp_ctx);
2627 options->request_timeout = SMB_REQUEST_TIMEOUT;
2628 options->ntstatus_support = lp_nt_status_support(lp_ctx);
2629 options->max_protocol = lp_cli_maxprotocol(lp_ctx);
2630 options->unicode = lp_unicode(lp_ctx);
2631 options->use_oplocks = false;
2632 options->use_level2_oplocks = false;