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