libwbclient: Make wbcGetSidAliases not use talloc
[Samba/ekacnet.git] / source4 / param / loadparm.c
blobb7dcd9bcee14ec39253f208018b59d5a6685edfd
1 /*
2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
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
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.
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.
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/>.
30 * Load parameters.
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.
36 * To add a parameter:
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
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!
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"
72 #define standard_sub_basic talloc_strdup
74 static bool do_parameter(const char *, const char *, void *);
75 static bool defaults_saved = false;
77 /**
78 * This structure describes global (ie., server-wide) parameters.
80 struct loadparm_global
82 enum server_role server_role;
83 enum sid_generator sid_generator;
85 const char **smb_ports;
86 char *ncalrpc_dir;
87 char *dos_charset;
88 char *unix_charset;
89 char *display_charset;
90 char *szLockDir;
91 char *szModulesDir;
92 char *szPidDir;
93 char *szSetupDir;
94 char *szServerString;
95 char *szAutoServices;
96 char *szPasswdChat;
97 char *szShareBackend;
98 char *szSAM_URL;
99 char *szIDMAP_URL;
100 char *szSECRETS_URL;
101 char *szSPOOLSS_URL;
102 char *szWINS_CONFIG_URL;
103 char *szWINS_URL;
104 char *szPrivateDir;
105 const char **szPasswordServers;
106 char *szSocketOptions;
107 char *szRealm;
108 char *szRealm_upper;
109 char *szRealm_lower;
110 const char **szWINSservers;
111 const char **szInterfaces;
112 char *szSocketAddress;
113 char *szAnnounceVersion; /* This is initialised in init_globals */
114 char *szWorkgroup;
115 char *szNetbiosName;
116 const char **szNetbiosAliases;
117 char *szNetbiosScope;
118 char *szDomainOtherSIDs;
119 const char **szNameResolveOrder;
120 const char **dcerpc_ep_servers;
121 const char **server_services;
122 char *ntptr_providor;
123 char *szWinbindSeparator;
124 char *szWinbinddPrivilegedSocketDirectory;
125 char *szWinbinddSocketDirectory;
126 char *szTemplateShell;
127 char *szTemplateHomedir;
128 int bWinbindSealedPipes;
129 int bIdmapTrustedOnly;
130 char *swat_directory;
131 int tls_enabled;
132 char *tls_keyfile;
133 char *tls_certfile;
134 char *tls_cafile;
135 char *tls_crlfile;
136 char *tls_dhpfile;
137 char *logfile;
138 char *panic_action;
139 int max_mux;
140 int debuglevel;
141 int max_xmit;
142 int pwordlevel;
143 int srv_maxprotocol;
144 int srv_minprotocol;
145 int cli_maxprotocol;
146 int cli_minprotocol;
147 int security;
148 int paranoid_server_security;
149 int max_wins_ttl;
150 int min_wins_ttl;
151 int announce_as; /* This is initialised in init_globals */
152 int nbt_port;
153 int dgram_port;
154 int cldap_port;
155 int krb5_port;
156 int kpasswd_port;
157 int web_port;
158 char *socket_options;
159 int bWINSsupport;
160 int bWINSdnsProxy;
161 char *szWINSHook;
162 int bLocalMaster;
163 int bPreferredMaster;
164 int bEncryptPasswords;
165 int bNullPasswords;
166 int bObeyPamRestrictions;
167 int bLargeReadwrite;
168 int bReadRaw;
169 int bWriteRaw;
170 int bTimeServer;
171 int bBindInterfacesOnly;
172 int bNTSmbSupport;
173 int bNTStatusSupport;
174 int bLanmanAuth;
175 int bNTLMAuth;
176 int bUseSpnego;
177 int server_signing;
178 int client_signing;
179 int bClientPlaintextAuth;
180 int bClientLanManAuth;
181 int bClientNTLMv2Auth;
182 int client_use_spnego_principal;
183 int bHostMSDfs;
184 int bUnicode;
185 int bUnixExtensions;
186 int bDisableNetbios;
187 int bRpcBigEndian;
188 char *szNTPSignDSocketDirectory;
189 const char **szRNDCCommand;
190 const char **szDNSUpdateCommand;
191 char *szNSUpdateCommand;
192 struct parmlist_entry *param_opt;
197 * This structure describes a single service.
199 struct loadparm_service
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;
234 char dummy[3]; /* for alignment */
238 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
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);
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}
264 static const struct enum_list enum_security[] = {
265 {SEC_SHARE, "SHARE"},
266 {SEC_USER, "USER"},
267 {-1, NULL}
270 static const struct enum_list enum_announce_as[] = {
271 {ANNOUNCE_AS_NT_SERVER, "NT"},
272 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
273 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
274 {ANNOUNCE_AS_WIN95, "win95"},
275 {ANNOUNCE_AS_WFW, "WfW"},
276 {-1, NULL}
279 static const struct enum_list enum_bool_auto[] = {
280 {false, "No"},
281 {false, "False"},
282 {false, "0"},
283 {true, "Yes"},
284 {true, "True"},
285 {true, "1"},
286 {Auto, "Auto"},
287 {-1, NULL}
290 /* Client-side offline caching policy types */
291 enum csc_policy {
292 CSC_POLICY_MANUAL=0,
293 CSC_POLICY_DOCUMENTS=1,
294 CSC_POLICY_PROGRAMS=2,
295 CSC_POLICY_DISABLE=3
298 static const struct enum_list enum_csc_policy[] = {
299 {CSC_POLICY_MANUAL, "manual"},
300 {CSC_POLICY_DOCUMENTS, "documents"},
301 {CSC_POLICY_PROGRAMS, "programs"},
302 {CSC_POLICY_DISABLE, "disable"},
303 {-1, NULL}
306 /* SMB signing types. */
307 static const struct enum_list enum_smb_signing_vals[] = {
308 {SMB_SIGNING_OFF, "No"},
309 {SMB_SIGNING_OFF, "False"},
310 {SMB_SIGNING_OFF, "0"},
311 {SMB_SIGNING_OFF, "Off"},
312 {SMB_SIGNING_OFF, "disabled"},
313 {SMB_SIGNING_SUPPORTED, "Yes"},
314 {SMB_SIGNING_SUPPORTED, "True"},
315 {SMB_SIGNING_SUPPORTED, "1"},
316 {SMB_SIGNING_SUPPORTED, "On"},
317 {SMB_SIGNING_SUPPORTED, "enabled"},
318 {SMB_SIGNING_REQUIRED, "required"},
319 {SMB_SIGNING_REQUIRED, "mandatory"},
320 {SMB_SIGNING_REQUIRED, "force"},
321 {SMB_SIGNING_REQUIRED, "forced"},
322 {SMB_SIGNING_REQUIRED, "enforced"},
323 {SMB_SIGNING_AUTO, "auto"},
324 {-1, NULL}
327 static const struct enum_list enum_server_role[] = {
328 {ROLE_STANDALONE, "standalone"},
329 {ROLE_DOMAIN_MEMBER, "member server"},
330 {ROLE_DOMAIN_MEMBER, "member"},
331 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
332 {ROLE_DOMAIN_CONTROLLER, "dc"},
333 {-1, NULL}
336 static const struct enum_list enum_sid_generator[] = {
337 {SID_GENERATOR_INTERNAL, "internal"},
338 {SID_GENERATOR_BACKEND, "backend"},
339 {-1, NULL}
342 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
343 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
345 static struct parm_struct parm_table[] = {
346 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
347 {"sid generator", P_ENUM, P_GLOBAL, GLOBAL_VAR(sid_generator), NULL, enum_sid_generator},
349 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
350 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
351 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
352 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
353 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
354 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
355 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
356 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
357 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), handle_realm, NULL},
358 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
359 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
360 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
361 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
362 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
363 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
364 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
365 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
366 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
367 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
369 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
370 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
371 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
372 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
373 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
374 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
375 {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
376 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
377 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
378 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
379 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
380 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
381 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
382 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
383 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
384 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
385 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
386 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
387 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
388 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
390 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
392 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
393 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
394 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
395 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
397 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
398 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
400 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
401 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
402 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
404 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
405 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
406 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
407 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
408 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
409 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
410 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
411 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
412 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
413 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
414 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
415 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
416 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
417 {"swat directory", P_STRING, P_GLOBAL, GLOBAL_VAR(swat_directory), 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},
428 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
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},
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},
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},
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},
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},
456 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
457 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
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},
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},
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},
474 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
476 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
477 {"oplocks", P_BOOL, P_LOCAL, LOCAL_VAR(bOplocks), NULL, NULL},
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 {"setup directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szSetupDir), NULL, NULL},
488 {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
489 {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
490 {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
492 {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
493 {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
494 {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
496 {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
498 {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
499 {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
500 {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
501 {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
502 {"winbindd privileged socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory), NULL, NULL },
503 {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
504 {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
505 {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
506 {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
508 {"ntp signd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szNTPSignDSocketDirectory), NULL, NULL },
509 {"rndc command", P_LIST, P_GLOBAL, GLOBAL_VAR(szRNDCCommand), NULL, NULL },
510 {"dns update command", P_LIST, P_GLOBAL, GLOBAL_VAR(szDNSUpdateCommand), NULL, NULL },
511 {"nsupdate command", P_STRING, P_GLOBAL, GLOBAL_VAR(szNSUpdateCommand), NULL, NULL },
513 {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
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 int iNumServices;
524 struct loadparm_service *currentService;
525 bool bInGlobalSection;
526 struct file_lists {
527 struct file_lists *next;
528 char *name;
529 char *subfname;
530 time_t modtime;
531 } *file_lists;
532 unsigned int flags[NUMPARAMETERS];
533 struct smb_iconv_convenience *iconv_convenience;
537 struct loadparm_service *lp_default_service(struct loadparm_context *lp_ctx)
539 return lp_ctx->sDefault;
543 return the parameter table
545 struct parm_struct *lp_parm_table(void)
547 return parm_table;
551 * Convenience routine to grab string parameters into temporary memory
552 * and run standard_sub_basic on them.
554 * The buffers can be written to by
555 * callers without affecting the source string.
558 static const char *lp_string(const char *s)
560 #if 0 /* until REWRITE done to make thread-safe */
561 size_t len = s ? strlen(s) : 0;
562 char *ret;
563 #endif
565 /* The follow debug is useful for tracking down memory problems
566 especially if you have an inner loop that is calling a lp_*()
567 function that returns a string. Perhaps this debug should be
568 present all the time? */
570 #if 0
571 DEBUG(10, ("lp_string(%s)\n", s));
572 #endif
574 #if 0 /* until REWRITE done to make thread-safe */
575 if (!lp_talloc)
576 lp_talloc = talloc_init("lp_talloc");
578 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
580 if (!ret)
581 return NULL;
583 if (!s)
584 *ret = 0;
585 else
586 strlcpy(ret, s, len);
588 if (trim_string(ret, "\"", "\"")) {
589 if (strchr(ret,'"') != NULL)
590 strlcpy(ret, s, len);
593 standard_sub_basic(ret,len+100);
594 return (ret);
595 #endif
596 return s;
600 In this section all the functions that are used to access the
601 parameters from the rest of the program are defined
604 #define FN_GLOBAL_STRING(fn_name,var_name) \
605 const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : "";}
606 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
607 const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name ? lp_ctx->globals->var_name : "";}
608 #define FN_GLOBAL_LIST(fn_name,var_name) \
609 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
610 #define FN_GLOBAL_BOOL(fn_name,var_name) \
611 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
612 #if 0 /* unused */
613 #define FN_GLOBAL_CHAR(fn_name,ptr) \
614 char fn_name(void) {return(*(char *)(ptr));}
615 #endif
616 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
617 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
619 #define FN_LOCAL_STRING(fn_name,val) \
620 const char *fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)));}
621 #define FN_LOCAL_LIST(fn_name,val) \
622 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
623 #define FN_LOCAL_BOOL(fn_name,val) \
624 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
625 #define FN_LOCAL_INTEGER(fn_name,val) \
626 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
628 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, server_role)
629 _PUBLIC_ FN_GLOBAL_INTEGER(lp_sid_generator, sid_generator)
630 _PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, smb_ports)
631 _PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, nbt_port)
632 _PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, dgram_port)
633 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, cldap_port)
634 _PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, krb5_port)
635 _PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, kpasswd_port)
636 _PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, web_port)
637 _PUBLIC_ FN_GLOBAL_STRING(lp_swat_directory, swat_directory)
638 _PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, tls_enabled)
639 _PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
640 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
641 _PUBLIC_ FN_GLOBAL_STRING(lp_idmap_url, szIDMAP_URL)
642 _PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
643 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
644 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
645 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
646 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
647 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
648 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
649 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
650 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
651 _PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
652 _PUBLIC_ FN_GLOBAL_BOOL(lp_idmap_trusted_only, bIdmapTrustedOnly)
653 _PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
654 _PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
655 _PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
656 _PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
657 _PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
658 _PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
659 _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
660 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
661 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
662 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
663 _PUBLIC_ FN_GLOBAL_LIST(lp_rndc_command, szRNDCCommand)
664 _PUBLIC_ FN_GLOBAL_LIST(lp_dns_update_command, szDNSUpdateCommand)
665 _PUBLIC_ FN_GLOBAL_STRING(lp_nsupdate_command, szNSUpdateCommand)
666 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
667 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
668 _PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
669 _PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
670 _PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
671 _PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
672 _PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
673 _PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm_upper)
674 _PUBLIC_ FN_GLOBAL_STRING(lp_dnsdomain, szRealm_lower)
675 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
676 _PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
677 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
678 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
679 _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
680 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
681 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
682 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
683 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
684 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
685 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
686 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
687 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
688 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
689 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
690 _PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
691 _PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
692 _PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
693 _PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
694 _PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
695 _PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
696 _PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
697 _PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
698 _PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
699 _PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
700 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
701 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
702 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
703 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
704 _PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
705 _PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
706 _PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
707 _PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
708 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
709 _PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
710 _PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
711 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
712 _PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
713 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
714 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
715 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
716 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
717 _PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
718 _PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
719 _PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
721 const char *lp_servicename(const struct loadparm_service *service)
723 return lp_string((const char *)service->szService);
726 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
727 static FN_LOCAL_STRING(_lp_printername, szPrintername)
728 _PUBLIC_ FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
729 _PUBLIC_ FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
730 _PUBLIC_ FN_LOCAL_STRING(lp_comment, comment)
731 _PUBLIC_ FN_LOCAL_STRING(lp_fstype, fstype)
732 static FN_LOCAL_STRING(lp_volume, volume)
733 _PUBLIC_ FN_LOCAL_LIST(lp_ntvfs_handler, ntvfs_handler)
734 _PUBLIC_ FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
735 _PUBLIC_ FN_LOCAL_BOOL(lp_browseable, bBrowseable)
736 _PUBLIC_ FN_LOCAL_BOOL(lp_readonly, bRead_only)
737 _PUBLIC_ FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
738 _PUBLIC_ FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
739 _PUBLIC_ FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
740 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
741 _PUBLIC_ FN_LOCAL_BOOL(lp_oplocks, bOplocks)
742 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
743 _PUBLIC_ FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
744 _PUBLIC_ FN_LOCAL_BOOL(lp_map_system, bMap_system)
745 _PUBLIC_ FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
746 _PUBLIC_ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
747 _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
748 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
749 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
750 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
751 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
752 _PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
754 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory, szNTPSignDSocketDirectory)
756 /* local prototypes */
757 static int map_parameter(const char *pszParmName);
758 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
759 const char *pszServiceName);
760 static void copy_service(struct loadparm_service *pserviceDest,
761 struct loadparm_service *pserviceSource,
762 int *pcopymapDest);
763 static bool service_ok(struct loadparm_service *service);
764 static bool do_section(const char *pszSectionName, void *);
765 static void init_copymap(struct loadparm_service *pservice);
767 /* This is a helper function for parametrical options support. */
768 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
769 /* Actual parametrical functions are quite simple */
770 const char *lp_get_parametric(struct loadparm_context *lp_ctx,
771 struct loadparm_service *service,
772 const char *type, const char *option)
774 char *vfskey;
775 struct parmlist_entry *data;
777 if (lp_ctx == NULL)
778 return NULL;
780 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
782 asprintf(&vfskey, "%s:%s", type, option);
783 strlower(vfskey);
785 while (data) {
786 if (strcmp(data->key, vfskey) == 0) {
787 free(vfskey);
788 return data->value;
790 data = data->next;
793 if (service != NULL) {
794 /* Try to fetch the same option but from globals */
795 /* but only if we are not already working with globals */
796 for (data = lp_ctx->globals->param_opt; data;
797 data = data->next) {
798 if (strcmp(data->key, vfskey) == 0) {
799 free(vfskey);
800 return data->value;
805 free(vfskey);
807 return NULL;
812 * convenience routine to return int parameters.
814 static int lp_int(const char *s)
817 if (!s) {
818 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
819 return -1;
822 return strtol(s, NULL, 0);
826 * convenience routine to return unsigned long parameters.
828 static int lp_ulong(const char *s)
831 if (!s) {
832 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
833 return -1;
836 return strtoul(s, NULL, 0);
840 * convenience routine to return unsigned long parameters.
842 static double lp_double(const char *s)
845 if (!s) {
846 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
847 return -1;
850 return strtod(s, NULL);
854 * convenience routine to return boolean parameters.
856 static bool lp_bool(const char *s)
858 bool ret = false;
860 if (!s) {
861 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
862 return false;
865 if (!set_boolean(s, &ret)) {
866 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
867 return false;
870 return ret;
875 * Return parametric option from a given service. Type is a part of option before ':'
876 * Parametric option has following syntax: 'Type: option = value'
877 * Returned value is allocated in 'lp_talloc' context
880 const char *lp_parm_string(struct loadparm_context *lp_ctx,
881 struct loadparm_service *service, const char *type,
882 const char *option)
884 const char *value = lp_get_parametric(lp_ctx, service, type, option);
886 if (value)
887 return lp_string(value);
889 return NULL;
893 * Return parametric option from a given service. Type is a part of option before ':'
894 * Parametric option has following syntax: 'Type: option = value'
895 * Returned value is allocated in 'lp_talloc' context
898 const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,
899 struct loadparm_context *lp_ctx,
900 struct loadparm_service *service,
901 const char *type,
902 const char *option, const char *separator)
904 const char *value = lp_get_parametric(lp_ctx, service, type, option);
906 if (value != NULL)
907 return (const char **)str_list_make(mem_ctx, value, separator);
909 return NULL;
913 * Return parametric option from a given service. Type is a part of option before ':'
914 * Parametric option has following syntax: 'Type: option = value'
917 int lp_parm_int(struct loadparm_context *lp_ctx,
918 struct loadparm_service *service, const char *type,
919 const char *option, int default_v)
921 const char *value = lp_get_parametric(lp_ctx, service, type, option);
923 if (value)
924 return lp_int(value);
926 return default_v;
930 * Return parametric option from a given service. Type is a part of
931 * option before ':'.
932 * Parametric option has following syntax: 'Type: option = value'.
935 int lp_parm_bytes(struct loadparm_context *lp_ctx,
936 struct loadparm_service *service, const char *type,
937 const char *option, int default_v)
939 uint64_t bval;
941 const char *value = lp_get_parametric(lp_ctx, service, type, option);
943 if (value && conv_str_size(value, &bval)) {
944 if (bval <= INT_MAX) {
945 return (int)bval;
949 return default_v;
953 * Return parametric option from a given service.
954 * Type is a part of option before ':'
955 * Parametric option has following syntax: 'Type: option = value'
957 unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,
958 struct loadparm_service *service, const char *type,
959 const char *option, unsigned long default_v)
961 const char *value = lp_get_parametric(lp_ctx, service, type, option);
963 if (value)
964 return lp_ulong(value);
966 return default_v;
970 double lp_parm_double(struct loadparm_context *lp_ctx,
971 struct loadparm_service *service, const char *type,
972 const char *option, double default_v)
974 const char *value = lp_get_parametric(lp_ctx, service, type, option);
976 if (value != NULL)
977 return lp_double(value);
979 return default_v;
983 * Return parametric option from a given service. Type is a part of option before ':'
984 * Parametric option has following syntax: 'Type: option = value'
987 bool lp_parm_bool(struct loadparm_context *lp_ctx,
988 struct loadparm_service *service, const char *type,
989 const char *option, bool default_v)
991 const char *value = lp_get_parametric(lp_ctx, service, type, option);
993 if (value != NULL)
994 return lp_bool(value);
996 return default_v;
1001 * Initialise a service to the defaults.
1004 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1006 struct loadparm_service *pservice =
1007 talloc_zero(mem_ctx, struct loadparm_service);
1008 copy_service(pservice, sDefault, NULL);
1009 return pservice;
1013 * Set a string value, deallocating any existing space, and allocing the space
1014 * for the string
1016 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1018 talloc_free(*dest);
1020 if (src == NULL)
1021 src = "";
1023 *dest = talloc_strdup(mem_ctx, src);
1024 if ((*dest) == NULL) {
1025 DEBUG(0,("Out of memory in string_init\n"));
1026 return false;
1029 return true;
1035 * Add a new service to the services array initialising it with the given
1036 * service.
1039 struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
1040 const struct loadparm_service *pservice,
1041 const char *name)
1043 int i;
1044 struct loadparm_service tservice;
1045 int num_to_alloc = lp_ctx->iNumServices + 1;
1046 struct parmlist_entry *data, *pdata;
1048 tservice = *pservice;
1050 /* it might already exist */
1051 if (name) {
1052 struct loadparm_service *service = getservicebyname(lp_ctx,
1053 name);
1054 if (service != NULL) {
1055 /* Clean all parametric options for service */
1056 /* They will be added during parsing again */
1057 data = service->param_opt;
1058 while (data) {
1059 pdata = data->next;
1060 talloc_free(data);
1061 data = pdata;
1063 service->param_opt = NULL;
1064 return service;
1068 /* find an invalid one */
1069 for (i = 0; i < lp_ctx->iNumServices; i++)
1070 if (lp_ctx->services[i] == NULL)
1071 break;
1073 /* if not, then create one */
1074 if (i == lp_ctx->iNumServices) {
1075 struct loadparm_service **tsp;
1077 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1079 if (!tsp) {
1080 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1081 return NULL;
1082 } else {
1083 lp_ctx->services = tsp;
1084 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1087 lp_ctx->iNumServices++;
1090 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1091 if (lp_ctx->services[i] == NULL) {
1092 DEBUG(0,("lp_add_service: out of memory!\n"));
1093 return NULL;
1095 copy_service(lp_ctx->services[i], &tservice, NULL);
1096 if (name != NULL)
1097 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1098 return lp_ctx->services[i];
1102 * Add a new home service, with the specified home directory, defaults coming
1103 * from service ifrom.
1106 bool lp_add_home(struct loadparm_context *lp_ctx,
1107 const char *pszHomename,
1108 struct loadparm_service *default_service,
1109 const char *user, const char *pszHomedir)
1111 struct loadparm_service *service;
1113 service = lp_add_service(lp_ctx, default_service, pszHomename);
1115 if (service == NULL)
1116 return false;
1118 if (!(*(default_service->szPath))
1119 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1120 service->szPath = talloc_strdup(service, pszHomedir);
1121 } else {
1122 service->szPath = string_sub_talloc(service, lp_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1125 if (!(*(service->comment))) {
1126 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1128 service->bAvailable = default_service->bAvailable;
1129 service->bBrowseable = default_service->bBrowseable;
1131 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1132 pszHomename, user, service->szPath));
1134 return true;
1138 * Add the IPC service.
1141 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,
1142 const char *fstype)
1144 struct loadparm_service *service = lp_add_service(lp_ctx, lp_ctx->sDefault, name);
1146 if (service == NULL)
1147 return false;
1149 string_set(service, &service->szPath, tmpdir());
1151 service->comment = talloc_asprintf(service, "%s Service (%s)",
1152 fstype, lp_ctx->globals->szServerString);
1153 string_set(service, &service->fstype, fstype);
1154 service->iMaxConnections = -1;
1155 service->bAvailable = true;
1156 service->bRead_only = true;
1157 service->bPrint_ok = false;
1158 service->bBrowseable = false;
1160 if (strcasecmp(fstype, "IPC") == 0) {
1161 lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
1162 "default");
1165 DEBUG(3, ("adding hidden service %s\n", name));
1167 return true;
1171 * Add a new printer service, with defaults coming from service iFrom.
1174 bool lp_add_printer(struct loadparm_context *lp_ctx,
1175 const char *pszPrintername,
1176 struct loadparm_service *default_service)
1178 const char *comment = "From Printcap";
1179 struct loadparm_service *service;
1180 service = lp_add_service(lp_ctx, default_service, pszPrintername);
1182 if (service == NULL)
1183 return false;
1185 /* note that we do NOT default the availability flag to True - */
1186 /* we take it from the default service passed. This allows all */
1187 /* dynamic printers to be disabled by disabling the [printers] */
1188 /* entry (if/when the 'available' keyword is implemented!). */
1190 /* the printer name is set to the service name. */
1191 string_set(service, &service->szPrintername, pszPrintername);
1192 string_set(service, &service->comment, comment);
1193 service->bBrowseable = default_service->bBrowseable;
1194 /* Printers cannot be read_only. */
1195 service->bRead_only = false;
1196 /* Printer services must be printable. */
1197 service->bPrint_ok = true;
1199 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1201 return true;
1205 * Map a parameter's string representation to something we can use.
1206 * Returns False if the parameter string is not recognised, else TRUE.
1209 static int map_parameter(const char *pszParmName)
1211 int iIndex;
1213 if (*pszParmName == '-')
1214 return -1;
1216 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1217 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1218 return iIndex;
1220 /* Warn only if it isn't parametric option */
1221 if (strchr(pszParmName, ':') == NULL)
1222 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1223 /* We do return 'fail' for parametric options as well because they are
1224 stored in different storage
1226 return -1;
1231 return the parameter structure for a parameter
1233 struct parm_struct *lp_parm_struct(const char *name)
1235 int parmnum = map_parameter(name);
1236 if (parmnum == -1) return NULL;
1237 return &parm_table[parmnum];
1241 return the parameter pointer for a parameter
1243 void *lp_parm_ptr(struct loadparm_context *lp_ctx,
1244 struct loadparm_service *service, struct parm_struct *parm)
1246 if (service == NULL) {
1247 if (parm->pclass == P_LOCAL)
1248 return ((char *)lp_ctx->sDefault)+parm->offset;
1249 else if (parm->pclass == P_GLOBAL)
1250 return ((char *)lp_ctx->globals)+parm->offset;
1251 else return NULL;
1252 } else {
1253 return ((char *)service) + parm->offset;
1258 * Find a service by name. Otherwise works like get_service.
1261 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1262 const char *pszServiceName)
1264 int iService;
1266 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1267 if (lp_ctx->services[iService] != NULL &&
1268 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1269 return lp_ctx->services[iService];
1272 return NULL;
1276 * Copy a service structure to another.
1277 * If pcopymapDest is NULL then copy all fields
1280 static void copy_service(struct loadparm_service *pserviceDest,
1281 struct loadparm_service *pserviceSource,
1282 int *pcopymapDest)
1284 int i;
1285 bool bcopyall = (pcopymapDest == NULL);
1286 struct parmlist_entry *data, *pdata, *paramo;
1287 bool not_added;
1289 for (i = 0; parm_table[i].label; i++)
1290 if (parm_table[i].offset != -1 && parm_table[i].pclass == P_LOCAL &&
1291 (bcopyall || pcopymapDest[i])) {
1292 void *src_ptr =
1293 ((char *)pserviceSource) + parm_table[i].offset;
1294 void *dest_ptr =
1295 ((char *)pserviceDest) + parm_table[i].offset;
1297 switch (parm_table[i].type) {
1298 case P_BOOL:
1299 *(int *)dest_ptr = *(int *)src_ptr;
1300 break;
1302 case P_INTEGER:
1303 case P_OCTAL:
1304 case P_ENUM:
1305 *(int *)dest_ptr = *(int *)src_ptr;
1306 break;
1308 case P_STRING:
1309 string_set(pserviceDest,
1310 (char **)dest_ptr,
1311 *(char **)src_ptr);
1312 break;
1314 case P_USTRING:
1315 string_set(pserviceDest,
1316 (char **)dest_ptr,
1317 *(char **)src_ptr);
1318 strupper(*(char **)dest_ptr);
1319 break;
1320 case P_LIST:
1321 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
1322 *(const char ***)src_ptr);
1323 break;
1324 default:
1325 break;
1329 if (bcopyall) {
1330 init_copymap(pserviceDest);
1331 if (pserviceSource->copymap)
1332 memcpy((void *)pserviceDest->copymap,
1333 (void *)pserviceSource->copymap,
1334 sizeof(int) * NUMPARAMETERS);
1337 data = pserviceSource->param_opt;
1338 while (data) {
1339 not_added = true;
1340 pdata = pserviceDest->param_opt;
1341 /* Traverse destination */
1342 while (pdata) {
1343 /* If we already have same option, override it */
1344 if (strcmp(pdata->key, data->key) == 0) {
1345 talloc_free(pdata->value);
1346 pdata->value = talloc_reference(pdata,
1347 data->value);
1348 not_added = false;
1349 break;
1351 pdata = pdata->next;
1353 if (not_added) {
1354 paramo = talloc(pserviceDest, struct parmlist_entry);
1355 if (paramo == NULL)
1356 smb_panic("OOM");
1357 paramo->key = talloc_reference(paramo, data->key);
1358 paramo->value = talloc_reference(paramo, data->value);
1359 DLIST_ADD(pserviceDest->param_opt, paramo);
1361 data = data->next;
1366 * Check a service for consistency. Return False if the service is in any way
1367 * incomplete or faulty, else True.
1369 static bool service_ok(struct loadparm_service *service)
1371 bool bRetval;
1373 bRetval = true;
1374 if (service->szService[0] == '\0') {
1375 DEBUG(0, ("The following message indicates an internal error:\n"));
1376 DEBUG(0, ("No service name in service entry.\n"));
1377 bRetval = false;
1380 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1381 /* I can't see why you'd want a non-printable printer service... */
1382 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1383 if (!service->bPrint_ok) {
1384 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1385 service->szService));
1386 service->bPrint_ok = true;
1388 /* [printers] service must also be non-browsable. */
1389 if (service->bBrowseable)
1390 service->bBrowseable = false;
1393 /* If a service is flagged unavailable, log the fact at level 0. */
1394 if (!service->bAvailable)
1395 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1396 service->szService));
1398 return bRetval;
1402 /*******************************************************************
1403 Keep a linked list of all config files so we know when one has changed
1404 it's date and needs to be reloaded.
1405 ********************************************************************/
1407 static void add_to_file_list(struct loadparm_context *lp_ctx,
1408 const char *fname, const char *subfname)
1410 struct file_lists *f = lp_ctx->file_lists;
1412 while (f) {
1413 if (f->name && !strcmp(f->name, fname))
1414 break;
1415 f = f->next;
1418 if (!f) {
1419 f = talloc(lp_ctx, struct file_lists);
1420 if (!f)
1421 return;
1422 f->next = lp_ctx->file_lists;
1423 f->name = talloc_strdup(f, fname);
1424 if (!f->name) {
1425 talloc_free(f);
1426 return;
1428 f->subfname = talloc_strdup(f, subfname);
1429 if (!f->subfname) {
1430 talloc_free(f);
1431 return;
1433 lp_ctx->file_lists = f;
1434 f->modtime = file_modtime(subfname);
1435 } else {
1436 time_t t = file_modtime(subfname);
1437 if (t)
1438 f->modtime = t;
1442 /*******************************************************************
1443 Check if a config file has changed date.
1444 ********************************************************************/
1445 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1447 struct file_lists *f;
1448 DEBUG(6, ("lp_file_list_changed()\n"));
1450 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1451 char *n2;
1452 time_t mod_time;
1454 n2 = standard_sub_basic(lp_ctx, f->name);
1456 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1457 f->name, n2, ctime(&f->modtime)));
1459 mod_time = file_modtime(n2);
1461 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1462 DEBUGADD(6, ("file %s modified: %s\n", n2,
1463 ctime(&mod_time)));
1464 f->modtime = mod_time;
1465 talloc_free(f->subfname);
1466 f->subfname = talloc_strdup(f, n2);
1467 return true;
1470 return false;
1473 /***************************************************************************
1474 Handle the "realm" parameter
1475 ***************************************************************************/
1477 static bool handle_realm(struct loadparm_context *lp_ctx,
1478 const char *pszParmValue, char **ptr)
1480 string_set(lp_ctx, ptr, pszParmValue);
1482 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
1483 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
1485 return true;
1488 /***************************************************************************
1489 Handle the include operation.
1490 ***************************************************************************/
1492 static bool handle_include(struct loadparm_context *lp_ctx,
1493 const char *pszParmValue, char **ptr)
1495 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1497 add_to_file_list(lp_ctx, pszParmValue, fname);
1499 string_set(lp_ctx, ptr, fname);
1501 if (file_exist(fname))
1502 return pm_process(fname, do_section, do_parameter, lp_ctx);
1504 DEBUG(2, ("Can't find include file %s\n", fname));
1506 return false;
1509 /***************************************************************************
1510 Handle the interpretation of the copy parameter.
1511 ***************************************************************************/
1513 static bool handle_copy(struct loadparm_context *lp_ctx,
1514 const char *pszParmValue, char **ptr)
1516 bool bRetval;
1517 struct loadparm_service *serviceTemp;
1519 string_set(lp_ctx, ptr, pszParmValue);
1521 bRetval = false;
1523 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1525 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1526 if (serviceTemp == lp_ctx->currentService) {
1527 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1528 } else {
1529 copy_service(lp_ctx->currentService,
1530 serviceTemp,
1531 lp_ctx->currentService->copymap);
1532 bRetval = true;
1534 } else {
1535 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1536 pszParmValue));
1537 bRetval = false;
1540 return bRetval;
1543 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1544 const char *pszParmValue, char **ptr)
1546 DEBUGLEVEL = atoi(pszParmValue);
1548 return true;
1551 static bool handle_logfile(struct loadparm_context *lp_ctx,
1552 const char *pszParmValue, char **ptr)
1554 if (logfile != NULL) {
1555 free(discard_const_p(char, logfile));
1557 logfile = strdup(pszParmValue);
1558 return true;
1561 /***************************************************************************
1562 Initialise a copymap.
1563 ***************************************************************************/
1565 static void init_copymap(struct loadparm_service *pservice)
1567 int i;
1568 talloc_free(pservice->copymap);
1569 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1570 if (pservice->copymap == NULL) {
1571 DEBUG(0,
1572 ("Couldn't allocate copymap!! (size %d)\n",
1573 (int)NUMPARAMETERS));
1574 return;
1576 for (i = 0; i < NUMPARAMETERS; i++)
1577 pservice->copymap[i] = true;
1581 * Process a parametric option
1583 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1584 struct loadparm_service *service,
1585 const char *pszParmName,
1586 const char *pszParmValue, int flags)
1588 struct parmlist_entry *paramo, *data;
1589 char *name;
1590 TALLOC_CTX *mem_ctx;
1592 while (isspace((unsigned char)*pszParmName)) {
1593 pszParmName++;
1596 name = strdup(pszParmName);
1597 if (!name) return false;
1599 strlower(name);
1601 if (service == NULL) {
1602 data = lp_ctx->globals->param_opt;
1603 mem_ctx = lp_ctx->globals;
1604 } else {
1605 data = service->param_opt;
1606 mem_ctx = service;
1609 /* Traverse destination */
1610 for (paramo=data; paramo; paramo=paramo->next) {
1611 /* If we already have the option set, override it unless
1612 it was a command line option and the new one isn't */
1613 if (strcmp(paramo->key, name) == 0) {
1614 if ((paramo->priority & FLAG_CMDLINE) &&
1615 !(flags & FLAG_CMDLINE)) {
1616 return true;
1619 talloc_free(paramo->value);
1620 paramo->value = talloc_strdup(paramo, pszParmValue);
1621 paramo->priority = flags;
1622 free(name);
1623 return true;
1627 paramo = talloc(mem_ctx, struct parmlist_entry);
1628 if (!paramo)
1629 smb_panic("OOM");
1630 paramo->key = talloc_strdup(paramo, name);
1631 paramo->value = talloc_strdup(paramo, pszParmValue);
1632 paramo->priority = flags;
1633 if (service == NULL) {
1634 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1635 } else {
1636 DLIST_ADD(service->param_opt, paramo);
1639 free(name);
1641 return true;
1644 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1645 const char *pszParmName, const char *pszParmValue,
1646 struct loadparm_context *lp_ctx)
1648 int i;
1649 /* if it is a special case then go ahead */
1650 if (parm_table[parmnum].special) {
1651 parm_table[parmnum].special(lp_ctx, pszParmValue,
1652 (char **)parm_ptr);
1653 return true;
1656 /* now switch on the type of variable it is */
1657 switch (parm_table[parmnum].type)
1659 case P_BOOL: {
1660 bool b;
1661 if (!set_boolean(pszParmValue, &b)) {
1662 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1663 return false;
1665 *(int *)parm_ptr = b;
1667 break;
1669 case P_INTEGER:
1670 *(int *)parm_ptr = atoi(pszParmValue);
1671 break;
1673 case P_OCTAL:
1674 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1675 break;
1677 case P_BYTES:
1679 uint64_t val;
1680 if (conv_str_size(pszParmValue, &val)) {
1681 if (val <= INT_MAX) {
1682 *(int *)parm_ptr = (int)val;
1683 break;
1687 DEBUG(0,("lp_do_parameter(%s): value is not "
1688 "a valid size specifier!\n", pszParmValue));
1689 return false;
1692 case P_LIST:
1693 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1694 pszParmValue, NULL);
1695 break;
1697 case P_STRING:
1698 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1699 break;
1701 case P_USTRING:
1702 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1703 strupper(*(char **)parm_ptr);
1704 break;
1706 case P_ENUM:
1707 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1708 if (strequal
1709 (pszParmValue,
1710 parm_table[parmnum].enum_list[i].name)) {
1711 *(int *)parm_ptr =
1712 parm_table[parmnum].
1713 enum_list[i].value;
1714 break;
1717 if (!parm_table[parmnum].enum_list[i].name) {
1718 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1719 pszParmValue, pszParmName));
1720 return false;
1722 break;
1725 if (lp_ctx->flags[parmnum] & FLAG_DEFAULT) {
1726 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1727 /* we have to also unset FLAG_DEFAULT on aliases */
1728 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1729 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1731 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1732 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1735 return true;
1739 bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
1740 const char *pszParmName, const char *pszParmValue)
1742 int parmnum = map_parameter(pszParmName);
1743 void *parm_ptr;
1745 if (parmnum < 0) {
1746 if (strchr(pszParmName, ':')) {
1747 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1749 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1750 return true;
1753 /* if the flag has been set on the command line, then don't allow override,
1754 but don't report an error */
1755 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1756 return true;
1759 parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1761 return set_variable(lp_ctx, parmnum, parm_ptr,
1762 pszParmName, pszParmValue, lp_ctx);
1765 bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
1766 struct loadparm_service *service,
1767 const char *pszParmName, const char *pszParmValue)
1769 void *parm_ptr;
1770 int i;
1771 int parmnum = map_parameter(pszParmName);
1773 if (parmnum < 0) {
1774 if (strchr(pszParmName, ':')) {
1775 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1777 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1778 return true;
1781 /* if the flag has been set on the command line, then don't allow override,
1782 but don't report an error */
1783 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1784 return true;
1787 if (parm_table[parmnum].pclass == P_GLOBAL) {
1788 DEBUG(0,
1789 ("Global parameter %s found in service section!\n",
1790 pszParmName));
1791 return true;
1793 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1795 if (!service->copymap)
1796 init_copymap(service);
1798 /* this handles the aliases - set the copymap for other
1799 * entries with the same data pointer */
1800 for (i = 0; parm_table[i].label; i++)
1801 if (parm_table[i].offset == parm_table[parmnum].offset &&
1802 parm_table[i].pclass == parm_table[parmnum].pclass)
1803 service->copymap[i] = false;
1805 return set_variable(service, parmnum, parm_ptr, pszParmName,
1806 pszParmValue, lp_ctx);
1810 * Process a parameter.
1813 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1814 void *userdata)
1816 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1818 if (lp_ctx->bInGlobalSection)
1819 return lp_do_global_parameter(lp_ctx, pszParmName,
1820 pszParmValue);
1821 else
1822 return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
1823 pszParmName, pszParmValue);
1827 variable argument do parameter
1829 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1830 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
1831 const char *pszParmName, const char *fmt, ...)
1833 char *s;
1834 bool ret;
1835 va_list ap;
1837 va_start(ap, fmt);
1838 s = talloc_vasprintf(NULL, fmt, ap);
1839 va_end(ap);
1840 ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
1841 talloc_free(s);
1842 return ret;
1847 set a parameter from the commandline - this is called from command line parameter
1848 parsing code. It sets the parameter then marks the parameter as unable to be modified
1849 by smb.conf processing
1851 bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1852 const char *pszParmValue)
1854 int parmnum = map_parameter(pszParmName);
1855 int i;
1857 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1860 if (parmnum < 0 && strchr(pszParmName, ':')) {
1861 /* set a parametric option */
1862 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1863 pszParmValue, FLAG_CMDLINE);
1866 if (parmnum < 0) {
1867 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1868 return false;
1871 /* reset the CMDLINE flag in case this has been called before */
1872 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1874 if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1875 return false;
1878 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1880 /* we have to also set FLAG_CMDLINE on aliases */
1881 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1882 lp_ctx->flags[i] |= FLAG_CMDLINE;
1884 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1885 lp_ctx->flags[i] |= FLAG_CMDLINE;
1888 return true;
1892 set a option from the commandline in 'a=b' format. Use to support --option
1894 bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
1896 char *p, *s;
1897 bool ret;
1899 s = strdup(option);
1900 if (!s) {
1901 return false;
1904 p = strchr(s, '=');
1905 if (!p) {
1906 free(s);
1907 return false;
1910 *p = 0;
1912 ret = lp_set_cmdline(lp_ctx, s, p+1);
1913 free(s);
1914 return ret;
1918 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1921 * Print a parameter of the specified type.
1924 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1926 int i;
1927 switch (p->type)
1929 case P_ENUM:
1930 for (i = 0; p->enum_list[i].name; i++) {
1931 if (*(int *)ptr == p->enum_list[i].value) {
1932 fprintf(f, "%s",
1933 p->enum_list[i].name);
1934 break;
1937 break;
1939 case P_BOOL:
1940 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1941 break;
1943 case P_INTEGER:
1944 case P_BYTES:
1945 fprintf(f, "%d", *(int *)ptr);
1946 break;
1948 case P_OCTAL:
1949 fprintf(f, "0%o", *(int *)ptr);
1950 break;
1952 case P_LIST:
1953 if ((char ***)ptr && *(char ***)ptr) {
1954 char **list = *(char ***)ptr;
1956 for (; *list; list++)
1957 fprintf(f, "%s%s", *list,
1958 ((*(list+1))?", ":""));
1960 break;
1962 case P_STRING:
1963 case P_USTRING:
1964 if (*(char **)ptr) {
1965 fprintf(f, "%s", *(char **)ptr);
1967 break;
1972 * Check if two parameters are equal.
1975 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1977 switch (type) {
1978 case P_BOOL:
1979 return (*((int *)ptr1) == *((int *)ptr2));
1981 case P_INTEGER:
1982 case P_OCTAL:
1983 case P_BYTES:
1984 case P_ENUM:
1985 return (*((int *)ptr1) == *((int *)ptr2));
1987 case P_LIST:
1988 return str_list_equal((const char **)(*(char ***)ptr1),
1989 (const char **)(*(char ***)ptr2));
1991 case P_STRING:
1992 case P_USTRING:
1994 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1995 if (p1 && !*p1)
1996 p1 = NULL;
1997 if (p2 && !*p2)
1998 p2 = NULL;
1999 return (p1 == p2 || strequal(p1, p2));
2002 return false;
2006 * Process a new section (service).
2008 * At this stage all sections are services.
2009 * Later we'll have special sections that permit server parameters to be set.
2010 * Returns True on success, False on failure.
2013 static bool do_section(const char *pszSectionName, void *userdata)
2015 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2016 bool bRetval;
2017 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2018 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2019 bRetval = false;
2021 /* if we've just struck a global section, note the fact. */
2022 lp_ctx->bInGlobalSection = isglobal;
2024 /* check for multiple global sections */
2025 if (lp_ctx->bInGlobalSection) {
2026 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
2027 return true;
2030 /* if we have a current service, tidy it up before moving on */
2031 bRetval = true;
2033 if (lp_ctx->currentService != NULL)
2034 bRetval = service_ok(lp_ctx->currentService);
2036 /* if all is still well, move to the next record in the services array */
2037 if (bRetval) {
2038 /* We put this here to avoid an odd message order if messages are */
2039 /* issued by the post-processing of a previous section. */
2040 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2042 if ((lp_ctx->currentService = lp_add_service(lp_ctx, lp_ctx->sDefault,
2043 pszSectionName))
2044 == NULL) {
2045 DEBUG(0, ("Failed to add a new service\n"));
2046 return false;
2050 return bRetval;
2055 * Determine if a particular base parameter is currently set to the default value.
2058 static bool is_default(struct loadparm_service *sDefault, int i)
2060 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2061 if (!defaults_saved)
2062 return false;
2063 switch (parm_table[i].type) {
2064 case P_LIST:
2065 return str_list_equal((const char **)parm_table[i].def.lvalue,
2066 (const char **)def_ptr);
2067 case P_STRING:
2068 case P_USTRING:
2069 return strequal(parm_table[i].def.svalue,
2070 *(char **)def_ptr);
2071 case P_BOOL:
2072 return parm_table[i].def.bvalue ==
2073 *(int *)def_ptr;
2074 case P_INTEGER:
2075 case P_OCTAL:
2076 case P_BYTES:
2077 case P_ENUM:
2078 return parm_table[i].def.ivalue ==
2079 *(int *)def_ptr;
2081 return false;
2085 *Display the contents of the global structure.
2088 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2089 bool show_defaults)
2091 int i;
2092 struct parmlist_entry *data;
2094 fprintf(f, "# Global parameters\n[global]\n");
2096 for (i = 0; parm_table[i].label; i++)
2097 if (parm_table[i].pclass == P_GLOBAL &&
2098 parm_table[i].offset != -1 &&
2099 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2100 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2101 continue;
2102 fprintf(f, "\t%s = ", parm_table[i].label);
2103 print_parameter(&parm_table[i], lp_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2104 fprintf(f, "\n");
2106 if (lp_ctx->globals->param_opt != NULL) {
2107 for (data = lp_ctx->globals->param_opt; data;
2108 data = data->next) {
2109 fprintf(f, "\t%s = %s\n", data->key, data->value);
2116 * Display the contents of a single services record.
2119 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f)
2121 int i;
2122 struct parmlist_entry *data;
2124 if (pService != sDefault)
2125 fprintf(f, "\n[%s]\n", pService->szService);
2127 for (i = 0; parm_table[i].label; i++) {
2128 if (parm_table[i].pclass == P_LOCAL &&
2129 parm_table[i].offset != -1 &&
2130 (*parm_table[i].label != '-') &&
2131 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
2133 if (pService == sDefault) {
2134 if (defaults_saved && is_default(sDefault, i))
2135 continue;
2136 } else {
2137 if (equal_parameter(parm_table[i].type,
2138 ((char *)pService) +
2139 parm_table[i].offset,
2140 ((char *)sDefault) +
2141 parm_table[i].offset))
2142 continue;
2145 fprintf(f, "\t%s = ", parm_table[i].label);
2146 print_parameter(&parm_table[i],
2147 ((char *)pService) + parm_table[i].offset, f);
2148 fprintf(f, "\n");
2151 if (pService->param_opt != NULL) {
2152 for (data = pService->param_opt; data; data = data->next) {
2153 fprintf(f, "\t%s = %s\n", data->key, data->value);
2158 bool lp_dump_a_parameter(struct loadparm_context *lp_ctx,
2159 struct loadparm_service *service,
2160 const char *parm_name, FILE * f)
2162 struct parm_struct *parm;
2163 void *ptr;
2165 parm = lp_parm_struct(parm_name);
2166 if (!parm) {
2167 return false;
2170 ptr = lp_parm_ptr(lp_ctx, service,parm);
2172 print_parameter(parm, ptr, f);
2173 fprintf(f, "\n");
2174 return true;
2178 * Return info about the next parameter in a service.
2179 * snum==-1 gives the globals.
2180 * Return NULL when out of parameters.
2183 struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2184 int allparameters)
2186 if (snum == -1) {
2187 /* do the globals */
2188 for (; parm_table[*i].label; (*i)++) {
2189 if (parm_table[*i].offset == -1
2190 || (*parm_table[*i].label == '-'))
2191 continue;
2193 if ((*i) > 0
2194 && (parm_table[*i].offset ==
2195 parm_table[(*i) - 1].offset))
2196 continue;
2198 return &parm_table[(*i)++];
2200 } else {
2201 struct loadparm_service *pService = lp_ctx->services[snum];
2203 for (; parm_table[*i].label; (*i)++) {
2204 if (parm_table[*i].pclass == P_LOCAL &&
2205 parm_table[*i].offset != -1 &&
2206 (*parm_table[*i].label != '-') &&
2207 ((*i) == 0 ||
2208 (parm_table[*i].offset !=
2209 parm_table[(*i) - 1].offset)))
2211 if (allparameters ||
2212 !equal_parameter(parm_table[*i].type,
2213 ((char *)pService) +
2214 parm_table[*i].offset,
2215 ((char *)lp_ctx->sDefault) +
2216 parm_table[*i].offset))
2218 return &parm_table[(*i)++];
2224 return NULL;
2229 * Auto-load some home services.
2231 static void lp_add_auto_services(struct loadparm_context *lp_ctx,
2232 const char *str)
2234 return;
2239 * Unload unused services.
2242 void lp_killunused(struct loadparm_context *lp_ctx,
2243 struct smbsrv_connection *smb,
2244 bool (*snumused) (struct smbsrv_connection *, int))
2246 int i;
2247 for (i = 0; i < lp_ctx->iNumServices; i++) {
2248 if (lp_ctx->services[i] == NULL)
2249 continue;
2251 if (!snumused || !snumused(smb, i)) {
2252 talloc_free(lp_ctx->services[i]);
2253 lp_ctx->services[i] = NULL;
2259 static int lp_destructor(struct loadparm_context *lp_ctx)
2261 struct parmlist_entry *data;
2263 if (lp_ctx->globals->param_opt != NULL) {
2264 struct parmlist_entry *next;
2265 for (data = lp_ctx->globals->param_opt; data; data=next) {
2266 next = data->next;
2267 if (data->priority & FLAG_CMDLINE) continue;
2268 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2269 talloc_free(data);
2273 return 0;
2277 * Initialise the global parameter structure.
2279 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2281 int i;
2282 char *myname;
2283 struct loadparm_context *lp_ctx;
2285 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2286 if (lp_ctx == NULL)
2287 return NULL;
2289 talloc_set_destructor(lp_ctx, lp_destructor);
2290 lp_ctx->bInGlobalSection = true;
2291 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2292 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2294 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2295 lp_ctx->sDefault->bAvailable = true;
2296 lp_ctx->sDefault->bBrowseable = true;
2297 lp_ctx->sDefault->bRead_only = true;
2298 lp_ctx->sDefault->bMap_archive = true;
2299 lp_ctx->sDefault->bStrictLocking = true;
2300 lp_ctx->sDefault->bOplocks = true;
2301 lp_ctx->sDefault->iCreate_mask = 0744;
2302 lp_ctx->sDefault->iCreate_force_mode = 0000;
2303 lp_ctx->sDefault->iDir_mask = 0755;
2304 lp_ctx->sDefault->iDir_force_mode = 0000;
2306 DEBUG(3, ("Initialising global parameters\n"));
2308 for (i = 0; parm_table[i].label; i++) {
2309 if ((parm_table[i].type == P_STRING ||
2310 parm_table[i].type == P_USTRING) &&
2311 parm_table[i].offset != -1 &&
2312 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2313 char **r;
2314 if (parm_table[i].pclass == P_LOCAL) {
2315 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2316 } else {
2317 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2319 *r = talloc_strdup(lp_ctx, "");
2323 lp_do_global_parameter(lp_ctx, "share backend", "classic");
2325 lp_do_global_parameter(lp_ctx, "server role", "standalone");
2327 /* options that can be set on the command line must be initialised via
2328 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2329 #ifdef TCP_NODELAY
2330 lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2331 #endif
2332 lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2333 myname = get_myname(lp_ctx);
2334 lp_do_global_parameter(lp_ctx, "netbios name", myname);
2335 talloc_free(myname);
2336 lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2338 lp_do_global_parameter(lp_ctx, "fstype", "NTFS");
2340 lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2341 lp_do_global_parameter(lp_ctx, "max connections", "-1");
2343 lp_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser");
2344 lp_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
2345 lp_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2346 lp_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain");
2347 lp_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2348 lp_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2349 lp_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2350 lp_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
2351 lp_do_global_parameter(lp_ctx, "idmap database", "idmap.ldb");
2352 lp_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
2353 lp_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2354 lp_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2355 lp_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2356 lp_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2358 /* This hive should be dynamically generated by Samba using
2359 data from the sam, but for the moment leave it in a tdb to
2360 keep regedt32 from popping up an annoying dialog. */
2361 lp_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2363 /* using UTF8 by default allows us to support all chars */
2364 lp_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2366 /* Use codepage 850 as a default for the dos character set */
2367 lp_do_global_parameter(lp_ctx, "dos charset", "CP850");
2370 * Allow the default PASSWD_CHAT to be overridden in local.h.
2372 lp_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2374 lp_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2375 lp_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2376 lp_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2377 lp_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2379 lp_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
2380 lp_do_global_parameter_var(lp_ctx, "server string",
2381 "Samba %s", SAMBA_VERSION_STRING);
2383 lp_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2384 DEFAULT_MAJOR_VERSION,
2385 DEFAULT_MINOR_VERSION);
2387 lp_do_global_parameter(lp_ctx, "password server", "*");
2389 lp_do_global_parameter(lp_ctx, "max mux", "50");
2390 lp_do_global_parameter(lp_ctx, "max xmit", "12288");
2391 lp_do_global_parameter(lp_ctx, "password level", "0");
2392 lp_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2393 lp_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2394 lp_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2395 lp_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2396 lp_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2397 lp_do_global_parameter(lp_ctx, "security", "USER");
2398 lp_do_global_parameter(lp_ctx, "paranoid server security", "True");
2399 lp_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2400 lp_do_global_parameter(lp_ctx, "ReadRaw", "True");
2401 lp_do_global_parameter(lp_ctx, "WriteRaw", "True");
2402 lp_do_global_parameter(lp_ctx, "NullPasswords", "False");
2403 lp_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2404 lp_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2406 lp_do_global_parameter(lp_ctx, "TimeServer", "False");
2407 lp_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2408 lp_do_global_parameter(lp_ctx, "Unicode", "True");
2409 lp_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2410 lp_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2411 lp_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2412 lp_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2414 lp_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2416 lp_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2417 lp_do_global_parameter(lp_ctx, "LocalMaster", "True");
2419 lp_do_global_parameter(lp_ctx, "wins support", "False");
2420 lp_do_global_parameter(lp_ctx, "dns proxy", "True");
2422 lp_do_global_parameter(lp_ctx, "winbind separator", "\\");
2423 lp_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2424 lp_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2425 lp_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2426 lp_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2427 lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2428 lp_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2430 lp_do_global_parameter(lp_ctx, "client signing", "Yes");
2431 lp_do_global_parameter(lp_ctx, "server signing", "auto");
2433 lp_do_global_parameter(lp_ctx, "use spnego", "True");
2435 lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
2436 lp_do_global_parameter(lp_ctx, "nbt port", "137");
2437 lp_do_global_parameter(lp_ctx, "dgram port", "138");
2438 lp_do_global_parameter(lp_ctx, "cldap port", "389");
2439 lp_do_global_parameter(lp_ctx, "krb5 port", "88");
2440 lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
2441 lp_do_global_parameter(lp_ctx, "web port", "901");
2442 lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
2444 lp_do_global_parameter(lp_ctx, "nt status support", "True");
2446 lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2447 lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
2449 lp_do_global_parameter(lp_ctx, "tls enabled", "True");
2450 lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2451 lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2452 lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2453 lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2454 dyn_SETUPDIR);
2456 lp_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2458 lp_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2459 lp_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2460 lp_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SBINDIR);
2461 lp_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2463 for (i = 0; parm_table[i].label; i++) {
2464 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2465 lp_ctx->flags[i] |= FLAG_DEFAULT;
2469 return lp_ctx;
2472 const char *lp_configfile(struct loadparm_context *lp_ctx)
2474 return lp_ctx->szConfigFile;
2477 const char *lp_default_path(void)
2479 if (getenv("SMB_CONF_PATH"))
2480 return getenv("SMB_CONF_PATH");
2481 else
2482 return dyn_CONFIGFILE;
2486 * Update the internal state of a loadparm context after settings
2487 * have changed.
2489 static bool lp_update(struct loadparm_context *lp_ctx)
2491 lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
2493 lp_add_hidden(lp_ctx, "IPC$", "IPC");
2494 lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
2496 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2497 lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2500 panic_action = lp_ctx->globals->panic_action;
2502 reload_charcnv(lp_ctx);
2504 /* FIXME: ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx); */
2506 /* FIXME: This is a bit of a hack, but we can't use a global, since
2507 * not everything that uses lp also uses the socket library */
2508 if (lp_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2509 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2510 } else {
2511 unsetenv("SOCKET_TESTNONBLOCK");
2514 /* FIXME: Check locale in environment for this: */
2515 if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
2516 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
2517 else
2518 d_set_iconv((smb_iconv_t)-1);
2520 return true;
2523 bool lp_load_default(struct loadparm_context *lp_ctx)
2525 const char *path;
2527 path = lp_default_path();
2529 if (!file_exist(path)) {
2530 /* We allow the default smb.conf file to not exist,
2531 * basically the equivalent of an empty file. */
2532 return lp_update(lp_ctx);
2535 return lp_load(lp_ctx, path);
2539 * Load the services array from the services file.
2541 * Return True on success, False on failure.
2543 bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
2545 char *n2;
2546 bool bRetval;
2548 filename = talloc_strdup(lp_ctx, filename);
2550 lp_ctx->szConfigFile = filename;
2552 lp_ctx->bInGlobalSection = true;
2553 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2554 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
2556 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2558 /* We get sections first, so have to start 'behind' to make up */
2559 lp_ctx->currentService = NULL;
2560 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2562 /* finish up the last section */
2563 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2564 if (bRetval)
2565 if (lp_ctx->currentService != NULL)
2566 bRetval = service_ok(lp_ctx->currentService);
2568 bRetval = bRetval && lp_update(lp_ctx);
2570 /* we do this unconditionally, so that it happens even
2571 for a missing smb.conf */
2572 reload_charcnv(lp_ctx);
2574 if (bRetval == true) {
2575 /* set this up so that any child python tasks will
2576 find the right smb.conf */
2577 setenv("SMB_CONF_PATH", filename, 1);
2580 return bRetval;
2584 * Return the max number of services.
2587 int lp_numservices(struct loadparm_context *lp_ctx)
2589 return lp_ctx->iNumServices;
2593 * Display the contents of the services array in human-readable form.
2596 void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2597 int maxtoprint)
2599 int iService;
2601 if (show_defaults)
2602 defaults_saved = false;
2604 dump_globals(lp_ctx, f, show_defaults);
2606 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f);
2608 for (iService = 0; iService < maxtoprint; iService++)
2609 lp_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2613 * Display the contents of one service in human-readable form.
2615 void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2617 if (service != NULL) {
2618 if (service->szService[0] == '\0')
2619 return;
2620 dump_a_service(service, sDefault, f);
2624 struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
2625 int snum)
2627 return lp_ctx->services[snum];
2630 struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
2631 const char *service_name)
2633 int iService;
2634 char *serviceName;
2636 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2637 if (lp_ctx->services[iService] &&
2638 lp_ctx->services[iService]->szService) {
2640 * The substitution here is used to support %U is
2641 * service names
2643 serviceName = standard_sub_basic(
2644 lp_ctx->services[iService],
2645 lp_ctx->services[iService]->szService);
2646 if (strequal(serviceName, service_name)) {
2647 talloc_free(serviceName);
2648 return lp_ctx->services[iService];
2650 talloc_free(serviceName);
2654 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
2655 return NULL;
2660 * A useful volume label function.
2662 const char *volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2664 const char *ret = lp_volume(service, sDefault);
2665 if (!*ret)
2666 return lp_servicename(service);
2667 return ret;
2672 * If we are PDC then prefer us as DMB
2674 const char *lp_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2676 const char *ret = _lp_printername(service, sDefault);
2677 if (ret == NULL || (ret != NULL && *ret == '\0'))
2678 ret = lp_servicename(service);
2680 return ret;
2685 * Return the max print jobs per queue.
2687 int lp_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2689 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2690 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2691 maxjobs = PRINT_MAX_JOBID - 1;
2693 return maxjobs;
2696 struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx)
2698 if (lp_ctx == NULL) {
2699 static struct smb_iconv_convenience *fallback_ic = NULL;
2700 if (fallback_ic == NULL)
2701 fallback_ic = smb_iconv_convenience_reinit(talloc_autofree_context(),
2702 "CP850", "UTF8", true, NULL);
2703 return fallback_ic;
2705 return lp_ctx->iconv_convenience;
2708 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2710 struct smb_iconv_convenience *old_ic = lp_ctx->iconv_convenience;
2711 if (old_ic == NULL) {
2712 old_ic = global_iconv_convenience;
2714 lp_ctx->iconv_convenience = smb_iconv_convenience_reinit_lp(lp_ctx, lp_ctx, old_ic);
2715 global_iconv_convenience = lp_ctx->iconv_convenience;
2718 void lp_smbcli_options(struct loadparm_context *lp_ctx,
2719 struct smbcli_options *options)
2721 options->max_xmit = lp_max_xmit(lp_ctx);
2722 options->max_mux = lp_maxmux(lp_ctx);
2723 options->use_spnego = lp_nt_status_support(lp_ctx) && lp_use_spnego(lp_ctx);
2724 options->signing = lp_client_signing(lp_ctx);
2725 options->request_timeout = SMB_REQUEST_TIMEOUT;
2726 options->ntstatus_support = lp_nt_status_support(lp_ctx);
2727 options->max_protocol = lp_cli_maxprotocol(lp_ctx);
2728 options->unicode = lp_unicode(lp_ctx);
2729 options->use_oplocks = true;
2730 options->use_level2_oplocks = true;
2733 void lp_smbcli_session_options(struct loadparm_context *lp_ctx,
2734 struct smbcli_session_options *options)
2736 options->lanman_auth = lp_client_lanman_auth(lp_ctx);
2737 options->ntlmv2_auth = lp_client_ntlmv2_auth(lp_ctx);
2738 options->plaintext_auth = lp_client_plaintext_auth(lp_ctx);
2741 _PUBLIC_ char *lp_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2743 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
2746 _PUBLIC_ char *lp_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2748 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
2751 _PUBLIC_ char *lp_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2753 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
2756 _PUBLIC_ char *lp_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2758 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
2761 _PUBLIC_ char *lp_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2763 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
2766 _PUBLIC_ struct dcerpc_server_info *lp_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2768 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
2770 ret->domain_name = talloc_reference(mem_ctx, lp_workgroup(lp_ctx));
2771 ret->version_major = lp_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
2772 ret->version_minor = lp_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
2773 ret->version_build = lp_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
2775 return ret;
2778 struct gensec_settings *lp_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2780 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
2781 if (settings == NULL)
2782 return NULL;
2783 SMB_ASSERT(lp_ctx != NULL);
2784 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2785 settings->iconv_convenience = lp_iconv_convenience(lp_ctx);
2786 settings->target_hostname = lp_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2787 return settings;