smbprinting: fix wrong == in shell tests
[Samba/gebeck_regimport.git] / source4 / param / loadparm.c
blob55cb45eaedef0433d8be428717c7afc25e8a8d2f
1 /*
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/>.
30 * Load parameters.
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.
36 * To add a parameter:
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
45 * Notes:
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
51 * careful!
55 #include "includes.h"
56 #include "version.h"
57 #include "dynconfig/dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "smb_server/smb_server.h"
62 #include "libcli/raw/signing.h"
63 #include "../lib/util/dlinklist.h"
64 #include "../lib/util/parmlist.h"
65 #include "param/param.h"
66 #include "param/loadparm.h"
67 #include "libcli/raw/libcliraw.h"
68 #include "rpc_server/common/common.h"
69 #include "lib/socket/socket.h"
70 #include "auth/gensec/gensec.h"
72 #define standard_sub_basic talloc_strdup
74 static bool do_parameter(const char *, const char *, void *);
75 static bool defaults_saved = false;
77 /**
78 * This structure describes global (ie., server-wide) parameters.
80 struct loadparm_global
82 enum server_role server_role;
83 enum sid_generator sid_generator;
85 const char **smb_ports;
86 char *ncalrpc_dir;
87 char *dos_charset;
88 char *unix_charset;
89 char *display_charset;
90 char *szLockDir;
91 char *szModulesDir;
92 char *szPidDir;
93 char *szSetupDir;
94 char *szServerString;
95 char *szAutoServices;
96 char *szPasswdChat;
97 char *szShareBackend;
98 char *szSAM_URL;
99 char *szIDMAP_URL;
100 char *szSECRETS_URL;
101 char *szSPOOLSS_URL;
102 char *szWINS_CONFIG_URL;
103 char *szWINS_URL;
104 char *szPrivateDir;
105 const char **szPasswordServers;
106 char *szSocketOptions;
107 char *szRealm;
108 char *szRealm_upper;
109 char *szRealm_lower;
110 const char **szWINSservers;
111 const char **szInterfaces;
112 char *szSocketAddress;
113 char *szAnnounceVersion; /* This is initialised in init_globals */
114 char *szWorkgroup;
115 char *szNetbiosName;
116 const char **szNetbiosAliases;
117 char *szNetbiosScope;
118 char *szDomainOtherSIDs;
119 const char **szNameResolveOrder;
120 const char **dcerpc_ep_servers;
121 const char **server_services;
122 char *ntptr_providor;
123 char *szWinbindSeparator;
124 char *szWinbinddPrivilegedSocketDirectory;
125 char *szWinbinddSocketDirectory;
126 char *szTemplateShell;
127 char *szTemplateHomedir;
128 int bWinbindSealedPipes;
129 int bIdmapTrustedOnly;
130 int tls_enabled;
131 char *tls_keyfile;
132 char *tls_certfile;
133 char *tls_cafile;
134 char *tls_crlfile;
135 char *tls_dhpfile;
136 char *logfile;
137 char *panic_action;
138 int max_mux;
139 int debuglevel;
140 int max_xmit;
141 int pwordlevel;
142 int srv_maxprotocol;
143 int srv_minprotocol;
144 int cli_maxprotocol;
145 int cli_minprotocol;
146 int security;
147 int paranoid_server_security;
148 int max_wins_ttl;
149 int min_wins_ttl;
150 int announce_as; /* This is initialised in init_globals */
151 int nbt_port;
152 int dgram_port;
153 int cldap_port;
154 int krb5_port;
155 int kpasswd_port;
156 int web_port;
157 char *socket_options;
158 int bWINSsupport;
159 int bWINSdnsProxy;
160 char *szWINSHook;
161 int bLocalMaster;
162 int bPreferredMaster;
163 int bEncryptPasswords;
164 int bNullPasswords;
165 int bObeyPamRestrictions;
166 int bLargeReadwrite;
167 int bReadRaw;
168 int bWriteRaw;
169 int bTimeServer;
170 int bBindInterfacesOnly;
171 int bNTSmbSupport;
172 int bNTStatusSupport;
173 int bLanmanAuth;
174 int bNTLMAuth;
175 int bUseSpnego;
176 int server_signing;
177 int client_signing;
178 int bClientPlaintextAuth;
179 int bClientLanManAuth;
180 int bClientNTLMv2Auth;
181 int client_use_spnego_principal;
182 int bHostMSDfs;
183 int bUnicode;
184 int bUnixExtensions;
185 int bDisableNetbios;
186 int bRpcBigEndian;
187 char *szNTPSignDSocketDirectory;
188 const char **szRNDCCommand;
189 const char **szDNSUpdateCommand;
190 const char **szSPNUpdateCommand;
191 char *szNSUpdateCommand;
192 struct parmlist_entry *param_opt;
197 * This structure describes a single service.
199 struct loadparm_service
201 char *szService;
202 char *szPath;
203 char *szCopy;
204 char *szInclude;
205 char *szPrintername;
206 char **szHostsallow;
207 char **szHostsdeny;
208 char *comment;
209 char *volume;
210 char *fstype;
211 char **ntvfs_handler;
212 int iMaxPrintJobs;
213 int iMaxConnections;
214 int iCSCPolicy;
215 int bAvailable;
216 int bBrowseable;
217 int bRead_only;
218 int bPrint_ok;
219 int bMap_system;
220 int bMap_hidden;
221 int bMap_archive;
222 int bStrictLocking;
223 int bOplocks;
224 int iCreate_mask;
225 int iCreate_force_mode;
226 int iDir_mask;
227 int iDir_force_mode;
228 int *copymap;
229 int bMSDfsRoot;
230 int bStrictSync;
231 int bCIFileSystem;
232 struct parmlist_entry *param_opt;
234 char dummy[3]; /* for alignment */
238 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
241 /* prototypes for the special type handlers */
242 static bool handle_include(struct loadparm_context *lp_ctx,
243 const char *pszParmValue, char **ptr);
244 static bool handle_realm(struct loadparm_context *lp_ctx,
245 const char *pszParmValue, char **ptr);
246 static bool handle_copy(struct loadparm_context *lp_ctx,
247 const char *pszParmValue, char **ptr);
248 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
249 const char *pszParmValue, char **ptr);
250 static bool handle_logfile(struct loadparm_context *lp_ctx,
251 const char *pszParmValue, char **ptr);
253 static const struct enum_list enum_protocol[] = {
254 {PROTOCOL_SMB2, "SMB2"},
255 {PROTOCOL_NT1, "NT1"},
256 {PROTOCOL_LANMAN2, "LANMAN2"},
257 {PROTOCOL_LANMAN1, "LANMAN1"},
258 {PROTOCOL_CORE, "CORE"},
259 {PROTOCOL_COREPLUS, "COREPLUS"},
260 {PROTOCOL_COREPLUS, "CORE+"},
261 {-1, NULL}
264 static const struct enum_list enum_security[] = {
265 {SEC_SHARE, "SHARE"},
266 {SEC_USER, "USER"},
267 {-1, NULL}
270 static const struct enum_list enum_announce_as[] = {
271 {ANNOUNCE_AS_NT_SERVER, "NT"},
272 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
273 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
274 {ANNOUNCE_AS_WIN95, "win95"},
275 {ANNOUNCE_AS_WFW, "WfW"},
276 {-1, NULL}
279 static const struct enum_list enum_bool_auto[] = {
280 {false, "No"},
281 {false, "False"},
282 {false, "0"},
283 {true, "Yes"},
284 {true, "True"},
285 {true, "1"},
286 {Auto, "Auto"},
287 {-1, NULL}
290 /* Client-side offline caching policy types */
291 enum csc_policy {
292 CSC_POLICY_MANUAL=0,
293 CSC_POLICY_DOCUMENTS=1,
294 CSC_POLICY_PROGRAMS=2,
295 CSC_POLICY_DISABLE=3
298 static const struct enum_list enum_csc_policy[] = {
299 {CSC_POLICY_MANUAL, "manual"},
300 {CSC_POLICY_DOCUMENTS, "documents"},
301 {CSC_POLICY_PROGRAMS, "programs"},
302 {CSC_POLICY_DISABLE, "disable"},
303 {-1, NULL}
306 /* SMB signing types. */
307 static const struct enum_list enum_smb_signing_vals[] = {
308 {SMB_SIGNING_OFF, "No"},
309 {SMB_SIGNING_OFF, "False"},
310 {SMB_SIGNING_OFF, "0"},
311 {SMB_SIGNING_OFF, "Off"},
312 {SMB_SIGNING_OFF, "disabled"},
313 {SMB_SIGNING_SUPPORTED, "Yes"},
314 {SMB_SIGNING_SUPPORTED, "True"},
315 {SMB_SIGNING_SUPPORTED, "1"},
316 {SMB_SIGNING_SUPPORTED, "On"},
317 {SMB_SIGNING_SUPPORTED, "enabled"},
318 {SMB_SIGNING_REQUIRED, "required"},
319 {SMB_SIGNING_REQUIRED, "mandatory"},
320 {SMB_SIGNING_REQUIRED, "force"},
321 {SMB_SIGNING_REQUIRED, "forced"},
322 {SMB_SIGNING_REQUIRED, "enforced"},
323 {SMB_SIGNING_AUTO, "auto"},
324 {-1, NULL}
327 static const struct enum_list enum_server_role[] = {
328 {ROLE_STANDALONE, "standalone"},
329 {ROLE_DOMAIN_MEMBER, "member server"},
330 {ROLE_DOMAIN_MEMBER, "member"},
331 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
332 {ROLE_DOMAIN_CONTROLLER, "dc"},
333 {-1, NULL}
336 static const struct enum_list enum_sid_generator[] = {
337 {SID_GENERATOR_INTERNAL, "internal"},
338 {SID_GENERATOR_BACKEND, "backend"},
339 {-1, NULL}
342 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
343 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
345 static struct parm_struct parm_table[] = {
346 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
347 {"sid generator", P_ENUM, P_GLOBAL, GLOBAL_VAR(sid_generator), NULL, enum_sid_generator},
349 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
350 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
351 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
352 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
353 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
354 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
355 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
356 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
357 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), handle_realm, NULL},
358 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
359 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
360 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
361 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
362 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
363 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
364 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
365 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
366 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
367 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
369 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
370 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
371 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
372 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
373 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
374 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
375 {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
376 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
377 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
378 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
379 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
380 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
381 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
382 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
383 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
384 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
385 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
386 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
387 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
388 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
390 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
392 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
393 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
394 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
395 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
397 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
398 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
400 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
401 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
402 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
404 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
405 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
406 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
407 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
408 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
409 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
410 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
411 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
412 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
413 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
414 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
415 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
416 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
417 {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
418 {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
419 {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
420 {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
421 {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
422 {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
423 {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
424 {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
425 {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
427 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
429 {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
430 {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
431 {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
432 {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
434 {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
435 {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
436 {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
437 {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
438 {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
439 {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
440 {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals},
441 {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals},
442 {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
444 {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
445 {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
446 {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
448 {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
449 {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL},
451 {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
452 {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
453 {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
455 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
456 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
458 {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
459 {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
460 {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
462 {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
463 {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
464 {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
465 {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
466 {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
468 {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
469 {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
470 {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
471 {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL},
473 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
475 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
476 {"oplocks", P_BOOL, P_LOCAL, LOCAL_VAR(bOplocks), NULL, NULL},
478 {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
479 {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
480 {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
481 {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
482 {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
483 {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
484 {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL},
485 {"setup directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szSetupDir), NULL, NULL},
487 {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
488 {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
489 {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
491 {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
492 {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
493 {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
495 {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
497 {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
498 {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
499 {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
500 {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
501 {"winbindd privileged socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory), NULL, NULL },
502 {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
503 {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
504 {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
505 {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
507 {"ntp signd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szNTPSignDSocketDirectory), NULL, NULL },
508 {"rndc command", P_LIST, P_GLOBAL, GLOBAL_VAR(szRNDCCommand), NULL, NULL },
509 {"dns update command", P_LIST, P_GLOBAL, GLOBAL_VAR(szDNSUpdateCommand), NULL, NULL },
510 {"spn update command", P_LIST, P_GLOBAL, GLOBAL_VAR(szSPNUpdateCommand), NULL, NULL },
511 {"nsupdate command", P_STRING, P_GLOBAL, GLOBAL_VAR(szNSUpdateCommand), NULL, NULL },
513 {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
517 /* local variables */
518 struct loadparm_context {
519 const char *szConfigFile;
520 struct loadparm_global *globals;
521 struct loadparm_service **services;
522 struct loadparm_service *sDefault;
523 struct smb_iconv_convenience *iconv_convenience;
524 int iNumServices;
525 struct loadparm_service *currentService;
526 bool bInGlobalSection;
527 struct file_lists {
528 struct file_lists *next;
529 char *name;
530 char *subfname;
531 time_t modtime;
532 } *file_lists;
533 unsigned int flags[NUMPARAMETERS];
534 bool loaded;
535 bool refuse_free;
539 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
541 return lp_ctx->sDefault;
545 return the parameter table
547 struct parm_struct *lpcfg_parm_table(void)
549 return parm_table;
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;
564 char *ret;
565 #endif
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? */
572 #if 0
573 DEBUG(10, ("lp_string(%s)\n", s));
574 #endif
576 #if 0 /* until REWRITE done to make thread-safe */
577 if (!lp_talloc)
578 lp_talloc = talloc_init("lp_talloc");
580 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
582 if (!ret)
583 return NULL;
585 if (!s)
586 *ret = 0;
587 else
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);
596 return (ret);
597 #endif
598 return s;
602 In this section all the functions that are used to access the
603 parameters from the rest of the program are defined
607 * the creation of separate lpcfg_*() and lp_*() functions is to allow
608 * for code compatibility between existing Samba4 and Samba3 code.
611 /* this global context supports the lp_*() function varients */
612 static struct loadparm_context *global_loadparm_context;
614 #define lpcfg_default_service global_loadparm_context->sDefault
615 #define lpcfg_global_service(i) global_loadparm_context->services[i]
617 #define FN_GLOBAL_STRING(fn_name,var_name) \
618 _PUBLIC_ const char *lpcfg_ ## 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) : "";}
620 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
621 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name ? lp_ctx->globals->var_name : "";}
623 #define FN_GLOBAL_LIST(fn_name,var_name) \
624 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
626 #define FN_GLOBAL_BOOL(fn_name,var_name) \
627 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
629 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
630 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
632 #define FN_LOCAL_STRING(fn_name,val) \
633 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)));}
635 #define FN_LOCAL_LIST(fn_name,val) \
636 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
638 #define FN_LOCAL_BOOL(fn_name,val) \
639 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
641 #define FN_LOCAL_INTEGER(fn_name,val) \
642 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
644 FN_GLOBAL_INTEGER(server_role, server_role)
645 FN_GLOBAL_INTEGER(sid_generator, sid_generator)
646 FN_GLOBAL_LIST(smb_ports, smb_ports)
647 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
648 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
649 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
650 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
651 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
652 FN_GLOBAL_INTEGER(web_port, web_port)
653 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
654 FN_GLOBAL_STRING(share_backend, szShareBackend)
655 FN_GLOBAL_STRING(sam_url, szSAM_URL)
656 FN_GLOBAL_STRING(idmap_url, szIDMAP_URL)
657 FN_GLOBAL_STRING(secrets_url, szSECRETS_URL)
658 FN_GLOBAL_STRING(spoolss_url, szSPOOLSS_URL)
659 FN_GLOBAL_STRING(wins_config_url, szWINS_CONFIG_URL)
660 FN_GLOBAL_STRING(wins_url, szWINS_URL)
661 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
662 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
663 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
664 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
665 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
666 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
667 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
668 FN_GLOBAL_STRING(private_dir, szPrivateDir)
669 FN_GLOBAL_STRING(serverstring, szServerString)
670 FN_GLOBAL_STRING(lockdir, szLockDir)
671 FN_GLOBAL_STRING(modulesdir, szModulesDir)
672 FN_GLOBAL_STRING(setupdir, szSetupDir)
673 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
674 FN_GLOBAL_STRING(dos_charset, dos_charset)
675 FN_GLOBAL_STRING(unix_charset, unix_charset)
676 FN_GLOBAL_STRING(display_charset, display_charset)
677 FN_GLOBAL_STRING(piddir, szPidDir)
678 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
679 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
680 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
681 FN_GLOBAL_STRING(nsupdate_command, szNSUpdateCommand)
682 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
683 FN_GLOBAL_LIST(server_services, server_services)
684 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
685 FN_GLOBAL_STRING(auto_services, szAutoServices)
686 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
687 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
688 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
689 FN_GLOBAL_STRING(realm, szRealm_upper)
690 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
691 FN_GLOBAL_STRING(socket_options, socket_options)
692 FN_GLOBAL_STRING(workgroup, szWorkgroup)
693 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
694 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
695 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
696 FN_GLOBAL_LIST(interfaces, szInterfaces)
697 FN_GLOBAL_STRING(socket_address, szSocketAddress)
698 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
699 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
700 FN_GLOBAL_BOOL(wins_support, bWINSsupport)
701 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
702 FN_GLOBAL_STRING(wins_hook, szWINSHook)
703 FN_GLOBAL_BOOL(local_master, bLocalMaster)
704 FN_GLOBAL_BOOL(readraw, bReadRaw)
705 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
706 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
707 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
708 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
709 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
710 FN_GLOBAL_BOOL(time_server, bTimeServer)
711 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
712 FN_GLOBAL_BOOL(unicode, bUnicode)
713 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
714 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
715 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
716 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
717 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
718 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
719 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
720 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
721 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
722 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
723 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
724 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
725 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
726 FN_GLOBAL_INTEGER(maxmux, max_mux)
727 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
728 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
729 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
730 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
731 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
732 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
733 FN_GLOBAL_INTEGER(security, security)
734 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
735 FN_GLOBAL_INTEGER(announce_as, announce_as)
737 FN_LOCAL_STRING(pathname, szPath)
738 FN_LOCAL_LIST(hostsallow, szHostsallow)
739 FN_LOCAL_LIST(hostsdeny, szHostsdeny)
740 FN_LOCAL_STRING(comment, comment)
741 FN_LOCAL_STRING(fstype, fstype)
742 FN_LOCAL_LIST(ntvfs_handler, ntvfs_handler)
743 FN_LOCAL_BOOL(msdfs_root, bMSDfsRoot)
744 FN_LOCAL_BOOL(browseable, bBrowseable)
745 FN_LOCAL_BOOL(readonly, bRead_only)
746 FN_LOCAL_BOOL(print_ok, bPrint_ok)
747 FN_LOCAL_BOOL(map_hidden, bMap_hidden)
748 FN_LOCAL_BOOL(map_archive, bMap_archive)
749 FN_LOCAL_BOOL(strict_locking, bStrictLocking)
750 FN_LOCAL_BOOL(oplocks, bOplocks)
751 FN_LOCAL_BOOL(strict_sync, bStrictSync)
752 FN_LOCAL_BOOL(ci_filesystem, bCIFileSystem)
753 FN_LOCAL_BOOL(map_system, bMap_system)
754 FN_LOCAL_INTEGER(max_connections, iMaxConnections)
755 FN_LOCAL_INTEGER(csc_policy, iCSCPolicy)
756 FN_LOCAL_INTEGER(create_mask, iCreate_mask)
757 FN_LOCAL_INTEGER(force_create_mode, iCreate_force_mode)
758 FN_LOCAL_INTEGER(dir_mask, iDir_mask)
759 FN_LOCAL_INTEGER(force_dir_mode, iDir_force_mode)
760 FN_GLOBAL_INTEGER(server_signing, server_signing)
761 FN_GLOBAL_INTEGER(client_signing, client_signing)
763 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
765 /* local prototypes */
766 static int map_parameter(const char *pszParmName);
767 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
768 const char *pszServiceName);
769 static void copy_service(struct loadparm_service *pserviceDest,
770 struct loadparm_service *pserviceSource,
771 int *pcopymapDest);
772 static bool service_ok(struct loadparm_service *service);
773 static bool do_section(const char *pszSectionName, void *);
774 static void init_copymap(struct loadparm_service *pservice);
776 /* This is a helper function for parametrical options support. */
777 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
778 /* Actual parametrical functions are quite simple */
779 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
780 struct loadparm_service *service,
781 const char *type, const char *option)
783 char *vfskey = NULL;
784 struct parmlist_entry *data;
786 if (lp_ctx == NULL)
787 return NULL;
789 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
791 asprintf(&vfskey, "%s:%s", type, option);
792 if (vfskey == NULL) return NULL;
793 strlower(vfskey);
795 while (data) {
796 if (strcmp(data->key, vfskey) == 0) {
797 free(vfskey);
798 return data->value;
800 data = data->next;
803 if (service != NULL) {
804 /* Try to fetch the same option but from globals */
805 /* but only if we are not already working with globals */
806 for (data = lp_ctx->globals->param_opt; data;
807 data = data->next) {
808 if (strcmp(data->key, vfskey) == 0) {
809 free(vfskey);
810 return data->value;
815 free(vfskey);
817 return NULL;
822 * convenience routine to return int parameters.
824 static int lp_int(const char *s)
827 if (!s) {
828 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
829 return -1;
832 return strtol(s, NULL, 0);
836 * convenience routine to return unsigned long parameters.
838 static int lp_ulong(const char *s)
841 if (!s) {
842 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
843 return -1;
846 return strtoul(s, NULL, 0);
850 * convenience routine to return unsigned long parameters.
852 static double lp_double(const char *s)
855 if (!s) {
856 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
857 return -1;
860 return strtod(s, NULL);
864 * convenience routine to return boolean parameters.
866 static bool lp_bool(const char *s)
868 bool ret = false;
870 if (!s) {
871 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
872 return false;
875 if (!set_boolean(s, &ret)) {
876 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
877 return false;
880 return ret;
885 * Return parametric option from a given service. Type is a part of option before ':'
886 * Parametric option has following syntax: 'Type: option = value'
887 * Returned value is allocated in 'lp_talloc' context
890 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
891 struct loadparm_service *service, const char *type,
892 const char *option)
894 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
896 if (value)
897 return lp_string(value);
899 return NULL;
903 * Return parametric option from a given service. Type is a part of option before ':'
904 * Parametric option has following syntax: 'Type: option = value'
905 * Returned value is allocated in 'lp_talloc' context
908 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
909 struct loadparm_context *lp_ctx,
910 struct loadparm_service *service,
911 const char *type,
912 const char *option, const char *separator)
914 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
916 if (value != NULL)
917 return (const char **)str_list_make(mem_ctx, value, separator);
919 return NULL;
923 * Return parametric option from a given service. Type is a part of option before ':'
924 * Parametric option has following syntax: 'Type: option = value'
927 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
928 struct loadparm_service *service, const char *type,
929 const char *option, int default_v)
931 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
933 if (value)
934 return lp_int(value);
936 return default_v;
940 * Return parametric option from a given service. Type is a part of
941 * option before ':'.
942 * Parametric option has following syntax: 'Type: option = value'.
945 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
946 struct loadparm_service *service, const char *type,
947 const char *option, int default_v)
949 uint64_t bval;
951 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
953 if (value && conv_str_size(value, &bval)) {
954 if (bval <= INT_MAX) {
955 return (int)bval;
959 return default_v;
963 * Return parametric option from a given service.
964 * Type is a part of option before ':'
965 * Parametric option has following syntax: 'Type: option = value'
967 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
968 struct loadparm_service *service, const char *type,
969 const char *option, unsigned long default_v)
971 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
973 if (value)
974 return lp_ulong(value);
976 return default_v;
980 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
981 struct loadparm_service *service, const char *type,
982 const char *option, double default_v)
984 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
986 if (value != NULL)
987 return lp_double(value);
989 return default_v;
993 * Return parametric option from a given service. Type is a part of option before ':'
994 * Parametric option has following syntax: 'Type: option = value'
997 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
998 struct loadparm_service *service, const char *type,
999 const char *option, bool default_v)
1001 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1003 if (value != NULL)
1004 return lp_bool(value);
1006 return default_v;
1011 * Initialise a service to the defaults.
1014 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1016 struct loadparm_service *pservice =
1017 talloc_zero(mem_ctx, struct loadparm_service);
1018 copy_service(pservice, sDefault, NULL);
1019 return pservice;
1023 * Set a string value, deallocating any existing space, and allocing the space
1024 * for the string
1026 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1028 talloc_free(*dest);
1030 if (src == NULL)
1031 src = "";
1033 *dest = talloc_strdup(mem_ctx, src);
1034 if ((*dest) == NULL) {
1035 DEBUG(0,("Out of memory in string_init\n"));
1036 return false;
1039 return true;
1045 * Add a new service to the services array initialising it with the given
1046 * service.
1049 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1050 const struct loadparm_service *pservice,
1051 const char *name)
1053 int i;
1054 struct loadparm_service tservice;
1055 int num_to_alloc = lp_ctx->iNumServices + 1;
1056 struct parmlist_entry *data, *pdata;
1058 if (pservice == NULL) {
1059 pservice = lp_ctx->sDefault;
1062 tservice = *pservice;
1064 /* it might already exist */
1065 if (name) {
1066 struct loadparm_service *service = getservicebyname(lp_ctx,
1067 name);
1068 if (service != NULL) {
1069 /* Clean all parametric options for service */
1070 /* They will be added during parsing again */
1071 data = service->param_opt;
1072 while (data) {
1073 pdata = data->next;
1074 talloc_free(data);
1075 data = pdata;
1077 service->param_opt = NULL;
1078 return service;
1082 /* find an invalid one */
1083 for (i = 0; i < lp_ctx->iNumServices; i++)
1084 if (lp_ctx->services[i] == NULL)
1085 break;
1087 /* if not, then create one */
1088 if (i == lp_ctx->iNumServices) {
1089 struct loadparm_service **tsp;
1091 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1093 if (!tsp) {
1094 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1095 return NULL;
1096 } else {
1097 lp_ctx->services = tsp;
1098 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1101 lp_ctx->iNumServices++;
1104 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1105 if (lp_ctx->services[i] == NULL) {
1106 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1107 return NULL;
1109 copy_service(lp_ctx->services[i], &tservice, NULL);
1110 if (name != NULL)
1111 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1112 return lp_ctx->services[i];
1116 * Add a new home service, with the specified home directory, defaults coming
1117 * from service ifrom.
1120 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1121 const char *pszHomename,
1122 struct loadparm_service *default_service,
1123 const char *user, const char *pszHomedir)
1125 struct loadparm_service *service;
1127 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1129 if (service == NULL)
1130 return false;
1132 if (!(*(default_service->szPath))
1133 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1134 service->szPath = talloc_strdup(service, pszHomedir);
1135 } else {
1136 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1139 if (!(*(service->comment))) {
1140 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1142 service->bAvailable = default_service->bAvailable;
1143 service->bBrowseable = default_service->bBrowseable;
1145 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1146 pszHomename, user, service->szPath));
1148 return true;
1152 * Add a new printer service, with defaults coming from service iFrom.
1155 bool lp_add_printer(struct loadparm_context *lp_ctx,
1156 const char *pszPrintername,
1157 struct loadparm_service *default_service)
1159 const char *comment = "From Printcap";
1160 struct loadparm_service *service;
1161 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1163 if (service == NULL)
1164 return false;
1166 /* note that we do NOT default the availability flag to True - */
1167 /* we take it from the default service passed. This allows all */
1168 /* dynamic printers to be disabled by disabling the [printers] */
1169 /* entry (if/when the 'available' keyword is implemented!). */
1171 /* the printer name is set to the service name. */
1172 string_set(service, &service->szPrintername, pszPrintername);
1173 string_set(service, &service->comment, comment);
1174 service->bBrowseable = default_service->bBrowseable;
1175 /* Printers cannot be read_only. */
1176 service->bRead_only = false;
1177 /* Printer services must be printable. */
1178 service->bPrint_ok = true;
1180 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1182 return true;
1186 * Map a parameter's string representation to something we can use.
1187 * Returns False if the parameter string is not recognised, else TRUE.
1190 static int map_parameter(const char *pszParmName)
1192 int iIndex;
1194 if (*pszParmName == '-')
1195 return -1;
1197 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1198 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1199 return iIndex;
1201 /* Warn only if it isn't parametric option */
1202 if (strchr(pszParmName, ':') == NULL)
1203 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1204 /* We do return 'fail' for parametric options as well because they are
1205 stored in different storage
1207 return -1;
1212 return the parameter structure for a parameter
1214 struct parm_struct *lpcfg_parm_struct(const char *name)
1216 int parmnum = map_parameter(name);
1217 if (parmnum == -1) return NULL;
1218 return &parm_table[parmnum];
1222 return the parameter pointer for a parameter
1224 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
1225 struct loadparm_service *service, struct parm_struct *parm)
1227 if (service == NULL) {
1228 if (parm->pclass == P_LOCAL)
1229 return ((char *)lp_ctx->sDefault)+parm->offset;
1230 else if (parm->pclass == P_GLOBAL)
1231 return ((char *)lp_ctx->globals)+parm->offset;
1232 else return NULL;
1233 } else {
1234 return ((char *)service) + parm->offset;
1239 * Find a service by name. Otherwise works like get_service.
1242 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1243 const char *pszServiceName)
1245 int iService;
1247 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1248 if (lp_ctx->services[iService] != NULL &&
1249 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1250 return lp_ctx->services[iService];
1253 return NULL;
1257 * Copy a service structure to another.
1258 * If pcopymapDest is NULL then copy all fields
1261 static void copy_service(struct loadparm_service *pserviceDest,
1262 struct loadparm_service *pserviceSource,
1263 int *pcopymapDest)
1265 int i;
1266 bool bcopyall = (pcopymapDest == NULL);
1267 struct parmlist_entry *data, *pdata, *paramo;
1268 bool not_added;
1270 for (i = 0; parm_table[i].label; i++)
1271 if (parm_table[i].offset != -1 && parm_table[i].pclass == P_LOCAL &&
1272 (bcopyall || pcopymapDest[i])) {
1273 void *src_ptr =
1274 ((char *)pserviceSource) + parm_table[i].offset;
1275 void *dest_ptr =
1276 ((char *)pserviceDest) + parm_table[i].offset;
1278 switch (parm_table[i].type) {
1279 case P_BOOL:
1280 *(int *)dest_ptr = *(int *)src_ptr;
1281 break;
1283 case P_INTEGER:
1284 case P_OCTAL:
1285 case P_ENUM:
1286 *(int *)dest_ptr = *(int *)src_ptr;
1287 break;
1289 case P_STRING:
1290 string_set(pserviceDest,
1291 (char **)dest_ptr,
1292 *(char **)src_ptr);
1293 break;
1295 case P_USTRING:
1296 string_set(pserviceDest,
1297 (char **)dest_ptr,
1298 *(char **)src_ptr);
1299 strupper(*(char **)dest_ptr);
1300 break;
1301 case P_LIST:
1302 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
1303 *(const char ***)src_ptr);
1304 break;
1305 default:
1306 break;
1310 if (bcopyall) {
1311 init_copymap(pserviceDest);
1312 if (pserviceSource->copymap)
1313 memcpy((void *)pserviceDest->copymap,
1314 (void *)pserviceSource->copymap,
1315 sizeof(int) * NUMPARAMETERS);
1318 data = pserviceSource->param_opt;
1319 while (data) {
1320 not_added = true;
1321 pdata = pserviceDest->param_opt;
1322 /* Traverse destination */
1323 while (pdata) {
1324 /* If we already have same option, override it */
1325 if (strcmp(pdata->key, data->key) == 0) {
1326 talloc_free(pdata->value);
1327 pdata->value = talloc_reference(pdata,
1328 data->value);
1329 not_added = false;
1330 break;
1332 pdata = pdata->next;
1334 if (not_added) {
1335 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
1336 if (paramo == NULL)
1337 smb_panic("OOM");
1338 paramo->key = talloc_reference(paramo, data->key);
1339 paramo->value = talloc_reference(paramo, data->value);
1340 DLIST_ADD(pserviceDest->param_opt, paramo);
1342 data = data->next;
1347 * Check a service for consistency. Return False if the service is in any way
1348 * incomplete or faulty, else True.
1350 static bool service_ok(struct loadparm_service *service)
1352 bool bRetval;
1354 bRetval = true;
1355 if (service->szService[0] == '\0') {
1356 DEBUG(0, ("The following message indicates an internal error:\n"));
1357 DEBUG(0, ("No service name in service entry.\n"));
1358 bRetval = false;
1361 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1362 /* I can't see why you'd want a non-printable printer service... */
1363 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1364 if (!service->bPrint_ok) {
1365 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1366 service->szService));
1367 service->bPrint_ok = true;
1369 /* [printers] service must also be non-browsable. */
1370 if (service->bBrowseable)
1371 service->bBrowseable = false;
1374 /* If a service is flagged unavailable, log the fact at level 0. */
1375 if (!service->bAvailable)
1376 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1377 service->szService));
1379 return bRetval;
1383 /*******************************************************************
1384 Keep a linked list of all config files so we know when one has changed
1385 it's date and needs to be reloaded.
1386 ********************************************************************/
1388 static void add_to_file_list(struct loadparm_context *lp_ctx,
1389 const char *fname, const char *subfname)
1391 struct file_lists *f = lp_ctx->file_lists;
1393 while (f) {
1394 if (f->name && !strcmp(f->name, fname))
1395 break;
1396 f = f->next;
1399 if (!f) {
1400 f = talloc(lp_ctx, struct file_lists);
1401 if (!f)
1402 return;
1403 f->next = lp_ctx->file_lists;
1404 f->name = talloc_strdup(f, fname);
1405 if (!f->name) {
1406 talloc_free(f);
1407 return;
1409 f->subfname = talloc_strdup(f, subfname);
1410 if (!f->subfname) {
1411 talloc_free(f);
1412 return;
1414 lp_ctx->file_lists = f;
1415 f->modtime = file_modtime(subfname);
1416 } else {
1417 time_t t = file_modtime(subfname);
1418 if (t)
1419 f->modtime = t;
1423 /*******************************************************************
1424 Check if a config file has changed date.
1425 ********************************************************************/
1426 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1428 struct file_lists *f;
1429 DEBUG(6, ("lp_file_list_changed()\n"));
1431 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1432 char *n2;
1433 time_t mod_time;
1435 n2 = standard_sub_basic(lp_ctx, f->name);
1437 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1438 f->name, n2, ctime(&f->modtime)));
1440 mod_time = file_modtime(n2);
1442 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1443 DEBUGADD(6, ("file %s modified: %s\n", n2,
1444 ctime(&mod_time)));
1445 f->modtime = mod_time;
1446 talloc_free(f->subfname);
1447 f->subfname = talloc_strdup(f, n2);
1448 return true;
1451 return false;
1454 /***************************************************************************
1455 Handle the "realm" parameter
1456 ***************************************************************************/
1458 static bool handle_realm(struct loadparm_context *lp_ctx,
1459 const char *pszParmValue, char **ptr)
1461 string_set(lp_ctx, ptr, pszParmValue);
1463 talloc_free(lp_ctx->globals->szRealm_upper);
1464 talloc_free(lp_ctx->globals->szRealm_lower);
1466 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
1467 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
1469 return true;
1472 /***************************************************************************
1473 Handle the include operation.
1474 ***************************************************************************/
1476 static bool handle_include(struct loadparm_context *lp_ctx,
1477 const char *pszParmValue, char **ptr)
1479 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1481 add_to_file_list(lp_ctx, pszParmValue, fname);
1483 string_set(lp_ctx, ptr, fname);
1485 if (file_exist(fname))
1486 return pm_process(fname, do_section, do_parameter, lp_ctx);
1488 DEBUG(2, ("Can't find include file %s\n", fname));
1490 return false;
1493 /***************************************************************************
1494 Handle the interpretation of the copy parameter.
1495 ***************************************************************************/
1497 static bool handle_copy(struct loadparm_context *lp_ctx,
1498 const char *pszParmValue, char **ptr)
1500 bool bRetval;
1501 struct loadparm_service *serviceTemp;
1503 string_set(lp_ctx, ptr, pszParmValue);
1505 bRetval = false;
1507 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1509 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1510 if (serviceTemp == lp_ctx->currentService) {
1511 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1512 } else {
1513 copy_service(lp_ctx->currentService,
1514 serviceTemp,
1515 lp_ctx->currentService->copymap);
1516 bRetval = true;
1518 } else {
1519 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1520 pszParmValue));
1521 bRetval = false;
1524 return bRetval;
1527 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1528 const char *pszParmValue, char **ptr)
1530 DEBUGLEVEL = atoi(pszParmValue);
1532 /* also set in the loadparm table, so querying debug level
1533 works */
1534 *(int *)ptr = DEBUGLEVEL;
1536 return true;
1539 static bool handle_logfile(struct loadparm_context *lp_ctx,
1540 const char *pszParmValue, char **ptr)
1542 if (logfile != NULL) {
1543 free(discard_const_p(char, logfile));
1545 logfile = strdup(pszParmValue);
1546 string_set(lp_ctx, ptr, pszParmValue);
1547 return true;
1550 /***************************************************************************
1551 Initialise a copymap.
1552 ***************************************************************************/
1554 static void init_copymap(struct loadparm_service *pservice)
1556 int i;
1557 talloc_free(pservice->copymap);
1558 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1559 if (pservice->copymap == NULL) {
1560 DEBUG(0,
1561 ("Couldn't allocate copymap!! (size %d)\n",
1562 (int)NUMPARAMETERS));
1563 return;
1565 for (i = 0; i < NUMPARAMETERS; i++)
1566 pservice->copymap[i] = true;
1570 * Process a parametric option
1572 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1573 struct loadparm_service *service,
1574 const char *pszParmName,
1575 const char *pszParmValue, int flags)
1577 struct parmlist_entry *paramo, *data;
1578 char *name;
1579 TALLOC_CTX *mem_ctx;
1581 while (isspace((unsigned char)*pszParmName)) {
1582 pszParmName++;
1585 name = strdup(pszParmName);
1586 if (!name) return false;
1588 strlower(name);
1590 if (service == NULL) {
1591 data = lp_ctx->globals->param_opt;
1592 mem_ctx = lp_ctx->globals;
1593 } else {
1594 data = service->param_opt;
1595 mem_ctx = service;
1598 /* Traverse destination */
1599 for (paramo=data; paramo; paramo=paramo->next) {
1600 /* If we already have the option set, override it unless
1601 it was a command line option and the new one isn't */
1602 if (strcmp(paramo->key, name) == 0) {
1603 if ((paramo->priority & FLAG_CMDLINE) &&
1604 !(flags & FLAG_CMDLINE)) {
1605 return true;
1608 talloc_free(paramo->value);
1609 paramo->value = talloc_strdup(paramo, pszParmValue);
1610 paramo->priority = flags;
1611 free(name);
1612 return true;
1616 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1617 if (!paramo)
1618 smb_panic("OOM");
1619 paramo->key = talloc_strdup(paramo, name);
1620 paramo->value = talloc_strdup(paramo, pszParmValue);
1621 paramo->priority = flags;
1622 if (service == NULL) {
1623 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1624 } else {
1625 DLIST_ADD(service->param_opt, paramo);
1628 free(name);
1630 return true;
1633 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1634 const char *pszParmName, const char *pszParmValue,
1635 struct loadparm_context *lp_ctx, bool on_globals)
1637 int i;
1638 /* if it is a special case then go ahead */
1639 if (parm_table[parmnum].special) {
1640 bool ret;
1641 ret = parm_table[parmnum].special(lp_ctx, pszParmValue,
1642 (char **)parm_ptr);
1643 if (!ret) {
1644 return false;
1646 goto mark_non_default;
1649 /* now switch on the type of variable it is */
1650 switch (parm_table[parmnum].type)
1652 case P_BOOL: {
1653 bool b;
1654 if (!set_boolean(pszParmValue, &b)) {
1655 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1656 return false;
1658 *(int *)parm_ptr = b;
1660 break;
1662 case P_INTEGER:
1663 *(int *)parm_ptr = atoi(pszParmValue);
1664 break;
1666 case P_OCTAL:
1667 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1668 break;
1670 case P_BYTES:
1672 uint64_t val;
1673 if (conv_str_size(pszParmValue, &val)) {
1674 if (val <= INT_MAX) {
1675 *(int *)parm_ptr = (int)val;
1676 break;
1680 DEBUG(0,("lp_do_parameter(%s): value is not "
1681 "a valid size specifier!\n", pszParmValue));
1682 return false;
1685 case P_LIST:
1686 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1687 pszParmValue, NULL);
1688 break;
1690 case P_STRING:
1691 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1692 break;
1694 case P_USTRING:
1695 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1696 strupper(*(char **)parm_ptr);
1697 break;
1699 case P_ENUM:
1700 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1701 if (strequal
1702 (pszParmValue,
1703 parm_table[parmnum].enum_list[i].name)) {
1704 *(int *)parm_ptr =
1705 parm_table[parmnum].
1706 enum_list[i].value;
1707 break;
1710 if (!parm_table[parmnum].enum_list[i].name) {
1711 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1712 pszParmValue, pszParmName));
1713 return false;
1715 break;
1718 mark_non_default:
1719 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1720 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1721 /* we have to also unset FLAG_DEFAULT on aliases */
1722 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1723 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1725 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1726 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1729 return true;
1733 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1734 const char *pszParmName, const char *pszParmValue)
1736 int parmnum = map_parameter(pszParmName);
1737 void *parm_ptr;
1739 if (parmnum < 0) {
1740 if (strchr(pszParmName, ':')) {
1741 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1743 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1744 return true;
1747 /* if the flag has been set on the command line, then don't allow override,
1748 but don't report an error */
1749 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1750 return true;
1753 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1755 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1756 pszParmName, pszParmValue, lp_ctx, true);
1759 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1760 struct loadparm_service *service,
1761 const char *pszParmName, const char *pszParmValue)
1763 void *parm_ptr;
1764 int i;
1765 int parmnum = map_parameter(pszParmName);
1767 if (parmnum < 0) {
1768 if (strchr(pszParmName, ':')) {
1769 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1771 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1772 return true;
1775 /* if the flag has been set on the command line, then don't allow override,
1776 but don't report an error */
1777 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1778 return true;
1781 if (parm_table[parmnum].pclass == P_GLOBAL) {
1782 DEBUG(0,
1783 ("Global parameter %s found in service section!\n",
1784 pszParmName));
1785 return true;
1787 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1789 if (!service->copymap)
1790 init_copymap(service);
1792 /* this handles the aliases - set the copymap for other
1793 * entries with the same data pointer */
1794 for (i = 0; parm_table[i].label; i++)
1795 if (parm_table[i].offset == parm_table[parmnum].offset &&
1796 parm_table[i].pclass == parm_table[parmnum].pclass)
1797 service->copymap[i] = false;
1799 return set_variable(service, parmnum, parm_ptr, pszParmName,
1800 pszParmValue, lp_ctx, false);
1804 * Process a parameter.
1807 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1808 void *userdata)
1810 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1812 if (lp_ctx->bInGlobalSection)
1813 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1814 pszParmValue);
1815 else
1816 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1817 pszParmName, pszParmValue);
1821 variable argument do parameter
1823 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1824 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1825 const char *pszParmName, const char *fmt, ...)
1827 char *s;
1828 bool ret;
1829 va_list ap;
1831 va_start(ap, fmt);
1832 s = talloc_vasprintf(NULL, fmt, ap);
1833 va_end(ap);
1834 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1835 talloc_free(s);
1836 return ret;
1841 set a parameter from the commandline - this is called from command line parameter
1842 parsing code. It sets the parameter then marks the parameter as unable to be modified
1843 by smb.conf processing
1845 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1846 const char *pszParmValue)
1848 int parmnum = map_parameter(pszParmName);
1849 int i;
1851 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1854 if (parmnum < 0 && strchr(pszParmName, ':')) {
1855 /* set a parametric option */
1856 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1857 pszParmValue, FLAG_CMDLINE);
1860 if (parmnum < 0) {
1861 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1862 return false;
1865 /* reset the CMDLINE flag in case this has been called before */
1866 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1868 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1869 return false;
1872 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1874 /* we have to also set FLAG_CMDLINE on aliases */
1875 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1876 lp_ctx->flags[i] |= FLAG_CMDLINE;
1878 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1879 lp_ctx->flags[i] |= FLAG_CMDLINE;
1882 return true;
1886 set a option from the commandline in 'a=b' format. Use to support --option
1888 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1890 char *p, *s;
1891 bool ret;
1893 s = strdup(option);
1894 if (!s) {
1895 return false;
1898 p = strchr(s, '=');
1899 if (!p) {
1900 free(s);
1901 return false;
1904 *p = 0;
1906 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1907 free(s);
1908 return ret;
1912 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1915 * Print a parameter of the specified type.
1918 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1920 int i;
1921 switch (p->type)
1923 case P_ENUM:
1924 for (i = 0; p->enum_list[i].name; i++) {
1925 if (*(int *)ptr == p->enum_list[i].value) {
1926 fprintf(f, "%s",
1927 p->enum_list[i].name);
1928 break;
1931 break;
1933 case P_BOOL:
1934 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1935 break;
1937 case P_INTEGER:
1938 case P_BYTES:
1939 fprintf(f, "%d", *(int *)ptr);
1940 break;
1942 case P_OCTAL:
1943 fprintf(f, "0%o", *(int *)ptr);
1944 break;
1946 case P_LIST:
1947 if ((char ***)ptr && *(char ***)ptr) {
1948 char **list = *(char ***)ptr;
1950 for (; *list; list++)
1951 fprintf(f, "%s%s", *list,
1952 ((*(list+1))?", ":""));
1954 break;
1956 case P_STRING:
1957 case P_USTRING:
1958 if (*(char **)ptr) {
1959 fprintf(f, "%s", *(char **)ptr);
1961 break;
1966 * Check if two parameters are equal.
1969 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1971 switch (type) {
1972 case P_BOOL:
1973 return (*((int *)ptr1) == *((int *)ptr2));
1975 case P_INTEGER:
1976 case P_OCTAL:
1977 case P_BYTES:
1978 case P_ENUM:
1979 return (*((int *)ptr1) == *((int *)ptr2));
1981 case P_LIST:
1982 return str_list_equal((const char **)(*(char ***)ptr1),
1983 (const char **)(*(char ***)ptr2));
1985 case P_STRING:
1986 case P_USTRING:
1988 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1989 if (p1 && !*p1)
1990 p1 = NULL;
1991 if (p2 && !*p2)
1992 p2 = NULL;
1993 return (p1 == p2 || strequal(p1, p2));
1996 return false;
2000 * Process a new section (service).
2002 * At this stage all sections are services.
2003 * Later we'll have special sections that permit server parameters to be set.
2004 * Returns True on success, False on failure.
2007 static bool do_section(const char *pszSectionName, void *userdata)
2009 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2010 bool bRetval;
2011 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2012 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2013 bRetval = false;
2015 /* if we've just struck a global section, note the fact. */
2016 lp_ctx->bInGlobalSection = isglobal;
2018 /* check for multiple global sections */
2019 if (lp_ctx->bInGlobalSection) {
2020 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
2021 return true;
2024 /* if we have a current service, tidy it up before moving on */
2025 bRetval = true;
2027 if (lp_ctx->currentService != NULL)
2028 bRetval = service_ok(lp_ctx->currentService);
2030 /* if all is still well, move to the next record in the services array */
2031 if (bRetval) {
2032 /* We put this here to avoid an odd message order if messages are */
2033 /* issued by the post-processing of a previous section. */
2034 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2036 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2037 pszSectionName))
2038 == NULL) {
2039 DEBUG(0, ("Failed to add a new service\n"));
2040 return false;
2044 return bRetval;
2049 * Determine if a particular base parameter is currently set to the default value.
2052 static bool is_default(struct loadparm_service *sDefault, int i)
2054 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2055 if (!defaults_saved)
2056 return false;
2057 switch (parm_table[i].type) {
2058 case P_LIST:
2059 return str_list_equal((const char **)parm_table[i].def.lvalue,
2060 (const char **)def_ptr);
2061 case P_STRING:
2062 case P_USTRING:
2063 return strequal(parm_table[i].def.svalue,
2064 *(char **)def_ptr);
2065 case P_BOOL:
2066 return parm_table[i].def.bvalue ==
2067 *(int *)def_ptr;
2068 case P_INTEGER:
2069 case P_OCTAL:
2070 case P_BYTES:
2071 case P_ENUM:
2072 return parm_table[i].def.ivalue ==
2073 *(int *)def_ptr;
2075 return false;
2079 *Display the contents of the global structure.
2082 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2083 bool show_defaults)
2085 int i;
2086 struct parmlist_entry *data;
2088 fprintf(f, "# Global parameters\n[global]\n");
2090 for (i = 0; parm_table[i].label; i++)
2091 if (parm_table[i].pclass == P_GLOBAL &&
2092 parm_table[i].offset != -1 &&
2093 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2094 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2095 continue;
2096 fprintf(f, "\t%s = ", parm_table[i].label);
2097 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2098 fprintf(f, "\n");
2100 if (lp_ctx->globals->param_opt != NULL) {
2101 for (data = lp_ctx->globals->param_opt; data;
2102 data = data->next) {
2103 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2104 continue;
2106 fprintf(f, "\t%s = %s\n", data->key, data->value);
2113 * Display the contents of a single services record.
2116 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2117 unsigned int *flags)
2119 int i;
2120 struct parmlist_entry *data;
2122 if (pService != sDefault)
2123 fprintf(f, "\n[%s]\n", pService->szService);
2125 for (i = 0; parm_table[i].label; i++) {
2126 if (parm_table[i].pclass == P_LOCAL &&
2127 parm_table[i].offset != -1 &&
2128 (*parm_table[i].label != '-') &&
2129 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
2131 if (pService == sDefault) {
2132 if (flags && (flags[i] & FLAG_DEFAULT)) {
2133 continue;
2135 if (defaults_saved) {
2136 if (is_default(sDefault, i)) {
2137 continue;
2140 } else {
2141 if (equal_parameter(parm_table[i].type,
2142 ((char *)pService) +
2143 parm_table[i].offset,
2144 ((char *)sDefault) +
2145 parm_table[i].offset))
2146 continue;
2149 fprintf(f, "\t%s = ", parm_table[i].label);
2150 print_parameter(&parm_table[i],
2151 ((char *)pService) + parm_table[i].offset, f);
2152 fprintf(f, "\n");
2155 if (pService->param_opt != NULL) {
2156 for (data = pService->param_opt; data; data = data->next) {
2157 fprintf(f, "\t%s = %s\n", data->key, data->value);
2162 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2163 struct loadparm_service *service,
2164 const char *parm_name, FILE * f)
2166 struct parm_struct *parm;
2167 void *ptr;
2169 parm = lpcfg_parm_struct(parm_name);
2170 if (!parm) {
2171 return false;
2174 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2176 print_parameter(parm, ptr, f);
2177 fprintf(f, "\n");
2178 return true;
2182 * Return info about the next parameter in a service.
2183 * snum==-1 gives the globals.
2184 * Return NULL when out of parameters.
2188 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2189 int allparameters)
2191 if (snum == -1) {
2192 /* do the globals */
2193 for (; parm_table[*i].label; (*i)++) {
2194 if (parm_table[*i].offset == -1
2195 || (*parm_table[*i].label == '-'))
2196 continue;
2198 if ((*i) > 0
2199 && (parm_table[*i].offset ==
2200 parm_table[(*i) - 1].offset))
2201 continue;
2203 return &parm_table[(*i)++];
2205 } else {
2206 struct loadparm_service *pService = lp_ctx->services[snum];
2208 for (; parm_table[*i].label; (*i)++) {
2209 if (parm_table[*i].pclass == P_LOCAL &&
2210 parm_table[*i].offset != -1 &&
2211 (*parm_table[*i].label != '-') &&
2212 ((*i) == 0 ||
2213 (parm_table[*i].offset !=
2214 parm_table[(*i) - 1].offset)))
2216 if (allparameters ||
2217 !equal_parameter(parm_table[*i].type,
2218 ((char *)pService) +
2219 parm_table[*i].offset,
2220 ((char *)lp_ctx->sDefault) +
2221 parm_table[*i].offset))
2223 return &parm_table[(*i)++];
2229 return NULL;
2234 * Auto-load some home services.
2236 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2237 const char *str)
2239 return;
2244 * Unload unused services.
2247 void lp_killunused(struct loadparm_context *lp_ctx,
2248 struct smbsrv_connection *smb,
2249 bool (*snumused) (struct smbsrv_connection *, int))
2251 int i;
2252 for (i = 0; i < lp_ctx->iNumServices; i++) {
2253 if (lp_ctx->services[i] == NULL)
2254 continue;
2256 if (!snumused || !snumused(smb, i)) {
2257 talloc_free(lp_ctx->services[i]);
2258 lp_ctx->services[i] = NULL;
2264 static int lp_destructor(struct loadparm_context *lp_ctx)
2266 struct parmlist_entry *data;
2268 if (lp_ctx->refuse_free) {
2269 /* someone is trying to free the
2270 global_loadparm_context.
2271 We can't allow that. */
2272 return -1;
2275 if (lp_ctx->globals->param_opt != NULL) {
2276 struct parmlist_entry *next;
2277 for (data = lp_ctx->globals->param_opt; data; data=next) {
2278 next = data->next;
2279 if (data->priority & FLAG_CMDLINE) continue;
2280 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2281 talloc_free(data);
2285 return 0;
2289 * Initialise the global parameter structure.
2291 * Note that most callers should use loadparm_init_global() instead
2293 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2295 int i;
2296 char *myname;
2297 struct loadparm_context *lp_ctx;
2298 struct parmlist_entry *parm;
2300 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2301 if (lp_ctx == NULL)
2302 return NULL;
2304 talloc_set_destructor(lp_ctx, lp_destructor);
2305 lp_ctx->bInGlobalSection = true;
2306 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2307 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2309 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2310 lp_ctx->sDefault->bAvailable = true;
2311 lp_ctx->sDefault->bBrowseable = true;
2312 lp_ctx->sDefault->bRead_only = true;
2313 lp_ctx->sDefault->bMap_archive = true;
2314 lp_ctx->sDefault->bStrictLocking = true;
2315 lp_ctx->sDefault->bOplocks = true;
2316 lp_ctx->sDefault->iCreate_mask = 0744;
2317 lp_ctx->sDefault->iCreate_force_mode = 0000;
2318 lp_ctx->sDefault->iDir_mask = 0755;
2319 lp_ctx->sDefault->iDir_force_mode = 0000;
2321 DEBUG(3, ("Initialising global parameters\n"));
2323 for (i = 0; parm_table[i].label; i++) {
2324 if ((parm_table[i].type == P_STRING ||
2325 parm_table[i].type == P_USTRING) &&
2326 parm_table[i].offset != -1 &&
2327 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2328 char **r;
2329 if (parm_table[i].pclass == P_LOCAL) {
2330 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2331 } else {
2332 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2334 *r = talloc_strdup(lp_ctx, "");
2338 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2340 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
2342 /* options that can be set on the command line must be initialised via
2343 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2344 #ifdef TCP_NODELAY
2345 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2346 #endif
2347 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2348 myname = get_myname(lp_ctx);
2349 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2350 talloc_free(myname);
2351 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2353 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2355 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2356 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
2358 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6");
2359 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
2360 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2361 /* the winbind method for domain controllers is for both RODC
2362 auth forwarding and for trusted domains */
2363 lpcfg_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain winbind");
2364 lpcfg_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2365 lpcfg_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2366 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2367 lpcfg_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
2368 lpcfg_do_global_parameter(lp_ctx, "idmap database", "idmap.ldb");
2369 lpcfg_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
2370 lpcfg_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2371 lpcfg_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2372 lpcfg_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2373 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2375 /* This hive should be dynamically generated by Samba using
2376 data from the sam, but for the moment leave it in a tdb to
2377 keep regedt32 from popping up an annoying dialog. */
2378 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2380 /* using UTF8 by default allows us to support all chars */
2381 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2383 /* Use codepage 850 as a default for the dos character set */
2384 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2387 * Allow the default PASSWD_CHAT to be overridden in local.h.
2389 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2391 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2392 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2393 lpcfg_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2394 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2396 lpcfg_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
2397 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2398 "Samba %s", SAMBA_VERSION_STRING);
2400 lpcfg_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2401 DEFAULT_MAJOR_VERSION,
2402 DEFAULT_MINOR_VERSION);
2404 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2406 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2407 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
2408 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
2409 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2410 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2411 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2412 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2413 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2414 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
2415 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
2416 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2417 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2418 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2419 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2420 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2421 lpcfg_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2423 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2424 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2425 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2426 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2427 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2428 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2429 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2431 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2433 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2434 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2436 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2437 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2439 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2440 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2441 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2442 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2443 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2444 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2445 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2447 lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
2448 lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
2450 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2452 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2453 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2454 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2455 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2456 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2457 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2458 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2460 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2462 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2463 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
2465 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2466 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2467 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2468 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2469 lpcfg_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2470 dyn_SETUPDIR);
2472 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2474 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2475 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2476 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2477 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2478 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2480 for (i = 0; parm_table[i].label; i++) {
2481 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2482 lp_ctx->flags[i] |= FLAG_DEFAULT;
2486 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2487 if (!(parm->priority & FLAG_CMDLINE)) {
2488 parm->priority |= FLAG_DEFAULT;
2492 return lp_ctx;
2496 * Initialise the global parameter structure.
2498 struct loadparm_context *loadparm_init_global(bool load_default)
2500 if (global_loadparm_context == NULL) {
2501 global_loadparm_context = loadparm_init(NULL);
2503 if (load_default && !global_loadparm_context->loaded) {
2504 lpcfg_load_default(global_loadparm_context);
2506 global_loadparm_context->refuse_free = true;
2507 return global_loadparm_context;
2510 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2512 return lp_ctx->szConfigFile;
2515 const char *lp_default_path(void)
2517 if (getenv("SMB_CONF_PATH"))
2518 return getenv("SMB_CONF_PATH");
2519 else
2520 return dyn_CONFIGFILE;
2524 * Update the internal state of a loadparm context after settings
2525 * have changed.
2527 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2529 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
2531 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2532 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2535 panic_action = lp_ctx->globals->panic_action;
2537 reload_charcnv(lp_ctx);
2539 /* FIXME: ntstatus_check_dos_mapping = lpcfg_nt_status_support(lp_ctx); */
2541 /* FIXME: This is a bit of a hack, but we can't use a global, since
2542 * not everything that uses lp also uses the socket library */
2543 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2544 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2545 } else {
2546 unsetenv("SOCKET_TESTNONBLOCK");
2549 /* FIXME: Check locale in environment for this: */
2550 if (strcmp(lpcfg_display_charset(lp_ctx), lpcfg_unix_charset(lp_ctx)) != 0)
2551 d_set_iconv(smb_iconv_open(lpcfg_display_charset(lp_ctx), lpcfg_unix_charset(lp_ctx)));
2552 else
2553 d_set_iconv((smb_iconv_t)-1);
2555 return true;
2558 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2560 const char *path;
2562 path = lp_default_path();
2564 if (!file_exist(path)) {
2565 /* We allow the default smb.conf file to not exist,
2566 * basically the equivalent of an empty file. */
2567 return lpcfg_update(lp_ctx);
2570 return lpcfg_load(lp_ctx, path);
2574 * Load the services array from the services file.
2576 * Return True on success, False on failure.
2578 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2580 char *n2;
2581 bool bRetval;
2583 filename = talloc_strdup(lp_ctx, filename);
2585 lp_ctx->szConfigFile = filename;
2587 lp_ctx->bInGlobalSection = true;
2588 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2589 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2591 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2593 /* We get sections first, so have to start 'behind' to make up */
2594 lp_ctx->currentService = NULL;
2595 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2597 /* finish up the last section */
2598 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2599 if (bRetval)
2600 if (lp_ctx->currentService != NULL)
2601 bRetval = service_ok(lp_ctx->currentService);
2603 bRetval = bRetval && lpcfg_update(lp_ctx);
2605 /* we do this unconditionally, so that it happens even
2606 for a missing smb.conf */
2607 reload_charcnv(lp_ctx);
2609 if (bRetval == true) {
2610 /* set this up so that any child python tasks will
2611 find the right smb.conf */
2612 setenv("SMB_CONF_PATH", filename, 1);
2614 /* set the context used by the lp_*() function
2615 varients */
2616 global_loadparm_context = lp_ctx;
2617 lp_ctx->loaded = true;
2620 return bRetval;
2624 * Return the max number of services.
2627 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2629 return lp_ctx->iNumServices;
2633 * Display the contents of the services array in human-readable form.
2636 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2637 int maxtoprint)
2639 int iService;
2641 defaults_saved = !show_defaults;
2643 dump_globals(lp_ctx, f, show_defaults);
2645 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2647 for (iService = 0; iService < maxtoprint; iService++)
2648 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2652 * Display the contents of one service in human-readable form.
2654 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2656 if (service != NULL) {
2657 if (service->szService[0] == '\0')
2658 return;
2659 dump_a_service(service, sDefault, f, NULL);
2663 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2664 int snum)
2666 return lp_ctx->services[snum];
2669 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2670 const char *service_name)
2672 int iService;
2673 char *serviceName;
2675 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2676 if (lp_ctx->services[iService] &&
2677 lp_ctx->services[iService]->szService) {
2679 * The substitution here is used to support %U is
2680 * service names
2682 serviceName = standard_sub_basic(
2683 lp_ctx->services[iService],
2684 lp_ctx->services[iService]->szService);
2685 if (strequal(serviceName, service_name)) {
2686 talloc_free(serviceName);
2687 return lp_ctx->services[iService];
2689 talloc_free(serviceName);
2693 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2694 return NULL;
2697 const char *lpcfg_servicename(const struct loadparm_service *service)
2699 return lp_string((const char *)service->szService);
2703 * A useful volume label function.
2705 const char *volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2707 const char *ret;
2708 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
2709 service->volume : sDefault->volume));
2710 if (!*ret)
2711 return lpcfg_servicename(service);
2712 return ret;
2716 * If we are PDC then prefer us as DMB
2718 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2720 const char *ret;
2721 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
2722 service->szPrintername : sDefault->szPrintername));
2723 if (ret == NULL || (ret != NULL && *ret == '\0'))
2724 ret = lpcfg_servicename(service);
2726 return ret;
2731 * Return the max print jobs per queue.
2733 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2735 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2736 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2737 maxjobs = PRINT_MAX_JOBID - 1;
2739 return maxjobs;
2742 struct smb_iconv_convenience *lpcfg_iconv_convenience(struct loadparm_context *lp_ctx)
2744 if (lp_ctx == NULL) {
2745 static struct smb_iconv_convenience *fallback_ic = NULL;
2746 if (fallback_ic == NULL)
2747 fallback_ic = smb_iconv_convenience_reinit(talloc_autofree_context(),
2748 "CP850", "UTF8", true, NULL);
2749 return fallback_ic;
2751 return lp_ctx->iconv_convenience;
2754 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2756 struct smb_iconv_convenience *old_ic = lp_ctx->iconv_convenience;
2757 if (old_ic == NULL) {
2758 old_ic = global_iconv_convenience;
2760 lp_ctx->iconv_convenience = smb_iconv_convenience_reinit_lp(lp_ctx, lp_ctx, old_ic);
2761 global_iconv_convenience = lp_ctx->iconv_convenience;
2764 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
2765 struct smbcli_options *options)
2767 options->max_xmit = lpcfg_max_xmit(lp_ctx);
2768 options->max_mux = lpcfg_maxmux(lp_ctx);
2769 options->use_spnego = lpcfg_nt_status_support(lp_ctx) && lpcfg_use_spnego(lp_ctx);
2770 options->signing = lpcfg_client_signing(lp_ctx);
2771 options->request_timeout = SMB_REQUEST_TIMEOUT;
2772 options->ntstatus_support = lpcfg_nt_status_support(lp_ctx);
2773 options->max_protocol = lpcfg_cli_maxprotocol(lp_ctx);
2774 options->unicode = lpcfg_unicode(lp_ctx);
2775 options->use_oplocks = true;
2776 options->use_level2_oplocks = true;
2779 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
2780 struct smbcli_session_options *options)
2782 options->lanman_auth = lpcfg_client_lanman_auth(lp_ctx);
2783 options->ntlmv2_auth = lpcfg_client_ntlmv2_auth(lp_ctx);
2784 options->plaintext_auth = lpcfg_client_plaintext_auth(lp_ctx);
2787 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2789 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
2792 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2794 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
2797 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2799 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
2802 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2804 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
2807 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2809 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
2812 _PUBLIC_ struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2814 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
2816 ret->domain_name = talloc_reference(mem_ctx, lpcfg_workgroup(lp_ctx));
2817 ret->version_major = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
2818 ret->version_minor = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
2819 ret->version_build = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
2821 return ret;
2824 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2826 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
2827 if (settings == NULL)
2828 return NULL;
2829 SMB_ASSERT(lp_ctx != NULL);
2830 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2831 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2832 return settings;