s4-param Remove 'secrets database' parameter
[samba.git] / source4 / param / loadparm.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Parameter loading functions
4    Copyright (C) Karl Auer 1993-1998
5
6    Largely re-written by Andrew Tridgell, September 1994
7
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
14
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.
19
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.
24
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/>.
27 */
28
29 /*
30  *  Load parameters.
31  *
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.
35  *
36  * To add a parameter:
37  *
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
43  *
44  *
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!
52  *
53  */
54
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"
71
72 #define standard_sub_basic talloc_strdup
73
74 static bool do_parameter(const char *, const char *, void *);
75 static bool defaults_saved = false;
76
77 /**
78  * This structure describes global (ie., server-wide) parameters.
79  */
80 struct loadparm_global
81 {
82         enum server_role server_role;
83         enum sid_generator sid_generator;
84
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 *szServerString;
94         char *szAutoServices;
95         char *szPasswdChat;
96         char *szShareBackend;
97         char *szIDMAP_URL;
98         char *szSPOOLSS_URL;
99         char *szWINS_CONFIG_URL;
100         char *szWINS_URL;
101         char *szPrivateDir;
102         const char **szPasswordServers;
103         char *szSocketOptions;
104         char *szRealm;
105         char *szRealm_upper;
106         char *szRealm_lower;
107         const char **szWINSservers;
108         const char **szInterfaces;
109         char *szSocketAddress;
110         char *szAnnounceVersion;        /* This is initialised in init_globals */
111         char *szWorkgroup;
112         char *szNetbiosName;
113         const char **szNetbiosAliases;
114         char *szNetbiosScope;
115         char *szDomainOtherSIDs;
116         const char **szNameResolveOrder;
117         const char **dcerpc_ep_servers;
118         const char **server_services;
119         char *ntptr_providor;
120         char *szWinbindSeparator;
121         char *szWinbinddPrivilegedSocketDirectory;
122         char *szWinbinddSocketDirectory;
123         char *szTemplateShell;
124         char *szTemplateHomedir;
125         int bWinbindSealedPipes;
126         int bIdmapTrustedOnly;
127         int tls_enabled;
128         char *tls_keyfile;
129         char *tls_certfile;
130         char *tls_cafile;
131         char *tls_crlfile;
132         char *tls_dhpfile;
133         char *logfile;
134         char *loglevel;
135         char *panic_action;
136         int max_mux;
137         int debuglevel;
138         int max_xmit;
139         int pwordlevel;
140         int srv_maxprotocol;
141         int srv_minprotocol;
142         int cli_maxprotocol;
143         int cli_minprotocol;
144         int security;
145         int paranoid_server_security;
146         int max_wins_ttl;
147         int min_wins_ttl;
148         int announce_as;        /* This is initialised in init_globals */
149         int nbt_port;
150         int dgram_port;
151         int cldap_port;
152         int krb5_port;
153         int kpasswd_port;
154         int web_port;
155         char *socket_options;
156         int bWINSsupport;
157         int bWINSdnsProxy;
158         char *szWINSHook;
159         int bLocalMaster;
160         int bPreferredMaster;
161         int bEncryptPasswords;
162         int bNullPasswords;
163         int bObeyPamRestrictions;
164         int bLargeReadwrite;
165         int bReadRaw;
166         int bWriteRaw;
167         int bTimeServer;
168         int bBindInterfacesOnly;
169         int bNTSmbSupport;
170         int bNTStatusSupport;
171         int bLanmanAuth;
172         int bNTLMAuth;
173         int bUseSpnego;
174         int server_signing;
175         int client_signing;
176         int bClientPlaintextAuth;
177         int bClientLanManAuth;
178         int bClientNTLMv2Auth;
179         int client_use_spnego_principal;
180         int bHostMSDfs;
181         int bUnicode;
182         int bUnixExtensions;
183         int bDisableNetbios;
184         int bRpcBigEndian;
185         char *szNTPSignDSocketDirectory;
186         const char **szRNDCCommand;
187         const char **szDNSUpdateCommand;
188         const char **szSPNUpdateCommand;
189         const char **szNSUpdateCommand;
190         struct parmlist_entry *param_opt;
191 };
192
193
194 /**
195  * This structure describes a single service.
196  */
197 struct loadparm_service
198 {
199         char *szService;
200         char *szPath;
201         char *szCopy;
202         char *szInclude;
203         char *szPrintername;
204         char **szHostsallow;
205         char **szHostsdeny;
206         char *comment;
207         char *volume;
208         char *fstype;
209         char **ntvfs_handler;
210         int iMaxPrintJobs;
211         int iMaxConnections;
212         int iCSCPolicy;
213         int bAvailable;
214         int bBrowseable;
215         int bRead_only;
216         int bPrint_ok;
217         int bMap_system;
218         int bMap_hidden;
219         int bMap_archive;
220         int bStrictLocking;
221         int bOplocks;
222         int iCreate_mask;
223         int iCreate_force_mode;
224         int iDir_mask;
225         int iDir_force_mode;
226         int *copymap;
227         int bMSDfsRoot;
228         int bStrictSync;
229         int bCIFileSystem;
230         struct parmlist_entry *param_opt;
231
232         char dummy[3];          /* for alignment */
233 };
234
235
236 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
237
238
239 /* prototypes for the special type handlers */
240 static bool handle_include(struct loadparm_context *lp_ctx,
241                            const char *pszParmValue, char **ptr);
242 static bool handle_realm(struct loadparm_context *lp_ctx,
243                          const char *pszParmValue, char **ptr);
244 static bool handle_copy(struct loadparm_context *lp_ctx,
245                         const char *pszParmValue, char **ptr);
246 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
247                               const char *pszParmValue, char **ptr);
248 static bool handle_logfile(struct loadparm_context *lp_ctx,
249                            const char *pszParmValue, char **ptr);
250
251 static const struct enum_list enum_protocol[] = {
252         {PROTOCOL_SMB2, "SMB2"},
253         {PROTOCOL_NT1, "NT1"},
254         {PROTOCOL_LANMAN2, "LANMAN2"},
255         {PROTOCOL_LANMAN1, "LANMAN1"},
256         {PROTOCOL_CORE, "CORE"},
257         {PROTOCOL_COREPLUS, "COREPLUS"},
258         {PROTOCOL_COREPLUS, "CORE+"},
259         {-1, NULL}
260 };
261
262 static const struct enum_list enum_security[] = {
263         {SEC_SHARE, "SHARE"},
264         {SEC_USER, "USER"},
265         {SEC_ADS, "ADS"},
266         {-1, NULL}
267 };
268
269 static const struct enum_list enum_announce_as[] = {
270         {ANNOUNCE_AS_NT_SERVER, "NT"},
271         {ANNOUNCE_AS_NT_SERVER, "NT Server"},
272         {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
273         {ANNOUNCE_AS_WIN95, "win95"},
274         {ANNOUNCE_AS_WFW, "WfW"},
275         {-1, NULL}
276 };
277
278 static const struct enum_list enum_bool_auto[] = {
279         {false, "No"},
280         {false, "False"},
281         {false, "0"},
282         {true, "Yes"},
283         {true, "True"},
284         {true, "1"},
285         {Auto, "Auto"},
286         {-1, NULL}
287 };
288
289 /* Client-side offline caching policy types */
290 enum csc_policy {
291         CSC_POLICY_MANUAL=0,
292         CSC_POLICY_DOCUMENTS=1,
293         CSC_POLICY_PROGRAMS=2,
294         CSC_POLICY_DISABLE=3
295 };
296
297 static const struct enum_list enum_csc_policy[] = {
298         {CSC_POLICY_MANUAL, "manual"},
299         {CSC_POLICY_DOCUMENTS, "documents"},
300         {CSC_POLICY_PROGRAMS, "programs"},
301         {CSC_POLICY_DISABLE, "disable"},
302         {-1, NULL}
303 };
304
305 /* SMB signing types. */
306 static const struct enum_list enum_smb_signing_vals[] = {
307         {SMB_SIGNING_OFF, "No"},
308         {SMB_SIGNING_OFF, "False"},
309         {SMB_SIGNING_OFF, "0"},
310         {SMB_SIGNING_OFF, "Off"},
311         {SMB_SIGNING_OFF, "disabled"},
312         {SMB_SIGNING_SUPPORTED, "Yes"},
313         {SMB_SIGNING_SUPPORTED, "True"},
314         {SMB_SIGNING_SUPPORTED, "1"},
315         {SMB_SIGNING_SUPPORTED, "On"},
316         {SMB_SIGNING_SUPPORTED, "enabled"},
317         {SMB_SIGNING_REQUIRED, "required"},
318         {SMB_SIGNING_REQUIRED, "mandatory"},
319         {SMB_SIGNING_REQUIRED, "force"},
320         {SMB_SIGNING_REQUIRED, "forced"},
321         {SMB_SIGNING_REQUIRED, "enforced"},
322         {SMB_SIGNING_AUTO, "auto"},
323         {-1, NULL}
324 };
325
326 static const struct enum_list enum_server_role[] = {
327         {ROLE_STANDALONE, "standalone"},
328         {ROLE_DOMAIN_MEMBER, "member server"},
329         {ROLE_DOMAIN_MEMBER, "member"},
330         {ROLE_DOMAIN_CONTROLLER, "domain controller"},
331         {ROLE_DOMAIN_CONTROLLER, "dc"},
332         {-1, NULL}
333 };
334
335 static const struct enum_list enum_sid_generator[] = {
336         {SID_GENERATOR_INTERNAL, "internal"},
337         {SID_GENERATOR_BACKEND, "backend"},
338         {-1, NULL}
339 };
340
341 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
342 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
343
344 static struct parm_struct parm_table[] = {
345         {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
346         {"sid generator", P_ENUM, P_GLOBAL, GLOBAL_VAR(sid_generator), NULL, enum_sid_generator},
347
348         {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
349         {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
350         {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
351         {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
352         {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
353         {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
354         {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
355         {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
356         {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), handle_realm, NULL},
357         {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
358         {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
359         {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
360         {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
361         {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
362         {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
363         {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
364         {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
365         {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
366         {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
367
368         {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
369         {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
370         {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
371         {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
372         {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
373         {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
374         {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
375         {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
376         {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
377         {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
378         {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
379         {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
380         {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
381         {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
382         {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
383         {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
384         {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
385         {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
386
387         {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
388
389         {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
390         {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL}, 
391         {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
392         {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL}, 
393
394         {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
395         {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
396
397         {"log level", P_STRING, P_GLOBAL, GLOBAL_VAR(loglevel), handle_debuglevel, NULL},
398         {"debuglevel", P_STRING, P_GLOBAL, GLOBAL_VAR(loglevel), handle_debuglevel, NULL},
399         {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
400
401         {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
402         {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
403         {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
404         {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
405         {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
406         {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
407         {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
408         {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
409         {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
410         {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
411         {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
412         {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
413         {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
414         {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
415         {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
416         {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
417         {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
418         {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
419         {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
420         {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
421         {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
422         {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
423
424         {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
425
426         {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
427         {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
428         {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
429         {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
430
431         {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
432         {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
433         {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
434         {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
435         {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
436         {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
437         {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals}, 
438         {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals}, 
439         {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
440
441         {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
442         {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
443         {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
444
445         {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
446         {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL}, 
447
448         {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
449         {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
450         {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
451
452         {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
453         {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
454
455         {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
456         {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
457         {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
458
459         {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
460         {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
461         {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
462         {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
463         {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
464
465         {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
466         {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
467         {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
468         {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL}, 
469
470         {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
471
472         {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
473         {"oplocks", P_BOOL, P_LOCAL, LOCAL_VAR(bOplocks), NULL, NULL},
474
475         {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
476         {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
477         {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
478         {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL}, 
479         {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
480         {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
481         {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL}, 
482
483         {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
484         {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
485         {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
486
487         {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
488         {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
489         {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
490
491         {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
492
493         {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
494         {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
495         {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
496         {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
497         {"winbindd privileged socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory), NULL, NULL },
498         {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
499         {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
500         {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
501         {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
502
503         {"ntp signd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szNTPSignDSocketDirectory), NULL, NULL },
504         {"rndc command", P_CMDLIST, P_GLOBAL, GLOBAL_VAR(szRNDCCommand), NULL, NULL },
505         {"dns update command", P_CMDLIST, P_GLOBAL, GLOBAL_VAR(szDNSUpdateCommand), NULL, NULL },
506         {"spn update command", P_CMDLIST, P_GLOBAL, GLOBAL_VAR(szSPNUpdateCommand), NULL, NULL },
507         {"nsupdate command", P_CMDLIST, P_GLOBAL, GLOBAL_VAR(szNSUpdateCommand), NULL, NULL },
508
509         {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
510 };
511
512
513 /* local variables */
514 struct loadparm_context {
515         const char *szConfigFile;
516         struct loadparm_global *globals;
517         struct loadparm_service **services;
518         struct loadparm_service *sDefault;
519         struct smb_iconv_handle *iconv_handle;
520         int iNumServices;
521         struct loadparm_service *currentService;
522         bool bInGlobalSection;
523         struct file_lists {
524                 struct file_lists *next;
525                 char *name;
526                 char *subfname;
527                 time_t modtime;
528         } *file_lists;
529         unsigned int flags[NUMPARAMETERS];
530         bool loaded;
531         bool refuse_free;
532         bool global; /* Is this the global context, which may set
533                       * global variables such as debug level etc? */
534 };
535
536
537 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
538 {
539         return lp_ctx->sDefault;
540 }
541
542 /*
543   return the parameter table
544 */
545 struct parm_struct *lpcfg_parm_table(void)
546 {
547         return parm_table;
548 }
549
550 /**
551  * Convenience routine to grab string parameters into temporary memory
552  * and run standard_sub_basic on them.
553  *
554  * The buffers can be written to by
555  * callers without affecting the source string.
556  */
557
558 static const char *lp_string(const char *s)
559 {
560 #if 0  /* until REWRITE done to make thread-safe */
561         size_t len = s ? strlen(s) : 0;
562         char *ret;
563 #endif
564
565         /* The follow debug is useful for tracking down memory problems
566            especially if you have an inner loop that is calling a lp_*()
567            function that returns a string.  Perhaps this debug should be
568            present all the time? */
569
570 #if 0
571         DEBUG(10, ("lp_string(%s)\n", s));
572 #endif
573
574 #if 0  /* until REWRITE done to make thread-safe */
575         if (!lp_talloc)
576                 lp_talloc = talloc_init("lp_talloc");
577
578         ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
579
580         if (!ret)
581                 return NULL;
582
583         if (!s)
584                 *ret = 0;
585         else
586                 strlcpy(ret, s, len);
587
588         if (trim_string(ret, "\"", "\"")) {
589                 if (strchr(ret,'"') != NULL)
590                         strlcpy(ret, s, len);
591         }
592
593         standard_sub_basic(ret,len+100);
594         return (ret);
595 #endif
596         return s;
597 }
598
599 /*
600    In this section all the functions that are used to access the
601    parameters from the rest of the program are defined
602 */
603
604 /*
605  * the creation of separate lpcfg_*() and lp_*() functions is to allow
606  * for code compatibility between existing Samba4 and Samba3 code.
607  */
608
609 /* this global context supports the lp_*() function varients */
610 static struct loadparm_context *global_loadparm_context;
611
612 #define lpcfg_default_service global_loadparm_context->sDefault
613 #define lpcfg_global_service(i) global_loadparm_context->services[i]
614
615 #define FN_GLOBAL_STRING(fn_name,var_name) \
616  _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) : "";}
617
618 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
619  _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 : "";}
620
621 #define FN_GLOBAL_LIST(fn_name,var_name) \
622  _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
623
624 #define FN_GLOBAL_BOOL(fn_name,var_name) \
625  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
626
627 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
628  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
629
630 #define FN_LOCAL_STRING(fn_name,val) \
631  _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)));}
632
633 #define FN_LOCAL_LIST(fn_name,val) \
634  _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);}
635
636 #define FN_LOCAL_BOOL(fn_name,val) \
637  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
638
639 #define FN_LOCAL_INTEGER(fn_name,val) \
640  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
641
642 FN_GLOBAL_INTEGER(server_role, server_role)
643 FN_GLOBAL_INTEGER(sid_generator, sid_generator)
644 FN_GLOBAL_LIST(smb_ports, smb_ports)
645 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
646 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
647 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
648 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
649 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
650 FN_GLOBAL_INTEGER(web_port, web_port)
651 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
652 FN_GLOBAL_STRING(logfile, logfile)
653 FN_GLOBAL_STRING(share_backend, szShareBackend)
654 FN_GLOBAL_STRING(idmap_url, szIDMAP_URL)
655 FN_GLOBAL_STRING(spoolss_url, szSPOOLSS_URL)
656 FN_GLOBAL_STRING(wins_config_url, szWINS_CONFIG_URL)
657 FN_GLOBAL_STRING(wins_url, szWINS_URL)
658 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
659 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
660 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
661 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
662 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
663 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
664 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
665 FN_GLOBAL_STRING(private_dir, szPrivateDir)
666 FN_GLOBAL_STRING(serverstring, szServerString)
667 FN_GLOBAL_STRING(lockdir, szLockDir)
668 FN_GLOBAL_STRING(modulesdir, szModulesDir)
669 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
670 FN_GLOBAL_STRING(dos_charset, dos_charset)
671 FN_GLOBAL_STRING(unix_charset, unix_charset)
672 FN_GLOBAL_STRING(display_charset, display_charset)
673 FN_GLOBAL_STRING(piddir, szPidDir)
674 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
675 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
676 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
677 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
678 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
679 FN_GLOBAL_LIST(server_services, server_services)
680 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
681 FN_GLOBAL_STRING(auto_services, szAutoServices)
682 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
683 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
684 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
685 FN_GLOBAL_STRING(realm, szRealm_upper)
686 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
687 FN_GLOBAL_STRING(socket_options, socket_options)
688 FN_GLOBAL_STRING(workgroup, szWorkgroup)
689 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
690 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
691 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
692 FN_GLOBAL_LIST(interfaces, szInterfaces)
693 FN_GLOBAL_STRING(socket_address, szSocketAddress)
694 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
695 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
696 FN_GLOBAL_BOOL(wins_support, bWINSsupport)
697 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
698 FN_GLOBAL_STRING(wins_hook, szWINSHook)
699 FN_GLOBAL_BOOL(local_master, bLocalMaster)
700 FN_GLOBAL_BOOL(readraw, bReadRaw)
701 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
702 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
703 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
704 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
705 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
706 FN_GLOBAL_BOOL(time_server, bTimeServer)
707 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
708 FN_GLOBAL_BOOL(unicode, bUnicode)
709 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
710 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
711 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
712 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
713 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
714 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
715 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
716 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
717 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
718 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
719 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
720 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
721 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
722 FN_GLOBAL_INTEGER(maxmux, max_mux)
723 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
724 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
725 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
726 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
727 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
728 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
729 FN_GLOBAL_INTEGER(security, security)
730 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
731 FN_GLOBAL_INTEGER(announce_as, announce_as)
732
733 FN_LOCAL_STRING(pathname, szPath)
734 FN_LOCAL_LIST(hostsallow, szHostsallow)
735 FN_LOCAL_LIST(hostsdeny, szHostsdeny)
736 FN_LOCAL_STRING(comment, comment)
737 FN_LOCAL_STRING(fstype, fstype)
738 FN_LOCAL_LIST(ntvfs_handler, ntvfs_handler)
739 FN_LOCAL_BOOL(msdfs_root, bMSDfsRoot)
740 FN_LOCAL_BOOL(browseable, bBrowseable)
741 FN_LOCAL_BOOL(readonly, bRead_only)
742 FN_LOCAL_BOOL(print_ok, bPrint_ok)
743 FN_LOCAL_BOOL(map_hidden, bMap_hidden)
744 FN_LOCAL_BOOL(map_archive, bMap_archive)
745 FN_LOCAL_BOOL(strict_locking, bStrictLocking)
746 FN_LOCAL_BOOL(oplocks, bOplocks)
747 FN_LOCAL_BOOL(strict_sync, bStrictSync)
748 FN_LOCAL_BOOL(ci_filesystem, bCIFileSystem)
749 FN_LOCAL_BOOL(map_system, bMap_system)
750 FN_LOCAL_INTEGER(max_connections, iMaxConnections)
751 FN_LOCAL_INTEGER(csc_policy, iCSCPolicy)
752 FN_LOCAL_INTEGER(create_mask, iCreate_mask)
753 FN_LOCAL_INTEGER(force_create_mode, iCreate_force_mode)
754 FN_LOCAL_INTEGER(dir_mask, iDir_mask)
755 FN_LOCAL_INTEGER(force_dir_mode, iDir_force_mode)
756 FN_GLOBAL_INTEGER(server_signing, server_signing)
757 FN_GLOBAL_INTEGER(client_signing, client_signing)
758
759 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
760
761 /* local prototypes */
762 static int map_parameter(const char *pszParmName);
763 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
764                                         const char *pszServiceName);
765 static void copy_service(struct loadparm_service *pserviceDest,
766                          struct loadparm_service *pserviceSource,
767                          int *pcopymapDest);
768 static bool service_ok(struct loadparm_service *service);
769 static bool do_section(const char *pszSectionName, void *);
770 static void init_copymap(struct loadparm_service *pservice);
771
772 /* This is a helper function for parametrical options support. */
773 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
774 /* Actual parametrical functions are quite simple */
775 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
776                               struct loadparm_service *service,
777                               const char *type, const char *option)
778 {
779         char *vfskey_tmp = NULL;
780         char *vfskey = NULL;
781         struct parmlist_entry *data;
782
783         if (lp_ctx == NULL)
784                 return NULL;
785
786         data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
787
788         vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
789         if (vfskey_tmp == NULL) return NULL;
790         vfskey = strlower_talloc(NULL, vfskey_tmp);
791         talloc_free(vfskey_tmp);
792
793         while (data) {
794                 if (strcmp(data->key, vfskey) == 0) {
795                         talloc_free(vfskey);
796                         return data->value;
797                 }
798                 data = data->next;
799         }
800
801         if (service != NULL) {
802                 /* Try to fetch the same option but from globals */
803                 /* but only if we are not already working with globals */
804                 for (data = lp_ctx->globals->param_opt; data;
805                      data = data->next) {
806                         if (strcmp(data->key, vfskey) == 0) {
807                                 talloc_free(vfskey);
808                                 return data->value;
809                         }
810                 }
811         }
812
813         talloc_free(vfskey);
814
815         return NULL;
816 }
817
818
819 /**
820  * convenience routine to return int parameters.
821  */
822 static int lp_int(const char *s)
823 {
824
825         if (!s) {
826                 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
827                 return -1;
828         }
829
830         return strtol(s, NULL, 0);
831 }
832
833 /**
834  * convenience routine to return unsigned long parameters.
835  */
836 static int lp_ulong(const char *s)
837 {
838
839         if (!s) {
840                 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
841                 return -1;
842         }
843
844         return strtoul(s, NULL, 0);
845 }
846
847 /**
848  * convenience routine to return unsigned long parameters.
849  */
850 static double lp_double(const char *s)
851 {
852
853         if (!s) {
854                 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
855                 return -1;
856         }
857
858         return strtod(s, NULL);
859 }
860
861 /**
862  * convenience routine to return boolean parameters.
863  */
864 static bool lp_bool(const char *s)
865 {
866         bool ret = false;
867
868         if (!s) {
869                 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
870                 return false;
871         }
872
873         if (!set_boolean(s, &ret)) {
874                 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
875                 return false;
876         }
877
878         return ret;
879 }
880
881
882 /**
883  * Return parametric option from a given service. Type is a part of option before ':'
884  * Parametric option has following syntax: 'Type: option = value'
885  * Returned value is allocated in 'lp_talloc' context
886  */
887
888 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
889                               struct loadparm_service *service, const char *type,
890                               const char *option)
891 {
892         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
893
894         if (value)
895                 return lp_string(value);
896
897         return NULL;
898 }
899
900 /**
901  * Return parametric option from a given service. Type is a part of option before ':'
902  * Parametric option has following syntax: 'Type: option = value'
903  * Returned value is allocated in 'lp_talloc' context
904  */
905
906 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
907                                     struct loadparm_context *lp_ctx,
908                                     struct loadparm_service *service,
909                                     const char *type,
910                                     const char *option, const char *separator)
911 {
912         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
913
914         if (value != NULL)
915                 return (const char **)str_list_make(mem_ctx, value, separator);
916
917         return NULL;
918 }
919
920 /**
921  * Return parametric option from a given service. Type is a part of option before ':'
922  * Parametric option has following syntax: 'Type: option = value'
923  */
924
925 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
926                    struct loadparm_service *service, const char *type,
927                    const char *option, int default_v)
928 {
929         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
930
931         if (value)
932                 return lp_int(value);
933
934         return default_v;
935 }
936
937 /**
938  * Return parametric option from a given service. Type is a part of
939  * option before ':'.
940  * Parametric option has following syntax: 'Type: option = value'.
941  */
942
943 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
944                   struct loadparm_service *service, const char *type,
945                   const char *option, int default_v)
946 {
947         uint64_t bval;
948
949         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
950
951         if (value && conv_str_size_error(value, &bval)) {
952                 if (bval <= INT_MAX) {
953                         return (int)bval;
954                 }
955         }
956
957         return default_v;
958 }
959
960 /**
961  * Return parametric option from a given service.
962  * Type is a part of option before ':'
963  * Parametric option has following syntax: 'Type: option = value'
964  */
965 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
966                             struct loadparm_service *service, const char *type,
967                             const char *option, unsigned long default_v)
968 {
969         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
970
971         if (value)
972                 return lp_ulong(value);
973
974         return default_v;
975 }
976
977
978 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
979                       struct loadparm_service *service, const char *type,
980                       const char *option, double default_v)
981 {
982         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
983
984         if (value != NULL)
985                 return lp_double(value);
986
987         return default_v;
988 }
989
990 /**
991  * Return parametric option from a given service. Type is a part of option before ':'
992  * Parametric option has following syntax: 'Type: option = value'
993  */
994
995 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
996                      struct loadparm_service *service, const char *type,
997                      const char *option, bool default_v)
998 {
999         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1000
1001         if (value != NULL)
1002                 return lp_bool(value);
1003
1004         return default_v;
1005 }
1006
1007
1008 /**
1009  * Initialise a service to the defaults.
1010  */
1011
1012 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1013 {
1014         struct loadparm_service *pservice =
1015                 talloc_zero(mem_ctx, struct loadparm_service);
1016         copy_service(pservice, sDefault, NULL);
1017         return pservice;
1018 }
1019
1020 /**
1021  * Set a string value, deallocating any existing space, and allocing the space
1022  * for the string
1023  */
1024 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1025 {
1026         talloc_free(*dest);
1027
1028         if (src == NULL)
1029                 src = "";
1030
1031         *dest = talloc_strdup(mem_ctx, src);
1032         if ((*dest) == NULL) {
1033                 DEBUG(0,("Out of memory in string_set\n"));
1034                 return false;
1035         }
1036
1037         return true;
1038 }
1039
1040 /**
1041  * Set a string value, deallocating any existing space, and allocing the space
1042  * for the string
1043  */
1044 static bool string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1045 {
1046         talloc_free(*dest);
1047
1048         if (src == NULL)
1049                 src = "";
1050
1051         *dest = strupper_talloc(mem_ctx, src);
1052         if ((*dest) == NULL) {
1053                 DEBUG(0,("Out of memory in string_set_upper\n"));
1054                 return false;
1055         }
1056
1057         return true;
1058 }
1059
1060
1061
1062 /**
1063  * Add a new service to the services array initialising it with the given
1064  * service.
1065  */
1066
1067 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1068                                            const struct loadparm_service *pservice,
1069                                            const char *name)
1070 {
1071         int i;
1072         struct loadparm_service tservice;
1073         int num_to_alloc = lp_ctx->iNumServices + 1;
1074         struct parmlist_entry *data, *pdata;
1075
1076         if (pservice == NULL) {
1077                 pservice = lp_ctx->sDefault;
1078         }
1079
1080         tservice = *pservice;
1081
1082         /* it might already exist */
1083         if (name) {
1084                 struct loadparm_service *service = getservicebyname(lp_ctx,
1085                                                                     name);
1086                 if (service != NULL) {
1087                         /* Clean all parametric options for service */
1088                         /* They will be added during parsing again */
1089                         data = service->param_opt;
1090                         while (data) {
1091                                 pdata = data->next;
1092                                 talloc_free(data);
1093                                 data = pdata;
1094                         }
1095                         service->param_opt = NULL;
1096                         return service;
1097                 }
1098         }
1099
1100         /* find an invalid one */
1101         for (i = 0; i < lp_ctx->iNumServices; i++)
1102                 if (lp_ctx->services[i] == NULL)
1103                         break;
1104
1105         /* if not, then create one */
1106         if (i == lp_ctx->iNumServices) {
1107                 struct loadparm_service **tsp;
1108
1109                 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1110
1111                 if (!tsp) {
1112                         DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1113                         return NULL;
1114                 } else {
1115                         lp_ctx->services = tsp;
1116                         lp_ctx->services[lp_ctx->iNumServices] = NULL;
1117                 }
1118
1119                 lp_ctx->iNumServices++;
1120         }
1121
1122         lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1123         if (lp_ctx->services[i] == NULL) {
1124                 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1125                 return NULL;
1126         }
1127         copy_service(lp_ctx->services[i], &tservice, NULL);
1128         if (name != NULL)
1129                 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1130         return lp_ctx->services[i];
1131 }
1132
1133 /**
1134  * Add a new home service, with the specified home directory, defaults coming
1135  * from service ifrom.
1136  */
1137
1138 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1139                  const char *pszHomename,
1140                  struct loadparm_service *default_service,
1141                  const char *user, const char *pszHomedir)
1142 {
1143         struct loadparm_service *service;
1144
1145         service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1146
1147         if (service == NULL)
1148                 return false;
1149
1150         if (!(*(default_service->szPath))
1151             || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1152                 service->szPath = talloc_strdup(service, pszHomedir);
1153         } else {
1154                 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1155         }
1156
1157         if (!(*(service->comment))) {
1158                 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1159         }
1160         service->bAvailable = default_service->bAvailable;
1161         service->bBrowseable = default_service->bBrowseable;
1162
1163         DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1164                   pszHomename, user, service->szPath));
1165
1166         return true;
1167 }
1168
1169 /**
1170  * Add a new printer service, with defaults coming from service iFrom.
1171  */
1172
1173 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1174                        const char *pszPrintername,
1175                        struct loadparm_service *default_service)
1176 {
1177         const char *comment = "From Printcap";
1178         struct loadparm_service *service;
1179         service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1180
1181         if (service == NULL)
1182                 return false;
1183
1184         /* note that we do NOT default the availability flag to True - */
1185         /* we take it from the default service passed. This allows all */
1186         /* dynamic printers to be disabled by disabling the [printers] */
1187         /* entry (if/when the 'available' keyword is implemented!).    */
1188
1189         /* the printer name is set to the service name. */
1190         string_set(service, &service->szPrintername, pszPrintername);
1191         string_set(service, &service->comment, comment);
1192         service->bBrowseable = default_service->bBrowseable;
1193         /* Printers cannot be read_only. */
1194         service->bRead_only = false;
1195         /* Printer services must be printable. */
1196         service->bPrint_ok = true;
1197
1198         DEBUG(3, ("adding printer service %s\n", pszPrintername));
1199
1200         return true;
1201 }
1202
1203 /**
1204  * Map a parameter's string representation to something we can use.
1205  * Returns False if the parameter string is not recognised, else TRUE.
1206  */
1207
1208 static int map_parameter(const char *pszParmName)
1209 {
1210         int iIndex;
1211
1212         if (*pszParmName == '-')
1213                 return -1;
1214
1215         for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1216                 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1217                         return iIndex;
1218
1219         /* Warn only if it isn't parametric option */
1220         if (strchr(pszParmName, ':') == NULL)
1221                 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1222         /* We do return 'fail' for parametric options as well because they are
1223            stored in different storage
1224          */
1225         return -1;
1226 }
1227
1228
1229 /**
1230   return the parameter structure for a parameter
1231 */
1232 struct parm_struct *lpcfg_parm_struct(const char *name)
1233 {
1234         int parmnum = map_parameter(name);
1235         if (parmnum == -1) return NULL;
1236         return &parm_table[parmnum];
1237 }
1238
1239 /**
1240   return the parameter pointer for a parameter
1241 */
1242 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
1243                   struct loadparm_service *service, struct parm_struct *parm)
1244 {
1245         if (service == NULL) {
1246                 if (parm->pclass == P_LOCAL)
1247                         return ((char *)lp_ctx->sDefault)+parm->offset;
1248                 else if (parm->pclass == P_GLOBAL)
1249                         return ((char *)lp_ctx->globals)+parm->offset;
1250                 else return NULL;
1251         } else {
1252                 return ((char *)service) + parm->offset;
1253         }
1254 }
1255
1256 /**
1257  * Find a service by name. Otherwise works like get_service.
1258  */
1259
1260 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1261                                         const char *pszServiceName)
1262 {
1263         int iService;
1264
1265         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1266                 if (lp_ctx->services[iService] != NULL &&
1267                     strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1268                         return lp_ctx->services[iService];
1269                 }
1270
1271         return NULL;
1272 }
1273
1274 /**
1275  * Copy a service structure to another.
1276  * If pcopymapDest is NULL then copy all fields
1277  */
1278
1279 static void copy_service(struct loadparm_service *pserviceDest,
1280                          struct loadparm_service *pserviceSource,
1281                          int *pcopymapDest)
1282 {
1283         int i;
1284         bool bcopyall = (pcopymapDest == NULL);
1285         struct parmlist_entry *data, *pdata, *paramo;
1286         bool not_added;
1287
1288         for (i = 0; parm_table[i].label; i++)
1289                 if (parm_table[i].offset != -1 && parm_table[i].pclass == P_LOCAL &&
1290                     (bcopyall || pcopymapDest[i])) {
1291                         void *src_ptr =
1292                                 ((char *)pserviceSource) + parm_table[i].offset;
1293                         void *dest_ptr =
1294                                 ((char *)pserviceDest) + parm_table[i].offset;
1295
1296                         switch (parm_table[i].type) {
1297                                 case P_BOOL:
1298                                         *(int *)dest_ptr = *(int *)src_ptr;
1299                                         break;
1300
1301                                 case P_INTEGER:
1302                                 case P_OCTAL:
1303                                 case P_ENUM:
1304                                         *(int *)dest_ptr = *(int *)src_ptr;
1305                                         break;
1306
1307                                 case P_STRING:
1308                                         string_set(pserviceDest,
1309                                                    (char **)dest_ptr,
1310                                                    *(char **)src_ptr);
1311                                         break;
1312
1313                                 case P_USTRING:
1314                                         string_set_upper(pserviceDest,
1315                                                          (char **)dest_ptr,
1316                                                          *(char **)src_ptr);
1317                                         break;
1318                                 case P_LIST:
1319                                         *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest, 
1320                                                                                   *(const char ***)src_ptr);
1321                                         break;
1322                                 default:
1323                                         break;
1324                         }
1325                 }
1326
1327         if (bcopyall) {
1328                 init_copymap(pserviceDest);
1329                 if (pserviceSource->copymap)
1330                         memcpy((void *)pserviceDest->copymap,
1331                                (void *)pserviceSource->copymap,
1332                                sizeof(int) * NUMPARAMETERS);
1333         }
1334
1335         data = pserviceSource->param_opt;
1336         while (data) {
1337                 not_added = true;
1338                 pdata = pserviceDest->param_opt;
1339                 /* Traverse destination */
1340                 while (pdata) {
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,
1345                                                              data->value);
1346                                 not_added = false;
1347                                 break;
1348                         }
1349                         pdata = pdata->next;
1350                 }
1351                 if (not_added) {
1352                         paramo = talloc_zero(pserviceDest, struct parmlist_entry);
1353                         if (paramo == NULL)
1354                                 smb_panic("OOM");
1355                         paramo->key = talloc_reference(paramo, data->key);
1356                         paramo->value = talloc_reference(paramo, data->value);
1357                         DLIST_ADD(pserviceDest->param_opt, paramo);
1358                 }
1359                 data = data->next;
1360         }
1361 }
1362
1363 /**
1364  * Check a service for consistency. Return False if the service is in any way
1365  * incomplete or faulty, else True.
1366  */
1367 static bool service_ok(struct loadparm_service *service)
1368 {
1369         bool bRetval;
1370
1371         bRetval = true;
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"));
1375                 bRetval = false;
1376         }
1377
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;
1385                 }
1386                 /* [printers] service must also be non-browsable. */
1387                 if (service->bBrowseable)
1388                         service->bBrowseable = false;
1389         }
1390
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));
1395
1396         return bRetval;
1397 }
1398
1399
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 ********************************************************************/
1404
1405 static void add_to_file_list(struct loadparm_context *lp_ctx,
1406                              const char *fname, const char *subfname)
1407 {
1408         struct file_lists *f = lp_ctx->file_lists;
1409
1410         while (f) {
1411                 if (f->name && !strcmp(f->name, fname))
1412                         break;
1413                 f = f->next;
1414         }
1415
1416         if (!f) {
1417                 f = talloc(lp_ctx, struct file_lists);
1418                 if (!f)
1419                         return;
1420                 f->next = lp_ctx->file_lists;
1421                 f->name = talloc_strdup(f, fname);
1422                 if (!f->name) {
1423                         talloc_free(f);
1424                         return;
1425                 }
1426                 f->subfname = talloc_strdup(f, subfname);
1427                 if (!f->subfname) {
1428                         talloc_free(f);
1429                         return;
1430                 }
1431                 lp_ctx->file_lists = f;
1432                 f->modtime = file_modtime(subfname);
1433         } else {
1434                 time_t t = file_modtime(subfname);
1435                 if (t)
1436                         f->modtime = t;
1437         }
1438 }
1439
1440 /*******************************************************************
1441  Check if a config file has changed date.
1442 ********************************************************************/
1443 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1444 {
1445         struct file_lists *f;
1446         DEBUG(6, ("lp_file_list_changed()\n"));
1447
1448         for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1449                 char *n2;
1450                 time_t mod_time;
1451
1452                 n2 = standard_sub_basic(lp_ctx, f->name);
1453
1454                 DEBUGADD(6, ("file %s -> %s  last mod_time: %s\n",
1455                              f->name, n2, ctime(&f->modtime)));
1456
1457                 mod_time = file_modtime(n2);
1458
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,
1461                                   ctime(&mod_time)));
1462                         f->modtime = mod_time;
1463                         talloc_free(f->subfname);
1464                         f->subfname = talloc_strdup(f, n2);
1465                         return true;
1466                 }
1467         }
1468         return false;
1469 }
1470
1471 /***************************************************************************
1472  Handle the "realm" parameter
1473 ***************************************************************************/
1474
1475 static bool handle_realm(struct loadparm_context *lp_ctx,
1476                          const char *pszParmValue, char **ptr)
1477 {
1478         string_set(lp_ctx, ptr, pszParmValue);
1479
1480         talloc_free(lp_ctx->globals->szRealm_upper);
1481         talloc_free(lp_ctx->globals->szRealm_lower);
1482
1483         lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
1484         lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
1485
1486         return true;
1487 }
1488
1489 /***************************************************************************
1490  Handle the include operation.
1491 ***************************************************************************/
1492
1493 static bool handle_include(struct loadparm_context *lp_ctx,
1494                            const char *pszParmValue, char **ptr)
1495 {
1496         char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1497
1498         add_to_file_list(lp_ctx, pszParmValue, fname);
1499
1500         string_set(lp_ctx, ptr, fname);
1501
1502         if (file_exist(fname))
1503                 return pm_process(fname, do_section, do_parameter, lp_ctx);
1504
1505         DEBUG(2, ("Can't find include file %s\n", fname));
1506
1507         return false;
1508 }
1509
1510 /***************************************************************************
1511  Handle the interpretation of the copy parameter.
1512 ***************************************************************************/
1513
1514 static bool handle_copy(struct loadparm_context *lp_ctx,
1515                         const char *pszParmValue, char **ptr)
1516 {
1517         bool bRetval;
1518         struct loadparm_service *serviceTemp;
1519
1520         string_set(lp_ctx, ptr, pszParmValue);
1521
1522         bRetval = false;
1523
1524         DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1525
1526         if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1527                 if (serviceTemp == lp_ctx->currentService) {
1528                         DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1529                 } else {
1530                         copy_service(lp_ctx->currentService,
1531                                      serviceTemp,
1532                                      lp_ctx->currentService->copymap);
1533                         bRetval = true;
1534                 }
1535         } else {
1536                 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1537                           pszParmValue));
1538                 bRetval = false;
1539         }
1540
1541         return bRetval;
1542 }
1543
1544 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1545                         const char *pszParmValue, char **ptr)
1546 {
1547
1548         string_set(lp_ctx, ptr, pszParmValue);
1549         if (lp_ctx->global) {
1550                 return debug_parse_levels(pszParmValue);
1551         }
1552         return true;
1553 }
1554
1555 static bool handle_logfile(struct loadparm_context *lp_ctx,
1556                         const char *pszParmValue, char **ptr)
1557 {
1558         debug_set_logfile(pszParmValue);
1559         if (lp_ctx->global) {
1560                 string_set(lp_ctx, ptr, pszParmValue);
1561         }
1562         return true;
1563 }
1564
1565 /***************************************************************************
1566  Initialise a copymap.
1567 ***************************************************************************/
1568
1569 static void init_copymap(struct loadparm_service *pservice)
1570 {
1571         int i;
1572         talloc_free(pservice->copymap);
1573         pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1574         if (pservice->copymap == NULL) {
1575                 DEBUG(0,
1576                       ("Couldn't allocate copymap!! (size %d)\n",
1577                        (int)NUMPARAMETERS));
1578                 return;
1579         }
1580         for (i = 0; i < NUMPARAMETERS; i++)
1581                 pservice->copymap[i] = true;
1582 }
1583
1584 /**
1585  * Process a parametric option
1586  */
1587 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1588                                        struct loadparm_service *service,
1589                                        const char *pszParmName,
1590                                        const char *pszParmValue, int flags)
1591 {
1592         struct parmlist_entry *paramo, *data;
1593         char *name;
1594         TALLOC_CTX *mem_ctx;
1595
1596         while (isspace((unsigned char)*pszParmName)) {
1597                 pszParmName++;
1598         }
1599
1600         name = strlower_talloc(lp_ctx, pszParmName);
1601         if (!name) return false;
1602
1603         if (service == NULL) {
1604                 data = lp_ctx->globals->param_opt;
1605                 mem_ctx = lp_ctx->globals;
1606         } else {
1607                 data = service->param_opt;
1608                 mem_ctx = service;
1609         }
1610
1611         /* Traverse destination */
1612         for (paramo=data; paramo; paramo=paramo->next) {
1613                 /* If we already have the option set, override it unless
1614                    it was a command line option and the new one isn't */
1615                 if (strcmp(paramo->key, name) == 0) {
1616                         if ((paramo->priority & FLAG_CMDLINE) &&
1617                             !(flags & FLAG_CMDLINE)) {
1618                                 talloc_free(name);
1619                                 return true;
1620                         }
1621
1622                         talloc_free(paramo->value);
1623                         paramo->value = talloc_strdup(paramo, pszParmValue);
1624                         paramo->priority = flags;
1625                         talloc_free(name);
1626                         return true;
1627                 }
1628         }
1629
1630         paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1631         if (!paramo)
1632                 smb_panic("OOM");
1633         paramo->key = talloc_strdup(paramo, name);
1634         paramo->value = talloc_strdup(paramo, pszParmValue);
1635         paramo->priority = flags;
1636         if (service == NULL) {
1637                 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1638         } else {
1639                 DLIST_ADD(service->param_opt, paramo);
1640         }
1641
1642         talloc_free(name);
1643
1644         return true;
1645 }
1646
1647 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1648                          const char *pszParmName, const char *pszParmValue,
1649                          struct loadparm_context *lp_ctx, bool on_globals)
1650 {
1651         int i;
1652         /* if it is a special case then go ahead */
1653         if (parm_table[parmnum].special) {
1654                 bool ret;
1655                 ret = parm_table[parmnum].special(lp_ctx, pszParmValue,
1656                                                   (char **)parm_ptr);
1657                 if (!ret) {
1658                         return false;
1659                 }
1660                 goto mark_non_default;
1661         }
1662
1663         /* now switch on the type of variable it is */
1664         switch (parm_table[parmnum].type)
1665         {
1666                 case P_BOOL: {
1667                         bool b;
1668                         if (!set_boolean(pszParmValue, &b)) {
1669                                 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1670                                 return false;
1671                         }
1672                         *(int *)parm_ptr = b;
1673                         }
1674                         break;
1675
1676                 case P_INTEGER:
1677                         *(int *)parm_ptr = atoi(pszParmValue);
1678                         break;
1679
1680                 case P_OCTAL:
1681                         *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1682                         break;
1683
1684                 case P_BYTES:
1685                 {
1686                         uint64_t val;
1687                         if (conv_str_size_error(pszParmValue, &val)) {
1688                                 if (val <= INT_MAX) {
1689                                         *(int *)parm_ptr = (int)val;
1690                                         break;
1691                                 }
1692                         }
1693
1694                         DEBUG(0,("lp_do_parameter(%s): value is not "
1695                             "a valid size specifier!\n", pszParmValue));
1696                         return false;
1697                 }
1698
1699                 case P_CMDLIST:
1700                         *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1701                                                                   pszParmValue, NULL);
1702                         break;
1703                 case P_LIST:
1704                 {
1705                         char **new_list = str_list_make(mem_ctx,
1706                                                         pszParmValue, NULL);
1707                         for (i=0; new_list[i]; i++) {
1708                                 if (new_list[i][0] == '+' && new_list[i][1] &&
1709                                     (!str_list_check(*(const char ***)parm_ptr,
1710                                                      &new_list[i][1]))) {
1711                                         *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1712                                                                                  &new_list[i][1]);
1713                                 } else if (new_list[i][0] == '-' && new_list[i][1]) {
1714 #if 0 /* This is commented out because we sometimes parse the list
1715        * twice, and so we can't assert on this */
1716                                         if (!str_list_check(*(const char ***)parm_ptr,
1717                                                             &new_list[i][1])) {
1718                                                 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
1719                                                           pszParmName, pszParmValue, new_list[i],
1720                                                           str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
1721                                                 return false;
1722
1723                                         }
1724 #endif
1725                                         str_list_remove(*(const char ***)parm_ptr,
1726                                                         &new_list[i][1]);
1727                                 } else {
1728                                         if (i != 0) {
1729                                                 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1730                                                           pszParmName, pszParmValue));
1731                                                 return false;
1732                                         }
1733                                         *(const char ***)parm_ptr = (const char **) new_list;
1734                                         break;
1735                                 }
1736                         }
1737                         break;
1738                 }
1739                 case P_STRING:
1740                         string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1741                         break;
1742
1743                 case P_USTRING:
1744                         string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1745                         break;
1746
1747                 case P_ENUM:
1748                         for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1749                                 if (strequal
1750                                     (pszParmValue,
1751                                      parm_table[parmnum].enum_list[i].name)) {
1752                                         *(int *)parm_ptr =
1753                                                 parm_table[parmnum].
1754                                                 enum_list[i].value;
1755                                         break;
1756                                 }
1757                         }
1758                         if (!parm_table[parmnum].enum_list[i].name) {
1759                                 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n", 
1760                                          pszParmValue, pszParmName));
1761                                 return false;
1762                         }
1763                         break;
1764         }
1765
1766 mark_non_default:
1767         if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1768                 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1769                 /* we have to also unset FLAG_DEFAULT on aliases */
1770                 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1771                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1772                 }
1773                 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1774                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1775                 }
1776         }
1777         return true;
1778 }
1779
1780
1781 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1782                                const char *pszParmName, const char *pszParmValue)
1783 {
1784         int parmnum = map_parameter(pszParmName);
1785         void *parm_ptr;
1786
1787         if (parmnum < 0) {
1788                 if (strchr(pszParmName, ':')) {
1789                         return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1790                 }
1791                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1792                 return true;
1793         }
1794
1795         /* if the flag has been set on the command line, then don't allow override,
1796            but don't report an error */
1797         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1798                 return true;
1799         }
1800
1801         parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1802
1803         return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1804                             pszParmName, pszParmValue, lp_ctx, true);
1805 }
1806
1807 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1808                                 struct loadparm_service *service,
1809                                 const char *pszParmName, const char *pszParmValue)
1810 {
1811         void *parm_ptr;
1812         int i;
1813         int parmnum = map_parameter(pszParmName);
1814
1815         if (parmnum < 0) {
1816                 if (strchr(pszParmName, ':')) {
1817                         return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1818                 }
1819                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1820                 return true;
1821         }
1822
1823         /* if the flag has been set on the command line, then don't allow override,
1824            but don't report an error */
1825         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1826                 return true;
1827         }
1828
1829         if (parm_table[parmnum].pclass == P_GLOBAL) {
1830                 DEBUG(0,
1831                       ("Global parameter %s found in service section!\n",
1832                        pszParmName));
1833                 return true;
1834         }
1835         parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1836
1837         if (!service->copymap)
1838                 init_copymap(service);
1839
1840         /* this handles the aliases - set the copymap for other
1841          * entries with the same data pointer */
1842         for (i = 0; parm_table[i].label; i++)
1843                 if (parm_table[i].offset == parm_table[parmnum].offset &&
1844                     parm_table[i].pclass == parm_table[parmnum].pclass)
1845                         service->copymap[i] = false;
1846
1847         return set_variable(service, parmnum, parm_ptr, pszParmName,
1848                             pszParmValue, lp_ctx, false);
1849 }
1850
1851 /**
1852  * Process a parameter.
1853  */
1854
1855 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1856                          void *userdata)
1857 {
1858         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1859
1860         if (lp_ctx->bInGlobalSection)
1861                 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1862                                               pszParmValue);
1863         else
1864                 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1865                                                   pszParmName, pszParmValue);
1866 }
1867
1868 /*
1869   variable argument do parameter
1870 */
1871 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1872 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1873                                 const char *pszParmName, const char *fmt, ...)
1874 {
1875         char *s;
1876         bool ret;
1877         va_list ap;
1878
1879         va_start(ap, fmt);
1880         s = talloc_vasprintf(NULL, fmt, ap);
1881         va_end(ap);
1882         ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1883         talloc_free(s);
1884         return ret;
1885 }
1886
1887
1888 /*
1889   set a parameter from the commandline - this is called from command line parameter
1890   parsing code. It sets the parameter then marks the parameter as unable to be modified
1891   by smb.conf processing
1892 */
1893 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1894                        const char *pszParmValue)
1895 {
1896         int parmnum = map_parameter(pszParmName);
1897         int i;
1898
1899         while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1900
1901
1902         if (parmnum < 0 && strchr(pszParmName, ':')) {
1903                 /* set a parametric option */
1904                 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1905                                                   pszParmValue, FLAG_CMDLINE);
1906         }
1907
1908         if (parmnum < 0) {
1909                 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1910                 return false;
1911         }
1912
1913         /* reset the CMDLINE flag in case this has been called before */
1914         lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1915
1916         if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1917                 return false;
1918         }
1919
1920         lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1921
1922         /* we have to also set FLAG_CMDLINE on aliases */
1923         for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1924                 lp_ctx->flags[i] |= FLAG_CMDLINE;
1925         }
1926         for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1927                 lp_ctx->flags[i] |= FLAG_CMDLINE;
1928         }
1929
1930         return true;
1931 }
1932
1933 /*
1934   set a option from the commandline in 'a=b' format. Use to support --option
1935 */
1936 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1937 {
1938         char *p, *s;
1939         bool ret;
1940
1941         s = strdup(option);
1942         if (!s) {
1943                 return false;
1944         }
1945
1946         p = strchr(s, '=');
1947         if (!p) {
1948                 free(s);
1949                 return false;
1950         }
1951
1952         *p = 0;
1953
1954         ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1955         free(s);
1956         return ret;
1957 }
1958
1959
1960 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1961
1962 /**
1963  * Print a parameter of the specified type.
1964  */
1965
1966 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1967 {
1968         int i;
1969         const char *list_sep = ", "; /* For the seperation of lists values that we print below */
1970         switch (p->type)
1971         {
1972                 case P_ENUM:
1973                         for (i = 0; p->enum_list[i].name; i++) {
1974                                 if (*(int *)ptr == p->enum_list[i].value) {
1975                                         fprintf(f, "%s",
1976                                                 p->enum_list[i].name);
1977                                         break;
1978                                 }
1979                         }
1980                         break;
1981
1982                 case P_BOOL:
1983                         fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1984                         break;
1985
1986                 case P_INTEGER:
1987                 case P_BYTES:
1988                         fprintf(f, "%d", *(int *)ptr);
1989                         break;
1990
1991                 case P_OCTAL:
1992                         fprintf(f, "0%o", *(int *)ptr);
1993                         break;
1994
1995                 case P_CMDLIST:
1996                         list_sep = " ";
1997                         /* fall through */
1998                 case P_LIST:
1999                         if ((char ***)ptr && *(char ***)ptr) {
2000                                 char **list = *(char ***)ptr;
2001
2002                                 for (; *list; list++) {
2003                                         if (*(list+1) == NULL) {
2004                                                 /* last item, print no extra seperator after */
2005                                                 list_sep = "";
2006                                         }
2007                                         fprintf(f, "%s%s", *list, list_sep);
2008                                 }
2009                         }
2010                         break;
2011
2012                 case P_STRING:
2013                 case P_USTRING:
2014                         if (*(char **)ptr) {
2015                                 fprintf(f, "%s", *(char **)ptr);
2016                         }
2017                         break;
2018         }
2019 }
2020
2021 /**
2022  * Check if two parameters are equal.
2023  */
2024
2025 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2026 {
2027         switch (type) {
2028                 case P_BOOL:
2029                         return (*((int *)ptr1) == *((int *)ptr2));
2030
2031                 case P_INTEGER:
2032                 case P_OCTAL:
2033                 case P_BYTES:
2034                 case P_ENUM:
2035                         return (*((int *)ptr1) == *((int *)ptr2));
2036
2037                 case P_CMDLIST:
2038                 case P_LIST:
2039                         return str_list_equal((const char **)(*(char ***)ptr1),
2040                                               (const char **)(*(char ***)ptr2));
2041
2042                 case P_STRING:
2043                 case P_USTRING:
2044                 {
2045                         char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2046                         if (p1 && !*p1)
2047                                 p1 = NULL;
2048                         if (p2 && !*p2)
2049                                 p2 = NULL;
2050                         return (p1 == p2 || strequal(p1, p2));
2051                 }
2052         }
2053         return false;
2054 }
2055
2056 /**
2057  * Process a new section (service).
2058  *
2059  * At this stage all sections are services.
2060  * Later we'll have special sections that permit server parameters to be set.
2061  * Returns True on success, False on failure.
2062  */
2063
2064 static bool do_section(const char *pszSectionName, void *userdata)
2065 {
2066         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2067         bool bRetval;
2068         bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2069                          (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2070         bRetval = false;
2071
2072         /* if we've just struck a global section, note the fact. */
2073         lp_ctx->bInGlobalSection = isglobal;
2074
2075         /* check for multiple global sections */
2076         if (lp_ctx->bInGlobalSection) {
2077                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2078                 return true;
2079         }
2080
2081         /* if we have a current service, tidy it up before moving on */
2082         bRetval = true;
2083
2084         if (lp_ctx->currentService != NULL)
2085                 bRetval = service_ok(lp_ctx->currentService);
2086
2087         /* if all is still well, move to the next record in the services array */
2088         if (bRetval) {
2089                 /* We put this here to avoid an odd message order if messages are */
2090                 /* issued by the post-processing of a previous section. */
2091                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2092
2093                 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2094                                                                    pszSectionName))
2095                     == NULL) {
2096                         DEBUG(0, ("Failed to add a new service\n"));
2097                         return false;
2098                 }
2099         }
2100
2101         return bRetval;
2102 }
2103
2104
2105 /**
2106  * Determine if a particular base parameter is currently set to the default value.
2107  */
2108
2109 static bool is_default(struct loadparm_service *sDefault, int i)
2110 {
2111         void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2112         if (!defaults_saved)
2113                 return false;
2114         switch (parm_table[i].type) {
2115                 case P_CMDLIST:
2116                 case P_LIST:
2117                         return str_list_equal((const char **)parm_table[i].def.lvalue, 
2118                                               (const char **)def_ptr);
2119                 case P_STRING:
2120                 case P_USTRING:
2121                         return strequal(parm_table[i].def.svalue,
2122                                         *(char **)def_ptr);
2123                 case P_BOOL:
2124                         return parm_table[i].def.bvalue ==
2125                                 *(int *)def_ptr;
2126                 case P_INTEGER:
2127                 case P_OCTAL:
2128                 case P_BYTES:
2129                 case P_ENUM:
2130                         return parm_table[i].def.ivalue ==
2131                                 *(int *)def_ptr;
2132         }
2133         return false;
2134 }
2135
2136 /**
2137  *Display the contents of the global structure.
2138  */
2139
2140 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2141                          bool show_defaults)
2142 {
2143         int i;
2144         struct parmlist_entry *data;
2145
2146         fprintf(f, "# Global parameters\n[global]\n");
2147
2148         for (i = 0; parm_table[i].label; i++)
2149                 if (parm_table[i].pclass == P_GLOBAL &&
2150                     parm_table[i].offset != -1 &&
2151                     (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2152                         if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2153                                 continue;
2154                         fprintf(f, "\t%s = ", parm_table[i].label);
2155                         print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2156                         fprintf(f, "\n");
2157         }
2158         if (lp_ctx->globals->param_opt != NULL) {
2159                 for (data = lp_ctx->globals->param_opt; data;
2160                      data = data->next) {
2161                         if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2162                                 continue;
2163                         }
2164                         fprintf(f, "\t%s = %s\n", data->key, data->value);
2165                 }
2166         }
2167
2168 }
2169
2170 /**
2171  * Display the contents of a single services record.
2172  */
2173
2174 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2175                            unsigned int *flags)
2176 {
2177         int i;
2178         struct parmlist_entry *data;
2179
2180         if (pService != sDefault)
2181                 fprintf(f, "\n[%s]\n", pService->szService);
2182
2183         for (i = 0; parm_table[i].label; i++) {
2184                 if (parm_table[i].pclass == P_LOCAL &&
2185                     parm_table[i].offset != -1 &&
2186                     (*parm_table[i].label != '-') &&
2187                     (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
2188                 {
2189                         if (pService == sDefault) {
2190                                 if (flags && (flags[i] & FLAG_DEFAULT)) {
2191                                         continue;
2192                                 }
2193                                 if (defaults_saved) {
2194                                         if (is_default(sDefault, i)) {
2195                                                 continue;
2196                                         }
2197                                 }
2198                         } else {
2199                                 if (equal_parameter(parm_table[i].type,
2200                                                     ((char *)pService) +
2201                                                     parm_table[i].offset,
2202                                                     ((char *)sDefault) +
2203                                                     parm_table[i].offset))
2204                                         continue;
2205                         }
2206
2207                         fprintf(f, "\t%s = ", parm_table[i].label);
2208                         print_parameter(&parm_table[i],
2209                                         ((char *)pService) + parm_table[i].offset, f);
2210                         fprintf(f, "\n");
2211                 }
2212         }
2213         if (pService->param_opt != NULL) {
2214                 for (data = pService->param_opt; data; data = data->next) {
2215                         fprintf(f, "\t%s = %s\n", data->key, data->value);
2216                 }
2217         }
2218 }
2219
2220 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2221                             struct loadparm_service *service,
2222                             const char *parm_name, FILE * f)
2223 {
2224         struct parm_struct *parm;
2225         void *ptr;
2226
2227         parm = lpcfg_parm_struct(parm_name);
2228         if (!parm) {
2229                 return false;
2230         }
2231
2232         ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2233
2234         print_parameter(parm, ptr, f);
2235         fprintf(f, "\n");
2236         return true;
2237 }
2238
2239 /**
2240  * Return info about the next parameter in a service.
2241  * snum==-1 gives the globals.
2242  * Return NULL when out of parameters.
2243  */
2244
2245
2246 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2247                                          int allparameters)
2248 {
2249         if (snum == -1) {
2250                 /* do the globals */
2251                 for (; parm_table[*i].label; (*i)++) {
2252                         if (parm_table[*i].offset == -1
2253                             || (*parm_table[*i].label == '-'))
2254                                 continue;
2255
2256                         if ((*i) > 0
2257                             && (parm_table[*i].offset ==
2258                                 parm_table[(*i) - 1].offset))
2259                                 continue;
2260
2261                         return &parm_table[(*i)++];
2262                 }
2263         } else {
2264                 struct loadparm_service *pService = lp_ctx->services[snum];
2265
2266                 for (; parm_table[*i].label; (*i)++) {
2267                         if (parm_table[*i].pclass == P_LOCAL &&
2268                             parm_table[*i].offset != -1 &&
2269                             (*parm_table[*i].label != '-') &&
2270                             ((*i) == 0 ||
2271                              (parm_table[*i].offset !=
2272                               parm_table[(*i) - 1].offset)))
2273                         {
2274                                 if (allparameters ||
2275                                     !equal_parameter(parm_table[*i].type,
2276                                                      ((char *)pService) +
2277                                                      parm_table[*i].offset,
2278                                                      ((char *)lp_ctx->sDefault) +
2279                                                      parm_table[*i].offset))
2280                                 {
2281                                         return &parm_table[(*i)++];
2282                                 }
2283                         }
2284                 }
2285         }
2286
2287         return NULL;
2288 }
2289
2290
2291 /**
2292  * Auto-load some home services.
2293  */
2294 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2295                                     const char *str)
2296 {
2297         return;
2298 }
2299
2300
2301 /**
2302  * Unload unused services.
2303  */
2304
2305 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2306                    struct smbsrv_connection *smb,
2307                    bool (*snumused) (struct smbsrv_connection *, int))
2308 {
2309         int i;
2310         for (i = 0; i < lp_ctx->iNumServices; i++) {
2311                 if (lp_ctx->services[i] == NULL)
2312                         continue;
2313
2314                 if (!snumused || !snumused(smb, i)) {
2315                         talloc_free(lp_ctx->services[i]);
2316                         lp_ctx->services[i] = NULL;
2317                 }
2318         }
2319 }
2320
2321
2322 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2323 {
2324         struct parmlist_entry *data;
2325
2326         if (lp_ctx->refuse_free) {
2327                 /* someone is trying to free the
2328                    global_loadparm_context.
2329                    We can't allow that. */
2330                 return -1;
2331         }
2332
2333         if (lp_ctx->globals->param_opt != NULL) {
2334                 struct parmlist_entry *next;
2335                 for (data = lp_ctx->globals->param_opt; data; data=next) {
2336                         next = data->next;
2337                         if (data->priority & FLAG_CMDLINE) continue;
2338                         DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2339                         talloc_free(data);
2340                 }
2341         }
2342
2343         return 0;
2344 }
2345
2346 /**
2347  * Initialise the global parameter structure.
2348  *
2349  * Note that most callers should use loadparm_init_global() instead
2350  */
2351 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2352 {
2353         int i;
2354         char *myname;
2355         struct loadparm_context *lp_ctx;
2356         struct parmlist_entry *parm;
2357         char *logfile;
2358
2359         lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2360         if (lp_ctx == NULL)
2361                 return NULL;
2362
2363         talloc_set_destructor(lp_ctx, lpcfg_destructor);
2364         lp_ctx->bInGlobalSection = true;
2365         lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2366         lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2367
2368         lp_ctx->sDefault->iMaxPrintJobs = 1000;
2369         lp_ctx->sDefault->bAvailable = true;
2370         lp_ctx->sDefault->bBrowseable = true;
2371         lp_ctx->sDefault->bRead_only = true;
2372         lp_ctx->sDefault->bMap_archive = true;
2373         lp_ctx->sDefault->bStrictLocking = true;
2374         lp_ctx->sDefault->bOplocks = true;
2375         lp_ctx->sDefault->iCreate_mask = 0744;
2376         lp_ctx->sDefault->iCreate_force_mode = 0000;
2377         lp_ctx->sDefault->iDir_mask = 0755;
2378         lp_ctx->sDefault->iDir_force_mode = 0000;
2379
2380         DEBUG(3, ("Initialising global parameters\n"));
2381
2382         for (i = 0; parm_table[i].label; i++) {
2383                 if ((parm_table[i].type == P_STRING ||
2384                      parm_table[i].type == P_USTRING) &&
2385                     parm_table[i].offset != -1 &&
2386                     !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2387                         char **r;
2388                         if (parm_table[i].pclass == P_LOCAL) {
2389                                 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2390                         } else {
2391                                 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2392                         }
2393                         *r = talloc_strdup(lp_ctx, "");
2394                 }
2395         }
2396
2397         logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2398         lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2399         talloc_free(logfile);
2400
2401         lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2402
2403         lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2404
2405         lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2406
2407         lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
2408
2409         /* options that can be set on the command line must be initialised via
2410            the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2411 #ifdef TCP_NODELAY
2412         lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2413 #endif
2414         lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2415         myname = get_myname(lp_ctx);
2416         lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2417         talloc_free(myname);
2418         lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2419
2420         lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2421
2422         lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2423         lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
2424
2425         lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
2426         lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate web");
2427         lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2428         /* the winbind method for domain controllers is for both RODC
2429            auth forwarding and for trusted domains */
2430         lpcfg_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain winbind");
2431         lpcfg_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2432         lpcfg_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2433         lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2434         lpcfg_do_global_parameter(lp_ctx, "idmap database", "idmap.ldb");
2435         lpcfg_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2436         lpcfg_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2437         lpcfg_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2438         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2439
2440         /* This hive should be dynamically generated by Samba using
2441            data from the sam, but for the moment leave it in a tdb to
2442            keep regedt32 from popping up an annoying dialog. */
2443         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2444
2445         /* using UTF8 by default allows us to support all chars */
2446         lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2447
2448         /* Use codepage 850 as a default for the dos character set */
2449         lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2450
2451         /*
2452          * Allow the default PASSWD_CHAT to be overridden in local.h.
2453          */
2454         lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2455
2456         lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2457         lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2458         lpcfg_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2459         lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2460
2461         lpcfg_do_global_parameter(lp_ctx, "socket address", "");
2462         lpcfg_do_global_parameter_var(lp_ctx, "server string",
2463                                    "Samba %s", SAMBA_VERSION_STRING);
2464
2465         lpcfg_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2466                          DEFAULT_MAJOR_VERSION,
2467                          DEFAULT_MINOR_VERSION);
2468
2469         lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2470
2471         lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2472         lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
2473         lpcfg_do_global_parameter(lp_ctx, "password level", "0");
2474         lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2475         lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2476         lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2477         lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2478         lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2479         lpcfg_do_global_parameter(lp_ctx, "security", "USER");
2480         lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
2481         lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2482         lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2483         lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2484         lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2485         lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2486         lpcfg_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2487
2488         lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2489         lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2490         lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2491         lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2492         lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2493         lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2494         lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2495         lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2496
2497         lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2498
2499         lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2500         lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2501
2502         lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2503         lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2504
2505         lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2506         lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2507         lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2508         lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2509         lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2510         lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2511         lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2512
2513         lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
2514         lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
2515
2516         lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2517
2518         lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2519         lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2520         lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2521         lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2522         lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2523         lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2524         lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2525
2526         lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2527
2528         lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2529         lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
2530
2531         lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2532         lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2533         lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2534         lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2535         lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2536
2537         lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2538         lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2539         lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2540         lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2541         lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2542
2543         for (i = 0; parm_table[i].label; i++) {
2544                 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2545                         lp_ctx->flags[i] |= FLAG_DEFAULT;
2546                 }
2547         }
2548
2549         for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2550                 if (!(parm->priority & FLAG_CMDLINE)) {
2551                         parm->priority |= FLAG_DEFAULT;
2552                 }
2553         }
2554
2555         return lp_ctx;
2556 }
2557
2558 /**
2559  * Initialise the global parameter structure.
2560  */
2561 struct loadparm_context *loadparm_init_global(bool load_default)
2562 {
2563         if (global_loadparm_context == NULL) {
2564                 global_loadparm_context = loadparm_init(NULL);
2565         }
2566         if (global_loadparm_context == NULL) {
2567                 return NULL;
2568         }
2569         global_loadparm_context->global = true;
2570         if (load_default && !global_loadparm_context->loaded) {
2571                 lpcfg_load_default(global_loadparm_context);
2572         }
2573         global_loadparm_context->refuse_free = true;
2574         return global_loadparm_context;
2575 }
2576
2577 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2578 {
2579         return lp_ctx->szConfigFile;
2580 }
2581
2582 const char *lp_default_path(void)
2583 {
2584     if (getenv("SMB_CONF_PATH"))
2585         return getenv("SMB_CONF_PATH");
2586     else
2587         return dyn_CONFIGFILE;
2588 }
2589
2590 /**
2591  * Update the internal state of a loadparm context after settings 
2592  * have changed.
2593  */
2594 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2595 {
2596         struct debug_settings settings;
2597         lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
2598
2599         if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2600                 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2601         }
2602
2603         if (!lp_ctx->global) {
2604                 return true;
2605         }
2606
2607         panic_action = lp_ctx->globals->panic_action;
2608
2609         reload_charcnv(lp_ctx);
2610
2611         ZERO_STRUCT(settings);
2612         /* Add any more debug-related smb.conf parameters created in
2613          * future here */
2614         settings.timestamp_logs = true;
2615         debug_set_settings(&settings);
2616
2617         /* FIXME: This is a bit of a hack, but we can't use a global, since 
2618          * not everything that uses lp also uses the socket library */
2619         if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2620                 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2621         } else {
2622                 unsetenv("SOCKET_TESTNONBLOCK");
2623         }
2624
2625         /* FIXME: Check locale in environment for this: */
2626         if (strcmp(lpcfg_display_charset(lp_ctx), lpcfg_unix_charset(lp_ctx)) != 0)
2627                 d_set_iconv(smb_iconv_open(lpcfg_display_charset(lp_ctx), lpcfg_unix_charset(lp_ctx)));
2628         else
2629                 d_set_iconv((smb_iconv_t)-1);
2630
2631         return true;
2632 }
2633
2634 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2635 {
2636     const char *path;
2637
2638     path = lp_default_path();
2639
2640     if (!file_exist(path)) {
2641             /* We allow the default smb.conf file to not exist, 
2642              * basically the equivalent of an empty file. */
2643             return lpcfg_update(lp_ctx);
2644     }
2645
2646     return lpcfg_load(lp_ctx, path);
2647 }
2648
2649 /**
2650  * Load the services array from the services file.
2651  *
2652  * Return True on success, False on failure.
2653  */
2654 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2655 {
2656         char *n2;
2657         bool bRetval;
2658
2659         filename = talloc_strdup(lp_ctx, filename);
2660
2661         lp_ctx->szConfigFile = filename;
2662
2663         lp_ctx->bInGlobalSection = true;
2664         n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2665         DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2666
2667         add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2668
2669         /* We get sections first, so have to start 'behind' to make up */
2670         lp_ctx->currentService = NULL;
2671         bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2672
2673         /* finish up the last section */
2674         DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2675         if (bRetval)
2676                 if (lp_ctx->currentService != NULL)
2677                         bRetval = service_ok(lp_ctx->currentService);
2678
2679         bRetval = bRetval && lpcfg_update(lp_ctx);
2680
2681         /* we do this unconditionally, so that it happens even
2682            for a missing smb.conf */
2683         reload_charcnv(lp_ctx);
2684
2685         if (bRetval == true) {
2686                 /* set this up so that any child python tasks will
2687                    find the right smb.conf */
2688                 setenv("SMB_CONF_PATH", filename, 1);
2689
2690                 /* set the context used by the lp_*() function
2691                    varients */
2692                 global_loadparm_context = lp_ctx;
2693                 lp_ctx->loaded = true;
2694         }
2695
2696         return bRetval;
2697 }
2698
2699 /**
2700  * Return the max number of services.
2701  */
2702
2703 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2704 {
2705         return lp_ctx->iNumServices;
2706 }
2707
2708 /**
2709  * Display the contents of the services array in human-readable form.
2710  */
2711
2712 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2713              int maxtoprint)
2714 {
2715         int iService;
2716
2717         defaults_saved = !show_defaults;
2718
2719         dump_globals(lp_ctx, f, show_defaults);
2720
2721         dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2722
2723         for (iService = 0; iService < maxtoprint; iService++)
2724                 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2725 }
2726
2727 /**
2728  * Display the contents of one service in human-readable form.
2729  */
2730 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2731 {
2732         if (service != NULL) {
2733                 if (service->szService[0] == '\0')
2734                         return;
2735                 dump_a_service(service, sDefault, f, NULL);
2736         }
2737 }
2738
2739 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2740                                          int snum)
2741 {
2742         return lp_ctx->services[snum];
2743 }
2744
2745 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2746                                     const char *service_name)
2747 {
2748         int iService;
2749         char *serviceName;
2750
2751         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2752                 if (lp_ctx->services[iService] &&
2753                     lp_ctx->services[iService]->szService) {
2754                         /*
2755                          * The substitution here is used to support %U is
2756                          * service names
2757                          */
2758                         serviceName = standard_sub_basic(
2759                                         lp_ctx->services[iService],
2760                                         lp_ctx->services[iService]->szService);
2761                         if (strequal(serviceName, service_name)) {
2762                                 talloc_free(serviceName);
2763                                 return lp_ctx->services[iService];
2764                         }
2765                         talloc_free(serviceName);
2766                 }
2767         }
2768
2769         DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2770         return NULL;
2771 }
2772
2773 const char *lpcfg_servicename(const struct loadparm_service *service)
2774 {
2775         return lp_string((const char *)service->szService);
2776 }
2777
2778 /**
2779  * A useful volume label function.
2780  */
2781 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2782 {
2783         const char *ret;
2784         ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
2785                                        service->volume : sDefault->volume));
2786         if (!*ret)
2787                 return lpcfg_servicename(service);
2788         return ret;
2789 }
2790
2791 /**
2792  * If we are PDC then prefer us as DMB
2793  */
2794 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2795 {
2796         const char *ret;
2797         ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
2798                                        service->szPrintername : sDefault->szPrintername));
2799         if (ret == NULL || (ret != NULL && *ret == '\0'))
2800                 ret = lpcfg_servicename(service);
2801
2802         return ret;
2803 }
2804
2805
2806 /**
2807  * Return the max print jobs per queue.
2808  */
2809 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2810 {
2811         int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2812         if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2813                 maxjobs = PRINT_MAX_JOBID - 1;
2814
2815         return maxjobs;
2816 }
2817
2818 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2819 {
2820         if (lp_ctx == NULL) {
2821                 return get_iconv_handle();
2822         }
2823         return lp_ctx->iconv_handle;
2824 }
2825
2826 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2827 {
2828         struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2829         if (!lp_ctx->global) {
2830                 return;
2831         }
2832
2833         if (old_ic == NULL) {
2834                 old_ic = global_iconv_handle;
2835         }
2836         lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2837         global_iconv_handle = lp_ctx->iconv_handle;
2838 }
2839
2840 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
2841                          struct smbcli_options *options)
2842 {
2843         options->max_xmit = lpcfg_max_xmit(lp_ctx);
2844         options->max_mux = lpcfg_maxmux(lp_ctx);
2845         options->use_spnego = lpcfg_nt_status_support(lp_ctx) && lpcfg_use_spnego(lp_ctx);
2846         options->signing = lpcfg_client_signing(lp_ctx);
2847         options->request_timeout = SMB_REQUEST_TIMEOUT;
2848         options->ntstatus_support = lpcfg_nt_status_support(lp_ctx);
2849         options->max_protocol = lpcfg_cli_maxprotocol(lp_ctx);
2850         options->unicode = lpcfg_unicode(lp_ctx);
2851         options->use_oplocks = true;
2852         options->use_level2_oplocks = true;
2853 }
2854
2855 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
2856                                  struct smbcli_session_options *options)
2857 {
2858         options->lanman_auth = lpcfg_client_lanman_auth(lp_ctx);
2859         options->ntlmv2_auth = lpcfg_client_ntlmv2_auth(lp_ctx);
2860         options->plaintext_auth = lpcfg_client_plaintext_auth(lp_ctx);
2861 }
2862
2863 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2864 {
2865         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
2866 }
2867
2868 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2869 {
2870         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
2871 }
2872
2873 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2874 {
2875         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
2876 }
2877
2878 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2879 {
2880         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
2881 }
2882
2883 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2884 {
2885         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
2886 }
2887
2888 _PUBLIC_ struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2889 {
2890         struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
2891
2892         ret->domain_name = talloc_reference(mem_ctx, lpcfg_workgroup(lp_ctx));
2893         ret->version_major = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
2894         ret->version_minor = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
2895         ret->version_build = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
2896
2897         return ret;
2898 }
2899
2900 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2901 {
2902         struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
2903         if (settings == NULL)
2904                 return NULL;
2905         SMB_ASSERT(lp_ctx != NULL);
2906         settings->lp_ctx = talloc_reference(settings, lp_ctx);
2907         settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2908         return settings;
2909 }
2910