source3/loadparm: make struct loadparm_service a talloc object.
[Samba.git] / source3 / param / loadparm.c
bloba4d5bfc55181e7cc5e75bf65d00f81ceceaa241a
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) Michael Adam 2008
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * Load parameters.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
37 * To add a parameter:
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
46 * Notes:
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
52 * careful!
56 #include "includes.h"
57 #include "system/filesys.h"
58 #include "util_tdb.h"
59 #include "lib/param/loadparm.h"
60 #include "printing.h"
61 #include "lib/smbconf/smbconf.h"
62 #include "lib/smbconf/smbconf_init.h"
64 #include "ads.h"
65 #include "../librpc/gen_ndr/svcctl.h"
66 #include "intl.h"
67 #include "../libcli/smb/smb_signing.h"
68 #include "dbwrap/dbwrap.h"
69 #include "dbwrap/dbwrap_rbt.h"
70 #include "../lib/util/bitmap.h"
72 #ifdef HAVE_SYS_SYSCTL_H
73 #include <sys/sysctl.h>
74 #endif
76 #ifdef HAVE_HTTPCONNECTENCRYPT
77 #include <cups/http.h>
78 #endif
80 #ifdef CLUSTER_SUPPORT
81 #include "ctdb_private.h"
82 #endif
84 bool bLoaded = false;
86 extern userdom_struct current_user_info;
88 /* the special value for the include parameter
89 * to be interpreted not as a file name but to
90 * trigger loading of the global smb.conf options
91 * from registry. */
92 #ifndef INCLUDE_REGISTRY_NAME
93 #define INCLUDE_REGISTRY_NAME "registry"
94 #endif
96 static bool in_client = false; /* Not in the client by default */
97 static struct smbconf_csn conf_last_csn;
99 static int config_backend = CONFIG_BACKEND_FILE;
101 /* some helpful bits */
102 #define LP_SNUM_OK(i) (((i) >= 0) && ((i) < iNumServices) && (ServicePtrs != NULL) && ServicePtrs[(i)]->valid)
103 #define VALID(i) (ServicePtrs != NULL && ServicePtrs[i]->valid)
105 #define USERSHARE_VALID 1
106 #define USERSHARE_PENDING_DELETE 2
108 static bool defaults_saved = false;
110 #define LOADPARM_EXTRA_GLOBALS \
111 struct parmlist_entry *param_opt; \
112 char *szRealm; \
113 char *loglevel; \
114 int iminreceivefile; \
115 char *szPrintcapname; \
116 int CupsEncrypt; \
117 int iPreferredMaster; \
118 char *szLdapMachineSuffix; \
119 char *szLdapUserSuffix; \
120 char *szLdapIdmapSuffix; \
121 char *szLdapGroupSuffix; \
122 char *szStateDir; \
123 char *szCacheDir; \
124 char *szUsershareTemplateShare; \
125 char *szIdmapUID; \
126 char *szIdmapGID; \
127 int winbindMaxDomainConnections; \
128 int ismb2_max_credits; \
129 char *tls_keyfile; \
130 char *tls_certfile; \
131 char *tls_cafile; \
132 char *tls_crlfile; \
133 char *tls_dhpfile; \
134 char *panic_action; \
135 int bPreferredMaster;
137 #include "param/param_global.h"
139 static struct loadparm_global Globals;
141 /* This is a default service used to prime a services structure */
142 static struct loadparm_service sDefault =
144 .valid = true,
145 .autoloaded = false,
146 .usershare = 0,
147 .usershare_last_mod = {0, 0},
148 .szService = NULL,
149 .szPath = NULL,
150 .szUsername = NULL,
151 .szInvalidUsers = NULL,
152 .szValidUsers = NULL,
153 .szAdminUsers = NULL,
154 .szCopy = NULL,
155 .szInclude = NULL,
156 .szPreExec = NULL,
157 .szPostExec = NULL,
158 .szRootPreExec = NULL,
159 .szRootPostExec = NULL,
160 .szCupsOptions = NULL,
161 .szPrintcommand = NULL,
162 .szLpqcommand = NULL,
163 .szLprmcommand = NULL,
164 .szLppausecommand = NULL,
165 .szLpresumecommand = NULL,
166 .szQueuepausecommand = NULL,
167 .szQueueresumecommand = NULL,
168 .szPrintername = NULL,
169 .szPrintjobUsername = NULL,
170 .szDontdescend = NULL,
171 .szHostsallow = NULL,
172 .szHostsdeny = NULL,
173 .szMagicScript = NULL,
174 .szMagicOutput = NULL,
175 .szVetoFiles = NULL,
176 .szHideFiles = NULL,
177 .szVetoOplockFiles = NULL,
178 .comment = NULL,
179 .force_user = NULL,
180 .force_group = NULL,
181 .readlist = NULL,
182 .writelist = NULL,
183 .volume = NULL,
184 .fstype = NULL,
185 .szVfsObjects = NULL,
186 .szMSDfsProxy = NULL,
187 .szAioWriteBehind = NULL,
188 .szDfree = NULL,
189 .iMinPrintSpace = 0,
190 .iMaxPrintJobs = 1000,
191 .iMaxReportedPrintJobs = 0,
192 .iWriteCacheSize = 0,
193 .iCreate_mask = 0744,
194 .iCreate_force_mode = 0,
195 .iSecurity_mask = 0777,
196 .iSecurity_force_mode = 0,
197 .iDir_mask = 0755,
198 .iDir_force_mode = 0,
199 .iDir_Security_mask = 0777,
200 .iDir_Security_force_mode = 0,
201 .iMaxConnections = 0,
202 .iDefaultCase = CASE_LOWER,
203 .iPrinting = DEFAULT_PRINTING,
204 .iOplockContentionLimit = 2,
205 .iCSCPolicy = 0,
206 .iBlock_size = 1024,
207 .iDfreeCacheTime = 0,
208 .bPreexecClose = false,
209 .bRootpreexecClose = false,
210 .iCaseSensitive = Auto,
211 .bCasePreserve = true,
212 .bShortCasePreserve = true,
213 .bHideDotFiles = true,
214 .bHideSpecialFiles = false,
215 .bHideUnReadable = false,
216 .bHideUnWriteableFiles = false,
217 .bBrowseable = true,
218 .bAccessBasedShareEnum = false,
219 .bAvailable = true,
220 .bRead_only = true,
221 .bNo_set_dir = true,
222 .bGuest_only = false,
223 .bAdministrative_share = false,
224 .bGuest_ok = false,
225 .bPrint_ok = false,
226 .bPrintNotifyBackchannel = true,
227 .bMap_system = false,
228 .bMap_hidden = false,
229 .bMap_archive = true,
230 .bStoreDosAttributes = false,
231 .bDmapiSupport = false,
232 .bLocking = true,
233 .iStrictLocking = Auto,
234 .bPosixLocking = true,
235 .bShareModes = true,
236 .bOpLocks = true,
237 .bKernelOplocks = false,
238 .bLevel2OpLocks = true,
239 .bOnlyUser = false,
240 .bMangledNames = true,
241 .bWidelinks = false,
242 .bSymlinks = true,
243 .bSyncAlways = false,
244 .bStrictAllocate = false,
245 .bStrictSync = false,
246 .magic_char = '~',
247 .copymap = NULL,
248 .bDeleteReadonly = false,
249 .bFakeOplocks = false,
250 .bDeleteVetoFiles = false,
251 .bDosFilemode = false,
252 .bDosFiletimes = true,
253 .bDosFiletimeResolution = false,
254 .bFakeDirCreateTimes = false,
255 .bBlockingLocks = true,
256 .bInheritPerms = false,
257 .bInheritACLS = false,
258 .bInheritOwner = false,
259 .bMSDfsRoot = false,
260 .bUseClientDriver = false,
261 .bDefaultDevmode = true,
262 .bForcePrintername = false,
263 .bNTAclSupport = true,
264 .bForceUnknownAclUser = false,
265 .bUseSendfile = false,
266 .bProfileAcls = false,
267 .bMap_acl_inherit = false,
268 .bAfs_Share = false,
269 .bEASupport = false,
270 .bAclCheckPermissions = true,
271 .bAclMapFullControl = true,
272 .bAclGroupControl = false,
273 .bChangeNotify = true,
274 .bKernelChangeNotify = true,
275 .iallocation_roundup_size = SMB_ROUNDUP_ALLOCATION_SIZE,
276 .iAioReadSize = 0,
277 .iAioWriteSize = 0,
278 .iMap_readonly = MAP_READONLY_YES,
279 #ifdef BROKEN_DIRECTORY_HANDLING
280 .iDirectoryNameCacheSize = 0,
281 #else
282 .iDirectoryNameCacheSize = 100,
283 #endif
284 .ismb_encrypt = Auto,
285 .param_opt = NULL,
286 .dummy = ""
289 /* local variables */
290 static struct loadparm_service **ServicePtrs = NULL;
291 static int iNumServices = 0;
292 static int iServiceIndex = 0;
293 static struct db_context *ServiceHash;
294 static int *invalid_services = NULL;
295 static int num_invalid_services = 0;
296 static bool bInGlobalSection = true;
297 static bool bGlobalOnly = false;
299 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
301 /* prototypes for the special type handlers */
302 static bool handle_include(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
303 static bool handle_copy(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
304 static bool handle_idmap_backend(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
305 static bool handle_idmap_uid(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
306 static bool handle_idmap_gid(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
307 static bool handle_debug_list(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
308 static bool handle_realm(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
309 static bool handle_netbios_aliases(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
310 static bool handle_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
311 static bool handle_dos_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
312 static bool handle_printing(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
313 static bool handle_ldap_debug_level(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
315 /* these are parameter handlers which are not needed in the
316 * source3 code
319 #define handle_logfile NULL
321 static void set_allowed_client_auth(void);
323 static void add_to_file_list(const char *fname, const char *subfname);
324 static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmValue, bool store_values);
325 static void free_param_opts(struct parmlist_entry **popts);
327 #include "lib/param/param_table.c"
329 /***************************************************************************
330 Initialise the sDefault parameter structure for the printer values.
331 ***************************************************************************/
333 static void init_printer_values(struct loadparm_service *pService)
335 /* choose defaults depending on the type of printing */
336 switch (pService->iPrinting) {
337 case PRINT_BSD:
338 case PRINT_AIX:
339 case PRINT_LPRNT:
340 case PRINT_LPROS2:
341 string_set(&pService->szLpqcommand, "lpq -P'%p'");
342 string_set(&pService->szLprmcommand, "lprm -P'%p' %j");
343 string_set(&pService->szPrintcommand, "lpr -r -P'%p' %s");
344 break;
346 case PRINT_LPRNG:
347 case PRINT_PLP:
348 string_set(&pService->szLpqcommand, "lpq -P'%p'");
349 string_set(&pService->szLprmcommand, "lprm -P'%p' %j");
350 string_set(&pService->szPrintcommand, "lpr -r -P'%p' %s");
351 string_set(&pService->szQueuepausecommand, "lpc stop '%p'");
352 string_set(&pService->szQueueresumecommand, "lpc start '%p'");
353 string_set(&pService->szLppausecommand, "lpc hold '%p' %j");
354 string_set(&pService->szLpresumecommand, "lpc release '%p' %j");
355 break;
357 case PRINT_CUPS:
358 case PRINT_IPRINT:
359 #ifdef HAVE_CUPS
360 /* set the lpq command to contain the destination printer
361 name only. This is used by cups_queue_get() */
362 string_set(&pService->szLpqcommand, "%p");
363 string_set(&pService->szLprmcommand, "");
364 string_set(&pService->szPrintcommand, "");
365 string_set(&pService->szLppausecommand, "");
366 string_set(&pService->szLpresumecommand, "");
367 string_set(&pService->szQueuepausecommand, "");
368 string_set(&pService->szQueueresumecommand, "");
369 #else
370 string_set(&pService->szLpqcommand, "lpq -P'%p'");
371 string_set(&pService->szLprmcommand, "lprm -P'%p' %j");
372 string_set(&pService->szPrintcommand, "lpr -P'%p' %s; rm %s");
373 string_set(&pService->szLppausecommand, "lp -i '%p-%j' -H hold");
374 string_set(&pService->szLpresumecommand, "lp -i '%p-%j' -H resume");
375 string_set(&pService->szQueuepausecommand, "disable '%p'");
376 string_set(&pService->szQueueresumecommand, "enable '%p'");
377 #endif /* HAVE_CUPS */
378 break;
380 case PRINT_SYSV:
381 case PRINT_HPUX:
382 string_set(&pService->szLpqcommand, "lpstat -o%p");
383 string_set(&pService->szLprmcommand, "cancel %p-%j");
384 string_set(&pService->szPrintcommand, "lp -c -d%p %s; rm %s");
385 string_set(&pService->szQueuepausecommand, "disable %p");
386 string_set(&pService->szQueueresumecommand, "enable %p");
387 #ifndef HPUX
388 string_set(&pService->szLppausecommand, "lp -i %p-%j -H hold");
389 string_set(&pService->szLpresumecommand, "lp -i %p-%j -H resume");
390 #endif /* HPUX */
391 break;
393 case PRINT_QNX:
394 string_set(&pService->szLpqcommand, "lpq -P%p");
395 string_set(&pService->szLprmcommand, "lprm -P%p %j");
396 string_set(&pService->szPrintcommand, "lp -r -P%p %s");
397 break;
399 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST) || defined(ENABLE_BUILD_FARM_HACKS)
401 case PRINT_TEST:
402 case PRINT_VLP: {
403 const char *tdbfile;
404 TALLOC_CTX *tmp_ctx = talloc_stackframe();
405 char *tmp;
407 tdbfile = talloc_asprintf(
408 tmp_ctx, "tdbfile=%s",
409 lp_parm_const_string(-1, "vlp", "tdbfile",
410 "/tmp/vlp.tdb"));
411 if (tdbfile == NULL) {
412 tdbfile="tdbfile=/tmp/vlp.tdb";
415 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
416 tdbfile);
417 string_set(&pService->szPrintcommand,
418 tmp ? tmp : "vlp print %p %s");
420 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
421 tdbfile);
422 string_set(&pService->szLpqcommand,
423 tmp ? tmp : "vlp lpq %p");
425 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
426 tdbfile);
427 string_set(&pService->szLprmcommand,
428 tmp ? tmp : "vlp lprm %p %j");
430 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
431 tdbfile);
432 string_set(&pService->szLppausecommand,
433 tmp ? tmp : "vlp lppause %p %j");
435 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
436 tdbfile);
437 string_set(&pService->szLpresumecommand,
438 tmp ? tmp : "vlp lpresume %p %j");
440 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
441 tdbfile);
442 string_set(&pService->szQueuepausecommand,
443 tmp ? tmp : "vlp queuepause %p");
445 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
446 tdbfile);
447 string_set(&pService->szQueueresumecommand,
448 tmp ? tmp : "vlp queueresume %p");
449 TALLOC_FREE(tmp_ctx);
451 break;
453 #endif /* DEVELOPER */
458 * Function to return the default value for the maximum number of open
459 * file descriptors permitted. This function tries to consult the
460 * kernel-level (sysctl) and ulimit (getrlimit()) values and goes
461 * the smaller of those.
463 static int max_open_files(void)
465 int sysctl_max = MAX_OPEN_FILES;
466 int rlimit_max = MAX_OPEN_FILES;
468 #ifdef HAVE_SYSCTLBYNAME
470 size_t size = sizeof(sysctl_max);
471 sysctlbyname("kern.maxfilesperproc", &sysctl_max, &size, NULL,
474 #endif
476 #if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
478 struct rlimit rl;
480 ZERO_STRUCT(rl);
482 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
483 rlimit_max = rl.rlim_cur;
485 #if defined(RLIM_INFINITY)
486 if(rl.rlim_cur == RLIM_INFINITY)
487 rlimit_max = MAX_OPEN_FILES;
488 #endif
490 #endif
492 if (sysctl_max < MIN_OPEN_FILES_WINDOWS) {
493 DEBUG(2,("max_open_files: increasing sysctl_max (%d) to "
494 "minimum Windows limit (%d)\n",
495 sysctl_max,
496 MIN_OPEN_FILES_WINDOWS));
497 sysctl_max = MIN_OPEN_FILES_WINDOWS;
500 if (rlimit_max < MIN_OPEN_FILES_WINDOWS) {
501 DEBUG(2,("rlimit_max: increasing rlimit_max (%d) to "
502 "minimum Windows limit (%d)\n",
503 rlimit_max,
504 MIN_OPEN_FILES_WINDOWS));
505 rlimit_max = MIN_OPEN_FILES_WINDOWS;
508 return MIN(sysctl_max, rlimit_max);
512 * Common part of freeing allocated data for one parameter.
514 static void free_one_parameter_common(void *parm_ptr,
515 struct parm_struct parm)
517 if ((parm.type == P_STRING) ||
518 (parm.type == P_USTRING))
520 string_free((char**)parm_ptr);
521 } else if (parm.type == P_LIST) {
522 TALLOC_FREE(*((char***)parm_ptr));
527 * Free the allocated data for one parameter for a share
528 * given as a service struct.
530 static void free_one_parameter(struct loadparm_service *service,
531 struct parm_struct parm)
533 void *parm_ptr;
535 if (parm.p_class != P_LOCAL) {
536 return;
539 parm_ptr = lp_parm_ptr(service, &parm);
541 free_one_parameter_common(parm_ptr, parm);
545 * Free the allocated parameter data of a share given
546 * as a service struct.
548 static void free_parameters(struct loadparm_service *service)
550 uint32_t i;
552 for (i=0; parm_table[i].label; i++) {
553 free_one_parameter(service, parm_table[i]);
558 * Free the allocated data for one parameter for a given share
559 * specified by an snum.
561 static void free_one_parameter_by_snum(int snum, struct parm_struct parm)
563 void *parm_ptr;
565 if (snum < 0) {
566 parm_ptr = lp_parm_ptr(NULL, &parm);
567 } else if (parm.p_class != P_LOCAL) {
568 return;
569 } else {
570 parm_ptr = lp_local_ptr_by_snum(snum, &parm);
573 free_one_parameter_common(parm_ptr, parm);
577 * Free the allocated parameter data for a share specified
578 * by an snum.
580 static void free_parameters_by_snum(int snum)
582 uint32_t i;
584 for (i=0; parm_table[i].label; i++) {
585 free_one_parameter_by_snum(snum, parm_table[i]);
590 * Free the allocated global parameters.
592 static void free_global_parameters(void)
594 free_param_opts(&Globals.param_opt);
595 free_parameters_by_snum(GLOBAL_SECTION_SNUM);
596 TALLOC_FREE(Globals.ctx);
599 static int map_parameter(const char *pszParmName);
601 struct lp_stored_option {
602 struct lp_stored_option *prev, *next;
603 const char *label;
604 const char *value;
607 static struct lp_stored_option *stored_options;
610 save options set by lp_set_cmdline() into a list. This list is
611 re-applied when we do a globals reset, so that cmdline set options
612 are sticky across reloads of smb.conf
614 static bool store_lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
616 struct lp_stored_option *entry, *entry_next;
617 for (entry = stored_options; entry != NULL; entry = entry_next) {
618 entry_next = entry->next;
619 if (strcmp(pszParmName, entry->label) == 0) {
620 DLIST_REMOVE(stored_options, entry);
621 talloc_free(entry);
622 break;
626 entry = talloc(NULL, struct lp_stored_option);
627 if (!entry) {
628 return false;
631 entry->label = talloc_strdup(entry, pszParmName);
632 if (!entry->label) {
633 talloc_free(entry);
634 return false;
637 entry->value = talloc_strdup(entry, pszParmValue);
638 if (!entry->value) {
639 talloc_free(entry);
640 return false;
643 DLIST_ADD_END(stored_options, entry, struct lp_stored_option);
645 return true;
648 static bool apply_lp_set_cmdline(void)
650 struct lp_stored_option *entry = NULL;
651 for (entry = stored_options; entry != NULL; entry = entry->next) {
652 if (!lp_set_cmdline_helper(entry->label, entry->value, false)) {
653 DEBUG(0, ("Failed to re-apply cmdline parameter %s = %s\n",
654 entry->label, entry->value));
655 return false;
658 return true;
661 /***************************************************************************
662 Initialise the global parameter structure.
663 ***************************************************************************/
665 static void init_globals(bool reinit_globals)
667 static bool done_init = false;
668 char *s = NULL;
669 int i;
671 /* If requested to initialize only once and we've already done it... */
672 if (!reinit_globals && done_init) {
673 /* ... then we have nothing more to do */
674 return;
677 if (!done_init) {
678 /* The logfile can be set before this is invoked. Free it if so. */
679 if (Globals.logfile != NULL) {
680 string_free(&Globals.logfile);
681 Globals.logfile = NULL;
683 done_init = true;
684 } else {
685 free_global_parameters();
688 /* This memset and the free_global_parameters() above will
689 * wipe out smb.conf options set with lp_set_cmdline(). The
690 * apply_lp_set_cmdline() call puts these values back in the
691 * table once the defaults are set */
692 ZERO_STRUCT(Globals);
694 Globals.ctx = talloc_new(NULL);
696 for (i = 0; parm_table[i].label; i++) {
697 if ((parm_table[i].type == P_STRING ||
698 parm_table[i].type == P_USTRING))
700 string_set((char **)lp_parm_ptr(NULL, &parm_table[i]), "");
705 string_set(&sDefault.fstype, FSTYPE_STRING);
706 string_set(&sDefault.szPrintjobUsername, "%U");
708 init_printer_values(&sDefault);
711 DEBUG(3, ("Initialising global parameters\n"));
713 /* Must manually force to upper case here, as this does not go via the handler */
714 string_set(&Globals.szNetbiosName, myhostname_upper());
716 string_set(&Globals.szSMBPasswdFile, get_dyn_SMB_PASSWD_FILE());
717 string_set(&Globals.szPrivateDir, get_dyn_PRIVATE_DIR());
719 /* use the new 'hash2' method by default, with a prefix of 1 */
720 string_set(&Globals.szManglingMethod, "hash2");
721 Globals.mangle_prefix = 1;
723 string_set(&Globals.szGuestaccount, GUEST_ACCOUNT);
725 /* using UTF8 by default allows us to support all chars */
726 string_set(&Globals.unix_charset, DEFAULT_UNIX_CHARSET);
728 /* Use codepage 850 as a default for the dos character set */
729 string_set(&Globals.dos_charset, DEFAULT_DOS_CHARSET);
732 * Allow the default PASSWD_CHAT to be overridden in local.h.
734 string_set(&Globals.szPasswdChat, DEFAULT_PASSWD_CHAT);
736 string_set(&Globals.szWorkgroup, DEFAULT_WORKGROUP);
738 string_set(&Globals.szPasswdProgram, "");
739 string_set(&Globals.szLockDir, get_dyn_LOCKDIR());
740 string_set(&Globals.szStateDir, get_dyn_STATEDIR());
741 string_set(&Globals.szCacheDir, get_dyn_CACHEDIR());
742 string_set(&Globals.szPidDir, get_dyn_PIDDIR());
743 string_set(&Globals.nbt_client_socket_address, "0.0.0.0");
745 * By default support explicit binding to broadcast
746 * addresses.
748 Globals.bNmbdBindExplicitBroadcast = true;
750 if (asprintf(&s, "Samba %s", samba_version_string()) < 0) {
751 smb_panic("init_globals: ENOMEM");
753 string_set(&Globals.szServerString, s);
754 SAFE_FREE(s);
755 #ifdef DEVELOPER
756 string_set(&Globals.szPanicAction, "/bin/sleep 999999999");
757 #endif
759 string_set(&Globals.socket_options, DEFAULT_SOCKET_OPTIONS);
761 string_set(&Globals.szLogonDrive, "");
762 /* %N is the NIS auto.home server if -DAUTOHOME is used, else same as %L */
763 string_set(&Globals.szLogonHome, "\\\\%N\\%U");
764 string_set(&Globals.szLogonPath, "\\\\%N\\%U\\profile");
766 Globals.szNameResolveOrder = (const char **)str_list_make_v3(NULL, "lmhosts wins host bcast", NULL);
767 string_set(&Globals.szPasswordServer, "*");
769 Globals.AlgorithmicRidBase = BASE_RID;
771 Globals.bLoadPrinters = true;
772 Globals.PrintcapCacheTime = 750; /* 12.5 minutes */
774 Globals.ConfigBackend = config_backend;
775 Globals.server_role = ROLE_AUTO;
777 /* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
778 /* Discovered by 2 days of pain by Don McCall @ HP :-). */
779 Globals.max_xmit = 0x4104;
780 Globals.max_mux = 50; /* This is *needed* for profile support. */
781 Globals.lpqcachetime = 30; /* changed to handle large print servers better -- jerry */
782 Globals.bDisableSpoolss = false;
783 Globals.iMaxSmbdProcesses = 0;/* no limit specified */
784 Globals.pwordlevel = 0;
785 Globals.unamelevel = 0;
786 Globals.deadtime = 0;
787 Globals.getwd_cache = true;
788 Globals.bLargeReadwrite = true;
789 Globals.max_log_size = 5000;
790 Globals.max_open_files = max_open_files();
791 Globals.open_files_db_hash_size = SMB_OPEN_DATABASE_TDB_HASH_SIZE;
792 Globals.srv_maxprotocol = PROTOCOL_SMB2_10;
793 Globals.srv_minprotocol = PROTOCOL_LANMAN1;
794 Globals.security = SEC_USER;
795 Globals.bEncryptPasswords = true;
796 Globals.clientSchannel = Auto;
797 Globals.serverSchannel = Auto;
798 Globals.bReadRaw = true;
799 Globals.bWriteRaw = true;
800 Globals.bNullPasswords = false;
801 Globals.bObeyPamRestrictions = false;
802 Globals.syslog = 1;
803 Globals.bSyslogOnly = false;
804 Globals.bTimestampLogs = true;
805 string_set(&Globals.loglevel, "0");
806 Globals.bDebugPrefixTimestamp = false;
807 Globals.bDebugHiresTimestamp = true;
808 Globals.bDebugPid = false;
809 Globals.bDebugUid = false;
810 Globals.bDebugClass = false;
811 Globals.bEnableCoreFiles = true;
812 Globals.max_ttl = 60 * 60 * 24 * 3; /* 3 days default. */
813 Globals.max_wins_ttl = 60 * 60 * 24 * 6; /* 6 days default. */
814 Globals.min_wins_ttl = 60 * 60 * 6; /* 6 hours default. */
815 Globals.machine_password_timeout = 60 * 60 * 24 * 7; /* 7 days default. */
816 Globals.lm_announce = Auto; /* = Auto: send only if LM clients found */
817 Globals.lm_interval = 60;
818 #if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT))
819 Globals.bNISHomeMap = false;
820 #ifdef WITH_NISPLUS_HOME
821 string_set(&Globals.szNISHomeMapName, "auto_home.org_dir");
822 #else
823 string_set(&Globals.szNISHomeMapName, "auto.home");
824 #endif
825 #endif
826 Globals.bTimeServer = false;
827 Globals.bBindInterfacesOnly = false;
828 Globals.bUnixPasswdSync = false;
829 Globals.bPamPasswordChange = false;
830 Globals.bPasswdChatDebug = false;
831 Globals.iPasswdChatTimeout = 2; /* 2 second default. */
832 Globals.bNTPipeSupport = true; /* Do NT pipes by default. */
833 Globals.bNTStatusSupport = true; /* Use NT status by default. */
834 Globals.bStatCache = true; /* use stat cache by default */
835 Globals.iMaxStatCacheSize = 256; /* 256k by default */
836 Globals.restrict_anonymous = 0;
837 Globals.bClientLanManAuth = false; /* Do NOT use the LanMan hash if it is available */
838 Globals.bClientPlaintextAuth = false; /* Do NOT use a plaintext password even if is requested by the server */
839 Globals.bLanmanAuth = false; /* Do NOT use the LanMan hash, even if it is supplied */
840 Globals.bNTLMAuth = true; /* Do use NTLMv1 if it is supplied by the client (otherwise NTLMv2) */
841 Globals.bClientNTLMv2Auth = true; /* Client should always use use NTLMv2, as we can't tell that the server supports it, but most modern servers do */
842 /* Note, that we will also use NTLM2 session security (which is different), if it is available */
844 Globals.map_to_guest = 0; /* By Default, "Never" */
845 Globals.oplock_break_wait_time = 0; /* By Default, 0 msecs. */
846 Globals.enhanced_browsing = true;
847 Globals.iLockSpinTime = WINDOWS_MINIMUM_LOCK_TIMEOUT_MS; /* msec. */
848 #ifdef MMAP_BLACKLIST
849 Globals.bUseMmap = false;
850 #else
851 Globals.bUseMmap = true;
852 #endif
853 Globals.bUnicode = true;
854 Globals.bUnixExtensions = true;
855 Globals.bResetOnZeroVC = false;
856 Globals.bLogWriteableFilesOnExit = false;
857 Globals.bCreateKrb5Conf = true;
858 Globals.winbindMaxDomainConnections = 1;
860 /* hostname lookups can be very expensive and are broken on
861 a large number of sites (tridge) */
862 Globals.bHostnameLookups = false;
864 string_set(&Globals.passdb_backend, "tdbsam");
865 string_set(&Globals.szLdapSuffix, "");
866 string_set(&Globals.szLdapMachineSuffix, "");
867 string_set(&Globals.szLdapUserSuffix, "");
868 string_set(&Globals.szLdapGroupSuffix, "");
869 string_set(&Globals.szLdapIdmapSuffix, "");
871 string_set(&Globals.szLdapAdminDn, "");
872 Globals.ldap_ssl = LDAP_SSL_START_TLS;
873 Globals.ldap_ssl_ads = false;
874 Globals.ldap_deref = -1;
875 Globals.ldap_passwd_sync = LDAP_PASSWD_SYNC_OFF;
876 Globals.ldap_delete_dn = false;
877 Globals.ldap_replication_sleep = 1000; /* wait 1 sec for replication */
878 Globals.ldap_follow_referral = Auto;
879 Globals.ldap_timeout = LDAP_DEFAULT_TIMEOUT;
880 Globals.ldap_connection_timeout = LDAP_CONNECTION_DEFAULT_TIMEOUT;
881 Globals.ldap_page_size = LDAP_PAGE_SIZE;
883 Globals.ldap_debug_level = 0;
884 Globals.ldap_debug_threshold = 10;
886 /* This is what we tell the afs client. in reality we set the token
887 * to never expire, though, when this runs out the afs client will
888 * forget the token. Set to 0 to get NEVERDATE.*/
889 Globals.iAfsTokenLifetime = 604800;
890 Globals.cups_connection_timeout = CUPS_DEFAULT_CONNECTION_TIMEOUT;
892 /* these parameters are set to defaults that are more appropriate
893 for the increasing samba install base:
895 as a member of the workgroup, that will possibly become a
896 _local_ master browser (lm = true). this is opposed to a forced
897 local master browser startup (pm = true).
899 doesn't provide WINS server service by default (wsupp = false),
900 and doesn't provide domain master browser services by default, either.
904 Globals.bMsAddPrinterWizard = true;
905 Globals.os_level = 20;
906 Globals.bLocalMaster = true;
907 Globals.domain_master = Auto; /* depending on bDomainLogons */
908 Globals.bDomainLogons = false;
909 Globals.bBrowseList = true;
910 Globals.bWINSsupport = false;
911 Globals.bWINSproxy = false;
913 TALLOC_FREE(Globals.szInitLogonDelayedHosts);
914 Globals.InitLogonDelay = 100; /* 100 ms default delay */
916 Globals.bWINSdnsProxy = true;
918 Globals.bAllowTrustedDomains = true;
919 string_set(&Globals.szIdmapBackend, "tdb");
921 string_set(&Globals.szTemplateShell, "/bin/false");
922 string_set(&Globals.szTemplateHomedir, "/home/%D/%U");
923 string_set(&Globals.szWinbindSeparator, "\\");
925 string_set(&Globals.szCupsServer, "");
926 string_set(&Globals.szIPrintServer, "");
928 #ifdef CLUSTER_SUPPORT
929 string_set(&Globals.ctdbdSocket, CTDB_PATH);
930 #else
931 string_set(&Globals.ctdbdSocket, "");
932 #endif
934 Globals.szClusterAddresses = NULL;
935 Globals.clustering = false;
936 Globals.ctdb_timeout = 0;
937 Globals.ctdb_locktime_warn_threshold = 0;
939 Globals.winbind_cache_time = 300; /* 5 minutes */
940 Globals.winbind_reconnect_delay = 30; /* 30 seconds */
941 Globals.winbind_max_clients = 200;
942 Globals.bWinbindEnumUsers = false;
943 Globals.bWinbindEnumGroups = false;
944 Globals.bWinbindUseDefaultDomain = false;
945 Globals.bWinbindTrustedDomainsOnly = false;
946 Globals.bWinbindNestedGroups = true;
947 Globals.winbind_expand_groups = 1;
948 Globals.szWinbindNssInfo = (const char **)str_list_make_v3(NULL, "template", NULL);
949 Globals.bWinbindRefreshTickets = false;
950 Globals.bWinbindOfflineLogon = false;
952 Globals.iIdmapCacheTime = 86400 * 7; /* a week by default */
953 Globals.iIdmapNegativeCacheTime = 120; /* 2 minutes by default */
955 Globals.bPassdbExpandExplicit = false;
957 Globals.name_cache_timeout = 660; /* In seconds */
959 Globals.bUseSpnego = true;
960 Globals.bClientUseSpnego = true;
962 Globals.client_signing = SMB_SIGNING_DEFAULT;
963 Globals.server_signing = SMB_SIGNING_DEFAULT;
965 Globals.bDeferSharingViolations = true;
966 Globals.smb_ports = (const char **)str_list_make_v3(NULL, SMB_PORTS, NULL);
968 Globals.bEnablePrivileges = true;
969 Globals.bHostMSDfs = true;
970 Globals.bASUSupport = false;
972 /* User defined shares. */
973 if (asprintf(&s, "%s/usershares", get_dyn_STATEDIR()) < 0) {
974 smb_panic("init_globals: ENOMEM");
976 string_set(&Globals.szUsersharePath, s);
977 SAFE_FREE(s);
978 string_set(&Globals.szUsershareTemplateShare, "");
979 Globals.iUsershareMaxShares = 0;
980 /* By default disallow sharing of directories not owned by the sharer. */
981 Globals.bUsershareOwnerOnly = true;
982 /* By default disallow guest access to usershares. */
983 Globals.bUsershareAllowGuests = false;
985 Globals.iKeepalive = DEFAULT_KEEPALIVE;
987 /* By default no shares out of the registry */
988 Globals.bRegistryShares = false;
990 Globals.iminreceivefile = 0;
992 Globals.bMapUntrustedToDomain = false;
993 Globals.bMulticastDnsRegister = true;
995 Globals.ismb2_max_read = DEFAULT_SMB2_MAX_READ;
996 Globals.ismb2_max_write = DEFAULT_SMB2_MAX_WRITE;
997 Globals.ismb2_max_trans = DEFAULT_SMB2_MAX_TRANSACT;
998 Globals.ismb2_max_credits = DEFAULT_SMB2_MAX_CREDITS;
1000 string_set(&Globals.ncalrpc_dir, get_dyn_NCALRPCDIR());
1002 /* Now put back the settings that were set with lp_set_cmdline() */
1003 apply_lp_set_cmdline();
1006 /*******************************************************************
1007 Convenience routine to grab string parameters into talloced memory
1008 and run standard_sub_basic on them. The buffers can be written to by
1009 callers without affecting the source string.
1010 ********************************************************************/
1012 static char *lp_string(TALLOC_CTX *ctx, const char *s)
1014 char *ret;
1016 /* The follow debug is useful for tracking down memory problems
1017 especially if you have an inner loop that is calling a lp_*()
1018 function that returns a string. Perhaps this debug should be
1019 present all the time? */
1021 #if 0
1022 DEBUG(10, ("lp_string(%s)\n", s));
1023 #endif
1024 if (!s) {
1025 return NULL;
1028 ret = talloc_sub_basic(ctx,
1029 get_current_username(),
1030 current_user_info.domain,
1032 if (trim_char(ret, '\"', '\"')) {
1033 if (strchr(ret,'\"') != NULL) {
1034 TALLOC_FREE(ret);
1035 ret = talloc_sub_basic(ctx,
1036 get_current_username(),
1037 current_user_info.domain,
1041 return ret;
1045 In this section all the functions that are used to access the
1046 parameters from the rest of the program are defined
1049 #define FN_GLOBAL_STRING(fn_name,ptr) \
1050 char *lp_ ## fn_name(TALLOC_CTX *ctx) {return(lp_string((ctx), *(char **)(&Globals.ptr) ? *(char **)(&Globals.ptr) : ""));}
1051 #define FN_GLOBAL_CONST_STRING(fn_name,ptr) \
1052 const char *lp_ ## fn_name(void) {return(*(const char **)(&Globals.ptr) ? *(const char **)(&Globals.ptr) : "");}
1053 #define FN_GLOBAL_LIST(fn_name,ptr) \
1054 const char **lp_ ## fn_name(void) {return(*(const char ***)(&Globals.ptr));}
1055 #define FN_GLOBAL_BOOL(fn_name,ptr) \
1056 bool lp_ ## fn_name(void) {return(*(bool *)(&Globals.ptr));}
1057 #define FN_GLOBAL_CHAR(fn_name,ptr) \
1058 char lp_ ## fn_name(void) {return(*(char *)(&Globals.ptr));}
1059 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
1060 int lp_ ## fn_name(void) {return(*(int *)(&Globals.ptr));}
1062 #define FN_LOCAL_STRING(fn_name,val) \
1063 char *lp_ ## fn_name(TALLOC_CTX *ctx,int i) {return(lp_string((ctx), (LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val));}
1064 #define FN_LOCAL_CONST_STRING(fn_name,val) \
1065 const char *lp_ ## fn_name(int i) {return (const char *)((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val);}
1066 #define FN_LOCAL_LIST(fn_name,val) \
1067 const char **lp_ ## fn_name(int i) {return(const char **)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1068 #define FN_LOCAL_BOOL(fn_name,val) \
1069 bool lp_ ## fn_name(int i) {return(bool)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1070 #define FN_LOCAL_INTEGER(fn_name,val) \
1071 int lp_ ## fn_name(int i) {return(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1073 #define FN_LOCAL_PARM_BOOL(fn_name,val) \
1074 bool lp_ ## fn_name(const struct share_params *p) {return(bool)(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1075 #define FN_LOCAL_PARM_INTEGER(fn_name,val) \
1076 int lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1077 #define FN_LOCAL_CHAR(fn_name,val) \
1078 char lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1081 static FN_GLOBAL_BOOL(_readraw, bReadRaw)
1082 static FN_GLOBAL_BOOL(_writeraw, bWriteRaw)
1084 /* If lp_statedir() and lp_cachedir() are explicitely set during the
1085 * build process or in smb.conf, we use that value. Otherwise they
1086 * default to the value of lp_lockdir(). */
1087 const char *lp_statedir(void) {
1088 if ((strcmp(get_dyn_STATEDIR(), get_dyn_LOCKDIR()) != 0) ||
1089 (strcmp(get_dyn_STATEDIR(), Globals.szStateDir) != 0))
1090 return(*(char **)(&Globals.szStateDir) ?
1091 *(char **)(&Globals.szStateDir) : "");
1092 else
1093 return(*(char **)(&Globals.szLockDir) ?
1094 *(char **)(&Globals.szLockDir) : "");
1096 const char *lp_cachedir(void) {
1097 if ((strcmp(get_dyn_CACHEDIR(), get_dyn_LOCKDIR()) != 0) ||
1098 (strcmp(get_dyn_CACHEDIR(), Globals.szCacheDir) != 0))
1099 return(*(char **)(&Globals.szCacheDir) ?
1100 *(char **)(&Globals.szCacheDir) : "");
1101 else
1102 return(*(char **)(&Globals.szLockDir) ?
1103 *(char **)(&Globals.szLockDir) : "");
1105 static FN_GLOBAL_INTEGER(winbind_max_domain_connections_int,
1106 winbindMaxDomainConnections)
1108 int lp_winbind_max_domain_connections(void)
1110 if (lp_winbind_offline_logon() &&
1111 lp_winbind_max_domain_connections_int() > 1) {
1112 DEBUG(1, ("offline logons active, restricting max domain "
1113 "connections to 1\n"));
1114 return 1;
1116 return MAX(1, lp_winbind_max_domain_connections_int());
1119 int lp_smb2_max_credits(void)
1121 if (Globals.ismb2_max_credits == 0) {
1122 Globals.ismb2_max_credits = DEFAULT_SMB2_MAX_CREDITS;
1124 return Globals.ismb2_max_credits;
1126 int lp_cups_encrypt(void)
1128 int result = 0;
1129 #ifdef HAVE_HTTPCONNECTENCRYPT
1130 switch (Globals.CupsEncrypt) {
1131 case Auto:
1132 result = HTTP_ENCRYPT_REQUIRED;
1133 break;
1134 case true:
1135 result = HTTP_ENCRYPT_ALWAYS;
1136 break;
1137 case false:
1138 result = HTTP_ENCRYPT_NEVER;
1139 break;
1141 #endif
1142 return result;
1145 /* These functions remain in source3/param for now */
1147 FN_GLOBAL_STRING(configfile, szConfigFile)
1149 #include "lib/param/param_functions.c"
1151 FN_LOCAL_STRING(servicename, szService)
1152 FN_LOCAL_CONST_STRING(const_servicename, szService)
1154 /* local prototypes */
1156 static int map_parameter_canonical(const char *pszParmName, bool *inverse);
1157 static const char *get_boolean(bool bool_value);
1158 static int getservicebyname(const char *pszServiceName,
1159 struct loadparm_service *pserviceDest);
1160 static void copy_service(struct loadparm_service *pserviceDest,
1161 struct loadparm_service *pserviceSource,
1162 struct bitmap *pcopymapDest);
1163 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1164 void *userdata);
1165 static bool do_section(const char *pszSectionName, void *userdata);
1166 static void init_copymap(struct loadparm_service *pservice);
1167 static bool hash_a_service(const char *name, int number);
1168 static void free_service_byindex(int iService);
1169 static void show_parameter(int parmIndex);
1170 static bool is_synonym_of(int parm1, int parm2, bool *inverse);
1173 * This is a helper function for parametrical options support. It returns a
1174 * pointer to parametrical option value if it exists or NULL otherwise. Actual
1175 * parametrical functions are quite simple
1177 static struct parmlist_entry *get_parametrics_by_service(struct loadparm_service *service, const char *type,
1178 const char *option)
1180 bool global_section = false;
1181 char* param_key;
1182 struct parmlist_entry *data;
1184 if (service == NULL) {
1185 data = Globals.param_opt;
1186 global_section = true;
1187 } else {
1188 data = service->param_opt;
1191 if (asprintf(&param_key, "%s:%s", type, option) == -1) {
1192 DEBUG(0,("asprintf failed!\n"));
1193 return NULL;
1196 while (data) {
1197 if (strwicmp(data->key, param_key) == 0) {
1198 string_free(&param_key);
1199 return data;
1201 data = data->next;
1204 if (!global_section) {
1205 /* Try to fetch the same option but from globals */
1206 /* but only if we are not already working with Globals */
1207 data = Globals.param_opt;
1208 while (data) {
1209 if (strwicmp(data->key, param_key) == 0) {
1210 string_free(&param_key);
1211 return data;
1213 data = data->next;
1217 string_free(&param_key);
1219 return NULL;
1223 * This is a helper function for parametrical options support. It returns a
1224 * pointer to parametrical option value if it exists or NULL otherwise. Actual
1225 * parametrical functions are quite simple
1227 static struct parmlist_entry *get_parametrics(int snum, const char *type,
1228 const char *option)
1230 if (snum >= iNumServices) return NULL;
1232 if (snum < 0) {
1233 return get_parametrics_by_service(NULL, type, option);
1234 } else {
1235 return get_parametrics_by_service(ServicePtrs[snum], type, option);
1240 #define MISSING_PARAMETER(name) \
1241 DEBUG(0, ("%s(): value is NULL or empty!\n", #name))
1243 /*******************************************************************
1244 convenience routine to return int parameters.
1245 ********************************************************************/
1246 static int lp_int(const char *s)
1249 if (!s || !*s) {
1250 MISSING_PARAMETER(lp_int);
1251 return (-1);
1254 return (int)strtol(s, NULL, 0);
1257 /*******************************************************************
1258 convenience routine to return unsigned long parameters.
1259 ********************************************************************/
1260 static unsigned long lp_ulong(const char *s)
1263 if (!s || !*s) {
1264 MISSING_PARAMETER(lp_ulong);
1265 return (0);
1268 return strtoul(s, NULL, 0);
1271 /*******************************************************************
1272 convenience routine to return boolean parameters.
1273 ********************************************************************/
1274 static bool lp_bool(const char *s)
1276 bool ret = false;
1278 if (!s || !*s) {
1279 MISSING_PARAMETER(lp_bool);
1280 return false;
1283 if (!set_boolean(s, &ret)) {
1284 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1285 return false;
1288 return ret;
1291 /*******************************************************************
1292 convenience routine to return enum parameters.
1293 ********************************************************************/
1294 static int lp_enum(const char *s,const struct enum_list *_enum)
1296 int i;
1298 if (!s || !*s || !_enum) {
1299 MISSING_PARAMETER(lp_enum);
1300 return (-1);
1303 for (i=0; _enum[i].name; i++) {
1304 if (strequal(_enum[i].name,s))
1305 return _enum[i].value;
1308 DEBUG(0,("lp_enum(%s,enum): value is not in enum_list!\n",s));
1309 return (-1);
1312 #undef MISSING_PARAMETER
1314 /* Return parametric option from a given service. Type is a part of option before ':' */
1315 /* Parametric option has following syntax: 'Type: option = value' */
1316 char *lp_parm_talloc_string(TALLOC_CTX *ctx, int snum, const char *type, const char *option, const char *def)
1318 struct parmlist_entry *data = get_parametrics(snum, type, option);
1320 if (data == NULL||data->value==NULL) {
1321 if (def) {
1322 return lp_string(ctx, def);
1323 } else {
1324 return NULL;
1328 return lp_string(ctx, data->value);
1331 /* Return parametric option from a given service. Type is a part of option before ':' */
1332 /* Parametric option has following syntax: 'Type: option = value' */
1333 const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def)
1335 struct parmlist_entry *data = get_parametrics(snum, type, option);
1337 if (data == NULL||data->value==NULL)
1338 return def;
1340 return data->value;
1343 const char *lp_parm_const_string_service(struct loadparm_service *service, const char *type, const char *option)
1345 struct parmlist_entry *data = get_parametrics_by_service(service, type, option);
1347 if (data == NULL||data->value==NULL)
1348 return NULL;
1350 return data->value;
1354 /* Return parametric option from a given service. Type is a part of option before ':' */
1355 /* Parametric option has following syntax: 'Type: option = value' */
1357 const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def)
1359 struct parmlist_entry *data = get_parametrics(snum, type, option);
1361 if (data == NULL||data->value==NULL)
1362 return (const char **)def;
1364 if (data->list==NULL) {
1365 data->list = str_list_make_v3(NULL, data->value, NULL);
1368 return (const char **)data->list;
1371 /* Return parametric option from a given service. Type is a part of option before ':' */
1372 /* Parametric option has following syntax: 'Type: option = value' */
1374 int lp_parm_int(int snum, const char *type, const char *option, int def)
1376 struct parmlist_entry *data = get_parametrics(snum, type, option);
1378 if (data && data->value && *data->value)
1379 return lp_int(data->value);
1381 return def;
1384 /* Return parametric option from a given service. Type is a part of option before ':' */
1385 /* Parametric option has following syntax: 'Type: option = value' */
1387 unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsigned long def)
1389 struct parmlist_entry *data = get_parametrics(snum, type, option);
1391 if (data && data->value && *data->value)
1392 return lp_ulong(data->value);
1394 return def;
1397 /* Return parametric option from a given service. Type is a part of option before ':' */
1398 /* Parametric option has following syntax: 'Type: option = value' */
1400 bool lp_parm_bool(int snum, const char *type, const char *option, bool def)
1402 struct parmlist_entry *data = get_parametrics(snum, type, option);
1404 if (data && data->value && *data->value)
1405 return lp_bool(data->value);
1407 return def;
1410 /* Return parametric option from a given service. Type is a part of option before ':' */
1411 /* Parametric option has following syntax: 'Type: option = value' */
1413 int lp_parm_enum(int snum, const char *type, const char *option,
1414 const struct enum_list *_enum, int def)
1416 struct parmlist_entry *data = get_parametrics(snum, type, option);
1418 if (data && data->value && *data->value && _enum)
1419 return lp_enum(data->value, _enum);
1421 return def;
1425 /***************************************************************************
1426 Initialise a service to the defaults.
1427 ***************************************************************************/
1429 static void init_service(struct loadparm_service *pservice)
1431 memset((char *)pservice, '\0', sizeof(struct loadparm_service));
1432 copy_service(pservice, &sDefault, NULL);
1437 * free a param_opts structure.
1438 * param_opts handling should be moved to talloc;
1439 * then this whole functions reduces to a TALLOC_FREE().
1442 static void free_param_opts(struct parmlist_entry **popts)
1444 struct parmlist_entry *opt, *next_opt;
1446 if (popts == NULL) {
1447 return;
1450 if (*popts != NULL) {
1451 DEBUG(5, ("Freeing parametrics:\n"));
1453 opt = *popts;
1454 while (opt != NULL) {
1455 string_free(&opt->key);
1456 string_free(&opt->value);
1457 TALLOC_FREE(opt->list);
1458 next_opt = opt->next;
1459 SAFE_FREE(opt);
1460 opt = next_opt;
1462 *popts = NULL;
1465 /***************************************************************************
1466 Free the dynamically allocated parts of a service struct.
1467 ***************************************************************************/
1469 static void free_service(struct loadparm_service *pservice)
1471 if (!pservice)
1472 return;
1474 if (pservice->szService)
1475 DEBUG(5, ("free_service: Freeing service %s\n",
1476 pservice->szService));
1478 free_parameters(pservice);
1480 string_free(&pservice->szService);
1481 TALLOC_FREE(pservice->copymap);
1483 free_param_opts(&pservice->param_opt);
1485 ZERO_STRUCTP(pservice);
1489 /***************************************************************************
1490 remove a service indexed in the ServicePtrs array from the ServiceHash
1491 and free the dynamically allocated parts
1492 ***************************************************************************/
1494 static void free_service_byindex(int idx)
1496 if ( !LP_SNUM_OK(idx) )
1497 return;
1499 ServicePtrs[idx]->valid = false;
1500 invalid_services[num_invalid_services++] = idx;
1502 /* we have to cleanup the hash record */
1504 if (ServicePtrs[idx]->szService) {
1505 char *canon_name = canonicalize_servicename(
1506 talloc_tos(),
1507 ServicePtrs[idx]->szService );
1509 dbwrap_delete_bystring(ServiceHash, canon_name );
1510 TALLOC_FREE(canon_name);
1513 free_service(ServicePtrs[idx]);
1514 talloc_free_children(ServicePtrs[idx]);
1517 /***************************************************************************
1518 Add a new service to the services array initialising it with the given
1519 service.
1520 ***************************************************************************/
1522 static int add_a_service(const struct loadparm_service *pservice, const char *name)
1524 int i;
1525 struct loadparm_service tservice;
1526 int num_to_alloc = iNumServices + 1;
1528 tservice = *pservice;
1530 /* it might already exist */
1531 if (name) {
1532 i = getservicebyname(name, NULL);
1533 if (i >= 0) {
1534 return (i);
1538 /* find an invalid one */
1539 i = iNumServices;
1540 if (num_invalid_services > 0) {
1541 i = invalid_services[--num_invalid_services];
1544 /* if not, then create one */
1545 if (i == iNumServices) {
1546 struct loadparm_service **tsp;
1547 int *tinvalid;
1549 tsp = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(ServicePtrs, struct loadparm_service *, num_to_alloc);
1550 if (tsp == NULL) {
1551 DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
1552 return (-1);
1554 ServicePtrs = tsp;
1555 ServicePtrs[iNumServices] = talloc(NULL, struct loadparm_service);
1556 if (!ServicePtrs[iNumServices]) {
1557 DEBUG(0,("add_a_service: out of memory!\n"));
1558 return (-1);
1560 iNumServices++;
1562 /* enlarge invalid_services here for now... */
1563 tinvalid = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(invalid_services, int,
1564 num_to_alloc);
1565 if (tinvalid == NULL) {
1566 DEBUG(0,("add_a_service: failed to enlarge "
1567 "invalid_services!\n"));
1568 return (-1);
1570 invalid_services = tinvalid;
1571 } else {
1572 free_service_byindex(i);
1575 ServicePtrs[i]->valid = true;
1577 init_service(ServicePtrs[i]);
1578 copy_service(ServicePtrs[i], &tservice, NULL);
1579 if (name)
1580 string_set(&ServicePtrs[i]->szService, name);
1582 DEBUG(8,("add_a_service: Creating snum = %d for %s\n",
1583 i, ServicePtrs[i]->szService));
1585 if (!hash_a_service(ServicePtrs[i]->szService, i)) {
1586 return (-1);
1589 return (i);
1592 /***************************************************************************
1593 Convert a string to uppercase and remove whitespaces.
1594 ***************************************************************************/
1596 char *canonicalize_servicename(TALLOC_CTX *ctx, const char *src)
1598 char *result;
1600 if ( !src ) {
1601 DEBUG(0,("canonicalize_servicename: NULL source name!\n"));
1602 return NULL;
1605 result = talloc_strdup(ctx, src);
1606 SMB_ASSERT(result != NULL);
1608 strlower_m(result);
1609 return result;
1612 /***************************************************************************
1613 Add a name/index pair for the services array to the hash table.
1614 ***************************************************************************/
1616 static bool hash_a_service(const char *name, int idx)
1618 char *canon_name;
1620 if ( !ServiceHash ) {
1621 DEBUG(10,("hash_a_service: creating servicehash\n"));
1622 ServiceHash = db_open_rbt(NULL);
1623 if ( !ServiceHash ) {
1624 DEBUG(0,("hash_a_service: open tdb servicehash failed!\n"));
1625 return false;
1629 DEBUG(10,("hash_a_service: hashing index %d for service name %s\n",
1630 idx, name));
1632 canon_name = canonicalize_servicename(talloc_tos(), name );
1634 dbwrap_store_bystring(ServiceHash, canon_name,
1635 make_tdb_data((uint8 *)&idx, sizeof(idx)),
1636 TDB_REPLACE);
1638 TALLOC_FREE(canon_name);
1640 return true;
1643 /***************************************************************************
1644 Add a new home service, with the specified home directory, defaults coming
1645 from service ifrom.
1646 ***************************************************************************/
1648 bool lp_add_home(const char *pszHomename, int iDefaultService,
1649 const char *user, const char *pszHomedir)
1651 int i;
1653 if (pszHomename == NULL || user == NULL || pszHomedir == NULL ||
1654 pszHomedir[0] == '\0') {
1655 return false;
1658 i = add_a_service(ServicePtrs[iDefaultService], pszHomename);
1660 if (i < 0)
1661 return false;
1663 if (!(*(ServicePtrs[iDefaultService]->szPath))
1664 || strequal(ServicePtrs[iDefaultService]->szPath,
1665 lp_pathname(talloc_tos(), GLOBAL_SECTION_SNUM))) {
1666 string_set(&ServicePtrs[i]->szPath, pszHomedir);
1669 if (!(*(ServicePtrs[i]->comment))) {
1670 char *comment = NULL;
1671 if (asprintf(&comment, "Home directory of %s", user) < 0) {
1672 return false;
1674 string_set(&ServicePtrs[i]->comment, comment);
1675 SAFE_FREE(comment);
1678 /* set the browseable flag from the global default */
1680 ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
1681 ServicePtrs[i]->bAccessBasedShareEnum = sDefault.bAccessBasedShareEnum;
1683 ServicePtrs[i]->autoloaded = true;
1685 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename,
1686 user, ServicePtrs[i]->szPath ));
1688 return true;
1691 /***************************************************************************
1692 Add a new service, based on an old one.
1693 ***************************************************************************/
1695 int lp_add_service(const char *pszService, int iDefaultService)
1697 if (iDefaultService < 0) {
1698 return add_a_service(&sDefault, pszService);
1701 return (add_a_service(ServicePtrs[iDefaultService], pszService));
1704 /***************************************************************************
1705 Add the IPC service.
1706 ***************************************************************************/
1708 static bool lp_add_ipc(const char *ipc_name, bool guest_ok)
1710 char *comment = NULL;
1711 int i = add_a_service(&sDefault, ipc_name);
1713 if (i < 0)
1714 return false;
1716 if (asprintf(&comment, "IPC Service (%s)",
1717 Globals.szServerString) < 0) {
1718 return false;
1721 string_set(&ServicePtrs[i]->szPath, tmpdir());
1722 string_set(&ServicePtrs[i]->szUsername, "");
1723 string_set(&ServicePtrs[i]->comment, comment);
1724 string_set(&ServicePtrs[i]->fstype, "IPC");
1725 ServicePtrs[i]->iMaxConnections = 0;
1726 ServicePtrs[i]->bAvailable = true;
1727 ServicePtrs[i]->bRead_only = true;
1728 ServicePtrs[i]->bGuest_only = false;
1729 ServicePtrs[i]->bAdministrative_share = true;
1730 ServicePtrs[i]->bGuest_ok = guest_ok;
1731 ServicePtrs[i]->bPrint_ok = false;
1732 ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
1734 DEBUG(3, ("adding IPC service\n"));
1736 SAFE_FREE(comment);
1737 return true;
1740 /***************************************************************************
1741 Add a new printer service, with defaults coming from service iFrom.
1742 ***************************************************************************/
1744 bool lp_add_printer(const char *pszPrintername, int iDefaultService)
1746 const char *comment = "From Printcap";
1747 int i = add_a_service(ServicePtrs[iDefaultService], pszPrintername);
1749 if (i < 0)
1750 return false;
1752 /* note that we do NOT default the availability flag to true - */
1753 /* we take it from the default service passed. This allows all */
1754 /* dynamic printers to be disabled by disabling the [printers] */
1755 /* entry (if/when the 'available' keyword is implemented!). */
1757 /* the printer name is set to the service name. */
1758 string_set(&ServicePtrs[i]->szPrintername, pszPrintername);
1759 string_set(&ServicePtrs[i]->comment, comment);
1761 /* set the browseable flag from the gloabl default */
1762 ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
1764 /* Printers cannot be read_only. */
1765 ServicePtrs[i]->bRead_only = false;
1766 /* No share modes on printer services. */
1767 ServicePtrs[i]->bShareModes = false;
1768 /* No oplocks on printer services. */
1769 ServicePtrs[i]->bOpLocks = false;
1770 /* Printer services must be printable. */
1771 ServicePtrs[i]->bPrint_ok = true;
1773 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1775 return true;
1779 /***************************************************************************
1780 Check whether the given parameter name is valid.
1781 Parametric options (names containing a colon) are considered valid.
1782 ***************************************************************************/
1784 bool lp_parameter_is_valid(const char *pszParmName)
1786 return ((map_parameter(pszParmName) != -1) ||
1787 (strchr(pszParmName, ':') != NULL));
1790 /***************************************************************************
1791 Check whether the given name is the name of a global parameter.
1792 Returns true for strings belonging to parameters of class
1793 P_GLOBAL, false for all other strings, also for parametric options
1794 and strings not belonging to any option.
1795 ***************************************************************************/
1797 bool lp_parameter_is_global(const char *pszParmName)
1799 int num = map_parameter(pszParmName);
1801 if (num >= 0) {
1802 return (parm_table[num].p_class == P_GLOBAL);
1805 return false;
1808 /**************************************************************************
1809 Check whether the given name is the canonical name of a parameter.
1810 Returns false if it is not a valid parameter Name.
1811 For parametric options, true is returned.
1812 **************************************************************************/
1814 bool lp_parameter_is_canonical(const char *parm_name)
1816 if (!lp_parameter_is_valid(parm_name)) {
1817 return false;
1820 return (map_parameter(parm_name) ==
1821 map_parameter_canonical(parm_name, NULL));
1824 /**************************************************************************
1825 Determine the canonical name for a parameter.
1826 Indicate when it is an inverse (boolean) synonym instead of a
1827 "usual" synonym.
1828 **************************************************************************/
1830 bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
1831 bool *inverse)
1833 int num;
1835 if (!lp_parameter_is_valid(parm_name)) {
1836 *canon_parm = NULL;
1837 return false;
1840 num = map_parameter_canonical(parm_name, inverse);
1841 if (num < 0) {
1842 /* parametric option */
1843 *canon_parm = parm_name;
1844 } else {
1845 *canon_parm = parm_table[num].label;
1848 return true;
1852 /**************************************************************************
1853 Determine the canonical name for a parameter.
1854 Turn the value given into the inverse boolean expression when
1855 the synonym is an invers boolean synonym.
1857 Return true if parm_name is a valid parameter name and
1858 in case it is an invers boolean synonym, if the val string could
1859 successfully be converted to the reverse bool.
1860 Return false in all other cases.
1861 **************************************************************************/
1863 bool lp_canonicalize_parameter_with_value(const char *parm_name,
1864 const char *val,
1865 const char **canon_parm,
1866 const char **canon_val)
1868 int num;
1869 bool inverse;
1871 if (!lp_parameter_is_valid(parm_name)) {
1872 *canon_parm = NULL;
1873 *canon_val = NULL;
1874 return false;
1877 num = map_parameter_canonical(parm_name, &inverse);
1878 if (num < 0) {
1879 /* parametric option */
1880 *canon_parm = parm_name;
1881 *canon_val = val;
1882 } else {
1883 *canon_parm = parm_table[num].label;
1884 if (inverse) {
1885 if (!lp_invert_boolean(val, canon_val)) {
1886 *canon_val = NULL;
1887 return false;
1889 } else {
1890 *canon_val = val;
1894 return true;
1897 /***************************************************************************
1898 Map a parameter's string representation to something we can use.
1899 Returns false if the parameter string is not recognised, else TRUE.
1900 ***************************************************************************/
1902 static int map_parameter(const char *pszParmName)
1904 int iIndex;
1906 if (*pszParmName == '-' && !strequal(pszParmName, "-valid"))
1907 return (-1);
1909 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1910 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1911 return (iIndex);
1913 /* Warn only if it isn't parametric option */
1914 if (strchr(pszParmName, ':') == NULL)
1915 DEBUG(1, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1916 /* We do return 'fail' for parametric options as well because they are
1917 stored in different storage
1919 return (-1);
1922 /***************************************************************************
1923 Map a parameter's string representation to the index of the canonical
1924 form of the parameter (it might be a synonym).
1925 Returns -1 if the parameter string is not recognised.
1926 ***************************************************************************/
1928 static int map_parameter_canonical(const char *pszParmName, bool *inverse)
1930 int parm_num, canon_num;
1931 bool loc_inverse = false;
1933 parm_num = map_parameter(pszParmName);
1934 if ((parm_num < 0) || !(parm_table[parm_num].flags & FLAG_HIDE)) {
1935 /* invalid, parametric or no canidate for synonyms ... */
1936 goto done;
1939 for (canon_num = 0; parm_table[canon_num].label; canon_num++) {
1940 if (is_synonym_of(parm_num, canon_num, &loc_inverse)) {
1941 parm_num = canon_num;
1942 goto done;
1946 done:
1947 if (inverse != NULL) {
1948 *inverse = loc_inverse;
1950 return parm_num;
1953 /***************************************************************************
1954 return true if parameter number parm1 is a synonym of parameter
1955 number parm2 (parm2 being the principal name).
1956 set inverse to true if parm1 is P_BOOLREV and parm2 is P_BOOL,
1957 false otherwise.
1958 ***************************************************************************/
1960 static bool is_synonym_of(int parm1, int parm2, bool *inverse)
1962 if ((parm_table[parm1].offset == parm_table[parm2].offset) &&
1963 (parm_table[parm1].p_class == parm_table[parm2].p_class) &&
1964 (parm_table[parm1].flags & FLAG_HIDE) &&
1965 !(parm_table[parm2].flags & FLAG_HIDE))
1967 if (inverse != NULL) {
1968 if ((parm_table[parm1].type == P_BOOLREV) &&
1969 (parm_table[parm2].type == P_BOOL))
1971 *inverse = true;
1972 } else {
1973 *inverse = false;
1976 return true;
1978 return false;
1981 /***************************************************************************
1982 Show one parameter's name, type, [values,] and flags.
1983 (helper functions for show_parameter_list)
1984 ***************************************************************************/
1986 static void show_parameter(int parmIndex)
1988 int enumIndex, flagIndex;
1989 int parmIndex2;
1990 bool hadFlag;
1991 bool hadSyn;
1992 bool inverse;
1993 const char *type[] = { "P_BOOL", "P_BOOLREV", "P_CHAR", "P_INTEGER",
1994 "P_OCTAL", "P_LIST", "P_STRING", "P_USTRING",
1995 "P_ENUM", "P_SEP"};
1996 unsigned flags[] = { FLAG_BASIC, FLAG_SHARE, FLAG_PRINT, FLAG_GLOBAL,
1997 FLAG_WIZARD, FLAG_ADVANCED, FLAG_DEVELOPER, FLAG_DEPRECATED,
1998 FLAG_HIDE};
1999 const char *flag_names[] = { "FLAG_BASIC", "FLAG_SHARE", "FLAG_PRINT",
2000 "FLAG_GLOBAL", "FLAG_WIZARD", "FLAG_ADVANCED", "FLAG_DEVELOPER",
2001 "FLAG_DEPRECATED", "FLAG_HIDE", NULL};
2003 printf("%s=%s", parm_table[parmIndex].label,
2004 type[parm_table[parmIndex].type]);
2005 if (parm_table[parmIndex].type == P_ENUM) {
2006 printf(",");
2007 for (enumIndex=0;
2008 parm_table[parmIndex].enum_list[enumIndex].name;
2009 enumIndex++)
2011 printf("%s%s",
2012 enumIndex ? "|" : "",
2013 parm_table[parmIndex].enum_list[enumIndex].name);
2016 printf(",");
2017 hadFlag = false;
2018 for (flagIndex=0; flag_names[flagIndex]; flagIndex++) {
2019 if (parm_table[parmIndex].flags & flags[flagIndex]) {
2020 printf("%s%s",
2021 hadFlag ? "|" : "",
2022 flag_names[flagIndex]);
2023 hadFlag = true;
2027 /* output synonyms */
2028 hadSyn = false;
2029 for (parmIndex2=0; parm_table[parmIndex2].label; parmIndex2++) {
2030 if (is_synonym_of(parmIndex, parmIndex2, &inverse)) {
2031 printf(" (%ssynonym of %s)", inverse ? "inverse " : "",
2032 parm_table[parmIndex2].label);
2033 } else if (is_synonym_of(parmIndex2, parmIndex, &inverse)) {
2034 if (!hadSyn) {
2035 printf(" (synonyms: ");
2036 hadSyn = true;
2037 } else {
2038 printf(", ");
2040 printf("%s%s", parm_table[parmIndex2].label,
2041 inverse ? "[i]" : "");
2044 if (hadSyn) {
2045 printf(")");
2048 printf("\n");
2051 /***************************************************************************
2052 Show all parameter's name, type, [values,] and flags.
2053 ***************************************************************************/
2055 void show_parameter_list(void)
2057 int classIndex, parmIndex;
2058 const char *section_names[] = { "local", "global", NULL};
2060 for (classIndex=0; section_names[classIndex]; classIndex++) {
2061 printf("[%s]\n", section_names[classIndex]);
2062 for (parmIndex = 0; parm_table[parmIndex].label; parmIndex++) {
2063 if (parm_table[parmIndex].p_class == classIndex) {
2064 show_parameter(parmIndex);
2070 /***************************************************************************
2071 Check if a given string correctly represents a boolean value.
2072 ***************************************************************************/
2074 bool lp_string_is_valid_boolean(const char *parm_value)
2076 return set_boolean(parm_value, NULL);
2079 /***************************************************************************
2080 Get the standard string representation of a boolean value ("yes" or "no")
2081 ***************************************************************************/
2083 static const char *get_boolean(bool bool_value)
2085 static const char *yes_str = "yes";
2086 static const char *no_str = "no";
2088 return (bool_value ? yes_str : no_str);
2091 /***************************************************************************
2092 Provide the string of the negated boolean value associated to the boolean
2093 given as a string. Returns false if the passed string does not correctly
2094 represent a boolean.
2095 ***************************************************************************/
2097 bool lp_invert_boolean(const char *str, const char **inverse_str)
2099 bool val;
2101 if (!set_boolean(str, &val)) {
2102 return false;
2105 *inverse_str = get_boolean(!val);
2106 return true;
2109 /***************************************************************************
2110 Provide the canonical string representation of a boolean value given
2111 as a string. Return true on success, false if the string given does
2112 not correctly represent a boolean.
2113 ***************************************************************************/
2115 bool lp_canonicalize_boolean(const char *str, const char**canon_str)
2117 bool val;
2119 if (!set_boolean(str, &val)) {
2120 return false;
2123 *canon_str = get_boolean(val);
2124 return true;
2127 /***************************************************************************
2128 Find a service by name. Otherwise works like get_service.
2129 ***************************************************************************/
2131 static int getservicebyname(const char *pszServiceName, struct loadparm_service *pserviceDest)
2133 int iService = -1;
2134 char *canon_name;
2135 TDB_DATA data;
2136 NTSTATUS status;
2138 if (ServiceHash == NULL) {
2139 return -1;
2142 canon_name = canonicalize_servicename(talloc_tos(), pszServiceName);
2144 status = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name,
2145 &data);
2147 if (NT_STATUS_IS_OK(status) &&
2148 (data.dptr != NULL) &&
2149 (data.dsize == sizeof(iService)))
2151 iService = *(int *)data.dptr;
2154 TALLOC_FREE(canon_name);
2156 if ((iService != -1) && (LP_SNUM_OK(iService))
2157 && (pserviceDest != NULL)) {
2158 copy_service(pserviceDest, ServicePtrs[iService], NULL);
2161 return (iService);
2164 /* Return a pointer to a service by name. Unlike getservicebyname, it does not copy the service */
2165 struct loadparm_service *lp_service(const char *pszServiceName)
2167 int iService = getservicebyname(pszServiceName, NULL);
2168 if (iService == -1 || !LP_SNUM_OK(iService)) {
2169 return NULL;
2171 return ServicePtrs[iService];
2174 struct loadparm_service *lp_servicebynum(int snum)
2176 if ((snum == -1) || !LP_SNUM_OK(snum)) {
2177 return NULL;
2179 return ServicePtrs[snum];
2182 struct loadparm_service *lp_default_loadparm_service()
2184 return &sDefault;
2188 /***************************************************************************
2189 Copy a service structure to another.
2190 If pcopymapDest is NULL then copy all fields
2191 ***************************************************************************/
2194 * Add a parametric option to a parmlist_entry,
2195 * replacing old value, if already present.
2197 static void set_param_opt(struct parmlist_entry **opt_list,
2198 const char *opt_name,
2199 const char *opt_value,
2200 unsigned priority)
2202 struct parmlist_entry *new_opt, *opt;
2203 bool not_added;
2205 if (opt_list == NULL) {
2206 return;
2209 opt = *opt_list;
2210 not_added = true;
2212 /* Traverse destination */
2213 while (opt) {
2214 /* If we already have same option, override it */
2215 if (strwicmp(opt->key, opt_name) == 0) {
2216 if ((opt->priority & FLAG_CMDLINE) &&
2217 !(priority & FLAG_CMDLINE)) {
2218 /* it's been marked as not to be
2219 overridden */
2220 return;
2222 string_free(&opt->value);
2223 TALLOC_FREE(opt->list);
2224 opt->value = SMB_STRDUP(opt_value);
2225 opt->priority = priority;
2226 not_added = false;
2227 break;
2229 opt = opt->next;
2231 if (not_added) {
2232 new_opt = SMB_XMALLOC_P(struct parmlist_entry);
2233 new_opt->key = SMB_STRDUP(opt_name);
2234 new_opt->value = SMB_STRDUP(opt_value);
2235 new_opt->list = NULL;
2236 new_opt->priority = priority;
2237 DLIST_ADD(*opt_list, new_opt);
2241 static void copy_service(struct loadparm_service *pserviceDest, struct loadparm_service *pserviceSource,
2242 struct bitmap *pcopymapDest)
2244 int i;
2245 bool bcopyall = (pcopymapDest == NULL);
2246 struct parmlist_entry *data;
2248 for (i = 0; parm_table[i].label; i++)
2249 if (parm_table[i].p_class == P_LOCAL &&
2250 (bcopyall || bitmap_query(pcopymapDest,i))) {
2251 void *src_ptr = lp_parm_ptr(pserviceSource, &parm_table[i]);
2252 void *dest_ptr = lp_parm_ptr(pserviceDest, &parm_table[i]);
2254 switch (parm_table[i].type) {
2255 case P_BOOL:
2256 case P_BOOLREV:
2257 *(bool *)dest_ptr = *(bool *)src_ptr;
2258 break;
2260 case P_INTEGER:
2261 case P_ENUM:
2262 case P_OCTAL:
2263 case P_BYTES:
2264 *(int *)dest_ptr = *(int *)src_ptr;
2265 break;
2267 case P_CHAR:
2268 *(char *)dest_ptr = *(char *)src_ptr;
2269 break;
2271 case P_STRING:
2272 string_set((char **)dest_ptr,
2273 *(char **)src_ptr);
2274 break;
2276 case P_USTRING:
2278 char *upper_string = strupper_talloc(talloc_tos(),
2279 *(char **)src_ptr);
2280 string_set((char **)dest_ptr,
2281 upper_string);
2282 TALLOC_FREE(upper_string);
2283 break;
2285 case P_LIST:
2286 TALLOC_FREE(*((char ***)dest_ptr));
2287 *((char ***)dest_ptr) = str_list_copy(NULL,
2288 *(const char ***)src_ptr);
2289 break;
2290 default:
2291 break;
2295 if (bcopyall) {
2296 init_copymap(pserviceDest);
2297 if (pserviceSource->copymap)
2298 bitmap_copy(pserviceDest->copymap,
2299 pserviceSource->copymap);
2302 data = pserviceSource->param_opt;
2303 while (data) {
2304 set_param_opt(&pserviceDest->param_opt, data->key, data->value, data->priority);
2305 data = data->next;
2309 /***************************************************************************
2310 Check a service for consistency. Return false if the service is in any way
2311 incomplete or faulty, else true.
2312 ***************************************************************************/
2314 bool service_ok(int iService)
2316 bool bRetval;
2318 bRetval = true;
2319 if (ServicePtrs[iService]->szService[0] == '\0') {
2320 DEBUG(0, ("The following message indicates an internal error:\n"));
2321 DEBUG(0, ("No service name in service entry.\n"));
2322 bRetval = false;
2325 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2326 /* I can't see why you'd want a non-printable printer service... */
2327 if (strwicmp(ServicePtrs[iService]->szService, PRINTERS_NAME) == 0) {
2328 if (!ServicePtrs[iService]->bPrint_ok) {
2329 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2330 ServicePtrs[iService]->szService));
2331 ServicePtrs[iService]->bPrint_ok = true;
2333 /* [printers] service must also be non-browsable. */
2334 if (ServicePtrs[iService]->bBrowseable)
2335 ServicePtrs[iService]->bBrowseable = false;
2338 if (ServicePtrs[iService]->szPath[0] == '\0' &&
2339 strwicmp(ServicePtrs[iService]->szService, HOMES_NAME) != 0 &&
2340 ServicePtrs[iService]->szMSDfsProxy[0] == '\0'
2342 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
2343 ServicePtrs[iService]->szService));
2344 ServicePtrs[iService]->bAvailable = false;
2347 /* If a service is flagged unavailable, log the fact at level 1. */
2348 if (!ServicePtrs[iService]->bAvailable)
2349 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2350 ServicePtrs[iService]->szService));
2352 return (bRetval);
2355 static struct smbconf_ctx *lp_smbconf_ctx(void)
2357 sbcErr err;
2358 static struct smbconf_ctx *conf_ctx = NULL;
2360 if (conf_ctx == NULL) {
2361 err = smbconf_init(NULL, &conf_ctx, "registry:");
2362 if (!SBC_ERROR_IS_OK(err)) {
2363 DEBUG(1, ("error initializing registry configuration: "
2364 "%s\n", sbcErrorString(err)));
2365 conf_ctx = NULL;
2369 return conf_ctx;
2372 static bool process_smbconf_service(struct smbconf_service *service)
2374 uint32_t count;
2375 bool ret;
2377 if (service == NULL) {
2378 return false;
2381 ret = do_section(service->name, NULL);
2382 if (ret != true) {
2383 return false;
2385 for (count = 0; count < service->num_params; count++) {
2386 ret = do_parameter(service->param_names[count],
2387 service->param_values[count],
2388 NULL);
2389 if (ret != true) {
2390 return false;
2393 if (iServiceIndex >= 0) {
2394 return service_ok(iServiceIndex);
2396 return true;
2400 * load a service from registry and activate it
2402 bool process_registry_service(const char *service_name)
2404 sbcErr err;
2405 struct smbconf_service *service = NULL;
2406 TALLOC_CTX *mem_ctx = talloc_stackframe();
2407 struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
2408 bool ret = false;
2410 if (conf_ctx == NULL) {
2411 goto done;
2414 DEBUG(5, ("process_registry_service: service name %s\n", service_name));
2416 if (!smbconf_share_exists(conf_ctx, service_name)) {
2418 * Registry does not contain data for this service (yet),
2419 * but make sure lp_load doesn't return false.
2421 ret = true;
2422 goto done;
2425 err = smbconf_get_share(conf_ctx, mem_ctx, service_name, &service);
2426 if (!SBC_ERROR_IS_OK(err)) {
2427 goto done;
2430 ret = process_smbconf_service(service);
2431 if (!ret) {
2432 goto done;
2435 /* store the csn */
2436 smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL);
2438 done:
2439 TALLOC_FREE(mem_ctx);
2440 return ret;
2444 * process_registry_globals
2446 static bool process_registry_globals(void)
2448 bool ret;
2450 add_to_file_list(INCLUDE_REGISTRY_NAME, INCLUDE_REGISTRY_NAME);
2452 ret = do_parameter("registry shares", "yes", NULL);
2453 if (!ret) {
2454 return ret;
2457 return process_registry_service(GLOBAL_NAME);
2460 bool process_registry_shares(void)
2462 sbcErr err;
2463 uint32_t count;
2464 struct smbconf_service **service = NULL;
2465 uint32_t num_shares = 0;
2466 TALLOC_CTX *mem_ctx = talloc_stackframe();
2467 struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
2468 bool ret = false;
2470 if (conf_ctx == NULL) {
2471 goto done;
2474 err = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &service);
2475 if (!SBC_ERROR_IS_OK(err)) {
2476 goto done;
2479 ret = true;
2481 for (count = 0; count < num_shares; count++) {
2482 if (strequal(service[count]->name, GLOBAL_NAME)) {
2483 continue;
2485 ret = process_smbconf_service(service[count]);
2486 if (!ret) {
2487 goto done;
2491 /* store the csn */
2492 smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL);
2494 done:
2495 TALLOC_FREE(mem_ctx);
2496 return ret;
2500 * reload those shares from registry that are already
2501 * activated in the services array.
2503 static bool reload_registry_shares(void)
2505 int i;
2506 bool ret = true;
2508 for (i = 0; i < iNumServices; i++) {
2509 if (!VALID(i)) {
2510 continue;
2513 if (ServicePtrs[i]->usershare == USERSHARE_VALID) {
2514 continue;
2517 ret = process_registry_service(ServicePtrs[i]->szService);
2518 if (!ret) {
2519 goto done;
2523 done:
2524 return ret;
2528 #define MAX_INCLUDE_DEPTH 100
2530 static uint8_t include_depth;
2532 static struct file_lists {
2533 struct file_lists *next;
2534 char *name;
2535 char *subfname;
2536 time_t modtime;
2537 } *file_lists = NULL;
2539 /*******************************************************************
2540 Keep a linked list of all config files so we know when one has changed
2541 it's date and needs to be reloaded.
2542 ********************************************************************/
2544 static void add_to_file_list(const char *fname, const char *subfname)
2546 struct file_lists *f = file_lists;
2548 while (f) {
2549 if (f->name && !strcmp(f->name, fname))
2550 break;
2551 f = f->next;
2554 if (!f) {
2555 f = SMB_MALLOC_P(struct file_lists);
2556 if (!f)
2557 return;
2558 f->next = file_lists;
2559 f->name = SMB_STRDUP(fname);
2560 if (!f->name) {
2561 SAFE_FREE(f);
2562 return;
2564 f->subfname = SMB_STRDUP(subfname);
2565 if (!f->subfname) {
2566 SAFE_FREE(f->name);
2567 SAFE_FREE(f);
2568 return;
2570 file_lists = f;
2571 f->modtime = file_modtime(subfname);
2572 } else {
2573 time_t t = file_modtime(subfname);
2574 if (t)
2575 f->modtime = t;
2577 return;
2581 * Free the file lists
2583 static void free_file_list(void)
2585 struct file_lists *f;
2586 struct file_lists *next;
2588 f = file_lists;
2589 while( f ) {
2590 next = f->next;
2591 SAFE_FREE( f->name );
2592 SAFE_FREE( f->subfname );
2593 SAFE_FREE( f );
2594 f = next;
2596 file_lists = NULL;
2601 * Utility function for outsiders to check if we're running on registry.
2603 bool lp_config_backend_is_registry(void)
2605 return (lp_config_backend() == CONFIG_BACKEND_REGISTRY);
2609 * Utility function to check if the config backend is FILE.
2611 bool lp_config_backend_is_file(void)
2613 return (lp_config_backend() == CONFIG_BACKEND_FILE);
2616 /*******************************************************************
2617 Check if a config file has changed date.
2618 ********************************************************************/
2620 bool lp_file_list_changed(void)
2622 struct file_lists *f = file_lists;
2624 DEBUG(6, ("lp_file_list_changed()\n"));
2626 while (f) {
2627 time_t mod_time;
2629 if (strequal(f->name, INCLUDE_REGISTRY_NAME)) {
2630 struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
2632 if (conf_ctx == NULL) {
2633 return false;
2635 if (smbconf_changed(conf_ctx, &conf_last_csn, NULL,
2636 NULL))
2638 DEBUGADD(6, ("registry config changed\n"));
2639 return true;
2641 } else {
2642 char *n2 = NULL;
2643 n2 = talloc_sub_basic(talloc_tos(),
2644 get_current_username(),
2645 current_user_info.domain,
2646 f->name);
2647 if (!n2) {
2648 return false;
2650 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2651 f->name, n2, ctime(&f->modtime)));
2653 mod_time = file_modtime(n2);
2655 if (mod_time &&
2656 ((f->modtime != mod_time) ||
2657 (f->subfname == NULL) ||
2658 (strcmp(n2, f->subfname) != 0)))
2660 DEBUGADD(6,
2661 ("file %s modified: %s\n", n2,
2662 ctime(&mod_time)));
2663 f->modtime = mod_time;
2664 SAFE_FREE(f->subfname);
2665 f->subfname = SMB_STRDUP(n2);
2666 TALLOC_FREE(n2);
2667 return true;
2669 TALLOC_FREE(n2);
2671 f = f->next;
2673 return false;
2678 * Initialize iconv conversion descriptors.
2680 * This is called the first time it is needed, and also called again
2681 * every time the configuration is reloaded, because the charset or
2682 * codepage might have changed.
2684 static void init_iconv(void)
2686 global_iconv_handle = smb_iconv_handle_reinit(NULL, lp_dos_charset(),
2687 lp_unix_charset(),
2688 true, global_iconv_handle);
2691 static bool handle_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2693 if (strcmp(*ptr, pszParmValue) != 0) {
2694 string_set(ptr, pszParmValue);
2695 init_iconv();
2697 return true;
2700 static bool handle_dos_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2702 bool is_utf8 = false;
2703 size_t len = strlen(pszParmValue);
2705 if (len == 4 || len == 5) {
2706 /* Don't use StrCaseCmp here as we don't want to
2707 initialize iconv. */
2708 if ((toupper_m(pszParmValue[0]) == 'U') &&
2709 (toupper_m(pszParmValue[1]) == 'T') &&
2710 (toupper_m(pszParmValue[2]) == 'F')) {
2711 if (len == 4) {
2712 if (pszParmValue[3] == '8') {
2713 is_utf8 = true;
2715 } else {
2716 if (pszParmValue[3] == '-' &&
2717 pszParmValue[4] == '8') {
2718 is_utf8 = true;
2724 if (strcmp(*ptr, pszParmValue) != 0) {
2725 if (is_utf8) {
2726 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
2727 "be UTF8, using (default value) %s instead.\n",
2728 DEFAULT_DOS_CHARSET));
2729 pszParmValue = DEFAULT_DOS_CHARSET;
2731 string_set(ptr, pszParmValue);
2732 init_iconv();
2734 return true;
2737 static bool handle_realm(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2739 bool ret = true;
2740 char *realm = strupper_talloc(talloc_tos(), pszParmValue);
2741 char *dnsdomain = strlower_talloc(realm, pszParmValue);
2743 ret &= string_set(&Globals.szRealm, pszParmValue);
2744 ret &= string_set(&Globals.szRealm_upper, realm);
2745 ret &= string_set(&Globals.szRealm_lower, dnsdomain);
2746 TALLOC_FREE(realm);
2748 return ret;
2751 static bool handle_netbios_aliases(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2753 TALLOC_FREE(Globals.szNetbiosAliases);
2754 Globals.szNetbiosAliases = (const char **)str_list_make_v3(NULL, pszParmValue, NULL);
2755 return set_netbios_aliases(Globals.szNetbiosAliases);
2758 /***************************************************************************
2759 Handle the include operation.
2760 ***************************************************************************/
2761 static bool bAllowIncludeRegistry = true;
2763 static bool handle_include(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2765 char *fname;
2767 if (include_depth >= MAX_INCLUDE_DEPTH) {
2768 DEBUG(0, ("Error: Maximum include depth (%u) exceeded!\n",
2769 include_depth));
2770 return false;
2773 if (strequal(pszParmValue, INCLUDE_REGISTRY_NAME)) {
2774 if (!bAllowIncludeRegistry) {
2775 return true;
2777 if (bInGlobalSection) {
2778 bool ret;
2779 include_depth++;
2780 ret = process_registry_globals();
2781 include_depth--;
2782 return ret;
2783 } else {
2784 DEBUG(1, ("\"include = registry\" only effective "
2785 "in %s section\n", GLOBAL_NAME));
2786 return false;
2790 fname = talloc_sub_basic(talloc_tos(), get_current_username(),
2791 current_user_info.domain,
2792 pszParmValue);
2794 add_to_file_list(pszParmValue, fname);
2796 string_set(ptr, fname);
2798 if (file_exist(fname)) {
2799 bool ret;
2800 include_depth++;
2801 ret = pm_process(fname, do_section, do_parameter, NULL);
2802 include_depth--;
2803 TALLOC_FREE(fname);
2804 return ret;
2807 DEBUG(2, ("Can't find include file %s\n", fname));
2808 TALLOC_FREE(fname);
2809 return true;
2812 /***************************************************************************
2813 Handle the interpretation of the copy parameter.
2814 ***************************************************************************/
2816 static bool handle_copy(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2818 bool bRetval;
2819 int iTemp;
2820 struct loadparm_service serviceTemp;
2822 string_set(ptr, pszParmValue);
2824 init_service(&serviceTemp);
2826 bRetval = false;
2828 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2830 if ((iTemp = getservicebyname(pszParmValue, &serviceTemp)) >= 0) {
2831 if (iTemp == iServiceIndex) {
2832 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2833 } else {
2834 copy_service(ServicePtrs[iServiceIndex],
2835 &serviceTemp,
2836 ServicePtrs[iServiceIndex]->copymap);
2837 bRetval = true;
2839 } else {
2840 DEBUG(0, ("Unable to copy service - source not found: %s\n", pszParmValue));
2841 bRetval = false;
2844 free_service(&serviceTemp);
2845 return (bRetval);
2848 static bool handle_ldap_debug_level(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2850 Globals.ldap_debug_level = lp_int(pszParmValue);
2851 init_ldap_debugging();
2852 return true;
2855 /***************************************************************************
2856 Handle idmap/non unix account uid and gid allocation parameters. The format of these
2857 parameters is:
2859 [global]
2861 idmap uid = 1000-1999
2862 idmap gid = 700-899
2864 We only do simple parsing checks here. The strings are parsed into useful
2865 structures in the idmap daemon code.
2867 ***************************************************************************/
2869 /* Some lp_ routines to return idmap [ug]id information */
2871 static uid_t idmap_uid_low, idmap_uid_high;
2872 static gid_t idmap_gid_low, idmap_gid_high;
2874 bool lp_idmap_uid(uid_t *low, uid_t *high)
2876 if (idmap_uid_low == 0 || idmap_uid_high == 0)
2877 return false;
2879 if (low)
2880 *low = idmap_uid_low;
2882 if (high)
2883 *high = idmap_uid_high;
2885 return true;
2888 bool lp_idmap_gid(gid_t *low, gid_t *high)
2890 if (idmap_gid_low == 0 || idmap_gid_high == 0)
2891 return false;
2893 if (low)
2894 *low = idmap_gid_low;
2896 if (high)
2897 *high = idmap_gid_high;
2899 return true;
2902 static bool handle_idmap_backend(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2904 lp_do_parameter(snum, "idmap config * : backend", pszParmValue);
2906 return true;
2909 /* Do some simple checks on "idmap [ug]id" parameter values */
2911 static bool handle_idmap_uid(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2913 lp_do_parameter(snum, "idmap config * : range", pszParmValue);
2915 return true;
2918 static bool handle_idmap_gid(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
2920 lp_do_parameter(snum, "idmap config * : range", pszParmValue);
2922 return true;
2925 /***************************************************************************
2926 Handle the DEBUG level list.
2927 ***************************************************************************/
2929 static bool handle_debug_list(struct loadparm_context *unused, int snum, const char *pszParmValueIn, char **ptr )
2931 string_set(ptr, pszParmValueIn);
2932 return debug_parse_levels(pszParmValueIn);
2935 /***************************************************************************
2936 Handle ldap suffixes - default to ldapsuffix if sub-suffixes are not defined.
2937 ***************************************************************************/
2939 static const char *append_ldap_suffix(TALLOC_CTX *ctx, const char *str )
2941 const char *suffix_string;
2943 suffix_string = talloc_asprintf(ctx, "%s,%s", str,
2944 Globals.szLdapSuffix );
2945 if ( !suffix_string ) {
2946 DEBUG(0,("append_ldap_suffix: talloc_asprintf() failed!\n"));
2947 return "";
2950 return suffix_string;
2953 const char *lp_ldap_machine_suffix(TALLOC_CTX *ctx)
2955 if (Globals.szLdapMachineSuffix[0])
2956 return append_ldap_suffix(ctx, Globals.szLdapMachineSuffix);
2958 return lp_string(ctx, Globals.szLdapSuffix);
2961 const char *lp_ldap_user_suffix(TALLOC_CTX *ctx)
2963 if (Globals.szLdapUserSuffix[0])
2964 return append_ldap_suffix(ctx, Globals.szLdapUserSuffix);
2966 return lp_string(ctx, Globals.szLdapSuffix);
2969 const char *lp_ldap_group_suffix(TALLOC_CTX *ctx)
2971 if (Globals.szLdapGroupSuffix[0])
2972 return append_ldap_suffix(ctx, Globals.szLdapGroupSuffix);
2974 return lp_string(ctx, Globals.szLdapSuffix);
2977 const char *lp_ldap_idmap_suffix(TALLOC_CTX *ctx)
2979 if (Globals.szLdapIdmapSuffix[0])
2980 return append_ldap_suffix(ctx, Globals.szLdapIdmapSuffix);
2982 return lp_string(ctx, Globals.szLdapSuffix);
2985 /****************************************************************************
2986 set the value for a P_ENUM
2987 ***************************************************************************/
2989 static void lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
2990 int *ptr )
2992 int i;
2994 for (i = 0; parm->enum_list[i].name; i++) {
2995 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
2996 *ptr = parm->enum_list[i].value;
2997 return;
3000 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
3001 pszParmValue, parm->label));
3004 /***************************************************************************
3005 ***************************************************************************/
3007 static bool handle_printing(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
3009 static int parm_num = -1;
3010 struct loadparm_service *s;
3012 if ( parm_num == -1 )
3013 parm_num = map_parameter( "printing" );
3015 lp_set_enum_parm( &parm_table[parm_num], pszParmValue, (int*)ptr );
3017 if ( snum < 0 )
3018 s = &sDefault;
3019 else
3020 s = ServicePtrs[snum];
3022 init_printer_values( s );
3024 return true;
3028 /***************************************************************************
3029 Initialise a copymap.
3030 ***************************************************************************/
3032 static void init_copymap(struct loadparm_service *pservice)
3034 int i;
3036 TALLOC_FREE(pservice->copymap);
3038 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
3039 if (!pservice->copymap)
3040 DEBUG(0,
3041 ("Couldn't allocate copymap!! (size %d)\n",
3042 (int)NUMPARAMETERS));
3043 else
3044 for (i = 0; i < NUMPARAMETERS; i++)
3045 bitmap_set(pservice->copymap, i);
3049 return the parameter pointer for a parameter
3051 void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm)
3053 if (service == NULL) {
3054 if (parm->p_class == P_LOCAL)
3055 return (void *)(((char *)&sDefault)+parm->offset);
3056 else if (parm->p_class == P_GLOBAL)
3057 return (void *)(((char *)&Globals)+parm->offset);
3058 else return NULL;
3059 } else {
3060 return (void *)(((char *)service) + parm->offset);
3064 /***************************************************************************
3065 Return the local pointer to a parameter given the service number and parameter
3066 ***************************************************************************/
3068 void *lp_local_ptr_by_snum(int snum, struct parm_struct *parm)
3070 return lp_parm_ptr(ServicePtrs[snum], parm);
3073 /***************************************************************************
3074 Process a parameter for a particular service number. If snum < 0
3075 then assume we are in the globals.
3076 ***************************************************************************/
3078 bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue)
3080 int parmnum, i;
3081 void *parm_ptr = NULL; /* where we are going to store the result */
3082 struct parmlist_entry **opt_list;
3084 parmnum = map_parameter(pszParmName);
3086 if (parmnum < 0) {
3087 if (strchr(pszParmName, ':') == NULL) {
3088 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n",
3089 pszParmName));
3090 return true;
3094 * We've got a parametric option
3097 opt_list = (snum < 0)
3098 ? &Globals.param_opt : &ServicePtrs[snum]->param_opt;
3099 set_param_opt(opt_list, pszParmName, pszParmValue, 0);
3101 return true;
3104 /* if it's already been set by the command line, then we don't
3105 override here */
3106 if (parm_table[parmnum].flags & FLAG_CMDLINE) {
3107 return true;
3110 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
3111 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
3112 pszParmName));
3115 /* we might point at a service, the default service or a global */
3116 if (snum < 0) {
3117 parm_ptr = lp_parm_ptr(NULL, &parm_table[parmnum]);
3118 } else {
3119 if (parm_table[parmnum].p_class == P_GLOBAL) {
3120 DEBUG(0,
3121 ("Global parameter %s found in service section!\n",
3122 pszParmName));
3123 return true;
3125 parm_ptr = lp_local_ptr_by_snum(snum, &parm_table[parmnum]);
3128 if (snum >= 0) {
3129 if (!ServicePtrs[snum]->copymap)
3130 init_copymap(ServicePtrs[snum]);
3132 /* this handles the aliases - set the copymap for other entries with
3133 the same data pointer */
3134 for (i = 0; parm_table[i].label; i++) {
3135 if ((parm_table[i].offset == parm_table[parmnum].offset)
3136 && (parm_table[i].p_class == parm_table[parmnum].p_class)) {
3137 bitmap_clear(ServicePtrs[snum]->copymap, i);
3142 /* if it is a special case then go ahead */
3143 if (parm_table[parmnum].special) {
3144 return parm_table[parmnum].special(NULL, snum, pszParmValue,
3145 (char **)parm_ptr);
3148 /* now switch on the type of variable it is */
3149 switch (parm_table[parmnum].type)
3151 case P_BOOL:
3152 *(bool *)parm_ptr = lp_bool(pszParmValue);
3153 break;
3155 case P_BOOLREV:
3156 *(bool *)parm_ptr = !lp_bool(pszParmValue);
3157 break;
3159 case P_INTEGER:
3160 *(int *)parm_ptr = lp_int(pszParmValue);
3161 break;
3163 case P_CHAR:
3164 *(char *)parm_ptr = *pszParmValue;
3165 break;
3167 case P_OCTAL:
3168 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
3169 if ( i != 1 ) {
3170 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
3172 break;
3174 case P_BYTES:
3176 uint64_t val;
3177 if (conv_str_size_error(pszParmValue, &val)) {
3178 if (val <= INT_MAX) {
3179 *(int *)parm_ptr = (int)val;
3180 break;
3184 DEBUG(0,("lp_do_parameter(%s): value is not "
3185 "a valid size specifier!\n", pszParmValue));
3186 return false;
3189 case P_LIST:
3190 case P_CMDLIST:
3191 TALLOC_FREE(*((char ***)parm_ptr));
3192 *(char ***)parm_ptr = str_list_make_v3(
3193 NULL, pszParmValue, NULL);
3194 break;
3196 case P_STRING:
3197 string_set((char **)parm_ptr, pszParmValue);
3198 break;
3200 case P_USTRING:
3202 char *upper_string = strupper_talloc(talloc_tos(),
3203 pszParmValue);
3204 string_set((char **)parm_ptr, upper_string);
3205 TALLOC_FREE(upper_string);
3206 break;
3208 case P_ENUM:
3209 lp_set_enum_parm( &parm_table[parmnum], pszParmValue, (int*)parm_ptr );
3210 break;
3211 case P_SEP:
3212 break;
3215 return true;
3218 /***************************************************************************
3219 set a parameter, marking it with FLAG_CMDLINE. Parameters marked as
3220 FLAG_CMDLINE won't be overridden by loads from smb.conf.
3221 ***************************************************************************/
3223 static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmValue, bool store_values)
3225 int parmnum, i;
3226 parmnum = map_parameter(pszParmName);
3227 if (parmnum >= 0) {
3228 parm_table[parmnum].flags &= ~FLAG_CMDLINE;
3229 if (!lp_do_parameter(-1, pszParmName, pszParmValue)) {
3230 return false;
3232 parm_table[parmnum].flags |= FLAG_CMDLINE;
3234 /* we have to also set FLAG_CMDLINE on aliases. Aliases must
3235 * be grouped in the table, so we don't have to search the
3236 * whole table */
3237 for (i=parmnum-1;
3238 i>=0 && parm_table[i].offset == parm_table[parmnum].offset
3239 && parm_table[i].p_class == parm_table[parmnum].p_class;
3240 i--) {
3241 parm_table[i].flags |= FLAG_CMDLINE;
3243 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset
3244 && parm_table[i].p_class == parm_table[parmnum].p_class;i++) {
3245 parm_table[i].flags |= FLAG_CMDLINE;
3248 if (store_values) {
3249 store_lp_set_cmdline(pszParmName, pszParmValue);
3251 return true;
3254 /* it might be parametric */
3255 if (strchr(pszParmName, ':') != NULL) {
3256 set_param_opt(&Globals.param_opt, pszParmName, pszParmValue, FLAG_CMDLINE);
3257 if (store_values) {
3258 store_lp_set_cmdline(pszParmName, pszParmValue);
3260 return true;
3263 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
3264 return true;
3267 bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
3269 return lp_set_cmdline_helper(pszParmName, pszParmValue, true);
3272 /***************************************************************************
3273 Process a parameter.
3274 ***************************************************************************/
3276 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
3277 void *userdata)
3279 if (!bInGlobalSection && bGlobalOnly)
3280 return true;
3282 DEBUGADD(4, ("doing parameter %s = %s\n", pszParmName, pszParmValue));
3284 return (lp_do_parameter(bInGlobalSection ? -2 : iServiceIndex,
3285 pszParmName, pszParmValue));
3289 set a option from the commandline in 'a=b' format. Use to support --option
3291 bool lp_set_option(const char *option)
3293 char *p, *s;
3294 bool ret;
3296 s = talloc_strdup(NULL, option);
3297 if (!s) {
3298 return false;
3301 p = strchr(s, '=');
3302 if (!p) {
3303 talloc_free(s);
3304 return false;
3307 *p = 0;
3309 /* skip white spaces after the = sign */
3310 do {
3311 p++;
3312 } while (*p == ' ');
3314 ret = lp_set_cmdline(s, p);
3315 talloc_free(s);
3316 return ret;
3319 /**************************************************************************
3320 Print a parameter of the specified type.
3321 ***************************************************************************/
3323 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
3325 /* For the seperation of lists values that we print below */
3326 const char *list_sep = ", ";
3327 int i;
3328 switch (p->type)
3330 case P_ENUM:
3331 for (i = 0; p->enum_list[i].name; i++) {
3332 if (*(int *)ptr == p->enum_list[i].value) {
3333 fprintf(f, "%s",
3334 p->enum_list[i].name);
3335 break;
3338 break;
3340 case P_BOOL:
3341 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
3342 break;
3344 case P_BOOLREV:
3345 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
3346 break;
3348 case P_INTEGER:
3349 case P_BYTES:
3350 fprintf(f, "%d", *(int *)ptr);
3351 break;
3353 case P_CHAR:
3354 fprintf(f, "%c", *(char *)ptr);
3355 break;
3357 case P_OCTAL: {
3358 int val = *(int *)ptr;
3359 if (val == -1) {
3360 fprintf(f, "-1");
3361 } else {
3362 fprintf(f, "0%o", val);
3364 break;
3367 case P_CMDLIST:
3368 list_sep = " ";
3369 /* fall through */
3370 case P_LIST:
3371 if ((char ***)ptr && *(char ***)ptr) {
3372 char **list = *(char ***)ptr;
3373 for (; *list; list++) {
3374 /* surround strings with whitespace in double quotes */
3375 if (*(list+1) == NULL) {
3376 /* last item, no extra separator */
3377 list_sep = "";
3379 if ( strchr_m( *list, ' ' ) ) {
3380 fprintf(f, "\"%s\"%s", *list, list_sep);
3381 } else {
3382 fprintf(f, "%s%s", *list, list_sep);
3386 break;
3388 case P_STRING:
3389 case P_USTRING:
3390 if (*(char **)ptr) {
3391 fprintf(f, "%s", *(char **)ptr);
3393 break;
3394 case P_SEP:
3395 break;
3399 /***************************************************************************
3400 Check if two parameters are equal.
3401 ***************************************************************************/
3403 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
3405 switch (type) {
3406 case P_BOOL:
3407 case P_BOOLREV:
3408 return (*((bool *)ptr1) == *((bool *)ptr2));
3410 case P_INTEGER:
3411 case P_ENUM:
3412 case P_OCTAL:
3413 case P_BYTES:
3414 return (*((int *)ptr1) == *((int *)ptr2));
3416 case P_CHAR:
3417 return (*((char *)ptr1) == *((char *)ptr2));
3419 case P_LIST:
3420 case P_CMDLIST:
3421 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
3423 case P_STRING:
3424 case P_USTRING:
3426 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
3427 if (p1 && !*p1)
3428 p1 = NULL;
3429 if (p2 && !*p2)
3430 p2 = NULL;
3431 return (p1 == p2 || strequal(p1, p2));
3433 case P_SEP:
3434 break;
3436 return false;
3439 /***************************************************************************
3440 Initialize any local varients in the sDefault table.
3441 ***************************************************************************/
3443 void init_locals(void)
3445 /* None as yet. */
3448 /***************************************************************************
3449 Process a new section (service). At this stage all sections are services.
3450 Later we'll have special sections that permit server parameters to be set.
3451 Returns true on success, false on failure.
3452 ***************************************************************************/
3454 static bool do_section(const char *pszSectionName, void *userdata)
3456 bool bRetval;
3457 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3458 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3459 bRetval = false;
3461 /* if we were in a global section then do the local inits */
3462 if (bInGlobalSection && !isglobal)
3463 init_locals();
3465 /* if we've just struck a global section, note the fact. */
3466 bInGlobalSection = isglobal;
3468 /* check for multiple global sections */
3469 if (bInGlobalSection) {
3470 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
3471 return true;
3474 if (!bInGlobalSection && bGlobalOnly)
3475 return true;
3477 /* if we have a current service, tidy it up before moving on */
3478 bRetval = true;
3480 if (iServiceIndex >= 0)
3481 bRetval = service_ok(iServiceIndex);
3483 /* if all is still well, move to the next record in the services array */
3484 if (bRetval) {
3485 /* We put this here to avoid an odd message order if messages are */
3486 /* issued by the post-processing of a previous section. */
3487 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
3489 iServiceIndex = add_a_service(&sDefault, pszSectionName);
3490 if (iServiceIndex < 0) {
3491 DEBUG(0, ("Failed to add a new service\n"));
3492 return false;
3494 /* Clean all parametric options for service */
3495 /* They will be added during parsing again */
3496 free_param_opts(&ServicePtrs[iServiceIndex]->param_opt);
3499 return bRetval;
3503 /***************************************************************************
3504 Determine if a partcular base parameter is currentl set to the default value.
3505 ***************************************************************************/
3507 static bool is_default(int i)
3509 if (!defaults_saved)
3510 return false;
3511 switch (parm_table[i].type) {
3512 case P_LIST:
3513 case P_CMDLIST:
3514 return str_list_equal((const char **)parm_table[i].def.lvalue,
3515 *(const char ***)lp_parm_ptr(NULL,
3516 &parm_table[i]));
3517 case P_STRING:
3518 case P_USTRING:
3519 return strequal(parm_table[i].def.svalue,
3520 *(char **)lp_parm_ptr(NULL,
3521 &parm_table[i]));
3522 case P_BOOL:
3523 case P_BOOLREV:
3524 return parm_table[i].def.bvalue ==
3525 *(bool *)lp_parm_ptr(NULL,
3526 &parm_table[i]);
3527 case P_CHAR:
3528 return parm_table[i].def.cvalue ==
3529 *(char *)lp_parm_ptr(NULL,
3530 &parm_table[i]);
3531 case P_INTEGER:
3532 case P_OCTAL:
3533 case P_ENUM:
3534 case P_BYTES:
3535 return parm_table[i].def.ivalue ==
3536 *(int *)lp_parm_ptr(NULL,
3537 &parm_table[i]);
3538 case P_SEP:
3539 break;
3541 return false;
3544 /***************************************************************************
3545 Display the contents of the global structure.
3546 ***************************************************************************/
3548 static void dump_globals(FILE *f)
3550 int i;
3551 struct parmlist_entry *data;
3553 fprintf(f, "[global]\n");
3555 for (i = 0; parm_table[i].label; i++)
3556 if (parm_table[i].p_class == P_GLOBAL &&
3557 !(parm_table[i].flags & FLAG_META) &&
3558 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3559 if (defaults_saved && is_default(i))
3560 continue;
3561 fprintf(f, "\t%s = ", parm_table[i].label);
3562 print_parameter(&parm_table[i], lp_parm_ptr(NULL,
3563 &parm_table[i]),
3565 fprintf(f, "\n");
3567 if (Globals.param_opt != NULL) {
3568 data = Globals.param_opt;
3569 while(data) {
3570 fprintf(f, "\t%s = %s\n", data->key, data->value);
3571 data = data->next;
3577 /***************************************************************************
3578 Return true if a local parameter is currently set to the global default.
3579 ***************************************************************************/
3581 bool lp_is_default(int snum, struct parm_struct *parm)
3583 return equal_parameter(parm->type,
3584 lp_parm_ptr(ServicePtrs[snum], parm),
3585 lp_parm_ptr(NULL, parm));
3588 /***************************************************************************
3589 Display the contents of a single services record.
3590 ***************************************************************************/
3592 static void dump_a_service(struct loadparm_service *pService, FILE * f)
3594 int i;
3595 struct parmlist_entry *data;
3597 if (pService != &sDefault)
3598 fprintf(f, "[%s]\n", pService->szService);
3600 for (i = 0; parm_table[i].label; i++) {
3602 if (parm_table[i].p_class == P_LOCAL &&
3603 !(parm_table[i].flags & FLAG_META) &&
3604 (*parm_table[i].label != '-') &&
3605 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3607 if (pService == &sDefault) {
3608 if (defaults_saved && is_default(i))
3609 continue;
3610 } else {
3611 if (equal_parameter(parm_table[i].type,
3612 lp_parm_ptr(pService, &parm_table[i]),
3613 lp_parm_ptr(NULL, &parm_table[i])))
3614 continue;
3617 fprintf(f, "\t%s = ", parm_table[i].label);
3618 print_parameter(&parm_table[i],
3619 lp_parm_ptr(pService, &parm_table[i]),
3621 fprintf(f, "\n");
3625 if (pService->param_opt != NULL) {
3626 data = pService->param_opt;
3627 while(data) {
3628 fprintf(f, "\t%s = %s\n", data->key, data->value);
3629 data = data->next;
3634 /***************************************************************************
3635 Display the contents of a parameter of a single services record.
3636 ***************************************************************************/
3638 bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
3640 int i;
3641 bool result = false;
3642 parm_class p_class;
3643 unsigned flag = 0;
3644 fstring local_parm_name;
3645 char *parm_opt;
3646 const char *parm_opt_value;
3648 /* check for parametrical option */
3649 fstrcpy( local_parm_name, parm_name);
3650 parm_opt = strchr( local_parm_name, ':');
3652 if (parm_opt) {
3653 *parm_opt = '\0';
3654 parm_opt++;
3655 if (strlen(parm_opt)) {
3656 parm_opt_value = lp_parm_const_string( snum,
3657 local_parm_name, parm_opt, NULL);
3658 if (parm_opt_value) {
3659 printf( "%s\n", parm_opt_value);
3660 result = true;
3663 return result;
3666 /* check for a key and print the value */
3667 if (isGlobal) {
3668 p_class = P_GLOBAL;
3669 flag = FLAG_GLOBAL;
3670 } else
3671 p_class = P_LOCAL;
3673 for (i = 0; parm_table[i].label; i++) {
3674 if (strwicmp(parm_table[i].label, parm_name) == 0 &&
3675 !(parm_table[i].flags & FLAG_META) &&
3676 (parm_table[i].p_class == p_class || parm_table[i].flags & flag) &&
3677 (*parm_table[i].label != '-') &&
3678 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3680 void *ptr;
3682 if (isGlobal) {
3683 ptr = lp_parm_ptr(NULL,
3684 &parm_table[i]);
3685 } else {
3686 ptr = lp_parm_ptr(ServicePtrs[snum],
3687 &parm_table[i]);
3690 print_parameter(&parm_table[i],
3691 ptr, f);
3692 fprintf(f, "\n");
3693 result = true;
3694 break;
3698 return result;
3701 /***************************************************************************
3702 Return info about the requested parameter (given as a string).
3703 Return NULL when the string is not a valid parameter name.
3704 ***************************************************************************/
3706 struct parm_struct *lp_get_parameter(const char *param_name)
3708 int num = map_parameter(param_name);
3710 if (num < 0) {
3711 return NULL;
3714 return &parm_table[num];
3717 /***************************************************************************
3718 Return info about the next parameter in a service.
3719 snum==GLOBAL_SECTION_SNUM gives the globals.
3720 Return NULL when out of parameters.
3721 ***************************************************************************/
3723 struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
3725 if (snum < 0) {
3726 /* do the globals */
3727 for (; parm_table[*i].label; (*i)++) {
3728 if (parm_table[*i].p_class == P_SEPARATOR)
3729 return &parm_table[(*i)++];
3731 if ((*parm_table[*i].label == '-'))
3732 continue;
3734 if ((*i) > 0
3735 && (parm_table[*i].offset ==
3736 parm_table[(*i) - 1].offset)
3737 && (parm_table[*i].p_class ==
3738 parm_table[(*i) - 1].p_class))
3739 continue;
3741 if (is_default(*i) && !allparameters)
3742 continue;
3744 return &parm_table[(*i)++];
3746 } else {
3747 struct loadparm_service *pService = ServicePtrs[snum];
3749 for (; parm_table[*i].label; (*i)++) {
3750 if (parm_table[*i].p_class == P_SEPARATOR)
3751 return &parm_table[(*i)++];
3753 if (parm_table[*i].p_class == P_LOCAL &&
3754 (*parm_table[*i].label != '-') &&
3755 ((*i) == 0 ||
3756 (parm_table[*i].offset !=
3757 parm_table[(*i) - 1].offset)))
3759 if (allparameters ||
3760 !equal_parameter(parm_table[*i].type,
3761 lp_parm_ptr(pService,
3762 &parm_table[*i]),
3763 lp_parm_ptr(NULL,
3764 &parm_table[*i])))
3766 return &parm_table[(*i)++];
3772 return NULL;
3776 #if 0
3777 /***************************************************************************
3778 Display the contents of a single copy structure.
3779 ***************************************************************************/
3780 static void dump_copy_map(bool *pcopymap)
3782 int i;
3783 if (!pcopymap)
3784 return;
3786 printf("\n\tNon-Copied parameters:\n");
3788 for (i = 0; parm_table[i].label; i++)
3789 if (parm_table[i].p_class == P_LOCAL &&
3790 parm_table[i].ptr && !pcopymap[i] &&
3791 (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr)))
3793 printf("\t\t%s\n", parm_table[i].label);
3796 #endif
3798 /***************************************************************************
3799 Return TRUE if the passed service number is within range.
3800 ***************************************************************************/
3802 bool lp_snum_ok(int iService)
3804 return (LP_SNUM_OK(iService) && ServicePtrs[iService]->bAvailable);
3807 /***************************************************************************
3808 Auto-load some home services.
3809 ***************************************************************************/
3811 static void lp_add_auto_services(char *str)
3813 char *s;
3814 char *p;
3815 int homes;
3816 char *saveptr;
3818 if (!str)
3819 return;
3821 s = SMB_STRDUP(str);
3822 if (!s)
3823 return;
3825 homes = lp_servicenumber(HOMES_NAME);
3827 for (p = strtok_r(s, LIST_SEP, &saveptr); p;
3828 p = strtok_r(NULL, LIST_SEP, &saveptr)) {
3829 char *home;
3831 if (lp_servicenumber(p) >= 0)
3832 continue;
3834 home = get_user_home_dir(talloc_tos(), p);
3836 if (home && home[0] && homes >= 0)
3837 lp_add_home(p, homes, p, home);
3839 TALLOC_FREE(home);
3841 SAFE_FREE(s);
3844 /***************************************************************************
3845 Auto-load one printer.
3846 ***************************************************************************/
3848 void lp_add_one_printer(const char *name, const char *comment,
3849 const char *location, void *pdata)
3851 int printers = lp_servicenumber(PRINTERS_NAME);
3852 int i;
3854 if (lp_servicenumber(name) < 0) {
3855 lp_add_printer(name, printers);
3856 if ((i = lp_servicenumber(name)) >= 0) {
3857 string_set(&ServicePtrs[i]->comment, comment);
3858 ServicePtrs[i]->autoloaded = true;
3863 /***************************************************************************
3864 Have we loaded a services file yet?
3865 ***************************************************************************/
3867 bool lp_loaded(void)
3869 return (bLoaded);
3872 /***************************************************************************
3873 Unload unused services.
3874 ***************************************************************************/
3876 void lp_killunused(struct smbd_server_connection *sconn,
3877 bool (*snumused) (struct smbd_server_connection *, int))
3879 int i;
3880 for (i = 0; i < iNumServices; i++) {
3881 if (!VALID(i))
3882 continue;
3884 /* don't kill autoloaded or usershare services */
3885 if ( ServicePtrs[i]->autoloaded ||
3886 ServicePtrs[i]->usershare == USERSHARE_VALID) {
3887 continue;
3890 if (!snumused || !snumused(sconn, i)) {
3891 free_service_byindex(i);
3897 * Kill all except autoloaded and usershare services - convenience wrapper
3899 void lp_kill_all_services(void)
3901 lp_killunused(NULL, NULL);
3904 /***************************************************************************
3905 Unload a service.
3906 ***************************************************************************/
3908 void lp_killservice(int iServiceIn)
3910 if (VALID(iServiceIn)) {
3911 free_service_byindex(iServiceIn);
3915 /***************************************************************************
3916 Save the curent values of all global and sDefault parameters into the
3917 defaults union. This allows swat and testparm to show only the
3918 changed (ie. non-default) parameters.
3919 ***************************************************************************/
3921 static void lp_save_defaults(void)
3923 int i;
3924 for (i = 0; parm_table[i].label; i++) {
3925 if (i > 0 && parm_table[i].offset == parm_table[i - 1].offset
3926 && parm_table[i].p_class == parm_table[i - 1].p_class)
3927 continue;
3928 switch (parm_table[i].type) {
3929 case P_LIST:
3930 case P_CMDLIST:
3931 parm_table[i].def.lvalue = str_list_copy(
3932 NULL, *(const char ***)lp_parm_ptr(NULL, &parm_table[i]));
3933 break;
3934 case P_STRING:
3935 case P_USTRING:
3936 parm_table[i].def.svalue = SMB_STRDUP(*(char **)lp_parm_ptr(NULL, &parm_table[i]));
3937 break;
3938 case P_BOOL:
3939 case P_BOOLREV:
3940 parm_table[i].def.bvalue =
3941 *(bool *)lp_parm_ptr(NULL, &parm_table[i]);
3942 break;
3943 case P_CHAR:
3944 parm_table[i].def.cvalue =
3945 *(char *)lp_parm_ptr(NULL, &parm_table[i]);
3946 break;
3947 case P_INTEGER:
3948 case P_OCTAL:
3949 case P_ENUM:
3950 case P_BYTES:
3951 parm_table[i].def.ivalue =
3952 *(int *)lp_parm_ptr(NULL, &parm_table[i]);
3953 break;
3954 case P_SEP:
3955 break;
3958 defaults_saved = true;
3961 /***********************************************************
3962 If we should send plaintext/LANMAN passwords in the clinet
3963 ************************************************************/
3965 static void set_allowed_client_auth(void)
3967 if (Globals.bClientNTLMv2Auth) {
3968 Globals.bClientLanManAuth = false;
3970 if (!Globals.bClientLanManAuth) {
3971 Globals.bClientPlaintextAuth = false;
3975 /***************************************************************************
3976 JRA.
3977 The following code allows smbd to read a user defined share file.
3978 Yes, this is my intent. Yes, I'm comfortable with that...
3980 THE FOLLOWING IS SECURITY CRITICAL CODE.
3982 It washes your clothes, it cleans your house, it guards you while you sleep...
3983 Do not f%^k with it....
3984 ***************************************************************************/
3986 #define MAX_USERSHARE_FILE_SIZE (10*1024)
3988 /***************************************************************************
3989 Check allowed stat state of a usershare file.
3990 Ensure we print out who is dicking with us so the admin can
3991 get their sorry ass fired.
3992 ***************************************************************************/
3994 static bool check_usershare_stat(const char *fname,
3995 const SMB_STRUCT_STAT *psbuf)
3997 if (!S_ISREG(psbuf->st_ex_mode)) {
3998 DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
3999 "not a regular file\n",
4000 fname, (unsigned int)psbuf->st_ex_uid ));
4001 return false;
4004 /* Ensure this doesn't have the other write bit set. */
4005 if (psbuf->st_ex_mode & S_IWOTH) {
4006 DEBUG(0,("check_usershare_stat: file %s owned by uid %u allows "
4007 "public write. Refusing to allow as a usershare file.\n",
4008 fname, (unsigned int)psbuf->st_ex_uid ));
4009 return false;
4012 /* Should be 10k or less. */
4013 if (psbuf->st_ex_size > MAX_USERSHARE_FILE_SIZE) {
4014 DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
4015 "too large (%u) to be a user share file.\n",
4016 fname, (unsigned int)psbuf->st_ex_uid,
4017 (unsigned int)psbuf->st_ex_size ));
4018 return false;
4021 return true;
4024 /***************************************************************************
4025 Parse the contents of a usershare file.
4026 ***************************************************************************/
4028 enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
4029 SMB_STRUCT_STAT *psbuf,
4030 const char *servicename,
4031 int snum,
4032 char **lines,
4033 int numlines,
4034 char **pp_sharepath,
4035 char **pp_comment,
4036 char **pp_cp_servicename,
4037 struct security_descriptor **ppsd,
4038 bool *pallow_guest)
4040 const char **prefixallowlist = lp_usershare_prefix_allow_list();
4041 const char **prefixdenylist = lp_usershare_prefix_deny_list();
4042 int us_vers;
4043 DIR *dp;
4044 SMB_STRUCT_STAT sbuf;
4045 char *sharepath = NULL;
4046 char *comment = NULL;
4048 *pp_sharepath = NULL;
4049 *pp_comment = NULL;
4051 *pallow_guest = false;
4053 if (numlines < 4) {
4054 return USERSHARE_MALFORMED_FILE;
4057 if (strcmp(lines[0], "#VERSION 1") == 0) {
4058 us_vers = 1;
4059 } else if (strcmp(lines[0], "#VERSION 2") == 0) {
4060 us_vers = 2;
4061 if (numlines < 5) {
4062 return USERSHARE_MALFORMED_FILE;
4064 } else {
4065 return USERSHARE_BAD_VERSION;
4068 if (strncmp(lines[1], "path=", 5) != 0) {
4069 return USERSHARE_MALFORMED_PATH;
4072 sharepath = talloc_strdup(ctx, &lines[1][5]);
4073 if (!sharepath) {
4074 return USERSHARE_POSIX_ERR;
4076 trim_string(sharepath, " ", " ");
4078 if (strncmp(lines[2], "comment=", 8) != 0) {
4079 return USERSHARE_MALFORMED_COMMENT_DEF;
4082 comment = talloc_strdup(ctx, &lines[2][8]);
4083 if (!comment) {
4084 return USERSHARE_POSIX_ERR;
4086 trim_string(comment, " ", " ");
4087 trim_char(comment, '"', '"');
4089 if (strncmp(lines[3], "usershare_acl=", 14) != 0) {
4090 return USERSHARE_MALFORMED_ACL_DEF;
4093 if (!parse_usershare_acl(ctx, &lines[3][14], ppsd)) {
4094 return USERSHARE_ACL_ERR;
4097 if (us_vers == 2) {
4098 if (strncmp(lines[4], "guest_ok=", 9) != 0) {
4099 return USERSHARE_MALFORMED_ACL_DEF;
4101 if (lines[4][9] == 'y') {
4102 *pallow_guest = true;
4105 /* Backwards compatible extension to file version #2. */
4106 if (numlines > 5) {
4107 if (strncmp(lines[5], "sharename=", 10) != 0) {
4108 return USERSHARE_MALFORMED_SHARENAME_DEF;
4110 if (!strequal(&lines[5][10], servicename)) {
4111 return USERSHARE_BAD_SHARENAME;
4113 *pp_cp_servicename = talloc_strdup(ctx, &lines[5][10]);
4114 if (!*pp_cp_servicename) {
4115 return USERSHARE_POSIX_ERR;
4120 if (*pp_cp_servicename == NULL) {
4121 *pp_cp_servicename = talloc_strdup(ctx, servicename);
4122 if (!*pp_cp_servicename) {
4123 return USERSHARE_POSIX_ERR;
4127 if (snum != -1 && (strcmp(sharepath, ServicePtrs[snum]->szPath) == 0)) {
4128 /* Path didn't change, no checks needed. */
4129 *pp_sharepath = sharepath;
4130 *pp_comment = comment;
4131 return USERSHARE_OK;
4134 /* The path *must* be absolute. */
4135 if (sharepath[0] != '/') {
4136 DEBUG(2,("parse_usershare_file: share %s: path %s is not an absolute path.\n",
4137 servicename, sharepath));
4138 return USERSHARE_PATH_NOT_ABSOLUTE;
4141 /* If there is a usershare prefix deny list ensure one of these paths
4142 doesn't match the start of the user given path. */
4143 if (prefixdenylist) {
4144 int i;
4145 for ( i=0; prefixdenylist[i]; i++ ) {
4146 DEBUG(10,("parse_usershare_file: share %s : checking prefixdenylist[%d]='%s' against %s\n",
4147 servicename, i, prefixdenylist[i], sharepath ));
4148 if (memcmp( sharepath, prefixdenylist[i], strlen(prefixdenylist[i])) == 0) {
4149 DEBUG(2,("parse_usershare_file: share %s path %s starts with one of the "
4150 "usershare prefix deny list entries.\n",
4151 servicename, sharepath));
4152 return USERSHARE_PATH_IS_DENIED;
4157 /* If there is a usershare prefix allow list ensure one of these paths
4158 does match the start of the user given path. */
4160 if (prefixallowlist) {
4161 int i;
4162 for ( i=0; prefixallowlist[i]; i++ ) {
4163 DEBUG(10,("parse_usershare_file: share %s checking prefixallowlist[%d]='%s' against %s\n",
4164 servicename, i, prefixallowlist[i], sharepath ));
4165 if (memcmp( sharepath, prefixallowlist[i], strlen(prefixallowlist[i])) == 0) {
4166 break;
4169 if (prefixallowlist[i] == NULL) {
4170 DEBUG(2,("parse_usershare_file: share %s path %s doesn't start with one of the "
4171 "usershare prefix allow list entries.\n",
4172 servicename, sharepath));
4173 return USERSHARE_PATH_NOT_ALLOWED;
4177 /* Ensure this is pointing to a directory. */
4178 dp = opendir(sharepath);
4180 if (!dp) {
4181 DEBUG(2,("parse_usershare_file: share %s path %s is not a directory.\n",
4182 servicename, sharepath));
4183 return USERSHARE_PATH_NOT_DIRECTORY;
4186 /* Ensure the owner of the usershare file has permission to share
4187 this directory. */
4189 if (sys_stat(sharepath, &sbuf, false) == -1) {
4190 DEBUG(2,("parse_usershare_file: share %s : stat failed on path %s. %s\n",
4191 servicename, sharepath, strerror(errno) ));
4192 closedir(dp);
4193 return USERSHARE_POSIX_ERR;
4196 closedir(dp);
4198 if (!S_ISDIR(sbuf.st_ex_mode)) {
4199 DEBUG(2,("parse_usershare_file: share %s path %s is not a directory.\n",
4200 servicename, sharepath ));
4201 return USERSHARE_PATH_NOT_DIRECTORY;
4204 /* Check if sharing is restricted to owner-only. */
4205 /* psbuf is the stat of the usershare definition file,
4206 sbuf is the stat of the target directory to be shared. */
4208 if (lp_usershare_owner_only()) {
4209 /* root can share anything. */
4210 if ((psbuf->st_ex_uid != 0) && (sbuf.st_ex_uid != psbuf->st_ex_uid)) {
4211 return USERSHARE_PATH_NOT_ALLOWED;
4215 *pp_sharepath = sharepath;
4216 *pp_comment = comment;
4217 return USERSHARE_OK;
4220 /***************************************************************************
4221 Deal with a usershare file.
4222 Returns:
4223 >= 0 - snum
4224 -1 - Bad name, invalid contents.
4225 - service name already existed and not a usershare, problem
4226 with permissions to share directory etc.
4227 ***************************************************************************/
4229 static int process_usershare_file(const char *dir_name, const char *file_name, int snum_template)
4231 SMB_STRUCT_STAT sbuf;
4232 SMB_STRUCT_STAT lsbuf;
4233 char *fname = NULL;
4234 char *sharepath = NULL;
4235 char *comment = NULL;
4236 char *cp_service_name = NULL;
4237 char **lines = NULL;
4238 int numlines = 0;
4239 int fd = -1;
4240 int iService = -1;
4241 TALLOC_CTX *ctx = talloc_stackframe();
4242 struct security_descriptor *psd = NULL;
4243 bool guest_ok = false;
4244 char *canon_name = NULL;
4245 bool added_service = false;
4246 int ret = -1;
4248 /* Ensure share name doesn't contain invalid characters. */
4249 if (!validate_net_name(file_name, INVALID_SHARENAME_CHARS, strlen(file_name))) {
4250 DEBUG(0,("process_usershare_file: share name %s contains "
4251 "invalid characters (any of %s)\n",
4252 file_name, INVALID_SHARENAME_CHARS ));
4253 goto out;
4256 canon_name = canonicalize_servicename(ctx, file_name);
4257 if (!canon_name) {
4258 goto out;
4261 fname = talloc_asprintf(ctx, "%s/%s", dir_name, file_name);
4262 if (!fname) {
4263 goto out;
4266 /* Minimize the race condition by doing an lstat before we
4267 open and fstat. Ensure this isn't a symlink link. */
4269 if (sys_lstat(fname, &lsbuf, false) != 0) {
4270 DEBUG(0,("process_usershare_file: stat of %s failed. %s\n",
4271 fname, strerror(errno) ));
4272 goto out;
4275 /* This must be a regular file, not a symlink, directory or
4276 other strange filetype. */
4277 if (!check_usershare_stat(fname, &lsbuf)) {
4278 goto out;
4282 TDB_DATA data;
4283 NTSTATUS status;
4285 status = dbwrap_fetch_bystring(ServiceHash, canon_name,
4286 canon_name, &data);
4288 iService = -1;
4290 if (NT_STATUS_IS_OK(status) &&
4291 (data.dptr != NULL) &&
4292 (data.dsize == sizeof(iService))) {
4293 memcpy(&iService, data.dptr, sizeof(iService));
4297 if (iService != -1 &&
4298 timespec_compare(&ServicePtrs[iService]->usershare_last_mod,
4299 &lsbuf.st_ex_mtime) == 0) {
4300 /* Nothing changed - Mark valid and return. */
4301 DEBUG(10,("process_usershare_file: service %s not changed.\n",
4302 canon_name ));
4303 ServicePtrs[iService]->usershare = USERSHARE_VALID;
4304 ret = iService;
4305 goto out;
4308 /* Try and open the file read only - no symlinks allowed. */
4309 #ifdef O_NOFOLLOW
4310 fd = open(fname, O_RDONLY|O_NOFOLLOW, 0);
4311 #else
4312 fd = open(fname, O_RDONLY, 0);
4313 #endif
4315 if (fd == -1) {
4316 DEBUG(0,("process_usershare_file: unable to open %s. %s\n",
4317 fname, strerror(errno) ));
4318 goto out;
4321 /* Now fstat to be *SURE* it's a regular file. */
4322 if (sys_fstat(fd, &sbuf, false) != 0) {
4323 close(fd);
4324 DEBUG(0,("process_usershare_file: fstat of %s failed. %s\n",
4325 fname, strerror(errno) ));
4326 goto out;
4329 /* Is it the same dev/inode as was lstated ? */
4330 if (!check_same_stat(&lsbuf, &sbuf)) {
4331 close(fd);
4332 DEBUG(0,("process_usershare_file: fstat of %s is a different file from lstat. "
4333 "Symlink spoofing going on ?\n", fname ));
4334 goto out;
4337 /* This must be a regular file, not a symlink, directory or
4338 other strange filetype. */
4339 if (!check_usershare_stat(fname, &sbuf)) {
4340 goto out;
4343 lines = fd_lines_load(fd, &numlines, MAX_USERSHARE_FILE_SIZE, NULL);
4345 close(fd);
4346 if (lines == NULL) {
4347 DEBUG(0,("process_usershare_file: loading file %s owned by %u failed.\n",
4348 fname, (unsigned int)sbuf.st_ex_uid ));
4349 goto out;
4352 if (parse_usershare_file(ctx, &sbuf, file_name,
4353 iService, lines, numlines, &sharepath,
4354 &comment, &cp_service_name,
4355 &psd, &guest_ok) != USERSHARE_OK) {
4356 goto out;
4359 /* Everything ok - add the service possibly using a template. */
4360 if (iService < 0) {
4361 const struct loadparm_service *sp = &sDefault;
4362 if (snum_template != -1) {
4363 sp = ServicePtrs[snum_template];
4366 if ((iService = add_a_service(sp, cp_service_name)) < 0) {
4367 DEBUG(0, ("process_usershare_file: Failed to add "
4368 "new service %s\n", cp_service_name));
4369 goto out;
4372 added_service = true;
4374 /* Read only is controlled by usershare ACL below. */
4375 ServicePtrs[iService]->bRead_only = false;
4378 /* Write the ACL of the new/modified share. */
4379 if (!set_share_security(canon_name, psd)) {
4380 DEBUG(0, ("process_usershare_file: Failed to set share "
4381 "security for user share %s\n",
4382 canon_name ));
4383 goto out;
4386 /* If from a template it may be marked invalid. */
4387 ServicePtrs[iService]->valid = true;
4389 /* Set the service as a valid usershare. */
4390 ServicePtrs[iService]->usershare = USERSHARE_VALID;
4392 /* Set guest access. */
4393 if (lp_usershare_allow_guests()) {
4394 ServicePtrs[iService]->bGuest_ok = guest_ok;
4397 /* And note when it was loaded. */
4398 ServicePtrs[iService]->usershare_last_mod = sbuf.st_ex_mtime;
4399 string_set(&ServicePtrs[iService]->szPath, sharepath);
4400 string_set(&ServicePtrs[iService]->comment, comment);
4402 ret = iService;
4404 out:
4406 if (ret == -1 && iService != -1 && added_service) {
4407 lp_remove_service(iService);
4410 TALLOC_FREE(lines);
4411 TALLOC_FREE(ctx);
4412 return ret;
4415 /***************************************************************************
4416 Checks if a usershare entry has been modified since last load.
4417 ***************************************************************************/
4419 static bool usershare_exists(int iService, struct timespec *last_mod)
4421 SMB_STRUCT_STAT lsbuf;
4422 const char *usersharepath = Globals.szUsersharePath;
4423 char *fname;
4425 if (asprintf(&fname, "%s/%s",
4426 usersharepath,
4427 ServicePtrs[iService]->szService) < 0) {
4428 return false;
4431 if (sys_lstat(fname, &lsbuf, false) != 0) {
4432 SAFE_FREE(fname);
4433 return false;
4436 if (!S_ISREG(lsbuf.st_ex_mode)) {
4437 SAFE_FREE(fname);
4438 return false;
4441 SAFE_FREE(fname);
4442 *last_mod = lsbuf.st_ex_mtime;
4443 return true;
4446 /***************************************************************************
4447 Load a usershare service by name. Returns a valid servicenumber or -1.
4448 ***************************************************************************/
4450 int load_usershare_service(const char *servicename)
4452 SMB_STRUCT_STAT sbuf;
4453 const char *usersharepath = Globals.szUsersharePath;
4454 int max_user_shares = Globals.iUsershareMaxShares;
4455 int snum_template = -1;
4457 if (*usersharepath == 0 || max_user_shares == 0) {
4458 return -1;
4461 if (sys_stat(usersharepath, &sbuf, false) != 0) {
4462 DEBUG(0,("load_usershare_service: stat of %s failed. %s\n",
4463 usersharepath, strerror(errno) ));
4464 return -1;
4467 if (!S_ISDIR(sbuf.st_ex_mode)) {
4468 DEBUG(0,("load_usershare_service: %s is not a directory.\n",
4469 usersharepath ));
4470 return -1;
4474 * This directory must be owned by root, and have the 't' bit set.
4475 * It also must not be writable by "other".
4478 #ifdef S_ISVTX
4479 if (sbuf.st_ex_uid != 0 || !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
4480 #else
4481 if (sbuf.st_ex_uid != 0 || (sbuf.st_ex_mode & S_IWOTH)) {
4482 #endif
4483 DEBUG(0,("load_usershare_service: directory %s is not owned by root "
4484 "or does not have the sticky bit 't' set or is writable by anyone.\n",
4485 usersharepath ));
4486 return -1;
4489 /* Ensure the template share exists if it's set. */
4490 if (Globals.szUsershareTemplateShare[0]) {
4491 /* We can't use lp_servicenumber here as we are recommending that
4492 template shares have -valid=false set. */
4493 for (snum_template = iNumServices - 1; snum_template >= 0; snum_template--) {
4494 if (ServicePtrs[snum_template]->szService &&
4495 strequal(ServicePtrs[snum_template]->szService,
4496 Globals.szUsershareTemplateShare)) {
4497 break;
4501 if (snum_template == -1) {
4502 DEBUG(0,("load_usershare_service: usershare template share %s "
4503 "does not exist.\n",
4504 Globals.szUsershareTemplateShare ));
4505 return -1;
4509 return process_usershare_file(usersharepath, servicename, snum_template);
4512 /***************************************************************************
4513 Load all user defined shares from the user share directory.
4514 We only do this if we're enumerating the share list.
4515 This is the function that can delete usershares that have
4516 been removed.
4517 ***************************************************************************/
4519 int load_usershare_shares(struct smbd_server_connection *sconn,
4520 bool (*snumused) (struct smbd_server_connection *, int))
4522 DIR *dp;
4523 SMB_STRUCT_STAT sbuf;
4524 struct dirent *de;
4525 int num_usershares = 0;
4526 int max_user_shares = Globals.iUsershareMaxShares;
4527 unsigned int num_dir_entries, num_bad_dir_entries, num_tmp_dir_entries;
4528 unsigned int allowed_bad_entries = ((2*max_user_shares)/10);
4529 unsigned int allowed_tmp_entries = ((2*max_user_shares)/10);
4530 int iService;
4531 int snum_template = -1;
4532 const char *usersharepath = Globals.szUsersharePath;
4533 int ret = lp_numservices();
4534 TALLOC_CTX *tmp_ctx;
4536 if (max_user_shares == 0 || *usersharepath == '\0') {
4537 return lp_numservices();
4540 if (sys_stat(usersharepath, &sbuf, false) != 0) {
4541 DEBUG(0,("load_usershare_shares: stat of %s failed. %s\n",
4542 usersharepath, strerror(errno) ));
4543 return ret;
4547 * This directory must be owned by root, and have the 't' bit set.
4548 * It also must not be writable by "other".
4551 #ifdef S_ISVTX
4552 if (sbuf.st_ex_uid != 0 || !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
4553 #else
4554 if (sbuf.st_ex_uid != 0 || (sbuf.st_ex_mode & S_IWOTH)) {
4555 #endif
4556 DEBUG(0,("load_usershare_shares: directory %s is not owned by root "
4557 "or does not have the sticky bit 't' set or is writable by anyone.\n",
4558 usersharepath ));
4559 return ret;
4562 /* Ensure the template share exists if it's set. */
4563 if (Globals.szUsershareTemplateShare[0]) {
4564 /* We can't use lp_servicenumber here as we are recommending that
4565 template shares have -valid=false set. */
4566 for (snum_template = iNumServices - 1; snum_template >= 0; snum_template--) {
4567 if (ServicePtrs[snum_template]->szService &&
4568 strequal(ServicePtrs[snum_template]->szService,
4569 Globals.szUsershareTemplateShare)) {
4570 break;
4574 if (snum_template == -1) {
4575 DEBUG(0,("load_usershare_shares: usershare template share %s "
4576 "does not exist.\n",
4577 Globals.szUsershareTemplateShare ));
4578 return ret;
4582 /* Mark all existing usershares as pending delete. */
4583 for (iService = iNumServices - 1; iService >= 0; iService--) {
4584 if (VALID(iService) && ServicePtrs[iService]->usershare) {
4585 ServicePtrs[iService]->usershare = USERSHARE_PENDING_DELETE;
4589 dp = opendir(usersharepath);
4590 if (!dp) {
4591 DEBUG(0,("load_usershare_shares:: failed to open directory %s. %s\n",
4592 usersharepath, strerror(errno) ));
4593 return ret;
4596 for (num_dir_entries = 0, num_bad_dir_entries = 0, num_tmp_dir_entries = 0;
4597 (de = readdir(dp));
4598 num_dir_entries++ ) {
4599 int r;
4600 const char *n = de->d_name;
4602 /* Ignore . and .. */
4603 if (*n == '.') {
4604 if ((n[1] == '\0') || (n[1] == '.' && n[2] == '\0')) {
4605 continue;
4609 if (n[0] == ':') {
4610 /* Temporary file used when creating a share. */
4611 num_tmp_dir_entries++;
4614 /* Allow 20% tmp entries. */
4615 if (num_tmp_dir_entries > allowed_tmp_entries) {
4616 DEBUG(0,("load_usershare_shares: too many temp entries (%u) "
4617 "in directory %s\n",
4618 num_tmp_dir_entries, usersharepath));
4619 break;
4622 r = process_usershare_file(usersharepath, n, snum_template);
4623 if (r == 0) {
4624 /* Update the services count. */
4625 num_usershares++;
4626 if (num_usershares >= max_user_shares) {
4627 DEBUG(0,("load_usershare_shares: max user shares reached "
4628 "on file %s in directory %s\n",
4629 n, usersharepath ));
4630 break;
4632 } else if (r == -1) {
4633 num_bad_dir_entries++;
4636 /* Allow 20% bad entries. */
4637 if (num_bad_dir_entries > allowed_bad_entries) {
4638 DEBUG(0,("load_usershare_shares: too many bad entries (%u) "
4639 "in directory %s\n",
4640 num_bad_dir_entries, usersharepath));
4641 break;
4644 /* Allow 20% bad entries. */
4645 if (num_dir_entries > max_user_shares + allowed_bad_entries) {
4646 DEBUG(0,("load_usershare_shares: too many total entries (%u) "
4647 "in directory %s\n",
4648 num_dir_entries, usersharepath));
4649 break;
4653 closedir(dp);
4655 /* Sweep through and delete any non-refreshed usershares that are
4656 not currently in use. */
4657 tmp_ctx = talloc_stackframe();
4658 for (iService = iNumServices - 1; iService >= 0; iService--) {
4659 if (VALID(iService) && (ServicePtrs[iService]->usershare == USERSHARE_PENDING_DELETE)) {
4660 char *servname;
4662 if (snumused && snumused(sconn, iService)) {
4663 continue;
4666 servname = lp_servicename(tmp_ctx, iService);
4668 /* Remove from the share ACL db. */
4669 DEBUG(10,("load_usershare_shares: Removing deleted usershare %s\n",
4670 servname ));
4671 delete_share_security(servname);
4672 free_service_byindex(iService);
4675 talloc_free(tmp_ctx);
4677 return lp_numservices();
4680 /********************************************************
4681 Destroy global resources allocated in this file
4682 ********************************************************/
4684 void gfree_loadparm(void)
4686 int i;
4688 free_file_list();
4690 /* Free resources allocated to services */
4692 for ( i = 0; i < iNumServices; i++ ) {
4693 if ( VALID(i) ) {
4694 free_service_byindex(i);
4698 SAFE_FREE( ServicePtrs );
4699 iNumServices = 0;
4701 /* Now release all resources allocated to global
4702 parameters and the default service */
4704 free_global_parameters();
4708 /***************************************************************************
4709 Allow client apps to specify that they are a client
4710 ***************************************************************************/
4711 static void lp_set_in_client(bool b)
4713 in_client = b;
4717 /***************************************************************************
4718 Determine if we're running in a client app
4719 ***************************************************************************/
4720 static bool lp_is_in_client(void)
4722 return in_client;
4725 /***************************************************************************
4726 Load the services array from the services file. Return true on success,
4727 false on failure.
4728 ***************************************************************************/
4730 static bool lp_load_ex(const char *pszFname,
4731 bool global_only,
4732 bool save_defaults,
4733 bool add_ipc,
4734 bool initialize_globals,
4735 bool allow_include_registry,
4736 bool load_all_shares)
4738 char *n2 = NULL;
4739 bool bRetval;
4741 bRetval = false;
4743 DEBUG(3, ("lp_load_ex: refreshing parameters\n"));
4745 bInGlobalSection = true;
4746 bGlobalOnly = global_only;
4747 bAllowIncludeRegistry = allow_include_registry;
4749 init_globals(initialize_globals);
4751 free_file_list();
4753 if (save_defaults) {
4754 init_locals();
4755 lp_save_defaults();
4758 if (!initialize_globals) {
4759 free_param_opts(&Globals.param_opt);
4760 apply_lp_set_cmdline();
4763 lp_do_parameter(-1, "idmap config * : backend", Globals.szIdmapBackend);
4765 /* We get sections first, so have to start 'behind' to make up */
4766 iServiceIndex = -1;
4768 if (lp_config_backend_is_file()) {
4769 n2 = talloc_sub_basic(talloc_tos(), get_current_username(),
4770 current_user_info.domain,
4771 pszFname);
4772 if (!n2) {
4773 smb_panic("lp_load_ex: out of memory");
4776 add_to_file_list(pszFname, n2);
4778 bRetval = pm_process(n2, do_section, do_parameter, NULL);
4779 TALLOC_FREE(n2);
4781 /* finish up the last section */
4782 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
4783 if (bRetval) {
4784 if (iServiceIndex >= 0) {
4785 bRetval = service_ok(iServiceIndex);
4789 if (lp_config_backend_is_registry()) {
4790 /* config backend changed to registry in config file */
4792 * We need to use this extra global variable here to
4793 * survive restart: init_globals uses this as a default
4794 * for ConfigBackend. Otherwise, init_globals would
4795 * send us into an endless loop here.
4797 config_backend = CONFIG_BACKEND_REGISTRY;
4798 /* start over */
4799 DEBUG(1, ("lp_load_ex: changing to config backend "
4800 "registry\n"));
4801 init_globals(true);
4802 lp_kill_all_services();
4803 return lp_load_ex(pszFname, global_only, save_defaults,
4804 add_ipc, initialize_globals,
4805 allow_include_registry,
4806 load_all_shares);
4808 } else if (lp_config_backend_is_registry()) {
4809 bRetval = process_registry_globals();
4810 } else {
4811 DEBUG(0, ("Illegal config backend given: %d\n",
4812 lp_config_backend()));
4813 bRetval = false;
4816 if (bRetval && lp_registry_shares()) {
4817 if (load_all_shares) {
4818 bRetval = process_registry_shares();
4819 } else {
4820 bRetval = reload_registry_shares();
4825 char *serv = lp_auto_services(talloc_tos());
4826 lp_add_auto_services(serv);
4827 TALLOC_FREE(serv);
4830 if (add_ipc) {
4831 /* When 'restrict anonymous = 2' guest connections to ipc$
4832 are denied */
4833 lp_add_ipc("IPC$", (lp_restrict_anonymous() < 2));
4834 if ( lp_enable_asu_support() ) {
4835 lp_add_ipc("ADMIN$", false);
4839 set_allowed_client_auth();
4841 if (lp_security() == SEC_ADS && strchr(lp_passwordserver(), ':')) {
4842 DEBUG(1, ("WARNING: The optional ':port' in password server = %s is deprecated\n",
4843 lp_passwordserver()));
4846 bLoaded = true;
4848 /* Now we check bWINSsupport and set szWINSserver to 127.0.0.1 */
4849 /* if bWINSsupport is true and we are in the client */
4850 if (lp_is_in_client() && Globals.bWINSsupport) {
4851 lp_do_parameter(GLOBAL_SECTION_SNUM, "wins server", "127.0.0.1");
4854 init_iconv();
4856 fault_configure(smb_panic_s3);
4858 bAllowIncludeRegistry = true;
4860 return (bRetval);
4863 bool lp_load(const char *pszFname,
4864 bool global_only,
4865 bool save_defaults,
4866 bool add_ipc,
4867 bool initialize_globals)
4869 return lp_load_ex(pszFname,
4870 global_only,
4871 save_defaults,
4872 add_ipc,
4873 initialize_globals,
4874 true, /* allow_include_registry */
4875 false); /* load_all_shares*/
4878 bool lp_load_initial_only(const char *pszFname)
4880 return lp_load_ex(pszFname,
4881 true, /* global only */
4882 false, /* save_defaults */
4883 false, /* add_ipc */
4884 true, /* initialize_globals */
4885 false, /* allow_include_registry */
4886 false); /* load_all_shares*/
4890 * most common lp_load wrapper, loading only the globals
4892 bool lp_load_global(const char *file_name)
4894 return lp_load_ex(file_name,
4895 true, /* global_only */
4896 false, /* save_defaults */
4897 false, /* add_ipc */
4898 true, /* initialize_globals */
4899 true, /* allow_include_registry */
4900 false); /* load_all_shares*/
4904 * lp_load wrapper, especially for clients
4906 bool lp_load_client(const char *file_name)
4908 lp_set_in_client(true);
4910 return lp_load_global(file_name);
4914 * lp_load wrapper, loading only globals, but intended
4915 * for subsequent calls, not reinitializing the globals
4916 * to default values
4918 bool lp_load_global_no_reinit(const char *file_name)
4920 return lp_load_ex(file_name,
4921 true, /* global_only */
4922 false, /* save_defaults */
4923 false, /* add_ipc */
4924 false, /* initialize_globals */
4925 true, /* allow_include_registry */
4926 false); /* load_all_shares*/
4930 * lp_load wrapper, especially for clients, no reinitialization
4932 bool lp_load_client_no_reinit(const char *file_name)
4934 lp_set_in_client(true);
4936 return lp_load_global_no_reinit(file_name);
4939 bool lp_load_with_registry_shares(const char *pszFname,
4940 bool global_only,
4941 bool save_defaults,
4942 bool add_ipc,
4943 bool initialize_globals)
4945 return lp_load_ex(pszFname,
4946 global_only,
4947 save_defaults,
4948 add_ipc,
4949 initialize_globals,
4950 true, /* allow_include_registry */
4951 true); /* load_all_shares*/
4954 /***************************************************************************
4955 Return the max number of services.
4956 ***************************************************************************/
4958 int lp_numservices(void)
4960 return (iNumServices);
4963 /***************************************************************************
4964 Display the contents of the services array in human-readable form.
4965 ***************************************************************************/
4967 void lp_dump(FILE *f, bool show_defaults, int maxtoprint)
4969 int iService;
4971 if (show_defaults)
4972 defaults_saved = false;
4974 dump_globals(f);
4976 dump_a_service(&sDefault, f);
4978 for (iService = 0; iService < maxtoprint; iService++) {
4979 fprintf(f,"\n");
4980 lp_dump_one(f, show_defaults, iService);
4984 /***************************************************************************
4985 Display the contents of one service in human-readable form.
4986 ***************************************************************************/
4988 void lp_dump_one(FILE * f, bool show_defaults, int snum)
4990 if (VALID(snum)) {
4991 if (ServicePtrs[snum]->szService[0] == '\0')
4992 return;
4993 dump_a_service(ServicePtrs[snum], f);
4997 /***************************************************************************
4998 Return the number of the service with the given name, or -1 if it doesn't
4999 exist. Note that this is a DIFFERENT ANIMAL from the internal function
5000 getservicebyname()! This works ONLY if all services have been loaded, and
5001 does not copy the found service.
5002 ***************************************************************************/
5004 int lp_servicenumber(const char *pszServiceName)
5006 int iService;
5007 fstring serviceName;
5009 if (!pszServiceName) {
5010 return GLOBAL_SECTION_SNUM;
5013 for (iService = iNumServices - 1; iService >= 0; iService--) {
5014 if (VALID(iService) && ServicePtrs[iService]->szService) {
5016 * The substitution here is used to support %U is
5017 * service names
5019 fstrcpy(serviceName, ServicePtrs[iService]->szService);
5020 standard_sub_basic(get_current_username(),
5021 current_user_info.domain,
5022 serviceName,sizeof(serviceName));
5023 if (strequal(serviceName, pszServiceName)) {
5024 break;
5029 if (iService >= 0 && ServicePtrs[iService]->usershare == USERSHARE_VALID) {
5030 struct timespec last_mod;
5032 if (!usershare_exists(iService, &last_mod)) {
5033 /* Remove the share security tdb entry for it. */
5034 delete_share_security(lp_servicename(talloc_tos(), iService));
5035 /* Remove it from the array. */
5036 free_service_byindex(iService);
5037 /* Doesn't exist anymore. */
5038 return GLOBAL_SECTION_SNUM;
5041 /* Has it been modified ? If so delete and reload. */
5042 if (timespec_compare(&ServicePtrs[iService]->usershare_last_mod,
5043 &last_mod) < 0) {
5044 /* Remove it from the array. */
5045 free_service_byindex(iService);
5046 /* and now reload it. */
5047 iService = load_usershare_service(pszServiceName);
5051 if (iService < 0) {
5052 DEBUG(7,("lp_servicenumber: couldn't find %s\n", pszServiceName));
5053 return GLOBAL_SECTION_SNUM;
5056 return (iService);
5059 /*******************************************************************
5060 A useful volume label function.
5061 ********************************************************************/
5063 const char *volume_label(TALLOC_CTX *ctx, int snum)
5065 char *ret;
5066 const char *label = lp_volume(ctx, snum);
5067 if (!*label) {
5068 label = lp_servicename(ctx, snum);
5071 /* This returns a 33 byte guarenteed null terminated string. */
5072 ret = talloc_strndup(ctx, label, 32);
5073 if (!ret) {
5074 return "";
5076 return ret;
5079 /*******************************************************************
5080 Get the default server type we will announce as via nmbd.
5081 ********************************************************************/
5083 int lp_default_server_announce(void)
5085 int default_server_announce = 0;
5086 default_server_announce |= SV_TYPE_WORKSTATION;
5087 default_server_announce |= SV_TYPE_SERVER;
5088 default_server_announce |= SV_TYPE_SERVER_UNIX;
5090 /* note that the flag should be set only if we have a
5091 printer service but nmbd doesn't actually load the
5092 services so we can't tell --jerry */
5094 default_server_announce |= SV_TYPE_PRINTQ_SERVER;
5096 default_server_announce |= SV_TYPE_SERVER_NT;
5097 default_server_announce |= SV_TYPE_NT;
5099 switch (lp_server_role()) {
5100 case ROLE_DOMAIN_MEMBER:
5101 default_server_announce |= SV_TYPE_DOMAIN_MEMBER;
5102 break;
5103 case ROLE_DOMAIN_PDC:
5104 default_server_announce |= SV_TYPE_DOMAIN_CTRL;
5105 break;
5106 case ROLE_DOMAIN_BDC:
5107 default_server_announce |= SV_TYPE_DOMAIN_BAKCTRL;
5108 break;
5109 case ROLE_STANDALONE:
5110 default:
5111 break;
5113 if (lp_time_server())
5114 default_server_announce |= SV_TYPE_TIME_SOURCE;
5116 if (lp_host_msdfs())
5117 default_server_announce |= SV_TYPE_DFS_SERVER;
5119 return default_server_announce;
5122 /***********************************************************
5123 If we are PDC then prefer us as DMB
5124 ************************************************************/
5126 bool lp_domain_master(void)
5128 if (Globals.domain_master == Auto)
5129 return (lp_server_role() == ROLE_DOMAIN_PDC);
5131 return (bool)Globals.domain_master;
5134 /***********************************************************
5135 If we are PDC then prefer us as DMB
5136 ************************************************************/
5138 static bool lp_domain_master_true_or_auto(void)
5140 if (Globals.domain_master) /* auto or yes */
5141 return true;
5143 return false;
5146 /***********************************************************
5147 If we are DMB then prefer us as LMB
5148 ************************************************************/
5150 bool lp_preferred_master(void)
5152 if (Globals.iPreferredMaster == Auto)
5153 return (lp_local_master() && lp_domain_master());
5155 return (bool)Globals.iPreferredMaster;
5158 /*******************************************************************
5159 Remove a service.
5160 ********************************************************************/
5162 void lp_remove_service(int snum)
5164 ServicePtrs[snum]->valid = false;
5165 invalid_services[num_invalid_services++] = snum;
5168 /*******************************************************************
5169 Copy a service.
5170 ********************************************************************/
5172 void lp_copy_service(int snum, const char *new_name)
5174 do_section(new_name, NULL);
5175 if (snum >= 0) {
5176 snum = lp_servicenumber(new_name);
5177 if (snum >= 0) {
5178 char *name = lp_servicename(talloc_tos(), snum);
5179 lp_do_parameter(snum, "copy", name);
5184 const char *lp_printername(TALLOC_CTX *ctx, int snum)
5186 const char *ret = lp__printername(talloc_tos(), snum);
5187 if (ret == NULL || *ret == '\0') {
5188 ret = lp_const_servicename(snum);
5191 return ret;
5195 /***********************************************************
5196 Allow daemons such as winbindd to fix their logfile name.
5197 ************************************************************/
5199 void lp_set_logfile(const char *name)
5201 string_set(&Globals.logfile, name);
5202 debug_set_logfile(name);
5205 /*******************************************************************
5206 Return the max print jobs per queue.
5207 ********************************************************************/
5209 int lp_maxprintjobs(int snum)
5211 int maxjobs = LP_SNUM_OK(snum) ? ServicePtrs[snum]->iMaxPrintJobs : sDefault.iMaxPrintJobs;
5212 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
5213 maxjobs = PRINT_MAX_JOBID - 1;
5215 return maxjobs;
5218 const char *lp_printcapname(void)
5220 if ((Globals.szPrintcapname != NULL) &&
5221 (Globals.szPrintcapname[0] != '\0'))
5222 return Globals.szPrintcapname;
5224 if (sDefault.iPrinting == PRINT_CUPS) {
5225 #ifdef HAVE_CUPS
5226 return "cups";
5227 #else
5228 return "lpstat";
5229 #endif
5232 if (sDefault.iPrinting == PRINT_BSD)
5233 return "/etc/printcap";
5235 return PRINTCAP_NAME;
5238 static uint32 spoolss_state;
5240 bool lp_disable_spoolss( void )
5242 if ( spoolss_state == SVCCTL_STATE_UNKNOWN )
5243 spoolss_state = lp__disable_spoolss() ? SVCCTL_STOPPED : SVCCTL_RUNNING;
5245 return spoolss_state == SVCCTL_STOPPED ? true : false;
5248 void lp_set_spoolss_state( uint32 state )
5250 SMB_ASSERT( (state == SVCCTL_STOPPED) || (state == SVCCTL_RUNNING) );
5252 spoolss_state = state;
5255 uint32 lp_get_spoolss_state( void )
5257 return lp_disable_spoolss() ? SVCCTL_STOPPED : SVCCTL_RUNNING;
5260 /*******************************************************************
5261 Ensure we don't use sendfile if server smb signing is active.
5262 ********************************************************************/
5264 bool lp_use_sendfile(int snum, struct smb_signing_state *signing_state)
5266 bool sign_active = false;
5268 /* Using sendfile blows the brains out of any DOS or Win9x TCP stack... JRA. */
5269 if (get_Protocol() < PROTOCOL_NT1) {
5270 return false;
5272 if (signing_state) {
5273 sign_active = smb_signing_is_active(signing_state);
5275 return (lp__use_sendfile(snum) &&
5276 (get_remote_arch() != RA_WIN95) &&
5277 !sign_active);
5280 /*******************************************************************
5281 Turn off sendfile if we find the underlying OS doesn't support it.
5282 ********************************************************************/
5284 void set_use_sendfile(int snum, bool val)
5286 if (LP_SNUM_OK(snum))
5287 ServicePtrs[snum]->bUseSendfile = val;
5288 else
5289 sDefault.bUseSendfile = val;
5292 /*******************************************************************
5293 Turn off storing DOS attributes if this share doesn't support it.
5294 ********************************************************************/
5296 void set_store_dos_attributes(int snum, bool val)
5298 if (!LP_SNUM_OK(snum))
5299 return;
5300 ServicePtrs[(snum)]->bStoreDosAttributes = val;
5303 void lp_set_mangling_method(const char *new_method)
5305 string_set(&Globals.szManglingMethod, new_method);
5308 /*******************************************************************
5309 Global state for POSIX pathname processing.
5310 ********************************************************************/
5312 static bool posix_pathnames;
5314 bool lp_posix_pathnames(void)
5316 return posix_pathnames;
5319 /*******************************************************************
5320 Change everything needed to ensure POSIX pathname processing (currently
5321 not much).
5322 ********************************************************************/
5324 void lp_set_posix_pathnames(void)
5326 posix_pathnames = true;
5329 /*******************************************************************
5330 Global state for POSIX lock processing - CIFS unix extensions.
5331 ********************************************************************/
5333 bool posix_default_lock_was_set;
5334 static enum brl_flavour posix_cifsx_locktype; /* By default 0 == WINDOWS_LOCK */
5336 enum brl_flavour lp_posix_cifsu_locktype(files_struct *fsp)
5338 if (posix_default_lock_was_set) {
5339 return posix_cifsx_locktype;
5340 } else {
5341 return fsp->posix_open ? POSIX_LOCK : WINDOWS_LOCK;
5345 /*******************************************************************
5346 ********************************************************************/
5348 void lp_set_posix_default_cifsx_readwrite_locktype(enum brl_flavour val)
5350 posix_default_lock_was_set = true;
5351 posix_cifsx_locktype = val;
5354 int lp_min_receive_file_size(void)
5356 if (Globals.iminreceivefile < 0) {
5357 return 0;
5359 return MIN(Globals.iminreceivefile, BUFFER_SIZE);
5362 /*******************************************************************
5363 Safe wide links checks.
5364 This helper function always verify the validity of wide links,
5365 even after a configuration file reload.
5366 ********************************************************************/
5368 static bool lp_widelinks_internal(int snum)
5370 return (bool)(LP_SNUM_OK(snum)? ServicePtrs[(snum)]->bWidelinks :
5371 sDefault.bWidelinks);
5374 void widelinks_warning(int snum)
5376 if (lp_allow_insecure_widelinks()) {
5377 return;
5380 if (lp_unix_extensions() && lp_widelinks_internal(snum)) {
5381 DEBUG(0,("Share '%s' has wide links and unix extensions enabled. "
5382 "These parameters are incompatible. "
5383 "Wide links will be disabled for this share.\n",
5384 lp_servicename(talloc_tos(), snum) ));
5388 bool lp_widelinks(int snum)
5390 /* wide links is always incompatible with unix extensions */
5391 if (lp_unix_extensions()) {
5393 * Unless we have "allow insecure widelinks"
5394 * turned on.
5396 if (!lp_allow_insecure_widelinks()) {
5397 return false;
5401 return lp_widelinks_internal(snum);
5404 bool lp_writeraw(void)
5406 if (lp_async_smb_echo_handler()) {
5407 return false;
5409 return lp__writeraw();
5412 bool lp_readraw(void)
5414 if (lp_async_smb_echo_handler()) {
5415 return false;
5417 return lp__readraw();
5420 int lp_server_role(void)
5422 return lp_find_server_role(lp__server_role(),
5423 lp__security(),
5424 lp__domain_logons(),
5425 lp_domain_master_true_or_auto());
5428 int lp_security(void)
5430 return lp_find_security(lp__server_role(),
5431 lp__security());