s3/loadparm: allocate a fresh sDefault object per lp_ctx
[Samba.git] / source3 / param / loadparm.c
blob433727b3f7982ff9f6b51d7144938990a539ce4d
1 /*
2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
12 Copyright (C) Michael Adam 2008
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * Load parameters.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
37 * To add a parameter:
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
46 * Notes:
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
52 * careful!
56 #include "includes.h"
57 #include "system/filesys.h"
58 #include "util_tdb.h"
59 #include "lib/param/loadparm.h"
60 #include "lib/param/param.h"
61 #include "printing.h"
62 #include "lib/smbconf/smbconf.h"
63 #include "lib/smbconf/smbconf_init.h"
65 #include "ads.h"
66 #include "../librpc/gen_ndr/svcctl.h"
67 #include "intl.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"
72 #include "librpc/gen_ndr/nbt.h"
73 #include "source4/lib/tls/tls.h"
74 #include "libcli/auth/ntlm_check.h"
76 #ifdef HAVE_SYS_SYSCTL_H
77 #include <sys/sysctl.h>
78 #endif
80 bool bLoaded = false;
82 extern userdom_struct current_user_info;
84 /* the special value for the include parameter
85 * to be interpreted not as a file name but to
86 * trigger loading of the global smb.conf options
87 * from registry. */
88 #ifndef INCLUDE_REGISTRY_NAME
89 #define INCLUDE_REGISTRY_NAME "registry"
90 #endif
92 static bool in_client = false; /* Not in the client by default */
93 static struct smbconf_csn conf_last_csn;
95 static int config_backend = CONFIG_BACKEND_FILE;
97 /* some helpful bits */
98 #define LP_SNUM_OK(i) (((i) >= 0) && ((i) < iNumServices) && \
99 (ServicePtrs != NULL) && \
100 (ServicePtrs[(i)] != NULL) && ServicePtrs[(i)]->valid)
101 #define VALID(i) ((ServicePtrs != NULL) && (ServicePtrs[i]!= NULL) && \
102 ServicePtrs[i]->valid)
104 #define USERSHARE_VALID 1
105 #define USERSHARE_PENDING_DELETE 2
107 static bool defaults_saved = false;
109 #include "lib/param/param_global.h"
111 static struct loadparm_global Globals;
113 /* This is a default service used to prime a services structure */
114 static struct loadparm_service sDefault =
116 .valid = true,
117 .autoloaded = false,
118 .usershare = 0,
119 .usershare_last_mod = {0, 0},
120 .szService = NULL,
121 .path = NULL,
122 .invalid_users = NULL,
123 .valid_users = NULL,
124 .admin_users = NULL,
125 .copy = NULL,
126 .include = NULL,
127 .preexec = NULL,
128 .postexec = NULL,
129 .root_preexec = NULL,
130 .root_postexec = NULL,
131 .cups_options = NULL,
132 .print_command = NULL,
133 .lpq_command = NULL,
134 .lprm_command = NULL,
135 .lppause_command = NULL,
136 .lpresume_command = NULL,
137 .queuepause_command = NULL,
138 .queueresume_command = NULL,
139 ._printername = NULL,
140 .printjob_username = NULL,
141 .dont_descend = NULL,
142 .hosts_allow = NULL,
143 .hosts_deny = NULL,
144 .magic_script = NULL,
145 .magic_output = NULL,
146 .veto_files = NULL,
147 .hide_files = NULL,
148 .veto_oplock_files = NULL,
149 .comment = NULL,
150 .force_user = NULL,
151 .force_group = NULL,
152 .read_list = NULL,
153 .write_list = NULL,
154 .volume = NULL,
155 .fstype = NULL,
156 .vfs_objects = NULL,
157 .msdfs_proxy = NULL,
158 .aio_write_behind = NULL,
159 .dfree_command = NULL,
160 .min_print_space = 0,
161 .max_print_jobs = 1000,
162 .max_reported_print_jobs = 0,
163 .write_cache_size = 0,
164 .create_mask = 0744,
165 .force_create_mode = 0,
166 .directory_mask = 0755,
167 .force_directory_mode = 0,
168 .max_connections = 0,
169 .default_case = CASE_LOWER,
170 .printing = DEFAULT_PRINTING,
171 .csc_policy = 0,
172 .block_size = 1024,
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,
183 .browseable = true,
184 .access_based_share_enum = false,
185 .available = true,
186 .read_only = true,
187 .spotlight = false,
188 .guest_only = false,
189 .administrative_share = false,
190 .guest_ok = false,
191 .printable = false,
192 .print_notify_backchannel = false,
193 .map_system = false,
194 .map_hidden = false,
195 .map_archive = true,
196 .store_dos_attributes = false,
197 .dmapi_support = false,
198 .locking = true,
199 .strict_locking = Auto,
200 .posix_locking = true,
201 .oplocks = true,
202 .kernel_oplocks = false,
203 .level2_oplocks = true,
204 .mangled_names = MANGLED_NAMES_YES,
205 .wide_links = false,
206 .follow_symlinks = true,
207 .sync_always = false,
208 .strict_allocate = false,
209 .strict_rename = false,
210 .strict_sync = true,
211 .mangling_char = '~',
212 .copymap = NULL,
213 .delete_readonly = false,
214 .fake_oplocks = false,
215 .delete_veto_files = false,
216 .dos_filemode = false,
217 .dos_filetimes = true,
218 .dos_filetime_resolution = false,
219 .fake_directory_create_times = false,
220 .blocking_locks = true,
221 .inherit_permissions = false,
222 .inherit_acls = false,
223 .inherit_owner = false,
224 .msdfs_root = false,
225 .msdfs_shuffle_referrals = false,
226 .use_client_driver = false,
227 .default_devmode = true,
228 .force_printername = false,
229 .nt_acl_support = true,
230 .force_unknown_acl_user = false,
231 ._use_sendfile = false,
232 .profile_acls = false,
233 .map_acl_inherit = false,
234 .afs_share = false,
235 .ea_support = false,
236 .acl_check_permissions = true,
237 .acl_map_full_control = true,
238 .acl_group_control = false,
239 .acl_allow_execute_always = false,
240 .allocation_roundup_size = SMB_ROUNDUP_ALLOCATION_SIZE,
241 .aio_read_size = 0,
242 .aio_write_size = 0,
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,
248 .param_opt = NULL,
249 .dummy = ""
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;
259 static struct file_lists *file_lists = NULL;
260 static unsigned int *flags_list = NULL;
262 static void set_allowed_client_auth(void);
264 static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmValue);
265 static void free_param_opts(struct parmlist_entry **popts);
268 * Function to return the default value for the maximum number of open
269 * file descriptors permitted. This function tries to consult the
270 * kernel-level (sysctl) and ulimit (getrlimit()) values and goes
271 * the smaller of those.
273 static int max_open_files(void)
275 int sysctl_max = MAX_OPEN_FILES;
276 int rlimit_max = MAX_OPEN_FILES;
278 #ifdef HAVE_SYSCTLBYNAME
280 size_t size = sizeof(sysctl_max);
281 sysctlbyname("kern.maxfilesperproc", &sysctl_max, &size, NULL,
284 #endif
286 #if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
288 struct rlimit rl;
290 ZERO_STRUCT(rl);
292 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
293 rlimit_max = rl.rlim_cur;
295 #if defined(RLIM_INFINITY)
296 if(rl.rlim_cur == RLIM_INFINITY)
297 rlimit_max = MAX_OPEN_FILES;
298 #endif
300 #endif
302 if (sysctl_max < MIN_OPEN_FILES_WINDOWS) {
303 DEBUG(2,("max_open_files: increasing sysctl_max (%d) to "
304 "minimum Windows limit (%d)\n",
305 sysctl_max,
306 MIN_OPEN_FILES_WINDOWS));
307 sysctl_max = MIN_OPEN_FILES_WINDOWS;
310 if (rlimit_max < MIN_OPEN_FILES_WINDOWS) {
311 DEBUG(2,("rlimit_max: increasing rlimit_max (%d) to "
312 "minimum Windows limit (%d)\n",
313 rlimit_max,
314 MIN_OPEN_FILES_WINDOWS));
315 rlimit_max = MIN_OPEN_FILES_WINDOWS;
318 return MIN(sysctl_max, rlimit_max);
322 * Common part of freeing allocated data for one parameter.
324 static void free_one_parameter_common(void *parm_ptr,
325 struct parm_struct parm)
327 if ((parm.type == P_STRING) ||
328 (parm.type == P_USTRING))
330 lpcfg_string_free((char**)parm_ptr);
331 } else if (parm.type == P_LIST || parm.type == P_CMDLIST) {
332 TALLOC_FREE(*((char***)parm_ptr));
337 * Free the allocated data for one parameter for a share
338 * given as a service struct.
340 static void free_one_parameter(struct loadparm_service *service,
341 struct parm_struct parm)
343 void *parm_ptr;
345 if (parm.p_class != P_LOCAL) {
346 return;
349 parm_ptr = lp_parm_ptr(service, &parm);
351 free_one_parameter_common(parm_ptr, parm);
355 * Free the allocated parameter data of a share given
356 * as a service struct.
358 static void free_parameters(struct loadparm_service *service)
360 uint32_t i;
362 for (i=0; parm_table[i].label; i++) {
363 free_one_parameter(service, parm_table[i]);
368 * Free the allocated data for one parameter for a given share
369 * specified by an snum.
371 static void free_one_parameter_by_snum(int snum, struct parm_struct parm)
373 void *parm_ptr;
375 if (snum < 0) {
376 parm_ptr = lp_parm_ptr(NULL, &parm);
377 } else if (parm.p_class != P_LOCAL) {
378 return;
379 } else {
380 parm_ptr = lp_parm_ptr(ServicePtrs[snum], &parm);
383 free_one_parameter_common(parm_ptr, parm);
387 * Free the allocated parameter data for a share specified
388 * by an snum.
390 static void free_parameters_by_snum(int snum)
392 uint32_t i;
394 for (i=0; parm_table[i].label; i++) {
395 free_one_parameter_by_snum(snum, parm_table[i]);
400 * Free the allocated global parameters.
402 static void free_global_parameters(void)
404 uint32_t i;
405 struct parm_struct *parm;
407 free_param_opts(&Globals.param_opt);
408 free_parameters_by_snum(GLOBAL_SECTION_SNUM);
410 /* Reset references in the defaults because the context is going to be freed */
411 for (i=0; parm_table[i].label; i++) {
412 parm = &parm_table[i];
413 if ((parm->type == P_STRING) ||
414 (parm->type == P_USTRING)) {
415 if ((parm->def.svalue != NULL) &&
416 (*(parm->def.svalue) != '\0')) {
417 if (talloc_parent(parm->def.svalue) == Globals.ctx) {
418 parm->def.svalue = NULL;
423 TALLOC_FREE(Globals.ctx);
426 struct lp_stored_option {
427 struct lp_stored_option *prev, *next;
428 const char *label;
429 const char *value;
432 static struct lp_stored_option *stored_options;
435 save options set by lp_set_cmdline() into a list. This list is
436 re-applied when we do a globals reset, so that cmdline set options
437 are sticky across reloads of smb.conf
439 bool store_lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
441 struct lp_stored_option *entry, *entry_next;
442 for (entry = stored_options; entry != NULL; entry = entry_next) {
443 entry_next = entry->next;
444 if (strcmp(pszParmName, entry->label) == 0) {
445 DLIST_REMOVE(stored_options, entry);
446 talloc_free(entry);
447 break;
451 entry = talloc(NULL, struct lp_stored_option);
452 if (!entry) {
453 return false;
456 entry->label = talloc_strdup(entry, pszParmName);
457 if (!entry->label) {
458 talloc_free(entry);
459 return false;
462 entry->value = talloc_strdup(entry, pszParmValue);
463 if (!entry->value) {
464 talloc_free(entry);
465 return false;
468 DLIST_ADD_END(stored_options, entry);
470 return true;
473 static bool apply_lp_set_cmdline(void)
475 struct lp_stored_option *entry = NULL;
476 for (entry = stored_options; entry != NULL; entry = entry->next) {
477 if (!lp_set_cmdline_helper(entry->label, entry->value)) {
478 DEBUG(0, ("Failed to re-apply cmdline parameter %s = %s\n",
479 entry->label, entry->value));
480 return false;
483 return true;
486 /***************************************************************************
487 Initialise the global parameter structure.
488 ***************************************************************************/
490 static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
492 static bool done_init = false;
493 char *s = NULL;
494 int i;
496 /* If requested to initialize only once and we've already done it... */
497 if (!reinit_globals && done_init) {
498 /* ... then we have nothing more to do */
499 return;
502 if (!done_init) {
503 /* The logfile can be set before this is invoked. Free it if so. */
504 lpcfg_string_free(&Globals.logfile);
505 done_init = true;
506 } else {
507 free_global_parameters();
510 /* This memset and the free_global_parameters() above will
511 * wipe out smb.conf options set with lp_set_cmdline(). The
512 * apply_lp_set_cmdline() call puts these values back in the
513 * table once the defaults are set */
514 ZERO_STRUCT(Globals);
516 Globals.ctx = talloc_pooled_object(NULL, char, 272, 2048);
518 /* Initialize the flags list if necessary */
519 if (flags_list == NULL) {
520 get_flags();
523 for (i = 0; parm_table[i].label; i++) {
524 if ((parm_table[i].type == P_STRING ||
525 parm_table[i].type == P_USTRING))
527 lpcfg_string_set(
528 Globals.ctx,
529 (char **)lp_parm_ptr(NULL, &parm_table[i]),
530 "");
535 lpcfg_string_set(Globals.ctx, &sDefault.fstype, FSTYPE_STRING);
536 lpcfg_string_set(Globals.ctx, &sDefault.printjob_username, "%U");
538 init_printer_values(lp_ctx, Globals.ctx, &sDefault);
540 sDefault.ntvfs_handler = str_list_make_v3_const(NULL, "unixuid default", NULL);
542 DEBUG(3, ("Initialising global parameters\n"));
544 /* Must manually force to upper case here, as this does not go via the handler */
545 lpcfg_string_set(Globals.ctx, &Globals.netbios_name,
546 myhostname_upper());
548 lpcfg_string_set(Globals.ctx, &Globals.smb_passwd_file,
549 get_dyn_SMB_PASSWD_FILE());
550 lpcfg_string_set(Globals.ctx, &Globals.private_dir,
551 get_dyn_PRIVATE_DIR());
552 lpcfg_string_set(Globals.ctx, &Globals.binddns_dir,
553 get_dyn_BINDDNS_DIR());
555 /* use the new 'hash2' method by default, with a prefix of 1 */
556 lpcfg_string_set(Globals.ctx, &Globals.mangling_method, "hash2");
557 Globals.mangle_prefix = 1;
559 lpcfg_string_set(Globals.ctx, &Globals.guest_account, GUEST_ACCOUNT);
561 /* using UTF8 by default allows us to support all chars */
562 lpcfg_string_set(Globals.ctx, &Globals.unix_charset,
563 DEFAULT_UNIX_CHARSET);
565 /* Use codepage 850 as a default for the dos character set */
566 lpcfg_string_set(Globals.ctx, &Globals.dos_charset,
567 DEFAULT_DOS_CHARSET);
570 * Allow the default PASSWD_CHAT to be overridden in local.h.
572 lpcfg_string_set(Globals.ctx, &Globals.passwd_chat,
573 DEFAULT_PASSWD_CHAT);
575 lpcfg_string_set(Globals.ctx, &Globals.workgroup, DEFAULT_WORKGROUP);
577 lpcfg_string_set(Globals.ctx, &Globals.passwd_program, "");
578 lpcfg_string_set(Globals.ctx, &Globals.lock_directory,
579 get_dyn_LOCKDIR());
580 lpcfg_string_set(Globals.ctx, &Globals.state_directory,
581 get_dyn_STATEDIR());
582 lpcfg_string_set(Globals.ctx, &Globals.cache_directory,
583 get_dyn_CACHEDIR());
584 lpcfg_string_set(Globals.ctx, &Globals.pid_directory,
585 get_dyn_PIDDIR());
586 lpcfg_string_set(Globals.ctx, &Globals.nbt_client_socket_address,
587 "0.0.0.0");
589 * By default support explicit binding to broadcast
590 * addresses.
592 Globals.nmbd_bind_explicit_broadcast = true;
594 s = talloc_asprintf(talloc_tos(), "Samba %s", samba_version_string());
595 if (s == NULL) {
596 smb_panic("init_globals: ENOMEM");
598 lpcfg_string_set(Globals.ctx, &Globals.server_string, s);
599 TALLOC_FREE(s);
600 #ifdef DEVELOPER
601 lpcfg_string_set(Globals.ctx, &Globals.panic_action,
602 "/bin/sleep 999999999");
603 #endif
605 lpcfg_string_set(Globals.ctx, &Globals.socket_options,
606 DEFAULT_SOCKET_OPTIONS);
608 lpcfg_string_set(Globals.ctx, &Globals.logon_drive, "");
609 /* %N is the NIS auto.home server if -DAUTOHOME is used, else same as %L */
610 lpcfg_string_set(Globals.ctx, &Globals.logon_home, "\\\\%N\\%U");
611 lpcfg_string_set(Globals.ctx, &Globals.logon_path,
612 "\\\\%N\\%U\\profile");
614 Globals.name_resolve_order =
615 str_list_make_v3_const(Globals.ctx,
616 DEFAULT_NAME_RESOLVE_ORDER,
617 NULL);
618 lpcfg_string_set(Globals.ctx, &Globals.password_server, "*");
620 Globals.algorithmic_rid_base = BASE_RID;
622 Globals.load_printers = true;
623 Globals.printcap_cache_time = 750; /* 12.5 minutes */
625 Globals.config_backend = config_backend;
626 Globals._server_role = ROLE_AUTO;
628 /* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
629 /* Discovered by 2 days of pain by Don McCall @ HP :-). */
630 Globals.max_xmit = 0x4104;
631 Globals.max_mux = 50; /* This is *needed* for profile support. */
632 Globals.lpq_cache_time = 30; /* changed to handle large print servers better -- jerry */
633 Globals._disable_spoolss = false;
634 Globals.max_smbd_processes = 0;/* no limit specified */
635 Globals.username_level = 0;
636 Globals.deadtime = 0;
637 Globals.getwd_cache = true;
638 Globals.large_readwrite = true;
639 Globals.max_log_size = 5000;
640 Globals.max_open_files = max_open_files();
641 Globals.server_max_protocol = PROTOCOL_SMB3_11;
642 Globals.server_min_protocol = PROTOCOL_LANMAN1;
643 Globals._client_max_protocol = PROTOCOL_DEFAULT;
644 Globals.client_min_protocol = PROTOCOL_CORE;
645 Globals._client_ipc_max_protocol = PROTOCOL_DEFAULT;
646 Globals._client_ipc_min_protocol = PROTOCOL_DEFAULT;
647 Globals._security = SEC_AUTO;
648 Globals.encrypt_passwords = true;
649 Globals.client_schannel = Auto;
650 Globals.winbind_sealed_pipes = true;
651 Globals.require_strong_key = true;
652 Globals.server_schannel = Auto;
653 Globals.read_raw = true;
654 Globals.write_raw = true;
655 Globals.null_passwords = false;
656 Globals.old_password_allowed_period = 60;
657 Globals.obey_pam_restrictions = false;
658 Globals.syslog = 1;
659 Globals.syslog_only = false;
660 Globals.timestamp_logs = true;
661 lpcfg_string_set(Globals.ctx, &Globals.log_level, "0");
662 Globals.debug_prefix_timestamp = false;
663 Globals.debug_hires_timestamp = true;
664 Globals.debug_pid = false;
665 Globals.debug_uid = false;
666 Globals.debug_class = false;
667 Globals.enable_core_files = true;
668 Globals.max_ttl = 60 * 60 * 24 * 3; /* 3 days default. */
669 Globals.max_wins_ttl = 60 * 60 * 24 * 6; /* 6 days default. */
670 Globals.min_wins_ttl = 60 * 60 * 6; /* 6 hours default. */
671 Globals.machine_password_timeout = 60 * 60 * 24 * 7; /* 7 days default. */
672 Globals.lm_announce = Auto; /* = Auto: send only if LM clients found */
673 Globals.lm_interval = 60;
674 #if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT))
675 Globals.nis_homedir = false;
676 #ifdef WITH_NISPLUS_HOME
677 lpcfg_string_set(Globals.ctx, &Globals.homedir_map,
678 "auto_home.org_dir");
679 #else
680 lpcfg_string_set(Globals.ctx, &Globals.homedir_map, "auto.home");
681 #endif
682 #endif
683 Globals.time_server = false;
684 Globals.bind_interfaces_only = false;
685 Globals.unix_password_sync = false;
686 Globals.pam_password_change = false;
687 Globals.passwd_chat_debug = false;
688 Globals.passwd_chat_timeout = 2; /* 2 second default. */
689 Globals.nt_pipe_support = true; /* Do NT pipes by default. */
690 Globals.nt_status_support = true; /* Use NT status by default. */
691 Globals.smbd_profiling_level = 0;
692 Globals.stat_cache = true; /* use stat cache by default */
693 Globals.max_stat_cache_size = 256; /* 256k by default */
694 Globals.restrict_anonymous = 0;
695 Globals.client_lanman_auth = false; /* Do NOT use the LanMan hash if it is available */
696 Globals.client_plaintext_auth = false; /* Do NOT use a plaintext password even if is requested by the server */
697 Globals._lanman_auth = false; /* Do NOT use the LanMan hash, even if it is supplied */
698 Globals.ntlm_auth = NTLM_AUTH_NTLMV2_ONLY; /* Do NOT use NTLMv1 if it is supplied by the client (otherwise NTLMv2) */
699 Globals.raw_ntlmv2_auth = false; /* Reject NTLMv2 without NTLMSSP */
700 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 */
701 /* Note, that we will also use NTLM2 session security (which is different), if it is available */
703 Globals.allow_dcerpc_auth_level_connect = false; /* we don't allow this by default */
705 Globals.map_to_guest = 0; /* By Default, "Never" */
706 Globals.oplock_break_wait_time = 0; /* By Default, 0 msecs. */
707 Globals.enhanced_browsing = true;
708 Globals.lock_spin_time = WINDOWS_MINIMUM_LOCK_TIMEOUT_MS; /* msec. */
709 #ifdef MMAP_BLACKLIST
710 Globals.use_mmap = false;
711 #else
712 Globals.use_mmap = true;
713 #endif
714 Globals.unicode = true;
715 Globals.unix_extensions = true;
716 Globals.reset_on_zero_vc = false;
717 Globals.log_writeable_files_on_exit = false;
718 Globals.create_krb5_conf = true;
719 Globals.include_system_krb5_conf = true;
720 Globals._winbind_max_domain_connections = 1;
722 /* hostname lookups can be very expensive and are broken on
723 a large number of sites (tridge) */
724 Globals.hostname_lookups = false;
726 Globals.change_notify = true,
727 Globals.kernel_change_notify = true,
729 lpcfg_string_set(Globals.ctx, &Globals.passdb_backend, "tdbsam");
730 lpcfg_string_set(Globals.ctx, &Globals.ldap_suffix, "");
731 lpcfg_string_set(Globals.ctx, &Globals._ldap_machine_suffix, "");
732 lpcfg_string_set(Globals.ctx, &Globals._ldap_user_suffix, "");
733 lpcfg_string_set(Globals.ctx, &Globals._ldap_group_suffix, "");
734 lpcfg_string_set(Globals.ctx, &Globals._ldap_idmap_suffix, "");
736 lpcfg_string_set(Globals.ctx, &Globals.ldap_admin_dn, "");
737 Globals.ldap_ssl = LDAP_SSL_START_TLS;
738 Globals.ldap_ssl_ads = false;
739 Globals.ldap_deref = -1;
740 Globals.ldap_passwd_sync = LDAP_PASSWD_SYNC_OFF;
741 Globals.ldap_delete_dn = false;
742 Globals.ldap_replication_sleep = 1000; /* wait 1 sec for replication */
743 Globals.ldap_follow_referral = Auto;
744 Globals.ldap_timeout = LDAP_DEFAULT_TIMEOUT;
745 Globals.ldap_connection_timeout = LDAP_CONNECTION_DEFAULT_TIMEOUT;
746 Globals.ldap_page_size = LDAP_PAGE_SIZE;
748 Globals.ldap_debug_level = 0;
749 Globals.ldap_debug_threshold = 10;
751 Globals.client_ldap_sasl_wrapping = ADS_AUTH_SASL_SIGN;
753 Globals.ldap_server_require_strong_auth =
754 LDAP_SERVER_REQUIRE_STRONG_AUTH_YES;
756 /* This is what we tell the afs client. in reality we set the token
757 * to never expire, though, when this runs out the afs client will
758 * forget the token. Set to 0 to get NEVERDATE.*/
759 Globals.afs_token_lifetime = 604800;
760 Globals.cups_connection_timeout = CUPS_DEFAULT_CONNECTION_TIMEOUT;
762 /* these parameters are set to defaults that are more appropriate
763 for the increasing samba install base:
765 as a member of the workgroup, that will possibly become a
766 _local_ master browser (lm = true). this is opposed to a forced
767 local master browser startup (pm = true).
769 doesn't provide WINS server service by default (wsupp = false),
770 and doesn't provide domain master browser services by default, either.
774 Globals.show_add_printer_wizard = true;
775 Globals.os_level = 20;
776 Globals.local_master = true;
777 Globals._domain_master = Auto; /* depending on _domain_logons */
778 Globals._domain_logons = false;
779 Globals.browse_list = true;
780 Globals.we_are_a_wins_server = false;
781 Globals.wins_proxy = false;
783 TALLOC_FREE(Globals.init_logon_delayed_hosts);
784 Globals.init_logon_delay = 100; /* 100 ms default delay */
786 Globals.wins_dns_proxy = true;
788 Globals.allow_trusted_domains = true;
789 lpcfg_string_set(Globals.ctx, &Globals.idmap_backend, "tdb");
791 lpcfg_string_set(Globals.ctx, &Globals.template_shell, "/bin/false");
792 lpcfg_string_set(Globals.ctx, &Globals.template_homedir,
793 "/home/%D/%U");
794 lpcfg_string_set(Globals.ctx, &Globals.winbind_separator, "\\");
795 lpcfg_string_set(Globals.ctx, &Globals.winbindd_socket_directory,
796 dyn_WINBINDD_SOCKET_DIR);
798 lpcfg_string_set(Globals.ctx, &Globals.cups_server, "");
799 lpcfg_string_set(Globals.ctx, &Globals.iprint_server, "");
801 lpcfg_string_set(Globals.ctx, &Globals._ctdbd_socket, "");
803 Globals.cluster_addresses = NULL;
804 Globals.clustering = false;
805 Globals.ctdb_timeout = 0;
806 Globals.ctdb_locktime_warn_threshold = 0;
808 Globals.winbind_cache_time = 300; /* 5 minutes */
809 Globals.winbind_reconnect_delay = 30; /* 30 seconds */
810 Globals.winbind_request_timeout = 60; /* 60 seconds */
811 Globals.winbind_max_clients = 200;
812 Globals.winbind_enum_users = false;
813 Globals.winbind_enum_groups = false;
814 Globals.winbind_use_default_domain = false;
815 Globals.winbind_trusted_domains_only = false;
816 Globals.winbind_nested_groups = true;
817 Globals.winbind_expand_groups = 0;
818 Globals.winbind_nss_info = str_list_make_v3_const(NULL, "template", NULL);
819 Globals.winbind_refresh_tickets = false;
820 Globals.winbind_offline_logon = false;
822 Globals.idmap_cache_time = 86400 * 7; /* a week by default */
823 Globals.idmap_negative_cache_time = 120; /* 2 minutes by default */
825 Globals.passdb_expand_explicit = false;
827 Globals.name_cache_timeout = 660; /* In seconds */
829 Globals.use_spnego = true;
830 Globals.client_use_spnego = true;
832 Globals.client_signing = SMB_SIGNING_DEFAULT;
833 Globals._client_ipc_signing = SMB_SIGNING_DEFAULT;
834 Globals.server_signing = SMB_SIGNING_DEFAULT;
836 Globals.defer_sharing_violations = true;
837 Globals.smb_ports = str_list_make_v3_const(NULL, SMB_PORTS, NULL);
839 Globals.enable_privileges = true;
840 Globals.host_msdfs = true;
841 Globals.enable_asu_support = false;
843 /* User defined shares. */
844 s = talloc_asprintf(talloc_tos(), "%s/usershares", get_dyn_STATEDIR());
845 if (s == NULL) {
846 smb_panic("init_globals: ENOMEM");
848 lpcfg_string_set(Globals.ctx, &Globals.usershare_path, s);
849 TALLOC_FREE(s);
850 lpcfg_string_set(Globals.ctx, &Globals.usershare_template_share, "");
851 Globals.usershare_max_shares = 0;
852 /* By default disallow sharing of directories not owned by the sharer. */
853 Globals.usershare_owner_only = true;
854 /* By default disallow guest access to usershares. */
855 Globals.usershare_allow_guests = false;
857 Globals.keepalive = DEFAULT_KEEPALIVE;
859 /* By default no shares out of the registry */
860 Globals.registry_shares = false;
862 Globals.min_receivefile_size = 0;
864 Globals.map_untrusted_to_domain = Auto;
865 Globals.multicast_dns_register = true;
867 Globals.smb2_max_read = DEFAULT_SMB2_MAX_READ;
868 Globals.smb2_max_write = DEFAULT_SMB2_MAX_WRITE;
869 Globals.smb2_max_trans = DEFAULT_SMB2_MAX_TRANSACT;
870 Globals.smb2_max_credits = DEFAULT_SMB2_MAX_CREDITS;
871 Globals.smb2_leases = true;
873 lpcfg_string_set(Globals.ctx, &Globals.ncalrpc_dir,
874 get_dyn_NCALRPCDIR());
876 Globals.server_services = str_list_make_v3_const(NULL, "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns", NULL);
878 Globals.dcerpc_endpoint_servers = str_list_make_v3_const(NULL, "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver", NULL);
880 Globals.tls_enabled = true;
881 Globals.tls_verify_peer = TLS_VERIFY_PEER_AS_STRICT_AS_POSSIBLE;
883 lpcfg_string_set(Globals.ctx, &Globals._tls_keyfile, "tls/key.pem");
884 lpcfg_string_set(Globals.ctx, &Globals._tls_certfile, "tls/cert.pem");
885 lpcfg_string_set(Globals.ctx, &Globals._tls_cafile, "tls/ca.pem");
886 lpcfg_string_set(Globals.ctx, &Globals.tls_priority,
887 "NORMAL:-VERS-SSL3.0");
889 lpcfg_string_set(Globals.ctx, &Globals.share_backend, "classic");
891 Globals._preferred_master = Auto;
893 Globals.allow_dns_updates = DNS_UPDATE_SIGNED;
895 lpcfg_string_set(Globals.ctx, &Globals.ntp_signd_socket_directory,
896 get_dyn_NTP_SIGND_SOCKET_DIR());
898 s = talloc_asprintf(talloc_tos(), "%s/samba_kcc", get_dyn_SCRIPTSBINDIR());
899 if (s == NULL) {
900 smb_panic("init_globals: ENOMEM");
902 Globals.samba_kcc_command = str_list_make_v3_const(NULL, s, NULL);
903 TALLOC_FREE(s);
905 #ifdef MIT_KDC_PATH
906 Globals.mit_kdc_command = str_list_make_v3_const(NULL, MIT_KDC_PATH, NULL);
907 #endif
909 s = talloc_asprintf(talloc_tos(), "%s/samba_dnsupdate", get_dyn_SCRIPTSBINDIR());
910 if (s == NULL) {
911 smb_panic("init_globals: ENOMEM");
913 Globals.dns_update_command = str_list_make_v3_const(NULL, s, NULL);
914 TALLOC_FREE(s);
916 s = talloc_asprintf(talloc_tos(), "%s/samba_gpoupdate", get_dyn_SCRIPTSBINDIR());
917 if (s == NULL) {
918 smb_panic("init_globals: ENOMEM");
920 Globals.gpo_update_command = str_list_make_v3_const(NULL, s, NULL);
921 TALLOC_FREE(s);
923 s = talloc_asprintf(talloc_tos(), "%s/samba_spnupdate", get_dyn_SCRIPTSBINDIR());
924 if (s == NULL) {
925 smb_panic("init_globals: ENOMEM");
927 Globals.spn_update_command = str_list_make_v3_const(NULL, s, NULL);
928 TALLOC_FREE(s);
930 Globals.nsupdate_command = str_list_make_v3_const(NULL, "/usr/bin/nsupdate -g", NULL);
932 Globals.rndc_command = str_list_make_v3_const(NULL, "/usr/sbin/rndc", NULL);
934 Globals.cldap_port = 389;
936 Globals.dgram_port = NBT_DGRAM_SERVICE_PORT;
938 Globals.nbt_port = NBT_NAME_SERVICE_PORT;
940 Globals.krb5_port = 88;
942 Globals.kpasswd_port = 464;
944 Globals.web_port = 901;
946 Globals.aio_max_threads = 100;
948 lpcfg_string_set(Globals.ctx,
949 &Globals.rpc_server_dynamic_port_range,
950 "49152-65535");
951 Globals.rpc_low_port = SERVER_TCP_LOW_PORT;
952 Globals.rpc_high_port = SERVER_TCP_HIGH_PORT;
953 Globals.prefork_children = 1;
955 /* Now put back the settings that were set with lp_set_cmdline() */
956 apply_lp_set_cmdline();
959 /* Convenience routine to setup an lp_context with additional s3 variables */
960 static struct loadparm_context *setup_lp_context(TALLOC_CTX *mem_ctx)
962 struct loadparm_context *lp_ctx;
964 lp_ctx = loadparm_init_s3(mem_ctx,
965 loadparm_s3_helpers());
966 if (lp_ctx == NULL) {
967 DEBUG(0, ("loadparm_init_s3 failed\n"));
968 return NULL;
971 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
972 if (lp_ctx->sDefault == NULL) {
973 DBG_ERR("talloc_zero failed\n");
974 TALLOC_FREE(lp_ctx);
975 return NULL;
978 *lp_ctx->sDefault = sDefault;
979 lp_ctx->services = NULL; /* We do not want to access this directly */
980 lp_ctx->bInGlobalSection = bInGlobalSection;
981 lp_ctx->flags = flags_list;
983 return lp_ctx;
986 /*******************************************************************
987 Convenience routine to grab string parameters into talloced memory
988 and run standard_sub_basic on them. The buffers can be written to by
989 callers without affecting the source string.
990 ********************************************************************/
992 char *lp_string(TALLOC_CTX *ctx, const char *s)
994 char *ret;
996 /* The follow debug is useful for tracking down memory problems
997 especially if you have an inner loop that is calling a lp_*()
998 function that returns a string. Perhaps this debug should be
999 present all the time? */
1001 #if 0
1002 DEBUG(10, ("lp_string(%s)\n", s));
1003 #endif
1004 if (!s) {
1005 return NULL;
1008 ret = talloc_sub_basic(ctx,
1009 get_current_username(),
1010 current_user_info.domain,
1012 if (trim_char(ret, '\"', '\"')) {
1013 if (strchr(ret,'\"') != NULL) {
1014 TALLOC_FREE(ret);
1015 ret = talloc_sub_basic(ctx,
1016 get_current_username(),
1017 current_user_info.domain,
1021 return ret;
1025 In this section all the functions that are used to access the
1026 parameters from the rest of the program are defined
1029 #define FN_GLOBAL_STRING(fn_name,ptr) \
1030 char *lp_ ## fn_name(TALLOC_CTX *ctx) {return(lp_string((ctx), *(char **)(&Globals.ptr) ? *(char **)(&Globals.ptr) : ""));}
1031 #define FN_GLOBAL_CONST_STRING(fn_name,ptr) \
1032 const char *lp_ ## fn_name(void) {return(*(const char * const *)(&Globals.ptr) ? *(const char * const *)(&Globals.ptr) : "");}
1033 #define FN_GLOBAL_LIST(fn_name,ptr) \
1034 const char **lp_ ## fn_name(void) {return(*(const char ***)(&Globals.ptr));}
1035 #define FN_GLOBAL_BOOL(fn_name,ptr) \
1036 bool lp_ ## fn_name(void) {return(*(bool *)(&Globals.ptr));}
1037 #define FN_GLOBAL_CHAR(fn_name,ptr) \
1038 char lp_ ## fn_name(void) {return(*(char *)(&Globals.ptr));}
1039 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
1040 int lp_ ## fn_name(void) {return(*(int *)(&Globals.ptr));}
1042 #define FN_LOCAL_STRING(fn_name,val) \
1043 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));}
1044 #define FN_LOCAL_CONST_STRING(fn_name,val) \
1045 const char *lp_ ## fn_name(int i) {return (const char *)((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val);}
1046 #define FN_LOCAL_LIST(fn_name,val) \
1047 const char **lp_ ## fn_name(int i) {return(const char **)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1048 #define FN_LOCAL_BOOL(fn_name,val) \
1049 bool lp_ ## fn_name(int i) {return(bool)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1050 #define FN_LOCAL_INTEGER(fn_name,val) \
1051 int lp_ ## fn_name(int i) {return(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
1053 #define FN_LOCAL_PARM_BOOL(fn_name,val) \
1054 bool lp_ ## fn_name(const struct share_params *p) {return(bool)(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1055 #define FN_LOCAL_PARM_INTEGER(fn_name,val) \
1056 int lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1057 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
1058 char lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
1060 int lp_winbind_max_domain_connections(void)
1062 if (lp_winbind_offline_logon() &&
1063 lp__winbind_max_domain_connections() > 1) {
1064 DEBUG(1, ("offline logons active, restricting max domain "
1065 "connections to 1\n"));
1066 return 1;
1068 return MAX(1, lp__winbind_max_domain_connections());
1071 /* These functions remain in source3/param for now */
1073 #include "lib/param/param_functions.c"
1075 FN_LOCAL_STRING(servicename, szService)
1076 FN_LOCAL_CONST_STRING(const_servicename, szService)
1078 /* These functions cannot be auto-generated */
1079 FN_LOCAL_BOOL(autoloaded, autoloaded)
1080 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
1082 /* local prototypes */
1084 static int map_parameter_canonical(const char *pszParmName, bool *inverse);
1085 static const char *get_boolean(bool bool_value);
1086 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1087 void *userdata);
1088 static bool hash_a_service(const char *name, int number);
1089 static void free_service_byindex(int iService);
1090 static void show_parameter(int parmIndex);
1091 static bool is_synonym_of(int parm1, int parm2, bool *inverse);
1092 static bool lp_parameter_value_is_valid(const char *parm_name, const char *val);
1095 * This is a helper function for parametrical options support. It returns a
1096 * pointer to parametrical option value if it exists or NULL otherwise. Actual
1097 * parametrical functions are quite simple
1099 static struct parmlist_entry *get_parametrics(int snum, const char *type,
1100 const char *option)
1102 if (snum >= iNumServices) return NULL;
1104 if (snum < 0) {
1105 return get_parametric_helper(NULL, type, option, Globals.param_opt);
1106 } else {
1107 return get_parametric_helper(ServicePtrs[snum],
1108 type, option, Globals.param_opt);
1112 static void discard_whitespace(char *str)
1114 size_t len = strlen(str);
1115 size_t i = 0;
1117 while (i < len) {
1118 if (isspace(str[i])) {
1119 memmove(&str[i], &str[i+1], len-i);
1120 len -= 1;
1121 continue;
1123 i += 1;
1128 * @brief Go through all global parametric parameters
1130 * @param regex_str A regular expression to scan param for
1131 * @param max_matches Max number of submatches the regexp expects
1132 * @param cb Function to call on match. Should return true
1133 * when it wants wi_scan_global_parametrics to stop
1134 * scanning
1135 * @param private_data Anonymous pointer passed to cb
1137 * @return 0: success, regcomp/regexec return value on error.
1138 * See "man regexec" for possible errors
1141 int lp_wi_scan_global_parametrics(
1142 const char *regex_str, size_t max_matches,
1143 bool (*cb)(const char *string, regmatch_t matches[],
1144 void *private_data),
1145 void *private_data)
1147 struct parmlist_entry *data;
1148 regex_t regex;
1149 int ret;
1151 ret = regcomp(&regex, regex_str, REG_ICASE);
1152 if (ret != 0) {
1153 return ret;
1156 for (data = Globals.param_opt; data != NULL; data = data->next) {
1157 size_t keylen = strlen(data->key);
1158 char key[keylen+1];
1159 regmatch_t matches[max_matches];
1160 bool stop;
1162 memcpy(key, data->key, sizeof(key));
1163 discard_whitespace(key);
1165 ret = regexec(&regex, key, max_matches, matches, 0);
1166 if (ret == REG_NOMATCH) {
1167 continue;
1169 if (ret != 0) {
1170 goto fail;
1173 stop = cb(key, matches, private_data);
1174 if (stop) {
1175 break;
1179 ret = 0;
1180 fail:
1181 regfree(&regex);
1182 return ret;
1186 #define MISSING_PARAMETER(name) \
1187 DEBUG(0, ("%s(): value is NULL or empty!\n", #name))
1189 /*******************************************************************
1190 convenience routine to return enum parameters.
1191 ********************************************************************/
1192 static int lp_enum(const char *s,const struct enum_list *_enum)
1194 int i;
1196 if (!s || !*s || !_enum) {
1197 MISSING_PARAMETER(lp_enum);
1198 return (-1);
1201 for (i=0; _enum[i].name; i++) {
1202 if (strequal(_enum[i].name,s))
1203 return _enum[i].value;
1206 DEBUG(0,("lp_enum(%s,enum): value is not in enum_list!\n",s));
1207 return (-1);
1210 #undef MISSING_PARAMETER
1212 /* Return parametric option from a given service. Type is a part of option before ':' */
1213 /* Parametric option has following syntax: 'Type: option = value' */
1214 char *lp_parm_talloc_string(TALLOC_CTX *ctx, int snum, const char *type, const char *option, const char *def)
1216 struct parmlist_entry *data = get_parametrics(snum, type, option);
1218 if (data == NULL||data->value==NULL) {
1219 if (def) {
1220 return lp_string(ctx, def);
1221 } else {
1222 return NULL;
1226 return lp_string(ctx, data->value);
1229 /* Return parametric option from a given service. Type is a part of option before ':' */
1230 /* Parametric option has following syntax: 'Type: option = value' */
1231 const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def)
1233 struct parmlist_entry *data = get_parametrics(snum, type, option);
1235 if (data == NULL||data->value==NULL)
1236 return def;
1238 return data->value;
1242 /* Return parametric option from a given service. Type is a part of option before ':' */
1243 /* Parametric option has following syntax: 'Type: option = value' */
1245 const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def)
1247 struct parmlist_entry *data = get_parametrics(snum, type, option);
1249 if (data == NULL||data->value==NULL)
1250 return (const char **)def;
1252 if (data->list==NULL) {
1253 data->list = str_list_make_v3(NULL, data->value, NULL);
1256 return discard_const_p(const char *, data->list);
1259 /* Return parametric option from a given service. Type is a part of option before ':' */
1260 /* Parametric option has following syntax: 'Type: option = value' */
1262 int lp_parm_int(int snum, const char *type, const char *option, int def)
1264 struct parmlist_entry *data = get_parametrics(snum, type, option);
1266 if (data && data->value && *data->value)
1267 return lp_int(data->value);
1269 return def;
1272 /* Return parametric option from a given service. Type is a part of option before ':' */
1273 /* Parametric option has following syntax: 'Type: option = value' */
1275 unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsigned long def)
1277 struct parmlist_entry *data = get_parametrics(snum, type, option);
1279 if (data && data->value && *data->value)
1280 return lp_ulong(data->value);
1282 return def;
1285 /* Return parametric option from a given service. Type is a part of option before ':' */
1286 /* Parametric option has following syntax: 'Type: option = value' */
1288 unsigned long long lp_parm_ulonglong(int snum, const char *type,
1289 const char *option, unsigned long long def)
1291 struct parmlist_entry *data = get_parametrics(snum, type, option);
1293 if (data && data->value && *data->value) {
1294 return lp_ulonglong(data->value);
1297 return def;
1300 /* Return parametric option from a given service. Type is a part of option
1301 * before ':' */
1302 /* Parametric option has following syntax: 'Type: option = value' */
1304 bool lp_parm_bool(int snum, const char *type, const char *option, bool def)
1306 struct parmlist_entry *data = get_parametrics(snum, type, option);
1308 if (data && data->value && *data->value)
1309 return lp_bool(data->value);
1311 return def;
1314 /* Return parametric option from a given service. Type is a part of option before ':' */
1315 /* Parametric option has following syntax: 'Type: option = value' */
1317 int lp_parm_enum(int snum, const char *type, const char *option,
1318 const struct enum_list *_enum, int def)
1320 struct parmlist_entry *data = get_parametrics(snum, type, option);
1322 if (data && data->value && *data->value && _enum)
1323 return lp_enum(data->value, _enum);
1325 return def;
1329 * free a param_opts structure.
1330 * param_opts handling should be moved to talloc;
1331 * then this whole functions reduces to a TALLOC_FREE().
1334 static void free_param_opts(struct parmlist_entry **popts)
1336 struct parmlist_entry *opt, *next_opt;
1338 if (*popts != NULL) {
1339 DEBUG(5, ("Freeing parametrics:\n"));
1341 opt = *popts;
1342 while (opt != NULL) {
1343 lpcfg_string_free(&opt->key);
1344 lpcfg_string_free(&opt->value);
1345 TALLOC_FREE(opt->list);
1346 next_opt = opt->next;
1347 TALLOC_FREE(opt);
1348 opt = next_opt;
1350 *popts = NULL;
1353 /***************************************************************************
1354 Free the dynamically allocated parts of a service struct.
1355 ***************************************************************************/
1357 static void free_service(struct loadparm_service *pservice)
1359 if (!pservice)
1360 return;
1362 if (pservice->szService)
1363 DEBUG(5, ("free_service: Freeing service %s\n",
1364 pservice->szService));
1366 free_parameters(pservice);
1368 lpcfg_string_free(&pservice->szService);
1369 TALLOC_FREE(pservice->copymap);
1371 free_param_opts(&pservice->param_opt);
1373 ZERO_STRUCTP(pservice);
1377 /***************************************************************************
1378 remove a service indexed in the ServicePtrs array from the ServiceHash
1379 and free the dynamically allocated parts
1380 ***************************************************************************/
1382 static void free_service_byindex(int idx)
1384 if ( !LP_SNUM_OK(idx) )
1385 return;
1387 ServicePtrs[idx]->valid = false;
1389 /* we have to cleanup the hash record */
1391 if (ServicePtrs[idx]->szService) {
1392 char *canon_name = canonicalize_servicename(
1393 talloc_tos(),
1394 ServicePtrs[idx]->szService );
1396 dbwrap_delete_bystring(ServiceHash, canon_name );
1397 TALLOC_FREE(canon_name);
1400 free_service(ServicePtrs[idx]);
1401 TALLOC_FREE(ServicePtrs[idx]);
1404 /***************************************************************************
1405 Add a new service to the services array initialising it with the given
1406 service.
1407 ***************************************************************************/
1409 static int add_a_service(const struct loadparm_service *pservice, const char *name)
1411 int i;
1412 struct loadparm_service **tsp = NULL;
1414 /* it might already exist */
1415 if (name) {
1416 i = getservicebyname(name, NULL);
1417 if (i >= 0) {
1418 return (i);
1422 /* Re use empty slots if any before allocating new one.*/
1423 for (i=0; i < iNumServices; i++) {
1424 if (ServicePtrs[i] == NULL) {
1425 break;
1428 if (i == iNumServices) {
1429 /* if not, then create one */
1430 tsp = talloc_realloc(NULL, ServicePtrs,
1431 struct loadparm_service *,
1432 iNumServices + 1);
1433 if (tsp == NULL) {
1434 DEBUG(0, ("add_a_service: failed to enlarge "
1435 "ServicePtrs!\n"));
1436 return (-1);
1438 ServicePtrs = tsp;
1439 iNumServices++;
1441 ServicePtrs[i] = talloc_zero(ServicePtrs, struct loadparm_service);
1442 if (!ServicePtrs[i]) {
1443 DEBUG(0,("add_a_service: out of memory!\n"));
1444 return (-1);
1447 ServicePtrs[i]->valid = true;
1449 copy_service(ServicePtrs[i], pservice, NULL);
1450 if (name)
1451 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->szService,
1452 name);
1454 DEBUG(8,("add_a_service: Creating snum = %d for %s\n",
1455 i, ServicePtrs[i]->szService));
1457 if (!hash_a_service(ServicePtrs[i]->szService, i)) {
1458 return (-1);
1461 return (i);
1464 /***************************************************************************
1465 Convert a string to uppercase and remove whitespaces.
1466 ***************************************************************************/
1468 char *canonicalize_servicename(TALLOC_CTX *ctx, const char *src)
1470 char *result;
1472 if ( !src ) {
1473 DEBUG(0,("canonicalize_servicename: NULL source name!\n"));
1474 return NULL;
1477 result = talloc_strdup(ctx, src);
1478 SMB_ASSERT(result != NULL);
1480 if (!strlower_m(result)) {
1481 TALLOC_FREE(result);
1482 return NULL;
1484 return result;
1487 /***************************************************************************
1488 Add a name/index pair for the services array to the hash table.
1489 ***************************************************************************/
1491 static bool hash_a_service(const char *name, int idx)
1493 char *canon_name;
1495 if ( !ServiceHash ) {
1496 DEBUG(10,("hash_a_service: creating servicehash\n"));
1497 ServiceHash = db_open_rbt(NULL);
1498 if ( !ServiceHash ) {
1499 DEBUG(0,("hash_a_service: open tdb servicehash failed!\n"));
1500 return false;
1504 DEBUG(10,("hash_a_service: hashing index %d for service name %s\n",
1505 idx, name));
1507 canon_name = canonicalize_servicename(talloc_tos(), name );
1509 dbwrap_store_bystring(ServiceHash, canon_name,
1510 make_tdb_data((uint8_t *)&idx, sizeof(idx)),
1511 TDB_REPLACE);
1513 TALLOC_FREE(canon_name);
1515 return true;
1518 /***************************************************************************
1519 Add a new home service, with the specified home directory, defaults coming
1520 from service ifrom.
1521 ***************************************************************************/
1523 bool lp_add_home(const char *pszHomename, int iDefaultService,
1524 const char *user, const char *pszHomedir)
1526 int i;
1528 if (pszHomename == NULL || user == NULL || pszHomedir == NULL ||
1529 pszHomedir[0] == '\0') {
1530 return false;
1533 i = add_a_service(ServicePtrs[iDefaultService], pszHomename);
1535 if (i < 0)
1536 return false;
1538 if (!(*(ServicePtrs[iDefaultService]->path))
1539 || strequal(ServicePtrs[iDefaultService]->path,
1540 lp_path(talloc_tos(), GLOBAL_SECTION_SNUM))) {
1541 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->path,
1542 pszHomedir);
1545 if (!(*(ServicePtrs[i]->comment))) {
1546 char *comment = talloc_asprintf(talloc_tos(), "Home directory of %s", user);
1547 if (comment == NULL) {
1548 return false;
1550 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->comment,
1551 comment);
1552 TALLOC_FREE(comment);
1555 /* set the browseable flag from the global default */
1557 ServicePtrs[i]->browseable = sDefault.browseable;
1558 ServicePtrs[i]->access_based_share_enum = sDefault.access_based_share_enum;
1560 ServicePtrs[i]->autoloaded = true;
1562 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename,
1563 user, ServicePtrs[i]->path ));
1565 return true;
1568 /***************************************************************************
1569 Add a new service, based on an old one.
1570 ***************************************************************************/
1572 int lp_add_service(const char *pszService, int iDefaultService)
1574 if (iDefaultService < 0) {
1575 return add_a_service(&sDefault, pszService);
1578 return (add_a_service(ServicePtrs[iDefaultService], pszService));
1581 /***************************************************************************
1582 Add the IPC service.
1583 ***************************************************************************/
1585 static bool lp_add_ipc(const char *ipc_name, bool guest_ok)
1587 char *comment = NULL;
1588 int i = add_a_service(&sDefault, ipc_name);
1590 if (i < 0)
1591 return false;
1593 comment = talloc_asprintf(talloc_tos(), "IPC Service (%s)",
1594 Globals.server_string);
1595 if (comment == NULL) {
1596 return false;
1599 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->path, tmpdir());
1600 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->comment, comment);
1601 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->fstype, "IPC");
1602 ServicePtrs[i]->max_connections = 0;
1603 ServicePtrs[i]->available = true;
1604 ServicePtrs[i]->read_only = true;
1605 ServicePtrs[i]->guest_only = false;
1606 ServicePtrs[i]->administrative_share = true;
1607 ServicePtrs[i]->guest_ok = guest_ok;
1608 ServicePtrs[i]->printable = false;
1609 ServicePtrs[i]->browseable = sDefault.browseable;
1610 ServicePtrs[i]->autoloaded = true;
1612 DEBUG(3, ("adding IPC service\n"));
1614 TALLOC_FREE(comment);
1615 return true;
1618 /***************************************************************************
1619 Add a new printer service, with defaults coming from service iFrom.
1620 ***************************************************************************/
1622 bool lp_add_printer(const char *pszPrintername, int iDefaultService)
1624 const char *comment = "From Printcap";
1625 int i = add_a_service(ServicePtrs[iDefaultService], pszPrintername);
1627 if (i < 0)
1628 return false;
1630 /* note that we do NOT default the availability flag to true - */
1631 /* we take it from the default service passed. This allows all */
1632 /* dynamic printers to be disabled by disabling the [printers] */
1633 /* entry (if/when the 'available' keyword is implemented!). */
1635 /* the printer name is set to the service name. */
1636 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->_printername,
1637 pszPrintername);
1638 lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->comment, comment);
1640 /* set the browseable flag from the gloabl default */
1641 ServicePtrs[i]->browseable = sDefault.browseable;
1643 /* Printers cannot be read_only. */
1644 ServicePtrs[i]->read_only = false;
1645 /* No oplocks on printer services. */
1646 ServicePtrs[i]->oplocks = false;
1647 /* Printer services must be printable. */
1648 ServicePtrs[i]->printable = true;
1650 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1652 return true;
1656 /***************************************************************************
1657 Check whether the given parameter name is valid.
1658 Parametric options (names containing a colon) are considered valid.
1659 ***************************************************************************/
1661 bool lp_parameter_is_valid(const char *pszParmName)
1663 return ((lpcfg_map_parameter(pszParmName) != -1) ||
1664 (strchr(pszParmName, ':') != NULL));
1667 /***************************************************************************
1668 Check whether the given name is the name of a global parameter.
1669 Returns true for strings belonging to parameters of class
1670 P_GLOBAL, false for all other strings, also for parametric options
1671 and strings not belonging to any option.
1672 ***************************************************************************/
1674 bool lp_parameter_is_global(const char *pszParmName)
1676 int num = lpcfg_map_parameter(pszParmName);
1678 if (num >= 0) {
1679 return (parm_table[num].p_class == P_GLOBAL);
1682 return false;
1685 /**************************************************************************
1686 Determine the canonical name for a parameter.
1687 Indicate when it is an inverse (boolean) synonym instead of a
1688 "usual" synonym.
1689 **************************************************************************/
1691 bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
1692 bool *inverse)
1694 int num;
1696 if (!lp_parameter_is_valid(parm_name)) {
1697 *canon_parm = NULL;
1698 return false;
1701 num = map_parameter_canonical(parm_name, inverse);
1702 if (num < 0) {
1703 /* parametric option */
1704 *canon_parm = parm_name;
1705 } else {
1706 *canon_parm = parm_table[num].label;
1709 return true;
1713 /**************************************************************************
1714 Determine the canonical name for a parameter.
1715 Turn the value given into the inverse boolean expression when
1716 the synonym is an invers boolean synonym.
1718 Return true if
1719 - parm_name is a valid parameter name and
1720 - val is a valid value for this parameter and
1721 - in case the parameter is an inverse boolean synonym, if the val
1722 string could successfully be converted to the reverse bool.
1723 Return false in all other cases.
1724 **************************************************************************/
1726 bool lp_canonicalize_parameter_with_value(const char *parm_name,
1727 const char *val,
1728 const char **canon_parm,
1729 const char **canon_val)
1731 int num;
1732 bool inverse;
1733 bool ret;
1735 if (!lp_parameter_is_valid(parm_name)) {
1736 *canon_parm = NULL;
1737 *canon_val = NULL;
1738 return false;
1741 num = map_parameter_canonical(parm_name, &inverse);
1742 if (num < 0) {
1743 /* parametric option */
1744 *canon_parm = parm_name;
1745 *canon_val = val;
1746 return true;
1749 *canon_parm = parm_table[num].label;
1750 if (inverse) {
1751 if (!lp_invert_boolean(val, canon_val)) {
1752 *canon_val = NULL;
1753 return false;
1755 } else {
1756 *canon_val = val;
1759 ret = lp_parameter_value_is_valid(*canon_parm, *canon_val);
1761 return ret;
1764 /***************************************************************************
1765 Map a parameter's string representation to the index of the canonical
1766 form of the parameter (it might be a synonym).
1767 Returns -1 if the parameter string is not recognised.
1768 ***************************************************************************/
1770 static int map_parameter_canonical(const char *pszParmName, bool *inverse)
1772 int parm_num, canon_num;
1773 bool loc_inverse = false;
1775 parm_num = lpcfg_map_parameter(pszParmName);
1776 if ((parm_num < 0) || !(parm_table[parm_num].flags & FLAG_SYNONYM)) {
1777 /* invalid, parametric or no canidate for synonyms ... */
1778 goto done;
1781 for (canon_num = 0; parm_table[canon_num].label; canon_num++) {
1782 if (is_synonym_of(parm_num, canon_num, &loc_inverse)) {
1783 parm_num = canon_num;
1784 goto done;
1788 done:
1789 if (inverse != NULL) {
1790 *inverse = loc_inverse;
1792 return parm_num;
1795 /***************************************************************************
1796 return true if parameter number parm1 is a synonym of parameter
1797 number parm2 (parm2 being the principal name).
1798 set inverse to true if parm1 is P_BOOLREV and parm2 is P_BOOL,
1799 false otherwise.
1800 ***************************************************************************/
1802 static bool is_synonym_of(int parm1, int parm2, bool *inverse)
1804 if ((parm_table[parm1].offset == parm_table[parm2].offset) &&
1805 (parm_table[parm1].p_class == parm_table[parm2].p_class) &&
1806 (parm_table[parm1].flags & FLAG_SYNONYM) &&
1807 !(parm_table[parm2].flags & FLAG_SYNONYM))
1809 if (inverse != NULL) {
1810 if ((parm_table[parm1].type == P_BOOLREV) &&
1811 (parm_table[parm2].type == P_BOOL))
1813 *inverse = true;
1814 } else {
1815 *inverse = false;
1818 return true;
1820 return false;
1823 /***************************************************************************
1824 Show one parameter's name, type, [values,] and flags.
1825 (helper functions for show_parameter_list)
1826 ***************************************************************************/
1828 static void show_parameter(int parmIndex)
1830 int enumIndex, flagIndex;
1831 int parmIndex2;
1832 bool hadFlag;
1833 bool hadSyn;
1834 bool inverse;
1835 const char *type[] = { "P_BOOL", "P_BOOLREV", "P_CHAR", "P_INTEGER",
1836 "P_OCTAL", "P_LIST", "P_STRING", "P_USTRING",
1837 "P_ENUM", "P_BYTES", "P_CMDLIST" };
1838 unsigned flags[] = { FLAG_DEPRECATED, FLAG_SYNONYM };
1839 const char *flag_names[] = { "FLAG_DEPRECATED", "FLAG_SYNONYM", NULL};
1841 printf("%s=%s", parm_table[parmIndex].label,
1842 type[parm_table[parmIndex].type]);
1843 if (parm_table[parmIndex].type == P_ENUM) {
1844 printf(",");
1845 for (enumIndex=0;
1846 parm_table[parmIndex].enum_list[enumIndex].name;
1847 enumIndex++)
1849 printf("%s%s",
1850 enumIndex ? "|" : "",
1851 parm_table[parmIndex].enum_list[enumIndex].name);
1854 printf(",");
1855 hadFlag = false;
1856 for (flagIndex=0; flag_names[flagIndex]; flagIndex++) {
1857 if (parm_table[parmIndex].flags & flags[flagIndex]) {
1858 printf("%s%s",
1859 hadFlag ? "|" : "",
1860 flag_names[flagIndex]);
1861 hadFlag = true;
1865 /* output synonyms */
1866 hadSyn = false;
1867 for (parmIndex2=0; parm_table[parmIndex2].label; parmIndex2++) {
1868 if (is_synonym_of(parmIndex, parmIndex2, &inverse)) {
1869 printf(" (%ssynonym of %s)", inverse ? "inverse " : "",
1870 parm_table[parmIndex2].label);
1871 } else if (is_synonym_of(parmIndex2, parmIndex, &inverse)) {
1872 if (!hadSyn) {
1873 printf(" (synonyms: ");
1874 hadSyn = true;
1875 } else {
1876 printf(", ");
1878 printf("%s%s", parm_table[parmIndex2].label,
1879 inverse ? "[i]" : "");
1882 if (hadSyn) {
1883 printf(")");
1886 printf("\n");
1890 * Check the value for a P_ENUM
1892 static bool check_enum_parameter(struct parm_struct *parm, const char *value)
1894 int i;
1896 for (i = 0; parm->enum_list[i].name; i++) {
1897 if (strwicmp(value, parm->enum_list[i].name) == 0) {
1898 return true;
1901 return false;
1904 /**************************************************************************
1905 Check whether the given value is valid for the given parameter name.
1906 **************************************************************************/
1908 static bool lp_parameter_value_is_valid(const char *parm_name, const char *val)
1910 bool ret = false, tmp_bool;
1911 int num = lpcfg_map_parameter(parm_name), tmp_int;
1912 uint64_t tmp_int64 = 0;
1913 struct parm_struct *parm;
1915 /* parametric options (parameter names containing a colon) cannot
1916 be checked and are therefore considered valid. */
1917 if (strchr(parm_name, ':') != NULL) {
1918 return true;
1921 if (num >= 0) {
1922 parm = &parm_table[num];
1923 switch (parm->type) {
1924 case P_BOOL:
1925 case P_BOOLREV:
1926 ret = set_boolean(val, &tmp_bool);
1927 break;
1929 case P_INTEGER:
1930 ret = (sscanf(val, "%d", &tmp_int) == 1);
1931 break;
1933 case P_OCTAL:
1934 ret = (sscanf(val, "%o", &tmp_int) == 1);
1935 break;
1937 case P_ENUM:
1938 ret = check_enum_parameter(parm, val);
1939 break;
1941 case P_BYTES:
1942 if (conv_str_size_error(val, &tmp_int64) &&
1943 tmp_int64 <= INT_MAX) {
1944 ret = true;
1946 break;
1948 case P_CHAR:
1949 case P_LIST:
1950 case P_STRING:
1951 case P_USTRING:
1952 case P_CMDLIST:
1953 ret = true;
1954 break;
1957 return ret;
1960 /***************************************************************************
1961 Show all parameter's name, type, [values,] and flags.
1962 ***************************************************************************/
1964 void show_parameter_list(void)
1966 int classIndex, parmIndex;
1967 const char *section_names[] = { "local", "global", NULL};
1969 for (classIndex=0; section_names[classIndex]; classIndex++) {
1970 printf("[%s]\n", section_names[classIndex]);
1971 for (parmIndex = 0; parm_table[parmIndex].label; parmIndex++) {
1972 if (parm_table[parmIndex].p_class == classIndex) {
1973 show_parameter(parmIndex);
1979 /***************************************************************************
1980 Get the standard string representation of a boolean value ("yes" or "no")
1981 ***************************************************************************/
1983 static const char *get_boolean(bool bool_value)
1985 static const char *yes_str = "yes";
1986 static const char *no_str = "no";
1988 return (bool_value ? yes_str : no_str);
1991 /***************************************************************************
1992 Provide the string of the negated boolean value associated to the boolean
1993 given as a string. Returns false if the passed string does not correctly
1994 represent a boolean.
1995 ***************************************************************************/
1997 bool lp_invert_boolean(const char *str, const char **inverse_str)
1999 bool val;
2001 if (!set_boolean(str, &val)) {
2002 return false;
2005 *inverse_str = get_boolean(!val);
2006 return true;
2009 /***************************************************************************
2010 Provide the canonical string representation of a boolean value given
2011 as a string. Return true on success, false if the string given does
2012 not correctly represent a boolean.
2013 ***************************************************************************/
2015 bool lp_canonicalize_boolean(const char *str, const char**canon_str)
2017 bool val;
2019 if (!set_boolean(str, &val)) {
2020 return false;
2023 *canon_str = get_boolean(val);
2024 return true;
2027 /***************************************************************************
2028 Find a service by name. Otherwise works like get_service.
2029 ***************************************************************************/
2031 int getservicebyname(const char *pszServiceName, struct loadparm_service *pserviceDest)
2033 int iService = -1;
2034 char *canon_name;
2035 TDB_DATA data;
2036 NTSTATUS status;
2038 if (ServiceHash == NULL) {
2039 return -1;
2042 canon_name = canonicalize_servicename(talloc_tos(), pszServiceName);
2044 status = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name,
2045 &data);
2047 if (NT_STATUS_IS_OK(status) &&
2048 (data.dptr != NULL) &&
2049 (data.dsize == sizeof(iService)))
2051 memcpy(&iService, data.dptr, sizeof(iService));
2054 TALLOC_FREE(canon_name);
2056 if ((iService != -1) && (LP_SNUM_OK(iService))
2057 && (pserviceDest != NULL)) {
2058 copy_service(pserviceDest, ServicePtrs[iService], NULL);
2061 return (iService);
2064 /* Return a pointer to a service by name. Unlike getservicebyname, it does not copy the service */
2065 struct loadparm_service *lp_service(const char *pszServiceName)
2067 int iService = getservicebyname(pszServiceName, NULL);
2068 if (iService == -1 || !LP_SNUM_OK(iService)) {
2069 return NULL;
2071 return ServicePtrs[iService];
2074 struct loadparm_service *lp_servicebynum(int snum)
2076 if ((snum == -1) || !LP_SNUM_OK(snum)) {
2077 return NULL;
2079 return ServicePtrs[snum];
2082 struct loadparm_service *lp_default_loadparm_service()
2084 return &sDefault;
2087 static struct smbconf_ctx *lp_smbconf_ctx(void)
2089 sbcErr err;
2090 static struct smbconf_ctx *conf_ctx = NULL;
2092 if (conf_ctx == NULL) {
2093 err = smbconf_init(NULL, &conf_ctx, "registry:");
2094 if (!SBC_ERROR_IS_OK(err)) {
2095 DEBUG(1, ("error initializing registry configuration: "
2096 "%s\n", sbcErrorString(err)));
2097 conf_ctx = NULL;
2101 return conf_ctx;
2104 static bool process_smbconf_service(struct smbconf_service *service)
2106 uint32_t count;
2107 bool ret;
2109 if (service == NULL) {
2110 return false;
2113 ret = lp_do_section(service->name, NULL);
2114 if (ret != true) {
2115 return false;
2117 for (count = 0; count < service->num_params; count++) {
2119 if (!bInGlobalSection && bGlobalOnly) {
2120 ret = true;
2121 } else {
2122 const char *pszParmName = service->param_names[count];
2123 const char *pszParmValue = service->param_values[count];
2125 DEBUGADD(4, ("doing parameter %s = %s\n", pszParmName, pszParmValue));
2127 ret = lp_do_parameter(bInGlobalSection ? -2 : iServiceIndex,
2128 pszParmName, pszParmValue);
2131 if (ret != true) {
2132 return false;
2135 if (iServiceIndex >= 0) {
2136 return lpcfg_service_ok(ServicePtrs[iServiceIndex]);
2138 return true;
2142 * load a service from registry and activate it
2144 bool process_registry_service(const char *service_name)
2146 sbcErr err;
2147 struct smbconf_service *service = NULL;
2148 TALLOC_CTX *mem_ctx = talloc_stackframe();
2149 struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
2150 bool ret = false;
2152 if (conf_ctx == NULL) {
2153 goto done;
2156 DEBUG(5, ("process_registry_service: service name %s\n", service_name));
2158 if (!smbconf_share_exists(conf_ctx, service_name)) {
2160 * Registry does not contain data for this service (yet),
2161 * but make sure lp_load doesn't return false.
2163 ret = true;
2164 goto done;
2167 err = smbconf_get_share(conf_ctx, mem_ctx, service_name, &service);
2168 if (!SBC_ERROR_IS_OK(err)) {
2169 goto done;
2172 ret = process_smbconf_service(service);
2173 if (!ret) {
2174 goto done;
2177 /* store the csn */
2178 smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL);
2180 done:
2181 TALLOC_FREE(mem_ctx);
2182 return ret;
2186 * process_registry_globals
2188 static bool process_registry_globals(void)
2190 bool ret;
2192 add_to_file_list(NULL, &file_lists, INCLUDE_REGISTRY_NAME, INCLUDE_REGISTRY_NAME);
2194 if (!bInGlobalSection && bGlobalOnly) {
2195 ret = true;
2196 } else {
2197 const char *pszParmName = "registry shares";
2198 const char *pszParmValue = "yes";
2200 DEBUGADD(4, ("doing parameter %s = %s\n", pszParmName, pszParmValue));
2202 ret = lp_do_parameter(bInGlobalSection ? -2 : iServiceIndex,
2203 pszParmName, pszParmValue);
2206 if (!ret) {
2207 return ret;
2210 return process_registry_service(GLOBAL_NAME);
2213 bool process_registry_shares(void)
2215 sbcErr err;
2216 uint32_t count;
2217 struct smbconf_service **service = NULL;
2218 uint32_t num_shares = 0;
2219 TALLOC_CTX *mem_ctx = talloc_stackframe();
2220 struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
2221 bool ret = false;
2223 if (conf_ctx == NULL) {
2224 goto done;
2227 err = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &service);
2228 if (!SBC_ERROR_IS_OK(err)) {
2229 goto done;
2232 ret = true;
2234 for (count = 0; count < num_shares; count++) {
2235 if (strequal(service[count]->name, GLOBAL_NAME)) {
2236 continue;
2238 ret = process_smbconf_service(service[count]);
2239 if (!ret) {
2240 goto done;
2244 /* store the csn */
2245 smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL);
2247 done:
2248 TALLOC_FREE(mem_ctx);
2249 return ret;
2253 * reload those shares from registry that are already
2254 * activated in the services array.
2256 static bool reload_registry_shares(void)
2258 int i;
2259 bool ret = true;
2261 for (i = 0; i < iNumServices; i++) {
2262 if (!VALID(i)) {
2263 continue;
2266 if (ServicePtrs[i]->usershare == USERSHARE_VALID) {
2267 continue;
2270 ret = process_registry_service(ServicePtrs[i]->szService);
2271 if (!ret) {
2272 goto done;
2276 done:
2277 return ret;
2281 #define MAX_INCLUDE_DEPTH 100
2283 static uint8_t include_depth;
2286 * Free the file lists
2288 static void free_file_list(void)
2290 struct file_lists *f;
2291 struct file_lists *next;
2293 f = file_lists;
2294 while( f ) {
2295 next = f->next;
2296 TALLOC_FREE( f );
2297 f = next;
2299 file_lists = NULL;
2304 * Utility function for outsiders to check if we're running on registry.
2306 bool lp_config_backend_is_registry(void)
2308 return (lp_config_backend() == CONFIG_BACKEND_REGISTRY);
2312 * Utility function to check if the config backend is FILE.
2314 bool lp_config_backend_is_file(void)
2316 return (lp_config_backend() == CONFIG_BACKEND_FILE);
2319 /*******************************************************************
2320 Check if a config file has changed date.
2321 ********************************************************************/
2323 bool lp_file_list_changed(void)
2325 struct file_lists *f = file_lists;
2327 DEBUG(6, ("lp_file_list_changed()\n"));
2329 while (f) {
2330 if (strequal(f->name, INCLUDE_REGISTRY_NAME)) {
2331 struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
2333 if (conf_ctx == NULL) {
2334 return false;
2336 if (smbconf_changed(conf_ctx, &conf_last_csn, NULL,
2337 NULL))
2339 DEBUGADD(6, ("registry config changed\n"));
2340 return true;
2342 } else {
2343 time_t mod_time;
2344 char *n2 = NULL;
2346 n2 = talloc_sub_basic(talloc_tos(),
2347 get_current_username(),
2348 current_user_info.domain,
2349 f->name);
2350 if (!n2) {
2351 return false;
2353 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2354 f->name, n2, ctime(&f->modtime)));
2356 mod_time = file_modtime(n2);
2358 if (mod_time &&
2359 ((f->modtime != mod_time) ||
2360 (f->subfname == NULL) ||
2361 (strcmp(n2, f->subfname) != 0)))
2363 DEBUGADD(6,
2364 ("file %s modified: %s\n", n2,
2365 ctime(&mod_time)));
2366 f->modtime = mod_time;
2367 TALLOC_FREE(f->subfname);
2368 f->subfname = talloc_strdup(f, n2);
2369 if (f->subfname == NULL) {
2370 smb_panic("talloc_strdup failed");
2372 TALLOC_FREE(n2);
2373 return true;
2375 TALLOC_FREE(n2);
2377 f = f->next;
2379 return false;
2384 * Initialize iconv conversion descriptors.
2386 * This is called the first time it is needed, and also called again
2387 * every time the configuration is reloaded, because the charset or
2388 * codepage might have changed.
2390 static void init_iconv(void)
2392 struct smb_iconv_handle *ret = NULL;
2394 ret = reinit_iconv_handle(NULL,
2395 lp_dos_charset(),
2396 lp_unix_charset());
2397 if (ret == NULL) {
2398 smb_panic("reinit_iconv_handle failed");
2402 /***************************************************************************
2403 Handle the include operation.
2404 ***************************************************************************/
2405 static bool bAllowIncludeRegistry = true;
2407 bool lp_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
2408 const char *pszParmValue, char **ptr)
2410 char *fname;
2412 if (include_depth >= MAX_INCLUDE_DEPTH) {
2413 DEBUG(0, ("Error: Maximum include depth (%u) exceeded!\n",
2414 include_depth));
2415 return false;
2418 if (strequal(pszParmValue, INCLUDE_REGISTRY_NAME)) {
2419 if (!bAllowIncludeRegistry) {
2420 return true;
2422 if (lp_ctx->bInGlobalSection) {
2423 bool ret;
2424 include_depth++;
2425 ret = process_registry_globals();
2426 include_depth--;
2427 return ret;
2428 } else {
2429 DEBUG(1, ("\"include = registry\" only effective "
2430 "in %s section\n", GLOBAL_NAME));
2431 return false;
2435 fname = talloc_sub_basic(talloc_tos(), get_current_username(),
2436 current_user_info.domain,
2437 pszParmValue);
2439 add_to_file_list(NULL, &file_lists, pszParmValue, fname);
2441 if (service == NULL) {
2442 lpcfg_string_set(Globals.ctx, ptr, fname);
2443 } else {
2444 lpcfg_string_set(service, ptr, fname);
2447 if (file_exist(fname)) {
2448 bool ret;
2449 include_depth++;
2450 ret = pm_process(fname, lp_do_section, do_parameter, lp_ctx);
2451 include_depth--;
2452 TALLOC_FREE(fname);
2453 return ret;
2456 DEBUG(2, ("Can't find include file %s\n", fname));
2457 TALLOC_FREE(fname);
2458 return true;
2461 bool lp_idmap_range(const char *domain_name, uint32_t *low, uint32_t *high)
2463 char *config_option = NULL;
2464 const char *range = NULL;
2465 bool ret = false;
2467 SMB_ASSERT(low != NULL);
2468 SMB_ASSERT(high != NULL);
2470 if ((domain_name == NULL) || (domain_name[0] == '\0')) {
2471 domain_name = "*";
2474 config_option = talloc_asprintf(talloc_tos(), "idmap config %s",
2475 domain_name);
2476 if (config_option == NULL) {
2477 DEBUG(0, ("out of memory\n"));
2478 return false;
2481 range = lp_parm_const_string(-1, config_option, "range", NULL);
2482 if (range == NULL) {
2483 DEBUG(1, ("idmap range not specified for domain '%s'\n", domain_name));
2484 goto done;
2487 if (sscanf(range, "%u - %u", low, high) != 2) {
2488 DEBUG(1, ("error parsing idmap range '%s' for domain '%s'\n",
2489 range, domain_name));
2490 goto done;
2493 ret = true;
2495 done:
2496 talloc_free(config_option);
2497 return ret;
2501 bool lp_idmap_default_range(uint32_t *low, uint32_t *high)
2503 return lp_idmap_range("*", low, high);
2506 const char *lp_idmap_backend(const char *domain_name)
2508 char *config_option = NULL;
2509 const char *backend = NULL;
2511 if ((domain_name == NULL) || (domain_name[0] == '\0')) {
2512 domain_name = "*";
2515 config_option = talloc_asprintf(talloc_tos(), "idmap config %s",
2516 domain_name);
2517 if (config_option == NULL) {
2518 DEBUG(0, ("out of memory\n"));
2519 return false;
2522 backend = lp_parm_const_string(-1, config_option, "backend", NULL);
2523 if (backend == NULL) {
2524 DEBUG(1, ("idmap backend not specified for domain '%s'\n", domain_name));
2525 goto done;
2528 done:
2529 talloc_free(config_option);
2530 return backend;
2533 const char *lp_idmap_default_backend(void)
2535 return lp_idmap_backend("*");
2538 /***************************************************************************
2539 Handle ldap suffixes - default to ldapsuffix if sub-suffixes are not defined.
2540 ***************************************************************************/
2542 static const char *append_ldap_suffix(TALLOC_CTX *ctx, const char *str )
2544 const char *suffix_string;
2546 suffix_string = talloc_asprintf(ctx, "%s,%s", str,
2547 Globals.ldap_suffix );
2548 if ( !suffix_string ) {
2549 DEBUG(0,("append_ldap_suffix: talloc_asprintf() failed!\n"));
2550 return "";
2553 return suffix_string;
2556 const char *lp_ldap_machine_suffix(TALLOC_CTX *ctx)
2558 if (Globals._ldap_machine_suffix[0])
2559 return append_ldap_suffix(ctx, Globals._ldap_machine_suffix);
2561 return lp_string(ctx, Globals.ldap_suffix);
2564 const char *lp_ldap_user_suffix(TALLOC_CTX *ctx)
2566 if (Globals._ldap_user_suffix[0])
2567 return append_ldap_suffix(ctx, Globals._ldap_user_suffix);
2569 return lp_string(ctx, Globals.ldap_suffix);
2572 const char *lp_ldap_group_suffix(TALLOC_CTX *ctx)
2574 if (Globals._ldap_group_suffix[0])
2575 return append_ldap_suffix(ctx, Globals._ldap_group_suffix);
2577 return lp_string(ctx, Globals.ldap_suffix);
2580 const char *lp_ldap_idmap_suffix(TALLOC_CTX *ctx)
2582 if (Globals._ldap_idmap_suffix[0])
2583 return append_ldap_suffix(ctx, Globals._ldap_idmap_suffix);
2585 return lp_string(ctx, Globals.ldap_suffix);
2589 return the parameter pointer for a parameter
2591 void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm)
2593 if (service == NULL) {
2594 if (parm->p_class == P_LOCAL)
2595 return (void *)(((char *)&sDefault)+parm->offset);
2596 else if (parm->p_class == P_GLOBAL)
2597 return (void *)(((char *)&Globals)+parm->offset);
2598 else return NULL;
2599 } else {
2600 return (void *)(((char *)service) + parm->offset);
2604 /***************************************************************************
2605 Process a parameter for a particular service number. If snum < 0
2606 then assume we are in the globals.
2607 ***************************************************************************/
2609 bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue)
2611 TALLOC_CTX *frame = talloc_stackframe();
2612 struct loadparm_context *lp_ctx;
2613 bool ok;
2615 lp_ctx = setup_lp_context(frame);
2616 if (lp_ctx == NULL) {
2617 TALLOC_FREE(frame);
2618 return false;
2621 if (snum < 0) {
2622 ok = lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue);
2623 } else {
2624 ok = lpcfg_do_service_parameter(lp_ctx, ServicePtrs[snum],
2625 pszParmName, pszParmValue);
2628 TALLOC_FREE(frame);
2630 return ok;
2633 /***************************************************************************
2634 set a parameter, marking it with FLAG_CMDLINE. Parameters marked as
2635 FLAG_CMDLINE won't be overridden by loads from smb.conf.
2636 ***************************************************************************/
2638 static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmValue)
2640 int parmnum, i;
2641 parmnum = lpcfg_map_parameter(pszParmName);
2642 if (parmnum >= 0) {
2643 flags_list[parmnum] &= ~FLAG_CMDLINE;
2644 if (!lp_do_parameter(-1, pszParmName, pszParmValue)) {
2645 return false;
2647 flags_list[parmnum] |= FLAG_CMDLINE;
2649 /* we have to also set FLAG_CMDLINE on aliases. Aliases must
2650 * be grouped in the table, so we don't have to search the
2651 * whole table */
2652 for (i=parmnum-1;
2653 i>=0 && parm_table[i].offset == parm_table[parmnum].offset
2654 && parm_table[i].p_class == parm_table[parmnum].p_class;
2655 i--) {
2656 flags_list[i] |= FLAG_CMDLINE;
2658 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset
2659 && parm_table[i].p_class == parm_table[parmnum].p_class;i++) {
2660 flags_list[i] |= FLAG_CMDLINE;
2663 return true;
2666 /* it might be parametric */
2667 if (strchr(pszParmName, ':') != NULL) {
2668 set_param_opt(NULL, &Globals.param_opt, pszParmName, pszParmValue, FLAG_CMDLINE);
2669 return true;
2672 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2673 return false;
2676 bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
2678 bool ret;
2679 TALLOC_CTX *frame = talloc_stackframe();
2680 struct loadparm_context *lp_ctx;
2682 lp_ctx = setup_lp_context(frame);
2683 if (lp_ctx == NULL) {
2684 TALLOC_FREE(frame);
2685 return false;
2688 ret = lpcfg_set_cmdline(lp_ctx, pszParmName, pszParmValue);
2690 TALLOC_FREE(frame);
2691 return ret;
2694 /***************************************************************************
2695 Process a parameter.
2696 ***************************************************************************/
2698 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2699 void *userdata)
2701 if (!bInGlobalSection && bGlobalOnly)
2702 return true;
2704 DEBUGADD(4, ("doing parameter %s = %s\n", pszParmName, pszParmValue));
2706 if (bInGlobalSection) {
2707 return lpcfg_do_global_parameter(userdata, pszParmName, pszParmValue);
2708 } else {
2709 return lpcfg_do_service_parameter(userdata, ServicePtrs[iServiceIndex],
2710 pszParmName, pszParmValue);
2714 /***************************************************************************
2715 Initialize any local variables in the sDefault table, after parsing a
2716 [globals] section.
2717 ***************************************************************************/
2719 static void init_locals(void)
2722 * We run this check once the [globals] is parsed, to force
2723 * the VFS objects and other per-share settings we need for
2724 * the standard way a AD DC is operated. We may change these
2725 * as our code evolves, which is why we force these settings.
2727 * We can't do this at the end of lp_load_ex(), as by that
2728 * point the services have been loaded and they will already
2729 * have "" as their vfs objects.
2731 if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC) {
2732 const char **vfs_objects = lp_vfs_objects(-1);
2733 if (!vfs_objects || !vfs_objects[0]) {
2734 if (lp_parm_const_string(-1, "xattr_tdb", "file", NULL)) {
2735 lp_do_parameter(-1, "vfs objects", "dfs_samba4 acl_xattr xattr_tdb");
2736 } else if (lp_parm_const_string(-1, "posix", "eadb", NULL)) {
2737 lp_do_parameter(-1, "vfs objects", "dfs_samba4 acl_xattr posix_eadb");
2738 } else {
2739 lp_do_parameter(-1, "vfs objects", "dfs_samba4 acl_xattr");
2743 lp_do_parameter(-1, "map hidden", "no");
2744 lp_do_parameter(-1, "map system", "no");
2745 lp_do_parameter(-1, "map readonly", "no");
2746 lp_do_parameter(-1, "map archive", "no");
2747 lp_do_parameter(-1, "store dos attributes", "yes");
2751 /***************************************************************************
2752 Process a new section (service). At this stage all sections are services.
2753 Later we'll have special sections that permit server parameters to be set.
2754 Returns true on success, false on failure.
2755 ***************************************************************************/
2757 bool lp_do_section(const char *pszSectionName, void *userdata)
2759 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2760 bool bRetval;
2761 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2762 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2763 bRetval = false;
2765 /* if we were in a global section then do the local inits */
2766 if (bInGlobalSection && !isglobal)
2767 init_locals();
2769 /* if we've just struck a global section, note the fact. */
2770 bInGlobalSection = isglobal;
2771 if (lp_ctx != NULL) {
2772 lp_ctx->bInGlobalSection = isglobal;
2775 /* check for multiple global sections */
2776 if (bInGlobalSection) {
2777 DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
2778 return true;
2781 if (!bInGlobalSection && bGlobalOnly)
2782 return true;
2784 /* if we have a current service, tidy it up before moving on */
2785 bRetval = true;
2787 if (iServiceIndex >= 0)
2788 bRetval = lpcfg_service_ok(ServicePtrs[iServiceIndex]);
2790 /* if all is still well, move to the next record in the services array */
2791 if (bRetval) {
2792 /* We put this here to avoid an odd message order if messages are */
2793 /* issued by the post-processing of a previous section. */
2794 DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
2796 iServiceIndex = add_a_service(&sDefault, pszSectionName);
2797 if (iServiceIndex < 0) {
2798 DEBUG(0, ("Failed to add a new service\n"));
2799 return false;
2801 /* Clean all parametric options for service */
2802 /* They will be added during parsing again */
2803 free_param_opts(&ServicePtrs[iServiceIndex]->param_opt);
2806 return bRetval;
2809 /***************************************************************************
2810 Display the contents of a parameter of a single services record.
2811 ***************************************************************************/
2813 bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
2815 bool result = false;
2816 struct loadparm_context *lp_ctx;
2818 lp_ctx = setup_lp_context(talloc_tos());
2819 if (lp_ctx == NULL) {
2820 return false;
2823 if (isGlobal) {
2824 result = lpcfg_dump_a_parameter(lp_ctx, NULL, parm_name, f);
2825 } else {
2826 result = lpcfg_dump_a_parameter(lp_ctx, ServicePtrs[snum], parm_name, f);
2828 TALLOC_FREE(lp_ctx);
2829 return result;
2832 #if 0
2833 /***************************************************************************
2834 Display the contents of a single copy structure.
2835 ***************************************************************************/
2836 static void dump_copy_map(bool *pcopymap)
2838 int i;
2839 if (!pcopymap)
2840 return;
2842 printf("\n\tNon-Copied parameters:\n");
2844 for (i = 0; parm_table[i].label; i++)
2845 if (parm_table[i].p_class == P_LOCAL &&
2846 parm_table[i].ptr && !pcopymap[i] &&
2847 (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr)))
2849 printf("\t\t%s\n", parm_table[i].label);
2852 #endif
2854 /***************************************************************************
2855 Return TRUE if the passed service number is within range.
2856 ***************************************************************************/
2858 bool lp_snum_ok(int iService)
2860 return (LP_SNUM_OK(iService) && ServicePtrs[iService]->available);
2863 /***************************************************************************
2864 Auto-load some home services.
2865 ***************************************************************************/
2867 static void lp_add_auto_services(char *str)
2869 char *s;
2870 char *p;
2871 int homes;
2872 char *saveptr;
2874 if (!str)
2875 return;
2877 s = talloc_strdup(talloc_tos(), str);
2878 if (!s) {
2879 smb_panic("talloc_strdup failed");
2880 return;
2883 homes = lp_servicenumber(HOMES_NAME);
2885 for (p = strtok_r(s, LIST_SEP, &saveptr); p;
2886 p = strtok_r(NULL, LIST_SEP, &saveptr)) {
2887 char *home;
2889 if (lp_servicenumber(p) >= 0)
2890 continue;
2892 home = get_user_home_dir(talloc_tos(), p);
2894 if (home && home[0] && homes >= 0)
2895 lp_add_home(p, homes, p, home);
2897 TALLOC_FREE(home);
2899 TALLOC_FREE(s);
2902 /***************************************************************************
2903 Auto-load one printer.
2904 ***************************************************************************/
2906 void lp_add_one_printer(const char *name, const char *comment,
2907 const char *location, void *pdata)
2909 int printers = lp_servicenumber(PRINTERS_NAME);
2910 int i;
2912 if (lp_servicenumber(name) < 0) {
2913 lp_add_printer(name, printers);
2914 if ((i = lp_servicenumber(name)) >= 0) {
2915 lpcfg_string_set(ServicePtrs[i],
2916 &ServicePtrs[i]->comment, comment);
2917 ServicePtrs[i]->autoloaded = true;
2922 /***************************************************************************
2923 Have we loaded a services file yet?
2924 ***************************************************************************/
2926 bool lp_loaded(void)
2928 return (bLoaded);
2931 /***************************************************************************
2932 Unload unused services.
2933 ***************************************************************************/
2935 void lp_killunused(struct smbd_server_connection *sconn,
2936 bool (*snumused) (struct smbd_server_connection *, int))
2938 int i;
2939 for (i = 0; i < iNumServices; i++) {
2940 if (!VALID(i))
2941 continue;
2943 /* don't kill autoloaded or usershare services */
2944 if ( ServicePtrs[i]->autoloaded ||
2945 ServicePtrs[i]->usershare == USERSHARE_VALID) {
2946 continue;
2949 if (!snumused || !snumused(sconn, i)) {
2950 free_service_byindex(i);
2956 * Kill all except autoloaded and usershare services - convenience wrapper
2958 void lp_kill_all_services(void)
2960 lp_killunused(NULL, NULL);
2963 /***************************************************************************
2964 Unload a service.
2965 ***************************************************************************/
2967 void lp_killservice(int iServiceIn)
2969 if (VALID(iServiceIn)) {
2970 free_service_byindex(iServiceIn);
2974 /***************************************************************************
2975 Save the curent values of all global and sDefault parameters into the
2976 defaults union. This allows testparm to show only the
2977 changed (ie. non-default) parameters.
2978 ***************************************************************************/
2980 static void lp_save_defaults(void)
2982 int i;
2983 struct parmlist_entry * parm;
2984 for (i = 0; parm_table[i].label; i++) {
2985 if (!(flags_list[i] & FLAG_CMDLINE)) {
2986 flags_list[i] |= FLAG_DEFAULT;
2989 if (i > 0 && parm_table[i].offset == parm_table[i - 1].offset
2990 && parm_table[i].p_class == parm_table[i - 1].p_class)
2991 continue;
2992 switch (parm_table[i].type) {
2993 case P_LIST:
2994 case P_CMDLIST:
2995 parm_table[i].def.lvalue = str_list_copy(
2996 NULL, *(const char ***)lp_parm_ptr(NULL, &parm_table[i]));
2997 break;
2998 case P_STRING:
2999 case P_USTRING:
3000 lpcfg_string_set(
3001 Globals.ctx,
3002 &parm_table[i].def.svalue,
3003 *(char **)lp_parm_ptr(
3004 NULL, &parm_table[i]));
3005 if (parm_table[i].def.svalue == NULL) {
3006 smb_panic("lpcfg_string_set() failed");
3008 break;
3009 case P_BOOL:
3010 case P_BOOLREV:
3011 parm_table[i].def.bvalue =
3012 *(bool *)lp_parm_ptr(NULL, &parm_table[i]);
3013 break;
3014 case P_CHAR:
3015 parm_table[i].def.cvalue =
3016 *(char *)lp_parm_ptr(NULL, &parm_table[i]);
3017 break;
3018 case P_INTEGER:
3019 case P_OCTAL:
3020 case P_ENUM:
3021 case P_BYTES:
3022 parm_table[i].def.ivalue =
3023 *(int *)lp_parm_ptr(NULL, &parm_table[i]);
3024 break;
3028 for (parm=Globals.param_opt; parm; parm=parm->next) {
3029 if (!(parm->priority & FLAG_CMDLINE)) {
3030 parm->priority |= FLAG_DEFAULT;
3034 for (parm=sDefault.param_opt; parm; parm=parm->next) {
3035 if (!(parm->priority & FLAG_CMDLINE)) {
3036 parm->priority |= FLAG_DEFAULT;
3040 defaults_saved = true;
3043 /***********************************************************
3044 If we should send plaintext/LANMAN passwords in the clinet
3045 ************************************************************/
3047 static void set_allowed_client_auth(void)
3049 if (Globals.client_ntlmv2_auth) {
3050 Globals.client_lanman_auth = false;
3052 if (!Globals.client_lanman_auth) {
3053 Globals.client_plaintext_auth = false;
3057 /***************************************************************************
3058 JRA.
3059 The following code allows smbd to read a user defined share file.
3060 Yes, this is my intent. Yes, I'm comfortable with that...
3062 THE FOLLOWING IS SECURITY CRITICAL CODE.
3064 It washes your clothes, it cleans your house, it guards you while you sleep...
3065 Do not f%^k with it....
3066 ***************************************************************************/
3068 #define MAX_USERSHARE_FILE_SIZE (10*1024)
3070 /***************************************************************************
3071 Check allowed stat state of a usershare file.
3072 Ensure we print out who is dicking with us so the admin can
3073 get their sorry ass fired.
3074 ***************************************************************************/
3076 static bool check_usershare_stat(const char *fname,
3077 const SMB_STRUCT_STAT *psbuf)
3079 if (!S_ISREG(psbuf->st_ex_mode)) {
3080 DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
3081 "not a regular file\n",
3082 fname, (unsigned int)psbuf->st_ex_uid ));
3083 return false;
3086 /* Ensure this doesn't have the other write bit set. */
3087 if (psbuf->st_ex_mode & S_IWOTH) {
3088 DEBUG(0,("check_usershare_stat: file %s owned by uid %u allows "
3089 "public write. Refusing to allow as a usershare file.\n",
3090 fname, (unsigned int)psbuf->st_ex_uid ));
3091 return false;
3094 /* Should be 10k or less. */
3095 if (psbuf->st_ex_size > MAX_USERSHARE_FILE_SIZE) {
3096 DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
3097 "too large (%u) to be a user share file.\n",
3098 fname, (unsigned int)psbuf->st_ex_uid,
3099 (unsigned int)psbuf->st_ex_size ));
3100 return false;
3103 return true;
3106 /***************************************************************************
3107 Parse the contents of a usershare file.
3108 ***************************************************************************/
3110 enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
3111 SMB_STRUCT_STAT *psbuf,
3112 const char *servicename,
3113 int snum,
3114 char **lines,
3115 int numlines,
3116 char **pp_sharepath,
3117 char **pp_comment,
3118 char **pp_cp_servicename,
3119 struct security_descriptor **ppsd,
3120 bool *pallow_guest)
3122 const char **prefixallowlist = lp_usershare_prefix_allow_list();
3123 const char **prefixdenylist = lp_usershare_prefix_deny_list();
3124 int us_vers;
3125 DIR *dp;
3126 SMB_STRUCT_STAT sbuf;
3127 char *sharepath = NULL;
3128 char *comment = NULL;
3130 *pp_sharepath = NULL;
3131 *pp_comment = NULL;
3133 *pallow_guest = false;
3135 if (numlines < 4) {
3136 return USERSHARE_MALFORMED_FILE;
3139 if (strcmp(lines[0], "#VERSION 1") == 0) {
3140 us_vers = 1;
3141 } else if (strcmp(lines[0], "#VERSION 2") == 0) {
3142 us_vers = 2;
3143 if (numlines < 5) {
3144 return USERSHARE_MALFORMED_FILE;
3146 } else {
3147 return USERSHARE_BAD_VERSION;
3150 if (strncmp(lines[1], "path=", 5) != 0) {
3151 return USERSHARE_MALFORMED_PATH;
3154 sharepath = talloc_strdup(ctx, &lines[1][5]);
3155 if (!sharepath) {
3156 return USERSHARE_POSIX_ERR;
3158 trim_string(sharepath, " ", " ");
3160 if (strncmp(lines[2], "comment=", 8) != 0) {
3161 return USERSHARE_MALFORMED_COMMENT_DEF;
3164 comment = talloc_strdup(ctx, &lines[2][8]);
3165 if (!comment) {
3166 return USERSHARE_POSIX_ERR;
3168 trim_string(comment, " ", " ");
3169 trim_char(comment, '"', '"');
3171 if (strncmp(lines[3], "usershare_acl=", 14) != 0) {
3172 return USERSHARE_MALFORMED_ACL_DEF;
3175 if (!parse_usershare_acl(ctx, &lines[3][14], ppsd)) {
3176 return USERSHARE_ACL_ERR;
3179 if (us_vers == 2) {
3180 if (strncmp(lines[4], "guest_ok=", 9) != 0) {
3181 return USERSHARE_MALFORMED_ACL_DEF;
3183 if (lines[4][9] == 'y') {
3184 *pallow_guest = true;
3187 /* Backwards compatible extension to file version #2. */
3188 if (numlines > 5) {
3189 if (strncmp(lines[5], "sharename=", 10) != 0) {
3190 return USERSHARE_MALFORMED_SHARENAME_DEF;
3192 if (!strequal(&lines[5][10], servicename)) {
3193 return USERSHARE_BAD_SHARENAME;
3195 *pp_cp_servicename = talloc_strdup(ctx, &lines[5][10]);
3196 if (!*pp_cp_servicename) {
3197 return USERSHARE_POSIX_ERR;
3202 if (*pp_cp_servicename == NULL) {
3203 *pp_cp_servicename = talloc_strdup(ctx, servicename);
3204 if (!*pp_cp_servicename) {
3205 return USERSHARE_POSIX_ERR;
3209 if (snum != -1 && (strcmp(sharepath, ServicePtrs[snum]->path) == 0)) {
3210 /* Path didn't change, no checks needed. */
3211 *pp_sharepath = sharepath;
3212 *pp_comment = comment;
3213 return USERSHARE_OK;
3216 /* The path *must* be absolute. */
3217 if (sharepath[0] != '/') {
3218 DEBUG(2,("parse_usershare_file: share %s: path %s is not an absolute path.\n",
3219 servicename, sharepath));
3220 return USERSHARE_PATH_NOT_ABSOLUTE;
3223 /* If there is a usershare prefix deny list ensure one of these paths
3224 doesn't match the start of the user given path. */
3225 if (prefixdenylist) {
3226 int i;
3227 for ( i=0; prefixdenylist[i]; i++ ) {
3228 DEBUG(10,("parse_usershare_file: share %s : checking prefixdenylist[%d]='%s' against %s\n",
3229 servicename, i, prefixdenylist[i], sharepath ));
3230 if (memcmp( sharepath, prefixdenylist[i], strlen(prefixdenylist[i])) == 0) {
3231 DEBUG(2,("parse_usershare_file: share %s path %s starts with one of the "
3232 "usershare prefix deny list entries.\n",
3233 servicename, sharepath));
3234 return USERSHARE_PATH_IS_DENIED;
3239 /* If there is a usershare prefix allow list ensure one of these paths
3240 does match the start of the user given path. */
3242 if (prefixallowlist) {
3243 int i;
3244 for ( i=0; prefixallowlist[i]; i++ ) {
3245 DEBUG(10,("parse_usershare_file: share %s checking prefixallowlist[%d]='%s' against %s\n",
3246 servicename, i, prefixallowlist[i], sharepath ));
3247 if (memcmp( sharepath, prefixallowlist[i], strlen(prefixallowlist[i])) == 0) {
3248 break;
3251 if (prefixallowlist[i] == NULL) {
3252 DEBUG(2,("parse_usershare_file: share %s path %s doesn't start with one of the "
3253 "usershare prefix allow list entries.\n",
3254 servicename, sharepath));
3255 return USERSHARE_PATH_NOT_ALLOWED;
3259 /* Ensure this is pointing to a directory. */
3260 dp = opendir(sharepath);
3262 if (!dp) {
3263 DEBUG(2,("parse_usershare_file: share %s path %s is not a directory.\n",
3264 servicename, sharepath));
3265 return USERSHARE_PATH_NOT_DIRECTORY;
3268 /* Ensure the owner of the usershare file has permission to share
3269 this directory. */
3271 if (sys_stat(sharepath, &sbuf, false) == -1) {
3272 DEBUG(2,("parse_usershare_file: share %s : stat failed on path %s. %s\n",
3273 servicename, sharepath, strerror(errno) ));
3274 closedir(dp);
3275 return USERSHARE_POSIX_ERR;
3278 closedir(dp);
3280 if (!S_ISDIR(sbuf.st_ex_mode)) {
3281 DEBUG(2,("parse_usershare_file: share %s path %s is not a directory.\n",
3282 servicename, sharepath ));
3283 return USERSHARE_PATH_NOT_DIRECTORY;
3286 /* Check if sharing is restricted to owner-only. */
3287 /* psbuf is the stat of the usershare definition file,
3288 sbuf is the stat of the target directory to be shared. */
3290 if (lp_usershare_owner_only()) {
3291 /* root can share anything. */
3292 if ((psbuf->st_ex_uid != 0) && (sbuf.st_ex_uid != psbuf->st_ex_uid)) {
3293 return USERSHARE_PATH_NOT_ALLOWED;
3297 *pp_sharepath = sharepath;
3298 *pp_comment = comment;
3299 return USERSHARE_OK;
3302 /***************************************************************************
3303 Deal with a usershare file.
3304 Returns:
3305 >= 0 - snum
3306 -1 - Bad name, invalid contents.
3307 - service name already existed and not a usershare, problem
3308 with permissions to share directory etc.
3309 ***************************************************************************/
3311 static int process_usershare_file(const char *dir_name, const char *file_name, int snum_template)
3313 SMB_STRUCT_STAT sbuf;
3314 SMB_STRUCT_STAT lsbuf;
3315 char *fname = NULL;
3316 char *sharepath = NULL;
3317 char *comment = NULL;
3318 char *cp_service_name = NULL;
3319 char **lines = NULL;
3320 int numlines = 0;
3321 int fd = -1;
3322 int iService = -1;
3323 TALLOC_CTX *ctx = talloc_stackframe();
3324 struct security_descriptor *psd = NULL;
3325 bool guest_ok = false;
3326 char *canon_name = NULL;
3327 bool added_service = false;
3328 int ret = -1;
3330 /* Ensure share name doesn't contain invalid characters. */
3331 if (!validate_net_name(file_name, INVALID_SHARENAME_CHARS, strlen(file_name))) {
3332 DEBUG(0,("process_usershare_file: share name %s contains "
3333 "invalid characters (any of %s)\n",
3334 file_name, INVALID_SHARENAME_CHARS ));
3335 goto out;
3338 canon_name = canonicalize_servicename(ctx, file_name);
3339 if (!canon_name) {
3340 goto out;
3343 fname = talloc_asprintf(ctx, "%s/%s", dir_name, file_name);
3344 if (!fname) {
3345 goto out;
3348 /* Minimize the race condition by doing an lstat before we
3349 open and fstat. Ensure this isn't a symlink link. */
3351 if (sys_lstat(fname, &lsbuf, false) != 0) {
3352 DEBUG(0,("process_usershare_file: stat of %s failed. %s\n",
3353 fname, strerror(errno) ));
3354 goto out;
3357 /* This must be a regular file, not a symlink, directory or
3358 other strange filetype. */
3359 if (!check_usershare_stat(fname, &lsbuf)) {
3360 goto out;
3364 TDB_DATA data;
3365 NTSTATUS status;
3367 status = dbwrap_fetch_bystring(ServiceHash, canon_name,
3368 canon_name, &data);
3370 iService = -1;
3372 if (NT_STATUS_IS_OK(status) &&
3373 (data.dptr != NULL) &&
3374 (data.dsize == sizeof(iService))) {
3375 memcpy(&iService, data.dptr, sizeof(iService));
3379 if (iService != -1 &&
3380 timespec_compare(&ServicePtrs[iService]->usershare_last_mod,
3381 &lsbuf.st_ex_mtime) == 0) {
3382 /* Nothing changed - Mark valid and return. */
3383 DEBUG(10,("process_usershare_file: service %s not changed.\n",
3384 canon_name ));
3385 ServicePtrs[iService]->usershare = USERSHARE_VALID;
3386 ret = iService;
3387 goto out;
3390 /* Try and open the file read only - no symlinks allowed. */
3391 #ifdef O_NOFOLLOW
3392 fd = open(fname, O_RDONLY|O_NOFOLLOW, 0);
3393 #else
3394 fd = open(fname, O_RDONLY, 0);
3395 #endif
3397 if (fd == -1) {
3398 DEBUG(0,("process_usershare_file: unable to open %s. %s\n",
3399 fname, strerror(errno) ));
3400 goto out;
3403 /* Now fstat to be *SURE* it's a regular file. */
3404 if (sys_fstat(fd, &sbuf, false) != 0) {
3405 close(fd);
3406 DEBUG(0,("process_usershare_file: fstat of %s failed. %s\n",
3407 fname, strerror(errno) ));
3408 goto out;
3411 /* Is it the same dev/inode as was lstated ? */
3412 if (!check_same_stat(&lsbuf, &sbuf)) {
3413 close(fd);
3414 DEBUG(0,("process_usershare_file: fstat of %s is a different file from lstat. "
3415 "Symlink spoofing going on ?\n", fname ));
3416 goto out;
3419 /* This must be a regular file, not a symlink, directory or
3420 other strange filetype. */
3421 if (!check_usershare_stat(fname, &sbuf)) {
3422 close(fd);
3423 goto out;
3426 lines = fd_lines_load(fd, &numlines, MAX_USERSHARE_FILE_SIZE, NULL);
3428 close(fd);
3429 if (lines == NULL) {
3430 DEBUG(0,("process_usershare_file: loading file %s owned by %u failed.\n",
3431 fname, (unsigned int)sbuf.st_ex_uid ));
3432 goto out;
3435 if (parse_usershare_file(ctx, &sbuf, file_name,
3436 iService, lines, numlines, &sharepath,
3437 &comment, &cp_service_name,
3438 &psd, &guest_ok) != USERSHARE_OK) {
3439 goto out;
3442 /* Everything ok - add the service possibly using a template. */
3443 if (iService < 0) {
3444 const struct loadparm_service *sp = &sDefault;
3445 if (snum_template != -1) {
3446 sp = ServicePtrs[snum_template];
3449 if ((iService = add_a_service(sp, cp_service_name)) < 0) {
3450 DEBUG(0, ("process_usershare_file: Failed to add "
3451 "new service %s\n", cp_service_name));
3452 goto out;
3455 added_service = true;
3457 /* Read only is controlled by usershare ACL below. */
3458 ServicePtrs[iService]->read_only = false;
3461 /* Write the ACL of the new/modified share. */
3462 if (!set_share_security(canon_name, psd)) {
3463 DEBUG(0, ("process_usershare_file: Failed to set share "
3464 "security for user share %s\n",
3465 canon_name ));
3466 goto out;
3469 /* If from a template it may be marked invalid. */
3470 ServicePtrs[iService]->valid = true;
3472 /* Set the service as a valid usershare. */
3473 ServicePtrs[iService]->usershare = USERSHARE_VALID;
3475 /* Set guest access. */
3476 if (lp_usershare_allow_guests()) {
3477 ServicePtrs[iService]->guest_ok = guest_ok;
3480 /* And note when it was loaded. */
3481 ServicePtrs[iService]->usershare_last_mod = sbuf.st_ex_mtime;
3482 lpcfg_string_set(ServicePtrs[iService], &ServicePtrs[iService]->path,
3483 sharepath);
3484 lpcfg_string_set(ServicePtrs[iService],
3485 &ServicePtrs[iService]->comment, comment);
3487 ret = iService;
3489 out:
3491 if (ret == -1 && iService != -1 && added_service) {
3492 lp_remove_service(iService);
3495 TALLOC_FREE(lines);
3496 TALLOC_FREE(ctx);
3497 return ret;
3500 /***************************************************************************
3501 Checks if a usershare entry has been modified since last load.
3502 ***************************************************************************/
3504 static bool usershare_exists(int iService, struct timespec *last_mod)
3506 SMB_STRUCT_STAT lsbuf;
3507 const char *usersharepath = Globals.usershare_path;
3508 char *fname;
3510 fname = talloc_asprintf(talloc_tos(),
3511 "%s/%s",
3512 usersharepath,
3513 ServicePtrs[iService]->szService);
3514 if (fname == NULL) {
3515 return false;
3518 if (sys_lstat(fname, &lsbuf, false) != 0) {
3519 TALLOC_FREE(fname);
3520 return false;
3523 if (!S_ISREG(lsbuf.st_ex_mode)) {
3524 TALLOC_FREE(fname);
3525 return false;
3528 TALLOC_FREE(fname);
3529 *last_mod = lsbuf.st_ex_mtime;
3530 return true;
3533 static bool usershare_directory_is_root(uid_t uid)
3535 if (uid == 0) {
3536 return true;
3539 if (uid_wrapper_enabled()) {
3540 return true;
3543 return false;
3546 /***************************************************************************
3547 Load a usershare service by name. Returns a valid servicenumber or -1.
3548 ***************************************************************************/
3550 int load_usershare_service(const char *servicename)
3552 SMB_STRUCT_STAT sbuf;
3553 const char *usersharepath = Globals.usershare_path;
3554 int max_user_shares = Globals.usershare_max_shares;
3555 int snum_template = -1;
3557 if (*usersharepath == 0 || max_user_shares == 0) {
3558 return -1;
3561 if (sys_stat(usersharepath, &sbuf, false) != 0) {
3562 DEBUG(0,("load_usershare_service: stat of %s failed. %s\n",
3563 usersharepath, strerror(errno) ));
3564 return -1;
3567 if (!S_ISDIR(sbuf.st_ex_mode)) {
3568 DEBUG(0,("load_usershare_service: %s is not a directory.\n",
3569 usersharepath ));
3570 return -1;
3574 * This directory must be owned by root, and have the 't' bit set.
3575 * It also must not be writable by "other".
3578 #ifdef S_ISVTX
3579 if (!usershare_directory_is_root(sbuf.st_ex_uid) ||
3580 !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
3581 #else
3582 if (!usershare_directory_is_root(sbuf.st_ex_uid) ||
3583 (sbuf.st_ex_mode & S_IWOTH)) {
3584 #endif
3585 DEBUG(0,("load_usershare_service: directory %s is not owned by root "
3586 "or does not have the sticky bit 't' set or is writable by anyone.\n",
3587 usersharepath ));
3588 return -1;
3591 /* Ensure the template share exists if it's set. */
3592 if (Globals.usershare_template_share[0]) {
3593 /* We can't use lp_servicenumber here as we are recommending that
3594 template shares have -valid=false set. */
3595 for (snum_template = iNumServices - 1; snum_template >= 0; snum_template--) {
3596 if (ServicePtrs[snum_template]->szService &&
3597 strequal(ServicePtrs[snum_template]->szService,
3598 Globals.usershare_template_share)) {
3599 break;
3603 if (snum_template == -1) {
3604 DEBUG(0,("load_usershare_service: usershare template share %s "
3605 "does not exist.\n",
3606 Globals.usershare_template_share ));
3607 return -1;
3611 return process_usershare_file(usersharepath, servicename, snum_template);
3614 /***************************************************************************
3615 Load all user defined shares from the user share directory.
3616 We only do this if we're enumerating the share list.
3617 This is the function that can delete usershares that have
3618 been removed.
3619 ***************************************************************************/
3621 int load_usershare_shares(struct smbd_server_connection *sconn,
3622 bool (*snumused) (struct smbd_server_connection *, int))
3624 DIR *dp;
3625 SMB_STRUCT_STAT sbuf;
3626 struct dirent *de;
3627 int num_usershares = 0;
3628 int max_user_shares = Globals.usershare_max_shares;
3629 unsigned int num_dir_entries, num_bad_dir_entries, num_tmp_dir_entries;
3630 unsigned int allowed_bad_entries = ((2*max_user_shares)/10);
3631 unsigned int allowed_tmp_entries = ((2*max_user_shares)/10);
3632 int iService;
3633 int snum_template = -1;
3634 const char *usersharepath = Globals.usershare_path;
3635 int ret = lp_numservices();
3636 TALLOC_CTX *tmp_ctx;
3638 if (max_user_shares == 0 || *usersharepath == '\0') {
3639 return lp_numservices();
3642 if (sys_stat(usersharepath, &sbuf, false) != 0) {
3643 DEBUG(0,("load_usershare_shares: stat of %s failed. %s\n",
3644 usersharepath, strerror(errno) ));
3645 return ret;
3649 * This directory must be owned by root, and have the 't' bit set.
3650 * It also must not be writable by "other".
3653 #ifdef S_ISVTX
3654 if (sbuf.st_ex_uid != 0 || !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
3655 #else
3656 if (sbuf.st_ex_uid != 0 || (sbuf.st_ex_mode & S_IWOTH)) {
3657 #endif
3658 DEBUG(0,("load_usershare_shares: directory %s is not owned by root "
3659 "or does not have the sticky bit 't' set or is writable by anyone.\n",
3660 usersharepath ));
3661 return ret;
3664 /* Ensure the template share exists if it's set. */
3665 if (Globals.usershare_template_share[0]) {
3666 /* We can't use lp_servicenumber here as we are recommending that
3667 template shares have -valid=false set. */
3668 for (snum_template = iNumServices - 1; snum_template >= 0; snum_template--) {
3669 if (ServicePtrs[snum_template]->szService &&
3670 strequal(ServicePtrs[snum_template]->szService,
3671 Globals.usershare_template_share)) {
3672 break;
3676 if (snum_template == -1) {
3677 DEBUG(0,("load_usershare_shares: usershare template share %s "
3678 "does not exist.\n",
3679 Globals.usershare_template_share ));
3680 return ret;
3684 /* Mark all existing usershares as pending delete. */
3685 for (iService = iNumServices - 1; iService >= 0; iService--) {
3686 if (VALID(iService) && ServicePtrs[iService]->usershare) {
3687 ServicePtrs[iService]->usershare = USERSHARE_PENDING_DELETE;
3691 dp = opendir(usersharepath);
3692 if (!dp) {
3693 DEBUG(0,("load_usershare_shares:: failed to open directory %s. %s\n",
3694 usersharepath, strerror(errno) ));
3695 return ret;
3698 for (num_dir_entries = 0, num_bad_dir_entries = 0, num_tmp_dir_entries = 0;
3699 (de = readdir(dp));
3700 num_dir_entries++ ) {
3701 int r;
3702 const char *n = de->d_name;
3704 /* Ignore . and .. */
3705 if (*n == '.') {
3706 if ((n[1] == '\0') || (n[1] == '.' && n[2] == '\0')) {
3707 continue;
3711 if (n[0] == ':') {
3712 /* Temporary file used when creating a share. */
3713 num_tmp_dir_entries++;
3716 /* Allow 20% tmp entries. */
3717 if (num_tmp_dir_entries > allowed_tmp_entries) {
3718 DEBUG(0,("load_usershare_shares: too many temp entries (%u) "
3719 "in directory %s\n",
3720 num_tmp_dir_entries, usersharepath));
3721 break;
3724 r = process_usershare_file(usersharepath, n, snum_template);
3725 if (r == 0) {
3726 /* Update the services count. */
3727 num_usershares++;
3728 if (num_usershares >= max_user_shares) {
3729 DEBUG(0,("load_usershare_shares: max user shares reached "
3730 "on file %s in directory %s\n",
3731 n, usersharepath ));
3732 break;
3734 } else if (r == -1) {
3735 num_bad_dir_entries++;
3738 /* Allow 20% bad entries. */
3739 if (num_bad_dir_entries > allowed_bad_entries) {
3740 DEBUG(0,("load_usershare_shares: too many bad entries (%u) "
3741 "in directory %s\n",
3742 num_bad_dir_entries, usersharepath));
3743 break;
3746 /* Allow 20% bad entries. */
3747 if (num_dir_entries > max_user_shares + allowed_bad_entries) {
3748 DEBUG(0,("load_usershare_shares: too many total entries (%u) "
3749 "in directory %s\n",
3750 num_dir_entries, usersharepath));
3751 break;
3755 closedir(dp);
3757 /* Sweep through and delete any non-refreshed usershares that are
3758 not currently in use. */
3759 tmp_ctx = talloc_stackframe();
3760 for (iService = iNumServices - 1; iService >= 0; iService--) {
3761 if (VALID(iService) && (ServicePtrs[iService]->usershare == USERSHARE_PENDING_DELETE)) {
3762 char *servname;
3764 if (snumused && snumused(sconn, iService)) {
3765 continue;
3768 servname = lp_servicename(tmp_ctx, iService);
3770 /* Remove from the share ACL db. */
3771 DEBUG(10,("load_usershare_shares: Removing deleted usershare %s\n",
3772 servname ));
3773 delete_share_security(servname);
3774 free_service_byindex(iService);
3777 talloc_free(tmp_ctx);
3779 return lp_numservices();
3782 /********************************************************
3783 Destroy global resources allocated in this file
3784 ********************************************************/
3786 void gfree_loadparm(void)
3788 int i;
3790 free_file_list();
3792 /* Free resources allocated to services */
3794 for ( i = 0; i < iNumServices; i++ ) {
3795 if ( VALID(i) ) {
3796 free_service_byindex(i);
3800 TALLOC_FREE( ServicePtrs );
3801 iNumServices = 0;
3803 /* Now release all resources allocated to global
3804 parameters and the default service */
3806 free_global_parameters();
3810 /***************************************************************************
3811 Allow client apps to specify that they are a client
3812 ***************************************************************************/
3813 static void lp_set_in_client(bool b)
3815 in_client = b;
3819 /***************************************************************************
3820 Determine if we're running in a client app
3821 ***************************************************************************/
3822 static bool lp_is_in_client(void)
3824 return in_client;
3827 static void lp_enforce_ad_dc_settings(void)
3829 lp_do_parameter(GLOBAL_SECTION_SNUM, "passdb backend", "samba_dsdb");
3830 lp_do_parameter(GLOBAL_SECTION_SNUM,
3831 "winbindd:use external pipes", "true");
3832 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:default", "external");
3833 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:svcctl", "embedded");
3834 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:srvsvc", "embedded");
3835 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:eventlog", "embedded");
3836 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:ntsvcs", "embedded");
3837 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:winreg", "embedded");
3838 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:spoolss", "embedded");
3839 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_daemon:spoolssd", "embedded");
3840 lp_do_parameter(GLOBAL_SECTION_SNUM, "rpc_server:tcpip", "no");
3843 /***************************************************************************
3844 Load the services array from the services file. Return true on success,
3845 false on failure.
3846 ***************************************************************************/
3848 static bool lp_load_ex(const char *pszFname,
3849 bool global_only,
3850 bool save_defaults,
3851 bool add_ipc,
3852 bool reinit_globals,
3853 bool allow_include_registry,
3854 bool load_all_shares)
3856 char *n2 = NULL;
3857 bool bRetval;
3858 TALLOC_CTX *frame = talloc_stackframe();
3859 struct loadparm_context *lp_ctx;
3861 bRetval = false;
3863 DEBUG(3, ("lp_load_ex: refreshing parameters\n"));
3865 bInGlobalSection = true;
3866 bGlobalOnly = global_only;
3867 bAllowIncludeRegistry = allow_include_registry;
3869 lp_ctx = setup_lp_context(talloc_tos());
3871 init_globals(lp_ctx, reinit_globals);
3873 free_file_list();
3875 if (save_defaults) {
3876 init_locals();
3877 lp_save_defaults();
3880 if (!reinit_globals) {
3881 free_param_opts(&Globals.param_opt);
3882 apply_lp_set_cmdline();
3885 lp_do_parameter(-1, "idmap config * : backend", Globals.idmap_backend);
3887 /* We get sections first, so have to start 'behind' to make up */
3888 iServiceIndex = -1;
3890 if (lp_config_backend_is_file()) {
3891 n2 = talloc_sub_basic(talloc_tos(), get_current_username(),
3892 current_user_info.domain,
3893 pszFname);
3894 if (!n2) {
3895 smb_panic("lp_load_ex: out of memory");
3898 add_to_file_list(NULL, &file_lists, pszFname, n2);
3900 bRetval = pm_process(n2, lp_do_section, do_parameter, lp_ctx);
3901 TALLOC_FREE(n2);
3903 /* finish up the last section */
3904 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3905 if (bRetval) {
3906 if (iServiceIndex >= 0) {
3907 bRetval = lpcfg_service_ok(ServicePtrs[iServiceIndex]);
3911 if (lp_config_backend_is_registry()) {
3912 bool ok;
3913 /* config backend changed to registry in config file */
3915 * We need to use this extra global variable here to
3916 * survive restart: init_globals uses this as a default
3917 * for config_backend. Otherwise, init_globals would
3918 * send us into an endless loop here.
3921 config_backend = CONFIG_BACKEND_REGISTRY;
3922 /* start over */
3923 DEBUG(1, ("lp_load_ex: changing to config backend "
3924 "registry\n"));
3925 init_globals(lp_ctx, true);
3927 TALLOC_FREE(lp_ctx);
3929 lp_kill_all_services();
3930 ok = lp_load_ex(pszFname, global_only, save_defaults,
3931 add_ipc, reinit_globals,
3932 allow_include_registry,
3933 load_all_shares);
3934 TALLOC_FREE(frame);
3935 return ok;
3937 } else if (lp_config_backend_is_registry()) {
3938 bRetval = process_registry_globals();
3939 } else {
3940 DEBUG(0, ("Illegal config backend given: %d\n",
3941 lp_config_backend()));
3942 bRetval = false;
3945 if (bRetval && lp_registry_shares()) {
3946 if (load_all_shares) {
3947 bRetval = process_registry_shares();
3948 } else {
3949 bRetval = reload_registry_shares();
3954 char *serv = lp_auto_services(talloc_tos());
3955 lp_add_auto_services(serv);
3956 TALLOC_FREE(serv);
3959 if (add_ipc) {
3960 /* When 'restrict anonymous = 2' guest connections to ipc$
3961 are denied */
3962 lp_add_ipc("IPC$", (lp_restrict_anonymous() < 2));
3963 if ( lp_enable_asu_support() ) {
3964 lp_add_ipc("ADMIN$", false);
3968 set_allowed_client_auth();
3970 if (lp_security() == SEC_ADS && strchr(lp_password_server(), ':')) {
3971 DEBUG(1, ("WARNING: The optional ':port' in password server = %s is deprecated\n",
3972 lp_password_server()));
3975 bLoaded = true;
3977 /* Now we check we_are_a_wins_server and set szWINSserver to 127.0.0.1 */
3978 /* if we_are_a_wins_server is true and we are in the client */
3979 if (lp_is_in_client() && Globals.we_are_a_wins_server) {
3980 lp_do_parameter(GLOBAL_SECTION_SNUM, "wins server", "127.0.0.1");
3983 init_iconv();
3985 fault_configure(smb_panic_s3);
3988 * We run this check once the whole smb.conf is parsed, to
3989 * force some settings for the standard way a AD DC is
3990 * operated. We may change these as our code evolves, which
3991 * is why we force these settings.
3993 if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC) {
3994 lp_enforce_ad_dc_settings();
3997 bAllowIncludeRegistry = true;
3999 TALLOC_FREE(frame);
4000 return (bRetval);
4003 static bool lp_load(const char *pszFname,
4004 bool global_only,
4005 bool save_defaults,
4006 bool add_ipc,
4007 bool reinit_globals)
4009 return lp_load_ex(pszFname,
4010 global_only,
4011 save_defaults,
4012 add_ipc,
4013 reinit_globals,
4014 true, /* allow_include_registry */
4015 false); /* load_all_shares*/
4018 bool lp_load_initial_only(const char *pszFname)
4020 return lp_load_ex(pszFname,
4021 true, /* global only */
4022 true, /* save_defaults */
4023 false, /* add_ipc */
4024 true, /* reinit_globals */
4025 false, /* allow_include_registry */
4026 false); /* load_all_shares*/
4030 * most common lp_load wrapper, loading only the globals
4032 * If this is used in a daemon or client utility it should be called
4033 * after processing popt.
4035 bool lp_load_global(const char *file_name)
4037 return lp_load(file_name,
4038 true, /* global_only */
4039 false, /* save_defaults */
4040 false, /* add_ipc */
4041 true); /* reinit_globals */
4045 * The typical lp_load wrapper with shares, loads global and
4046 * shares, including IPC, but does not force immediate
4047 * loading of all shares from registry.
4049 bool lp_load_with_shares(const char *file_name)
4051 return lp_load(file_name,
4052 false, /* global_only */
4053 false, /* save_defaults */
4054 true, /* add_ipc */
4055 true); /* reinit_globals */
4059 * lp_load wrapper, especially for clients
4061 bool lp_load_client(const char *file_name)
4063 lp_set_in_client(true);
4065 return lp_load_global(file_name);
4069 * lp_load wrapper, loading only globals, but intended
4070 * for subsequent calls, not reinitializing the globals
4071 * to default values
4073 bool lp_load_global_no_reinit(const char *file_name)
4075 return lp_load(file_name,
4076 true, /* global_only */
4077 false, /* save_defaults */
4078 false, /* add_ipc */
4079 false); /* reinit_globals */
4083 * lp_load wrapper, loading globals and shares,
4084 * intended for subsequent calls, i.e. not reinitializing
4085 * the globals to default values.
4087 bool lp_load_no_reinit(const char *file_name)
4089 return lp_load(file_name,
4090 false, /* global_only */
4091 false, /* save_defaults */
4092 false, /* add_ipc */
4093 false); /* reinit_globals */
4098 * lp_load wrapper, especially for clients, no reinitialization
4100 bool lp_load_client_no_reinit(const char *file_name)
4102 lp_set_in_client(true);
4104 return lp_load_global_no_reinit(file_name);
4107 bool lp_load_with_registry_shares(const char *pszFname)
4109 return lp_load_ex(pszFname,
4110 false, /* global_only */
4111 true, /* save_defaults */
4112 false, /* add_ipc */
4113 false, /* reinit_globals */
4114 true, /* allow_include_registry */
4115 true); /* load_all_shares*/
4118 /***************************************************************************
4119 Return the max number of services.
4120 ***************************************************************************/
4122 int lp_numservices(void)
4124 return (iNumServices);
4127 /***************************************************************************
4128 Display the contents of the services array in human-readable form.
4129 ***************************************************************************/
4131 void lp_dump(FILE *f, bool show_defaults, int maxtoprint)
4133 int iService;
4134 struct loadparm_context *lp_ctx;
4136 if (show_defaults)
4137 defaults_saved = false;
4139 lp_ctx = setup_lp_context(talloc_tos());
4140 if (lp_ctx == NULL) {
4141 return;
4144 lpcfg_dump_globals(lp_ctx, f, !defaults_saved);
4146 lpcfg_dump_a_service(&sDefault, &sDefault, f, flags_list, show_defaults);
4148 for (iService = 0; iService < maxtoprint; iService++) {
4149 fprintf(f,"\n");
4150 lp_dump_one(f, show_defaults, iService);
4154 /***************************************************************************
4155 Display the contents of one service in human-readable form.
4156 ***************************************************************************/
4158 void lp_dump_one(FILE * f, bool show_defaults, int snum)
4160 if (VALID(snum)) {
4161 if (ServicePtrs[snum]->szService[0] == '\0')
4162 return;
4163 lpcfg_dump_a_service(ServicePtrs[snum], &sDefault, f,
4164 flags_list, show_defaults);
4168 /***************************************************************************
4169 Return the number of the service with the given name, or -1 if it doesn't
4170 exist. Note that this is a DIFFERENT ANIMAL from the internal function
4171 getservicebyname()! This works ONLY if all services have been loaded, and
4172 does not copy the found service.
4173 ***************************************************************************/
4175 int lp_servicenumber(const char *pszServiceName)
4177 int iService;
4178 fstring serviceName;
4180 if (!pszServiceName) {
4181 return GLOBAL_SECTION_SNUM;
4184 for (iService = iNumServices - 1; iService >= 0; iService--) {
4185 if (VALID(iService) && ServicePtrs[iService]->szService) {
4187 * The substitution here is used to support %U in
4188 * service names
4190 fstrcpy(serviceName, ServicePtrs[iService]->szService);
4191 standard_sub_basic(get_current_username(),
4192 current_user_info.domain,
4193 serviceName,sizeof(serviceName));
4194 if (strequal(serviceName, pszServiceName)) {
4195 break;
4200 if (iService >= 0 && ServicePtrs[iService]->usershare == USERSHARE_VALID) {
4201 struct timespec last_mod;
4203 if (!usershare_exists(iService, &last_mod)) {
4204 /* Remove the share security tdb entry for it. */
4205 delete_share_security(lp_servicename(talloc_tos(), iService));
4206 /* Remove it from the array. */
4207 free_service_byindex(iService);
4208 /* Doesn't exist anymore. */
4209 return GLOBAL_SECTION_SNUM;
4212 /* Has it been modified ? If so delete and reload. */
4213 if (timespec_compare(&ServicePtrs[iService]->usershare_last_mod,
4214 &last_mod) < 0) {
4215 /* Remove it from the array. */
4216 free_service_byindex(iService);
4217 /* and now reload it. */
4218 iService = load_usershare_service(pszServiceName);
4222 if (iService < 0) {
4223 DEBUG(7,("lp_servicenumber: couldn't find %s\n", pszServiceName));
4224 return GLOBAL_SECTION_SNUM;
4227 return (iService);
4230 /*******************************************************************
4231 A useful volume label function.
4232 ********************************************************************/
4234 const char *volume_label(TALLOC_CTX *ctx, int snum)
4236 char *ret;
4237 const char *label = lp_volume(ctx, snum);
4238 if (!*label) {
4239 label = lp_servicename(ctx, snum);
4242 /* This returns a 33 byte guarenteed null terminated string. */
4243 ret = talloc_strndup(ctx, label, 32);
4244 if (!ret) {
4245 return "";
4247 return ret;
4250 /*******************************************************************
4251 Get the default server type we will announce as via nmbd.
4252 ********************************************************************/
4254 int lp_default_server_announce(void)
4256 int default_server_announce = 0;
4257 default_server_announce |= SV_TYPE_WORKSTATION;
4258 default_server_announce |= SV_TYPE_SERVER;
4259 default_server_announce |= SV_TYPE_SERVER_UNIX;
4261 /* note that the flag should be set only if we have a
4262 printer service but nmbd doesn't actually load the
4263 services so we can't tell --jerry */
4265 default_server_announce |= SV_TYPE_PRINTQ_SERVER;
4267 default_server_announce |= SV_TYPE_SERVER_NT;
4268 default_server_announce |= SV_TYPE_NT;
4270 switch (lp_server_role()) {
4271 case ROLE_DOMAIN_MEMBER:
4272 default_server_announce |= SV_TYPE_DOMAIN_MEMBER;
4273 break;
4274 case ROLE_DOMAIN_PDC:
4275 default_server_announce |= SV_TYPE_DOMAIN_CTRL;
4276 break;
4277 case ROLE_DOMAIN_BDC:
4278 default_server_announce |= SV_TYPE_DOMAIN_BAKCTRL;
4279 break;
4280 case ROLE_STANDALONE:
4281 default:
4282 break;
4284 if (lp_time_server())
4285 default_server_announce |= SV_TYPE_TIME_SOURCE;
4287 if (lp_host_msdfs())
4288 default_server_announce |= SV_TYPE_DFS_SERVER;
4290 return default_server_announce;
4293 /***********************************************************
4294 If we are PDC then prefer us as DMB
4295 ************************************************************/
4297 bool lp_domain_master(void)
4299 if (Globals._domain_master == Auto)
4300 return (lp_server_role() == ROLE_DOMAIN_PDC);
4302 return (bool)Globals._domain_master;
4305 /***********************************************************
4306 If we are PDC then prefer us as DMB
4307 ************************************************************/
4309 static bool lp_domain_master_true_or_auto(void)
4311 if (Globals._domain_master) /* auto or yes */
4312 return true;
4314 return false;
4317 /***********************************************************
4318 If we are DMB then prefer us as LMB
4319 ************************************************************/
4321 bool lp_preferred_master(void)
4323 int preferred_master = lp__preferred_master();
4325 if (preferred_master == Auto)
4326 return (lp_local_master() && lp_domain_master());
4328 return (bool)preferred_master;
4331 /*******************************************************************
4332 Remove a service.
4333 ********************************************************************/
4335 void lp_remove_service(int snum)
4337 ServicePtrs[snum]->valid = false;
4340 const char *lp_printername(TALLOC_CTX *ctx, int snum)
4342 const char *ret = lp__printername(ctx, snum);
4343 if (ret == NULL || *ret == '\0') {
4344 ret = lp_const_servicename(snum);
4347 return ret;
4351 /***********************************************************
4352 Allow daemons such as winbindd to fix their logfile name.
4353 ************************************************************/
4355 void lp_set_logfile(const char *name)
4357 lpcfg_string_set(Globals.ctx, &Globals.logfile, name);
4358 debug_set_logfile(name);
4361 /*******************************************************************
4362 Return the max print jobs per queue.
4363 ********************************************************************/
4365 int lp_maxprintjobs(int snum)
4367 int maxjobs = lp_max_print_jobs(snum);
4369 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
4370 maxjobs = PRINT_MAX_JOBID - 1;
4372 return maxjobs;
4375 const char *lp_printcapname(void)
4377 const char *printcap_name = lp_printcap_name();
4379 if ((printcap_name != NULL) &&
4380 (printcap_name[0] != '\0'))
4381 return printcap_name;
4383 if (sDefault.printing == PRINT_CUPS) {
4384 return "cups";
4387 if (sDefault.printing == PRINT_BSD)
4388 return "/etc/printcap";
4390 return PRINTCAP_NAME;
4393 static uint32_t spoolss_state;
4395 bool lp_disable_spoolss( void )
4397 if ( spoolss_state == SVCCTL_STATE_UNKNOWN )
4398 spoolss_state = lp__disable_spoolss() ? SVCCTL_STOPPED : SVCCTL_RUNNING;
4400 return spoolss_state == SVCCTL_STOPPED ? true : false;
4403 void lp_set_spoolss_state( uint32_t state )
4405 SMB_ASSERT( (state == SVCCTL_STOPPED) || (state == SVCCTL_RUNNING) );
4407 spoolss_state = state;
4410 uint32_t lp_get_spoolss_state( void )
4412 return lp_disable_spoolss() ? SVCCTL_STOPPED : SVCCTL_RUNNING;
4415 /*******************************************************************
4416 Ensure we don't use sendfile if server smb signing is active.
4417 ********************************************************************/
4419 bool lp_use_sendfile(int snum, struct smb_signing_state *signing_state)
4421 bool sign_active = false;
4423 /* Using sendfile blows the brains out of any DOS or Win9x TCP stack... JRA. */
4424 if (get_Protocol() < PROTOCOL_NT1) {
4425 return false;
4427 if (signing_state) {
4428 sign_active = smb_signing_is_active(signing_state);
4430 return (lp__use_sendfile(snum) &&
4431 (get_remote_arch() != RA_WIN95) &&
4432 !sign_active);
4435 /*******************************************************************
4436 Turn off sendfile if we find the underlying OS doesn't support it.
4437 ********************************************************************/
4439 void set_use_sendfile(int snum, bool val)
4441 if (LP_SNUM_OK(snum))
4442 ServicePtrs[snum]->_use_sendfile = val;
4443 else
4444 sDefault._use_sendfile = val;
4447 void lp_set_mangling_method(const char *new_method)
4449 lpcfg_string_set(Globals.ctx, &Globals.mangling_method, new_method);
4452 /*******************************************************************
4453 Global state for POSIX pathname processing.
4454 ********************************************************************/
4456 static bool posix_pathnames;
4458 bool lp_posix_pathnames(void)
4460 return posix_pathnames;
4463 /*******************************************************************
4464 Change everything needed to ensure POSIX pathname processing (currently
4465 not much).
4466 ********************************************************************/
4468 void lp_set_posix_pathnames(void)
4470 posix_pathnames = true;
4473 /*******************************************************************
4474 Global state for POSIX lock processing - CIFS unix extensions.
4475 ********************************************************************/
4477 bool posix_default_lock_was_set;
4478 static enum brl_flavour posix_cifsx_locktype; /* By default 0 == WINDOWS_LOCK */
4480 enum brl_flavour lp_posix_cifsu_locktype(files_struct *fsp)
4482 if (posix_default_lock_was_set) {
4483 return posix_cifsx_locktype;
4484 } else {
4485 return (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) ?
4486 POSIX_LOCK : WINDOWS_LOCK;
4490 /*******************************************************************
4491 ********************************************************************/
4493 void lp_set_posix_default_cifsx_readwrite_locktype(enum brl_flavour val)
4495 posix_default_lock_was_set = true;
4496 posix_cifsx_locktype = val;
4499 int lp_min_receive_file_size(void)
4501 int min_receivefile_size = lp_min_receivefile_size();
4503 if (min_receivefile_size < 0) {
4504 return 0;
4506 return min_receivefile_size;
4509 /*******************************************************************
4510 Safe wide links checks.
4511 This helper function always verify the validity of wide links,
4512 even after a configuration file reload.
4513 ********************************************************************/
4515 void widelinks_warning(int snum)
4517 if (lp_allow_insecure_wide_links()) {
4518 return;
4521 if (lp_unix_extensions() && lp_wide_links(snum)) {
4522 DEBUG(0,("Share '%s' has wide links and unix extensions enabled. "
4523 "These parameters are incompatible. "
4524 "Wide links will be disabled for this share.\n",
4525 lp_servicename(talloc_tos(), snum) ));
4529 bool lp_widelinks(int snum)
4531 /* wide links is always incompatible with unix extensions */
4532 if (lp_unix_extensions()) {
4534 * Unless we have "allow insecure widelinks"
4535 * turned on.
4537 if (!lp_allow_insecure_wide_links()) {
4538 return false;
4542 return lp_wide_links(snum);
4545 int lp_server_role(void)
4547 return lp_find_server_role(lp__server_role(),
4548 lp__security(),
4549 lp__domain_logons(),
4550 lp_domain_master_true_or_auto());
4553 int lp_security(void)
4555 return lp_find_security(lp__server_role(),
4556 lp__security());
4559 int lp_client_max_protocol(void)
4561 int client_max_protocol = lp__client_max_protocol();
4562 if (client_max_protocol == PROTOCOL_DEFAULT) {
4563 return PROTOCOL_LATEST;
4565 return client_max_protocol;
4568 int lp_client_ipc_min_protocol(void)
4570 int client_ipc_min_protocol = lp__client_ipc_min_protocol();
4571 if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
4572 client_ipc_min_protocol = lp_client_min_protocol();
4574 if (client_ipc_min_protocol < PROTOCOL_NT1) {
4575 return PROTOCOL_NT1;
4577 return client_ipc_min_protocol;
4580 int lp_client_ipc_max_protocol(void)
4582 int client_ipc_max_protocol = lp__client_ipc_max_protocol();
4583 if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
4584 return PROTOCOL_LATEST;
4586 if (client_ipc_max_protocol < PROTOCOL_NT1) {
4587 return PROTOCOL_NT1;
4589 return client_ipc_max_protocol;
4592 int lp_client_ipc_signing(void)
4594 int client_ipc_signing = lp__client_ipc_signing();
4595 if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
4596 return SMB_SIGNING_REQUIRED;
4598 return client_ipc_signing;
4601 int lp_rpc_low_port(void)
4603 return Globals.rpc_low_port;
4606 int lp_rpc_high_port(void)
4608 return Globals.rpc_high_port;
4612 * Do not allow LanMan auth if unless NTLMv1 is also allowed
4614 * This also ensures it is disabled if NTLM is totally disabled
4616 bool lp_lanman_auth(void)
4618 enum ntlm_auth_level ntlm_auth_level = lp_ntlm_auth();
4620 if (ntlm_auth_level == NTLM_AUTH_ON) {
4621 return lp__lanman_auth();
4622 } else {
4623 return false;
4627 struct loadparm_global * get_globals(void)
4629 return &Globals;
4632 unsigned int * get_flags(void)
4634 if (flags_list == NULL) {
4635 flags_list = talloc_zero_array(NULL, unsigned int, num_parameters());
4638 return flags_list;