s4 - SID allocation using FDS DNA plugin
[Samba/fernandojvsilva.git] / source4 / param / loadparm.c
blobf2e4ace122c2cc9fe0693e94bb95872bdeb169ab
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 "param/param.h"
65 #include "param/loadparm.h"
66 #include "libcli/raw/libcliraw.h"
67 #include "rpc_server/common/common.h"
68 #include "lib/socket/socket.h"
69 #include "auth/gensec/gensec.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved = false;
76 /**
77 * This structure describes global (ie., server-wide) parameters.
79 struct loadparm_global
81 enum server_role server_role;
82 enum sid_generator sid_generator;
84 const char **smb_ports;
85 char *ncalrpc_dir;
86 char *dos_charset;
87 char *unix_charset;
88 char *display_charset;
89 char *szLockDir;
90 char *szModulesDir;
91 char *szPidDir;
92 char *szSetupDir;
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 char *swat_directory;
130 int tls_enabled;
131 char *tls_keyfile;
132 char *tls_certfile;
133 char *tls_cafile;
134 char *tls_crlfile;
135 char *tls_dhpfile;
136 char *logfile;
137 char *panic_action;
138 int max_mux;
139 int debuglevel;
140 int max_xmit;
141 int pwordlevel;
142 int srv_maxprotocol;
143 int srv_minprotocol;
144 int cli_maxprotocol;
145 int cli_minprotocol;
146 int security;
147 int paranoid_server_security;
148 int max_wins_ttl;
149 int min_wins_ttl;
150 int announce_as; /* This is initialised in init_globals */
151 int nbt_port;
152 int dgram_port;
153 int cldap_port;
154 int krb5_port;
155 int kpasswd_port;
156 int web_port;
157 char *socket_options;
158 int bWINSsupport;
159 int bWINSdnsProxy;
160 char *szWINSHook;
161 int bLocalMaster;
162 int bPreferredMaster;
163 int bEncryptPasswords;
164 int bNullPasswords;
165 int bObeyPamRestrictions;
166 int bLargeReadwrite;
167 int bReadRaw;
168 int bWriteRaw;
169 int bTimeServer;
170 int bBindInterfacesOnly;
171 int bNTSmbSupport;
172 int bNTStatusSupport;
173 int bLanmanAuth;
174 int bNTLMAuth;
175 int bUseSpnego;
176 int server_signing;
177 int client_signing;
178 int bClientPlaintextAuth;
179 int bClientLanManAuth;
180 int bClientNTLMv2Auth;
181 int client_use_spnego_principal;
182 int bHostMSDfs;
183 int bUnicode;
184 int bUnixExtensions;
185 int bDisableNetbios;
186 int bRpcBigEndian;
187 char *szNTPSignDSocketDirectory;
188 struct parmlist_entry *param_opt;
193 * This structure describes a single service.
195 struct loadparm_service
197 char *szService;
198 char *szPath;
199 char *szCopy;
200 char *szInclude;
201 char *szPrintername;
202 char **szHostsallow;
203 char **szHostsdeny;
204 char *comment;
205 char *volume;
206 char *fstype;
207 char **ntvfs_handler;
208 int iMaxPrintJobs;
209 int iMaxConnections;
210 int iCSCPolicy;
211 int bAvailable;
212 int bBrowseable;
213 int bRead_only;
214 int bPrint_ok;
215 int bMap_system;
216 int bMap_hidden;
217 int bMap_archive;
218 int bStrictLocking;
219 int bOplocks;
220 int iCreate_mask;
221 int iCreate_force_mode;
222 int iDir_mask;
223 int iDir_force_mode;
224 int *copymap;
225 int bMSDfsRoot;
226 int bStrictSync;
227 int bCIFileSystem;
228 struct parmlist_entry *param_opt;
230 char dummy[3]; /* for alignment */
234 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
237 /* prototypes for the special type handlers */
238 static bool handle_include(struct loadparm_context *lp_ctx,
239 const char *pszParmValue, char **ptr);
240 static bool handle_realm(struct loadparm_context *lp_ctx,
241 const char *pszParmValue, char **ptr);
242 static bool handle_copy(struct loadparm_context *lp_ctx,
243 const char *pszParmValue, char **ptr);
244 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
245 const char *pszParmValue, char **ptr);
246 static bool handle_logfile(struct loadparm_context *lp_ctx,
247 const char *pszParmValue, char **ptr);
249 static const struct enum_list enum_protocol[] = {
250 {PROTOCOL_SMB2, "SMB2"},
251 {PROTOCOL_NT1, "NT1"},
252 {PROTOCOL_LANMAN2, "LANMAN2"},
253 {PROTOCOL_LANMAN1, "LANMAN1"},
254 {PROTOCOL_CORE, "CORE"},
255 {PROTOCOL_COREPLUS, "COREPLUS"},
256 {PROTOCOL_COREPLUS, "CORE+"},
257 {-1, NULL}
260 static const struct enum_list enum_security[] = {
261 {SEC_SHARE, "SHARE"},
262 {SEC_USER, "USER"},
263 {-1, NULL}
266 static const struct enum_list enum_announce_as[] = {
267 {ANNOUNCE_AS_NT_SERVER, "NT"},
268 {ANNOUNCE_AS_NT_SERVER, "NT Server"},
269 {ANNOUNCE_AS_NT_WORKSTATION, "NT Workstation"},
270 {ANNOUNCE_AS_WIN95, "win95"},
271 {ANNOUNCE_AS_WFW, "WfW"},
272 {-1, NULL}
275 static const struct enum_list enum_bool_auto[] = {
276 {false, "No"},
277 {false, "False"},
278 {false, "0"},
279 {true, "Yes"},
280 {true, "True"},
281 {true, "1"},
282 {Auto, "Auto"},
283 {-1, NULL}
286 /* Client-side offline caching policy types */
287 enum csc_policy {
288 CSC_POLICY_MANUAL=0,
289 CSC_POLICY_DOCUMENTS=1,
290 CSC_POLICY_PROGRAMS=2,
291 CSC_POLICY_DISABLE=3
294 static const struct enum_list enum_csc_policy[] = {
295 {CSC_POLICY_MANUAL, "manual"},
296 {CSC_POLICY_DOCUMENTS, "documents"},
297 {CSC_POLICY_PROGRAMS, "programs"},
298 {CSC_POLICY_DISABLE, "disable"},
299 {-1, NULL}
302 /* SMB signing types. */
303 static const struct enum_list enum_smb_signing_vals[] = {
304 {SMB_SIGNING_OFF, "No"},
305 {SMB_SIGNING_OFF, "False"},
306 {SMB_SIGNING_OFF, "0"},
307 {SMB_SIGNING_OFF, "Off"},
308 {SMB_SIGNING_OFF, "disabled"},
309 {SMB_SIGNING_SUPPORTED, "Yes"},
310 {SMB_SIGNING_SUPPORTED, "True"},
311 {SMB_SIGNING_SUPPORTED, "1"},
312 {SMB_SIGNING_SUPPORTED, "On"},
313 {SMB_SIGNING_SUPPORTED, "enabled"},
314 {SMB_SIGNING_REQUIRED, "required"},
315 {SMB_SIGNING_REQUIRED, "mandatory"},
316 {SMB_SIGNING_REQUIRED, "force"},
317 {SMB_SIGNING_REQUIRED, "forced"},
318 {SMB_SIGNING_REQUIRED, "enforced"},
319 {SMB_SIGNING_AUTO, "auto"},
320 {-1, NULL}
323 static const struct enum_list enum_server_role[] = {
324 {ROLE_STANDALONE, "standalone"},
325 {ROLE_DOMAIN_MEMBER, "member server"},
326 {ROLE_DOMAIN_MEMBER, "member"},
327 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
328 {ROLE_DOMAIN_CONTROLLER, "dc"},
329 {-1, NULL}
332 static const struct enum_list enum_sid_generator[] = {
333 {SID_GENERATOR_INTERNAL, "internal"},
334 {SID_GENERATOR_BACKEND, "backend"},
335 {-1, NULL}
338 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
339 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
341 static struct parm_struct parm_table[] = {
342 {"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
343 {"sid generator", P_ENUM, P_GLOBAL, GLOBAL_VAR(sid_generator), NULL, enum_sid_generator},
345 {"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
346 {"unix charset", P_STRING, P_GLOBAL, GLOBAL_VAR(unix_charset), NULL, NULL},
347 {"ncalrpc dir", P_STRING, P_GLOBAL, GLOBAL_VAR(ncalrpc_dir), NULL, NULL},
348 {"display charset", P_STRING, P_GLOBAL, GLOBAL_VAR(display_charset), NULL, NULL},
349 {"comment", P_STRING, P_LOCAL, LOCAL_VAR(comment), NULL, NULL},
350 {"path", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
351 {"directory", P_STRING, P_LOCAL, LOCAL_VAR(szPath), NULL, NULL},
352 {"workgroup", P_USTRING, P_GLOBAL, GLOBAL_VAR(szWorkgroup), NULL, NULL},
353 {"realm", P_STRING, P_GLOBAL, GLOBAL_VAR(szRealm), handle_realm, NULL},
354 {"netbios name", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosName), NULL, NULL},
355 {"netbios aliases", P_LIST, P_GLOBAL, GLOBAL_VAR(szNetbiosAliases), NULL, NULL},
356 {"netbios scope", P_USTRING, P_GLOBAL, GLOBAL_VAR(szNetbiosScope), NULL, NULL},
357 {"server string", P_STRING, P_GLOBAL, GLOBAL_VAR(szServerString), NULL, NULL},
358 {"interfaces", P_LIST, P_GLOBAL, GLOBAL_VAR(szInterfaces), NULL, NULL},
359 {"bind interfaces only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bBindInterfacesOnly), NULL, NULL},
360 {"ntvfs handler", P_LIST, P_LOCAL, LOCAL_VAR(ntvfs_handler), NULL, NULL},
361 {"ntptr providor", P_STRING, P_GLOBAL, GLOBAL_VAR(ntptr_providor), NULL, NULL},
362 {"dcerpc endpoint servers", P_LIST, P_GLOBAL, GLOBAL_VAR(dcerpc_ep_servers), NULL, NULL},
363 {"server services", P_LIST, P_GLOBAL, GLOBAL_VAR(server_services), NULL, NULL},
365 {"security", P_ENUM, P_GLOBAL, GLOBAL_VAR(security), NULL, enum_security},
366 {"encrypt passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bEncryptPasswords), NULL, NULL},
367 {"null passwords", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNullPasswords), NULL, NULL},
368 {"obey pam restrictions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bObeyPamRestrictions), NULL, NULL},
369 {"password server", P_LIST, P_GLOBAL, GLOBAL_VAR(szPasswordServers), NULL, NULL},
370 {"sam database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSAM_URL), NULL, NULL},
371 {"idmap database", P_STRING, P_GLOBAL, GLOBAL_VAR(szIDMAP_URL), NULL, NULL},
372 {"secrets database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSECRETS_URL), NULL, NULL},
373 {"spoolss database", P_STRING, P_GLOBAL, GLOBAL_VAR(szSPOOLSS_URL), NULL, NULL},
374 {"wins config database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_CONFIG_URL), NULL, NULL},
375 {"wins database", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINS_URL), NULL, NULL},
376 {"private dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szPrivateDir), NULL, NULL},
377 {"passwd chat", P_STRING, P_GLOBAL, GLOBAL_VAR(szPasswdChat), NULL, NULL},
378 {"password level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(pwordlevel), NULL, NULL},
379 {"lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLanmanAuth), NULL, NULL},
380 {"ntlm auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTLMAuth), NULL, NULL},
381 {"client NTLMv2 auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientNTLMv2Auth), NULL, NULL},
382 {"client lanman auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientLanManAuth), NULL, NULL},
383 {"client plaintext auth", P_BOOL, P_GLOBAL, GLOBAL_VAR(bClientPlaintextAuth), NULL, NULL},
384 {"client use spnego principal", P_BOOL, P_GLOBAL, GLOBAL_VAR(client_use_spnego_principal), NULL, NULL},
386 {"read only", P_BOOL, P_LOCAL, LOCAL_VAR(bRead_only), NULL, NULL},
388 {"create mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_mask), NULL, NULL},
389 {"force create mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iCreate_force_mode), NULL, NULL},
390 {"directory mask", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_mask), NULL, NULL},
391 {"force directory mode", P_OCTAL, P_LOCAL, LOCAL_VAR(iDir_force_mode), NULL, NULL},
393 {"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
394 {"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
396 {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
397 {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
398 {"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
400 {"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
401 {"nbt port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(nbt_port), NULL, NULL},
402 {"dgram port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(dgram_port), NULL, NULL},
403 {"cldap port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(cldap_port), NULL, NULL},
404 {"krb5 port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(krb5_port), NULL, NULL},
405 {"kpasswd port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(kpasswd_port), NULL, NULL},
406 {"web port", P_INTEGER, P_GLOBAL, GLOBAL_VAR(web_port), NULL, NULL},
407 {"tls enabled", P_BOOL, P_GLOBAL, GLOBAL_VAR(tls_enabled), NULL, NULL},
408 {"tls keyfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_keyfile), NULL, NULL},
409 {"tls certfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_certfile), NULL, NULL},
410 {"tls cafile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_cafile), NULL, NULL},
411 {"tls crlfile", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_crlfile), NULL, NULL},
412 {"tls dh params file", P_STRING, P_GLOBAL, GLOBAL_VAR(tls_dhpfile), NULL, NULL},
413 {"swat directory", P_STRING, P_GLOBAL, GLOBAL_VAR(swat_directory), NULL, NULL},
414 {"large readwrite", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLargeReadwrite), NULL, NULL},
415 {"server max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_maxprotocol), NULL, enum_protocol},
416 {"server min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(srv_minprotocol), NULL, enum_protocol},
417 {"client max protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_maxprotocol), NULL, enum_protocol},
418 {"client min protocol", P_ENUM, P_GLOBAL, GLOBAL_VAR(cli_minprotocol), NULL, enum_protocol},
419 {"unicode", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnicode), NULL, NULL},
420 {"read raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bReadRaw), NULL, NULL},
421 {"write raw", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWriteRaw), NULL, NULL},
422 {"disable netbios", P_BOOL, P_GLOBAL, GLOBAL_VAR(bDisableNetbios), NULL, NULL},
424 {"nt status support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bNTStatusSupport), NULL, NULL},
426 {"announce version", P_STRING, P_GLOBAL, GLOBAL_VAR(szAnnounceVersion), NULL, NULL},
427 {"announce as", P_ENUM, P_GLOBAL, GLOBAL_VAR(announce_as), NULL, enum_announce_as},
428 {"max mux", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_mux), NULL, NULL},
429 {"max xmit", P_BYTES, P_GLOBAL, GLOBAL_VAR(max_xmit), NULL, NULL},
431 {"name resolve order", P_LIST, P_GLOBAL, GLOBAL_VAR(szNameResolveOrder), NULL, NULL},
432 {"max wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(max_wins_ttl), NULL, NULL},
433 {"min wins ttl", P_INTEGER, P_GLOBAL, GLOBAL_VAR(min_wins_ttl), NULL, NULL},
434 {"time server", P_BOOL, P_GLOBAL, GLOBAL_VAR(bTimeServer), NULL, NULL},
435 {"unix extensions", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUnixExtensions), NULL, NULL},
436 {"use spnego", P_BOOL, P_GLOBAL, GLOBAL_VAR(bUseSpnego), NULL, NULL},
437 {"server signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_signing), NULL, enum_smb_signing_vals},
438 {"client signing", P_ENUM, P_GLOBAL, GLOBAL_VAR(client_signing), NULL, enum_smb_signing_vals},
439 {"rpc big endian", P_BOOL, P_GLOBAL, GLOBAL_VAR(bRpcBigEndian), NULL, NULL},
441 {"max connections", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxConnections), NULL, NULL},
442 {"paranoid server security", P_BOOL, P_GLOBAL, GLOBAL_VAR(paranoid_server_security), NULL, NULL},
443 {"socket options", P_STRING, P_GLOBAL, GLOBAL_VAR(socket_options), NULL, NULL},
445 {"strict sync", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictSync), NULL, NULL},
446 {"case insensitive filesystem", P_BOOL, P_LOCAL, LOCAL_VAR(bCIFileSystem), NULL, NULL},
448 {"max print jobs", P_INTEGER, P_LOCAL, LOCAL_VAR(iMaxPrintJobs), NULL, NULL},
449 {"printable", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
450 {"print ok", P_BOOL, P_LOCAL, LOCAL_VAR(bPrint_ok), NULL, NULL},
452 {"printer name", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
453 {"printer", P_STRING, P_LOCAL, LOCAL_VAR(szPrintername), NULL, NULL},
455 {"map system", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_system), NULL, NULL},
456 {"map hidden", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_hidden), NULL, NULL},
457 {"map archive", P_BOOL, P_LOCAL, LOCAL_VAR(bMap_archive), NULL, NULL},
459 {"preferred master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
460 {"prefered master", P_ENUM, P_GLOBAL, GLOBAL_VAR(bPreferredMaster), NULL, enum_bool_auto},
461 {"local master", P_BOOL, P_GLOBAL, GLOBAL_VAR(bLocalMaster), NULL, NULL},
462 {"browseable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
463 {"browsable", P_BOOL, P_LOCAL, LOCAL_VAR(bBrowseable), NULL, NULL},
465 {"wins server", P_LIST, P_GLOBAL, GLOBAL_VAR(szWINSservers), NULL, NULL},
466 {"wins support", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSsupport), NULL, NULL},
467 {"dns proxy", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWINSdnsProxy), NULL, NULL},
468 {"wins hook", P_STRING, P_GLOBAL, GLOBAL_VAR(szWINSHook), NULL, NULL},
470 {"csc policy", P_ENUM, P_LOCAL, LOCAL_VAR(iCSCPolicy), NULL, enum_csc_policy},
472 {"strict locking", P_BOOL, P_LOCAL, LOCAL_VAR(bStrictLocking), NULL, NULL},
473 {"oplocks", P_BOOL, P_LOCAL, LOCAL_VAR(bOplocks), NULL, NULL},
475 {"share backend", P_STRING, P_GLOBAL, GLOBAL_VAR(szShareBackend), NULL, NULL},
476 {"preload", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
477 {"auto services", P_STRING, P_GLOBAL, GLOBAL_VAR(szAutoServices), NULL, NULL},
478 {"lock dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
479 {"lock directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szLockDir), NULL, NULL},
480 {"modules dir", P_STRING, P_GLOBAL, GLOBAL_VAR(szModulesDir), NULL, NULL},
481 {"pid directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szPidDir), NULL, NULL},
482 {"setup directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szSetupDir), NULL, NULL},
484 {"socket address", P_STRING, P_GLOBAL, GLOBAL_VAR(szSocketAddress), NULL, NULL},
485 {"copy", P_STRING, P_LOCAL, LOCAL_VAR(szCopy), handle_copy, NULL},
486 {"include", P_STRING, P_LOCAL, LOCAL_VAR(szInclude), handle_include, NULL},
488 {"available", P_BOOL, P_LOCAL, LOCAL_VAR(bAvailable), NULL, NULL},
489 {"volume", P_STRING, P_LOCAL, LOCAL_VAR(volume), NULL, NULL },
490 {"fstype", P_STRING, P_LOCAL, LOCAL_VAR(fstype), NULL, NULL},
492 {"panic action", P_STRING, P_GLOBAL, GLOBAL_VAR(panic_action), NULL, NULL},
494 {"msdfs root", P_BOOL, P_LOCAL, LOCAL_VAR(bMSDfsRoot), NULL, NULL},
495 {"host msdfs", P_BOOL, P_GLOBAL, GLOBAL_VAR(bHostMSDfs), NULL, NULL},
496 {"winbind separator", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbindSeparator), NULL, NULL },
497 {"winbindd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddSocketDirectory), NULL, NULL },
498 {"winbindd privileged socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory), NULL, NULL },
499 {"winbind sealed pipes", P_BOOL, P_GLOBAL, GLOBAL_VAR(bWinbindSealedPipes), NULL, NULL },
500 {"template shell", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateShell), NULL, NULL },
501 {"template homedir", P_STRING, P_GLOBAL, GLOBAL_VAR(szTemplateHomedir), NULL, NULL },
502 {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
504 {"ntp signd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szNTPSignDSocketDirectory), NULL, NULL },
506 {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
510 /* local variables */
511 struct loadparm_context {
512 const char *szConfigFile;
513 struct loadparm_global *globals;
514 struct loadparm_service **services;
515 struct loadparm_service *sDefault;
516 int iNumServices;
517 struct loadparm_service *currentService;
518 bool bInGlobalSection;
519 struct file_lists {
520 struct file_lists *next;
521 char *name;
522 char *subfname;
523 time_t modtime;
524 } *file_lists;
525 unsigned int flags[NUMPARAMETERS];
526 struct smb_iconv_convenience *iconv_convenience;
530 struct loadparm_service *lp_default_service(struct loadparm_context *lp_ctx)
532 return lp_ctx->sDefault;
536 return the parameter table
538 struct parm_struct *lp_parm_table(void)
540 return parm_table;
544 * Convenience routine to grab string parameters into temporary memory
545 * and run standard_sub_basic on them.
547 * The buffers can be written to by
548 * callers without affecting the source string.
551 static const char *lp_string(const char *s)
553 #if 0 /* until REWRITE done to make thread-safe */
554 size_t len = s ? strlen(s) : 0;
555 char *ret;
556 #endif
558 /* The follow debug is useful for tracking down memory problems
559 especially if you have an inner loop that is calling a lp_*()
560 function that returns a string. Perhaps this debug should be
561 present all the time? */
563 #if 0
564 DEBUG(10, ("lp_string(%s)\n", s));
565 #endif
567 #if 0 /* until REWRITE done to make thread-safe */
568 if (!lp_talloc)
569 lp_talloc = talloc_init("lp_talloc");
571 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
573 if (!ret)
574 return NULL;
576 if (!s)
577 *ret = 0;
578 else
579 strlcpy(ret, s, len);
581 if (trim_string(ret, "\"", "\"")) {
582 if (strchr(ret,'"') != NULL)
583 strlcpy(ret, s, len);
586 standard_sub_basic(ret,len+100);
587 return (ret);
588 #endif
589 return s;
593 In this section all the functions that are used to access the
594 parameters from the rest of the program are defined
597 #define FN_GLOBAL_STRING(fn_name,var_name) \
598 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) : "";}
599 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
600 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 : "";}
601 #define FN_GLOBAL_LIST(fn_name,var_name) \
602 const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->globals->var_name;}
603 #define FN_GLOBAL_BOOL(fn_name,var_name) \
604 bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->globals->var_name;}
605 #if 0 /* unused */
606 #define FN_GLOBAL_CHAR(fn_name,ptr) \
607 char fn_name(void) {return(*(char *)(ptr));}
608 #endif
609 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
610 int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;}
612 #define FN_LOCAL_STRING(fn_name,val) \
613 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)));}
614 #define FN_LOCAL_LIST(fn_name,val) \
615 const char **fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val);}
616 #define FN_LOCAL_BOOL(fn_name,val) \
617 bool fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
618 #define FN_LOCAL_INTEGER(fn_name,val) \
619 int fn_name(struct loadparm_service *service, struct loadparm_service *sDefault) {return((service != NULL)? service->val : sDefault->val);}
621 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, server_role)
622 _PUBLIC_ FN_GLOBAL_INTEGER(lp_sid_generator, sid_generator)
623 _PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, smb_ports)
624 _PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, nbt_port)
625 _PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, dgram_port)
626 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, cldap_port)
627 _PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, krb5_port)
628 _PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, kpasswd_port)
629 _PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, web_port)
630 _PUBLIC_ FN_GLOBAL_STRING(lp_swat_directory, swat_directory)
631 _PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, tls_enabled)
632 _PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
633 _PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
634 _PUBLIC_ FN_GLOBAL_STRING(lp_idmap_url, szIDMAP_URL)
635 _PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
636 _PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
637 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
638 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
639 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
640 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
641 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
642 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
643 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
644 _PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
645 _PUBLIC_ FN_GLOBAL_BOOL(lp_idmap_trusted_only, bIdmapTrustedOnly)
646 _PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
647 _PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
648 _PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
649 _PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
650 _PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
651 _PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
652 _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
653 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
654 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
655 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
656 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
657 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
658 _PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
659 _PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
660 _PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
661 _PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
662 _PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
663 _PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm_upper)
664 _PUBLIC_ FN_GLOBAL_STRING(lp_dnsdomain, szRealm_lower)
665 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
666 _PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
667 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
668 _PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
669 _PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
670 _PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
671 _PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
672 _PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
673 _PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
674 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
675 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
676 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
677 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
678 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
679 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
680 _PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
681 _PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
682 _PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
683 _PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
684 _PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
685 _PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
686 _PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
687 _PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
688 _PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
689 _PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
690 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
691 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
692 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
693 _PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
694 _PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
695 _PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
696 _PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
697 _PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
698 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
699 _PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
700 _PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
701 _PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
702 _PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
703 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
704 _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
705 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
706 _PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
707 _PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
708 _PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
709 _PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
711 const char *lp_servicename(const struct loadparm_service *service)
713 return lp_string((const char *)service->szService);
716 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
717 static FN_LOCAL_STRING(_lp_printername, szPrintername)
718 _PUBLIC_ FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
719 _PUBLIC_ FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
720 _PUBLIC_ FN_LOCAL_STRING(lp_comment, comment)
721 _PUBLIC_ FN_LOCAL_STRING(lp_fstype, fstype)
722 static FN_LOCAL_STRING(lp_volume, volume)
723 _PUBLIC_ FN_LOCAL_LIST(lp_ntvfs_handler, ntvfs_handler)
724 _PUBLIC_ FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
725 _PUBLIC_ FN_LOCAL_BOOL(lp_browseable, bBrowseable)
726 _PUBLIC_ FN_LOCAL_BOOL(lp_readonly, bRead_only)
727 _PUBLIC_ FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
728 _PUBLIC_ FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
729 _PUBLIC_ FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
730 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
731 _PUBLIC_ FN_LOCAL_BOOL(lp_oplocks, bOplocks)
732 _PUBLIC_ FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
733 _PUBLIC_ FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
734 _PUBLIC_ FN_LOCAL_BOOL(lp_map_system, bMap_system)
735 _PUBLIC_ FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
736 _PUBLIC_ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
737 _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
738 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
739 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
740 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
741 _PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
742 _PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
744 _PUBLIC_ FN_GLOBAL_CONST_STRING(lp_ntp_signd_socket_directory, szNTPSignDSocketDirectory)
746 /* local prototypes */
747 static int map_parameter(const char *pszParmName);
748 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
749 const char *pszServiceName);
750 static void copy_service(struct loadparm_service *pserviceDest,
751 struct loadparm_service *pserviceSource,
752 int *pcopymapDest);
753 static bool service_ok(struct loadparm_service *service);
754 static bool do_section(const char *pszSectionName, void *);
755 static void init_copymap(struct loadparm_service *pservice);
757 /* This is a helper function for parametrical options support. */
758 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
759 /* Actual parametrical functions are quite simple */
760 const char *lp_get_parametric(struct loadparm_context *lp_ctx,
761 struct loadparm_service *service,
762 const char *type, const char *option)
764 char *vfskey;
765 struct parmlist_entry *data;
767 if (lp_ctx == NULL)
768 return NULL;
770 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
772 asprintf(&vfskey, "%s:%s", type, option);
773 strlower(vfskey);
775 while (data) {
776 if (strcmp(data->key, vfskey) == 0) {
777 free(vfskey);
778 return data->value;
780 data = data->next;
783 if (service != NULL) {
784 /* Try to fetch the same option but from globals */
785 /* but only if we are not already working with globals */
786 for (data = lp_ctx->globals->param_opt; data;
787 data = data->next) {
788 if (strcmp(data->key, vfskey) == 0) {
789 free(vfskey);
790 return data->value;
795 free(vfskey);
797 return NULL;
802 * convenience routine to return int parameters.
804 static int lp_int(const char *s)
807 if (!s) {
808 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
809 return -1;
812 return strtol(s, NULL, 0);
816 * convenience routine to return unsigned long parameters.
818 static int lp_ulong(const char *s)
821 if (!s) {
822 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
823 return -1;
826 return strtoul(s, NULL, 0);
830 * convenience routine to return unsigned long parameters.
832 static double lp_double(const char *s)
835 if (!s) {
836 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
837 return -1;
840 return strtod(s, NULL);
844 * convenience routine to return boolean parameters.
846 static bool lp_bool(const char *s)
848 bool ret = false;
850 if (!s) {
851 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
852 return false;
855 if (!set_boolean(s, &ret)) {
856 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
857 return false;
860 return ret;
865 * Return parametric option from a given service. Type is a part of option before ':'
866 * Parametric option has following syntax: 'Type: option = value'
867 * Returned value is allocated in 'lp_talloc' context
870 const char *lp_parm_string(struct loadparm_context *lp_ctx,
871 struct loadparm_service *service, const char *type,
872 const char *option)
874 const char *value = lp_get_parametric(lp_ctx, service, type, option);
876 if (value)
877 return lp_string(value);
879 return NULL;
883 * Return parametric option from a given service. Type is a part of option before ':'
884 * Parametric option has following syntax: 'Type: option = value'
885 * Returned value is allocated in 'lp_talloc' context
888 const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,
889 struct loadparm_context *lp_ctx,
890 struct loadparm_service *service,
891 const char *type,
892 const char *option, const char *separator)
894 const char *value = lp_get_parametric(lp_ctx, service, type, option);
896 if (value != NULL)
897 return (const char **)str_list_make(mem_ctx, value, separator);
899 return NULL;
903 * Return parametric option from a given service. Type is a part of option before ':'
904 * Parametric option has following syntax: 'Type: option = value'
907 int lp_parm_int(struct loadparm_context *lp_ctx,
908 struct loadparm_service *service, const char *type,
909 const char *option, int default_v)
911 const char *value = lp_get_parametric(lp_ctx, service, type, option);
913 if (value)
914 return lp_int(value);
916 return default_v;
920 * Return parametric option from a given service. Type is a part of
921 * option before ':'.
922 * Parametric option has following syntax: 'Type: option = value'.
925 int lp_parm_bytes(struct loadparm_context *lp_ctx,
926 struct loadparm_service *service, const char *type,
927 const char *option, int default_v)
929 uint64_t bval;
931 const char *value = lp_get_parametric(lp_ctx, service, type, option);
933 if (value && conv_str_size(value, &bval)) {
934 if (bval <= INT_MAX) {
935 return (int)bval;
939 return default_v;
943 * Return parametric option from a given service.
944 * Type is a part of option before ':'
945 * Parametric option has following syntax: 'Type: option = value'
947 unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,
948 struct loadparm_service *service, const char *type,
949 const char *option, unsigned long default_v)
951 const char *value = lp_get_parametric(lp_ctx, service, type, option);
953 if (value)
954 return lp_ulong(value);
956 return default_v;
960 double lp_parm_double(struct loadparm_context *lp_ctx,
961 struct loadparm_service *service, const char *type,
962 const char *option, double default_v)
964 const char *value = lp_get_parametric(lp_ctx, service, type, option);
966 if (value != NULL)
967 return lp_double(value);
969 return default_v;
973 * Return parametric option from a given service. Type is a part of option before ':'
974 * Parametric option has following syntax: 'Type: option = value'
977 bool lp_parm_bool(struct loadparm_context *lp_ctx,
978 struct loadparm_service *service, const char *type,
979 const char *option, bool default_v)
981 const char *value = lp_get_parametric(lp_ctx, service, type, option);
983 if (value != NULL)
984 return lp_bool(value);
986 return default_v;
991 * Initialise a service to the defaults.
994 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
996 struct loadparm_service *pservice =
997 talloc_zero(mem_ctx, struct loadparm_service);
998 copy_service(pservice, sDefault, NULL);
999 return pservice;
1003 * Set a string value, deallocating any existing space, and allocing the space
1004 * for the string
1006 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1008 talloc_free(*dest);
1010 if (src == NULL)
1011 src = "";
1013 *dest = talloc_strdup(mem_ctx, src);
1014 if ((*dest) == NULL) {
1015 DEBUG(0,("Out of memory in string_init\n"));
1016 return false;
1019 return true;
1025 * Add a new service to the services array initialising it with the given
1026 * service.
1029 struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
1030 const struct loadparm_service *pservice,
1031 const char *name)
1033 int i;
1034 struct loadparm_service tservice;
1035 int num_to_alloc = lp_ctx->iNumServices + 1;
1036 struct parmlist_entry *data, *pdata;
1038 tservice = *pservice;
1040 /* it might already exist */
1041 if (name) {
1042 struct loadparm_service *service = getservicebyname(lp_ctx,
1043 name);
1044 if (service != NULL) {
1045 /* Clean all parametric options for service */
1046 /* They will be added during parsing again */
1047 data = service->param_opt;
1048 while (data) {
1049 pdata = data->next;
1050 talloc_free(data);
1051 data = pdata;
1053 service->param_opt = NULL;
1054 return service;
1058 /* find an invalid one */
1059 for (i = 0; i < lp_ctx->iNumServices; i++)
1060 if (lp_ctx->services[i] == NULL)
1061 break;
1063 /* if not, then create one */
1064 if (i == lp_ctx->iNumServices) {
1065 struct loadparm_service **tsp;
1067 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1069 if (!tsp) {
1070 DEBUG(0,("lp_add_service: failed to enlarge services!\n"));
1071 return NULL;
1072 } else {
1073 lp_ctx->services = tsp;
1074 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1077 lp_ctx->iNumServices++;
1080 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1081 if (lp_ctx->services[i] == NULL) {
1082 DEBUG(0,("lp_add_service: out of memory!\n"));
1083 return NULL;
1085 copy_service(lp_ctx->services[i], &tservice, NULL);
1086 if (name != NULL)
1087 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1088 return lp_ctx->services[i];
1092 * Add a new home service, with the specified home directory, defaults coming
1093 * from service ifrom.
1096 bool lp_add_home(struct loadparm_context *lp_ctx,
1097 const char *pszHomename,
1098 struct loadparm_service *default_service,
1099 const char *user, const char *pszHomedir)
1101 struct loadparm_service *service;
1103 service = lp_add_service(lp_ctx, default_service, pszHomename);
1105 if (service == NULL)
1106 return false;
1108 if (!(*(default_service->szPath))
1109 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1110 service->szPath = talloc_strdup(service, pszHomedir);
1111 } else {
1112 service->szPath = string_sub_talloc(service, lp_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1115 if (!(*(service->comment))) {
1116 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1118 service->bAvailable = default_service->bAvailable;
1119 service->bBrowseable = default_service->bBrowseable;
1121 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1122 pszHomename, user, service->szPath));
1124 return true;
1128 * Add the IPC service.
1131 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,
1132 const char *fstype)
1134 struct loadparm_service *service = lp_add_service(lp_ctx, lp_ctx->sDefault, name);
1136 if (service == NULL)
1137 return false;
1139 string_set(service, &service->szPath, tmpdir());
1141 service->comment = talloc_asprintf(service, "%s Service (%s)",
1142 fstype, lp_ctx->globals->szServerString);
1143 string_set(service, &service->fstype, fstype);
1144 service->iMaxConnections = -1;
1145 service->bAvailable = true;
1146 service->bRead_only = true;
1147 service->bPrint_ok = false;
1148 service->bBrowseable = false;
1150 if (strcasecmp(fstype, "IPC") == 0) {
1151 lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
1152 "default");
1155 DEBUG(3, ("adding hidden service %s\n", name));
1157 return true;
1161 * Add a new printer service, with defaults coming from service iFrom.
1164 bool lp_add_printer(struct loadparm_context *lp_ctx,
1165 const char *pszPrintername,
1166 struct loadparm_service *default_service)
1168 const char *comment = "From Printcap";
1169 struct loadparm_service *service;
1170 service = lp_add_service(lp_ctx, default_service, pszPrintername);
1172 if (service == NULL)
1173 return false;
1175 /* note that we do NOT default the availability flag to True - */
1176 /* we take it from the default service passed. This allows all */
1177 /* dynamic printers to be disabled by disabling the [printers] */
1178 /* entry (if/when the 'available' keyword is implemented!). */
1180 /* the printer name is set to the service name. */
1181 string_set(service, &service->szPrintername, pszPrintername);
1182 string_set(service, &service->comment, comment);
1183 service->bBrowseable = default_service->bBrowseable;
1184 /* Printers cannot be read_only. */
1185 service->bRead_only = false;
1186 /* Printer services must be printable. */
1187 service->bPrint_ok = true;
1189 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1191 return true;
1195 * Map a parameter's string representation to something we can use.
1196 * Returns False if the parameter string is not recognised, else TRUE.
1199 static int map_parameter(const char *pszParmName)
1201 int iIndex;
1203 if (*pszParmName == '-')
1204 return -1;
1206 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1207 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1208 return iIndex;
1210 /* Warn only if it isn't parametric option */
1211 if (strchr(pszParmName, ':') == NULL)
1212 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1213 /* We do return 'fail' for parametric options as well because they are
1214 stored in different storage
1216 return -1;
1221 return the parameter structure for a parameter
1223 struct parm_struct *lp_parm_struct(const char *name)
1225 int parmnum = map_parameter(name);
1226 if (parmnum == -1) return NULL;
1227 return &parm_table[parmnum];
1231 return the parameter pointer for a parameter
1233 void *lp_parm_ptr(struct loadparm_context *lp_ctx,
1234 struct loadparm_service *service, struct parm_struct *parm)
1236 if (service == NULL) {
1237 if (parm->pclass == P_LOCAL)
1238 return ((char *)lp_ctx->sDefault)+parm->offset;
1239 else if (parm->pclass == P_GLOBAL)
1240 return ((char *)lp_ctx->globals)+parm->offset;
1241 else return NULL;
1242 } else {
1243 return ((char *)service) + parm->offset;
1248 * Find a service by name. Otherwise works like get_service.
1251 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1252 const char *pszServiceName)
1254 int iService;
1256 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
1257 if (lp_ctx->services[iService] != NULL &&
1258 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
1259 return lp_ctx->services[iService];
1262 return NULL;
1266 * Copy a service structure to another.
1267 * If pcopymapDest is NULL then copy all fields
1270 static void copy_service(struct loadparm_service *pserviceDest,
1271 struct loadparm_service *pserviceSource,
1272 int *pcopymapDest)
1274 int i;
1275 bool bcopyall = (pcopymapDest == NULL);
1276 struct parmlist_entry *data, *pdata, *paramo;
1277 bool not_added;
1279 for (i = 0; parm_table[i].label; i++)
1280 if (parm_table[i].offset != -1 && parm_table[i].pclass == P_LOCAL &&
1281 (bcopyall || pcopymapDest[i])) {
1282 void *src_ptr =
1283 ((char *)pserviceSource) + parm_table[i].offset;
1284 void *dest_ptr =
1285 ((char *)pserviceDest) + parm_table[i].offset;
1287 switch (parm_table[i].type) {
1288 case P_BOOL:
1289 *(int *)dest_ptr = *(int *)src_ptr;
1290 break;
1292 case P_INTEGER:
1293 case P_OCTAL:
1294 case P_ENUM:
1295 *(int *)dest_ptr = *(int *)src_ptr;
1296 break;
1298 case P_STRING:
1299 string_set(pserviceDest,
1300 (char **)dest_ptr,
1301 *(char **)src_ptr);
1302 break;
1304 case P_USTRING:
1305 string_set(pserviceDest,
1306 (char **)dest_ptr,
1307 *(char **)src_ptr);
1308 strupper(*(char **)dest_ptr);
1309 break;
1310 case P_LIST:
1311 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
1312 *(const char ***)src_ptr);
1313 break;
1314 default:
1315 break;
1319 if (bcopyall) {
1320 init_copymap(pserviceDest);
1321 if (pserviceSource->copymap)
1322 memcpy((void *)pserviceDest->copymap,
1323 (void *)pserviceSource->copymap,
1324 sizeof(int) * NUMPARAMETERS);
1327 data = pserviceSource->param_opt;
1328 while (data) {
1329 not_added = true;
1330 pdata = pserviceDest->param_opt;
1331 /* Traverse destination */
1332 while (pdata) {
1333 /* If we already have same option, override it */
1334 if (strcmp(pdata->key, data->key) == 0) {
1335 talloc_free(pdata->value);
1336 pdata->value = talloc_reference(pdata,
1337 data->value);
1338 not_added = false;
1339 break;
1341 pdata = pdata->next;
1343 if (not_added) {
1344 paramo = talloc(pserviceDest, struct parmlist_entry);
1345 if (paramo == NULL)
1346 smb_panic("OOM");
1347 paramo->key = talloc_reference(paramo, data->key);
1348 paramo->value = talloc_reference(paramo, data->value);
1349 DLIST_ADD(pserviceDest->param_opt, paramo);
1351 data = data->next;
1356 * Check a service for consistency. Return False if the service is in any way
1357 * incomplete or faulty, else True.
1359 static bool service_ok(struct loadparm_service *service)
1361 bool bRetval;
1363 bRetval = true;
1364 if (service->szService[0] == '\0') {
1365 DEBUG(0, ("The following message indicates an internal error:\n"));
1366 DEBUG(0, ("No service name in service entry.\n"));
1367 bRetval = false;
1370 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1371 /* I can't see why you'd want a non-printable printer service... */
1372 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1373 if (!service->bPrint_ok) {
1374 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1375 service->szService));
1376 service->bPrint_ok = true;
1378 /* [printers] service must also be non-browsable. */
1379 if (service->bBrowseable)
1380 service->bBrowseable = false;
1383 /* If a service is flagged unavailable, log the fact at level 0. */
1384 if (!service->bAvailable)
1385 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1386 service->szService));
1388 return bRetval;
1392 /*******************************************************************
1393 Keep a linked list of all config files so we know when one has changed
1394 it's date and needs to be reloaded.
1395 ********************************************************************/
1397 static void add_to_file_list(struct loadparm_context *lp_ctx,
1398 const char *fname, const char *subfname)
1400 struct file_lists *f = lp_ctx->file_lists;
1402 while (f) {
1403 if (f->name && !strcmp(f->name, fname))
1404 break;
1405 f = f->next;
1408 if (!f) {
1409 f = talloc(lp_ctx, struct file_lists);
1410 if (!f)
1411 return;
1412 f->next = lp_ctx->file_lists;
1413 f->name = talloc_strdup(f, fname);
1414 if (!f->name) {
1415 talloc_free(f);
1416 return;
1418 f->subfname = talloc_strdup(f, subfname);
1419 if (!f->subfname) {
1420 talloc_free(f);
1421 return;
1423 lp_ctx->file_lists = f;
1424 f->modtime = file_modtime(subfname);
1425 } else {
1426 time_t t = file_modtime(subfname);
1427 if (t)
1428 f->modtime = t;
1432 /*******************************************************************
1433 Check if a config file has changed date.
1434 ********************************************************************/
1435 bool lp_file_list_changed(struct loadparm_context *lp_ctx)
1437 struct file_lists *f;
1438 DEBUG(6, ("lp_file_list_changed()\n"));
1440 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1441 char *n2;
1442 time_t mod_time;
1444 n2 = standard_sub_basic(lp_ctx, f->name);
1446 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1447 f->name, n2, ctime(&f->modtime)));
1449 mod_time = file_modtime(n2);
1451 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1452 DEBUGADD(6, ("file %s modified: %s\n", n2,
1453 ctime(&mod_time)));
1454 f->modtime = mod_time;
1455 talloc_free(f->subfname);
1456 f->subfname = talloc_strdup(f, n2);
1457 return true;
1460 return false;
1463 /***************************************************************************
1464 Handle the "realm" parameter
1465 ***************************************************************************/
1467 static bool handle_realm(struct loadparm_context *lp_ctx,
1468 const char *pszParmValue, char **ptr)
1470 string_set(lp_ctx, ptr, pszParmValue);
1472 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
1473 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
1475 return true;
1478 /***************************************************************************
1479 Handle the include operation.
1480 ***************************************************************************/
1482 static bool handle_include(struct loadparm_context *lp_ctx,
1483 const char *pszParmValue, char **ptr)
1485 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1487 add_to_file_list(lp_ctx, pszParmValue, fname);
1489 string_set(lp_ctx, ptr, fname);
1491 if (file_exist(fname))
1492 return pm_process(fname, do_section, do_parameter, lp_ctx);
1494 DEBUG(2, ("Can't find include file %s\n", fname));
1496 return false;
1499 /***************************************************************************
1500 Handle the interpretation of the copy parameter.
1501 ***************************************************************************/
1503 static bool handle_copy(struct loadparm_context *lp_ctx,
1504 const char *pszParmValue, char **ptr)
1506 bool bRetval;
1507 struct loadparm_service *serviceTemp;
1509 string_set(lp_ctx, ptr, pszParmValue);
1511 bRetval = false;
1513 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1515 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1516 if (serviceTemp == lp_ctx->currentService) {
1517 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1518 } else {
1519 copy_service(lp_ctx->currentService,
1520 serviceTemp,
1521 lp_ctx->currentService->copymap);
1522 bRetval = true;
1524 } else {
1525 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1526 pszParmValue));
1527 bRetval = false;
1530 return bRetval;
1533 static bool handle_debuglevel(struct loadparm_context *lp_ctx,
1534 const char *pszParmValue, char **ptr)
1536 DEBUGLEVEL = atoi(pszParmValue);
1538 return true;
1541 static bool handle_logfile(struct loadparm_context *lp_ctx,
1542 const char *pszParmValue, char **ptr)
1544 logfile = pszParmValue;
1545 return true;
1548 /***************************************************************************
1549 Initialise a copymap.
1550 ***************************************************************************/
1552 static void init_copymap(struct loadparm_service *pservice)
1554 int i;
1555 talloc_free(pservice->copymap);
1556 pservice->copymap = talloc_array(pservice, int, NUMPARAMETERS);
1557 if (pservice->copymap == NULL) {
1558 DEBUG(0,
1559 ("Couldn't allocate copymap!! (size %d)\n",
1560 (int)NUMPARAMETERS));
1561 return;
1563 for (i = 0; i < NUMPARAMETERS; i++)
1564 pservice->copymap[i] = true;
1568 * Process a parametric option
1570 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1571 struct loadparm_service *service,
1572 const char *pszParmName,
1573 const char *pszParmValue, int flags)
1575 struct parmlist_entry *paramo, *data;
1576 char *name;
1577 TALLOC_CTX *mem_ctx;
1579 while (isspace((unsigned char)*pszParmName)) {
1580 pszParmName++;
1583 name = strdup(pszParmName);
1584 if (!name) return false;
1586 strlower(name);
1588 if (service == NULL) {
1589 data = lp_ctx->globals->param_opt;
1590 mem_ctx = lp_ctx->globals;
1591 } else {
1592 data = service->param_opt;
1593 mem_ctx = service;
1596 /* Traverse destination */
1597 for (paramo=data; paramo; paramo=paramo->next) {
1598 /* If we already have the option set, override it unless
1599 it was a command line option and the new one isn't */
1600 if (strcmp(paramo->key, name) == 0) {
1601 if ((paramo->priority & FLAG_CMDLINE) &&
1602 !(flags & FLAG_CMDLINE)) {
1603 return true;
1606 talloc_free(paramo->value);
1607 paramo->value = talloc_strdup(paramo, pszParmValue);
1608 paramo->priority = flags;
1609 free(name);
1610 return true;
1614 paramo = talloc(mem_ctx, struct parmlist_entry);
1615 if (!paramo)
1616 smb_panic("OOM");
1617 paramo->key = talloc_strdup(paramo, name);
1618 paramo->value = talloc_strdup(paramo, pszParmValue);
1619 paramo->priority = flags;
1620 if (service == NULL) {
1621 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1622 } else {
1623 DLIST_ADD(service->param_opt, paramo);
1626 free(name);
1628 return true;
1631 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1632 const char *pszParmName, const char *pszParmValue,
1633 struct loadparm_context *lp_ctx)
1635 int i;
1636 /* if it is a special case then go ahead */
1637 if (parm_table[parmnum].special) {
1638 parm_table[parmnum].special(lp_ctx, pszParmValue,
1639 (char **)parm_ptr);
1640 return true;
1643 /* now switch on the type of variable it is */
1644 switch (parm_table[parmnum].type)
1646 case P_BOOL: {
1647 bool b;
1648 if (!set_boolean(pszParmValue, &b)) {
1649 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1650 return false;
1652 *(int *)parm_ptr = b;
1654 break;
1656 case P_INTEGER:
1657 *(int *)parm_ptr = atoi(pszParmValue);
1658 break;
1660 case P_OCTAL:
1661 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1662 break;
1664 case P_BYTES:
1666 uint64_t val;
1667 if (conv_str_size(pszParmValue, &val)) {
1668 if (val <= INT_MAX) {
1669 *(int *)parm_ptr = (int)val;
1670 break;
1674 DEBUG(0,("lp_do_parameter(%s): value is not "
1675 "a valid size specifier!\n", pszParmValue));
1676 return false;
1679 case P_LIST:
1680 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1681 pszParmValue, NULL);
1682 break;
1684 case P_STRING:
1685 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1686 break;
1688 case P_USTRING:
1689 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1690 strupper(*(char **)parm_ptr);
1691 break;
1693 case P_ENUM:
1694 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1695 if (strequal
1696 (pszParmValue,
1697 parm_table[parmnum].enum_list[i].name)) {
1698 *(int *)parm_ptr =
1699 parm_table[parmnum].
1700 enum_list[i].value;
1701 break;
1704 if (!parm_table[parmnum].enum_list[i].name) {
1705 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1706 pszParmValue, pszParmName));
1707 return false;
1709 break;
1712 if (lp_ctx->flags[parmnum] & FLAG_DEFAULT) {
1713 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1714 /* we have to also unset FLAG_DEFAULT on aliases */
1715 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1716 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1718 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1719 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1722 return true;
1726 bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
1727 const char *pszParmName, const char *pszParmValue)
1729 int parmnum = map_parameter(pszParmName);
1730 void *parm_ptr;
1732 if (parmnum < 0) {
1733 if (strchr(pszParmName, ':')) {
1734 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1736 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1737 return true;
1740 /* if the flag has been set on the command line, then don't allow override,
1741 but don't report an error */
1742 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1743 return true;
1746 parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1748 return set_variable(lp_ctx, parmnum, parm_ptr,
1749 pszParmName, pszParmValue, lp_ctx);
1752 bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
1753 struct loadparm_service *service,
1754 const char *pszParmName, const char *pszParmValue)
1756 void *parm_ptr;
1757 int i;
1758 int parmnum = map_parameter(pszParmName);
1760 if (parmnum < 0) {
1761 if (strchr(pszParmName, ':')) {
1762 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1764 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1765 return true;
1768 /* if the flag has been set on the command line, then don't allow override,
1769 but don't report an error */
1770 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1771 return true;
1774 if (parm_table[parmnum].pclass == P_GLOBAL) {
1775 DEBUG(0,
1776 ("Global parameter %s found in service section!\n",
1777 pszParmName));
1778 return true;
1780 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1782 if (!service->copymap)
1783 init_copymap(service);
1785 /* this handles the aliases - set the copymap for other
1786 * entries with the same data pointer */
1787 for (i = 0; parm_table[i].label; i++)
1788 if (parm_table[i].offset == parm_table[parmnum].offset &&
1789 parm_table[i].pclass == parm_table[parmnum].pclass)
1790 service->copymap[i] = false;
1792 return set_variable(service, parmnum, parm_ptr, pszParmName,
1793 pszParmValue, lp_ctx);
1797 * Process a parameter.
1800 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1801 void *userdata)
1803 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1805 if (lp_ctx->bInGlobalSection)
1806 return lp_do_global_parameter(lp_ctx, pszParmName,
1807 pszParmValue);
1808 else
1809 return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
1810 pszParmName, pszParmValue);
1814 variable argument do parameter
1816 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1817 bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
1818 const char *pszParmName, const char *fmt, ...)
1820 char *s;
1821 bool ret;
1822 va_list ap;
1824 va_start(ap, fmt);
1825 s = talloc_vasprintf(NULL, fmt, ap);
1826 va_end(ap);
1827 ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
1828 talloc_free(s);
1829 return ret;
1834 set a parameter from the commandline - this is called from command line parameter
1835 parsing code. It sets the parameter then marks the parameter as unable to be modified
1836 by smb.conf processing
1838 bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1839 const char *pszParmValue)
1841 int parmnum = map_parameter(pszParmName);
1842 int i;
1844 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1847 if (parmnum < 0 && strchr(pszParmName, ':')) {
1848 /* set a parametric option */
1849 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1850 pszParmValue, FLAG_CMDLINE);
1853 if (parmnum < 0) {
1854 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1855 return false;
1858 /* reset the CMDLINE flag in case this has been called before */
1859 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1861 if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1862 return false;
1865 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1867 /* we have to also set FLAG_CMDLINE on aliases */
1868 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1869 lp_ctx->flags[i] |= FLAG_CMDLINE;
1871 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1872 lp_ctx->flags[i] |= FLAG_CMDLINE;
1875 return true;
1879 set a option from the commandline in 'a=b' format. Use to support --option
1881 bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
1883 char *p, *s;
1884 bool ret;
1886 s = strdup(option);
1887 if (!s) {
1888 return false;
1891 p = strchr(s, '=');
1892 if (!p) {
1893 free(s);
1894 return false;
1897 *p = 0;
1899 ret = lp_set_cmdline(lp_ctx, s, p+1);
1900 free(s);
1901 return ret;
1905 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1908 * Print a parameter of the specified type.
1911 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1913 int i;
1914 switch (p->type)
1916 case P_ENUM:
1917 for (i = 0; p->enum_list[i].name; i++) {
1918 if (*(int *)ptr == p->enum_list[i].value) {
1919 fprintf(f, "%s",
1920 p->enum_list[i].name);
1921 break;
1924 break;
1926 case P_BOOL:
1927 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
1928 break;
1930 case P_INTEGER:
1931 case P_BYTES:
1932 fprintf(f, "%d", *(int *)ptr);
1933 break;
1935 case P_OCTAL:
1936 fprintf(f, "0%o", *(int *)ptr);
1937 break;
1939 case P_LIST:
1940 if ((char ***)ptr && *(char ***)ptr) {
1941 char **list = *(char ***)ptr;
1943 for (; *list; list++)
1944 fprintf(f, "%s%s", *list,
1945 ((*(list+1))?", ":""));
1947 break;
1949 case P_STRING:
1950 case P_USTRING:
1951 if (*(char **)ptr) {
1952 fprintf(f, "%s", *(char **)ptr);
1954 break;
1959 * Check if two parameters are equal.
1962 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1964 switch (type) {
1965 case P_BOOL:
1966 return (*((int *)ptr1) == *((int *)ptr2));
1968 case P_INTEGER:
1969 case P_OCTAL:
1970 case P_BYTES:
1971 case P_ENUM:
1972 return (*((int *)ptr1) == *((int *)ptr2));
1974 case P_LIST:
1975 return str_list_equal((const char **)(*(char ***)ptr1),
1976 (const char **)(*(char ***)ptr2));
1978 case P_STRING:
1979 case P_USTRING:
1981 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1982 if (p1 && !*p1)
1983 p1 = NULL;
1984 if (p2 && !*p2)
1985 p2 = NULL;
1986 return (p1 == p2 || strequal(p1, p2));
1989 return false;
1993 * Process a new section (service).
1995 * At this stage all sections are services.
1996 * Later we'll have special sections that permit server parameters to be set.
1997 * Returns True on success, False on failure.
2000 static bool do_section(const char *pszSectionName, void *userdata)
2002 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2003 bool bRetval;
2004 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2005 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2006 bRetval = false;
2008 /* if we've just struck a global section, note the fact. */
2009 lp_ctx->bInGlobalSection = isglobal;
2011 /* check for multiple global sections */
2012 if (lp_ctx->bInGlobalSection) {
2013 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
2014 return true;
2017 /* if we have a current service, tidy it up before moving on */
2018 bRetval = true;
2020 if (lp_ctx->currentService != NULL)
2021 bRetval = service_ok(lp_ctx->currentService);
2023 /* if all is still well, move to the next record in the services array */
2024 if (bRetval) {
2025 /* We put this here to avoid an odd message order if messages are */
2026 /* issued by the post-processing of a previous section. */
2027 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2029 if ((lp_ctx->currentService = lp_add_service(lp_ctx, lp_ctx->sDefault,
2030 pszSectionName))
2031 == NULL) {
2032 DEBUG(0, ("Failed to add a new service\n"));
2033 return false;
2037 return bRetval;
2042 * Determine if a particular base parameter is currently set to the default value.
2045 static bool is_default(struct loadparm_service *sDefault, int i)
2047 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2048 if (!defaults_saved)
2049 return false;
2050 switch (parm_table[i].type) {
2051 case P_LIST:
2052 return str_list_equal((const char **)parm_table[i].def.lvalue,
2053 (const char **)def_ptr);
2054 case P_STRING:
2055 case P_USTRING:
2056 return strequal(parm_table[i].def.svalue,
2057 *(char **)def_ptr);
2058 case P_BOOL:
2059 return parm_table[i].def.bvalue ==
2060 *(int *)def_ptr;
2061 case P_INTEGER:
2062 case P_OCTAL:
2063 case P_BYTES:
2064 case P_ENUM:
2065 return parm_table[i].def.ivalue ==
2066 *(int *)def_ptr;
2068 return false;
2072 *Display the contents of the global structure.
2075 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2076 bool show_defaults)
2078 int i;
2079 struct parmlist_entry *data;
2081 fprintf(f, "# Global parameters\n[global]\n");
2083 for (i = 0; parm_table[i].label; i++)
2084 if (parm_table[i].pclass == P_GLOBAL &&
2085 parm_table[i].offset != -1 &&
2086 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2087 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2088 continue;
2089 fprintf(f, "\t%s = ", parm_table[i].label);
2090 print_parameter(&parm_table[i], lp_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2091 fprintf(f, "\n");
2093 if (lp_ctx->globals->param_opt != NULL) {
2094 for (data = lp_ctx->globals->param_opt; data;
2095 data = data->next) {
2096 fprintf(f, "\t%s = %s\n", data->key, data->value);
2103 * Display the contents of a single services record.
2106 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f)
2108 int i;
2109 struct parmlist_entry *data;
2111 if (pService != sDefault)
2112 fprintf(f, "\n[%s]\n", pService->szService);
2114 for (i = 0; parm_table[i].label; i++) {
2115 if (parm_table[i].pclass == P_LOCAL &&
2116 parm_table[i].offset != -1 &&
2117 (*parm_table[i].label != '-') &&
2118 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
2120 if (pService == sDefault) {
2121 if (defaults_saved && is_default(sDefault, i))
2122 continue;
2123 } else {
2124 if (equal_parameter(parm_table[i].type,
2125 ((char *)pService) +
2126 parm_table[i].offset,
2127 ((char *)sDefault) +
2128 parm_table[i].offset))
2129 continue;
2132 fprintf(f, "\t%s = ", parm_table[i].label);
2133 print_parameter(&parm_table[i],
2134 ((char *)pService) + parm_table[i].offset, f);
2135 fprintf(f, "\n");
2138 if (pService->param_opt != NULL) {
2139 for (data = pService->param_opt; data; data = data->next) {
2140 fprintf(f, "\t%s = %s\n", data->key, data->value);
2145 bool lp_dump_a_parameter(struct loadparm_context *lp_ctx,
2146 struct loadparm_service *service,
2147 const char *parm_name, FILE * f)
2149 struct parm_struct *parm;
2150 void *ptr;
2152 parm = lp_parm_struct(parm_name);
2153 if (!parm) {
2154 return false;
2157 ptr = lp_parm_ptr(lp_ctx, service,parm);
2159 print_parameter(parm, ptr, f);
2160 fprintf(f, "\n");
2161 return true;
2165 * Return info about the next parameter in a service.
2166 * snum==-1 gives the globals.
2167 * Return NULL when out of parameters.
2170 struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
2171 int allparameters)
2173 if (snum == -1) {
2174 /* do the globals */
2175 for (; parm_table[*i].label; (*i)++) {
2176 if (parm_table[*i].offset == -1
2177 || (*parm_table[*i].label == '-'))
2178 continue;
2180 if ((*i) > 0
2181 && (parm_table[*i].offset ==
2182 parm_table[(*i) - 1].offset))
2183 continue;
2185 return &parm_table[(*i)++];
2187 } else {
2188 struct loadparm_service *pService = lp_ctx->services[snum];
2190 for (; parm_table[*i].label; (*i)++) {
2191 if (parm_table[*i].pclass == P_LOCAL &&
2192 parm_table[*i].offset != -1 &&
2193 (*parm_table[*i].label != '-') &&
2194 ((*i) == 0 ||
2195 (parm_table[*i].offset !=
2196 parm_table[(*i) - 1].offset)))
2198 if (allparameters ||
2199 !equal_parameter(parm_table[*i].type,
2200 ((char *)pService) +
2201 parm_table[*i].offset,
2202 ((char *)lp_ctx->sDefault) +
2203 parm_table[*i].offset))
2205 return &parm_table[(*i)++];
2211 return NULL;
2216 * Auto-load some home services.
2218 static void lp_add_auto_services(struct loadparm_context *lp_ctx,
2219 const char *str)
2221 return;
2226 * Unload unused services.
2229 void lp_killunused(struct loadparm_context *lp_ctx,
2230 struct smbsrv_connection *smb,
2231 bool (*snumused) (struct smbsrv_connection *, int))
2233 int i;
2234 for (i = 0; i < lp_ctx->iNumServices; i++) {
2235 if (lp_ctx->services[i] == NULL)
2236 continue;
2238 if (!snumused || !snumused(smb, i)) {
2239 talloc_free(lp_ctx->services[i]);
2240 lp_ctx->services[i] = NULL;
2246 static int lp_destructor(struct loadparm_context *lp_ctx)
2248 struct parmlist_entry *data;
2250 if (lp_ctx->globals->param_opt != NULL) {
2251 struct parmlist_entry *next;
2252 for (data = lp_ctx->globals->param_opt; data; data=next) {
2253 next = data->next;
2254 if (data->priority & FLAG_CMDLINE) continue;
2255 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2256 talloc_free(data);
2260 return 0;
2264 * Initialise the global parameter structure.
2266 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2268 int i;
2269 char *myname;
2270 struct loadparm_context *lp_ctx;
2272 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2273 if (lp_ctx == NULL)
2274 return NULL;
2276 talloc_set_destructor(lp_ctx, lp_destructor);
2277 lp_ctx->bInGlobalSection = true;
2278 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2279 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2281 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2282 lp_ctx->sDefault->bAvailable = true;
2283 lp_ctx->sDefault->bBrowseable = true;
2284 lp_ctx->sDefault->bRead_only = true;
2285 lp_ctx->sDefault->bMap_archive = true;
2286 lp_ctx->sDefault->bStrictLocking = true;
2287 lp_ctx->sDefault->bOplocks = true;
2288 lp_ctx->sDefault->iCreate_mask = 0744;
2289 lp_ctx->sDefault->iCreate_force_mode = 0000;
2290 lp_ctx->sDefault->iDir_mask = 0755;
2291 lp_ctx->sDefault->iDir_force_mode = 0000;
2293 DEBUG(3, ("Initialising global parameters\n"));
2295 for (i = 0; parm_table[i].label; i++) {
2296 if ((parm_table[i].type == P_STRING ||
2297 parm_table[i].type == P_USTRING) &&
2298 parm_table[i].offset != -1 &&
2299 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2300 char **r;
2301 if (parm_table[i].pclass == P_LOCAL) {
2302 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2303 } else {
2304 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2306 *r = talloc_strdup(lp_ctx, "");
2310 lp_do_global_parameter(lp_ctx, "share backend", "classic");
2312 lp_do_global_parameter(lp_ctx, "server role", "standalone");
2314 /* options that can be set on the command line must be initialised via
2315 the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2316 #ifdef TCP_NODELAY
2317 lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2318 #endif
2319 lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2320 myname = get_myname(lp_ctx);
2321 lp_do_global_parameter(lp_ctx, "netbios name", myname);
2322 talloc_free(myname);
2323 lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2325 lp_do_global_parameter(lp_ctx, "fstype", "NTFS");
2327 lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2328 lp_do_global_parameter(lp_ctx, "max connections", "-1");
2330 lp_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser");
2331 lp_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc");
2332 lp_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
2333 lp_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain");
2334 lp_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
2335 lp_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
2336 lp_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2337 lp_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
2338 lp_do_global_parameter(lp_ctx, "idmap database", "idmap.ldb");
2339 lp_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
2340 lp_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
2341 lp_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
2342 lp_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
2343 lp_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2345 /* This hive should be dynamically generated by Samba using
2346 data from the sam, but for the moment leave it in a tdb to
2347 keep regedt32 from popping up an annoying dialog. */
2348 lp_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2350 /* using UTF8 by default allows us to support all chars */
2351 lp_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2353 /* Use codepage 850 as a default for the dos character set */
2354 lp_do_global_parameter(lp_ctx, "dos charset", "CP850");
2357 * Allow the default PASSWD_CHAT to be overridden in local.h.
2359 lp_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2361 lp_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2362 lp_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2363 lp_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
2364 lp_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2366 lp_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
2367 lp_do_global_parameter_var(lp_ctx, "server string",
2368 "Samba %s", SAMBA_VERSION_STRING);
2370 lp_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
2371 DEFAULT_MAJOR_VERSION,
2372 DEFAULT_MINOR_VERSION);
2374 lp_do_global_parameter(lp_ctx, "password server", "*");
2376 lp_do_global_parameter(lp_ctx, "max mux", "50");
2377 lp_do_global_parameter(lp_ctx, "max xmit", "12288");
2378 lp_do_global_parameter(lp_ctx, "password level", "0");
2379 lp_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2380 lp_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2381 lp_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2382 lp_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2383 lp_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2384 lp_do_global_parameter(lp_ctx, "security", "USER");
2385 lp_do_global_parameter(lp_ctx, "paranoid server security", "True");
2386 lp_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2387 lp_do_global_parameter(lp_ctx, "ReadRaw", "True");
2388 lp_do_global_parameter(lp_ctx, "WriteRaw", "True");
2389 lp_do_global_parameter(lp_ctx, "NullPasswords", "False");
2390 lp_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2391 lp_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
2393 lp_do_global_parameter(lp_ctx, "TimeServer", "False");
2394 lp_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2395 lp_do_global_parameter(lp_ctx, "Unicode", "True");
2396 lp_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2397 lp_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2398 lp_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2399 lp_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2401 lp_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2403 lp_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2404 lp_do_global_parameter(lp_ctx, "LocalMaster", "True");
2406 lp_do_global_parameter(lp_ctx, "wins support", "False");
2407 lp_do_global_parameter(lp_ctx, "dns proxy", "True");
2409 lp_do_global_parameter(lp_ctx, "winbind separator", "\\");
2410 lp_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2411 lp_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2412 lp_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2413 lp_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2414 lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2415 lp_do_global_parameter(lp_ctx, "idmap trusted only", "False");
2417 lp_do_global_parameter(lp_ctx, "client signing", "Yes");
2418 lp_do_global_parameter(lp_ctx, "server signing", "auto");
2420 lp_do_global_parameter(lp_ctx, "use spnego", "True");
2422 lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
2423 lp_do_global_parameter(lp_ctx, "nbt port", "137");
2424 lp_do_global_parameter(lp_ctx, "dgram port", "138");
2425 lp_do_global_parameter(lp_ctx, "cldap port", "389");
2426 lp_do_global_parameter(lp_ctx, "krb5 port", "88");
2427 lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
2428 lp_do_global_parameter(lp_ctx, "web port", "901");
2429 lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
2431 lp_do_global_parameter(lp_ctx, "nt status support", "True");
2433 lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2434 lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
2436 lp_do_global_parameter(lp_ctx, "tls enabled", "True");
2437 lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2438 lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2439 lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2440 lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
2441 dyn_SETUPDIR);
2443 lp_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2445 lp_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2447 for (i = 0; parm_table[i].label; i++) {
2448 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2449 lp_ctx->flags[i] |= FLAG_DEFAULT;
2453 return lp_ctx;
2456 const char *lp_configfile(struct loadparm_context *lp_ctx)
2458 return lp_ctx->szConfigFile;
2461 const char *lp_default_path(void)
2463 if (getenv("SMB_CONF_PATH"))
2464 return getenv("SMB_CONF_PATH");
2465 else
2466 return dyn_CONFIGFILE;
2470 * Update the internal state of a loadparm context after settings
2471 * have changed.
2473 static bool lp_update(struct loadparm_context *lp_ctx)
2475 lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
2477 lp_add_hidden(lp_ctx, "IPC$", "IPC");
2478 lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
2480 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2481 lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2484 panic_action = lp_ctx->globals->panic_action;
2486 reload_charcnv(lp_ctx);
2488 /* FIXME: ntstatus_check_dos_mapping = lp_nt_status_support(lp_ctx); */
2490 /* FIXME: This is a bit of a hack, but we can't use a global, since
2491 * not everything that uses lp also uses the socket library */
2492 if (lp_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2493 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2494 } else {
2495 unsetenv("SOCKET_TESTNONBLOCK");
2498 /* FIXME: Check locale in environment for this: */
2499 if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0)
2500 d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)));
2501 else
2502 d_set_iconv((smb_iconv_t)-1);
2504 return true;
2507 bool lp_load_default(struct loadparm_context *lp_ctx)
2509 const char *path;
2511 path = lp_default_path();
2513 if (!file_exist(path)) {
2514 /* We allow the default smb.conf file to not exist,
2515 * basically the equivalent of an empty file. */
2516 return lp_update(lp_ctx);
2519 return lp_load(lp_ctx, path);
2523 * Load the services array from the services file.
2525 * Return True on success, False on failure.
2527 bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
2529 char *n2;
2530 bool bRetval;
2532 filename = talloc_strdup(lp_ctx, filename);
2534 lp_ctx->szConfigFile = filename;
2536 lp_ctx->bInGlobalSection = true;
2537 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2538 DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
2540 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2542 /* We get sections first, so have to start 'behind' to make up */
2543 lp_ctx->currentService = NULL;
2544 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2546 /* finish up the last section */
2547 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2548 if (bRetval)
2549 if (lp_ctx->currentService != NULL)
2550 bRetval = service_ok(lp_ctx->currentService);
2552 bRetval = bRetval && lp_update(lp_ctx);
2554 return bRetval;
2558 * Return the max number of services.
2561 int lp_numservices(struct loadparm_context *lp_ctx)
2563 return lp_ctx->iNumServices;
2567 * Display the contents of the services array in human-readable form.
2570 void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2571 int maxtoprint)
2573 int iService;
2575 if (show_defaults)
2576 defaults_saved = false;
2578 dump_globals(lp_ctx, f, show_defaults);
2580 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f);
2582 for (iService = 0; iService < maxtoprint; iService++)
2583 lp_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2587 * Display the contents of one service in human-readable form.
2589 void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2591 if (service != NULL) {
2592 if (service->szService[0] == '\0')
2593 return;
2594 dump_a_service(service, sDefault, f);
2598 struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
2599 int snum)
2601 return lp_ctx->services[snum];
2604 struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
2605 const char *service_name)
2607 int iService;
2608 char *serviceName;
2610 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2611 if (lp_ctx->services[iService] &&
2612 lp_ctx->services[iService]->szService) {
2614 * The substitution here is used to support %U is
2615 * service names
2617 serviceName = standard_sub_basic(
2618 lp_ctx->services[iService],
2619 lp_ctx->services[iService]->szService);
2620 if (strequal(serviceName, service_name)) {
2621 talloc_free(serviceName);
2622 return lp_ctx->services[iService];
2624 talloc_free(serviceName);
2628 DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
2629 return NULL;
2634 * A useful volume label function.
2636 const char *volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2638 const char *ret = lp_volume(service, sDefault);
2639 if (!*ret)
2640 return lp_servicename(service);
2641 return ret;
2646 * If we are PDC then prefer us as DMB
2648 const char *lp_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2650 const char *ret = _lp_printername(service, sDefault);
2651 if (ret == NULL || (ret != NULL && *ret == '\0'))
2652 ret = lp_servicename(service);
2654 return ret;
2659 * Return the max print jobs per queue.
2661 int lp_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2663 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2664 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2665 maxjobs = PRINT_MAX_JOBID - 1;
2667 return maxjobs;
2670 struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx)
2672 if (lp_ctx == NULL) {
2673 static struct smb_iconv_convenience *fallback_ic = NULL;
2674 if (fallback_ic == NULL)
2675 fallback_ic = smb_iconv_convenience_init(talloc_autofree_context(),
2676 "CP850", "UTF8", true);
2677 return fallback_ic;
2679 return lp_ctx->iconv_convenience;
2682 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2684 talloc_unlink(lp_ctx, lp_ctx->iconv_convenience);
2685 global_iconv_convenience = lp_ctx->iconv_convenience = smb_iconv_convenience_init_lp(lp_ctx, lp_ctx);
2688 void lp_smbcli_options(struct loadparm_context *lp_ctx,
2689 struct smbcli_options *options)
2691 options->max_xmit = lp_max_xmit(lp_ctx);
2692 options->max_mux = lp_maxmux(lp_ctx);
2693 options->use_spnego = lp_nt_status_support(lp_ctx) && lp_use_spnego(lp_ctx);
2694 options->signing = lp_client_signing(lp_ctx);
2695 options->request_timeout = SMB_REQUEST_TIMEOUT;
2696 options->ntstatus_support = lp_nt_status_support(lp_ctx);
2697 options->max_protocol = lp_cli_maxprotocol(lp_ctx);
2698 options->unicode = lp_unicode(lp_ctx);
2699 options->use_oplocks = true;
2700 options->use_level2_oplocks = true;
2703 void lp_smbcli_session_options(struct loadparm_context *lp_ctx,
2704 struct smbcli_session_options *options)
2706 options->lanman_auth = lp_client_lanman_auth(lp_ctx);
2707 options->ntlmv2_auth = lp_client_ntlmv2_auth(lp_ctx);
2708 options->plaintext_auth = lp_client_plaintext_auth(lp_ctx);
2711 _PUBLIC_ char *lp_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2713 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
2716 _PUBLIC_ char *lp_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2718 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
2721 _PUBLIC_ char *lp_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2723 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
2726 _PUBLIC_ char *lp_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2728 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
2731 _PUBLIC_ char *lp_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2733 return private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
2736 _PUBLIC_ struct dcerpc_server_info *lp_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2738 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
2740 ret->domain_name = talloc_reference(mem_ctx, lp_workgroup(lp_ctx));
2741 ret->version_major = lp_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
2742 ret->version_minor = lp_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
2743 ret->version_build = lp_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
2745 return ret;
2748 struct gensec_settings *lp_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2750 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
2751 if (settings == NULL)
2752 return NULL;
2753 SMB_ASSERT(lp_ctx != NULL);
2754 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2755 settings->iconv_convenience = lp_iconv_convenience(lp_ctx);
2756 settings->target_hostname = lp_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2757 return settings;