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