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/>.
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.
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
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
57 #include "system/filesys.h"
59 #include "lib/param/loadparm.h"
60 #include "lib/param/param.h"
62 #include "lib/smbconf/smbconf.h"
63 #include "lib/smbconf/smbconf_init.h"
66 #include "../librpc/gen_ndr/svcctl.h"
68 #include "../libcli/smb/smb_signing.h"
69 #include "dbwrap/dbwrap.h"
70 #include "dbwrap/dbwrap_rbt.h"
71 #include "../lib/util/bitmap.h"
73 #ifdef HAVE_SYS_SYSCTL_H
74 #include <sys/sysctl.h>
77 #ifdef HAVE_HTTPCONNECTENCRYPT
78 #include <cups/http.h>
83 extern userdom_struct current_user_info
;
85 /* the special value for the include parameter
86 * to be interpreted not as a file name but to
87 * trigger loading of the global smb.conf options
89 #ifndef INCLUDE_REGISTRY_NAME
90 #define INCLUDE_REGISTRY_NAME "registry"
93 static bool in_client
= false; /* Not in the client by default */
94 static struct smbconf_csn conf_last_csn
;
96 static int config_backend
= CONFIG_BACKEND_FILE
;
98 /* some helpful bits */
99 #define LP_SNUM_OK(i) (((i) >= 0) && ((i) < iNumServices) && (ServicePtrs != NULL) && ServicePtrs[(i)]->valid)
100 #define VALID(i) (ServicePtrs != NULL && ServicePtrs[i]->valid)
102 #define USERSHARE_VALID 1
103 #define USERSHARE_PENDING_DELETE 2
105 static bool defaults_saved
= false;
107 #include "lib/param/param_global.h"
109 static struct loadparm_global Globals
;
111 /* This is a default service used to prime a services structure */
112 static struct loadparm_service sDefault
=
117 .usershare_last_mod
= {0, 0},
121 .invalid_users
= NULL
,
128 .root_preexec
= NULL
,
129 .root_postexec
= NULL
,
130 .cups_options
= NULL
,
131 .print_command
= NULL
,
133 .lprm_command
= NULL
,
134 .lppause_command
= NULL
,
135 .lpresume_command
= NULL
,
136 .queuepause_command
= NULL
,
137 .queueresume_command
= NULL
,
138 ._printername
= NULL
,
139 .printjob_username
= NULL
,
140 .dont_descend
= NULL
,
143 .magic_script
= NULL
,
144 .magic_output
= NULL
,
147 .veto_oplock_files
= NULL
,
157 .aio_write_behind
= NULL
,
158 .dfree_command
= NULL
,
159 .min_print_space
= 0,
160 .iMaxPrintJobs
= 1000,
161 .max_reported_print_jobs
= 0,
162 .write_cache_size
= 0,
164 .force_create_mode
= 0,
165 .directory_mask
= 0755,
166 .force_directory_mode
= 0,
167 .max_connections
= 0,
168 .default_case
= CASE_LOWER
,
169 .printing
= DEFAULT_PRINTING
,
170 .oplock_contention_limit
= 2,
173 .dfree_cache_time
= 0,
174 .preexec_close
= false,
175 .root_preexec_close
= false,
176 .case_sensitive
= Auto
,
177 .preserve_case
= true,
178 .short_preserve_case
= true,
179 .hide_dot_files
= true,
180 .hide_special_files
= false,
181 .hide_unreadable
= false,
182 .hide_unwriteable_files
= false,
184 .access_based_share_enum
= false,
188 .administrative_share
= false,
191 .print_notify_backchannel
= false,
195 .store_dos_attributes
= false,
196 .dmapi_support
= false,
198 .strict_locking
= Auto
,
199 .posix_locking
= true,
201 .kernel_oplocks
= false,
202 .level2_oplocks
= true,
204 .mangled_names
= true,
206 .follow_symlinks
= true,
207 .sync_always
= false,
208 .strict_allocate
= false,
209 .strict_sync
= false,
210 .mangling_char
= '~',
212 .delete_readonly
= false,
213 .fake_oplocks
= false,
214 .delete_veto_files
= false,
215 .dos_filemode
= false,
216 .dos_filetimes
= true,
217 .dos_filetime_resolution
= false,
218 .fake_directory_create_times
= false,
219 .blocking_locks
= true,
220 .inherit_permissions
= false,
221 .inherit_acls
= false,
222 .inherit_owner
= false,
224 .use_client_driver
= false,
225 .default_devmode
= true,
226 .force_printername
= false,
227 .nt_acl_support
= true,
228 .force_unknown_acl_user
= false,
229 ._use_sendfile
= false,
230 .profile_acls
= false,
231 .map_acl_inherit
= false,
234 .acl_check_permissions
= true,
235 .acl_map_full_control
= true,
236 .acl_group_control
= false,
237 .acl_allow_execute_always
= false,
238 .change_notify
= true,
239 .kernel_change_notify
= true,
240 .allocation_roundup_size
= SMB_ROUNDUP_ALLOCATION_SIZE
,
243 .map_readonly
= MAP_READONLY_YES
,
244 .directory_name_cache_size
= 100,
245 .smb_encrypt
= SMB_SIGNING_DEFAULT
,
246 .kernel_share_modes
= true,
247 .durable_handles
= true,
252 /* local variables */
253 static struct loadparm_service
**ServicePtrs
= NULL
;
254 static int iNumServices
= 0;
255 static int iServiceIndex
= 0;
256 static struct db_context
*ServiceHash
;
257 static bool bInGlobalSection
= true;
258 static bool bGlobalOnly
= false;
260 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
262 /* prototypes for the special type handlers */
263 static bool handle_include(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
264 static bool handle_copy(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
265 static bool handle_idmap_backend(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
266 static bool handle_idmap_uid(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
267 static bool handle_idmap_gid(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
268 static bool handle_debug_list(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
269 static bool handle_realm(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
270 static bool handle_netbios_aliases(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
271 static bool handle_charset(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
272 static bool handle_dos_charset(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
273 static bool handle_printing(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
274 static bool handle_ldap_debug_level(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
);
276 /* these are parameter handlers which are not needed in the
280 #define handle_logfile NULL
282 static void set_allowed_client_auth(void);
284 static void add_to_file_list(const char *fname
, const char *subfname
);
285 static bool lp_set_cmdline_helper(const char *pszParmName
, const char *pszParmValue
, bool store_values
);
286 static void free_param_opts(struct parmlist_entry
**popts
);
288 #include "lib/param/param_table.c"
290 /* this is used to prevent lots of mallocs of size 1 */
291 static const char null_string
[] = "";
297 static void string_free(char **s
)
301 if (*s
== null_string
)
307 Set a string value, deallocating any existing space, and allocing the space
311 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
,const char *src
)
319 (*dest
) = talloc_strdup(mem_ctx
, src
);
320 if ((*dest
) == NULL
) {
321 DEBUG(0,("Out of memory in string_init\n"));
328 bool lp_string_set(char **dest
, const char *src
) {
329 return string_set(Globals
.ctx
, dest
, src
);
332 /***************************************************************************
333 Initialise the sDefault parameter structure for the printer values.
334 ***************************************************************************/
336 static void init_printer_values(TALLOC_CTX
*ctx
, struct loadparm_service
*pService
)
338 /* choose defaults depending on the type of printing */
339 switch (pService
->printing
) {
344 string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
345 string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
346 string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
351 string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
352 string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
353 string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
354 string_set(ctx
, &pService
->queuepause_command
, "lpc stop '%p'");
355 string_set(ctx
, &pService
->queueresume_command
, "lpc start '%p'");
356 string_set(ctx
, &pService
->lppause_command
, "lpc hold '%p' %j");
357 string_set(ctx
, &pService
->lpresume_command
, "lpc release '%p' %j");
362 /* set the lpq command to contain the destination printer
363 name only. This is used by cups_queue_get() */
364 string_set(ctx
, &pService
->lpq_command
, "%p");
365 string_set(ctx
, &pService
->lprm_command
, "");
366 string_set(ctx
, &pService
->print_command
, "");
367 string_set(ctx
, &pService
->lppause_command
, "");
368 string_set(ctx
, &pService
->lpresume_command
, "");
369 string_set(ctx
, &pService
->queuepause_command
, "");
370 string_set(ctx
, &pService
->queueresume_command
, "");
375 string_set(ctx
, &pService
->lpq_command
, "lpstat -o%p");
376 string_set(ctx
, &pService
->lprm_command
, "cancel %p-%j");
377 string_set(ctx
, &pService
->print_command
, "lp -c -d%p %s; rm %s");
378 string_set(ctx
, &pService
->queuepause_command
, "disable %p");
379 string_set(ctx
, &pService
->queueresume_command
, "enable %p");
381 string_set(ctx
, &pService
->lppause_command
, "lp -i %p-%j -H hold");
382 string_set(ctx
, &pService
->lpresume_command
, "lp -i %p-%j -H resume");
387 string_set(ctx
, &pService
->lpq_command
, "lpq -P%p");
388 string_set(ctx
, &pService
->lprm_command
, "lprm -P%p %j");
389 string_set(ctx
, &pService
->print_command
, "lp -r -P%p %s");
392 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
397 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
400 tdbfile
= talloc_asprintf(
401 tmp_ctx
, "tdbfile=%s",
402 lp_parm_const_string(-1, "vlp", "tdbfile",
404 if (tdbfile
== NULL
) {
405 tdbfile
="tdbfile=/tmp/vlp.tdb";
408 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s print %%p %%s",
410 string_set(ctx
, &pService
->print_command
,
411 tmp
? tmp
: "vlp print %p %s");
413 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpq %%p",
415 string_set(ctx
, &pService
->lpq_command
,
416 tmp
? tmp
: "vlp lpq %p");
418 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lprm %%p %%j",
420 string_set(ctx
, &pService
->lprm_command
,
421 tmp
? tmp
: "vlp lprm %p %j");
423 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lppause %%p %%j",
425 string_set(ctx
, &pService
->lppause_command
,
426 tmp
? tmp
: "vlp lppause %p %j");
428 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpresume %%p %%j",
430 string_set(ctx
, &pService
->lpresume_command
,
431 tmp
? tmp
: "vlp lpresume %p %j");
433 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queuepause %%p",
435 string_set(ctx
, &pService
->queuepause_command
,
436 tmp
? tmp
: "vlp queuepause %p");
438 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queueresume %%p",
440 string_set(ctx
, &pService
->queueresume_command
,
441 tmp
? tmp
: "vlp queueresume %p");
442 TALLOC_FREE(tmp_ctx
);
446 #endif /* DEVELOPER */
451 * Function to return the default value for the maximum number of open
452 * file descriptors permitted. This function tries to consult the
453 * kernel-level (sysctl) and ulimit (getrlimit()) values and goes
454 * the smaller of those.
456 static int max_open_files(void)
458 int sysctl_max
= MAX_OPEN_FILES
;
459 int rlimit_max
= MAX_OPEN_FILES
;
461 #ifdef HAVE_SYSCTLBYNAME
463 size_t size
= sizeof(sysctl_max
);
464 sysctlbyname("kern.maxfilesperproc", &sysctl_max
, &size
, NULL
,
469 #if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
475 if (getrlimit(RLIMIT_NOFILE
, &rl
) == 0)
476 rlimit_max
= rl
.rlim_cur
;
478 #if defined(RLIM_INFINITY)
479 if(rl
.rlim_cur
== RLIM_INFINITY
)
480 rlimit_max
= MAX_OPEN_FILES
;
485 if (sysctl_max
< MIN_OPEN_FILES_WINDOWS
) {
486 DEBUG(2,("max_open_files: increasing sysctl_max (%d) to "
487 "minimum Windows limit (%d)\n",
489 MIN_OPEN_FILES_WINDOWS
));
490 sysctl_max
= MIN_OPEN_FILES_WINDOWS
;
493 if (rlimit_max
< MIN_OPEN_FILES_WINDOWS
) {
494 DEBUG(2,("rlimit_max: increasing rlimit_max (%d) to "
495 "minimum Windows limit (%d)\n",
497 MIN_OPEN_FILES_WINDOWS
));
498 rlimit_max
= MIN_OPEN_FILES_WINDOWS
;
501 return MIN(sysctl_max
, rlimit_max
);
505 * Common part of freeing allocated data for one parameter.
507 static void free_one_parameter_common(void *parm_ptr
,
508 struct parm_struct parm
)
510 if ((parm
.type
== P_STRING
) ||
511 (parm
.type
== P_USTRING
))
513 string_free((char**)parm_ptr
);
514 } else if (parm
.type
== P_LIST
) {
515 TALLOC_FREE(*((char***)parm_ptr
));
520 * Free the allocated data for one parameter for a share
521 * given as a service struct.
523 static void free_one_parameter(struct loadparm_service
*service
,
524 struct parm_struct parm
)
528 if (parm
.p_class
!= P_LOCAL
) {
532 parm_ptr
= lp_parm_ptr(service
, &parm
);
534 free_one_parameter_common(parm_ptr
, parm
);
538 * Free the allocated parameter data of a share given
539 * as a service struct.
541 static void free_parameters(struct loadparm_service
*service
)
545 for (i
=0; parm_table
[i
].label
; i
++) {
546 free_one_parameter(service
, parm_table
[i
]);
551 * Free the allocated data for one parameter for a given share
552 * specified by an snum.
554 static void free_one_parameter_by_snum(int snum
, struct parm_struct parm
)
559 parm_ptr
= lp_parm_ptr(NULL
, &parm
);
560 } else if (parm
.p_class
!= P_LOCAL
) {
563 parm_ptr
= lp_local_ptr_by_snum(snum
, &parm
);
566 free_one_parameter_common(parm_ptr
, parm
);
570 * Free the allocated parameter data for a share specified
573 static void free_parameters_by_snum(int snum
)
577 for (i
=0; parm_table
[i
].label
; i
++) {
578 free_one_parameter_by_snum(snum
, parm_table
[i
]);
583 * Free the allocated global parameters.
585 static void free_global_parameters(void)
587 free_param_opts(&Globals
.param_opt
);
588 free_parameters_by_snum(GLOBAL_SECTION_SNUM
);
589 TALLOC_FREE(Globals
.ctx
);
592 struct lp_stored_option
{
593 struct lp_stored_option
*prev
, *next
;
598 static struct lp_stored_option
*stored_options
;
601 save options set by lp_set_cmdline() into a list. This list is
602 re-applied when we do a globals reset, so that cmdline set options
603 are sticky across reloads of smb.conf
605 static bool store_lp_set_cmdline(const char *pszParmName
, const char *pszParmValue
)
607 struct lp_stored_option
*entry
, *entry_next
;
608 for (entry
= stored_options
; entry
!= NULL
; entry
= entry_next
) {
609 entry_next
= entry
->next
;
610 if (strcmp(pszParmName
, entry
->label
) == 0) {
611 DLIST_REMOVE(stored_options
, entry
);
617 entry
= talloc(NULL
, struct lp_stored_option
);
622 entry
->label
= talloc_strdup(entry
, pszParmName
);
628 entry
->value
= talloc_strdup(entry
, pszParmValue
);
634 DLIST_ADD_END(stored_options
, entry
, struct lp_stored_option
);
639 static bool apply_lp_set_cmdline(void)
641 struct lp_stored_option
*entry
= NULL
;
642 for (entry
= stored_options
; entry
!= NULL
; entry
= entry
->next
) {
643 if (!lp_set_cmdline_helper(entry
->label
, entry
->value
, false)) {
644 DEBUG(0, ("Failed to re-apply cmdline parameter %s = %s\n",
645 entry
->label
, entry
->value
));
652 /***************************************************************************
653 Initialise the global parameter structure.
654 ***************************************************************************/
656 static void init_globals(bool reinit_globals
)
658 static bool done_init
= false;
662 /* If requested to initialize only once and we've already done it... */
663 if (!reinit_globals
&& done_init
) {
664 /* ... then we have nothing more to do */
669 /* The logfile can be set before this is invoked. Free it if so. */
670 if (Globals
.logfile
!= NULL
) {
671 string_free(&Globals
.logfile
);
672 Globals
.logfile
= NULL
;
676 free_global_parameters();
679 /* This memset and the free_global_parameters() above will
680 * wipe out smb.conf options set with lp_set_cmdline(). The
681 * apply_lp_set_cmdline() call puts these values back in the
682 * table once the defaults are set */
683 ZERO_STRUCT(Globals
);
685 Globals
.ctx
= talloc_pooled_object(NULL
, char, 272, 2048);
687 for (i
= 0; parm_table
[i
].label
; i
++) {
688 if ((parm_table
[i
].type
== P_STRING
||
689 parm_table
[i
].type
== P_USTRING
))
691 string_set(Globals
.ctx
, (char **)lp_parm_ptr(NULL
, &parm_table
[i
]), "");
696 string_set(Globals
.ctx
, &sDefault
.fstype
, FSTYPE_STRING
);
697 string_set(Globals
.ctx
, &sDefault
.printjob_username
, "%U");
699 init_printer_values(Globals
.ctx
, &sDefault
);
701 sDefault
.ntvfs_handler
= (const char **)str_list_make_v3(NULL
, "unixuid default", NULL
);
703 DEBUG(3, ("Initialising global parameters\n"));
705 /* Must manually force to upper case here, as this does not go via the handler */
706 string_set(Globals
.ctx
, &Globals
.netbios_name
, myhostname_upper());
708 string_set(Globals
.ctx
, &Globals
.smb_passwd_file
, get_dyn_SMB_PASSWD_FILE());
709 string_set(Globals
.ctx
, &Globals
.private_dir
, get_dyn_PRIVATE_DIR());
711 /* use the new 'hash2' method by default, with a prefix of 1 */
712 string_set(Globals
.ctx
, &Globals
.mangling_method
, "hash2");
713 Globals
.mangle_prefix
= 1;
715 string_set(Globals
.ctx
, &Globals
.guest_account
, GUEST_ACCOUNT
);
717 /* using UTF8 by default allows us to support all chars */
718 string_set(Globals
.ctx
, &Globals
.unix_charset
, DEFAULT_UNIX_CHARSET
);
720 /* Use codepage 850 as a default for the dos character set */
721 string_set(Globals
.ctx
, &Globals
.dos_charset
, DEFAULT_DOS_CHARSET
);
724 * Allow the default PASSWD_CHAT to be overridden in local.h.
726 string_set(Globals
.ctx
, &Globals
.passwd_chat
, DEFAULT_PASSWD_CHAT
);
728 string_set(Globals
.ctx
, &Globals
.workgroup
, DEFAULT_WORKGROUP
);
730 string_set(Globals
.ctx
, &Globals
.passwd_program
, "");
731 string_set(Globals
.ctx
, &Globals
.lock_directory
, get_dyn_LOCKDIR());
732 string_set(Globals
.ctx
, &Globals
.state_directory
, get_dyn_STATEDIR());
733 string_set(Globals
.ctx
, &Globals
.cache_directory
, get_dyn_CACHEDIR());
734 string_set(Globals
.ctx
, &Globals
.pid_directory
, get_dyn_PIDDIR());
735 string_set(Globals
.ctx
, &Globals
.nbt_client_socket_address
, "0.0.0.0");
737 * By default support explicit binding to broadcast
740 Globals
.nmbd_bind_explicit_broadcast
= true;
742 s
= talloc_asprintf(talloc_tos(), "Samba %s", samba_version_string());
744 smb_panic("init_globals: ENOMEM");
746 string_set(Globals
.ctx
, &Globals
.server_string
, s
);
749 string_set(Globals
.ctx
, &Globals
.panic_action
, "/bin/sleep 999999999");
752 string_set(Globals
.ctx
, &Globals
.socket_options
, DEFAULT_SOCKET_OPTIONS
);
754 string_set(Globals
.ctx
, &Globals
.logon_drive
, "");
755 /* %N is the NIS auto.home server if -DAUTOHOME is used, else same as %L */
756 string_set(Globals
.ctx
, &Globals
.logon_home
, "\\\\%N\\%U");
757 string_set(Globals
.ctx
, &Globals
.logon_path
, "\\\\%N\\%U\\profile");
759 Globals
.name_resolve_order
= (const char **)str_list_make_v3(NULL
, "lmhosts wins host bcast", NULL
);
760 string_set(Globals
.ctx
, &Globals
.password_server
, "*");
762 Globals
.algorithmic_rid_base
= BASE_RID
;
764 Globals
.load_printers
= true;
765 Globals
.printcap_cache_time
= 750; /* 12.5 minutes */
767 Globals
.config_backend
= config_backend
;
768 Globals
._server_role
= ROLE_AUTO
;
770 /* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
771 /* Discovered by 2 days of pain by Don McCall @ HP :-). */
772 Globals
.max_xmit
= 0x4104;
773 Globals
.max_mux
= 50; /* This is *needed* for profile support. */
774 Globals
.lpq_cache_time
= 30; /* changed to handle large print servers better -- jerry */
775 Globals
._disable_spoolss
= false;
776 Globals
.max_smbd_processes
= 0;/* no limit specified */
777 Globals
.username_level
= 0;
778 Globals
.deadtime
= 0;
779 Globals
.getwd_cache
= true;
780 Globals
.large_readwrite
= true;
781 Globals
.max_log_size
= 5000;
782 Globals
.max_open_files
= max_open_files();
783 Globals
.server_max_protocol
= PROTOCOL_SMB3_00
;
784 Globals
.server_min_protocol
= PROTOCOL_LANMAN1
;
785 Globals
.client_max_protocol
= PROTOCOL_NT1
;
786 Globals
.client_min_protocol
= PROTOCOL_CORE
;
787 Globals
._security
= SEC_AUTO
;
788 Globals
.encrypt_passwords
= true;
789 Globals
.client_schannel
= Auto
;
790 Globals
.winbind_sealed_pipes
= true;
791 Globals
.require_strong_key
= true;
792 Globals
.server_schannel
= Auto
;
793 Globals
.read_raw
= true;
794 Globals
.write_raw
= true;
795 Globals
.null_passwords
= false;
796 Globals
.old_password_allowed_period
= 60;
797 Globals
.obey_pam_restrictions
= false;
799 Globals
.syslog_only
= false;
800 Globals
.timestamp_logs
= true;
801 string_set(Globals
.ctx
, &Globals
.log_level
, "0");
802 Globals
.debug_prefix_timestamp
= false;
803 Globals
.debug_hires_timestamp
= true;
804 Globals
.debug_pid
= false;
805 Globals
.debug_uid
= false;
806 Globals
.debug_class
= false;
807 Globals
.enable_core_files
= true;
808 Globals
.max_ttl
= 60 * 60 * 24 * 3; /* 3 days default. */
809 Globals
.max_wins_ttl
= 60 * 60 * 24 * 6; /* 6 days default. */
810 Globals
.min_wins_ttl
= 60 * 60 * 6; /* 6 hours default. */
811 Globals
.machine_password_timeout
= 60 * 60 * 24 * 7; /* 7 days default. */
812 Globals
.lm_announce
= Auto
; /* = Auto: send only if LM clients found */
813 Globals
.lm_interval
= 60;
814 #if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT))
815 Globals
.nis_homedir
= false;
816 #ifdef WITH_NISPLUS_HOME
817 string_set(Globals
.ctx
, &Globals
.homedir_map
, "auto_home.org_dir");
819 string_set(Globals
.ctx
, &Globals
.homedir_map
, "auto.home");
822 Globals
.time_server
= false;
823 Globals
.bind_interfaces_only
= false;
824 Globals
.unix_password_sync
= false;
825 Globals
.pam_password_change
= false;
826 Globals
.passwd_chat_debug
= false;
827 Globals
.passwd_chat_timeout
= 2; /* 2 second default. */
828 Globals
.nt_pipe_support
= true; /* Do NT pipes by default. */
829 Globals
.nt_status_support
= true; /* Use NT status by default. */
830 Globals
.stat_cache
= true; /* use stat cache by default */
831 Globals
.max_stat_cache_size
= 256; /* 256k by default */
832 Globals
.restrict_anonymous
= 0;
833 Globals
.client_lanman_auth
= false; /* Do NOT use the LanMan hash if it is available */
834 Globals
.client_plaintext_auth
= false; /* Do NOT use a plaintext password even if is requested by the server */
835 Globals
.lanman_auth
= false; /* Do NOT use the LanMan hash, even if it is supplied */
836 Globals
.ntlm_auth
= true; /* Do use NTLMv1 if it is supplied by the client (otherwise NTLMv2) */
837 Globals
.client_ntlmv2_auth
= true; /* Client should always use use NTLMv2, as we can't tell that the server supports it, but most modern servers do */
838 /* Note, that we will also use NTLM2 session security (which is different), if it is available */
840 Globals
.map_to_guest
= 0; /* By Default, "Never" */
841 Globals
.oplock_break_wait_time
= 0; /* By Default, 0 msecs. */
842 Globals
.enhanced_browsing
= true;
843 Globals
.lock_spin_time
= WINDOWS_MINIMUM_LOCK_TIMEOUT_MS
; /* msec. */
844 #ifdef MMAP_BLACKLIST
845 Globals
.use_mmap
= false;
847 Globals
.use_mmap
= true;
849 Globals
.unicode
= true;
850 Globals
.unix_extensions
= true;
851 Globals
.reset_on_zero_vc
= false;
852 Globals
.log_writeable_files_on_exit
= false;
853 Globals
.create_krb5_conf
= true;
854 Globals
.winbindMaxDomainConnections
= 1;
856 /* hostname lookups can be very expensive and are broken on
857 a large number of sites (tridge) */
858 Globals
.hostname_lookups
= false;
860 string_set(Globals
.ctx
, &Globals
.passdb_backend
, "tdbsam");
861 string_set(Globals
.ctx
, &Globals
.ldap_suffix
, "");
862 string_set(Globals
.ctx
, &Globals
.szLdapMachineSuffix
, "");
863 string_set(Globals
.ctx
, &Globals
.szLdapUserSuffix
, "");
864 string_set(Globals
.ctx
, &Globals
.szLdapGroupSuffix
, "");
865 string_set(Globals
.ctx
, &Globals
.szLdapIdmapSuffix
, "");
867 string_set(Globals
.ctx
, &Globals
.ldap_admin_dn
, "");
868 Globals
.ldap_ssl
= LDAP_SSL_START_TLS
;
869 Globals
.ldap_ssl_ads
= false;
870 Globals
.ldap_deref
= -1;
871 Globals
.ldap_passwd_sync
= LDAP_PASSWD_SYNC_OFF
;
872 Globals
.ldap_delete_dn
= false;
873 Globals
.ldap_replication_sleep
= 1000; /* wait 1 sec for replication */
874 Globals
.ldap_follow_referral
= Auto
;
875 Globals
.ldap_timeout
= LDAP_DEFAULT_TIMEOUT
;
876 Globals
.ldap_connection_timeout
= LDAP_CONNECTION_DEFAULT_TIMEOUT
;
877 Globals
.ldap_page_size
= LDAP_PAGE_SIZE
;
879 Globals
.ldap_debug_level
= 0;
880 Globals
.ldap_debug_threshold
= 10;
882 /* This is what we tell the afs client. in reality we set the token
883 * to never expire, though, when this runs out the afs client will
884 * forget the token. Set to 0 to get NEVERDATE.*/
885 Globals
.afs_token_lifetime
= 604800;
886 Globals
.cups_connection_timeout
= CUPS_DEFAULT_CONNECTION_TIMEOUT
;
888 /* these parameters are set to defaults that are more appropriate
889 for the increasing samba install base:
891 as a member of the workgroup, that will possibly become a
892 _local_ master browser (lm = true). this is opposed to a forced
893 local master browser startup (pm = true).
895 doesn't provide WINS server service by default (wsupp = false),
896 and doesn't provide domain master browser services by default, either.
900 Globals
.show_add_printer_wizard
= true;
901 Globals
.os_level
= 20;
902 Globals
.local_master
= true;
903 Globals
._domain_master
= Auto
; /* depending on _domain_logons */
904 Globals
._domain_logons
= false;
905 Globals
.browse_list
= true;
906 Globals
.we_are_a_wins_server
= false;
907 Globals
.wins_proxy
= false;
909 TALLOC_FREE(Globals
.init_logon_delayed_hosts
);
910 Globals
.init_logon_delay
= 100; /* 100 ms default delay */
912 Globals
.wins_dns_proxy
= true;
914 Globals
.allow_trusted_domains
= true;
915 string_set(Globals
.ctx
, &Globals
.szIdmapBackend
, "tdb");
917 string_set(Globals
.ctx
, &Globals
.template_shell
, "/bin/false");
918 string_set(Globals
.ctx
, &Globals
.template_homedir
, "/home/%D/%U");
919 string_set(Globals
.ctx
, &Globals
.winbind_separator
, "\\");
920 string_set(Globals
.ctx
, &Globals
.winbindd_socket_directory
, dyn_WINBINDD_SOCKET_DIR
);
922 string_set(Globals
.ctx
, &Globals
.cups_server
, "");
923 string_set(Globals
.ctx
, &Globals
.iprint_server
, "");
925 string_set(Globals
.ctx
, &Globals
._ctdbd_socket
, "");
927 Globals
.cluster_addresses
= NULL
;
928 Globals
.clustering
= false;
929 Globals
.ctdb_timeout
= 0;
930 Globals
.ctdb_locktime_warn_threshold
= 0;
932 Globals
.winbind_cache_time
= 300; /* 5 minutes */
933 Globals
.winbind_reconnect_delay
= 30; /* 30 seconds */
934 Globals
.winbind_max_clients
= 200;
935 Globals
.winbind_enum_users
= false;
936 Globals
.winbind_enum_groups
= false;
937 Globals
.winbind_use_default_domain
= false;
938 Globals
.winbind_trusted_domains_only
= false;
939 Globals
.winbind_nested_groups
= true;
940 Globals
.winbind_expand_groups
= 1;
941 Globals
.winbind_nss_info
= (const char **)str_list_make_v3(NULL
, "template", NULL
);
942 Globals
.winbind_refresh_tickets
= false;
943 Globals
.winbind_offline_logon
= false;
945 Globals
.idmap_cache_time
= 86400 * 7; /* a week by default */
946 Globals
.idmap_negative_cache_time
= 120; /* 2 minutes by default */
948 Globals
.passdb_expand_explicit
= false;
950 Globals
.name_cache_timeout
= 660; /* In seconds */
952 Globals
.use_spnego
= true;
953 Globals
.client_use_spnego
= true;
955 Globals
.client_signing
= SMB_SIGNING_DEFAULT
;
956 Globals
.server_signing
= SMB_SIGNING_DEFAULT
;
958 Globals
.defer_sharing_violations
= true;
959 Globals
.smb_ports
= (const char **)str_list_make_v3(NULL
, SMB_PORTS
, NULL
);
961 Globals
.enable_privileges
= true;
962 Globals
.host_msdfs
= true;
963 Globals
.enable_asu_support
= false;
965 /* User defined shares. */
966 s
= talloc_asprintf(talloc_tos(), "%s/usershares", get_dyn_STATEDIR());
968 smb_panic("init_globals: ENOMEM");
970 string_set(Globals
.ctx
, &Globals
.usershare_path
, s
);
972 string_set(Globals
.ctx
, &Globals
.usershare_template_share
, "");
973 Globals
.usershare_max_shares
= 0;
974 /* By default disallow sharing of directories not owned by the sharer. */
975 Globals
.usershare_owner_only
= true;
976 /* By default disallow guest access to usershares. */
977 Globals
.usershare_allow_guests
= false;
979 Globals
.keepalive
= DEFAULT_KEEPALIVE
;
981 /* By default no shares out of the registry */
982 Globals
.registry_shares
= false;
984 Globals
.iminreceivefile
= 0;
986 Globals
.map_untrusted_to_domain
= false;
987 Globals
.multicast_dns_register
= true;
989 Globals
.smb2_max_read
= DEFAULT_SMB2_MAX_READ
;
990 Globals
.smb2_max_write
= DEFAULT_SMB2_MAX_WRITE
;
991 Globals
.smb2_max_trans
= DEFAULT_SMB2_MAX_TRANSACT
;
992 Globals
.ismb2_max_credits
= DEFAULT_SMB2_MAX_CREDITS
;
994 string_set(Globals
.ctx
, &Globals
.ncalrpc_dir
, get_dyn_NCALRPCDIR());
996 Globals
.server_services
= (const char **)str_list_make_v3(NULL
, "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns", NULL
);
998 Globals
.dcerpc_endpoint_servers
= (const char **)str_list_make_v3(NULL
, "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver", NULL
);
1000 Globals
.tls_enabled
= true;
1002 string_set(Globals
.ctx
, &Globals
._tls_keyfile
, "tls/key.pem");
1003 string_set(Globals
.ctx
, &Globals
._tls_certfile
, "tls/cert.pem");
1004 string_set(Globals
.ctx
, &Globals
._tls_cafile
, "tls/ca.pem");
1006 string_set(Globals
.ctx
, &Globals
.share_backend
, "classic");
1008 Globals
.iPreferredMaster
= Auto
;
1010 Globals
.allow_dns_updates
= DNS_UPDATE_SIGNED
;
1012 string_set(Globals
.ctx
, &Globals
.ntp_signd_socket_directory
, get_dyn_NTP_SIGND_SOCKET_DIR());
1014 string_set(Globals
.ctx
, &Globals
.winbindd_privileged_socket_directory
, get_dyn_WINBINDD_PRIVILEGED_SOCKET_DIR());
1016 s
= talloc_asprintf(talloc_tos(), "%s/samba_kcc", get_dyn_SCRIPTSBINDIR());
1018 smb_panic("init_globals: ENOMEM");
1020 Globals
.samba_kcc_command
= (const char **)str_list_make_v3(NULL
, s
, NULL
);
1023 s
= talloc_asprintf(talloc_tos(), "%s/samba_dnsupdate", get_dyn_SCRIPTSBINDIR());
1025 smb_panic("init_globals: ENOMEM");
1027 Globals
.dns_update_command
= (const char **)str_list_make_v3(NULL
, s
, NULL
);
1030 s
= talloc_asprintf(talloc_tos(), "%s/samba_spnupdate", get_dyn_SCRIPTSBINDIR());
1032 smb_panic("init_globals: ENOMEM");
1034 Globals
.spn_update_command
= (const char **)str_list_make_v3(NULL
, s
, NULL
);
1037 Globals
.nsupdate_command
= (const char **)str_list_make_v3(NULL
, "/usr/bin/nsupdate -g", NULL
);
1039 Globals
.rndc_command
= (const char **)str_list_make_v3(NULL
, "/usr/sbin/rndc", NULL
);
1041 Globals
.cldap_port
= 389;
1043 Globals
.dgram_port
= 138;
1045 Globals
.nbt_port
= 137;
1047 Globals
.krb5_port
= 88;
1049 Globals
.kpasswd_port
= 464;
1051 Globals
.web_port
= 901;
1053 /* Now put back the settings that were set with lp_set_cmdline() */
1054 apply_lp_set_cmdline();
1057 /*******************************************************************
1058 Convenience routine to grab string parameters into talloced memory
1059 and run standard_sub_basic on them. The buffers can be written to by
1060 callers without affecting the source string.
1061 ********************************************************************/
1063 char *lp_string(TALLOC_CTX
*ctx
, const char *s
)
1067 /* The follow debug is useful for tracking down memory problems
1068 especially if you have an inner loop that is calling a lp_*()
1069 function that returns a string. Perhaps this debug should be
1070 present all the time? */
1073 DEBUG(10, ("lp_string(%s)\n", s
));
1079 ret
= talloc_sub_basic(ctx
,
1080 get_current_username(),
1081 current_user_info
.domain
,
1083 if (trim_char(ret
, '\"', '\"')) {
1084 if (strchr(ret
,'\"') != NULL
) {
1086 ret
= talloc_sub_basic(ctx
,
1087 get_current_username(),
1088 current_user_info
.domain
,
1096 In this section all the functions that are used to access the
1097 parameters from the rest of the program are defined
1100 #define FN_GLOBAL_STRING(fn_name,ptr) \
1101 char *lp_ ## fn_name(TALLOC_CTX *ctx) {return(lp_string((ctx), *(char **)(&Globals.ptr) ? *(char **)(&Globals.ptr) : ""));}
1102 #define FN_GLOBAL_CONST_STRING(fn_name,ptr) \
1103 const char *lp_ ## fn_name(void) {return(*(const char * const *)(&Globals.ptr) ? *(const char * const *)(&Globals.ptr) : "");}
1104 #define FN_GLOBAL_LIST(fn_name,ptr) \
1105 const char **lp_ ## fn_name(void) {return(*(const char ***)(&Globals.ptr));}
1106 #define FN_GLOBAL_BOOL(fn_name,ptr) \
1107 bool lp_ ## fn_name(void) {return(*(bool *)(&Globals.ptr));}
1108 #define FN_GLOBAL_CHAR(fn_name,ptr) \
1109 char lp_ ## fn_name(void) {return(*(char *)(&Globals.ptr));}
1110 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
1111 int lp_ ## fn_name(void) {return(*(int *)(&Globals.ptr));}
1113 #define FN_LOCAL_STRING(fn_name,val) \
1114 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));}
1115 #define FN_LOCAL_CONST_STRING(fn_name,val) \
1116 const char *lp_ ## fn_name(int i) {return (const char *)((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val);}
1117 #define FN_LOCAL_LIST(fn_name,val) \
1118 const char **lp_ ## fn_name(int i) {return(const char **)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1119 #define FN_LOCAL_BOOL(fn_name,val) \
1120 bool lp_ ## fn_name(int i) {return(bool)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1121 #define FN_LOCAL_INTEGER(fn_name,val) \
1122 int lp_ ## fn_name(int i) {return(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1124 #define FN_LOCAL_PARM_BOOL(fn_name,val) \
1125 bool lp_ ## fn_name(const struct share_params *p) {return(bool)(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1126 #define FN_LOCAL_PARM_INTEGER(fn_name,val) \
1127 int lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1128 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
1129 char lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1131 static FN_GLOBAL_INTEGER(winbind_max_domain_connections_int
,
1132 winbindMaxDomainConnections
)
1134 int lp_winbind_max_domain_connections(void)
1136 if (lp_winbind_offline_logon() &&
1137 lp_winbind_max_domain_connections_int() > 1) {
1138 DEBUG(1, ("offline logons active, restricting max domain "
1139 "connections to 1\n"));
1142 return MAX(1, lp_winbind_max_domain_connections_int());
1145 int lp_smb2_max_credits(void)
1147 if (Globals
.ismb2_max_credits
== 0) {
1148 Globals
.ismb2_max_credits
= DEFAULT_SMB2_MAX_CREDITS
;
1150 return Globals
.ismb2_max_credits
;
1152 int lp_cups_encrypt(void)
1155 #ifdef HAVE_HTTPCONNECTENCRYPT
1156 switch (Globals
.CupsEncrypt
) {
1158 result
= HTTP_ENCRYPT_REQUIRED
;
1161 result
= HTTP_ENCRYPT_ALWAYS
;
1164 result
= HTTP_ENCRYPT_NEVER
;
1171 /* These functions remain in source3/param for now */
1173 #include "lib/param/param_functions.c"
1175 FN_LOCAL_STRING(servicename
, szService
)
1176 FN_LOCAL_CONST_STRING(const_servicename
, szService
)
1178 /* These functions cannot be auto-generated */
1179 FN_LOCAL_BOOL(autoloaded
, autoloaded
)
1181 /* local prototypes */
1183 static int map_parameter_canonical(const char *pszParmName
, bool *inverse
);
1184 static const char *get_boolean(bool bool_value
);
1185 static int getservicebyname(const char *pszServiceName
,
1186 struct loadparm_service
*pserviceDest
);
1187 static void copy_service(struct loadparm_service
*pserviceDest
,
1188 struct loadparm_service
*pserviceSource
,
1189 struct bitmap
*pcopymapDest
);
1190 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1192 static bool do_section(const char *pszSectionName
, void *userdata
);
1193 static void init_copymap(struct loadparm_service
*pservice
);
1194 static bool hash_a_service(const char *name
, int number
);
1195 static void free_service_byindex(int iService
);
1196 static void show_parameter(int parmIndex
);
1197 static bool is_synonym_of(int parm1
, int parm2
, bool *inverse
);
1200 * This is a helper function for parametrical options support. It returns a
1201 * pointer to parametrical option value if it exists or NULL otherwise. Actual
1202 * parametrical functions are quite simple
1204 static struct parmlist_entry
*get_parametrics_by_service(struct loadparm_service
*service
, const char *type
,
1207 bool global_section
= false;
1209 struct parmlist_entry
*data
;
1210 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1212 if (service
== NULL
) {
1213 data
= Globals
.param_opt
;
1214 global_section
= true;
1216 data
= service
->param_opt
;
1219 param_key
= talloc_asprintf(mem_ctx
, "%s:%s", type
, option
);
1220 if (param_key
== NULL
) {
1221 DEBUG(0,("asprintf failed!\n"));
1222 TALLOC_FREE(mem_ctx
);
1227 if (strwicmp(data
->key
, param_key
) == 0) {
1228 TALLOC_FREE(mem_ctx
);
1234 if (!global_section
) {
1235 /* Try to fetch the same option but from globals */
1236 /* but only if we are not already working with Globals */
1237 data
= Globals
.param_opt
;
1239 if (strwicmp(data
->key
, param_key
) == 0) {
1240 TALLOC_FREE(mem_ctx
);
1247 TALLOC_FREE(mem_ctx
);
1253 * This is a helper function for parametrical options support. It returns a
1254 * pointer to parametrical option value if it exists or NULL otherwise. Actual
1255 * parametrical functions are quite simple
1257 static struct parmlist_entry
*get_parametrics(int snum
, const char *type
,
1260 if (snum
>= iNumServices
) return NULL
;
1263 return get_parametrics_by_service(NULL
, type
, option
);
1265 return get_parametrics_by_service(ServicePtrs
[snum
], type
, option
);
1270 #define MISSING_PARAMETER(name) \
1271 DEBUG(0, ("%s(): value is NULL or empty!\n", #name))
1273 /*******************************************************************
1274 convenience routine to return int parameters.
1275 ********************************************************************/
1276 static int lp_int(const char *s
)
1280 MISSING_PARAMETER(lp_int
);
1284 return (int)strtol(s
, NULL
, 0);
1287 /*******************************************************************
1288 convenience routine to return unsigned long parameters.
1289 ********************************************************************/
1290 static unsigned long lp_ulong(const char *s
)
1294 MISSING_PARAMETER(lp_ulong
);
1298 return strtoul(s
, NULL
, 0);
1301 /*******************************************************************
1302 convenience routine to return boolean parameters.
1303 ********************************************************************/
1304 static bool lp_bool(const char *s
)
1309 MISSING_PARAMETER(lp_bool
);
1313 if (!set_boolean(s
, &ret
)) {
1314 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
1321 /*******************************************************************
1322 convenience routine to return enum parameters.
1323 ********************************************************************/
1324 static int lp_enum(const char *s
,const struct enum_list
*_enum
)
1328 if (!s
|| !*s
|| !_enum
) {
1329 MISSING_PARAMETER(lp_enum
);
1333 for (i
=0; _enum
[i
].name
; i
++) {
1334 if (strequal(_enum
[i
].name
,s
))
1335 return _enum
[i
].value
;
1338 DEBUG(0,("lp_enum(%s,enum): value is not in enum_list!\n",s
));
1342 #undef MISSING_PARAMETER
1344 /* Return parametric option from a given service. Type is a part of option before ':' */
1345 /* Parametric option has following syntax: 'Type: option = value' */
1346 char *lp_parm_talloc_string(TALLOC_CTX
*ctx
, int snum
, const char *type
, const char *option
, const char *def
)
1348 struct parmlist_entry
*data
= get_parametrics(snum
, type
, option
);
1350 if (data
== NULL
||data
->value
==NULL
) {
1352 return lp_string(ctx
, def
);
1358 return lp_string(ctx
, data
->value
);
1361 /* Return parametric option from a given service. Type is a part of option before ':' */
1362 /* Parametric option has following syntax: 'Type: option = value' */
1363 const char *lp_parm_const_string(int snum
, const char *type
, const char *option
, const char *def
)
1365 struct parmlist_entry
*data
= get_parametrics(snum
, type
, option
);
1367 if (data
== NULL
||data
->value
==NULL
)
1373 const char *lp_parm_const_string_service(struct loadparm_service
*service
, const char *type
, const char *option
)
1375 struct parmlist_entry
*data
= get_parametrics_by_service(service
, type
, option
);
1377 if (data
== NULL
||data
->value
==NULL
)
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 const char **lp_parm_string_list(int snum
, const char *type
, const char *option
, const char **def
)
1389 struct parmlist_entry
*data
= get_parametrics(snum
, type
, option
);
1391 if (data
== NULL
||data
->value
==NULL
)
1392 return (const char **)def
;
1394 if (data
->list
==NULL
) {
1395 data
->list
= str_list_make_v3(NULL
, data
->value
, NULL
);
1398 return (const char **)data
->list
;
1401 /* Return parametric option from a given service. Type is a part of option before ':' */
1402 /* Parametric option has following syntax: 'Type: option = value' */
1404 int lp_parm_int(int snum
, const char *type
, const char *option
, int def
)
1406 struct parmlist_entry
*data
= get_parametrics(snum
, type
, option
);
1408 if (data
&& data
->value
&& *data
->value
)
1409 return lp_int(data
->value
);
1414 /* Return parametric option from a given service. Type is a part of option before ':' */
1415 /* Parametric option has following syntax: 'Type: option = value' */
1417 unsigned long lp_parm_ulong(int snum
, const char *type
, const char *option
, unsigned long def
)
1419 struct parmlist_entry
*data
= get_parametrics(snum
, type
, option
);
1421 if (data
&& data
->value
&& *data
->value
)
1422 return lp_ulong(data
->value
);
1427 /* Return parametric option from a given service. Type is a part of option before ':' */
1428 /* Parametric option has following syntax: 'Type: option = value' */
1430 bool lp_parm_bool(int snum
, const char *type
, const char *option
, bool def
)
1432 struct parmlist_entry
*data
= get_parametrics(snum
, type
, option
);
1434 if (data
&& data
->value
&& *data
->value
)
1435 return lp_bool(data
->value
);
1440 /* Return parametric option from a given service. Type is a part of option before ':' */
1441 /* Parametric option has following syntax: 'Type: option = value' */
1443 int lp_parm_enum(int snum
, const char *type
, const char *option
,
1444 const struct enum_list
*_enum
, int def
)
1446 struct parmlist_entry
*data
= get_parametrics(snum
, type
, option
);
1448 if (data
&& data
->value
&& *data
->value
&& _enum
)
1449 return lp_enum(data
->value
, _enum
);
1455 /***************************************************************************
1456 Initialise a service to the defaults.
1457 ***************************************************************************/
1459 static void init_service(struct loadparm_service
*pservice
)
1461 memset((char *)pservice
, '\0', sizeof(struct loadparm_service
));
1462 copy_service(pservice
, &sDefault
, NULL
);
1467 * free a param_opts structure.
1468 * param_opts handling should be moved to talloc;
1469 * then this whole functions reduces to a TALLOC_FREE().
1472 static void free_param_opts(struct parmlist_entry
**popts
)
1474 struct parmlist_entry
*opt
, *next_opt
;
1476 if (*popts
!= NULL
) {
1477 DEBUG(5, ("Freeing parametrics:\n"));
1480 while (opt
!= NULL
) {
1481 string_free(&opt
->key
);
1482 string_free(&opt
->value
);
1483 TALLOC_FREE(opt
->list
);
1484 next_opt
= opt
->next
;
1491 /***************************************************************************
1492 Free the dynamically allocated parts of a service struct.
1493 ***************************************************************************/
1495 static void free_service(struct loadparm_service
*pservice
)
1500 if (pservice
->szService
)
1501 DEBUG(5, ("free_service: Freeing service %s\n",
1502 pservice
->szService
));
1504 free_parameters(pservice
);
1506 string_free(&pservice
->szService
);
1507 TALLOC_FREE(pservice
->copymap
);
1509 free_param_opts(&pservice
->param_opt
);
1511 ZERO_STRUCTP(pservice
);
1515 /***************************************************************************
1516 remove a service indexed in the ServicePtrs array from the ServiceHash
1517 and free the dynamically allocated parts
1518 ***************************************************************************/
1520 static void free_service_byindex(int idx
)
1522 if ( !LP_SNUM_OK(idx
) )
1525 ServicePtrs
[idx
]->valid
= false;
1527 /* we have to cleanup the hash record */
1529 if (ServicePtrs
[idx
]->szService
) {
1530 char *canon_name
= canonicalize_servicename(
1532 ServicePtrs
[idx
]->szService
);
1534 dbwrap_delete_bystring(ServiceHash
, canon_name
);
1535 TALLOC_FREE(canon_name
);
1538 free_service(ServicePtrs
[idx
]);
1539 talloc_free_children(ServicePtrs
[idx
]);
1542 /***************************************************************************
1543 Add a new service to the services array initialising it with the given
1545 ***************************************************************************/
1547 static int add_a_service(const struct loadparm_service
*pservice
, const char *name
)
1550 struct loadparm_service tservice
;
1551 int num_to_alloc
= iNumServices
+ 1;
1552 struct loadparm_service
**tsp
= NULL
;
1554 tservice
= *pservice
;
1556 /* it might already exist */
1558 i
= getservicebyname(name
, NULL
);
1564 /* if not, then create one */
1566 tsp
= talloc_realloc(NULL
, ServicePtrs
, struct loadparm_service
*, num_to_alloc
);
1568 DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
1572 ServicePtrs
[iNumServices
] = talloc(NULL
, struct loadparm_service
);
1573 if (!ServicePtrs
[iNumServices
]) {
1574 DEBUG(0,("add_a_service: out of memory!\n"));
1579 ServicePtrs
[i
]->valid
= true;
1581 init_service(ServicePtrs
[i
]);
1582 copy_service(ServicePtrs
[i
], &tservice
, NULL
);
1584 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->szService
, name
);
1586 DEBUG(8,("add_a_service: Creating snum = %d for %s\n",
1587 i
, ServicePtrs
[i
]->szService
));
1589 if (!hash_a_service(ServicePtrs
[i
]->szService
, i
)) {
1596 /***************************************************************************
1597 Convert a string to uppercase and remove whitespaces.
1598 ***************************************************************************/
1600 char *canonicalize_servicename(TALLOC_CTX
*ctx
, const char *src
)
1605 DEBUG(0,("canonicalize_servicename: NULL source name!\n"));
1609 result
= talloc_strdup(ctx
, src
);
1610 SMB_ASSERT(result
!= NULL
);
1612 if (!strlower_m(result
)) {
1613 TALLOC_FREE(result
);
1619 /***************************************************************************
1620 Add a name/index pair for the services array to the hash table.
1621 ***************************************************************************/
1623 static bool hash_a_service(const char *name
, int idx
)
1627 if ( !ServiceHash
) {
1628 DEBUG(10,("hash_a_service: creating servicehash\n"));
1629 ServiceHash
= db_open_rbt(NULL
);
1630 if ( !ServiceHash
) {
1631 DEBUG(0,("hash_a_service: open tdb servicehash failed!\n"));
1636 DEBUG(10,("hash_a_service: hashing index %d for service name %s\n",
1639 canon_name
= canonicalize_servicename(talloc_tos(), name
);
1641 dbwrap_store_bystring(ServiceHash
, canon_name
,
1642 make_tdb_data((uint8
*)&idx
, sizeof(idx
)),
1645 TALLOC_FREE(canon_name
);
1650 /***************************************************************************
1651 Add a new home service, with the specified home directory, defaults coming
1653 ***************************************************************************/
1655 bool lp_add_home(const char *pszHomename
, int iDefaultService
,
1656 const char *user
, const char *pszHomedir
)
1660 if (pszHomename
== NULL
|| user
== NULL
|| pszHomedir
== NULL
||
1661 pszHomedir
[0] == '\0') {
1665 i
= add_a_service(ServicePtrs
[iDefaultService
], pszHomename
);
1670 if (!(*(ServicePtrs
[iDefaultService
]->path
))
1671 || strequal(ServicePtrs
[iDefaultService
]->path
,
1672 lp_path(talloc_tos(), GLOBAL_SECTION_SNUM
))) {
1673 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->path
, pszHomedir
);
1676 if (!(*(ServicePtrs
[i
]->comment
))) {
1677 char *comment
= talloc_asprintf(talloc_tos(), "Home directory of %s", user
);
1678 if (comment
== NULL
) {
1681 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->comment
, comment
);
1682 TALLOC_FREE(comment
);
1685 /* set the browseable flag from the global default */
1687 ServicePtrs
[i
]->browseable
= sDefault
.browseable
;
1688 ServicePtrs
[i
]->access_based_share_enum
= sDefault
.access_based_share_enum
;
1690 ServicePtrs
[i
]->autoloaded
= true;
1692 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename
,
1693 user
, ServicePtrs
[i
]->path
));
1698 /***************************************************************************
1699 Add a new service, based on an old one.
1700 ***************************************************************************/
1702 int lp_add_service(const char *pszService
, int iDefaultService
)
1704 if (iDefaultService
< 0) {
1705 return add_a_service(&sDefault
, pszService
);
1708 return (add_a_service(ServicePtrs
[iDefaultService
], pszService
));
1711 /***************************************************************************
1712 Add the IPC service.
1713 ***************************************************************************/
1715 static bool lp_add_ipc(const char *ipc_name
, bool guest_ok
)
1717 char *comment
= NULL
;
1718 int i
= add_a_service(&sDefault
, ipc_name
);
1723 comment
= talloc_asprintf(talloc_tos(), "IPC Service (%s)",
1724 Globals
.server_string
);
1725 if (comment
== NULL
) {
1729 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->path
, tmpdir());
1730 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->username
, "");
1731 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->comment
, comment
);
1732 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->fstype
, "IPC");
1733 ServicePtrs
[i
]->max_connections
= 0;
1734 ServicePtrs
[i
]->bAvailable
= true;
1735 ServicePtrs
[i
]->read_only
= true;
1736 ServicePtrs
[i
]->guest_only
= false;
1737 ServicePtrs
[i
]->administrative_share
= true;
1738 ServicePtrs
[i
]->guest_ok
= guest_ok
;
1739 ServicePtrs
[i
]->printable
= false;
1740 ServicePtrs
[i
]->browseable
= sDefault
.browseable
;
1742 DEBUG(3, ("adding IPC service\n"));
1744 TALLOC_FREE(comment
);
1748 /***************************************************************************
1749 Add a new printer service, with defaults coming from service iFrom.
1750 ***************************************************************************/
1752 bool lp_add_printer(const char *pszPrintername
, int iDefaultService
)
1754 const char *comment
= "From Printcap";
1755 int i
= add_a_service(ServicePtrs
[iDefaultService
], pszPrintername
);
1760 /* note that we do NOT default the availability flag to true - */
1761 /* we take it from the default service passed. This allows all */
1762 /* dynamic printers to be disabled by disabling the [printers] */
1763 /* entry (if/when the 'available' keyword is implemented!). */
1765 /* the printer name is set to the service name. */
1766 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->_printername
, pszPrintername
);
1767 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->comment
, comment
);
1769 /* set the browseable flag from the gloabl default */
1770 ServicePtrs
[i
]->browseable
= sDefault
.browseable
;
1772 /* Printers cannot be read_only. */
1773 ServicePtrs
[i
]->read_only
= false;
1774 /* No oplocks on printer services. */
1775 ServicePtrs
[i
]->oplocks
= false;
1776 /* Printer services must be printable. */
1777 ServicePtrs
[i
]->printable
= true;
1779 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1785 /***************************************************************************
1786 Check whether the given parameter name is valid.
1787 Parametric options (names containing a colon) are considered valid.
1788 ***************************************************************************/
1790 bool lp_parameter_is_valid(const char *pszParmName
)
1792 return ((lpcfg_map_parameter(pszParmName
) != -1) ||
1793 (strchr(pszParmName
, ':') != NULL
));
1796 /***************************************************************************
1797 Check whether the given name is the name of a global parameter.
1798 Returns true for strings belonging to parameters of class
1799 P_GLOBAL, false for all other strings, also for parametric options
1800 and strings not belonging to any option.
1801 ***************************************************************************/
1803 bool lp_parameter_is_global(const char *pszParmName
)
1805 int num
= lpcfg_map_parameter(pszParmName
);
1808 return (parm_table
[num
].p_class
== P_GLOBAL
);
1814 /**************************************************************************
1815 Check whether the given name is the canonical name of a parameter.
1816 Returns false if it is not a valid parameter Name.
1817 For parametric options, true is returned.
1818 **************************************************************************/
1820 bool lp_parameter_is_canonical(const char *parm_name
)
1822 if (!lp_parameter_is_valid(parm_name
)) {
1826 return (lpcfg_map_parameter(parm_name
) ==
1827 map_parameter_canonical(parm_name
, NULL
));
1830 /**************************************************************************
1831 Determine the canonical name for a parameter.
1832 Indicate when it is an inverse (boolean) synonym instead of a
1834 **************************************************************************/
1836 bool lp_canonicalize_parameter(const char *parm_name
, const char **canon_parm
,
1841 if (!lp_parameter_is_valid(parm_name
)) {
1846 num
= map_parameter_canonical(parm_name
, inverse
);
1848 /* parametric option */
1849 *canon_parm
= parm_name
;
1851 *canon_parm
= parm_table
[num
].label
;
1858 /**************************************************************************
1859 Determine the canonical name for a parameter.
1860 Turn the value given into the inverse boolean expression when
1861 the synonym is an invers boolean synonym.
1863 Return true if parm_name is a valid parameter name and
1864 in case it is an invers boolean synonym, if the val string could
1865 successfully be converted to the reverse bool.
1866 Return false in all other cases.
1867 **************************************************************************/
1869 bool lp_canonicalize_parameter_with_value(const char *parm_name
,
1871 const char **canon_parm
,
1872 const char **canon_val
)
1877 if (!lp_parameter_is_valid(parm_name
)) {
1883 num
= map_parameter_canonical(parm_name
, &inverse
);
1885 /* parametric option */
1886 *canon_parm
= parm_name
;
1889 *canon_parm
= parm_table
[num
].label
;
1891 if (!lp_invert_boolean(val
, canon_val
)) {
1903 /***************************************************************************
1904 Map a parameter's string representation to the index of the canonical
1905 form of the parameter (it might be a synonym).
1906 Returns -1 if the parameter string is not recognised.
1907 ***************************************************************************/
1909 static int map_parameter_canonical(const char *pszParmName
, bool *inverse
)
1911 int parm_num
, canon_num
;
1912 bool loc_inverse
= false;
1914 parm_num
= lpcfg_map_parameter(pszParmName
);
1915 if ((parm_num
< 0) || !(parm_table
[parm_num
].flags
& FLAG_HIDE
)) {
1916 /* invalid, parametric or no canidate for synonyms ... */
1920 for (canon_num
= 0; parm_table
[canon_num
].label
; canon_num
++) {
1921 if (is_synonym_of(parm_num
, canon_num
, &loc_inverse
)) {
1922 parm_num
= canon_num
;
1928 if (inverse
!= NULL
) {
1929 *inverse
= loc_inverse
;
1934 /***************************************************************************
1935 return true if parameter number parm1 is a synonym of parameter
1936 number parm2 (parm2 being the principal name).
1937 set inverse to true if parm1 is P_BOOLREV and parm2 is P_BOOL,
1939 ***************************************************************************/
1941 static bool is_synonym_of(int parm1
, int parm2
, bool *inverse
)
1943 if ((parm_table
[parm1
].offset
== parm_table
[parm2
].offset
) &&
1944 (parm_table
[parm1
].p_class
== parm_table
[parm2
].p_class
) &&
1945 (parm_table
[parm1
].flags
& FLAG_HIDE
) &&
1946 !(parm_table
[parm2
].flags
& FLAG_HIDE
))
1948 if (inverse
!= NULL
) {
1949 if ((parm_table
[parm1
].type
== P_BOOLREV
) &&
1950 (parm_table
[parm2
].type
== P_BOOL
))
1962 /***************************************************************************
1963 Show one parameter's name, type, [values,] and flags.
1964 (helper functions for show_parameter_list)
1965 ***************************************************************************/
1967 static void show_parameter(int parmIndex
)
1969 int enumIndex
, flagIndex
;
1974 const char *type
[] = { "P_BOOL", "P_BOOLREV", "P_CHAR", "P_INTEGER",
1975 "P_OCTAL", "P_LIST", "P_STRING", "P_USTRING",
1977 unsigned flags
[] = { FLAG_BASIC
, FLAG_SHARE
, FLAG_PRINT
, FLAG_GLOBAL
,
1978 FLAG_WIZARD
, FLAG_ADVANCED
, FLAG_DEVELOPER
, FLAG_DEPRECATED
,
1980 const char *flag_names
[] = { "FLAG_BASIC", "FLAG_SHARE", "FLAG_PRINT",
1981 "FLAG_GLOBAL", "FLAG_WIZARD", "FLAG_ADVANCED", "FLAG_DEVELOPER",
1982 "FLAG_DEPRECATED", "FLAG_HIDE", NULL
};
1984 printf("%s=%s", parm_table
[parmIndex
].label
,
1985 type
[parm_table
[parmIndex
].type
]);
1986 if (parm_table
[parmIndex
].type
== P_ENUM
) {
1989 parm_table
[parmIndex
].enum_list
[enumIndex
].name
;
1993 enumIndex
? "|" : "",
1994 parm_table
[parmIndex
].enum_list
[enumIndex
].name
);
1999 for (flagIndex
=0; flag_names
[flagIndex
]; flagIndex
++) {
2000 if (parm_table
[parmIndex
].flags
& flags
[flagIndex
]) {
2003 flag_names
[flagIndex
]);
2008 /* output synonyms */
2010 for (parmIndex2
=0; parm_table
[parmIndex2
].label
; parmIndex2
++) {
2011 if (is_synonym_of(parmIndex
, parmIndex2
, &inverse
)) {
2012 printf(" (%ssynonym of %s)", inverse
? "inverse " : "",
2013 parm_table
[parmIndex2
].label
);
2014 } else if (is_synonym_of(parmIndex2
, parmIndex
, &inverse
)) {
2016 printf(" (synonyms: ");
2021 printf("%s%s", parm_table
[parmIndex2
].label
,
2022 inverse
? "[i]" : "");
2032 /***************************************************************************
2033 Show all parameter's name, type, [values,] and flags.
2034 ***************************************************************************/
2036 void show_parameter_list(void)
2038 int classIndex
, parmIndex
;
2039 const char *section_names
[] = { "local", "global", NULL
};
2041 for (classIndex
=0; section_names
[classIndex
]; classIndex
++) {
2042 printf("[%s]\n", section_names
[classIndex
]);
2043 for (parmIndex
= 0; parm_table
[parmIndex
].label
; parmIndex
++) {
2044 if (parm_table
[parmIndex
].p_class
== classIndex
) {
2045 show_parameter(parmIndex
);
2051 /***************************************************************************
2052 Check if a given string correctly represents a boolean value.
2053 ***************************************************************************/
2055 bool lp_string_is_valid_boolean(const char *parm_value
)
2057 return set_boolean(parm_value
, NULL
);
2060 /***************************************************************************
2061 Get the standard string representation of a boolean value ("yes" or "no")
2062 ***************************************************************************/
2064 static const char *get_boolean(bool bool_value
)
2066 static const char *yes_str
= "yes";
2067 static const char *no_str
= "no";
2069 return (bool_value
? yes_str
: no_str
);
2072 /***************************************************************************
2073 Provide the string of the negated boolean value associated to the boolean
2074 given as a string. Returns false if the passed string does not correctly
2075 represent a boolean.
2076 ***************************************************************************/
2078 bool lp_invert_boolean(const char *str
, const char **inverse_str
)
2082 if (!set_boolean(str
, &val
)) {
2086 *inverse_str
= get_boolean(!val
);
2090 /***************************************************************************
2091 Provide the canonical string representation of a boolean value given
2092 as a string. Return true on success, false if the string given does
2093 not correctly represent a boolean.
2094 ***************************************************************************/
2096 bool lp_canonicalize_boolean(const char *str
, const char**canon_str
)
2100 if (!set_boolean(str
, &val
)) {
2104 *canon_str
= get_boolean(val
);
2108 /***************************************************************************
2109 Find a service by name. Otherwise works like get_service.
2110 ***************************************************************************/
2112 static int getservicebyname(const char *pszServiceName
, struct loadparm_service
*pserviceDest
)
2119 if (ServiceHash
== NULL
) {
2123 canon_name
= canonicalize_servicename(talloc_tos(), pszServiceName
);
2125 status
= dbwrap_fetch_bystring(ServiceHash
, canon_name
, canon_name
,
2128 if (NT_STATUS_IS_OK(status
) &&
2129 (data
.dptr
!= NULL
) &&
2130 (data
.dsize
== sizeof(iService
)))
2132 iService
= *(int *)data
.dptr
;
2135 TALLOC_FREE(canon_name
);
2137 if ((iService
!= -1) && (LP_SNUM_OK(iService
))
2138 && (pserviceDest
!= NULL
)) {
2139 copy_service(pserviceDest
, ServicePtrs
[iService
], NULL
);
2145 /* Return a pointer to a service by name. Unlike getservicebyname, it does not copy the service */
2146 struct loadparm_service
*lp_service(const char *pszServiceName
)
2148 int iService
= getservicebyname(pszServiceName
, NULL
);
2149 if (iService
== -1 || !LP_SNUM_OK(iService
)) {
2152 return ServicePtrs
[iService
];
2155 struct loadparm_service
*lp_servicebynum(int snum
)
2157 if ((snum
== -1) || !LP_SNUM_OK(snum
)) {
2160 return ServicePtrs
[snum
];
2163 struct loadparm_service
*lp_default_loadparm_service()
2169 /***************************************************************************
2170 Copy a service structure to another.
2171 If pcopymapDest is NULL then copy all fields
2172 ***************************************************************************/
2175 * Add a parametric option to a parmlist_entry,
2176 * replacing old value, if already present.
2178 static void set_param_opt(struct parmlist_entry
**opt_list
,
2179 const char *opt_name
,
2180 const char *opt_value
,
2183 struct parmlist_entry
*new_opt
, *opt
;
2189 /* Traverse destination */
2191 /* If we already have same option, override it */
2192 if (strwicmp(opt
->key
, opt_name
) == 0) {
2193 if ((opt
->priority
& FLAG_CMDLINE
) &&
2194 !(priority
& FLAG_CMDLINE
)) {
2195 /* it's been marked as not to be
2199 string_free(&opt
->value
);
2200 TALLOC_FREE(opt
->list
);
2202 opt
->value
= talloc_strdup(NULL
, opt_value
);
2203 if (opt
->value
== NULL
) {
2204 smb_panic("talloc_strdup failed");
2207 opt
->priority
= priority
;
2214 new_opt
= talloc(NULL
, struct parmlist_entry
);
2215 if (new_opt
== NULL
) {
2219 new_opt
->key
= talloc_strdup(NULL
, opt_name
);
2220 if (new_opt
->key
== NULL
) {
2221 smb_panic("talloc_strdup failed");
2224 new_opt
->value
= talloc_strdup(NULL
, opt_value
);
2225 if (new_opt
->value
== NULL
) {
2226 smb_panic("talloc_strdup failed");
2229 new_opt
->list
= NULL
;
2230 new_opt
->priority
= priority
;
2231 DLIST_ADD(*opt_list
, new_opt
);
2235 static void copy_service(struct loadparm_service
*pserviceDest
, struct loadparm_service
*pserviceSource
,
2236 struct bitmap
*pcopymapDest
)
2239 bool bcopyall
= (pcopymapDest
== NULL
);
2240 struct parmlist_entry
*data
;
2242 for (i
= 0; parm_table
[i
].label
; i
++)
2243 if (parm_table
[i
].p_class
== P_LOCAL
&&
2244 (bcopyall
|| bitmap_query(pcopymapDest
,i
))) {
2245 void *src_ptr
= lp_parm_ptr(pserviceSource
, &parm_table
[i
]);
2246 void *dest_ptr
= lp_parm_ptr(pserviceDest
, &parm_table
[i
]);
2248 switch (parm_table
[i
].type
) {
2251 *(bool *)dest_ptr
= *(bool *)src_ptr
;
2258 *(int *)dest_ptr
= *(int *)src_ptr
;
2262 *(char *)dest_ptr
= *(char *)src_ptr
;
2266 string_set(pserviceDest
, (char **)dest_ptr
,
2272 char *upper_string
= strupper_talloc(talloc_tos(),
2274 string_set(pserviceDest
, (char **)dest_ptr
,
2276 TALLOC_FREE(upper_string
);
2280 TALLOC_FREE(*((char ***)dest_ptr
));
2281 *((char ***)dest_ptr
) = str_list_copy(NULL
,
2282 *(const char ***)src_ptr
);
2290 init_copymap(pserviceDest
);
2291 if (pserviceSource
->copymap
)
2292 bitmap_copy(pserviceDest
->copymap
,
2293 pserviceSource
->copymap
);
2296 data
= pserviceSource
->param_opt
;
2298 set_param_opt(&pserviceDest
->param_opt
, data
->key
, data
->value
, data
->priority
);
2303 /***************************************************************************
2304 Check a service for consistency. Return false if the service is in any way
2305 incomplete or faulty, else true.
2306 ***************************************************************************/
2308 bool service_ok(int iService
)
2313 if (ServicePtrs
[iService
]->szService
[0] == '\0') {
2314 DEBUG(0, ("The following message indicates an internal error:\n"));
2315 DEBUG(0, ("No service name in service entry.\n"));
2319 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2320 /* I can't see why you'd want a non-printable printer service... */
2321 if (strwicmp(ServicePtrs
[iService
]->szService
, PRINTERS_NAME
) == 0) {
2322 if (!ServicePtrs
[iService
]->printable
) {
2323 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2324 ServicePtrs
[iService
]->szService
));
2325 ServicePtrs
[iService
]->printable
= true;
2327 /* [printers] service must also be non-browsable. */
2328 if (ServicePtrs
[iService
]->browseable
)
2329 ServicePtrs
[iService
]->browseable
= false;
2332 if (ServicePtrs
[iService
]->path
[0] == '\0' &&
2333 strwicmp(ServicePtrs
[iService
]->szService
, HOMES_NAME
) != 0 &&
2334 ServicePtrs
[iService
]->msdfs_proxy
[0] == '\0'
2336 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
2337 ServicePtrs
[iService
]->szService
));
2338 ServicePtrs
[iService
]->bAvailable
= false;
2341 /* If a service is flagged unavailable, log the fact at level 1. */
2342 if (!ServicePtrs
[iService
]->bAvailable
)
2343 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2344 ServicePtrs
[iService
]->szService
));
2349 static struct smbconf_ctx
*lp_smbconf_ctx(void)
2352 static struct smbconf_ctx
*conf_ctx
= NULL
;
2354 if (conf_ctx
== NULL
) {
2355 err
= smbconf_init(NULL
, &conf_ctx
, "registry:");
2356 if (!SBC_ERROR_IS_OK(err
)) {
2357 DEBUG(1, ("error initializing registry configuration: "
2358 "%s\n", sbcErrorString(err
)));
2366 static bool process_smbconf_service(struct smbconf_service
*service
)
2371 if (service
== NULL
) {
2375 ret
= do_section(service
->name
, NULL
);
2379 for (count
= 0; count
< service
->num_params
; count
++) {
2380 ret
= do_parameter(service
->param_names
[count
],
2381 service
->param_values
[count
],
2387 if (iServiceIndex
>= 0) {
2388 return service_ok(iServiceIndex
);
2394 * load a service from registry and activate it
2396 bool process_registry_service(const char *service_name
)
2399 struct smbconf_service
*service
= NULL
;
2400 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
2401 struct smbconf_ctx
*conf_ctx
= lp_smbconf_ctx();
2404 if (conf_ctx
== NULL
) {
2408 DEBUG(5, ("process_registry_service: service name %s\n", service_name
));
2410 if (!smbconf_share_exists(conf_ctx
, service_name
)) {
2412 * Registry does not contain data for this service (yet),
2413 * but make sure lp_load doesn't return false.
2419 err
= smbconf_get_share(conf_ctx
, mem_ctx
, service_name
, &service
);
2420 if (!SBC_ERROR_IS_OK(err
)) {
2424 ret
= process_smbconf_service(service
);
2430 smbconf_changed(conf_ctx
, &conf_last_csn
, NULL
, NULL
);
2433 TALLOC_FREE(mem_ctx
);
2438 * process_registry_globals
2440 static bool process_registry_globals(void)
2444 add_to_file_list(INCLUDE_REGISTRY_NAME
, INCLUDE_REGISTRY_NAME
);
2446 ret
= do_parameter("registry shares", "yes", NULL
);
2451 return process_registry_service(GLOBAL_NAME
);
2454 bool process_registry_shares(void)
2458 struct smbconf_service
**service
= NULL
;
2459 uint32_t num_shares
= 0;
2460 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
2461 struct smbconf_ctx
*conf_ctx
= lp_smbconf_ctx();
2464 if (conf_ctx
== NULL
) {
2468 err
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &service
);
2469 if (!SBC_ERROR_IS_OK(err
)) {
2475 for (count
= 0; count
< num_shares
; count
++) {
2476 if (strequal(service
[count
]->name
, GLOBAL_NAME
)) {
2479 ret
= process_smbconf_service(service
[count
]);
2486 smbconf_changed(conf_ctx
, &conf_last_csn
, NULL
, NULL
);
2489 TALLOC_FREE(mem_ctx
);
2494 * reload those shares from registry that are already
2495 * activated in the services array.
2497 static bool reload_registry_shares(void)
2502 for (i
= 0; i
< iNumServices
; i
++) {
2507 if (ServicePtrs
[i
]->usershare
== USERSHARE_VALID
) {
2511 ret
= process_registry_service(ServicePtrs
[i
]->szService
);
2522 #define MAX_INCLUDE_DEPTH 100
2524 static uint8_t include_depth
;
2526 static struct file_lists
{
2527 struct file_lists
*next
;
2531 } *file_lists
= NULL
;
2533 /*******************************************************************
2534 Keep a linked list of all config files so we know when one has changed
2535 it's date and needs to be reloaded.
2536 ********************************************************************/
2538 static void add_to_file_list(const char *fname
, const char *subfname
)
2540 struct file_lists
*f
= file_lists
;
2543 if (f
->name
&& !strcmp(f
->name
, fname
))
2549 f
= talloc(NULL
, struct file_lists
);
2553 f
->next
= file_lists
;
2554 f
->name
= talloc_strdup(f
, fname
);
2559 f
->subfname
= talloc_strdup(f
, subfname
);
2565 f
->modtime
= file_modtime(subfname
);
2567 time_t t
= file_modtime(subfname
);
2574 DEBUG(0, ("Unable to add file to file list: %s\n", fname
));
2579 * Free the file lists
2581 static void free_file_list(void)
2583 struct file_lists
*f
;
2584 struct file_lists
*next
;
2597 * Utility function for outsiders to check if we're running on registry.
2599 bool lp_config_backend_is_registry(void)
2601 return (lp_config_backend() == CONFIG_BACKEND_REGISTRY
);
2605 * Utility function to check if the config backend is FILE.
2607 bool lp_config_backend_is_file(void)
2609 return (lp_config_backend() == CONFIG_BACKEND_FILE
);
2612 /*******************************************************************
2613 Check if a config file has changed date.
2614 ********************************************************************/
2616 bool lp_file_list_changed(void)
2618 struct file_lists
*f
= file_lists
;
2620 DEBUG(6, ("lp_file_list_changed()\n"));
2625 if (strequal(f
->name
, INCLUDE_REGISTRY_NAME
)) {
2626 struct smbconf_ctx
*conf_ctx
= lp_smbconf_ctx();
2628 if (conf_ctx
== NULL
) {
2631 if (smbconf_changed(conf_ctx
, &conf_last_csn
, NULL
,
2634 DEBUGADD(6, ("registry config changed\n"));
2639 n2
= talloc_sub_basic(talloc_tos(),
2640 get_current_username(),
2641 current_user_info
.domain
,
2646 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2647 f
->name
, n2
, ctime(&f
->modtime
)));
2649 mod_time
= file_modtime(n2
);
2652 ((f
->modtime
!= mod_time
) ||
2653 (f
->subfname
== NULL
) ||
2654 (strcmp(n2
, f
->subfname
) != 0)))
2657 ("file %s modified: %s\n", n2
,
2659 f
->modtime
= mod_time
;
2660 TALLOC_FREE(f
->subfname
);
2661 f
->subfname
= talloc_strdup(f
, n2
);
2662 if (f
->subfname
== NULL
) {
2663 smb_panic("talloc_strdup failed");
2677 * Initialize iconv conversion descriptors.
2679 * This is called the first time it is needed, and also called again
2680 * every time the configuration is reloaded, because the charset or
2681 * codepage might have changed.
2683 static void init_iconv(void)
2685 global_iconv_handle
= smb_iconv_handle_reinit(NULL
, lp_dos_charset(),
2687 true, global_iconv_handle
);
2690 static bool handle_charset(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2692 if (strcmp(*ptr
, pszParmValue
) != 0) {
2693 string_set(Globals
.ctx
, ptr
, pszParmValue
);
2699 static bool handle_dos_charset(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2701 bool is_utf8
= false;
2702 size_t len
= strlen(pszParmValue
);
2704 if (len
== 4 || len
== 5) {
2705 /* Don't use StrCaseCmp here as we don't want to
2706 initialize iconv. */
2707 if ((toupper_m(pszParmValue
[0]) == 'U') &&
2708 (toupper_m(pszParmValue
[1]) == 'T') &&
2709 (toupper_m(pszParmValue
[2]) == 'F')) {
2711 if (pszParmValue
[3] == '8') {
2715 if (pszParmValue
[3] == '-' &&
2716 pszParmValue
[4] == '8') {
2723 if (strcmp(*ptr
, pszParmValue
) != 0) {
2725 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
2726 "be UTF8, using (default value) %s instead.\n",
2727 DEFAULT_DOS_CHARSET
));
2728 pszParmValue
= DEFAULT_DOS_CHARSET
;
2730 string_set(Globals
.ctx
, ptr
, pszParmValue
);
2736 static bool handle_realm(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2739 TALLOC_CTX
*frame
= talloc_stackframe();
2740 char *realm
= strupper_talloc(frame
, pszParmValue
);
2741 char *dnsdomain
= strlower_talloc(realm
, pszParmValue
);
2743 ret
&= string_set(Globals
.ctx
, &Globals
.realm_original
, pszParmValue
);
2744 ret
&= string_set(Globals
.ctx
, &Globals
.realm
, realm
);
2745 ret
&= string_set(Globals
.ctx
, &Globals
.dnsdomain
, dnsdomain
);
2751 static bool handle_netbios_aliases(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2753 TALLOC_FREE(Globals
.netbios_aliases
);
2754 Globals
.netbios_aliases
= (const char **)str_list_make_v3(NULL
, pszParmValue
, NULL
);
2755 return set_netbios_aliases(Globals
.netbios_aliases
);
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
)
2767 if (include_depth
>= MAX_INCLUDE_DEPTH
) {
2768 DEBUG(0, ("Error: Maximum include depth (%u) exceeded!\n",
2773 if (strequal(pszParmValue
, INCLUDE_REGISTRY_NAME
)) {
2774 if (!bAllowIncludeRegistry
) {
2777 if (bInGlobalSection
) {
2780 ret
= process_registry_globals();
2784 DEBUG(1, ("\"include = registry\" only effective "
2785 "in %s section\n", GLOBAL_NAME
));
2790 fname
= talloc_sub_basic(talloc_tos(), get_current_username(),
2791 current_user_info
.domain
,
2794 add_to_file_list(pszParmValue
, fname
);
2797 string_set(Globals
.ctx
, ptr
, fname
);
2799 string_set(ServicePtrs
[snum
], ptr
, fname
);
2802 if (file_exist(fname
)) {
2805 ret
= pm_process(fname
, do_section
, do_parameter
, NULL
);
2811 DEBUG(2, ("Can't find include file %s\n", fname
));
2816 /***************************************************************************
2817 Handle the interpretation of the copy parameter.
2818 ***************************************************************************/
2820 static bool handle_copy(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2827 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2829 if ((iTemp
= getservicebyname(pszParmValue
, NULL
)) >= 0) {
2830 if (iTemp
== iServiceIndex
) {
2831 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2833 copy_service(ServicePtrs
[iServiceIndex
],
2835 ServicePtrs
[iServiceIndex
]->copymap
);
2836 string_set(ServicePtrs
[iServiceIndex
], ptr
, pszParmValue
);
2840 DEBUG(0, ("Unable to copy service - source not found: %s\n", pszParmValue
));
2847 static bool handle_ldap_debug_level(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2849 Globals
.ldap_debug_level
= lp_int(pszParmValue
);
2850 init_ldap_debugging();
2855 * idmap related parameters
2858 static bool handle_idmap_backend(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2860 lp_do_parameter(snum
, "idmap config * : backend", pszParmValue
);
2865 static bool handle_idmap_uid(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2867 lp_do_parameter(snum
, "idmap config * : range", pszParmValue
);
2872 static bool handle_idmap_gid(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
2874 lp_do_parameter(snum
, "idmap config * : range", pszParmValue
);
2879 bool lp_idmap_range(const char *domain_name
, uint32_t *low
, uint32_t *high
)
2881 char *config_option
= NULL
;
2882 const char *range
= NULL
;
2885 SMB_ASSERT(low
!= NULL
);
2886 SMB_ASSERT(high
!= NULL
);
2888 if ((domain_name
== NULL
) || (domain_name
[0] == '\0')) {
2892 config_option
= talloc_asprintf(talloc_tos(), "idmap config %s",
2894 if (config_option
== NULL
) {
2895 DEBUG(0, ("out of memory\n"));
2899 range
= lp_parm_const_string(-1, config_option
, "range", NULL
);
2900 if (range
== NULL
) {
2901 DEBUG(1, ("idmap range not specified for domain '%s'\n", domain_name
));
2905 if (sscanf(range
, "%u - %u", low
, high
) != 2) {
2906 DEBUG(1, ("error parsing idmap range '%s' for domain '%s'\n",
2907 range
, domain_name
));
2914 talloc_free(config_option
);
2919 bool lp_idmap_default_range(uint32_t *low
, uint32_t *high
)
2921 return lp_idmap_range("*", low
, high
);
2924 const char *lp_idmap_backend(const char *domain_name
)
2926 char *config_option
= NULL
;
2927 const char *backend
= NULL
;
2929 if ((domain_name
== NULL
) || (domain_name
[0] == '\0')) {
2933 config_option
= talloc_asprintf(talloc_tos(), "idmap config %s",
2935 if (config_option
== NULL
) {
2936 DEBUG(0, ("out of memory\n"));
2940 backend
= lp_parm_const_string(-1, config_option
, "backend", NULL
);
2941 if (backend
== NULL
) {
2942 DEBUG(1, ("idmap backend not specified for domain '%s'\n", domain_name
));
2947 talloc_free(config_option
);
2951 const char *lp_idmap_default_backend(void)
2953 return lp_idmap_backend("*");
2956 /***************************************************************************
2957 Handle the DEBUG level list.
2958 ***************************************************************************/
2960 static bool handle_debug_list(struct loadparm_context
*unused
, int snum
, const char *pszParmValueIn
, char **ptr
)
2962 string_set(Globals
.ctx
, ptr
, pszParmValueIn
);
2963 return debug_parse_levels(pszParmValueIn
);
2966 /***************************************************************************
2967 Handle ldap suffixes - default to ldapsuffix if sub-suffixes are not defined.
2968 ***************************************************************************/
2970 static const char *append_ldap_suffix(TALLOC_CTX
*ctx
, const char *str
)
2972 const char *suffix_string
;
2974 suffix_string
= talloc_asprintf(ctx
, "%s,%s", str
,
2975 Globals
.ldap_suffix
);
2976 if ( !suffix_string
) {
2977 DEBUG(0,("append_ldap_suffix: talloc_asprintf() failed!\n"));
2981 return suffix_string
;
2984 const char *lp_ldap_machine_suffix(TALLOC_CTX
*ctx
)
2986 if (Globals
.szLdapMachineSuffix
[0])
2987 return append_ldap_suffix(ctx
, Globals
.szLdapMachineSuffix
);
2989 return lp_string(ctx
, Globals
.ldap_suffix
);
2992 const char *lp_ldap_user_suffix(TALLOC_CTX
*ctx
)
2994 if (Globals
.szLdapUserSuffix
[0])
2995 return append_ldap_suffix(ctx
, Globals
.szLdapUserSuffix
);
2997 return lp_string(ctx
, Globals
.ldap_suffix
);
3000 const char *lp_ldap_group_suffix(TALLOC_CTX
*ctx
)
3002 if (Globals
.szLdapGroupSuffix
[0])
3003 return append_ldap_suffix(ctx
, Globals
.szLdapGroupSuffix
);
3005 return lp_string(ctx
, Globals
.ldap_suffix
);
3008 const char *lp_ldap_idmap_suffix(TALLOC_CTX
*ctx
)
3010 if (Globals
.szLdapIdmapSuffix
[0])
3011 return append_ldap_suffix(ctx
, Globals
.szLdapIdmapSuffix
);
3013 return lp_string(ctx
, Globals
.ldap_suffix
);
3016 /****************************************************************************
3017 set the value for a P_ENUM
3018 ***************************************************************************/
3020 static void lp_set_enum_parm( struct parm_struct
*parm
, const char *pszParmValue
,
3025 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
3026 if ( strequal(pszParmValue
, parm
->enum_list
[i
].name
)) {
3027 *ptr
= parm
->enum_list
[i
].value
;
3031 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
3032 pszParmValue
, parm
->label
));
3035 /***************************************************************************
3036 ***************************************************************************/
3038 static bool handle_printing(struct loadparm_context
*unused
, int snum
, const char *pszParmValue
, char **ptr
)
3040 static int parm_num
= -1;
3041 struct loadparm_service
*s
;
3043 if ( parm_num
== -1 )
3044 parm_num
= lpcfg_map_parameter( "printing" );
3046 lp_set_enum_parm( &parm_table
[parm_num
], pszParmValue
, (int*)ptr
);
3050 init_printer_values(Globals
.ctx
, s
);
3052 s
= ServicePtrs
[snum
];
3053 init_printer_values(s
, s
);
3060 /***************************************************************************
3061 Initialise a copymap.
3062 ***************************************************************************/
3064 static void init_copymap(struct loadparm_service
*pservice
)
3068 TALLOC_FREE(pservice
->copymap
);
3070 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
3071 if (!pservice
->copymap
)
3073 ("Couldn't allocate copymap!! (size %d)\n",
3074 (int)NUMPARAMETERS
));
3076 for (i
= 0; i
< NUMPARAMETERS
; i
++)
3077 bitmap_set(pservice
->copymap
, i
);
3081 return the parameter pointer for a parameter
3083 void *lp_parm_ptr(struct loadparm_service
*service
, struct parm_struct
*parm
)
3085 if (service
== NULL
) {
3086 if (parm
->p_class
== P_LOCAL
)
3087 return (void *)(((char *)&sDefault
)+parm
->offset
);
3088 else if (parm
->p_class
== P_GLOBAL
)
3089 return (void *)(((char *)&Globals
)+parm
->offset
);
3092 return (void *)(((char *)service
) + parm
->offset
);
3096 /***************************************************************************
3097 Return the local pointer to a parameter given the service number and parameter
3098 ***************************************************************************/
3100 void *lp_local_ptr_by_snum(int snum
, struct parm_struct
*parm
)
3102 return lp_parm_ptr(ServicePtrs
[snum
], parm
);
3105 /***************************************************************************
3106 Process a parameter for a particular service number. If snum < 0
3107 then assume we are in the globals.
3108 ***************************************************************************/
3110 bool lp_do_parameter(int snum
, const char *pszParmName
, const char *pszParmValue
)
3113 void *parm_ptr
= NULL
; /* where we are going to store the result */
3114 struct parmlist_entry
**opt_list
;
3115 TALLOC_CTX
*mem_ctx
;
3117 parmnum
= lpcfg_map_parameter(pszParmName
);
3120 if (strchr(pszParmName
, ':') == NULL
) {
3121 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n",
3127 * We've got a parametric option
3130 opt_list
= (snum
< 0)
3131 ? &Globals
.param_opt
: &ServicePtrs
[snum
]->param_opt
;
3132 set_param_opt(opt_list
, pszParmName
, pszParmValue
, 0);
3137 /* if it's already been set by the command line, then we don't
3139 if (parm_table
[parmnum
].flags
& FLAG_CMDLINE
) {
3143 if (parm_table
[parmnum
].flags
& FLAG_DEPRECATED
) {
3144 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
3148 /* we might point at a service, the default service or a global */
3150 parm_ptr
= lp_parm_ptr(NULL
, &parm_table
[parmnum
]);
3152 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
3154 ("Global parameter %s found in service section!\n",
3158 parm_ptr
= lp_local_ptr_by_snum(snum
, &parm_table
[parmnum
]);
3162 if (!ServicePtrs
[snum
]->copymap
)
3163 init_copymap(ServicePtrs
[snum
]);
3165 /* this handles the aliases - set the copymap for other entries with
3166 the same data pointer */
3167 for (i
= 0; parm_table
[i
].label
; i
++) {
3168 if ((parm_table
[i
].offset
== parm_table
[parmnum
].offset
)
3169 && (parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)) {
3170 bitmap_clear(ServicePtrs
[snum
]->copymap
, i
);
3173 mem_ctx
= ServicePtrs
[snum
];
3175 mem_ctx
= Globals
.ctx
;
3178 /* if it is a special case then go ahead */
3179 if (parm_table
[parmnum
].special
) {
3181 struct loadparm_context
*lp_ctx
= loadparm_init_s3(talloc_tos(),
3182 loadparm_s3_helpers());
3183 ok
= parm_table
[parmnum
].special(lp_ctx
, snum
, pszParmValue
,
3185 TALLOC_FREE(lp_ctx
);
3190 /* now switch on the type of variable it is */
3191 switch (parm_table
[parmnum
].type
)
3194 *(bool *)parm_ptr
= lp_bool(pszParmValue
);
3198 *(bool *)parm_ptr
= !lp_bool(pszParmValue
);
3202 *(int *)parm_ptr
= lp_int(pszParmValue
);
3206 *(char *)parm_ptr
= *pszParmValue
;
3210 i
= sscanf(pszParmValue
, "%o", (int *)parm_ptr
);
3212 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName
));
3219 if (conv_str_size_error(pszParmValue
, &val
)) {
3220 if (val
<= INT_MAX
) {
3221 *(int *)parm_ptr
= (int)val
;
3226 DEBUG(0,("lp_do_parameter(%s): value is not "
3227 "a valid size specifier!\n", pszParmValue
));
3233 TALLOC_FREE(*((char ***)parm_ptr
));
3234 *(char ***)parm_ptr
= str_list_make_v3(
3235 NULL
, pszParmValue
, NULL
);
3239 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
3244 char *upper_string
= strupper_talloc(talloc_tos(),
3246 string_set(mem_ctx
, (char **)parm_ptr
, upper_string
);
3247 TALLOC_FREE(upper_string
);
3251 lp_set_enum_parm( &parm_table
[parmnum
], pszParmValue
, (int*)parm_ptr
);
3260 /***************************************************************************
3261 set a parameter, marking it with FLAG_CMDLINE. Parameters marked as
3262 FLAG_CMDLINE won't be overridden by loads from smb.conf.
3263 ***************************************************************************/
3265 static bool lp_set_cmdline_helper(const char *pszParmName
, const char *pszParmValue
, bool store_values
)
3268 parmnum
= lpcfg_map_parameter(pszParmName
);
3270 parm_table
[parmnum
].flags
&= ~FLAG_CMDLINE
;
3271 if (!lp_do_parameter(-1, pszParmName
, pszParmValue
)) {
3274 parm_table
[parmnum
].flags
|= FLAG_CMDLINE
;
3276 /* we have to also set FLAG_CMDLINE on aliases. Aliases must
3277 * be grouped in the table, so we don't have to search the
3280 i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
3281 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
;
3283 parm_table
[i
].flags
|= FLAG_CMDLINE
;
3285 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
3286 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
;i
++) {
3287 parm_table
[i
].flags
|= FLAG_CMDLINE
;
3291 store_lp_set_cmdline(pszParmName
, pszParmValue
);
3296 /* it might be parametric */
3297 if (strchr(pszParmName
, ':') != NULL
) {
3298 set_param_opt(&Globals
.param_opt
, pszParmName
, pszParmValue
, FLAG_CMDLINE
);
3300 store_lp_set_cmdline(pszParmName
, pszParmValue
);
3305 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
3309 bool lp_set_cmdline(const char *pszParmName
, const char *pszParmValue
)
3311 return lp_set_cmdline_helper(pszParmName
, pszParmValue
, true);
3314 /***************************************************************************
3315 Process a parameter.
3316 ***************************************************************************/
3318 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
3321 if (!bInGlobalSection
&& bGlobalOnly
)
3324 DEBUGADD(4, ("doing parameter %s = %s\n", pszParmName
, pszParmValue
));
3326 return (lp_do_parameter(bInGlobalSection
? -2 : iServiceIndex
,
3327 pszParmName
, pszParmValue
));
3331 set a option from the commandline in 'a=b' format. Use to support --option
3333 bool lp_set_option(const char *option
)
3338 s
= talloc_strdup(NULL
, option
);
3351 /* skip white spaces after the = sign */
3354 } while (*p
== ' ');
3356 ret
= lp_set_cmdline(s
, p
);
3361 /***************************************************************************
3362 Initialize any local variables in the sDefault table, after parsing a
3364 ***************************************************************************/
3366 static void init_locals(void)
3369 * We run this check once the [globals] is parsed, to force
3370 * the VFS objects and other per-share settings we need for
3371 * the standard way a AD DC is operated. We may change these
3372 * as our code evolves, which is why we force these settings.
3374 * We can't do this at the end of lp_load_ex(), as by that
3375 * point the services have been loaded and they will already
3376 * have "" as their vfs objects.
3378 if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC
) {
3379 const char **vfs_objects
= lp_vfs_objects(-1);
3380 if (!vfs_objects
|| !vfs_objects
[0]) {
3381 if (lp_parm_const_string(-1, "xattr_tdb", "file", NULL
)) {
3382 lp_do_parameter(-1, "vfs objects", "dfs_samba4 acl_xattr xattr_tdb");
3383 } else if (lp_parm_const_string(-1, "posix", "eadb", NULL
)) {
3384 lp_do_parameter(-1, "vfs objects", "dfs_samba4 acl_xattr posix_eadb");
3386 lp_do_parameter(-1, "vfs objects", "dfs_samba4 acl_xattr");
3390 lp_do_parameter(-1, "map hidden", "no");
3391 lp_do_parameter(-1, "map system", "no");
3392 lp_do_parameter(-1, "map readonly", "no");
3393 lp_do_parameter(-1, "map archive", "no");
3394 lp_do_parameter(-1, "store dos attributes", "yes");
3398 /***************************************************************************
3399 Process a new section (service). At this stage all sections are services.
3400 Later we'll have special sections that permit server parameters to be set.
3401 Returns true on success, false on failure.
3402 ***************************************************************************/
3404 static bool do_section(const char *pszSectionName
, void *userdata
)
3407 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
3408 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
3411 /* if we were in a global section then do the local inits */
3412 if (bInGlobalSection
&& !isglobal
)
3415 /* if we've just struck a global section, note the fact. */
3416 bInGlobalSection
= isglobal
;
3418 /* check for multiple global sections */
3419 if (bInGlobalSection
) {
3420 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName
));
3424 if (!bInGlobalSection
&& bGlobalOnly
)
3427 /* if we have a current service, tidy it up before moving on */
3430 if (iServiceIndex
>= 0)
3431 bRetval
= service_ok(iServiceIndex
);
3433 /* if all is still well, move to the next record in the services array */
3435 /* We put this here to avoid an odd message order if messages are */
3436 /* issued by the post-processing of a previous section. */
3437 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName
));
3439 iServiceIndex
= add_a_service(&sDefault
, pszSectionName
);
3440 if (iServiceIndex
< 0) {
3441 DEBUG(0, ("Failed to add a new service\n"));
3444 /* Clean all parametric options for service */
3445 /* They will be added during parsing again */
3446 free_param_opts(&ServicePtrs
[iServiceIndex
]->param_opt
);
3453 /***************************************************************************
3454 Determine if a partcular base parameter is currentl set to the default value.
3455 ***************************************************************************/
3457 static bool is_default(int i
)
3459 switch (parm_table
[i
].type
) {
3462 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
3463 *(const char ***)lp_parm_ptr(NULL
,
3467 return strequal(parm_table
[i
].def
.svalue
,
3468 *(char **)lp_parm_ptr(NULL
,
3472 return parm_table
[i
].def
.bvalue
==
3473 *(bool *)lp_parm_ptr(NULL
,
3476 return parm_table
[i
].def
.cvalue
==
3477 *(char *)lp_parm_ptr(NULL
,
3483 return parm_table
[i
].def
.ivalue
==
3484 *(int *)lp_parm_ptr(NULL
,
3492 /***************************************************************************
3493 Display the contents of the global structure.
3494 ***************************************************************************/
3496 static void dump_globals(FILE *f
)
3499 struct parmlist_entry
*data
;
3501 fprintf(f
, "[global]\n");
3503 for (i
= 0; parm_table
[i
].label
; i
++)
3504 if (parm_table
[i
].p_class
== P_GLOBAL
&&
3505 !(parm_table
[i
].flags
& FLAG_META
) &&
3506 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
3507 if (defaults_saved
&& is_default(i
))
3509 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3510 lpcfg_print_parameter(&parm_table
[i
], lp_parm_ptr(NULL
,
3515 if (Globals
.param_opt
!= NULL
) {
3516 data
= Globals
.param_opt
;
3518 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3525 /***************************************************************************
3526 Display the contents of a single services record.
3527 ***************************************************************************/
3529 static void dump_a_service(struct loadparm_service
*pService
, FILE * f
)
3532 struct parmlist_entry
*data
;
3534 if (pService
!= &sDefault
)
3535 fprintf(f
, "[%s]\n", pService
->szService
);
3537 for (i
= 0; parm_table
[i
].label
; i
++) {
3539 if (parm_table
[i
].p_class
== P_LOCAL
&&
3540 !(parm_table
[i
].flags
& FLAG_META
) &&
3541 (*parm_table
[i
].label
!= '-') &&
3542 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3544 if (pService
== &sDefault
) {
3545 if (defaults_saved
&& is_default(i
))
3548 if (lpcfg_equal_parameter(parm_table
[i
].type
,
3549 lp_parm_ptr(pService
, &parm_table
[i
]),
3550 lp_parm_ptr(NULL
, &parm_table
[i
])))
3554 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3555 lpcfg_print_parameter(&parm_table
[i
],
3556 lp_parm_ptr(pService
, &parm_table
[i
]),
3562 if (pService
->param_opt
!= NULL
) {
3563 data
= pService
->param_opt
;
3565 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3571 /***************************************************************************
3572 Display the contents of a parameter of a single services record.
3573 ***************************************************************************/
3575 bool dump_a_parameter(int snum
, char *parm_name
, FILE * f
, bool isGlobal
)
3577 bool result
= false;
3578 fstring local_parm_name
;
3580 const char *parm_opt_value
;
3582 struct loadparm_context
*lp_ctx
;
3584 /* check for parametrical option */
3585 fstrcpy( local_parm_name
, parm_name
);
3586 parm_opt
= strchr( local_parm_name
, ':');
3591 if (strlen(parm_opt
)) {
3592 parm_opt_value
= lp_parm_const_string( snum
,
3593 local_parm_name
, parm_opt
, NULL
);
3594 if (parm_opt_value
) {
3595 printf( "%s\n", parm_opt_value
);
3602 lp_ctx
= loadparm_init_s3(talloc_tos(), loadparm_s3_helpers());
3603 if (lp_ctx
== NULL
) {
3608 result
= lpcfg_dump_a_parameter(lp_ctx
, NULL
, parm_name
, f
);
3610 result
= lpcfg_dump_a_parameter(lp_ctx
, ServicePtrs
[snum
], parm_name
, f
);
3612 TALLOC_FREE(lp_ctx
);
3616 /***************************************************************************
3617 Return info about the requested parameter (given as a string).
3618 Return NULL when the string is not a valid parameter name.
3619 ***************************************************************************/
3621 struct parm_struct
*lp_get_parameter(const char *param_name
)
3623 int num
= lpcfg_map_parameter(param_name
);
3629 return &parm_table
[num
];
3633 /***************************************************************************
3634 Display the contents of a single copy structure.
3635 ***************************************************************************/
3636 static void dump_copy_map(bool *pcopymap
)
3642 printf("\n\tNon-Copied parameters:\n");
3644 for (i
= 0; parm_table
[i
].label
; i
++)
3645 if (parm_table
[i
].p_class
== P_LOCAL
&&
3646 parm_table
[i
].ptr
&& !pcopymap
[i
] &&
3647 (i
== 0 || (parm_table
[i
].ptr
!= parm_table
[i
- 1].ptr
)))
3649 printf("\t\t%s\n", parm_table
[i
].label
);
3654 /***************************************************************************
3655 Return TRUE if the passed service number is within range.
3656 ***************************************************************************/
3658 bool lp_snum_ok(int iService
)
3660 return (LP_SNUM_OK(iService
) && ServicePtrs
[iService
]->bAvailable
);
3663 /***************************************************************************
3664 Auto-load some home services.
3665 ***************************************************************************/
3667 static void lp_add_auto_services(char *str
)
3677 s
= talloc_strdup(talloc_tos(), str
);
3679 smb_panic("talloc_strdup failed");
3683 homes
= lp_servicenumber(HOMES_NAME
);
3685 for (p
= strtok_r(s
, LIST_SEP
, &saveptr
); p
;
3686 p
= strtok_r(NULL
, LIST_SEP
, &saveptr
)) {
3689 if (lp_servicenumber(p
) >= 0)
3692 home
= get_user_home_dir(talloc_tos(), p
);
3694 if (home
&& home
[0] && homes
>= 0)
3695 lp_add_home(p
, homes
, p
, home
);
3702 /***************************************************************************
3703 Auto-load one printer.
3704 ***************************************************************************/
3706 void lp_add_one_printer(const char *name
, const char *comment
,
3707 const char *location
, void *pdata
)
3709 int printers
= lp_servicenumber(PRINTERS_NAME
);
3712 if (lp_servicenumber(name
) < 0) {
3713 lp_add_printer(name
, printers
);
3714 if ((i
= lp_servicenumber(name
)) >= 0) {
3715 string_set(ServicePtrs
[i
], &ServicePtrs
[i
]->comment
, comment
);
3716 ServicePtrs
[i
]->autoloaded
= true;
3721 /***************************************************************************
3722 Have we loaded a services file yet?
3723 ***************************************************************************/
3725 bool lp_loaded(void)
3730 /***************************************************************************
3731 Unload unused services.
3732 ***************************************************************************/
3734 void lp_killunused(struct smbd_server_connection
*sconn
,
3735 bool (*snumused
) (struct smbd_server_connection
*, int))
3738 for (i
= 0; i
< iNumServices
; i
++) {
3742 /* don't kill autoloaded or usershare services */
3743 if ( ServicePtrs
[i
]->autoloaded
||
3744 ServicePtrs
[i
]->usershare
== USERSHARE_VALID
) {
3748 if (!snumused
|| !snumused(sconn
, i
)) {
3749 free_service_byindex(i
);
3755 * Kill all except autoloaded and usershare services - convenience wrapper
3757 void lp_kill_all_services(void)
3759 lp_killunused(NULL
, NULL
);
3762 /***************************************************************************
3764 ***************************************************************************/
3766 void lp_killservice(int iServiceIn
)
3768 if (VALID(iServiceIn
)) {
3769 free_service_byindex(iServiceIn
);
3773 /***************************************************************************
3774 Save the curent values of all global and sDefault parameters into the
3775 defaults union. This allows testparm to show only the
3776 changed (ie. non-default) parameters.
3777 ***************************************************************************/
3779 static void lp_save_defaults(void)
3782 for (i
= 0; parm_table
[i
].label
; i
++) {
3783 if (i
> 0 && parm_table
[i
].offset
== parm_table
[i
- 1].offset
3784 && parm_table
[i
].p_class
== parm_table
[i
- 1].p_class
)
3786 switch (parm_table
[i
].type
) {
3789 parm_table
[i
].def
.lvalue
= str_list_copy(
3790 NULL
, *(const char ***)lp_parm_ptr(NULL
, &parm_table
[i
]));
3794 parm_table
[i
].def
.svalue
= talloc_strdup(Globals
.ctx
, *(char **)lp_parm_ptr(NULL
, &parm_table
[i
]));
3795 if (parm_table
[i
].def
.svalue
== NULL
) {
3796 smb_panic("talloc_strdup failed");
3801 parm_table
[i
].def
.bvalue
=
3802 *(bool *)lp_parm_ptr(NULL
, &parm_table
[i
]);
3805 parm_table
[i
].def
.cvalue
=
3806 *(char *)lp_parm_ptr(NULL
, &parm_table
[i
]);
3812 parm_table
[i
].def
.ivalue
=
3813 *(int *)lp_parm_ptr(NULL
, &parm_table
[i
]);
3819 defaults_saved
= true;
3822 /***********************************************************
3823 If we should send plaintext/LANMAN passwords in the clinet
3824 ************************************************************/
3826 static void set_allowed_client_auth(void)
3828 if (Globals
.client_ntlmv2_auth
) {
3829 Globals
.client_lanman_auth
= false;
3831 if (!Globals
.client_lanman_auth
) {
3832 Globals
.client_plaintext_auth
= false;
3836 /***************************************************************************
3838 The following code allows smbd to read a user defined share file.
3839 Yes, this is my intent. Yes, I'm comfortable with that...
3841 THE FOLLOWING IS SECURITY CRITICAL CODE.
3843 It washes your clothes, it cleans your house, it guards you while you sleep...
3844 Do not f%^k with it....
3845 ***************************************************************************/
3847 #define MAX_USERSHARE_FILE_SIZE (10*1024)
3849 /***************************************************************************
3850 Check allowed stat state of a usershare file.
3851 Ensure we print out who is dicking with us so the admin can
3852 get their sorry ass fired.
3853 ***************************************************************************/
3855 static bool check_usershare_stat(const char *fname
,
3856 const SMB_STRUCT_STAT
*psbuf
)
3858 if (!S_ISREG(psbuf
->st_ex_mode
)) {
3859 DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
3860 "not a regular file\n",
3861 fname
, (unsigned int)psbuf
->st_ex_uid
));
3865 /* Ensure this doesn't have the other write bit set. */
3866 if (psbuf
->st_ex_mode
& S_IWOTH
) {
3867 DEBUG(0,("check_usershare_stat: file %s owned by uid %u allows "
3868 "public write. Refusing to allow as a usershare file.\n",
3869 fname
, (unsigned int)psbuf
->st_ex_uid
));
3873 /* Should be 10k or less. */
3874 if (psbuf
->st_ex_size
> MAX_USERSHARE_FILE_SIZE
) {
3875 DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
3876 "too large (%u) to be a user share file.\n",
3877 fname
, (unsigned int)psbuf
->st_ex_uid
,
3878 (unsigned int)psbuf
->st_ex_size
));
3885 /***************************************************************************
3886 Parse the contents of a usershare file.
3887 ***************************************************************************/
3889 enum usershare_err
parse_usershare_file(TALLOC_CTX
*ctx
,
3890 SMB_STRUCT_STAT
*psbuf
,
3891 const char *servicename
,
3895 char **pp_sharepath
,
3897 char **pp_cp_servicename
,
3898 struct security_descriptor
**ppsd
,
3901 const char **prefixallowlist
= lp_usershare_prefix_allow_list();
3902 const char **prefixdenylist
= lp_usershare_prefix_deny_list();
3905 SMB_STRUCT_STAT sbuf
;
3906 char *sharepath
= NULL
;
3907 char *comment
= NULL
;
3909 *pp_sharepath
= NULL
;
3912 *pallow_guest
= false;
3915 return USERSHARE_MALFORMED_FILE
;
3918 if (strcmp(lines
[0], "#VERSION 1") == 0) {
3920 } else if (strcmp(lines
[0], "#VERSION 2") == 0) {
3923 return USERSHARE_MALFORMED_FILE
;
3926 return USERSHARE_BAD_VERSION
;
3929 if (strncmp(lines
[1], "path=", 5) != 0) {
3930 return USERSHARE_MALFORMED_PATH
;
3933 sharepath
= talloc_strdup(ctx
, &lines
[1][5]);
3935 return USERSHARE_POSIX_ERR
;
3937 trim_string(sharepath
, " ", " ");
3939 if (strncmp(lines
[2], "comment=", 8) != 0) {
3940 return USERSHARE_MALFORMED_COMMENT_DEF
;
3943 comment
= talloc_strdup(ctx
, &lines
[2][8]);
3945 return USERSHARE_POSIX_ERR
;
3947 trim_string(comment
, " ", " ");
3948 trim_char(comment
, '"', '"');
3950 if (strncmp(lines
[3], "usershare_acl=", 14) != 0) {
3951 return USERSHARE_MALFORMED_ACL_DEF
;
3954 if (!parse_usershare_acl(ctx
, &lines
[3][14], ppsd
)) {
3955 return USERSHARE_ACL_ERR
;
3959 if (strncmp(lines
[4], "guest_ok=", 9) != 0) {
3960 return USERSHARE_MALFORMED_ACL_DEF
;
3962 if (lines
[4][9] == 'y') {
3963 *pallow_guest
= true;
3966 /* Backwards compatible extension to file version #2. */
3968 if (strncmp(lines
[5], "sharename=", 10) != 0) {
3969 return USERSHARE_MALFORMED_SHARENAME_DEF
;
3971 if (!strequal(&lines
[5][10], servicename
)) {
3972 return USERSHARE_BAD_SHARENAME
;
3974 *pp_cp_servicename
= talloc_strdup(ctx
, &lines
[5][10]);
3975 if (!*pp_cp_servicename
) {
3976 return USERSHARE_POSIX_ERR
;
3981 if (*pp_cp_servicename
== NULL
) {
3982 *pp_cp_servicename
= talloc_strdup(ctx
, servicename
);
3983 if (!*pp_cp_servicename
) {
3984 return USERSHARE_POSIX_ERR
;
3988 if (snum
!= -1 && (strcmp(sharepath
, ServicePtrs
[snum
]->path
) == 0)) {
3989 /* Path didn't change, no checks needed. */
3990 *pp_sharepath
= sharepath
;
3991 *pp_comment
= comment
;
3992 return USERSHARE_OK
;
3995 /* The path *must* be absolute. */
3996 if (sharepath
[0] != '/') {
3997 DEBUG(2,("parse_usershare_file: share %s: path %s is not an absolute path.\n",
3998 servicename
, sharepath
));
3999 return USERSHARE_PATH_NOT_ABSOLUTE
;
4002 /* If there is a usershare prefix deny list ensure one of these paths
4003 doesn't match the start of the user given path. */
4004 if (prefixdenylist
) {
4006 for ( i
=0; prefixdenylist
[i
]; i
++ ) {
4007 DEBUG(10,("parse_usershare_file: share %s : checking prefixdenylist[%d]='%s' against %s\n",
4008 servicename
, i
, prefixdenylist
[i
], sharepath
));
4009 if (memcmp( sharepath
, prefixdenylist
[i
], strlen(prefixdenylist
[i
])) == 0) {
4010 DEBUG(2,("parse_usershare_file: share %s path %s starts with one of the "
4011 "usershare prefix deny list entries.\n",
4012 servicename
, sharepath
));
4013 return USERSHARE_PATH_IS_DENIED
;
4018 /* If there is a usershare prefix allow list ensure one of these paths
4019 does match the start of the user given path. */
4021 if (prefixallowlist
) {
4023 for ( i
=0; prefixallowlist
[i
]; i
++ ) {
4024 DEBUG(10,("parse_usershare_file: share %s checking prefixallowlist[%d]='%s' against %s\n",
4025 servicename
, i
, prefixallowlist
[i
], sharepath
));
4026 if (memcmp( sharepath
, prefixallowlist
[i
], strlen(prefixallowlist
[i
])) == 0) {
4030 if (prefixallowlist
[i
] == NULL
) {
4031 DEBUG(2,("parse_usershare_file: share %s path %s doesn't start with one of the "
4032 "usershare prefix allow list entries.\n",
4033 servicename
, sharepath
));
4034 return USERSHARE_PATH_NOT_ALLOWED
;
4038 /* Ensure this is pointing to a directory. */
4039 dp
= opendir(sharepath
);
4042 DEBUG(2,("parse_usershare_file: share %s path %s is not a directory.\n",
4043 servicename
, sharepath
));
4044 return USERSHARE_PATH_NOT_DIRECTORY
;
4047 /* Ensure the owner of the usershare file has permission to share
4050 if (sys_stat(sharepath
, &sbuf
, false) == -1) {
4051 DEBUG(2,("parse_usershare_file: share %s : stat failed on path %s. %s\n",
4052 servicename
, sharepath
, strerror(errno
) ));
4054 return USERSHARE_POSIX_ERR
;
4059 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
4060 DEBUG(2,("parse_usershare_file: share %s path %s is not a directory.\n",
4061 servicename
, sharepath
));
4062 return USERSHARE_PATH_NOT_DIRECTORY
;
4065 /* Check if sharing is restricted to owner-only. */
4066 /* psbuf is the stat of the usershare definition file,
4067 sbuf is the stat of the target directory to be shared. */
4069 if (lp_usershare_owner_only()) {
4070 /* root can share anything. */
4071 if ((psbuf
->st_ex_uid
!= 0) && (sbuf
.st_ex_uid
!= psbuf
->st_ex_uid
)) {
4072 return USERSHARE_PATH_NOT_ALLOWED
;
4076 *pp_sharepath
= sharepath
;
4077 *pp_comment
= comment
;
4078 return USERSHARE_OK
;
4081 /***************************************************************************
4082 Deal with a usershare file.
4085 -1 - Bad name, invalid contents.
4086 - service name already existed and not a usershare, problem
4087 with permissions to share directory etc.
4088 ***************************************************************************/
4090 static int process_usershare_file(const char *dir_name
, const char *file_name
, int snum_template
)
4092 SMB_STRUCT_STAT sbuf
;
4093 SMB_STRUCT_STAT lsbuf
;
4095 char *sharepath
= NULL
;
4096 char *comment
= NULL
;
4097 char *cp_service_name
= NULL
;
4098 char **lines
= NULL
;
4102 TALLOC_CTX
*ctx
= talloc_stackframe();
4103 struct security_descriptor
*psd
= NULL
;
4104 bool guest_ok
= false;
4105 char *canon_name
= NULL
;
4106 bool added_service
= false;
4109 /* Ensure share name doesn't contain invalid characters. */
4110 if (!validate_net_name(file_name
, INVALID_SHARENAME_CHARS
, strlen(file_name
))) {
4111 DEBUG(0,("process_usershare_file: share name %s contains "
4112 "invalid characters (any of %s)\n",
4113 file_name
, INVALID_SHARENAME_CHARS
));
4117 canon_name
= canonicalize_servicename(ctx
, file_name
);
4122 fname
= talloc_asprintf(ctx
, "%s/%s", dir_name
, file_name
);
4127 /* Minimize the race condition by doing an lstat before we
4128 open and fstat. Ensure this isn't a symlink link. */
4130 if (sys_lstat(fname
, &lsbuf
, false) != 0) {
4131 DEBUG(0,("process_usershare_file: stat of %s failed. %s\n",
4132 fname
, strerror(errno
) ));
4136 /* This must be a regular file, not a symlink, directory or
4137 other strange filetype. */
4138 if (!check_usershare_stat(fname
, &lsbuf
)) {
4146 status
= dbwrap_fetch_bystring(ServiceHash
, canon_name
,
4151 if (NT_STATUS_IS_OK(status
) &&
4152 (data
.dptr
!= NULL
) &&
4153 (data
.dsize
== sizeof(iService
))) {
4154 memcpy(&iService
, data
.dptr
, sizeof(iService
));
4158 if (iService
!= -1 &&
4159 timespec_compare(&ServicePtrs
[iService
]->usershare_last_mod
,
4160 &lsbuf
.st_ex_mtime
) == 0) {
4161 /* Nothing changed - Mark valid and return. */
4162 DEBUG(10,("process_usershare_file: service %s not changed.\n",
4164 ServicePtrs
[iService
]->usershare
= USERSHARE_VALID
;
4169 /* Try and open the file read only - no symlinks allowed. */
4171 fd
= open(fname
, O_RDONLY
|O_NOFOLLOW
, 0);
4173 fd
= open(fname
, O_RDONLY
, 0);
4177 DEBUG(0,("process_usershare_file: unable to open %s. %s\n",
4178 fname
, strerror(errno
) ));
4182 /* Now fstat to be *SURE* it's a regular file. */
4183 if (sys_fstat(fd
, &sbuf
, false) != 0) {
4185 DEBUG(0,("process_usershare_file: fstat of %s failed. %s\n",
4186 fname
, strerror(errno
) ));
4190 /* Is it the same dev/inode as was lstated ? */
4191 if (!check_same_stat(&lsbuf
, &sbuf
)) {
4193 DEBUG(0,("process_usershare_file: fstat of %s is a different file from lstat. "
4194 "Symlink spoofing going on ?\n", fname
));
4198 /* This must be a regular file, not a symlink, directory or
4199 other strange filetype. */
4200 if (!check_usershare_stat(fname
, &sbuf
)) {
4205 lines
= fd_lines_load(fd
, &numlines
, MAX_USERSHARE_FILE_SIZE
, NULL
);
4208 if (lines
== NULL
) {
4209 DEBUG(0,("process_usershare_file: loading file %s owned by %u failed.\n",
4210 fname
, (unsigned int)sbuf
.st_ex_uid
));
4214 if (parse_usershare_file(ctx
, &sbuf
, file_name
,
4215 iService
, lines
, numlines
, &sharepath
,
4216 &comment
, &cp_service_name
,
4217 &psd
, &guest_ok
) != USERSHARE_OK
) {
4221 /* Everything ok - add the service possibly using a template. */
4223 const struct loadparm_service
*sp
= &sDefault
;
4224 if (snum_template
!= -1) {
4225 sp
= ServicePtrs
[snum_template
];
4228 if ((iService
= add_a_service(sp
, cp_service_name
)) < 0) {
4229 DEBUG(0, ("process_usershare_file: Failed to add "
4230 "new service %s\n", cp_service_name
));
4234 added_service
= true;
4236 /* Read only is controlled by usershare ACL below. */
4237 ServicePtrs
[iService
]->read_only
= false;
4240 /* Write the ACL of the new/modified share. */
4241 if (!set_share_security(canon_name
, psd
)) {
4242 DEBUG(0, ("process_usershare_file: Failed to set share "
4243 "security for user share %s\n",
4248 /* If from a template it may be marked invalid. */
4249 ServicePtrs
[iService
]->valid
= true;
4251 /* Set the service as a valid usershare. */
4252 ServicePtrs
[iService
]->usershare
= USERSHARE_VALID
;
4254 /* Set guest access. */
4255 if (lp_usershare_allow_guests()) {
4256 ServicePtrs
[iService
]->guest_ok
= guest_ok
;
4259 /* And note when it was loaded. */
4260 ServicePtrs
[iService
]->usershare_last_mod
= sbuf
.st_ex_mtime
;
4261 string_set(ServicePtrs
[iService
], &ServicePtrs
[iService
]->path
, sharepath
);
4262 string_set(ServicePtrs
[iService
], &ServicePtrs
[iService
]->comment
, comment
);
4268 if (ret
== -1 && iService
!= -1 && added_service
) {
4269 lp_remove_service(iService
);
4277 /***************************************************************************
4278 Checks if a usershare entry has been modified since last load.
4279 ***************************************************************************/
4281 static bool usershare_exists(int iService
, struct timespec
*last_mod
)
4283 SMB_STRUCT_STAT lsbuf
;
4284 const char *usersharepath
= Globals
.usershare_path
;
4287 fname
= talloc_asprintf(talloc_tos(),
4290 ServicePtrs
[iService
]->szService
);
4291 if (fname
== NULL
) {
4295 if (sys_lstat(fname
, &lsbuf
, false) != 0) {
4300 if (!S_ISREG(lsbuf
.st_ex_mode
)) {
4306 *last_mod
= lsbuf
.st_ex_mtime
;
4310 /***************************************************************************
4311 Load a usershare service by name. Returns a valid servicenumber or -1.
4312 ***************************************************************************/
4314 int load_usershare_service(const char *servicename
)
4316 SMB_STRUCT_STAT sbuf
;
4317 const char *usersharepath
= Globals
.usershare_path
;
4318 int max_user_shares
= Globals
.usershare_max_shares
;
4319 int snum_template
= -1;
4321 if (*usersharepath
== 0 || max_user_shares
== 0) {
4325 if (sys_stat(usersharepath
, &sbuf
, false) != 0) {
4326 DEBUG(0,("load_usershare_service: stat of %s failed. %s\n",
4327 usersharepath
, strerror(errno
) ));
4331 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
4332 DEBUG(0,("load_usershare_service: %s is not a directory.\n",
4338 * This directory must be owned by root, and have the 't' bit set.
4339 * It also must not be writable by "other".
4343 if (sbuf
.st_ex_uid
!= 0 || !(sbuf
.st_ex_mode
& S_ISVTX
) || (sbuf
.st_ex_mode
& S_IWOTH
)) {
4345 if (sbuf
.st_ex_uid
!= 0 || (sbuf
.st_ex_mode
& S_IWOTH
)) {
4347 DEBUG(0,("load_usershare_service: directory %s is not owned by root "
4348 "or does not have the sticky bit 't' set or is writable by anyone.\n",
4353 /* Ensure the template share exists if it's set. */
4354 if (Globals
.usershare_template_share
[0]) {
4355 /* We can't use lp_servicenumber here as we are recommending that
4356 template shares have -valid=false set. */
4357 for (snum_template
= iNumServices
- 1; snum_template
>= 0; snum_template
--) {
4358 if (ServicePtrs
[snum_template
]->szService
&&
4359 strequal(ServicePtrs
[snum_template
]->szService
,
4360 Globals
.usershare_template_share
)) {
4365 if (snum_template
== -1) {
4366 DEBUG(0,("load_usershare_service: usershare template share %s "
4367 "does not exist.\n",
4368 Globals
.usershare_template_share
));
4373 return process_usershare_file(usersharepath
, servicename
, snum_template
);
4376 /***************************************************************************
4377 Load all user defined shares from the user share directory.
4378 We only do this if we're enumerating the share list.
4379 This is the function that can delete usershares that have
4381 ***************************************************************************/
4383 int load_usershare_shares(struct smbd_server_connection
*sconn
,
4384 bool (*snumused
) (struct smbd_server_connection
*, int))
4387 SMB_STRUCT_STAT sbuf
;
4389 int num_usershares
= 0;
4390 int max_user_shares
= Globals
.usershare_max_shares
;
4391 unsigned int num_dir_entries
, num_bad_dir_entries
, num_tmp_dir_entries
;
4392 unsigned int allowed_bad_entries
= ((2*max_user_shares
)/10);
4393 unsigned int allowed_tmp_entries
= ((2*max_user_shares
)/10);
4395 int snum_template
= -1;
4396 const char *usersharepath
= Globals
.usershare_path
;
4397 int ret
= lp_numservices();
4398 TALLOC_CTX
*tmp_ctx
;
4400 if (max_user_shares
== 0 || *usersharepath
== '\0') {
4401 return lp_numservices();
4404 if (sys_stat(usersharepath
, &sbuf
, false) != 0) {
4405 DEBUG(0,("load_usershare_shares: stat of %s failed. %s\n",
4406 usersharepath
, strerror(errno
) ));
4411 * This directory must be owned by root, and have the 't' bit set.
4412 * It also must not be writable by "other".
4416 if (sbuf
.st_ex_uid
!= 0 || !(sbuf
.st_ex_mode
& S_ISVTX
) || (sbuf
.st_ex_mode
& S_IWOTH
)) {
4418 if (sbuf
.st_ex_uid
!= 0 || (sbuf
.st_ex_mode
& S_IWOTH
)) {
4420 DEBUG(0,("load_usershare_shares: directory %s is not owned by root "
4421 "or does not have the sticky bit 't' set or is writable by anyone.\n",
4426 /* Ensure the template share exists if it's set. */
4427 if (Globals
.usershare_template_share
[0]) {
4428 /* We can't use lp_servicenumber here as we are recommending that
4429 template shares have -valid=false set. */
4430 for (snum_template
= iNumServices
- 1; snum_template
>= 0; snum_template
--) {
4431 if (ServicePtrs
[snum_template
]->szService
&&
4432 strequal(ServicePtrs
[snum_template
]->szService
,
4433 Globals
.usershare_template_share
)) {
4438 if (snum_template
== -1) {
4439 DEBUG(0,("load_usershare_shares: usershare template share %s "
4440 "does not exist.\n",
4441 Globals
.usershare_template_share
));
4446 /* Mark all existing usershares as pending delete. */
4447 for (iService
= iNumServices
- 1; iService
>= 0; iService
--) {
4448 if (VALID(iService
) && ServicePtrs
[iService
]->usershare
) {
4449 ServicePtrs
[iService
]->usershare
= USERSHARE_PENDING_DELETE
;
4453 dp
= opendir(usersharepath
);
4455 DEBUG(0,("load_usershare_shares:: failed to open directory %s. %s\n",
4456 usersharepath
, strerror(errno
) ));
4460 for (num_dir_entries
= 0, num_bad_dir_entries
= 0, num_tmp_dir_entries
= 0;
4462 num_dir_entries
++ ) {
4464 const char *n
= de
->d_name
;
4466 /* Ignore . and .. */
4468 if ((n
[1] == '\0') || (n
[1] == '.' && n
[2] == '\0')) {
4474 /* Temporary file used when creating a share. */
4475 num_tmp_dir_entries
++;
4478 /* Allow 20% tmp entries. */
4479 if (num_tmp_dir_entries
> allowed_tmp_entries
) {
4480 DEBUG(0,("load_usershare_shares: too many temp entries (%u) "
4481 "in directory %s\n",
4482 num_tmp_dir_entries
, usersharepath
));
4486 r
= process_usershare_file(usersharepath
, n
, snum_template
);
4488 /* Update the services count. */
4490 if (num_usershares
>= max_user_shares
) {
4491 DEBUG(0,("load_usershare_shares: max user shares reached "
4492 "on file %s in directory %s\n",
4493 n
, usersharepath
));
4496 } else if (r
== -1) {
4497 num_bad_dir_entries
++;
4500 /* Allow 20% bad entries. */
4501 if (num_bad_dir_entries
> allowed_bad_entries
) {
4502 DEBUG(0,("load_usershare_shares: too many bad entries (%u) "
4503 "in directory %s\n",
4504 num_bad_dir_entries
, usersharepath
));
4508 /* Allow 20% bad entries. */
4509 if (num_dir_entries
> max_user_shares
+ allowed_bad_entries
) {
4510 DEBUG(0,("load_usershare_shares: too many total entries (%u) "
4511 "in directory %s\n",
4512 num_dir_entries
, usersharepath
));
4519 /* Sweep through and delete any non-refreshed usershares that are
4520 not currently in use. */
4521 tmp_ctx
= talloc_stackframe();
4522 for (iService
= iNumServices
- 1; iService
>= 0; iService
--) {
4523 if (VALID(iService
) && (ServicePtrs
[iService
]->usershare
== USERSHARE_PENDING_DELETE
)) {
4526 if (snumused
&& snumused(sconn
, iService
)) {
4530 servname
= lp_servicename(tmp_ctx
, iService
);
4532 /* Remove from the share ACL db. */
4533 DEBUG(10,("load_usershare_shares: Removing deleted usershare %s\n",
4535 delete_share_security(servname
);
4536 free_service_byindex(iService
);
4539 talloc_free(tmp_ctx
);
4541 return lp_numservices();
4544 /********************************************************
4545 Destroy global resources allocated in this file
4546 ********************************************************/
4548 void gfree_loadparm(void)
4554 /* Free resources allocated to services */
4556 for ( i
= 0; i
< iNumServices
; i
++ ) {
4558 free_service_byindex(i
);
4562 TALLOC_FREE( ServicePtrs
);
4565 /* Now release all resources allocated to global
4566 parameters and the default service */
4568 free_global_parameters();
4572 /***************************************************************************
4573 Allow client apps to specify that they are a client
4574 ***************************************************************************/
4575 static void lp_set_in_client(bool b
)
4581 /***************************************************************************
4582 Determine if we're running in a client app
4583 ***************************************************************************/
4584 static bool lp_is_in_client(void)
4589 /***************************************************************************
4590 Load the services array from the services file. Return true on success,
4592 ***************************************************************************/
4594 static bool lp_load_ex(const char *pszFname
,
4598 bool initialize_globals
,
4599 bool allow_include_registry
,
4600 bool load_all_shares
)
4607 DEBUG(3, ("lp_load_ex: refreshing parameters\n"));
4609 bInGlobalSection
= true;
4610 bGlobalOnly
= global_only
;
4611 bAllowIncludeRegistry
= allow_include_registry
;
4613 init_globals(initialize_globals
);
4617 if (save_defaults
) {
4622 if (!initialize_globals
) {
4623 free_param_opts(&Globals
.param_opt
);
4624 apply_lp_set_cmdline();
4627 lp_do_parameter(-1, "idmap config * : backend", Globals
.szIdmapBackend
);
4629 /* We get sections first, so have to start 'behind' to make up */
4632 if (lp_config_backend_is_file()) {
4633 n2
= talloc_sub_basic(talloc_tos(), get_current_username(),
4634 current_user_info
.domain
,
4637 smb_panic("lp_load_ex: out of memory");
4640 add_to_file_list(pszFname
, n2
);
4642 bRetval
= pm_process(n2
, do_section
, do_parameter
, NULL
);
4645 /* finish up the last section */
4646 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
4648 if (iServiceIndex
>= 0) {
4649 bRetval
= service_ok(iServiceIndex
);
4653 if (lp_config_backend_is_registry()) {
4654 /* config backend changed to registry in config file */
4656 * We need to use this extra global variable here to
4657 * survive restart: init_globals uses this as a default
4658 * for config_backend. Otherwise, init_globals would
4659 * send us into an endless loop here.
4661 config_backend
= CONFIG_BACKEND_REGISTRY
;
4663 DEBUG(1, ("lp_load_ex: changing to config backend "
4666 lp_kill_all_services();
4667 return lp_load_ex(pszFname
, global_only
, save_defaults
,
4668 add_ipc
, initialize_globals
,
4669 allow_include_registry
,
4672 } else if (lp_config_backend_is_registry()) {
4673 bRetval
= process_registry_globals();
4675 DEBUG(0, ("Illegal config backend given: %d\n",
4676 lp_config_backend()));
4680 if (bRetval
&& lp_registry_shares()) {
4681 if (load_all_shares
) {
4682 bRetval
= process_registry_shares();
4684 bRetval
= reload_registry_shares();
4689 char *serv
= lp_auto_services(talloc_tos());
4690 lp_add_auto_services(serv
);
4695 /* When 'restrict anonymous = 2' guest connections to ipc$
4697 lp_add_ipc("IPC$", (lp_restrict_anonymous() < 2));
4698 if ( lp_enable_asu_support() ) {
4699 lp_add_ipc("ADMIN$", false);
4703 set_allowed_client_auth();
4705 if (lp_security() == SEC_ADS
&& strchr(lp_password_server(), ':')) {
4706 DEBUG(1, ("WARNING: The optional ':port' in password server = %s is deprecated\n",
4707 lp_password_server()));
4712 /* Now we check we_are_a_wins_server and set szWINSserver to 127.0.0.1 */
4713 /* if we_are_a_wins_server is true and we are in the client */
4714 if (lp_is_in_client() && Globals
.we_are_a_wins_server
) {
4715 lp_do_parameter(GLOBAL_SECTION_SNUM
, "wins server", "127.0.0.1");
4720 fault_configure(smb_panic_s3
);
4723 * We run this check once the whole smb.conf is parsed, to
4724 * force some settings for the standard way a AD DC is
4725 * operated. We may changed these as our code evolves, which
4726 * is why we force these settings.
4728 if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC
) {
4729 lp_do_parameter(-1, "passdb backend", "samba_dsdb");
4731 lp_do_parameter(-1, "rpc_server:default", "external");
4732 lp_do_parameter(-1, "rpc_server:svcctl", "embedded");
4733 lp_do_parameter(-1, "rpc_server:srvsvc", "embedded");
4734 lp_do_parameter(-1, "rpc_server:eventlog", "embedded");
4735 lp_do_parameter(-1, "rpc_server:ntsvcs", "embedded");
4736 lp_do_parameter(-1, "rpc_server:winreg", "embedded");
4737 lp_do_parameter(-1, "rpc_server:spoolss", "embedded");
4738 lp_do_parameter(-1, "rpc_daemon:spoolssd", "embedded");
4739 lp_do_parameter(-1, "rpc_server:tcpip", "no");
4742 bAllowIncludeRegistry
= true;
4747 bool lp_load(const char *pszFname
,
4751 bool initialize_globals
)
4753 return lp_load_ex(pszFname
,
4758 true, /* allow_include_registry */
4759 false); /* load_all_shares*/
4762 bool lp_load_initial_only(const char *pszFname
)
4764 return lp_load_ex(pszFname
,
4765 true, /* global only */
4766 false, /* save_defaults */
4767 false, /* add_ipc */
4768 true, /* initialize_globals */
4769 false, /* allow_include_registry */
4770 false); /* load_all_shares*/
4774 * most common lp_load wrapper, loading only the globals
4776 bool lp_load_global(const char *file_name
)
4778 return lp_load_ex(file_name
,
4779 true, /* global_only */
4780 false, /* save_defaults */
4781 false, /* add_ipc */
4782 true, /* initialize_globals */
4783 true, /* allow_include_registry */
4784 false); /* load_all_shares*/
4788 * lp_load wrapper, especially for clients
4790 bool lp_load_client(const char *file_name
)
4792 lp_set_in_client(true);
4794 return lp_load_global(file_name
);
4798 * lp_load wrapper, loading only globals, but intended
4799 * for subsequent calls, not reinitializing the globals
4802 bool lp_load_global_no_reinit(const char *file_name
)
4804 return lp_load_ex(file_name
,
4805 true, /* global_only */
4806 false, /* save_defaults */
4807 false, /* add_ipc */
4808 false, /* initialize_globals */
4809 true, /* allow_include_registry */
4810 false); /* load_all_shares*/
4814 * lp_load wrapper, especially for clients, no reinitialization
4816 bool lp_load_client_no_reinit(const char *file_name
)
4818 lp_set_in_client(true);
4820 return lp_load_global_no_reinit(file_name
);
4823 bool lp_load_with_registry_shares(const char *pszFname
,
4827 bool initialize_globals
)
4829 return lp_load_ex(pszFname
,
4834 true, /* allow_include_registry */
4835 true); /* load_all_shares*/
4838 /***************************************************************************
4839 Return the max number of services.
4840 ***************************************************************************/
4842 int lp_numservices(void)
4844 return (iNumServices
);
4847 /***************************************************************************
4848 Display the contents of the services array in human-readable form.
4849 ***************************************************************************/
4851 void lp_dump(FILE *f
, bool show_defaults
, int maxtoprint
)
4856 defaults_saved
= false;
4860 dump_a_service(&sDefault
, f
);
4862 for (iService
= 0; iService
< maxtoprint
; iService
++) {
4864 lp_dump_one(f
, show_defaults
, iService
);
4868 /***************************************************************************
4869 Display the contents of one service in human-readable form.
4870 ***************************************************************************/
4872 void lp_dump_one(FILE * f
, bool show_defaults
, int snum
)
4875 if (ServicePtrs
[snum
]->szService
[0] == '\0')
4877 dump_a_service(ServicePtrs
[snum
], f
);
4881 /***************************************************************************
4882 Return the number of the service with the given name, or -1 if it doesn't
4883 exist. Note that this is a DIFFERENT ANIMAL from the internal function
4884 getservicebyname()! This works ONLY if all services have been loaded, and
4885 does not copy the found service.
4886 ***************************************************************************/
4888 int lp_servicenumber(const char *pszServiceName
)
4891 fstring serviceName
;
4893 if (!pszServiceName
) {
4894 return GLOBAL_SECTION_SNUM
;
4897 for (iService
= iNumServices
- 1; iService
>= 0; iService
--) {
4898 if (VALID(iService
) && ServicePtrs
[iService
]->szService
) {
4900 * The substitution here is used to support %U is
4903 fstrcpy(serviceName
, ServicePtrs
[iService
]->szService
);
4904 standard_sub_basic(get_current_username(),
4905 current_user_info
.domain
,
4906 serviceName
,sizeof(serviceName
));
4907 if (strequal(serviceName
, pszServiceName
)) {
4913 if (iService
>= 0 && ServicePtrs
[iService
]->usershare
== USERSHARE_VALID
) {
4914 struct timespec last_mod
;
4916 if (!usershare_exists(iService
, &last_mod
)) {
4917 /* Remove the share security tdb entry for it. */
4918 delete_share_security(lp_servicename(talloc_tos(), iService
));
4919 /* Remove it from the array. */
4920 free_service_byindex(iService
);
4921 /* Doesn't exist anymore. */
4922 return GLOBAL_SECTION_SNUM
;
4925 /* Has it been modified ? If so delete and reload. */
4926 if (timespec_compare(&ServicePtrs
[iService
]->usershare_last_mod
,
4928 /* Remove it from the array. */
4929 free_service_byindex(iService
);
4930 /* and now reload it. */
4931 iService
= load_usershare_service(pszServiceName
);
4936 DEBUG(7,("lp_servicenumber: couldn't find %s\n", pszServiceName
));
4937 return GLOBAL_SECTION_SNUM
;
4943 /*******************************************************************
4944 A useful volume label function.
4945 ********************************************************************/
4947 const char *volume_label(TALLOC_CTX
*ctx
, int snum
)
4950 const char *label
= lp_volume(ctx
, snum
);
4952 label
= lp_servicename(ctx
, snum
);
4955 /* This returns a 33 byte guarenteed null terminated string. */
4956 ret
= talloc_strndup(ctx
, label
, 32);
4963 /*******************************************************************
4964 Get the default server type we will announce as via nmbd.
4965 ********************************************************************/
4967 int lp_default_server_announce(void)
4969 int default_server_announce
= 0;
4970 default_server_announce
|= SV_TYPE_WORKSTATION
;
4971 default_server_announce
|= SV_TYPE_SERVER
;
4972 default_server_announce
|= SV_TYPE_SERVER_UNIX
;
4974 /* note that the flag should be set only if we have a
4975 printer service but nmbd doesn't actually load the
4976 services so we can't tell --jerry */
4978 default_server_announce
|= SV_TYPE_PRINTQ_SERVER
;
4980 default_server_announce
|= SV_TYPE_SERVER_NT
;
4981 default_server_announce
|= SV_TYPE_NT
;
4983 switch (lp_server_role()) {
4984 case ROLE_DOMAIN_MEMBER
:
4985 default_server_announce
|= SV_TYPE_DOMAIN_MEMBER
;
4987 case ROLE_DOMAIN_PDC
:
4988 default_server_announce
|= SV_TYPE_DOMAIN_CTRL
;
4990 case ROLE_DOMAIN_BDC
:
4991 default_server_announce
|= SV_TYPE_DOMAIN_BAKCTRL
;
4993 case ROLE_STANDALONE
:
4997 if (lp_time_server())
4998 default_server_announce
|= SV_TYPE_TIME_SOURCE
;
5000 if (lp_host_msdfs())
5001 default_server_announce
|= SV_TYPE_DFS_SERVER
;
5003 return default_server_announce
;
5006 /***********************************************************
5007 If we are PDC then prefer us as DMB
5008 ************************************************************/
5010 bool lp_domain_master(void)
5012 if (Globals
._domain_master
== Auto
)
5013 return (lp_server_role() == ROLE_DOMAIN_PDC
);
5015 return (bool)Globals
._domain_master
;
5018 /***********************************************************
5019 If we are PDC then prefer us as DMB
5020 ************************************************************/
5022 static bool lp_domain_master_true_or_auto(void)
5024 if (Globals
._domain_master
) /* auto or yes */
5030 /***********************************************************
5031 If we are DMB then prefer us as LMB
5032 ************************************************************/
5034 bool lp_preferred_master(void)
5036 if (Globals
.iPreferredMaster
== Auto
)
5037 return (lp_local_master() && lp_domain_master());
5039 return (bool)Globals
.iPreferredMaster
;
5042 /*******************************************************************
5044 ********************************************************************/
5046 void lp_remove_service(int snum
)
5048 ServicePtrs
[snum
]->valid
= false;
5051 /*******************************************************************
5053 ********************************************************************/
5055 void lp_copy_service(int snum
, const char *new_name
)
5057 do_section(new_name
, NULL
);
5059 snum
= lp_servicenumber(new_name
);
5061 char *name
= lp_servicename(talloc_tos(), snum
);
5062 lp_do_parameter(snum
, "copy", name
);
5067 const char *lp_printername(TALLOC_CTX
*ctx
, int snum
)
5069 const char *ret
= lp__printername(ctx
, snum
);
5070 if (ret
== NULL
|| *ret
== '\0') {
5071 ret
= lp_const_servicename(snum
);
5078 /***********************************************************
5079 Allow daemons such as winbindd to fix their logfile name.
5080 ************************************************************/
5082 void lp_set_logfile(const char *name
)
5084 string_set(Globals
.ctx
, &Globals
.logfile
, name
);
5085 debug_set_logfile(name
);
5088 /*******************************************************************
5089 Return the max print jobs per queue.
5090 ********************************************************************/
5092 int lp_maxprintjobs(int snum
)
5094 int maxjobs
= LP_SNUM_OK(snum
) ? ServicePtrs
[snum
]->iMaxPrintJobs
: sDefault
.iMaxPrintJobs
;
5095 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
5096 maxjobs
= PRINT_MAX_JOBID
- 1;
5101 const char *lp_printcapname(void)
5103 if ((Globals
.szPrintcapname
!= NULL
) &&
5104 (Globals
.szPrintcapname
[0] != '\0'))
5105 return Globals
.szPrintcapname
;
5107 if (sDefault
.printing
== PRINT_CUPS
) {
5111 if (sDefault
.printing
== PRINT_BSD
)
5112 return "/etc/printcap";
5114 return PRINTCAP_NAME
;
5117 static uint32 spoolss_state
;
5119 bool lp_disable_spoolss( void )
5121 if ( spoolss_state
== SVCCTL_STATE_UNKNOWN
)
5122 spoolss_state
= lp__disable_spoolss() ? SVCCTL_STOPPED
: SVCCTL_RUNNING
;
5124 return spoolss_state
== SVCCTL_STOPPED
? true : false;
5127 void lp_set_spoolss_state( uint32 state
)
5129 SMB_ASSERT( (state
== SVCCTL_STOPPED
) || (state
== SVCCTL_RUNNING
) );
5131 spoolss_state
= state
;
5134 uint32
lp_get_spoolss_state( void )
5136 return lp_disable_spoolss() ? SVCCTL_STOPPED
: SVCCTL_RUNNING
;
5139 /*******************************************************************
5140 Ensure we don't use sendfile if server smb signing is active.
5141 ********************************************************************/
5143 bool lp_use_sendfile(int snum
, struct smb_signing_state
*signing_state
)
5145 bool sign_active
= false;
5147 /* Using sendfile blows the brains out of any DOS or Win9x TCP stack... JRA. */
5148 if (get_Protocol() < PROTOCOL_NT1
) {
5151 if (signing_state
) {
5152 sign_active
= smb_signing_is_active(signing_state
);
5154 return (lp__use_sendfile(snum
) &&
5155 (get_remote_arch() != RA_WIN95
) &&
5159 /*******************************************************************
5160 Turn off sendfile if we find the underlying OS doesn't support it.
5161 ********************************************************************/
5163 void set_use_sendfile(int snum
, bool val
)
5165 if (LP_SNUM_OK(snum
))
5166 ServicePtrs
[snum
]->_use_sendfile
= val
;
5168 sDefault
._use_sendfile
= val
;
5171 /*******************************************************************
5172 Turn off storing DOS attributes if this share doesn't support it.
5173 ********************************************************************/
5175 void set_store_dos_attributes(int snum
, bool val
)
5177 if (!LP_SNUM_OK(snum
))
5179 ServicePtrs
[(snum
)]->store_dos_attributes
= val
;
5182 void lp_set_mangling_method(const char *new_method
)
5184 string_set(Globals
.ctx
, &Globals
.mangling_method
, new_method
);
5187 /*******************************************************************
5188 Global state for POSIX pathname processing.
5189 ********************************************************************/
5191 static bool posix_pathnames
;
5193 bool lp_posix_pathnames(void)
5195 return posix_pathnames
;
5198 /*******************************************************************
5199 Change everything needed to ensure POSIX pathname processing (currently
5201 ********************************************************************/
5203 void lp_set_posix_pathnames(void)
5205 posix_pathnames
= true;
5208 /*******************************************************************
5209 Global state for POSIX lock processing - CIFS unix extensions.
5210 ********************************************************************/
5212 bool posix_default_lock_was_set
;
5213 static enum brl_flavour posix_cifsx_locktype
; /* By default 0 == WINDOWS_LOCK */
5215 enum brl_flavour
lp_posix_cifsu_locktype(files_struct
*fsp
)
5217 if (posix_default_lock_was_set
) {
5218 return posix_cifsx_locktype
;
5220 return fsp
->posix_open
? POSIX_LOCK
: WINDOWS_LOCK
;
5224 /*******************************************************************
5225 ********************************************************************/
5227 void lp_set_posix_default_cifsx_readwrite_locktype(enum brl_flavour val
)
5229 posix_default_lock_was_set
= true;
5230 posix_cifsx_locktype
= val
;
5233 int lp_min_receive_file_size(void)
5235 if (Globals
.iminreceivefile
< 0) {
5238 return Globals
.iminreceivefile
;
5241 /*******************************************************************
5242 Safe wide links checks.
5243 This helper function always verify the validity of wide links,
5244 even after a configuration file reload.
5245 ********************************************************************/
5247 static bool lp_widelinks_internal(int snum
)
5249 return (bool)(LP_SNUM_OK(snum
)? ServicePtrs
[(snum
)]->bWidelinks
:
5250 sDefault
.bWidelinks
);
5253 void widelinks_warning(int snum
)
5255 if (lp_allow_insecure_wide_links()) {
5259 if (lp_unix_extensions() && lp_widelinks_internal(snum
)) {
5260 DEBUG(0,("Share '%s' has wide links and unix extensions enabled. "
5261 "These parameters are incompatible. "
5262 "Wide links will be disabled for this share.\n",
5263 lp_servicename(talloc_tos(), snum
) ));
5267 bool lp_widelinks(int snum
)
5269 /* wide links is always incompatible with unix extensions */
5270 if (lp_unix_extensions()) {
5272 * Unless we have "allow insecure widelinks"
5275 if (!lp_allow_insecure_wide_links()) {
5280 return lp_widelinks_internal(snum
);
5283 int lp_server_role(void)
5285 return lp_find_server_role(lp__server_role(),
5287 lp__domain_logons(),
5288 lp_domain_master_true_or_auto());
5291 int lp_security(void)
5293 return lp_find_security(lp__server_role(),
5297 struct loadparm_global
* get_globals(void)