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