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