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