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