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