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