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