1996-05-04 11:50:46 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1996-05-04 11:50:46 +04:00
Parameter loading functions
1998-01-22 16:27:43 +03:00
Copyright ( C ) Karl Auer 1993 - 1998
1996-05-04 11:50:46 +04:00
Largely re - written by Andrew Tridgell , September 1994
2001-07-25 00:02:48 +04:00
Copyright ( C ) Simo Sorce 2001
2002-07-15 14:35:28 +04:00
Copyright ( C ) Alexander Bokovoy 2002
2003-01-14 13:47:56 +03:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2002
2003-08-01 19:30:44 +04:00
Copyright ( C ) Jim McDonough < jmcd @ us . ibm . com > 2003
2008-01-16 19:15:08 +03:00
Copyright ( C ) Michael Adam 2008
2011-06-29 03:52:46 +04:00
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2007
Copyright ( C ) Andrew Bartlett 2011
2009-11-21 18:17:16 +03:00
1996-05-04 11:50:46 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1996-05-04 11:50:46 +04:00
( at your option ) any later version .
2009-11-21 18:17:16 +03:00
1996-05-04 11:50:46 +04:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2009-11-21 18:17:16 +03:00
1996-05-04 11:50:46 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1996-05-04 11:50:46 +04:00
*/
/*
* Load parameters .
*
* This module provides suitable callback functions for the params
* module . It builds the internal table of service details which is
* then used by the rest of the server .
*
* To add a parameter :
*
* 1 ) add it to the global or service structure definition
* 2 ) add it to the parm_table
* 3 ) add it to the list of available functions ( eg : using FN_GLOBAL_STRING ( ) )
* 4 ) If it ' s a global then initialise it in init_globals . If a local
* ( ie . service ) parameter then initialise it in the sDefault structure
*
*
* Notes :
* The configuration file is processed sequentially for speed . It is NOT
* accessed randomly as happens in ' real ' Windows . For this reason , there
* is a fair bit of sequence - dependent code here - ie . , code which assumes
* that certain things happen before others . In particular , the code which
* happens at the boundary between sections is delicately poised , so be
* careful !
*
*/
# include "includes.h"
2011-02-26 01:20:06 +03:00
# include "system/filesys.h"
2011-05-05 13:25:29 +04:00
# include "util_tdb.h"
2012-07-23 06:47:01 +04:00
# include "lib/param/loadparm.h"
2014-01-15 04:39:14 +04:00
# include "lib/param/param.h"
2008-09-24 03:54:05 +04:00
# include "printing.h"
2010-05-18 04:27:34 +04:00
# include "lib/smbconf/smbconf.h"
# include "lib/smbconf/smbconf_init.h"
1996-05-04 11:50:46 +04:00
2010-07-02 02:32:52 +04:00
# include "ads.h"
2010-08-03 01:23:12 +04:00
# include "../librpc/gen_ndr/svcctl.h"
2011-02-14 14:02:00 +03:00
# include "intl.h"
2011-10-24 18:50:19 +04:00
# include "../libcli/smb/smb_signing.h"
2011-07-07 19:42:08 +04:00
# include "dbwrap/dbwrap.h"
2011-08-16 18:20:14 +04:00
# include "dbwrap/dbwrap_rbt.h"
2011-07-07 15:04:31 +04:00
# include "../lib/util/bitmap.h"
2010-08-17 17:03:58 +04:00
2009-09-15 08:48:49 +04:00
# ifdef HAVE_SYS_SYSCTL_H
# include <sys/sysctl.h>
# endif
2009-03-27 15:05:00 +03:00
# ifdef HAVE_HTTPCONNECTENCRYPT
# include <cups/http.h>
# endif
2012-03-30 17:37:33 +04:00
# ifdef CLUSTER_SUPPORT
# include "ctdb_private.h"
# endif
2011-06-29 09:06:49 +04:00
bool bLoaded = false ;
1996-05-04 11:50:46 +04:00
2006-07-11 22:01:26 +04:00
extern userdom_struct current_user_info ;
1996-05-04 11:50:46 +04:00
2008-04-07 00:23:54 +04:00
/* the special value for the include parameter
* to be interpreted not as a file name but to
* trigger loading of the global smb . conf options
* from registry . */
# ifndef INCLUDE_REGISTRY_NAME
# define INCLUDE_REGISTRY_NAME "registry"
# endif
2011-06-29 09:06:49 +04:00
static bool in_client = false ; /* Not in the client by default */
2008-03-19 01:29:11 +03:00
static struct smbconf_csn conf_last_csn ;
2007-06-16 01:38:10 +04:00
2008-01-16 18:18:28 +03:00
static int config_backend = CONFIG_BACKEND_FILE ;
1996-05-04 11:50:46 +04:00
/* some helpful bits */
2005-10-23 20:29:02 +04:00
# define LP_SNUM_OK(i) (((i) >= 0) && ((i) < iNumServices) && (ServicePtrs != NULL) && ServicePtrs[(i)]->valid)
2005-04-01 00:28:47 +04:00
# define VALID(i) (ServicePtrs != NULL && ServicePtrs[i]->valid)
1996-05-04 11:50:46 +04:00
2006-02-04 01:19:41 +03:00
# define USERSHARE_VALID 1
# define USERSHARE_PENDING_DELETE 2
2011-06-29 09:06:49 +04:00
static bool defaults_saved = false ;
1998-03-14 11:27:41 +03:00
2011-07-01 08:36:25 +04:00
# define LOADPARM_EXTRA_GLOBALS \
2011-07-08 03:18:09 +04:00
struct parmlist_entry * param_opt ; \
2013-12-24 07:04:04 +04:00
char * realm_original ; \
2012-07-23 05:43:54 +04:00
char * loglevel ; \
2011-07-01 08:36:25 +04:00
int iminreceivefile ; \
char * szPrintcapname ; \
int CupsEncrypt ; \
int iPreferredMaster ; \
char * szLdapMachineSuffix ; \
char * szLdapUserSuffix ; \
char * szLdapIdmapSuffix ; \
char * szLdapGroupSuffix ; \
char * szStateDir ; \
char * szCacheDir ; \
char * szUsershareTemplateShare ; \
char * szIdmapUID ; \
char * szIdmapGID ; \
2013-01-28 17:35:53 +04:00
char * szIdmapBackend ; \
2011-07-01 08:36:25 +04:00
int winbindMaxDomainConnections ; \
2012-07-23 05:40:21 +04:00
int ismb2_max_credits ; \
char * tls_keyfile ; \
char * tls_certfile ; \
char * tls_cafile ; \
char * tls_crlfile ; \
char * tls_dhpfile ; \
int bPreferredMaster ;
1996-05-04 11:50:46 +04:00
2011-07-01 08:36:25 +04:00
# include "param/param_global.h"
static struct loadparm_global Globals ;
1996-05-04 11:50:46 +04:00
/* This is a default service used to prime a services structure */
2011-06-29 09:03:24 +04:00
static struct loadparm_service sDefault =
{
. valid = true ,
. autoloaded = false ,
. usershare = 0 ,
. usershare_last_mod = { 0 , 0 } ,
. szService = NULL ,
2013-12-24 07:03:16 +04:00
. pathname = NULL ,
2013-12-24 07:03:21 +04:00
. username = NULL ,
2013-12-24 07:03:21 +04:00
. invalid_users = NULL ,
2013-12-24 07:03:22 +04:00
. valid_users = NULL ,
2013-12-24 07:03:22 +04:00
. admin_users = NULL ,
2011-06-29 09:03:24 +04:00
. szCopy = NULL ,
. szInclude = NULL ,
2013-12-24 07:03:20 +04:00
. preexec = NULL ,
2013-12-24 07:03:20 +04:00
. postexec = NULL ,
2013-12-24 07:03:20 +04:00
. rootpreexec = NULL ,
2013-12-24 07:03:21 +04:00
. rootpostexec = NULL ,
2013-12-24 07:03:41 +04:00
. cups_options = NULL ,
2013-12-24 07:03:22 +04:00
. printcommand = NULL ,
2013-12-24 07:03:22 +04:00
. lpqcommand = NULL ,
2013-12-24 07:03:22 +04:00
. lprmcommand = NULL ,
2013-12-24 07:03:23 +04:00
. lppausecommand = NULL ,
2013-12-24 07:03:23 +04:00
. lpresumecommand = NULL ,
2013-12-24 07:03:23 +04:00
. queuepausecommand = NULL ,
2013-12-24 07:03:23 +04:00
. queueresumecommand = NULL ,
2011-06-29 09:03:24 +04:00
. szPrintername = NULL ,
2013-12-24 07:03:24 +04:00
. printjob_username = NULL ,
2013-12-24 07:03:21 +04:00
. dontdescend = NULL ,
2013-12-24 07:03:16 +04:00
. hostsallow = NULL ,
2013-12-24 07:03:16 +04:00
. hostsdeny = NULL ,
2013-12-24 07:03:24 +04:00
. magicscript = NULL ,
2013-12-24 07:03:24 +04:00
. magicoutput = NULL ,
2013-12-24 07:03:26 +04:00
. veto_files = NULL ,
2013-12-24 07:03:26 +04:00
. hide_files = NULL ,
2013-12-24 07:03:26 +04:00
. veto_oplocks = NULL ,
2011-06-29 09:03:24 +04:00
. comment = NULL ,
. force_user = NULL ,
. force_group = NULL ,
. readlist = NULL ,
. writelist = NULL ,
. volume = NULL ,
. fstype = NULL ,
2013-12-24 07:03:25 +04:00
. vfs_objects = NULL ,
2013-12-24 07:03:25 +04:00
. msdfs_proxy = NULL ,
2013-12-24 07:03:26 +04:00
. aio_write_behind = NULL ,
2013-12-24 07:03:27 +04:00
. dfree_command = NULL ,
2013-12-24 07:03:38 +04:00
. minprintspace = 0 ,
2011-06-29 09:03:24 +04:00
. iMaxPrintJobs = 1000 ,
2013-12-24 07:03:39 +04:00
. max_reported_jobs = 0 ,
2013-12-24 07:03:39 +04:00
. write_cache_size = 0 ,
2013-12-24 07:03:19 +04:00
. create_mask = 0744 ,
2013-12-24 07:03:19 +04:00
. force_create_mode = 0 ,
2013-12-24 07:03:20 +04:00
. dir_mask = 0755 ,
2013-12-24 07:03:20 +04:00
. force_dir_mode = 0 ,
2013-12-24 07:03:19 +04:00
. max_connections = 0 ,
2013-12-24 07:03:38 +04:00
. defaultcase = CASE_LOWER ,
2013-12-24 07:03:38 +04:00
. printing = DEFAULT_PRINTING ,
2013-12-24 07:03:39 +04:00
. oplock_contention_limit = 2 ,
2013-12-24 07:03:19 +04:00
. csc_policy = 0 ,
2013-12-24 07:03:39 +04:00
. block_size = 1024 ,
2013-12-24 07:03:39 +04:00
. dfree_cache_time = 0 ,
2013-12-24 07:03:27 +04:00
. preexec_close = false ,
2013-12-24 07:03:27 +04:00
. rootpreexec_close = false ,
2013-12-24 07:03:28 +04:00
. casesensitive = Auto ,
2013-12-24 07:03:28 +04:00
. preservecase = true ,
2013-12-24 07:03:28 +04:00
. shortpreservecase = true ,
2013-12-24 07:03:28 +04:00
. hide_dot_files = true ,
2013-12-24 07:03:28 +04:00
. hide_special_files = false ,
2013-12-24 07:03:29 +04:00
. hideunreadable = false ,
2013-12-24 07:03:29 +04:00
. hideunwriteable_files = false ,
2013-12-24 07:03:17 +04:00
. browseable = true ,
2013-12-24 07:03:29 +04:00
. access_based_share_enum = false ,
2011-06-29 09:03:24 +04:00
. bAvailable = true ,
2013-12-24 07:03:17 +04:00
. readonly = true ,
2013-12-24 07:03:29 +04:00
. guest_only = false ,
2013-12-24 07:03:30 +04:00
. administrative_share = false ,
2013-12-24 07:03:29 +04:00
. guest_ok = false ,
2013-12-24 07:03:18 +04:00
. print_ok = false ,
2013-12-24 07:03:30 +04:00
. print_notify_backchannel = false ,
2013-12-24 07:03:19 +04:00
. map_system = false ,
2013-12-24 07:03:18 +04:00
. map_hidden = false ,
2013-12-24 07:03:18 +04:00
. map_archive = true ,
2013-12-24 07:03:30 +04:00
. store_dos_attributes = false ,
2013-12-24 07:03:30 +04:00
. dmapi_support = false ,
2013-12-24 07:03:30 +04:00
. locking = true ,
2013-12-24 07:03:31 +04:00
. strict_locking = Auto ,
2013-12-24 07:03:31 +04:00
. posix_locking = true ,
2013-12-24 07:03:18 +04:00
. oplocks = true ,
2013-12-24 07:03:31 +04:00
. kernel_oplocks = false ,
2013-12-24 07:03:31 +04:00
. level2_oplocks = true ,
2013-12-24 07:03:32 +04:00
. onlyuser = false ,
2013-12-24 07:03:32 +04:00
. manglednames = true ,
2011-06-29 09:03:24 +04:00
. bWidelinks = false ,
2013-12-24 07:03:32 +04:00
. symlinks = true ,
2013-12-24 07:03:32 +04:00
. syncalways = false ,
2013-12-24 07:03:32 +04:00
. strict_allocate = false ,
2013-12-24 07:03:18 +04:00
. strict_sync = false ,
2013-12-24 07:03:41 +04:00
. magicchar = ' ~ ' ,
2011-06-29 09:03:24 +04:00
. copymap = NULL ,
2013-12-24 07:03:33 +04:00
. delete_readonly = false ,
2013-12-24 07:03:33 +04:00
. fake_oplocks = false ,
2013-12-24 07:03:33 +04:00
. recursive_veto_delete = false ,
2013-12-24 07:03:33 +04:00
. dos_filemode = false ,
2013-12-24 07:03:33 +04:00
. dos_filetimes = true ,
2013-12-24 07:03:34 +04:00
. dos_filetime_resolution = false ,
2013-12-24 07:03:34 +04:00
. fake_dir_create_times = false ,
2013-12-24 07:03:34 +04:00
. blocking_locks = true ,
2013-12-24 07:03:34 +04:00
. inherit_perms = false ,
2013-12-24 07:03:35 +04:00
. inherit_acls = false ,
2013-12-24 07:03:35 +04:00
. inherit_owner = false ,
2013-12-24 07:03:17 +04:00
. msdfs_root = false ,
2013-12-24 07:03:35 +04:00
. use_client_driver = false ,
2013-12-24 07:03:35 +04:00
. default_devmode = true ,
2013-12-24 07:03:35 +04:00
. force_printername = false ,
2013-12-24 07:03:36 +04:00
. nt_acl_support = true ,
2013-12-24 07:03:36 +04:00
. force_unknown_acl_user = false ,
2013-12-24 07:03:36 +04:00
. _use_sendfile = false ,
2013-12-24 07:03:36 +04:00
. profile_acls = false ,
2013-12-24 07:03:37 +04:00
. map_acl_inherit = false ,
2013-12-24 07:03:37 +04:00
. afs_share = false ,
2013-12-24 07:03:36 +04:00
. ea_support = false ,
2013-12-24 07:03:37 +04:00
. acl_check_permissions = true ,
2013-12-24 07:03:37 +04:00
. acl_map_full_control = true ,
2013-12-24 07:03:37 +04:00
. acl_group_control = false ,
2013-12-24 07:03:38 +04:00
. acl_allow_execute_always = false ,
2013-12-24 07:03:41 +04:00
. change_notify = true ,
2013-12-24 07:03:41 +04:00
. kernel_change_notify = true ,
2013-12-24 07:03:40 +04:00
. allocation_roundup_size = SMB_ROUNDUP_ALLOCATION_SIZE ,
2013-12-24 07:03:40 +04:00
. aio_read_size = 0 ,
2013-12-24 07:03:40 +04:00
. aio_write_size = 0 ,
2013-12-24 07:03:40 +04:00
. map_readonly = MAP_READONLY_YES ,
2007-08-24 01:53:00 +04:00
# ifdef BROKEN_DIRECTORY_HANDLING
2013-12-24 07:03:40 +04:00
. directory_name_cache_size = 0 ,
2007-08-24 01:53:00 +04:00
# else
2013-12-24 07:03:40 +04:00
. directory_name_cache_size = 100 ,
2007-08-24 01:53:00 +04:00
# endif
2013-12-24 07:03:41 +04:00
. smb_encrypt = SMB_SIGNING_DEFAULT ,
2013-12-24 07:03:31 +04:00
. kernel_share_modes = true ,
2013-12-24 07:03:42 +04:00
. durable_handles = true ,
2011-06-29 09:03:24 +04:00
. param_opt = NULL ,
. dummy = " "
1996-05-04 11:50:46 +04:00
} ;
/* local variables */
2011-06-28 04:06:05 +04:00
static struct loadparm_service * * ServicePtrs = NULL ;
1996-05-04 11:50:46 +04:00
static int iNumServices = 0 ;
static int iServiceIndex = 0 ;
2007-11-24 21:56:41 +03:00
static struct db_context * ServiceHash ;
2011-06-29 09:05:37 +04:00
static bool bInGlobalSection = true ;
2011-06-29 09:06:49 +04:00
static bool bGlobalOnly = false ;
1996-05-04 11:50:46 +04:00
# define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
/* prototypes for the special type handlers */
2011-06-29 07:18:57 +04:00
static bool handle_include ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_copy ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_idmap_backend ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_idmap_uid ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_idmap_gid ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_debug_list ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_realm ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_netbios_aliases ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_charset ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_dos_charset ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_printing ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
static bool handle_ldap_debug_level ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr ) ;
2002-10-23 05:22:32 +04:00
2012-07-27 04:01:44 +04:00
/* these are parameter handlers which are not needed in the
* source3 code
*/
# define handle_logfile NULL
2003-06-08 16:49:31 +04:00
static void set_allowed_client_auth ( void ) ;
1997-08-05 05:31:55 +04:00
2009-05-06 04:08:33 +04:00
static void add_to_file_list ( const char * fname , const char * subfname ) ;
2010-08-11 07:35:14 +04:00
static bool lp_set_cmdline_helper ( const char * pszParmName , const char * pszParmValue , bool store_values ) ;
2011-07-26 06:19:58 +04:00
static void free_param_opts ( struct parmlist_entry * * popts ) ;
2009-05-06 04:08:33 +04:00
2012-07-23 06:35:02 +04:00
# include "lib/param/param_table.c"
1997-11-22 10:09:12 +03:00
2012-07-23 09:21:39 +04:00
/* this is used to prevent lots of mallocs of size 1 */
static const char null_string [ ] = " " ;
/**
Set a string value , allocing the space for the string
* */
static bool string_init ( char * * dest , const char * src )
{
size_t l ;
if ( ! src )
src = " " ;
l = strlen ( src ) ;
if ( l = = 0 ) {
* dest = discard_const_p ( char , null_string ) ;
} else {
( * dest ) = SMB_STRDUP ( src ) ;
if ( ( * dest ) = = NULL ) {
DEBUG ( 0 , ( " Out of memory in string_init \n " ) ) ;
return false ;
}
}
return ( true ) ;
}
/**
Free a string value .
* */
static void string_free ( char * * s )
{
if ( ! s | | ! ( * s ) )
return ;
if ( * s = = null_string )
* s = NULL ;
SAFE_FREE ( * s ) ;
}
/**
Set a string value , deallocating any existing space , and allocing the space
for the string
* */
static bool string_set ( char * * dest , const char * src )
{
string_free ( dest ) ;
return ( string_init ( dest , src ) ) ;
}
2000-09-20 02:32:56 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Initialise the sDefault parameter structure for the printer values .
2000-09-20 02:32:56 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-28 04:06:05 +04:00
static void init_printer_values ( struct loadparm_service * pService )
2000-09-20 02:32:56 +04:00
{
/* choose defaults depending on the type of printing */
2013-12-24 07:03:38 +04:00
switch ( pService - > printing ) {
2000-09-20 02:32:56 +04:00
case PRINT_BSD :
case PRINT_AIX :
2000-10-07 04:48:27 +04:00
case PRINT_LPRNT :
case PRINT_LPROS2 :
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lpqcommand , " lpq -P'%p' " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lprmcommand , " lprm -P'%p' %j " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > printcommand , " lpr -r -P'%p' %s " ) ;
2000-09-20 02:32:56 +04:00
break ;
case PRINT_LPRNG :
case PRINT_PLP :
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lpqcommand , " lpq -P'%p' " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lprmcommand , " lprm -P'%p' %j " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > printcommand , " lpr -r -P'%p' %s " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queuepausecommand , " lpc stop '%p' " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queueresumecommand , " lpc start '%p' " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lppausecommand , " lpc hold '%p' %j " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lpresumecommand , " lpc release '%p' %j " ) ;
2000-09-20 02:32:56 +04:00
break ;
case PRINT_CUPS :
2005-09-21 03:28:22 +04:00
case PRINT_IPRINT :
2005-02-12 17:41:00 +03:00
/* set the lpq command to contain the destination printer
name only . This is used by cups_queue_get ( ) */
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lpqcommand , " %p " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lprmcommand , " " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > printcommand , " " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lppausecommand , " " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lpresumecommand , " " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queuepausecommand , " " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queueresumecommand , " " ) ;
2000-09-20 02:32:56 +04:00
break ;
case PRINT_SYSV :
case PRINT_HPUX :
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lpqcommand , " lpstat -o%p " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lprmcommand , " cancel %p-%j " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > printcommand , " lp -c -d%p %s; rm %s " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queuepausecommand , " disable %p " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queueresumecommand , " enable %p " ) ;
2000-09-20 02:32:56 +04:00
# ifndef HPUX
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lppausecommand , " lp -i %p-%j -H hold " ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lpresumecommand , " lp -i %p-%j -H resume " ) ;
2002-10-01 17:10:57 +04:00
# endif /* HPUX */
2000-09-20 02:32:56 +04:00
break ;
case PRINT_QNX :
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lpqcommand , " lpq -P%p " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lprmcommand , " lprm -P%p %j " ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > printcommand , " lp -r -P%p %s " ) ;
2000-09-20 02:32:56 +04:00
break ;
2012-08-21 02:16:24 +04:00
# if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2011-03-16 00:51:58 +03:00
2000-11-14 18:26:53 +03:00
case PRINT_TEST :
2011-04-02 20:51:55 +04:00
case PRINT_VLP : {
const char * tdbfile ;
2012-07-18 09:37:23 +04:00
TALLOC_CTX * tmp_ctx = talloc_stackframe ( ) ;
2011-04-02 20:51:55 +04:00
char * tmp ;
tdbfile = talloc_asprintf (
2012-07-18 09:37:23 +04:00
tmp_ctx , " tdbfile=%s " ,
2011-04-02 20:51:55 +04:00
lp_parm_const_string ( - 1 , " vlp " , " tdbfile " ,
" /tmp/vlp.tdb " ) ) ;
if ( tdbfile = = NULL ) {
tdbfile = " tdbfile=/tmp/vlp.tdb " ;
}
2012-07-18 09:37:23 +04:00
tmp = talloc_asprintf ( tmp_ctx , " vlp %s print %%p %%s " ,
2011-04-02 20:51:55 +04:00
tdbfile ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > printcommand ,
2011-04-02 20:51:55 +04:00
tmp ? tmp : " vlp print %p %s " ) ;
2012-07-18 09:37:23 +04:00
tmp = talloc_asprintf ( tmp_ctx , " vlp %s lpq %%p " ,
2011-04-02 20:51:55 +04:00
tdbfile ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lpqcommand ,
2011-04-02 20:51:55 +04:00
tmp ? tmp : " vlp lpq %p " ) ;
2012-07-18 09:37:23 +04:00
tmp = talloc_asprintf ( tmp_ctx , " vlp %s lprm %%p %%j " ,
2011-04-02 20:51:55 +04:00
tdbfile ) ;
2013-12-24 07:03:22 +04:00
string_set ( & pService - > lprmcommand ,
2011-04-02 20:51:55 +04:00
tmp ? tmp : " vlp lprm %p %j " ) ;
2012-07-18 09:37:23 +04:00
tmp = talloc_asprintf ( tmp_ctx , " vlp %s lppause %%p %%j " ,
2011-04-02 20:51:55 +04:00
tdbfile ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lppausecommand ,
2011-04-02 20:51:55 +04:00
tmp ? tmp : " vlp lppause %p %j " ) ;
2012-07-18 09:37:23 +04:00
tmp = talloc_asprintf ( tmp_ctx , " vlp %s lpresume %%p %%j " ,
2011-04-02 20:51:55 +04:00
tdbfile ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > lpresumecommand ,
2011-04-02 20:51:55 +04:00
tmp ? tmp : " vlp lpresume %p %j " ) ;
2012-07-18 09:37:23 +04:00
tmp = talloc_asprintf ( tmp_ctx , " vlp %s queuepause %%p " ,
2011-04-02 20:51:55 +04:00
tdbfile ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queuepausecommand ,
2011-04-02 20:51:55 +04:00
tmp ? tmp : " vlp queuepause %p " ) ;
2012-07-18 09:37:23 +04:00
tmp = talloc_asprintf ( tmp_ctx , " vlp %s queueresume %%p " ,
2011-04-02 20:51:55 +04:00
tdbfile ) ;
2013-12-24 07:03:23 +04:00
string_set ( & pService - > queueresumecommand ,
2011-04-02 20:51:55 +04:00
tmp ? tmp : " vlp queueresume %p " ) ;
2012-07-18 09:37:23 +04:00
TALLOC_FREE ( tmp_ctx ) ;
2011-04-02 20:51:55 +04:00
2000-11-14 18:26:53 +03:00
break ;
2011-04-02 20:51:55 +04:00
}
2000-11-14 18:26:53 +03:00
# endif /* DEVELOPER */
2000-09-20 02:32:56 +04:00
}
}
2009-02-19 20:33:30 +03:00
/**
* Function to return the default value for the maximum number of open
* file descriptors permitted . This function tries to consult the
* kernel - level ( sysctl ) and ulimit ( getrlimit ( ) ) values and goes
* the smaller of those .
*/
static int max_open_files ( void )
{
2009-02-21 14:49:01 +03:00
int sysctl_max = MAX_OPEN_FILES ;
2009-02-23 08:55:25 +03:00
int rlimit_max = MAX_OPEN_FILES ;
2009-02-19 20:33:30 +03:00
# ifdef HAVE_SYSCTLBYNAME
2009-02-23 08:55:25 +03:00
{
size_t size = sizeof ( sysctl_max ) ;
sysctlbyname ( " kern.maxfilesperproc " , & sysctl_max , & size , NULL ,
0 ) ;
}
2009-02-19 20:33:30 +03:00
# endif
2009-02-23 08:55:25 +03:00
# if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
{
2009-03-04 14:21:26 +03:00
struct rlimit rl ;
ZERO_STRUCT ( rl ) ;
2009-02-23 08:55:25 +03:00
if ( getrlimit ( RLIMIT_NOFILE , & rl ) = = 0 )
rlimit_max = rl . rlim_cur ;
2009-02-19 20:33:30 +03:00
2009-02-23 08:55:25 +03:00
# if defined(RLIM_INFINITY)
if ( rl . rlim_cur = = RLIM_INFINITY )
rlimit_max = MAX_OPEN_FILES ;
# endif
2011-01-19 18:13:42 +03:00
}
2009-02-23 08:55:25 +03:00
# endif
2009-12-02 21:01:14 +03:00
if ( sysctl_max < MIN_OPEN_FILES_WINDOWS ) {
2011-01-02 11:40:09 +03:00
DEBUG ( 2 , ( " max_open_files: increasing sysctl_max (%d) to "
2009-12-02 21:01:14 +03:00
" minimum Windows limit (%d) \n " ,
sysctl_max ,
MIN_OPEN_FILES_WINDOWS ) ) ;
sysctl_max = MIN_OPEN_FILES_WINDOWS ;
}
if ( rlimit_max < MIN_OPEN_FILES_WINDOWS ) {
2011-01-02 11:40:09 +03:00
DEBUG ( 2 , ( " rlimit_max: increasing rlimit_max (%d) to "
2009-12-02 21:01:14 +03:00
" minimum Windows limit (%d) \n " ,
rlimit_max ,
MIN_OPEN_FILES_WINDOWS ) ) ;
rlimit_max = MIN_OPEN_FILES_WINDOWS ;
}
2009-02-23 08:55:25 +03:00
return MIN ( sysctl_max , rlimit_max ) ;
2009-02-19 20:33:30 +03:00
}
1996-05-04 11:50:46 +04:00
2008-12-15 16:38:51 +03:00
/**
* Common part of freeing allocated data for one parameter .
*/
static void free_one_parameter_common ( void * parm_ptr ,
struct parm_struct parm )
{
if ( ( parm . type = = P_STRING ) | |
( parm . type = = P_USTRING ) )
{
string_free ( ( char * * ) parm_ptr ) ;
} else if ( parm . type = = P_LIST ) {
TALLOC_FREE ( * ( ( char * * * ) parm_ptr ) ) ;
}
}
/**
* Free the allocated data for one parameter for a share
* given as a service struct .
*/
2011-06-28 04:06:05 +04:00
static void free_one_parameter ( struct loadparm_service * service ,
2008-12-15 16:38:51 +03:00
struct parm_struct parm )
{
void * parm_ptr ;
if ( parm . p_class ! = P_LOCAL ) {
return ;
}
2011-06-29 03:52:46 +04:00
parm_ptr = lp_parm_ptr ( service , & parm ) ;
2008-12-15 16:38:51 +03:00
free_one_parameter_common ( parm_ptr , parm ) ;
}
/**
* Free the allocated parameter data of a share given
* as a service struct .
*/
2011-06-28 04:06:05 +04:00
static void free_parameters ( struct loadparm_service * service )
2008-12-15 16:38:51 +03:00
{
uint32_t i ;
for ( i = 0 ; parm_table [ i ] . label ; i + + ) {
free_one_parameter ( service , parm_table [ i ] ) ;
}
}
2008-12-15 16:28:03 +03:00
2008-09-28 00:19:56 +04:00
/**
2008-12-15 16:28:03 +03:00
* Free the allocated data for one parameter for a given share
* specified by an snum .
2008-09-28 00:19:56 +04:00
*/
2008-12-15 16:28:03 +03:00
static void free_one_parameter_by_snum ( int snum , struct parm_struct parm )
2008-09-28 00:19:56 +04:00
{
void * parm_ptr ;
if ( snum < 0 ) {
2011-06-29 03:52:46 +04:00
parm_ptr = lp_parm_ptr ( NULL , & parm ) ;
2008-09-28 00:19:56 +04:00
} else if ( parm . p_class ! = P_LOCAL ) {
return ;
} else {
2011-06-29 03:52:46 +04:00
parm_ptr = lp_local_ptr_by_snum ( snum , & parm ) ;
2008-09-28 00:19:56 +04:00
}
2008-12-15 16:38:51 +03:00
free_one_parameter_common ( parm_ptr , parm ) ;
2008-09-28 00:19:56 +04:00
}
/**
2008-12-15 16:29:34 +03:00
* Free the allocated parameter data for a share specified
* by an snum .
2008-09-28 00:19:56 +04:00
*/
2008-12-15 16:29:34 +03:00
static void free_parameters_by_snum ( int snum )
2008-09-28 00:19:56 +04:00
{
uint32_t i ;
for ( i = 0 ; parm_table [ i ] . label ; i + + ) {
2008-12-15 16:28:03 +03:00
free_one_parameter_by_snum ( snum , parm_table [ i ] ) ;
2008-09-28 00:19:56 +04:00
}
}
/**
* Free the allocated global parameters .
*/
static void free_global_parameters ( void )
{
2011-07-26 06:19:58 +04:00
free_param_opts ( & Globals . param_opt ) ;
2008-12-15 16:29:34 +03:00
free_parameters_by_snum ( GLOBAL_SECTION_SNUM ) ;
2012-07-23 06:49:46 +04:00
TALLOC_FREE ( Globals . ctx ) ;
2008-09-28 00:19:56 +04:00
}
2010-08-11 07:35:14 +04:00
struct lp_stored_option {
struct lp_stored_option * prev , * next ;
const char * label ;
const char * value ;
} ;
static struct lp_stored_option * stored_options ;
/*
save options set by lp_set_cmdline ( ) into a list . This list is
re - applied when we do a globals reset , so that cmdline set options
are sticky across reloads of smb . conf
*/
static bool store_lp_set_cmdline ( const char * pszParmName , const char * pszParmValue )
{
2010-11-02 07:33:42 +03:00
struct lp_stored_option * entry , * entry_next ;
for ( entry = stored_options ; entry ! = NULL ; entry = entry_next ) {
entry_next = entry - > next ;
2010-08-11 07:35:14 +04:00
if ( strcmp ( pszParmName , entry - > label ) = = 0 ) {
DLIST_REMOVE ( stored_options , entry ) ;
talloc_free ( entry ) ;
break ;
}
}
entry = talloc ( NULL , struct lp_stored_option ) ;
if ( ! entry ) {
return false ;
}
entry - > label = talloc_strdup ( entry , pszParmName ) ;
if ( ! entry - > label ) {
talloc_free ( entry ) ;
return false ;
}
entry - > value = talloc_strdup ( entry , pszParmValue ) ;
if ( ! entry - > value ) {
talloc_free ( entry ) ;
return false ;
}
DLIST_ADD_END ( stored_options , entry , struct lp_stored_option ) ;
return true ;
}
static bool apply_lp_set_cmdline ( void )
{
struct lp_stored_option * entry = NULL ;
for ( entry = stored_options ; entry ! = NULL ; entry = entry - > next ) {
if ( ! lp_set_cmdline_helper ( entry - > label , entry - > value , false ) ) {
DEBUG ( 0 , ( " Failed to re-apply cmdline parameter %s = %s \n " ,
entry - > label , entry - > value ) ) ;
return false ;
}
}
return true ;
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Initialise the global parameter structure .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2010-08-20 11:51:48 +04:00
static void init_globals ( bool reinit_globals )
1996-05-04 11:50:46 +04:00
{
2011-06-29 09:06:49 +04:00
static bool done_init = false ;
2007-11-14 05:42:42 +03:00
char * s = NULL ;
2008-03-10 19:16:01 +03:00
int i ;
2000-05-29 03:34:34 +04:00
2006-01-29 01:53:04 +03:00
/* If requested to initialize only once and we've already done it... */
2010-08-20 11:51:48 +04:00
if ( ! reinit_globals & & done_init ) {
2006-01-29 01:53:04 +03:00
/* ... then we have nothing more to do */
return ;
}
2002-11-13 02:20:50 +03:00
if ( ! done_init ) {
2004-06-23 05:51:45 +04:00
/* The logfile can be set before this is invoked. Free it if so. */
2012-04-12 10:51:54 +04:00
if ( Globals . logfile ! = NULL ) {
string_free ( & Globals . logfile ) ;
Globals . logfile = NULL ;
2004-06-23 05:51:45 +04:00
}
2011-06-29 09:05:37 +04:00
done_init = true ;
2008-03-10 19:16:01 +03:00
} else {
2008-09-28 00:19:56 +04:00
free_global_parameters ( ) ;
2008-03-10 19:16:01 +03:00
}
2000-05-29 03:34:34 +04:00
2010-08-11 07:35:14 +04:00
/* This memset and the free_global_parameters() above will
* wipe out smb . conf options set with lp_set_cmdline ( ) . The
* apply_lp_set_cmdline ( ) call puts these values back in the
* table once the defaults are set */
2011-08-16 14:30:58 +04:00
ZERO_STRUCT ( Globals ) ;
2004-08-31 22:34:52 +04:00
2012-07-23 06:49:46 +04:00
Globals . ctx = talloc_new ( NULL ) ;
2008-03-10 19:16:01 +03:00
for ( i = 0 ; parm_table [ i ] . label ; i + + ) {
if ( ( parm_table [ i ] . type = = P_STRING | |
2011-06-29 06:36:06 +04:00
parm_table [ i ] . type = = P_USTRING ) )
2008-03-10 19:16:01 +03:00
{
2011-07-21 19:22:22 +04:00
string_set ( ( char * * ) lp_parm_ptr ( NULL , & parm_table [ i ] ) , " " ) ;
2008-03-10 19:16:01 +03:00
}
2000-05-29 03:34:34 +04:00
}
2011-06-09 09:31:03 +04:00
2008-03-10 19:16:01 +03:00
string_set ( & sDefault . fstype , FSTYPE_STRING ) ;
2013-12-24 07:03:24 +04:00
string_set ( & sDefault . printjob_username , " %U " ) ;
2008-03-10 19:16:01 +03:00
init_printer_values ( & sDefault ) ;
2014-01-06 05:19:13 +04:00
sDefault . ntvfs_handler = ( const char * * ) str_list_make_v3 ( NULL , " unixuid default " , NULL ) ;
2000-05-29 03:34:34 +04:00
DEBUG ( 3 , ( " Initialising global parameters \n " ) ) ;
2011-06-09 09:31:03 +04:00
/* Must manually force to upper case here, as this does not go via the handler */
2013-12-24 07:04:02 +04:00
string_set ( & Globals . netbios_name , myhostname_upper ( ) ) ;
2011-06-09 09:31:03 +04:00
2013-12-24 07:04:04 +04:00
string_set ( & Globals . smb_passwd_file , get_dyn_SMB_PASSWD_FILE ( ) ) ;
2013-12-24 07:04:03 +04:00
string_set ( & Globals . private_dir , get_dyn_PRIVATE_DIR ( ) ) ;
2001-11-09 14:16:06 +03:00
2002-10-22 00:40:23 +04:00
/* use the new 'hash2' method by default, with a prefix of 1 */
2013-12-24 07:04:31 +04:00
string_set ( & Globals . mangling_method , " hash2 " ) ;
2002-10-22 00:40:23 +04:00
Globals . mangle_prefix = 1 ;
2002-04-12 14:18:46 +04:00
2013-12-24 07:04:01 +04:00
string_set ( & Globals . guestaccount , GUEST_ACCOUNT ) ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
2002-03-04 00:38:56 +03:00
/* using UTF8 by default allows us to support all chars */
2003-08-16 00:09:12 +04:00
string_set ( & Globals . unix_charset , DEFAULT_UNIX_CHARSET ) ;
2002-03-04 00:38:56 +03:00
2002-08-17 21:00:51 +04:00
/* Use codepage 850 as a default for the dos character set */
2003-08-16 00:09:12 +04:00
string_set ( & Globals . dos_charset , DEFAULT_DOS_CHARSET ) ;
2002-08-17 21:00:51 +04:00
2000-05-29 03:34:34 +04:00
/*
* Allow the default PASSWD_CHAT to be overridden in local . h .
*/
2013-12-24 07:04:32 +04:00
string_set ( & Globals . passwd_chat , DEFAULT_PASSWD_CHAT ) ;
2007-11-14 05:42:42 +03:00
2013-12-24 07:04:06 +04:00
string_set ( & Globals . workgroup , DEFAULT_WORKGROUP ) ;
2007-11-14 05:42:42 +03:00
2013-12-24 07:04:32 +04:00
string_set ( & Globals . passwd_program , " " ) ;
2013-12-24 07:04:01 +04:00
string_set ( & Globals . lockdir , get_dyn_LOCKDIR ( ) ) ;
2009-01-08 22:18:13 +03:00
string_set ( & Globals . szStateDir , get_dyn_STATEDIR ( ) ) ;
string_set ( & Globals . szCacheDir , get_dyn_CACHEDIR ( ) ) ;
2013-12-24 07:04:03 +04:00
string_set ( & Globals . piddir , get_dyn_PIDDIR ( ) ) ;
2012-07-27 06:56:22 +04:00
string_set ( & Globals . nbt_client_socket_address , " 0.0.0.0 " ) ;
2010-02-09 01:35:02 +03:00
/*
2010-02-10 23:42:27 +03:00
* By default support explicit binding to broadcast
* addresses .
2010-02-09 01:35:02 +03:00
*/
2013-12-24 07:03:51 +04:00
Globals . nmbd_bind_explicit_broadcast = true ;
2007-11-14 05:42:42 +03:00
2009-01-16 00:27:52 +03:00
if ( asprintf ( & s , " Samba %s " , samba_version_string ( ) ) < 0 ) {
2007-11-14 05:42:42 +03:00
smb_panic ( " init_globals: ENOMEM " ) ;
}
2013-12-24 07:04:33 +04:00
string_set ( & Globals . serverstring , s ) ;
2007-11-14 05:42:42 +03:00
SAFE_FREE ( s ) ;
2005-11-16 09:54:39 +03:00
# ifdef DEVELOPER
2013-12-24 07:04:32 +04:00
string_set ( & Globals . panic_action , " /bin/sleep 999999999 " ) ;
2005-11-16 09:54:39 +03:00
# endif
2000-05-29 03:34:34 +04:00
2012-05-28 11:19:07 +04:00
string_set ( & Globals . socket_options , DEFAULT_SOCKET_OPTIONS ) ;
2000-05-29 03:34:34 +04:00
2013-12-24 07:04:01 +04:00
string_set ( & Globals . logon_drive , " " ) ;
2000-05-29 03:34:34 +04:00
/* %N is the NIS auto.home server if -DAUTOHOME is used, else same as %L */
2013-12-24 07:04:01 +04:00
string_set ( & Globals . logon_home , " \\ \\ %N \\ %U " ) ;
2013-12-24 07:04:01 +04:00
string_set ( & Globals . logon_path , " \\ \\ %N \\ %U \\ profile " ) ;
2000-05-29 03:34:34 +04:00
2013-12-24 07:04:23 +04:00
Globals . name_resolve_order = ( const char * * ) str_list_make_v3 ( NULL , " lmhosts wins host bcast " , NULL ) ;
2013-12-24 07:04:03 +04:00
string_set ( & Globals . passwordserver , " * " ) ;
2000-05-29 03:34:34 +04:00
2013-12-24 07:04:06 +04:00
Globals . algorithmic_rid_base = BASE_RID ;
2002-07-15 14:35:28 +04:00
2013-12-24 07:03:49 +04:00
Globals . load_printers = true ;
2013-12-24 07:04:18 +04:00
Globals . printcap_cache_time = 750 ; /* 12.5 minutes */
2005-09-30 21:13:37 +04:00
2013-12-24 07:04:08 +04:00
Globals . config_backend = config_backend ;
2012-07-23 05:38:25 +04:00
Globals . server_role = ROLE_AUTO ;
2008-01-16 18:18:28 +03:00
2002-10-16 01:35:46 +04:00
/* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
/* Discovered by 2 days of pain by Don McCall @ HP :-). */
Globals . max_xmit = 0x4104 ;
2013-12-24 07:04:15 +04:00
Globals . maxmux = 50 ; /* This is *needed* for profile support. */
2004-12-08 06:02:29 +03:00
Globals . lpqcachetime = 30 ; /* changed to handle large print servers better -- jerry */
2013-12-24 07:03:46 +04:00
Globals . _disable_spoolss = false ;
2013-12-24 07:04:15 +04:00
Globals . max_smbd_processes = 0 ; /* no limit specified */
2013-12-24 07:04:20 +04:00
Globals . usernamelevel = 0 ;
2000-05-29 03:34:34 +04:00
Globals . deadtime = 0 ;
2007-12-18 11:41:03 +03:00
Globals . getwd_cache = true ;
2013-12-24 07:03:48 +04:00
Globals . large_readwrite = true ;
2000-05-29 03:34:34 +04:00
Globals . max_log_size = 5000 ;
2009-02-19 20:33:30 +03:00
Globals . max_open_files = max_open_files ( ) ;
2006-03-30 02:19:01 +04:00
Globals . open_files_db_hash_size = SMB_OPEN_DATABASE_TDB_HASH_SIZE ;
2012-06-04 01:04:44 +04:00
Globals . srv_maxprotocol = PROTOCOL_SMB3_00 ;
2012-05-30 06:32:56 +04:00
Globals . srv_minprotocol = PROTOCOL_LANMAN1 ;
2013-08-08 02:17:01 +04:00
Globals . cli_maxprotocol = PROTOCOL_NT1 ;
Globals . cli_minprotocol = PROTOCOL_CORE ;
2000-05-29 03:34:34 +04:00
Globals . security = SEC_USER ;
2013-12-24 07:03:47 +04:00
Globals . encrypted_passwords = true ;
2013-12-24 07:04:07 +04:00
Globals . client_schannel = Auto ;
2013-12-24 07:03:58 +04:00
Globals . winbind_sealed_pipes = true ;
2013-12-24 07:03:53 +04:00
Globals . require_strong_key = true ;
2013-12-24 07:04:18 +04:00
Globals . server_schannel = Auto ;
2011-06-29 09:05:37 +04:00
Globals . bReadRaw = true ;
Globals . bWriteRaw = true ;
2013-12-24 07:03:51 +04:00
Globals . null_passwords = false ;
2013-12-24 07:03:52 +04:00
Globals . obey_pam_restrictions = false ;
2000-05-29 03:34:34 +04:00
Globals . syslog = 1 ;
2013-12-24 07:03:54 +04:00
Globals . syslog_only = false ;
2013-12-24 07:03:54 +04:00
Globals . timestamp_logs = true ;
2012-07-23 05:43:54 +04:00
string_set ( & Globals . loglevel , " 0 " ) ;
2013-12-24 07:03:45 +04:00
Globals . debug_prefix_timestamp = false ;
2013-12-24 07:03:45 +04:00
Globals . debug_hires_timestamp = true ;
2013-12-24 07:03:45 +04:00
Globals . debug_pid = false ;
2013-12-24 07:03:45 +04:00
Globals . debug_uid = false ;
2013-12-24 07:03:45 +04:00
Globals . debug_class = false ;
2013-12-24 07:03:47 +04:00
Globals . enable_core_files = true ;
2000-05-29 03:34:34 +04:00
Globals . max_ttl = 60 * 60 * 24 * 3 ; /* 3 days default. */
Globals . max_wins_ttl = 60 * 60 * 24 * 6 ; /* 6 days default. */
Globals . min_wins_ttl = 60 * 60 * 6 ; /* 6 hours default. */
Globals . machine_password_timeout = 60 * 60 * 24 * 7 ; /* 7 days default. */
2011-10-06 09:34:52 +04:00
Globals . lm_announce = Auto ; /* = Auto: send only if LM clients found */
2000-05-29 03:34:34 +04:00
Globals . lm_interval = 60 ;
1998-07-29 07:08:05 +04:00
# if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT))
2013-12-24 07:03:50 +04:00
Globals . nis_home_map = false ;
1998-08-08 05:15:14 +04:00
# ifdef WITH_NISPLUS_HOME
2013-12-24 07:04:31 +04:00
string_set ( & Globals . nis_home_map_name , " auto_home.org_dir " ) ;
1998-04-10 00:48:48 +04:00
# else
2013-12-24 07:04:31 +04:00
string_set ( & Globals . nis_home_map_name , " auto.home " ) ;
1998-04-10 00:48:48 +04:00
# endif
1997-05-07 21:56:46 +04:00
# endif
2013-12-24 07:03:54 +04:00
Globals . time_server = false ;
2013-12-24 07:03:43 +04:00
Globals . bind_interfaces_only = false ;
2013-12-24 07:03:55 +04:00
Globals . unix_password_sync = false ;
2013-12-24 07:03:52 +04:00
Globals . pam_password_change = false ;
2013-12-24 07:03:52 +04:00
Globals . passwd_chat_debug = false ;
2013-12-24 07:04:17 +04:00
Globals . passwd_chat_timeout = 2 ; /* 2 second default. */
2013-12-24 07:03:51 +04:00
Globals . nt_pipe_support = true ; /* Do NT pipes by default. */
2013-12-24 07:03:51 +04:00
Globals . nt_status_support = true ; /* Use NT status by default. */
2013-12-24 07:03:54 +04:00
Globals . stat_cache = true ; /* use stat cache by default */
2013-12-24 07:04:15 +04:00
Globals . max_stat_cache_size = 256 ; /* 256k by default */
2002-07-15 14:35:28 +04:00
Globals . restrict_anonymous = 0 ;
2013-12-24 07:03:43 +04:00
Globals . client_lanman_auth = false ; /* Do NOT use the LanMan hash if it is available */
2013-12-24 07:03:44 +04:00
Globals . client_plaintext_auth = false ; /* Do NOT use a plaintext password even if is requested by the server */
2013-12-24 07:03:48 +04:00
Globals . lanman_auth = false ; /* Do NOT use the LanMan hash, even if it is supplied */
2013-12-24 07:03:51 +04:00
Globals . ntlm_auth = true ; /* Do use NTLMv1 if it is supplied by the client (otherwise NTLMv2) */
2013-12-24 07:03:43 +04:00
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 */
2010-12-04 06:57:46 +03:00
/* Note, that we will also use NTLM2 session security (which is different), if it is available */
2003-08-09 02:19:09 +04:00
2000-05-29 03:34:34 +04:00
Globals . map_to_guest = 0 ; /* By Default, "Never" */
2001-01-30 03:37:12 +03:00
Globals . oplock_break_wait_time = 0 ; /* By Default, 0 msecs. */
2007-10-20 18:24:46 +04:00
Globals . enhanced_browsing = true ;
2013-12-24 07:04:13 +04:00
Globals . lock_spin_time = WINDOWS_MINIMUM_LOCK_TIMEOUT_MS ; /* msec. */
2001-08-03 00:52:57 +04:00
# ifdef MMAP_BLACKLIST
2013-12-24 07:03:55 +04:00
Globals . use_mmap = false ;
2001-08-03 00:52:57 +04:00
# else
2013-12-24 07:03:55 +04:00
Globals . use_mmap = true ;
2001-08-03 00:52:57 +04:00
# endif
2013-12-24 07:03:55 +04:00
Globals . unicode = true ;
2013-12-24 07:03:55 +04:00
Globals . unix_extensions = true ;
2013-12-24 07:03:53 +04:00
Globals . reset_on_zero_vc = false ;
2013-12-24 07:03:49 +04:00
Globals . log_writeable_files_on_exit = false ;
2013-12-24 07:03:44 +04:00
Globals . create_krb5_conf = true ;
2010-04-07 19:45:12 +04:00
Globals . winbindMaxDomainConnections = 1 ;
1996-05-04 11:50:46 +04:00
2001-09-13 04:30:47 +04:00
/* hostname lookups can be very expensive and are broken on
a large number of sites ( tridge ) */
2013-12-24 07:03:48 +04:00
Globals . hostname_lookups = false ;
2001-09-13 04:30:47 +04:00
2012-05-28 11:19:07 +04:00
string_set ( & Globals . passdb_backend , " tdbsam " ) ;
2013-12-24 07:04:30 +04:00
string_set ( & Globals . ldap_suffix , " " ) ;
2002-03-02 15:30:06 +03:00
string_set ( & Globals . szLdapMachineSuffix , " " ) ;
string_set ( & Globals . szLdapUserSuffix , " " ) ;
2003-06-06 17:48:39 +04:00
string_set ( & Globals . szLdapGroupSuffix , " " ) ;
string_set ( & Globals . szLdapIdmapSuffix , " " ) ;
2002-03-02 15:30:06 +03:00
2013-12-24 07:04:30 +04:00
string_set ( & Globals . ldap_admin_dn , " " ) ;
2008-12-21 10:55:30 +03:00
Globals . ldap_ssl = LDAP_SSL_START_TLS ;
2011-06-29 09:06:49 +04:00
Globals . ldap_ssl_ads = false ;
2009-12-11 00:22:54 +03:00
Globals . ldap_deref = - 1 ;
2002-09-25 19:19:00 +04:00
Globals . ldap_passwd_sync = LDAP_PASSWD_SYNC_OFF ;
2011-06-29 09:06:49 +04:00
Globals . ldap_delete_dn = false ;
2003-12-26 02:11:07 +03:00
Globals . ldap_replication_sleep = 1000 ; /* wait 1 sec for replication */
2009-10-26 14:11:59 +03:00
Globals . ldap_follow_referral = Auto ;
2008-05-26 13:29:24 +04:00
Globals . ldap_timeout = LDAP_DEFAULT_TIMEOUT ;
Globals . ldap_connection_timeout = LDAP_CONNECTION_DEFAULT_TIMEOUT ;
2005-04-15 17:41:49 +04:00
Globals . ldap_page_size = LDAP_PAGE_SIZE ;
1998-06-16 05:35:52 +04:00
2008-01-28 16:47:01 +03:00
Globals . ldap_debug_level = 0 ;
Globals . ldap_debug_threshold = 10 ;
2004-12-17 14:42:10 +03:00
/* This is what we tell the afs client. in reality we set the token
* to never expire , though , when this runs out the afs client will
* forget the token . Set to 0 to get NEVERDATE . */
2013-12-24 07:04:06 +04:00
Globals . afs_token_lifetime = 604800 ;
2008-09-24 20:53:21 +04:00
Globals . cups_connection_timeout = CUPS_DEFAULT_CONNECTION_TIMEOUT ;
2004-12-17 14:42:10 +03:00
2001-01-17 21:47:46 +03:00
/* these parameters are set to defaults that are more appropriate
1997-05-20 04:32:51 +04:00
for the increasing samba install base :
as a member of the workgroup , that will possibly become a
2011-06-29 09:05:37 +04:00
_local_ master browser ( lm = true ) . this is opposed to a forced
local master browser startup ( pm = true ) .
1997-05-20 04:32:51 +04:00
2011-06-29 09:06:49 +04:00
doesn ' t provide WINS server service by default ( wsupp = false ) ,
1997-05-20 04:32:51 +04:00
and doesn ' t provide domain master browser services by default , either .
2001-01-17 21:47:46 +03:00
1997-05-20 04:32:51 +04:00
*/
2013-12-24 07:03:50 +04:00
Globals . ms_add_printer_wizard = true ;
2000-05-29 03:34:34 +04:00
Globals . os_level = 20 ;
2013-12-24 07:03:49 +04:00
Globals . local_master = true ;
2014-01-10 02:21:46 +04:00
Globals . _domain_master = Auto ; /* depending on _domain_logons */
2013-12-24 07:03:46 +04:00
Globals . _domain_logons = false ;
2013-12-24 07:03:43 +04:00
Globals . browse_list = true ;
2013-12-24 07:03:57 +04:00
Globals . we_are_a_wins_server = false ;
2013-12-24 07:03:59 +04:00
Globals . wins_proxy = false ;
1997-07-06 16:06:23 +04:00
2014-01-10 02:32:42 +04:00
TALLOC_FREE ( Globals . init_logon_delayed_hosts ) ;
2013-12-24 07:04:10 +04:00
Globals . init_logon_delay = 100 ; /* 100 ms default delay */
2008-08-09 02:31:48 +04:00
2013-12-24 07:03:59 +04:00
Globals . wins_dns_proxy = true ;
1998-03-03 23:19:14 +03:00
2013-12-24 07:03:42 +04:00
Globals . allow_trusted_domains = true ;
2008-07-13 14:07:40 +04:00
string_set ( & Globals . szIdmapBackend , " tdb " ) ;
1999-03-01 19:31:14 +03:00
2013-12-24 07:04:04 +04:00
string_set ( & Globals . template_shell , " /bin/false " ) ;
2013-12-24 07:04:04 +04:00
string_set ( & Globals . template_homedir , " /home/%D/%U " ) ;
2013-12-24 07:04:05 +04:00
string_set ( & Globals . winbind_separator , " \\ " ) ;
2013-12-24 07:04:05 +04:00
string_set ( & Globals . winbindd_socket_directory , dyn_WINBINDD_SOCKET_DIR ) ;
2007-01-31 08:38:36 +03:00
2013-12-24 07:04:28 +04:00
string_set ( & Globals . cups_server , " " ) ;
2013-12-24 07:04:30 +04:00
string_set ( & Globals . iprint_server , " " ) ;
2001-05-04 11:32:28 +04:00
2012-07-19 07:36:37 +04:00
# ifdef CLUSTER_SUPPORT
2013-12-24 07:03:59 +04:00
string_set ( & Globals . ctdbd_socket , CTDB_PATH ) ;
2012-07-19 07:36:37 +04:00
# else
2013-12-24 07:03:59 +04:00
string_set ( & Globals . ctdbd_socket , " " ) ;
2012-07-19 07:36:37 +04:00
# endif
2013-12-24 07:04:22 +04:00
Globals . cluster_addresses = NULL ;
2011-06-29 09:06:49 +04:00
Globals . clustering = false ;
2009-11-03 07:41:02 +03:00
Globals . ctdb_timeout = 0 ;
2010-03-05 18:46:36 +03:00
Globals . ctdb_locktime_warn_threshold = 0 ;
2007-06-10 21:02:09 +04:00
2003-07-07 09:11:10 +04:00
Globals . winbind_cache_time = 300 ; /* 5 minutes */
2008-08-21 03:24:22 +04:00
Globals . winbind_reconnect_delay = 30 ; /* 30 seconds */
2010-09-15 03:43:39 +04:00
Globals . winbind_max_clients = 200 ;
2013-12-24 07:03:57 +04:00
Globals . winbind_enum_users = false ;
2013-12-24 07:03:57 +04:00
Globals . winbind_enum_groups = false ;
2013-12-24 07:03:59 +04:00
Globals . winbind_use_default_domain = false ;
2013-12-24 07:03:58 +04:00
Globals . winbind_trusted_domains_only = false ;
2013-12-24 07:03:57 +04:00
Globals . winbind_nested_groups = true ;
2007-10-11 00:34:30 +04:00
Globals . winbind_expand_groups = 1 ;
2013-12-24 07:04:25 +04:00
Globals . winbind_nss_info = ( const char * * ) str_list_make_v3 ( NULL , " template " , NULL ) ;
2013-12-24 07:03:58 +04:00
Globals . winbind_refresh_tickets = false ;
2013-12-24 07:03:58 +04:00
Globals . winbind_offline_logon = false ;
2001-12-07 04:01:10 +03:00
2013-12-24 07:04:09 +04:00
Globals . idmap_cache_time = 86400 * 7 ; /* a week by default */
2013-12-24 07:04:10 +04:00
Globals . idmap_negative_cache_time = 120 ; /* 2 minutes by default */
2006-12-12 17:52:13 +03:00
2013-12-24 07:03:52 +04:00
Globals . passdb_expand_explicit = false ;
2003-04-23 15:54:56 +04:00
2002-08-17 21:00:51 +04:00
Globals . name_cache_timeout = 660 ; /* In seconds */
2013-12-24 07:03:56 +04:00
Globals . use_spnego = true ;
2013-12-24 07:03:44 +04:00
Globals . client_use_spnego = true ;
2001-12-07 04:01:10 +03:00
2011-11-02 22:08:54 +04:00
Globals . client_signing = SMB_SIGNING_DEFAULT ;
Globals . server_signing = SMB_SIGNING_DEFAULT ;
2003-08-12 00:50:42 +04:00
2013-12-24 07:03:46 +04:00
Globals . defer_sharing_violations = true ;
2012-07-18 05:51:00 +04:00
Globals . smb_ports = ( const char * * ) str_list_make_v3 ( NULL , SMB_PORTS , NULL ) ;
2005-01-17 23:27:29 +03:00
2013-12-24 07:03:47 +04:00
Globals . enable_privileges = true ;
2013-12-24 07:03:48 +04:00
Globals . host_msdfs = true ;
2013-12-24 07:03:46 +04:00
Globals . enable_asu_support = false ;
2007-11-14 05:42:42 +03:00
2006-02-04 01:19:41 +03:00
/* User defined shares. */
2007-12-10 22:30:37 +03:00
if ( asprintf ( & s , " %s/usershares " , get_dyn_STATEDIR ( ) ) < 0 ) {
2007-11-14 05:42:42 +03:00
smb_panic ( " init_globals: ENOMEM " ) ;
}
2013-12-24 07:04:35 +04:00
string_set ( & Globals . usershare_path , s ) ;
2007-11-14 05:42:42 +03:00
SAFE_FREE ( s ) ;
2006-02-04 01:19:41 +03:00
string_set ( & Globals . szUsershareTemplateShare , " " ) ;
2013-12-24 07:04:20 +04:00
Globals . usershare_max_shares = 0 ;
2006-02-04 01:19:41 +03:00
/* By default disallow sharing of directories not owned by the sharer. */
2013-12-24 07:03:56 +04:00
Globals . usershare_owner_only = true ;
2006-04-30 04:36:26 +04:00
/* By default disallow guest access to usershares. */
2013-12-24 07:03:56 +04:00
Globals . usershare_allow_guests = false ;
2006-11-30 10:38:40 +03:00
2013-12-24 07:04:10 +04:00
Globals . keepalive = DEFAULT_KEEPALIVE ;
2007-03-18 13:57:46 +03:00
2006-11-30 10:38:40 +03:00
/* By default no shares out of the registry */
2013-12-24 07:03:52 +04:00
Globals . registry_shares = false ;
2007-10-31 02:22:24 +03:00
Globals . iminreceivefile = 0 ;
2009-02-13 00:01:45 +03:00
2013-12-24 07:03:50 +04:00
Globals . map_untrusted_to_domain = false ;
2013-12-24 07:03:50 +04:00
Globals . multicast_dns_register = true ;
2010-04-07 02:43:35 +04:00
2013-12-24 07:04:18 +04:00
Globals . smb2_max_read = DEFAULT_SMB2_MAX_READ ;
2013-12-24 07:04:19 +04:00
Globals . smb2_max_write = DEFAULT_SMB2_MAX_WRITE ;
2013-12-24 07:04:19 +04:00
Globals . smb2_max_trans = DEFAULT_SMB2_MAX_TRANSACT ;
2010-12-11 02:46:41 +03:00
Globals . ismb2_max_credits = DEFAULT_SMB2_MAX_CREDITS ;
2010-08-11 07:35:14 +04:00
2010-05-20 16:39:10 +04:00
string_set ( & Globals . ncalrpc_dir , get_dyn_NCALRPCDIR ( ) ) ;
2014-01-06 04:29:51 +04:00
Globals . server_services = ( const char * * ) str_list_make_v3 ( NULL , " s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns " , NULL ) ;
2014-01-06 05:25:00 +04:00
Globals . dcerpc_endpoint_servers = ( const char * * ) str_list_make_v3 ( NULL , " epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver " , NULL ) ;
2014-01-06 05:38:21 +04:00
Globals . tls_enabled = true ;
2014-01-09 04:52:44 +04:00
string_set ( & Globals . tls_keyfile , " tls/key.pem " ) ;
string_set ( & Globals . tls_certfile , " tls/cert.pem " ) ;
string_set ( & Globals . tls_cafile , " tls/ca.pem " ) ;
2014-01-06 06:00:23 +04:00
string_set ( & Globals . share_backend , " classic " ) ;
2014-01-06 06:03:46 +04:00
Globals . iPreferredMaster = Auto ;
2014-01-06 06:37:42 +04:00
Globals . allow_dns_updates = DNS_UPDATE_SIGNED ;
2014-01-09 04:43:56 +04:00
string_set ( & Globals . ntp_signd_socket_directory , get_dyn_NTP_SIGND_SOCKET_DIR ( ) ) ;
2014-01-09 04:45:33 +04:00
string_set ( & Globals . winbindd_privileged_socket_directory , get_dyn_WINBINDD_PRIVILEGED_SOCKET_DIR ( ) ) ;
2014-01-09 05:01:03 +04:00
if ( asprintf ( & s , " %s/samba_kcc " , get_dyn_SCRIPTSBINDIR ( ) ) < 0 ) {
smb_panic ( " init_globals: ENOMEM " ) ;
}
Globals . samba_kcc_command = ( const char * * ) str_list_make_v3 ( NULL , s , NULL ) ;
SAFE_FREE ( s ) ;
2014-01-09 05:02:07 +04:00
if ( asprintf ( & s , " %s/samba_dnsupdate " , get_dyn_SCRIPTSBINDIR ( ) ) < 0 ) {
smb_panic ( " init_globals: ENOMEM " ) ;
}
Globals . dns_update_command = ( const char * * ) str_list_make_v3 ( NULL , s , NULL ) ;
SAFE_FREE ( s ) ;
2014-01-09 05:03:34 +04:00
if ( asprintf ( & s , " %s/samba_spnupdate " , get_dyn_SCRIPTSBINDIR ( ) ) < 0 ) {
smb_panic ( " init_globals: ENOMEM " ) ;
}
Globals . spn_update_command = ( const char * * ) str_list_make_v3 ( NULL , s , NULL ) ;
SAFE_FREE ( s ) ;
2014-01-09 05:04:24 +04:00
Globals . nsupdate_command = ( const char * * ) str_list_make_v3 ( NULL , " /usr/bin/nsupdate -g " , NULL ) ;
2014-01-09 05:05:58 +04:00
Globals . rndc_command = ( const char * * ) str_list_make_v3 ( NULL , " /usr/sbin/rndc " , NULL ) ;
2014-01-09 06:45:45 +04:00
Globals . cldap_port = 389 ;
Globals . dgram_port = 138 ;
Globals . nbt_port = 137 ;
Globals . krb5_port = 88 ;
Globals . kpasswd_port = 464 ;
Globals . web_port = 901 ;
2010-08-11 07:35:14 +04:00
/* Now put back the settings that were set with lp_set_cmdline() */
apply_lp_set_cmdline ( ) ;
1996-05-04 11:50:46 +04:00
}
2000-01-05 09:36:36 +03:00
/*******************************************************************
2012-07-18 09:37:23 +04:00
Convenience routine to grab string parameters into talloced memory
2002-11-13 02:20:50 +03:00
and run standard_sub_basic on them . The buffers can be written to by
callers without affecting the source string .
1997-11-03 22:24:45 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2012-07-18 09:37:23 +04:00
static char * lp_string ( TALLOC_CTX * ctx , const char * s )
1997-11-02 23:35:20 +03:00
{
2007-11-28 06:12:42 +03:00
char * ret ;
1997-11-02 23:35:20 +03:00
2002-02-16 22:34:58 +03:00
/* The follow debug is useful for tracking down memory problems
especially if you have an inner loop that is calling a lp_ * ( )
function that returns a string . Perhaps this debug should be
present all the time ? */
#if 0
DEBUG ( 10 , ( " lp_string(%s) \n " , s ) ) ;
# endif
2009-07-15 11:36:02 +04:00
if ( ! s ) {
return NULL ;
}
2002-02-16 22:34:58 +03:00
2007-11-28 06:12:42 +03:00
ret = talloc_sub_basic ( ctx ,
get_current_username ( ) ,
current_user_info . domain ,
s ) ;
if ( trim_char ( ret , ' \" ' , ' \" ' ) ) {
if ( strchr ( ret , ' \" ' ) ! = NULL ) {
TALLOC_FREE ( ret ) ;
ret = talloc_sub_basic ( ctx ,
get_current_username ( ) ,
current_user_info . domain ,
s ) ;
2003-05-29 05:41:56 +04:00
}
2002-08-17 21:00:51 +04:00
}
2007-11-28 06:12:42 +03:00
return ret ;
1996-05-04 11:50:46 +04:00
}
/*
2009-01-08 22:18:13 +03:00
In this section all the functions that are used to access the
parameters from the rest of the program are defined
1996-05-04 11:50:46 +04:00
*/
# define FN_GLOBAL_STRING(fn_name,ptr) \
2012-07-18 09:37:23 +04:00
char * lp_ # # fn_name ( TALLOC_CTX * ctx ) { return ( lp_string ( ( ctx ) , * ( char * * ) ( & Globals . ptr ) ? * ( char * * ) ( & Globals . ptr ) : " " ) ) ; }
2002-07-15 14:35:28 +04:00
# define FN_GLOBAL_CONST_STRING(fn_name,ptr) \
2012-08-10 14:05:15 +04:00
const char * lp_ # # fn_name ( void ) { return ( * ( const char * const * ) ( & Globals . ptr ) ? * ( const char * const * ) ( & Globals . ptr ) : " " ) ; }
2001-06-20 20:54:32 +04:00
# define FN_GLOBAL_LIST(fn_name,ptr) \
2012-04-12 11:10:36 +04:00
const char * * lp_ # # fn_name ( void ) { return ( * ( const char * * * ) ( & Globals . ptr ) ) ; }
1996-05-04 11:50:46 +04:00
# define FN_GLOBAL_BOOL(fn_name,ptr) \
2012-04-12 11:10:36 +04:00
bool lp_ # # fn_name ( void ) { return ( * ( bool * ) ( & Globals . ptr ) ) ; }
1996-05-04 11:50:46 +04:00
# define FN_GLOBAL_CHAR(fn_name,ptr) \
2012-04-12 11:10:36 +04:00
char lp_ # # fn_name ( void ) { return ( * ( char * ) ( & Globals . ptr ) ) ; }
1996-05-04 11:50:46 +04:00
# define FN_GLOBAL_INTEGER(fn_name,ptr) \
2012-04-12 11:10:36 +04:00
int lp_ # # fn_name ( void ) { return ( * ( int * ) ( & Globals . ptr ) ) ; }
1996-05-04 11:50:46 +04:00
# define FN_LOCAL_STRING(fn_name,val) \
2012-07-18 09:37:23 +04:00
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 ) ) ; }
2002-07-15 14:35:28 +04:00
# define FN_LOCAL_CONST_STRING(fn_name,val) \
2011-07-08 03:19:43 +04:00
const char * lp_ # # fn_name ( int i ) { return ( const char * ) ( ( LP_SNUM_OK ( i ) & & ServicePtrs [ ( i ) ] - > val ) ? ServicePtrs [ ( i ) ] - > val : sDefault . val ) ; }
2001-06-20 20:54:32 +04:00
# define FN_LOCAL_LIST(fn_name,val) \
2011-07-08 03:19:43 +04:00
const char * * lp_ # # fn_name ( int i ) { return ( const char * * ) ( LP_SNUM_OK ( i ) ? ServicePtrs [ ( i ) ] - > val : sDefault . val ) ; }
1996-05-04 11:50:46 +04:00
# define FN_LOCAL_BOOL(fn_name,val) \
2011-07-08 03:19:43 +04:00
bool lp_ # # fn_name ( int i ) { return ( bool ) ( LP_SNUM_OK ( i ) ? ServicePtrs [ ( i ) ] - > val : sDefault . val ) ; }
1996-05-04 11:50:46 +04:00
# define FN_LOCAL_INTEGER(fn_name,val) \
2011-07-08 03:19:43 +04:00
int lp_ # # fn_name ( int i ) { return ( LP_SNUM_OK ( i ) ? ServicePtrs [ ( i ) ] - > val : sDefault . val ) ; }
1996-05-04 11:50:46 +04:00
2006-07-11 22:01:26 +04:00
# define FN_LOCAL_PARM_BOOL(fn_name,val) \
2011-07-08 03:19:43 +04:00
bool lp_ # # fn_name ( const struct share_params * p ) { return ( bool ) ( LP_SNUM_OK ( p - > service ) ? ServicePtrs [ ( p - > service ) ] - > val : sDefault . val ) ; }
2006-11-11 20:05:11 +03:00
# define FN_LOCAL_PARM_INTEGER(fn_name,val) \
2011-07-08 03:19:43 +04:00
int lp_ # # fn_name ( const struct share_params * p ) { return ( LP_SNUM_OK ( p - > service ) ? ServicePtrs [ ( p - > service ) ] - > val : sDefault . val ) ; }
2013-10-14 06:33:20 +04:00
# define FN_LOCAL_PARM_CHAR(fn_name,val) \
2011-07-08 03:19:43 +04:00
char lp_ # # fn_name ( const struct share_params * p ) { return ( LP_SNUM_OK ( p - > service ) ? ServicePtrs [ ( p - > service ) ] - > val : sDefault . val ) ; }
2006-07-11 22:01:26 +04:00
2012-05-28 11:30:44 +04:00
2012-05-28 09:17:44 +04:00
static FN_GLOBAL_BOOL ( _readraw , bReadRaw )
static FN_GLOBAL_BOOL ( _writeraw , bWriteRaw )
2009-01-08 22:18:13 +03:00
/* If lp_statedir() and lp_cachedir() are explicitely set during the
* build process or in smb . conf , we use that value . Otherwise they
* default to the value of lp_lockdir ( ) . */
2011-06-01 05:48:38 +04:00
const char * lp_statedir ( void ) {
2009-01-08 22:18:13 +03:00
if ( ( strcmp ( get_dyn_STATEDIR ( ) , get_dyn_LOCKDIR ( ) ) ! = 0 ) | |
( strcmp ( get_dyn_STATEDIR ( ) , Globals . szStateDir ) ! = 0 ) )
2011-06-01 05:48:38 +04:00
return ( * ( char * * ) ( & Globals . szStateDir ) ?
* ( char * * ) ( & Globals . szStateDir ) : " " ) ;
2009-01-08 22:18:13 +03:00
else
2013-12-24 07:04:01 +04:00
return ( * ( char * * ) ( & Globals . lockdir ) ?
* ( char * * ) ( & Globals . lockdir ) : " " ) ;
2009-01-08 22:18:13 +03:00
}
2011-06-01 05:51:12 +04:00
const char * lp_cachedir ( void ) {
2009-01-08 22:18:13 +03:00
if ( ( strcmp ( get_dyn_CACHEDIR ( ) , get_dyn_LOCKDIR ( ) ) ! = 0 ) | |
( strcmp ( get_dyn_CACHEDIR ( ) , Globals . szCacheDir ) ! = 0 ) )
2011-06-01 05:51:12 +04:00
return ( * ( char * * ) ( & Globals . szCacheDir ) ?
* ( char * * ) ( & Globals . szCacheDir ) : " " ) ;
2009-01-08 22:18:13 +03:00
else
2013-12-24 07:04:01 +04:00
return ( * ( char * * ) ( & Globals . lockdir ) ?
* ( char * * ) ( & Globals . lockdir ) : " " ) ;
2009-01-08 22:18:13 +03:00
}
2012-04-12 11:10:36 +04:00
static FN_GLOBAL_INTEGER ( winbind_max_domain_connections_int ,
2011-06-20 11:57:24 +04:00
winbindMaxDomainConnections )
2010-04-07 19:45:12 +04:00
int lp_winbind_max_domain_connections ( void )
{
if ( lp_winbind_offline_logon ( ) & &
lp_winbind_max_domain_connections_int ( ) > 1 ) {
DEBUG ( 1 , ( " offline logons active, restricting max domain "
" connections to 1 \n " ) ) ;
return 1 ;
}
return MAX ( 1 , lp_winbind_max_domain_connections_int ( ) ) ;
}
2005-03-24 02:26:33 +03:00
2010-12-11 02:46:41 +03:00
int lp_smb2_max_credits ( void )
{
if ( Globals . ismb2_max_credits = = 0 ) {
Globals . ismb2_max_credits = DEFAULT_SMB2_MAX_CREDITS ;
}
return Globals . ismb2_max_credits ;
}
2009-03-27 15:05:00 +03:00
int lp_cups_encrypt ( void )
{
2010-05-05 02:07:57 +04:00
int result = 0 ;
2009-03-27 15:05:00 +03:00
# ifdef HAVE_HTTPCONNECTENCRYPT
switch ( Globals . CupsEncrypt ) {
case Auto :
2010-05-05 02:07:57 +04:00
result = HTTP_ENCRYPT_REQUIRED ;
2009-03-27 15:05:00 +03:00
break ;
2011-06-29 09:05:37 +04:00
case true :
2010-05-05 02:07:57 +04:00
result = HTTP_ENCRYPT_ALWAYS ;
2009-03-27 15:05:00 +03:00
break ;
2011-06-29 09:06:49 +04:00
case false :
2010-05-05 02:07:57 +04:00
result = HTTP_ENCRYPT_NEVER ;
2009-03-27 15:05:00 +03:00
break ;
}
# endif
2010-05-05 02:07:57 +04:00
return result ;
2009-03-27 15:05:00 +03:00
}
2010-05-20 16:39:10 +04:00
2012-05-28 11:30:44 +04:00
/* These functions remain in source3/param for now */
FN_GLOBAL_STRING ( configfile , szConfigFile )
2011-07-08 03:19:43 +04:00
# include "lib/param/param_functions.c"
FN_LOCAL_STRING ( servicename , szService )
FN_LOCAL_CONST_STRING ( const_servicename , szService )
1996-05-04 11:50:46 +04:00
/* local prototypes */
2001-01-10 19:05:41 +03:00
2007-10-19 04:40:25 +04:00
static int map_parameter_canonical ( const char * pszParmName , bool * inverse ) ;
static const char * get_boolean ( bool bool_value ) ;
2001-10-31 09:22:19 +03:00
static int getservicebyname ( const char * pszServiceName ,
2011-06-28 04:06:05 +04:00
struct loadparm_service * pserviceDest ) ;
static void copy_service ( struct loadparm_service * pserviceDest ,
struct loadparm_service * pserviceSource ,
2007-10-31 17:06:22 +03:00
struct bitmap * pcopymapDest ) ;
2008-03-26 00:53:47 +03:00
static bool do_parameter ( const char * pszParmName , const char * pszParmValue ,
void * userdata ) ;
static bool do_section ( const char * pszSectionName , void * userdata ) ;
2011-06-28 04:06:05 +04:00
static void init_copymap ( struct loadparm_service * pservice ) ;
2007-10-19 04:40:25 +04:00
static bool hash_a_service ( const char * name , int number ) ;
2005-10-23 20:29:02 +04:00
static void free_service_byindex ( int iService ) ;
2007-08-17 17:07:52 +04:00
static void show_parameter ( int parmIndex ) ;
2007-10-19 04:40:25 +04:00
static bool is_synonym_of ( int parm1 , int parm2 , bool * inverse ) ;
1996-05-04 11:50:46 +04:00
2008-07-16 17:49:28 +04:00
/*
* This is a helper function for parametrical options support . It returns a
* pointer to parametrical option value if it exists or NULL otherwise . Actual
* parametrical functions are quite simple
*/
2011-07-08 03:18:09 +04:00
static struct parmlist_entry * get_parametrics_by_service ( struct loadparm_service * service , const char * type ,
2011-07-07 14:33:55 +04:00
const char * option )
2003-04-24 07:46:17 +04:00
{
2011-06-29 09:06:49 +04:00
bool global_section = false ;
2003-04-24 07:46:17 +04:00
char * param_key ;
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data ;
2009-11-21 18:17:16 +03:00
2011-07-07 14:33:55 +04:00
if ( service = = NULL ) {
2003-04-24 07:46:17 +04:00
data = Globals . param_opt ;
2011-06-29 09:05:37 +04:00
global_section = true ;
2003-04-24 07:46:17 +04:00
} else {
2011-07-07 14:33:55 +04:00
data = service - > param_opt ;
2003-04-24 07:46:17 +04:00
}
2009-11-21 18:17:16 +03:00
2008-02-25 17:24:49 +03:00
if ( asprintf ( & param_key , " %s:%s " , type , option ) = = - 1 ) {
2003-04-24 07:46:17 +04:00
DEBUG ( 0 , ( " asprintf failed! \n " ) ) ;
return NULL ;
}
while ( data ) {
2008-07-16 18:08:28 +04:00
if ( strwicmp ( data - > key , param_key ) = = 0 ) {
2003-04-24 07:46:17 +04:00
string_free ( & param_key ) ;
return data ;
}
data = data - > next ;
}
if ( ! global_section ) {
/* Try to fetch the same option but from globals */
/* but only if we are not already working with Globals */
data = Globals . param_opt ;
while ( data ) {
2008-07-16 18:08:28 +04:00
if ( strwicmp ( data - > key , param_key ) = = 0 ) {
2003-04-24 07:46:17 +04:00
string_free ( & param_key ) ;
return data ;
}
data = data - > next ;
}
}
string_free ( & param_key ) ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
return NULL ;
}
2011-07-07 14:33:55 +04:00
/*
* This is a helper function for parametrical options support . It returns a
* pointer to parametrical option value if it exists or NULL otherwise . Actual
* parametrical functions are quite simple
*/
2011-07-08 03:18:09 +04:00
static struct parmlist_entry * get_parametrics ( int snum , const char * type ,
2011-07-07 14:33:55 +04:00
const char * option )
{
if ( snum > = iNumServices ) return NULL ;
if ( snum < 0 ) {
return get_parametrics_by_service ( NULL , type , option ) ;
} else {
return get_parametrics_by_service ( ServicePtrs [ snum ] , type , option ) ;
}
}
2003-04-24 07:46:17 +04:00
2006-02-28 03:59:14 +03:00
# define MISSING_PARAMETER(name) \
DEBUG ( 0 , ( " %s(): value is NULL or empty! \n " , # name ) )
2003-04-24 07:46:17 +04:00
/*******************************************************************
convenience routine to return int parameters .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int lp_int ( const char * s )
{
2006-02-28 03:59:14 +03:00
if ( ! s | | ! * s ) {
MISSING_PARAMETER ( lp_int ) ;
2003-04-24 07:46:17 +04:00
return ( - 1 ) ;
}
2007-04-17 02:42:45 +04:00
return ( int ) strtol ( s , NULL , 0 ) ;
2003-04-24 07:46:17 +04:00
}
/*******************************************************************
convenience routine to return unsigned long parameters .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-28 03:59:14 +03:00
static unsigned long lp_ulong ( const char * s )
2003-04-24 07:46:17 +04:00
{
2006-02-28 03:59:14 +03:00
if ( ! s | | ! * s ) {
MISSING_PARAMETER ( lp_ulong ) ;
return ( 0 ) ;
2003-04-24 07:46:17 +04:00
}
2007-04-17 02:42:45 +04:00
return strtoul ( s , NULL , 0 ) ;
2003-04-24 07:46:17 +04:00
}
/*******************************************************************
convenience routine to return boolean parameters .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool lp_bool ( const char * s )
2003-04-24 07:46:17 +04:00
{
2011-06-29 09:06:49 +04:00
bool ret = false ;
2003-04-24 07:46:17 +04:00
2006-02-28 03:59:14 +03:00
if ( ! s | | ! * s ) {
MISSING_PARAMETER ( lp_bool ) ;
2011-06-29 09:06:49 +04:00
return false ;
2003-04-24 07:46:17 +04:00
}
2009-11-21 18:17:16 +03:00
2008-11-01 05:14:43 +03:00
if ( ! set_boolean ( s , & ret ) ) {
2003-04-24 07:46:17 +04:00
DEBUG ( 0 , ( " lp_bool(%s): value is not boolean! \n " , s ) ) ;
2011-06-29 09:06:49 +04:00
return false ;
2003-04-24 07:46:17 +04:00
}
return ret ;
}
/*******************************************************************
convenience routine to return enum parameters .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int lp_enum ( const char * s , const struct enum_list * _enum )
{
int i ;
2006-02-28 03:59:14 +03:00
if ( ! s | | ! * s | | ! _enum ) {
MISSING_PARAMETER ( lp_enum ) ;
2003-04-24 07:46:17 +04:00
return ( - 1 ) ;
}
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
for ( i = 0 ; _enum [ i ] . name ; i + + ) {
2003-10-23 03:38:20 +04:00
if ( strequal ( _enum [ i ] . name , s ) )
2003-04-24 07:46:17 +04:00
return _enum [ i ] . value ;
}
DEBUG ( 0 , ( " lp_enum(%s,enum): value is not in enum_list! \n " , s ) ) ;
return ( - 1 ) ;
}
2006-02-28 03:59:14 +03:00
# undef MISSING_PARAMETER
2003-04-24 07:46:17 +04:00
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
2012-07-18 09:37:23 +04:00
char * lp_parm_talloc_string ( TALLOC_CTX * ctx , int snum , const char * type , const char * option , const char * def )
2003-04-24 07:46:17 +04:00
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics ( snum , type , option ) ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
if ( data = = NULL | | data - > value = = NULL ) {
if ( def ) {
2012-07-18 09:37:23 +04:00
return lp_string ( ctx , def ) ;
2003-04-24 07:46:17 +04:00
} else {
return NULL ;
}
}
2012-07-18 09:37:23 +04:00
return lp_string ( ctx , data - > value ) ;
2003-04-24 07:46:17 +04:00
}
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
const char * lp_parm_const_string ( int snum , const char * type , const char * option , const char * def )
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics ( snum , type , option ) ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
if ( data = = NULL | | data - > value = = NULL )
return def ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
return data - > value ;
}
2011-07-07 14:33:55 +04:00
const char * lp_parm_const_string_service ( struct loadparm_service * service , const char * type , const char * option )
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics_by_service ( service , type , option ) ;
2011-07-07 14:33:55 +04:00
if ( data = = NULL | | data - > value = = NULL )
return NULL ;
return data - > value ;
}
2003-04-24 07:46:17 +04:00
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
const char * * lp_parm_string_list ( int snum , const char * type , const char * option , const char * * def )
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics ( snum , type , option ) ;
2003-04-24 07:46:17 +04:00
if ( data = = NULL | | data - > value = = NULL )
return ( const char * * ) def ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
if ( data - > list = = NULL ) {
2010-10-07 23:29:19 +04:00
data - > list = str_list_make_v3 ( NULL , data - > value , NULL ) ;
2003-04-24 07:46:17 +04:00
}
return ( const char * * ) data - > list ;
}
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
int lp_parm_int ( int snum , const char * type , const char * option , int def )
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics ( snum , type , option ) ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
if ( data & & data - > value & & * data - > value )
return lp_int ( data - > value ) ;
return def ;
}
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
unsigned long lp_parm_ulong ( int snum , const char * type , const char * option , unsigned long def )
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics ( snum , type , option ) ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
if ( data & & data - > value & & * data - > value )
return lp_ulong ( data - > value ) ;
return def ;
}
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
2007-10-19 04:40:25 +04:00
bool lp_parm_bool ( int snum , const char * type , const char * option , bool def )
2003-04-24 07:46:17 +04:00
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics ( snum , type , option ) ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
if ( data & & data - > value & & * data - > value )
return lp_bool ( data - > value ) ;
return def ;
}
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
int lp_parm_enum ( int snum , const char * type , const char * option ,
const struct enum_list * _enum , int def )
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data = get_parametrics ( snum , type , option ) ;
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
if ( data & & data - > value & & * data - > value & & _enum )
return lp_enum ( data - > value , _enum ) ;
return def ;
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Initialise a service to the defaults .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-28 04:06:05 +04:00
static void init_service ( struct loadparm_service * pservice )
1996-05-04 11:50:46 +04:00
{
2011-06-28 04:06:05 +04:00
memset ( ( char * ) pservice , ' \0 ' , sizeof ( struct loadparm_service ) ) ;
2000-05-29 03:34:34 +04:00
copy_service ( pservice , & sDefault , NULL ) ;
1996-05-04 11:50:46 +04:00
}
2008-09-28 00:19:56 +04:00
2008-09-24 23:59:34 +04:00
/**
* free a param_opts structure .
* param_opts handling should be moved to talloc ;
* then this whole functions reduces to a TALLOC_FREE ( ) .
*/
2011-07-08 03:18:09 +04:00
static void free_param_opts ( struct parmlist_entry * * popts )
2008-09-24 23:59:34 +04:00
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * opt , * next_opt ;
2008-09-24 23:59:34 +04:00
if ( * popts ! = NULL ) {
DEBUG ( 5 , ( " Freeing parametrics: \n " ) ) ;
}
opt = * popts ;
while ( opt ! = NULL ) {
string_free ( & opt - > key ) ;
string_free ( & opt - > value ) ;
TALLOC_FREE ( opt - > list ) ;
next_opt = opt - > next ;
SAFE_FREE ( opt ) ;
opt = next_opt ;
}
* popts = NULL ;
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Free the dynamically allocated parts of a service struct .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-28 04:06:05 +04:00
static void free_service ( struct loadparm_service * pservice )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
if ( ! pservice )
return ;
if ( pservice - > szService )
2002-11-13 02:20:50 +03:00
DEBUG ( 5 , ( " free_service: Freeing service %s \n " ,
2000-05-29 03:34:34 +04:00
pservice - > szService ) ) ;
2008-12-15 16:42:13 +03:00
free_parameters ( pservice ) ;
2008-09-28 00:19:56 +04:00
2000-05-29 03:34:34 +04:00
string_free ( & pservice - > szService ) ;
2010-03-28 16:13:48 +04:00
TALLOC_FREE ( pservice - > copymap ) ;
1998-01-24 15:34:16 +03:00
2008-09-24 23:59:34 +04:00
free_param_opts ( & pservice - > param_opt ) ;
2001-05-11 02:10:31 +04:00
ZERO_STRUCTP ( pservice ) ;
1996-05-04 11:50:46 +04:00
}
2005-10-23 20:29:02 +04:00
/***************************************************************************
remove a service indexed in the ServicePtrs array from the ServiceHash
and free the dynamically allocated parts
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void free_service_byindex ( int idx )
{
2005-10-25 18:54:41 +04:00
if ( ! LP_SNUM_OK ( idx ) )
2005-10-23 20:29:02 +04:00
return ;
2011-06-29 09:06:49 +04:00
ServicePtrs [ idx ] - > valid = false ;
2005-10-25 18:54:41 +04:00
/* we have to cleanup the hash record */
2005-10-23 20:29:02 +04:00
if ( ServicePtrs [ idx ] - > szService ) {
2007-11-24 21:56:41 +03:00
char * canon_name = canonicalize_servicename (
2010-03-23 01:57:31 +03:00
talloc_tos ( ) ,
2007-11-24 21:56:41 +03:00
ServicePtrs [ idx ] - > szService ) ;
2009-11-21 18:17:16 +03:00
2007-11-24 21:56:41 +03:00
dbwrap_delete_bystring ( ServiceHash , canon_name ) ;
TALLOC_FREE ( canon_name ) ;
2005-10-23 20:29:02 +04:00
}
2005-10-25 18:54:41 +04:00
2005-10-23 20:29:02 +04:00
free_service ( ServicePtrs [ idx ] ) ;
2012-07-23 06:50:26 +04:00
talloc_free_children ( ServicePtrs [ idx ] ) ;
2005-10-23 20:29:02 +04:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Add a new service to the services array initialising it with the given
service .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-28 04:06:05 +04:00
static int add_a_service ( const struct loadparm_service * pservice , const char * name )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
int i ;
2011-06-28 04:06:05 +04:00
struct loadparm_service tservice ;
2000-05-29 03:34:34 +04:00
int num_to_alloc = iNumServices + 1 ;
2013-09-27 17:29:41 +04:00
struct loadparm_service * * tsp = NULL ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
tservice = * pservice ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
/* it might already exist */
2002-11-13 02:20:50 +03:00
if ( name ) {
2000-05-29 03:34:34 +04:00
i = getservicebyname ( name , NULL ) ;
2003-04-24 07:46:17 +04:00
if ( i > = 0 ) {
2000-05-29 03:34:34 +04:00
return ( i ) ;
2003-04-24 07:46:17 +04:00
}
2000-05-29 03:34:34 +04:00
}
1996-05-04 11:50:46 +04:00
2013-09-27 17:29:41 +04:00
/* if not, then create one */
2005-10-23 20:29:02 +04:00
i = iNumServices ;
2013-09-27 17:29:41 +04:00
tsp = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR ( ServicePtrs , struct loadparm_service * , num_to_alloc ) ;
if ( tsp = = NULL ) {
DEBUG ( 0 , ( " add_a_service: failed to enlarge ServicePtrs! \n " ) ) ;
return ( - 1 ) ;
2005-10-23 20:29:02 +04:00
}
2013-09-27 17:29:41 +04:00
ServicePtrs = tsp ;
ServicePtrs [ iNumServices ] = talloc ( NULL , struct loadparm_service ) ;
if ( ! ServicePtrs [ iNumServices ] ) {
DEBUG ( 0 , ( " add_a_service: out of memory! \n " ) ) ;
return ( - 1 ) ;
2005-10-23 20:29:02 +04:00
}
2013-09-27 17:29:41 +04:00
iNumServices + + ;
1996-05-04 11:50:46 +04:00
2011-06-29 09:05:37 +04:00
ServicePtrs [ i ] - > valid = true ;
1996-05-04 11:50:46 +04:00
2001-05-11 02:10:31 +04:00
init_service ( ServicePtrs [ i ] ) ;
copy_service ( ServicePtrs [ i ] , & tservice , NULL ) ;
2000-05-29 03:34:34 +04:00
if ( name )
2001-05-11 02:10:31 +04:00
string_set ( & ServicePtrs [ i ] - > szService , name ) ;
2009-11-21 18:17:16 +03:00
2004-08-27 00:47:58 +04:00
DEBUG ( 8 , ( " add_a_service: Creating snum = %d for %s \n " ,
i , ServicePtrs [ i ] - > szService ) ) ;
2005-10-23 20:29:02 +04:00
if ( ! hash_a_service ( ServicePtrs [ i ] - > szService , i ) ) {
return ( - 1 ) ;
}
2009-11-21 18:17:16 +03:00
2000-05-29 03:34:34 +04:00
return ( i ) ;
1996-05-04 11:50:46 +04:00
}
2005-10-23 20:29:02 +04:00
/***************************************************************************
2007-10-11 00:34:30 +04:00
Convert a string to uppercase and remove whitespaces .
2005-10-23 20:29:02 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-03-23 01:57:31 +03:00
char * canonicalize_servicename ( TALLOC_CTX * ctx , const char * src )
2005-10-23 20:29:02 +04:00
{
2007-11-24 21:56:41 +03:00
char * result ;
2005-10-23 20:29:02 +04:00
2005-10-25 18:54:41 +04:00
if ( ! src ) {
DEBUG ( 0 , ( " canonicalize_servicename: NULL source name! \n " ) ) ;
return NULL ;
}
2010-03-23 01:57:31 +03:00
result = talloc_strdup ( ctx , src ) ;
2007-11-24 21:56:41 +03:00
SMB_ASSERT ( result ! = NULL ) ;
2005-10-25 18:54:41 +04:00
2012-08-09 04:01:00 +04:00
if ( ! strlower_m ( result ) ) {
TALLOC_FREE ( result ) ;
return NULL ;
}
2007-11-24 21:56:41 +03:00
return result ;
2005-10-23 20:29:02 +04:00
}
/***************************************************************************
Add a name / index pair for the services array to the hash table .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool hash_a_service ( const char * name , int idx )
2005-10-23 20:29:02 +04:00
{
2005-10-25 18:54:41 +04:00
char * canon_name ;
if ( ! ServiceHash ) {
2007-11-24 23:42:46 +03:00
DEBUG ( 10 , ( " hash_a_service: creating servicehash \n " ) ) ;
ServiceHash = db_open_rbt ( NULL ) ;
2005-10-25 18:54:41 +04:00
if ( ! ServiceHash ) {
2005-10-23 20:29:02 +04:00
DEBUG ( 0 , ( " hash_a_service: open tdb servicehash failed! \n " ) ) ;
2011-06-29 09:06:49 +04:00
return false ;
2005-10-23 20:29:02 +04:00
}
}
2005-10-25 18:54:41 +04:00
2005-10-23 20:29:02 +04:00
DEBUG ( 10 , ( " hash_a_service: hashing index %d for service name %s \n " ,
2005-10-25 18:54:41 +04:00
idx , name ) ) ;
2010-03-23 01:57:31 +03:00
canon_name = canonicalize_servicename ( talloc_tos ( ) , name ) ;
2007-11-24 21:56:41 +03:00
dbwrap_store_bystring ( ServiceHash , canon_name ,
make_tdb_data ( ( uint8 * ) & idx , sizeof ( idx ) ) ,
TDB_REPLACE ) ;
2005-10-25 18:54:41 +04:00
2007-11-24 21:56:41 +03:00
TALLOC_FREE ( canon_name ) ;
2005-10-25 18:54:41 +04:00
2011-06-29 09:05:37 +04:00
return true ;
2005-10-23 20:29:02 +04:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2007-11-14 05:42:42 +03:00
Add a new home service , with the specified home directory , defaults coming
2002-11-13 02:20:50 +03:00
from service ifrom .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-11-14 05:42:42 +03:00
bool lp_add_home ( const char * pszHomename , int iDefaultService ,
2002-07-15 14:35:28 +04:00
const char * user , const char * pszHomedir )
1996-05-04 11:50:46 +04:00
{
2001-11-05 08:28:03 +03:00
int i ;
2002-07-15 14:35:28 +04:00
2009-10-01 21:23:29 +04:00
if ( pszHomename = = NULL | | user = = NULL | | pszHomedir = = NULL | |
pszHomedir [ 0 ] = = ' \0 ' ) {
return false ;
}
2001-11-05 08:28:03 +03:00
i = add_a_service ( ServicePtrs [ iDefaultService ] , pszHomename ) ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
if ( i < 0 )
2011-10-06 09:58:32 +04:00
return false ;
1996-05-04 11:50:46 +04:00
2013-12-24 07:03:16 +04:00
if ( ! ( * ( ServicePtrs [ iDefaultService ] - > pathname ) )
| | strequal ( ServicePtrs [ iDefaultService ] - > pathname ,
2012-07-18 09:37:23 +04:00
lp_pathname ( talloc_tos ( ) , GLOBAL_SECTION_SNUM ) ) ) {
2013-12-24 07:03:16 +04:00
string_set ( & ServicePtrs [ i ] - > pathname , pszHomedir ) ;
2007-11-14 05:42:42 +03:00
}
2002-07-15 14:35:28 +04:00
2002-11-13 02:20:50 +03:00
if ( ! ( * ( ServicePtrs [ i ] - > comment ) ) ) {
2007-11-14 05:42:42 +03:00
char * comment = NULL ;
if ( asprintf ( & comment , " Home directory of %s " , user ) < 0 ) {
return false ;
}
2001-05-11 02:10:31 +04:00
string_set ( & ServicePtrs [ i ] - > comment , comment ) ;
2007-11-14 05:42:42 +03:00
SAFE_FREE ( comment ) ;
2000-05-29 03:34:34 +04:00
}
1996-05-04 11:50:46 +04:00
2005-12-16 18:58:31 +03:00
/* set the browseable flag from the global default */
2003-08-28 20:13:16 +04:00
2013-12-24 07:03:17 +04:00
ServicePtrs [ i ] - > browseable = sDefault . browseable ;
2013-12-24 07:03:29 +04:00
ServicePtrs [ i ] - > access_based_share_enum = sDefault . access_based_share_enum ;
2003-08-28 20:13:16 +04:00
2011-06-29 09:05:37 +04:00
ServicePtrs [ i ] - > autoloaded = true ;
2004-06-21 21:51:06 +04:00
2002-11-13 02:20:50 +03:00
DEBUG ( 3 , ( " adding home's share [%s] for user '%s' at '%s' \n " , pszHomename ,
2013-12-24 07:03:16 +04:00
user , ServicePtrs [ i ] - > pathname ) ) ;
2007-11-14 05:42:42 +03:00
2011-10-06 09:58:32 +04:00
return true ;
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
2002-11-13 02:20:50 +03:00
Add a new service , based on an old one .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2002-01-16 05:42:07 +03:00
int lp_add_service ( const char * pszService , int iDefaultService )
1996-05-04 11:50:46 +04:00
{
2006-11-30 10:38:40 +03:00
if ( iDefaultService < 0 ) {
return add_a_service ( & sDefault , pszService ) ;
}
2001-05-11 02:10:31 +04:00
return ( add_a_service ( ServicePtrs [ iDefaultService ] , pszService ) ) ;
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
2002-11-13 02:20:50 +03:00
Add the IPC service .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
static bool lp_add_ipc ( const char * ipc_name , bool guest_ok )
1996-05-04 11:50:46 +04:00
{
2007-11-14 05:42:42 +03:00
char * comment = NULL ;
2001-03-13 03:31:07 +03:00
int i = add_a_service ( & sDefault , ipc_name ) ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
if ( i < 0 )
2011-10-06 09:58:32 +04:00
return false ;
1996-05-04 11:50:46 +04:00
2007-11-14 05:42:42 +03:00
if ( asprintf ( & comment , " IPC Service (%s) " ,
2013-12-24 07:04:33 +04:00
Globals . serverstring ) < 0 ) {
2011-10-06 09:58:32 +04:00
return false ;
2007-11-14 05:42:42 +03:00
}
1996-05-04 11:50:46 +04:00
2013-12-24 07:03:16 +04:00
string_set ( & ServicePtrs [ i ] - > pathname , tmpdir ( ) ) ;
2013-12-24 07:03:21 +04:00
string_set ( & ServicePtrs [ i ] - > username , " " ) ;
2001-05-11 02:10:31 +04:00
string_set ( & ServicePtrs [ i ] - > comment , comment ) ;
string_set ( & ServicePtrs [ i ] - > fstype , " IPC " ) ;
2013-12-24 07:03:19 +04:00
ServicePtrs [ i ] - > max_connections = 0 ;
2011-06-29 09:05:37 +04:00
ServicePtrs [ i ] - > bAvailable = true ;
2013-12-24 07:03:17 +04:00
ServicePtrs [ i ] - > readonly = true ;
2013-12-24 07:03:29 +04:00
ServicePtrs [ i ] - > guest_only = false ;
2013-12-24 07:03:30 +04:00
ServicePtrs [ i ] - > administrative_share = true ;
2013-12-24 07:03:29 +04:00
ServicePtrs [ i ] - > guest_ok = guest_ok ;
2013-12-24 07:03:18 +04:00
ServicePtrs [ i ] - > print_ok = false ;
2013-12-24 07:03:17 +04:00
ServicePtrs [ i ] - > browseable = sDefault . browseable ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
DEBUG ( 3 , ( " adding IPC service \n " ) ) ;
1996-05-04 11:50:46 +04:00
2007-11-14 05:42:42 +03:00
SAFE_FREE ( comment ) ;
2011-10-06 09:58:32 +04:00
return true ;
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
2002-11-13 02:20:50 +03:00
Add a new printer service , with defaults coming from service iFrom .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
bool lp_add_printer ( const char * pszPrintername , int iDefaultService )
1996-05-04 11:50:46 +04:00
{
2002-08-17 21:00:51 +04:00
const char * comment = " From Printcap " ;
2001-05-11 02:10:31 +04:00
int i = add_a_service ( ServicePtrs [ iDefaultService ] , pszPrintername ) ;
2000-05-29 03:34:34 +04:00
if ( i < 0 )
2011-10-06 09:58:32 +04:00
return false ;
2000-05-29 03:34:34 +04:00
2011-06-29 09:05:37 +04:00
/* note that we do NOT default the availability flag to true - */
2000-05-29 03:34:34 +04:00
/* we take it from the default service passed. This allows all */
/* dynamic printers to be disabled by disabling the [printers] */
/* entry (if/when the 'available' keyword is implemented!). */
/* the printer name is set to the service name. */
2001-05-11 02:10:31 +04:00
string_set ( & ServicePtrs [ i ] - > szPrintername , pszPrintername ) ;
string_set ( & ServicePtrs [ i ] - > comment , comment ) ;
2003-08-22 17:39:49 +04:00
2003-08-28 20:13:16 +04:00
/* set the browseable flag from the gloabl default */
2013-12-24 07:03:17 +04:00
ServicePtrs [ i ] - > browseable = sDefault . browseable ;
2003-08-28 20:13:16 +04:00
2000-05-29 03:34:34 +04:00
/* Printers cannot be read_only. */
2013-12-24 07:03:17 +04:00
ServicePtrs [ i ] - > readonly = false ;
2000-05-29 03:34:34 +04:00
/* No oplocks on printer services. */
2013-12-24 07:03:18 +04:00
ServicePtrs [ i ] - > oplocks = false ;
2000-05-29 03:34:34 +04:00
/* Printer services must be printable. */
2013-12-24 07:03:18 +04:00
ServicePtrs [ i ] - > print_ok = true ;
2009-11-21 18:17:16 +03:00
2000-05-29 03:34:34 +04:00
DEBUG ( 3 , ( " adding printer service %s \n " , pszPrintername ) ) ;
2011-10-06 09:58:32 +04:00
return true ;
1996-05-04 11:50:46 +04:00
}
2007-06-29 16:30:41 +04:00
/***************************************************************************
Check whether the given parameter name is valid .
Parametric options ( names containing a colon ) are considered valid .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_parameter_is_valid ( const char * pszParmName )
2007-06-29 16:30:41 +04:00
{
2014-01-15 05:19:21 +04:00
return ( ( lpcfg_map_parameter ( pszParmName ) ! = - 1 ) | |
2007-06-29 16:30:41 +04:00
( strchr ( pszParmName , ' : ' ) ! = NULL ) ) ;
}
2007-06-29 17:07:54 +04:00
/***************************************************************************
Check whether the given name is the name of a global parameter .
2011-06-29 09:05:37 +04:00
Returns true for strings belonging to parameters of class
2011-06-29 09:06:49 +04:00
P_GLOBAL , false for all other strings , also for parametric options
2007-06-29 17:07:54 +04:00
and strings not belonging to any option .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_parameter_is_global ( const char * pszParmName )
2007-06-29 17:07:54 +04:00
{
2014-01-15 05:19:21 +04:00
int num = lpcfg_map_parameter ( pszParmName ) ;
2007-06-29 17:07:54 +04:00
if ( num > = 0 ) {
return ( parm_table [ num ] . p_class = = P_GLOBAL ) ;
}
2011-06-29 09:06:49 +04:00
return false ;
2007-06-29 17:07:54 +04:00
}
2007-08-20 13:32:30 +04:00
/**************************************************************************
Check whether the given name is the canonical name of a parameter .
2011-06-29 09:06:49 +04:00
Returns false if it is not a valid parameter Name .
2011-06-29 09:05:37 +04:00
For parametric options , true is returned .
2007-08-20 13:32:30 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_parameter_is_canonical ( const char * parm_name )
2007-08-20 13:32:30 +04:00
{
if ( ! lp_parameter_is_valid ( parm_name ) ) {
2011-06-29 09:06:49 +04:00
return false ;
2007-08-20 13:32:30 +04:00
}
2014-01-15 05:19:21 +04:00
return ( lpcfg_map_parameter ( parm_name ) = =
2007-08-20 13:32:30 +04:00
map_parameter_canonical ( parm_name , NULL ) ) ;
}
2007-08-16 19:27:06 +04:00
/**************************************************************************
Determine the canonical name for a parameter .
Indicate when it is an inverse ( boolean ) synonym instead of a
" usual " synonym .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_canonicalize_parameter ( const char * parm_name , const char * * canon_parm ,
bool * inverse )
2007-08-16 19:27:06 +04:00
{
2007-08-17 19:38:19 +04:00
int num ;
2007-08-16 19:27:06 +04:00
if ( ! lp_parameter_is_valid ( parm_name ) ) {
* canon_parm = NULL ;
2011-06-29 09:06:49 +04:00
return false ;
2007-08-16 19:27:06 +04:00
}
2007-08-17 19:38:19 +04:00
num = map_parameter_canonical ( parm_name , inverse ) ;
if ( num < 0 ) {
/* parametric option */
2007-08-16 19:27:06 +04:00
* canon_parm = parm_name ;
2007-08-17 19:38:19 +04:00
} else {
* canon_parm = parm_table [ num ] . label ;
2007-08-16 19:27:06 +04:00
}
2011-06-29 09:05:37 +04:00
return true ;
2007-08-17 19:38:19 +04:00
2007-08-16 19:27:06 +04:00
}
2007-08-17 20:03:18 +04:00
/**************************************************************************
Determine the canonical name for a parameter .
Turn the value given into the inverse boolean expression when
the synonym is an invers boolean synonym .
2011-06-29 09:05:37 +04:00
Return true if parm_name is a valid parameter name and
2007-08-17 20:03:18 +04:00
in case it is an invers boolean synonym , if the val string could
successfully be converted to the reverse bool .
Return false in all other cases .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_canonicalize_parameter_with_value ( const char * parm_name ,
2007-08-17 20:03:18 +04:00
const char * val ,
const char * * canon_parm ,
const char * * canon_val )
{
int num ;
2007-10-19 04:40:25 +04:00
bool inverse ;
2007-08-17 20:03:18 +04:00
if ( ! lp_parameter_is_valid ( parm_name ) ) {
* canon_parm = NULL ;
* canon_val = NULL ;
2011-06-29 09:06:49 +04:00
return false ;
2007-08-17 20:03:18 +04:00
}
num = map_parameter_canonical ( parm_name , & inverse ) ;
if ( num < 0 ) {
/* parametric option */
* canon_parm = parm_name ;
* canon_val = val ;
} else {
* canon_parm = parm_table [ num ] . label ;
if ( inverse ) {
if ( ! lp_invert_boolean ( val , canon_val ) ) {
* canon_val = NULL ;
2011-06-29 09:06:49 +04:00
return false ;
2007-08-17 20:03:18 +04:00
}
} else {
* canon_val = val ;
}
}
2011-06-29 09:05:37 +04:00
return true ;
2007-08-17 20:03:18 +04:00
}
2007-08-17 19:38:19 +04:00
/***************************************************************************
Map a parameter ' s string representation to the index of the canonical
form of the parameter ( it might be a synonym ) .
Returns - 1 if the parameter string is not recognised .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static int map_parameter_canonical ( const char * pszParmName , bool * inverse )
2007-08-17 19:38:19 +04:00
{
int parm_num , canon_num ;
2011-06-29 09:06:49 +04:00
bool loc_inverse = false ;
2007-08-17 19:38:19 +04:00
2014-01-15 05:19:21 +04:00
parm_num = lpcfg_map_parameter ( pszParmName ) ;
2007-08-17 19:38:19 +04:00
if ( ( parm_num < 0 ) | | ! ( parm_table [ parm_num ] . flags & FLAG_HIDE ) ) {
/* invalid, parametric or no canidate for synonyms ... */
2007-08-20 13:32:30 +04:00
goto done ;
2007-08-17 19:38:19 +04:00
}
for ( canon_num = 0 ; parm_table [ canon_num ] . label ; canon_num + + ) {
2007-08-20 13:32:30 +04:00
if ( is_synonym_of ( parm_num , canon_num , & loc_inverse ) ) {
parm_num = canon_num ;
goto done ;
2007-08-17 19:38:19 +04:00
}
}
2007-08-20 13:32:30 +04:00
done :
if ( inverse ! = NULL ) {
* inverse = loc_inverse ;
}
2007-08-17 19:38:19 +04:00
return parm_num ;
1996-05-04 11:50:46 +04:00
}
2007-08-17 18:10:49 +04:00
/***************************************************************************
return true if parameter number parm1 is a synonym of parameter
number parm2 ( parm2 being the principal name ) .
2011-06-29 09:05:37 +04:00
set inverse to true if parm1 is P_BOOLREV and parm2 is P_BOOL ,
2011-06-29 09:06:49 +04:00
false otherwise .
2007-08-17 18:10:49 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool is_synonym_of ( int parm1 , int parm2 , bool * inverse )
2007-08-17 18:10:49 +04:00
{
2011-06-29 04:48:35 +04:00
if ( ( parm_table [ parm1 ] . offset = = parm_table [ parm2 ] . offset ) & &
2011-07-07 15:16:24 +04:00
( parm_table [ parm1 ] . p_class = = parm_table [ parm2 ] . p_class ) & &
2007-08-17 18:10:49 +04:00
( parm_table [ parm1 ] . flags & FLAG_HIDE ) & &
! ( parm_table [ parm2 ] . flags & FLAG_HIDE ) )
{
2007-08-20 13:32:30 +04:00
if ( inverse ! = NULL ) {
if ( ( parm_table [ parm1 ] . type = = P_BOOLREV ) & &
( parm_table [ parm2 ] . type = = P_BOOL ) )
{
2011-06-29 09:05:37 +04:00
* inverse = true ;
2007-08-20 13:32:30 +04:00
} else {
2011-06-29 09:06:49 +04:00
* inverse = false ;
2007-08-20 13:32:30 +04:00
}
2007-08-17 18:10:49 +04:00
}
2011-06-29 09:05:37 +04:00
return true ;
2007-08-17 18:10:49 +04:00
}
2011-06-29 09:06:49 +04:00
return false ;
2007-08-17 18:10:49 +04:00
}
2005-06-12 20:00:29 +04:00
/***************************************************************************
2007-08-17 17:07:52 +04:00
Show one parameter ' s name , type , [ values , ] and flags .
( helper functions for show_parameter_list )
2005-06-12 20:00:29 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-08-17 17:07:52 +04:00
static void show_parameter ( int parmIndex )
2005-06-12 20:00:29 +04:00
{
2007-08-17 17:07:52 +04:00
int enumIndex , flagIndex ;
2007-08-17 18:10:49 +04:00
int parmIndex2 ;
2007-10-19 04:40:25 +04:00
bool hadFlag ;
bool hadSyn ;
bool inverse ;
2007-12-07 23:26:32 +03:00
const char * type [ ] = { " P_BOOL " , " P_BOOLREV " , " P_CHAR " , " P_INTEGER " ,
" P_OCTAL " , " P_LIST " , " P_STRING " , " P_USTRING " ,
" P_ENUM " , " P_SEP " } ;
2005-06-12 20:00:29 +04:00
unsigned flags [ ] = { FLAG_BASIC , FLAG_SHARE , FLAG_PRINT , FLAG_GLOBAL ,
FLAG_WIZARD , FLAG_ADVANCED , FLAG_DEVELOPER , FLAG_DEPRECATED ,
2011-06-29 07:22:26 +04:00
FLAG_HIDE } ;
2005-06-13 13:33:09 +04:00
const char * flag_names [ ] = { " FLAG_BASIC " , " FLAG_SHARE " , " FLAG_PRINT " ,
2005-06-12 20:00:29 +04:00
" FLAG_GLOBAL " , " FLAG_WIZARD " , " FLAG_ADVANCED " , " FLAG_DEVELOPER " ,
2011-06-29 07:22:26 +04:00
" FLAG_DEPRECATED " , " FLAG_HIDE " , NULL } ;
2005-06-12 20:00:29 +04:00
2007-08-17 17:07:52 +04:00
printf ( " %s=%s " , parm_table [ parmIndex ] . label ,
type [ parm_table [ parmIndex ] . type ] ) ;
if ( parm_table [ parmIndex ] . type = = P_ENUM ) {
printf ( " , " ) ;
for ( enumIndex = 0 ;
parm_table [ parmIndex ] . enum_list [ enumIndex ] . name ;
enumIndex + + )
{
printf ( " %s%s " ,
enumIndex ? " | " : " " ,
parm_table [ parmIndex ] . enum_list [ enumIndex ] . name ) ;
}
}
printf ( " , " ) ;
2011-06-29 09:06:49 +04:00
hadFlag = false ;
2007-08-17 17:07:52 +04:00
for ( flagIndex = 0 ; flag_names [ flagIndex ] ; flagIndex + + ) {
if ( parm_table [ parmIndex ] . flags & flags [ flagIndex ] ) {
printf ( " %s%s " ,
hadFlag ? " | " : " " ,
flag_names [ flagIndex ] ) ;
2011-06-29 09:05:37 +04:00
hadFlag = true ;
2007-08-17 17:07:52 +04:00
}
}
2007-08-17 18:10:49 +04:00
/* output synonyms */
2011-06-29 09:06:49 +04:00
hadSyn = false ;
2007-08-17 18:10:49 +04:00
for ( parmIndex2 = 0 ; parm_table [ parmIndex2 ] . label ; parmIndex2 + + ) {
if ( is_synonym_of ( parmIndex , parmIndex2 , & inverse ) ) {
printf ( " (%ssynonym of %s) " , inverse ? " inverse " : " " ,
parm_table [ parmIndex2 ] . label ) ;
} else if ( is_synonym_of ( parmIndex2 , parmIndex , & inverse ) ) {
if ( ! hadSyn ) {
printf ( " (synonyms: " ) ;
2011-06-29 09:05:37 +04:00
hadSyn = true ;
2007-08-17 18:10:49 +04:00
} else {
printf ( " , " ) ;
}
printf ( " %s%s " , parm_table [ parmIndex2 ] . label ,
inverse ? " [i] " : " " ) ;
}
}
if ( hadSyn ) {
printf ( " ) " ) ;
}
2007-08-17 17:07:52 +04:00
printf ( " \n " ) ;
}
/***************************************************************************
Show all parameter ' s name , type , [ values , ] and flags .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void show_parameter_list ( void )
{
int classIndex , parmIndex ;
const char * section_names [ ] = { " local " , " global " , NULL } ;
for ( classIndex = 0 ; section_names [ classIndex ] ; classIndex + + ) {
2005-06-12 20:00:29 +04:00
printf ( " [%s] \n " , section_names [ classIndex ] ) ;
for ( parmIndex = 0 ; parm_table [ parmIndex ] . label ; parmIndex + + ) {
2005-06-25 00:25:18 +04:00
if ( parm_table [ parmIndex ] . p_class = = classIndex ) {
2007-08-17 17:07:52 +04:00
show_parameter ( parmIndex ) ;
2005-06-12 20:00:29 +04:00
}
}
}
}
2007-08-21 18:47:15 +04:00
/***************************************************************************
Check if a given string correctly represents a boolean value .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_string_is_valid_boolean ( const char * parm_value )
2007-08-21 18:47:15 +04:00
{
2008-11-01 05:14:43 +03:00
return set_boolean ( parm_value , NULL ) ;
2007-08-21 18:47:15 +04:00
}
2007-08-16 19:27:06 +04:00
/***************************************************************************
Get the standard string representation of a boolean value ( " yes " or " no " )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static const char * get_boolean ( bool bool_value )
2007-08-16 19:27:06 +04:00
{
static const char * yes_str = " yes " ;
static const char * no_str = " no " ;
return ( bool_value ? yes_str : no_str ) ;
}
/***************************************************************************
Provide the string of the negated boolean value associated to the boolean
2011-06-29 09:06:49 +04:00
given as a string . Returns false if the passed string does not correctly
2007-08-16 19:27:06 +04:00
represent a boolean .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_invert_boolean ( const char * str , const char * * inverse_str )
2007-08-16 19:27:06 +04:00
{
2007-10-19 04:40:25 +04:00
bool val ;
2007-08-16 19:27:06 +04:00
2008-11-01 05:14:43 +03:00
if ( ! set_boolean ( str , & val ) ) {
2011-06-29 09:06:49 +04:00
return false ;
2007-08-16 19:27:06 +04:00
}
* inverse_str = get_boolean ( ! val ) ;
2011-06-29 09:05:37 +04:00
return true ;
2007-08-16 19:27:06 +04:00
}
/***************************************************************************
Provide the canonical string representation of a boolean value given
2011-06-29 09:06:49 +04:00
as a string . Return true on success , false if the string given does
2007-08-16 19:27:06 +04:00
not correctly represent a boolean .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_canonicalize_boolean ( const char * str , const char * * canon_str )
2007-08-16 19:27:06 +04:00
{
2007-10-19 04:40:25 +04:00
bool val ;
2007-08-16 19:27:06 +04:00
2008-11-01 05:14:43 +03:00
if ( ! set_boolean ( str , & val ) ) {
2011-06-29 09:06:49 +04:00
return false ;
2007-08-16 19:27:06 +04:00
}
* canon_str = get_boolean ( val ) ;
2011-06-29 09:05:37 +04:00
return true ;
2007-08-16 19:27:06 +04:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
Find a service by name . Otherwise works like get_service .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-28 04:06:05 +04:00
static int getservicebyname ( const char * pszServiceName , struct loadparm_service * pserviceDest )
2000-05-29 03:34:34 +04:00
{
2005-10-23 20:29:02 +04:00
int iService = - 1 ;
2005-10-25 18:54:41 +04:00
char * canon_name ;
2007-11-24 21:56:41 +03:00
TDB_DATA data ;
2011-08-24 15:08:13 +04:00
NTSTATUS status ;
2005-10-23 20:29:02 +04:00
2007-11-24 21:56:41 +03:00
if ( ServiceHash = = NULL ) {
return - 1 ;
}
2005-10-25 18:54:41 +04:00
2010-03-23 01:57:31 +03:00
canon_name = canonicalize_servicename ( talloc_tos ( ) , pszServiceName ) ;
2005-10-25 18:54:41 +04:00
2011-08-24 15:08:13 +04:00
status = dbwrap_fetch_bystring ( ServiceHash , canon_name , canon_name ,
& data ) ;
2007-11-24 21:56:41 +03:00
2011-08-24 15:08:13 +04:00
if ( NT_STATUS_IS_OK ( status ) & &
( data . dptr ! = NULL ) & &
( data . dsize = = sizeof ( iService ) ) )
{
2007-11-24 21:56:41 +03:00
iService = * ( int * ) data . dptr ;
}
TALLOC_FREE ( canon_name ) ;
if ( ( iService ! = - 1 ) & & ( LP_SNUM_OK ( iService ) )
& & ( pserviceDest ! = NULL ) ) {
copy_service ( pserviceDest , ServicePtrs [ iService ] , NULL ) ;
2005-10-23 20:29:02 +04:00
}
2005-10-25 18:54:41 +04:00
2000-05-29 03:34:34 +04:00
return ( iService ) ;
1996-05-04 11:50:46 +04:00
}
2011-07-07 14:33:55 +04:00
/* Return a pointer to a service by name. Unlike getservicebyname, it does not copy the service */
struct loadparm_service * lp_service ( const char * pszServiceName )
{
int iService = getservicebyname ( pszServiceName , NULL ) ;
if ( iService = = - 1 | | ! LP_SNUM_OK ( iService ) ) {
return NULL ;
}
return ServicePtrs [ iService ] ;
}
2011-07-12 10:03:11 +04:00
struct loadparm_service * lp_servicebynum ( int snum )
{
2011-07-21 16:10:50 +04:00
if ( ( snum = = - 1 ) | | ! LP_SNUM_OK ( snum ) ) {
2011-07-12 10:03:11 +04:00
return NULL ;
}
return ServicePtrs [ snum ] ;
}
struct loadparm_service * lp_default_loadparm_service ( )
{
return & sDefault ;
}
2011-07-07 14:33:55 +04:00
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Copy a service structure to another .
If pcopymapDest is NULL then copy all fields
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2008-09-25 02:52:11 +04:00
/**
2011-07-08 03:18:09 +04:00
* Add a parametric option to a parmlist_entry ,
2008-09-25 02:52:11 +04:00
* replacing old value , if already present .
*/
2011-07-08 03:18:09 +04:00
static void set_param_opt ( struct parmlist_entry * * opt_list ,
2008-09-25 02:52:11 +04:00
const char * opt_name ,
2010-08-11 07:35:14 +04:00
const char * opt_value ,
2011-07-08 03:18:09 +04:00
unsigned priority )
2008-09-25 02:52:11 +04:00
{
2011-07-08 03:18:09 +04:00
struct parmlist_entry * new_opt , * opt ;
2008-09-25 02:52:11 +04:00
bool not_added ;
opt = * opt_list ;
not_added = true ;
/* Traverse destination */
while ( opt ) {
/* If we already have same option, override it */
if ( strwicmp ( opt - > key , opt_name ) = = 0 ) {
2011-07-08 03:18:09 +04:00
if ( ( opt - > priority & FLAG_CMDLINE ) & &
! ( priority & FLAG_CMDLINE ) ) {
2010-08-11 07:35:14 +04:00
/* it's been marked as not to be
overridden */
return ;
}
2008-09-25 02:52:11 +04:00
string_free ( & opt - > value ) ;
TALLOC_FREE ( opt - > list ) ;
opt - > value = SMB_STRDUP ( opt_value ) ;
2011-07-08 03:18:09 +04:00
opt - > priority = priority ;
2008-09-25 02:52:11 +04:00
not_added = false ;
break ;
}
opt = opt - > next ;
}
if ( not_added ) {
2011-07-08 03:18:09 +04:00
new_opt = SMB_XMALLOC_P ( struct parmlist_entry ) ;
2008-09-25 02:52:11 +04:00
new_opt - > key = SMB_STRDUP ( opt_name ) ;
new_opt - > value = SMB_STRDUP ( opt_value ) ;
new_opt - > list = NULL ;
2011-07-08 03:18:09 +04:00
new_opt - > priority = priority ;
2008-09-25 02:52:11 +04:00
DLIST_ADD ( * opt_list , new_opt ) ;
}
}
2011-06-28 04:06:05 +04:00
static void copy_service ( struct loadparm_service * pserviceDest , struct loadparm_service * pserviceSource ,
2007-10-31 17:06:22 +03:00
struct bitmap * pcopymapDest )
2000-05-29 03:34:34 +04:00
{
int i ;
2007-10-19 04:40:25 +04:00
bool bcopyall = ( pcopymapDest = = NULL ) ;
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data ;
2000-05-29 03:34:34 +04:00
for ( i = 0 ; parm_table [ i ] . label ; i + + )
2011-06-29 06:36:06 +04:00
if ( parm_table [ i ] . p_class = = P_LOCAL & &
2007-10-31 17:06:22 +03:00
( bcopyall | | bitmap_query ( pcopymapDest , i ) ) ) {
2011-06-29 03:52:46 +04:00
void * src_ptr = lp_parm_ptr ( pserviceSource , & parm_table [ i ] ) ;
void * dest_ptr = lp_parm_ptr ( pserviceDest , & parm_table [ i ] ) ;
2000-05-29 03:34:34 +04:00
2002-11-13 02:20:50 +03:00
switch ( parm_table [ i ] . type ) {
2000-05-29 03:34:34 +04:00
case P_BOOL :
case P_BOOLREV :
2007-10-19 04:40:25 +04:00
* ( bool * ) dest_ptr = * ( bool * ) src_ptr ;
2000-05-29 03:34:34 +04:00
break ;
case P_INTEGER :
case P_ENUM :
case P_OCTAL :
2012-01-17 20:14:38 +04:00
case P_BYTES :
2000-05-29 03:34:34 +04:00
* ( int * ) dest_ptr = * ( int * ) src_ptr ;
break ;
case P_CHAR :
* ( char * ) dest_ptr = * ( char * ) src_ptr ;
break ;
case P_STRING :
2005-06-25 00:25:18 +04:00
string_set ( ( char * * ) dest_ptr ,
2000-05-29 03:34:34 +04:00
* ( char * * ) src_ptr ) ;
break ;
case P_USTRING :
2011-06-10 03:37:06 +04:00
{
char * upper_string = strupper_talloc ( talloc_tos ( ) ,
* ( char * * ) src_ptr ) ;
2005-06-25 00:25:18 +04:00
string_set ( ( char * * ) dest_ptr ,
2011-06-10 03:37:06 +04:00
upper_string ) ;
TALLOC_FREE ( upper_string ) ;
2000-05-29 03:34:34 +04:00
break ;
2011-06-10 03:37:06 +04:00
}
2001-06-20 20:54:32 +04:00
case P_LIST :
2008-02-04 23:05:41 +03:00
TALLOC_FREE ( * ( ( char * * * ) dest_ptr ) ) ;
2008-10-12 03:46:15 +04:00
* ( ( char * * * ) dest_ptr ) = str_list_copy ( NULL ,
2008-02-04 22:57:35 +03:00
* ( const char * * * ) src_ptr ) ;
2001-06-20 20:54:32 +04:00
break ;
2000-05-29 03:34:34 +04:00
default :
break ;
}
}
1996-05-04 11:50:46 +04:00
2002-11-13 02:20:50 +03:00
if ( bcopyall ) {
2000-05-29 03:34:34 +04:00
init_copymap ( pserviceDest ) ;
if ( pserviceSource - > copymap )
2007-10-31 17:06:22 +03:00
bitmap_copy ( pserviceDest - > copymap ,
pserviceSource - > copymap ) ;
2000-05-29 03:34:34 +04:00
}
2009-11-21 18:17:16 +03:00
2003-04-24 07:46:17 +04:00
data = pserviceSource - > param_opt ;
while ( data ) {
2011-07-08 03:18:09 +04:00
set_param_opt ( & pserviceDest - > param_opt , data - > key , data - > value , data - > priority ) ;
2003-04-24 07:46:17 +04:00
data = data - > next ;
}
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
2011-06-29 09:06:49 +04:00
Check a service for consistency . Return false if the service is in any way
2011-06-29 09:05:37 +04:00
incomplete or faulty , else true .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
bool service_ok ( int iService )
1996-05-04 11:50:46 +04:00
{
2007-10-19 04:40:25 +04:00
bool bRetval ;
2000-05-29 03:34:34 +04:00
2011-06-29 09:05:37 +04:00
bRetval = true ;
2002-11-13 02:20:50 +03:00
if ( ServicePtrs [ iService ] - > szService [ 0 ] = = ' \0 ' ) {
DEBUG ( 0 , ( " The following message indicates an internal error: \n " ) ) ;
2000-05-29 03:34:34 +04:00
DEBUG ( 0 , ( " No service name in service entry. \n " ) ) ;
2011-06-29 09:06:49 +04:00
bRetval = false ;
2000-05-29 03:34:34 +04:00
}
/* The [printers] entry MUST be printable. I'm all for flexibility, but */
/* I can't see why you'd want a non-printable printer service... */
2001-05-11 02:10:31 +04:00
if ( strwicmp ( ServicePtrs [ iService ] - > szService , PRINTERS_NAME ) = = 0 ) {
2013-12-24 07:03:18 +04:00
if ( ! ServicePtrs [ iService ] - > print_ok ) {
2002-11-13 02:20:50 +03:00
DEBUG ( 0 , ( " WARNING: [%s] service MUST be printable! \n " ,
2001-05-11 02:10:31 +04:00
ServicePtrs [ iService ] - > szService ) ) ;
2013-12-24 07:03:18 +04:00
ServicePtrs [ iService ] - > print_ok = true ;
2000-05-29 03:34:34 +04:00
}
2000-06-23 03:59:22 +04:00
/* [printers] service must also be non-browsable. */
2013-12-24 07:03:17 +04:00
if ( ServicePtrs [ iService ] - > browseable )
ServicePtrs [ iService ] - > browseable = false ;
2000-06-23 03:59:22 +04:00
}
2000-05-29 03:34:34 +04:00
2013-12-24 07:03:16 +04:00
if ( ServicePtrs [ iService ] - > pathname [ 0 ] = = ' \0 ' & &
2006-02-22 04:31:43 +03:00
strwicmp ( ServicePtrs [ iService ] - > szService , HOMES_NAME ) ! = 0 & &
2013-12-24 07:03:25 +04:00
ServicePtrs [ iService ] - > msdfs_proxy [ 0 ] = = ' \0 '
2006-02-22 04:31:43 +03:00
) {
DEBUG ( 0 , ( " WARNING: No path in service %s - making it unavailable! \n " ,
ServicePtrs [ iService ] - > szService ) ) ;
2011-06-29 09:06:49 +04:00
ServicePtrs [ iService ] - > bAvailable = false ;
2000-05-29 03:34:34 +04:00
}
2007-02-26 23:14:35 +03:00
/* If a service is flagged unavailable, log the fact at level 1. */
2001-05-11 02:10:31 +04:00
if ( ! ServicePtrs [ iService ] - > bAvailable )
2000-05-29 03:34:34 +04:00
DEBUG ( 1 , ( " NOTE: Service %s is flagged unavailable. \n " ,
2001-05-11 02:10:31 +04:00
ServicePtrs [ iService ] - > szService ) ) ;
2000-05-29 03:34:34 +04:00
return ( bRetval ) ;
}
2008-05-15 03:40:11 +04:00
static struct smbconf_ctx * lp_smbconf_ctx ( void )
{
2011-04-07 19:19:03 +04:00
sbcErr err ;
2008-05-15 03:40:11 +04:00
static struct smbconf_ctx * conf_ctx = NULL ;
if ( conf_ctx = = NULL ) {
2011-04-07 19:19:03 +04:00
err = smbconf_init ( NULL , & conf_ctx , " registry: " ) ;
if ( ! SBC_ERROR_IS_OK ( err ) ) {
2008-05-15 03:40:11 +04:00
DEBUG ( 1 , ( " error initializing registry configuration: "
2011-04-07 19:19:03 +04:00
" %s \n " , sbcErrorString ( err ) ) ) ;
2008-05-15 03:40:11 +04:00
conf_ctx = NULL ;
}
}
return conf_ctx ;
}
2008-09-24 22:31:39 +04:00
static bool process_smbconf_service ( struct smbconf_service * service )
2008-05-15 04:08:14 +04:00
{
uint32_t count ;
bool ret ;
if ( service = = NULL ) {
return false ;
}
2008-05-15 04:39:02 +04:00
ret = do_section ( service - > name , NULL ) ;
if ( ret ! = true ) {
return false ;
}
2008-05-15 04:08:14 +04:00
for ( count = 0 ; count < service - > num_params ; count + + ) {
ret = do_parameter ( service - > param_names [ count ] ,
service - > param_values [ count ] ,
NULL ) ;
if ( ret ! = true ) {
return false ;
}
}
2009-04-28 03:24:27 +04:00
if ( iServiceIndex > = 0 ) {
2009-05-05 19:46:20 +04:00
return service_ok ( iServiceIndex ) ;
2009-04-28 03:24:27 +04:00
}
2008-05-15 04:08:14 +04:00
return true ;
}
2009-04-29 03:31:03 +04:00
/**
* load a service from registry and activate it
2007-06-16 01:38:10 +04:00
*/
2009-04-29 03:31:03 +04:00
bool process_registry_service ( const char * service_name )
2007-06-16 01:38:10 +04:00
{
2011-04-08 19:20:35 +04:00
sbcErr err ;
2008-04-22 18:31:16 +04:00
struct smbconf_service * service = NULL ;
2008-02-19 03:22:32 +03:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2008-05-15 03:40:11 +04:00
struct smbconf_ctx * conf_ctx = lp_smbconf_ctx ( ) ;
2008-02-19 03:22:32 +03:00
bool ret = false ;
if ( conf_ctx = = NULL ) {
2008-05-15 03:40:11 +04:00
goto done ;
2007-06-16 01:38:10 +04:00
}
2009-04-29 03:31:03 +04:00
DEBUG ( 5 , ( " process_registry_service: service name %s \n " , service_name ) ) ;
2008-06-03 22:51:42 +04:00
2009-04-29 03:31:03 +04:00
if ( ! smbconf_share_exists ( conf_ctx , service_name ) ) {
/*
* Registry does not contain data for this service ( yet ) ,
* but make sure lp_load doesn ' t return false .
*/
2008-03-06 02:51:20 +03:00
ret = true ;
goto done ;
}
2011-04-08 19:20:35 +04:00
err = smbconf_get_share ( conf_ctx , mem_ctx , service_name , & service ) ;
if ( ! SBC_ERROR_IS_OK ( err ) ) {
2007-06-16 01:38:10 +04:00
goto done ;
}
2008-09-24 22:31:39 +04:00
ret = process_smbconf_service ( service ) ;
2008-05-15 04:08:14 +04:00
if ( ! ret ) {
goto done ;
2007-06-16 01:38:10 +04:00
}
2008-03-19 01:29:11 +03:00
/* store the csn */
smbconf_changed ( conf_ctx , & conf_last_csn , NULL , NULL ) ;
2007-06-16 01:38:10 +04:00
done :
2008-02-19 03:22:32 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-06-16 01:38:10 +04:00
return ret ;
}
2009-04-29 03:31:03 +04:00
/*
* process_registry_globals
*/
static bool process_registry_globals ( void )
{
bool ret ;
2009-05-06 04:08:33 +04:00
add_to_file_list ( INCLUDE_REGISTRY_NAME , INCLUDE_REGISTRY_NAME ) ;
2009-04-29 03:31:03 +04:00
ret = do_parameter ( " registry shares " , " yes " , NULL ) ;
if ( ! ret ) {
return ret ;
}
return process_registry_service ( GLOBAL_NAME ) ;
}
2009-04-29 03:49:53 +04:00
bool process_registry_shares ( void )
2008-05-15 04:15:20 +04:00
{
2011-04-11 19:43:10 +04:00
sbcErr err ;
2008-05-15 04:15:20 +04:00
uint32_t count ;
struct smbconf_service * * service = NULL ;
uint32_t num_shares = 0 ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
struct smbconf_ctx * conf_ctx = lp_smbconf_ctx ( ) ;
bool ret = false ;
if ( conf_ctx = = NULL ) {
goto done ;
}
2011-04-11 19:43:10 +04:00
err = smbconf_get_config ( conf_ctx , mem_ctx , & num_shares , & service ) ;
if ( ! SBC_ERROR_IS_OK ( err ) ) {
2008-05-15 04:15:20 +04:00
goto done ;
}
2008-05-27 12:59:11 +04:00
ret = true ;
2008-05-15 04:15:20 +04:00
for ( count = 0 ; count < num_shares ; count + + ) {
if ( strequal ( service [ count ] - > name , GLOBAL_NAME ) ) {
continue ;
}
2008-09-24 22:31:39 +04:00
ret = process_smbconf_service ( service [ count ] ) ;
2008-05-15 04:15:20 +04:00
if ( ! ret ) {
goto done ;
}
}
/* store the csn */
smbconf_changed ( conf_ctx , & conf_last_csn , NULL , NULL ) ;
done :
TALLOC_FREE ( mem_ctx ) ;
return ret ;
}
2011-07-22 12:10:43 +04:00
/**
* reload those shares from registry that are already
* activated in the services array .
*/
static bool reload_registry_shares ( void )
{
int i ;
bool ret = true ;
for ( i = 0 ; i < iNumServices ; i + + ) {
if ( ! VALID ( i ) ) {
continue ;
}
if ( ServicePtrs [ i ] - > usershare = = USERSHARE_VALID ) {
continue ;
}
ret = process_registry_service ( ServicePtrs [ i ] - > szService ) ;
if ( ! ret ) {
goto done ;
}
}
done :
return ret ;
}
2009-04-27 20:10:14 +04:00
# define MAX_INCLUDE_DEPTH 100
static uint8_t include_depth ;
2002-11-13 02:20:50 +03:00
static struct file_lists {
2000-05-29 03:34:34 +04:00
struct file_lists * next ;
char * name ;
2001-07-08 17:02:16 +04:00
char * subfname ;
2000-05-29 03:34:34 +04:00
time_t modtime ;
2002-11-13 02:20:50 +03:00
} * file_lists = NULL ;
1996-05-04 11:50:46 +04:00
/*******************************************************************
2002-11-13 02:20:50 +03:00
Keep a linked list of all config files so we know when one has changed
it ' s date and needs to be reloaded .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2002-01-15 04:38:05 +03:00
static void add_to_file_list ( const char * fname , const char * subfname )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
struct file_lists * f = file_lists ;
1996-05-04 11:50:46 +04:00
2002-11-13 02:20:50 +03:00
while ( f ) {
2000-05-29 03:34:34 +04:00
if ( f - > name & & ! strcmp ( f - > name , fname ) )
break ;
f = f - > next ;
}
1996-05-04 11:50:46 +04:00
2002-11-13 02:20:50 +03:00
if ( ! f ) {
2004-12-07 21:25:53 +03:00
f = SMB_MALLOC_P ( struct file_lists ) ;
2000-05-29 03:34:34 +04:00
if ( ! f )
return ;
f - > next = file_lists ;
2004-12-07 21:25:53 +03:00
f - > name = SMB_STRDUP ( fname ) ;
2002-11-13 02:20:50 +03:00
if ( ! f - > name ) {
2001-09-17 08:58:38 +04:00
SAFE_FREE ( f ) ;
2000-05-29 03:34:34 +04:00
return ;
}
2004-12-07 21:25:53 +03:00
f - > subfname = SMB_STRDUP ( subfname ) ;
2002-11-13 02:20:50 +03:00
if ( ! f - > subfname ) {
2009-11-30 12:30:25 +03:00
SAFE_FREE ( f - > name ) ;
2001-09-17 08:58:38 +04:00
SAFE_FREE ( f ) ;
2001-07-08 17:02:16 +04:00
return ;
}
2000-05-29 03:34:34 +04:00
file_lists = f ;
2002-04-02 23:56:54 +04:00
f - > modtime = file_modtime ( subfname ) ;
} else {
time_t t = file_modtime ( subfname ) ;
if ( t )
f - > modtime = t ;
2000-05-29 03:34:34 +04:00
}
2009-11-30 12:30:25 +03:00
return ;
1996-05-04 11:50:46 +04:00
}
2009-05-06 04:09:56 +04:00
/**
* Free the file lists
*/
static void free_file_list ( void )
{
struct file_lists * f ;
struct file_lists * next ;
f = file_lists ;
while ( f ) {
next = f - > next ;
SAFE_FREE ( f - > name ) ;
SAFE_FREE ( f - > subfname ) ;
SAFE_FREE ( f ) ;
f = next ;
}
file_lists = NULL ;
}
2008-01-16 19:03:21 +03:00
/**
* Utility function for outsiders to check if we ' re running on registry .
*/
bool lp_config_backend_is_registry ( void )
{
return ( lp_config_backend ( ) = = CONFIG_BACKEND_REGISTRY ) ;
}
2008-03-11 14:41:20 +03:00
/**
* Utility function to check if the config backend is FILE .
*/
bool lp_config_backend_is_file ( void )
{
return ( lp_config_backend ( ) = = CONFIG_BACKEND_FILE ) ;
}
1996-05-04 11:50:46 +04:00
/*******************************************************************
2002-11-13 02:20:50 +03:00
Check if a config file has changed date .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
bool lp_file_list_changed ( void )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
struct file_lists * f = file_lists ;
2004-03-20 01:06:54 +03:00
DEBUG ( 6 , ( " lp_file_list_changed() \n " ) ) ;
2002-04-02 23:56:54 +04:00
while ( f ) {
2000-05-29 03:34:34 +04:00
time_t mod_time ;
1997-09-05 21:16:21 +04:00
2009-05-06 04:08:33 +04:00
if ( strequal ( f - > name , INCLUDE_REGISTRY_NAME ) ) {
struct smbconf_ctx * conf_ctx = lp_smbconf_ctx ( ) ;
if ( conf_ctx = = NULL ) {
return false ;
}
if ( smbconf_changed ( conf_ctx , & conf_last_csn , NULL ,
NULL ) )
{
DEBUGADD ( 6 , ( " registry config changed \n " ) ) ;
return true ;
}
} else {
2009-11-21 22:23:35 +03:00
char * n2 = NULL ;
n2 = talloc_sub_basic ( talloc_tos ( ) ,
get_current_username ( ) ,
current_user_info . domain ,
f - > name ) ;
2009-05-06 04:08:33 +04:00
if ( ! n2 ) {
return false ;
}
DEBUGADD ( 6 , ( " file %s -> %s last mod_time: %s \n " ,
f - > name , n2 , ctime ( & f - > modtime ) ) ) ;
mod_time = file_modtime ( n2 ) ;
if ( mod_time & &
( ( f - > modtime ! = mod_time ) | |
( f - > subfname = = NULL ) | |
( strcmp ( n2 , f - > subfname ) ! = 0 ) ) )
{
DEBUGADD ( 6 ,
( " file %s modified: %s \n " , n2 ,
ctime ( & mod_time ) ) ) ;
f - > modtime = mod_time ;
SAFE_FREE ( f - > subfname ) ;
2009-11-30 12:30:25 +03:00
f - > subfname = SMB_STRDUP ( n2 ) ;
TALLOC_FREE ( n2 ) ;
2009-05-06 04:08:33 +04:00
return true ;
}
2009-11-21 22:23:35 +03:00
TALLOC_FREE ( n2 ) ;
2000-05-29 03:34:34 +04:00
}
f = f - > next ;
}
2011-10-06 09:58:32 +04:00
return false ;
1996-05-04 11:50:46 +04:00
}
2008-01-16 18:18:28 +03:00
2011-05-30 07:40:33 +04:00
/**
* Initialize iconv conversion descriptors .
*
* This is called the first time it is needed , and also called again
* every time the configuration is reloaded , because the charset or
* codepage might have changed .
* */
static void init_iconv ( void )
{
global_iconv_handle = smb_iconv_handle_reinit ( NULL , lp_dos_charset ( ) ,
2011-06-22 03:52:31 +04:00
lp_unix_charset ( ) ,
2011-05-30 07:40:33 +04:00
true , global_iconv_handle ) ;
}
2011-06-29 07:18:57 +04:00
static bool handle_charset ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2003-08-27 05:25:01 +04:00
{
2003-09-05 03:03:58 +04:00
if ( strcmp ( * ptr , pszParmValue ) ! = 0 ) {
string_set ( ptr , pszParmValue ) ;
init_iconv ( ) ;
}
2011-06-29 09:05:37 +04:00
return true ;
2003-08-27 05:25:01 +04:00
}
2011-06-29 07:18:57 +04:00
static bool handle_dos_charset ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2011-05-23 21:57:56 +04:00
{
bool is_utf8 = false ;
size_t len = strlen ( pszParmValue ) ;
if ( len = = 4 | | len = = 5 ) {
/* Don't use StrCaseCmp here as we don't want to
initialize iconv . */
2011-07-20 00:19:29 +04:00
if ( ( toupper_m ( pszParmValue [ 0 ] ) = = ' U ' ) & &
( toupper_m ( pszParmValue [ 1 ] ) = = ' T ' ) & &
( toupper_m ( pszParmValue [ 2 ] ) = = ' F ' ) ) {
2011-05-23 21:57:56 +04:00
if ( len = = 4 ) {
if ( pszParmValue [ 3 ] = = ' 8 ' ) {
is_utf8 = true ;
}
} else {
if ( pszParmValue [ 3 ] = = ' - ' & &
pszParmValue [ 4 ] = = ' 8 ' ) {
is_utf8 = true ;
}
}
}
}
if ( strcmp ( * ptr , pszParmValue ) ! = 0 ) {
if ( is_utf8 ) {
DEBUG ( 0 , ( " ERROR: invalid DOS charset: 'dos charset' must not "
" be UTF8, using (default value) %s instead. \n " ,
DEFAULT_DOS_CHARSET ) ) ;
pszParmValue = DEFAULT_DOS_CHARSET ;
}
string_set ( ptr , pszParmValue ) ;
init_iconv ( ) ;
}
return true ;
}
2011-06-29 07:18:57 +04:00
static bool handle_realm ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2011-06-01 17:22:24 +04:00
{
bool ret = true ;
2012-08-28 01:46:49 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
char * realm = strupper_talloc ( frame , pszParmValue ) ;
2012-07-18 09:37:23 +04:00
char * dnsdomain = strlower_talloc ( realm , pszParmValue ) ;
2011-06-01 17:22:24 +04:00
2013-12-24 07:04:04 +04:00
ret & = string_set ( & Globals . realm_original , pszParmValue ) ;
ret & = string_set ( & Globals . realm , realm ) ;
2013-12-24 07:04:00 +04:00
ret & = string_set ( & Globals . dnsdomain , dnsdomain ) ;
2012-08-28 01:46:49 +04:00
TALLOC_FREE ( frame ) ;
2011-06-01 17:22:24 +04:00
return ret ;
}
2011-06-29 07:18:57 +04:00
static bool handle_netbios_aliases ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2002-11-13 02:20:50 +03:00
{
2013-12-24 07:04:23 +04:00
TALLOC_FREE ( Globals . netbios_aliases ) ;
Globals . netbios_aliases = ( const char * * ) str_list_make_v3 ( NULL , pszParmValue , NULL ) ;
return set_netbios_aliases ( Globals . netbios_aliases ) ;
2002-11-13 02:20:50 +03:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Handle the include operation .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-21 02:17:49 +04:00
static bool bAllowIncludeRegistry = true ;
1999-12-13 16:27:58 +03:00
2011-06-29 07:18:57 +04:00
static bool handle_include ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2000-05-29 03:34:34 +04:00
{
2007-11-14 05:42:42 +03:00
char * fname ;
1996-05-04 11:50:46 +04:00
2009-04-27 20:10:14 +04:00
if ( include_depth > = MAX_INCLUDE_DEPTH ) {
DEBUG ( 0 , ( " Error: Maximum include depth (%u) exceeded! \n " ,
include_depth ) ) ;
return false ;
}
2008-04-07 00:23:54 +04:00
if ( strequal ( pszParmValue , INCLUDE_REGISTRY_NAME ) ) {
2008-04-21 02:17:49 +04:00
if ( ! bAllowIncludeRegistry ) {
2008-04-21 02:06:45 +04:00
return true ;
}
2008-04-07 00:23:54 +04:00
if ( bInGlobalSection ) {
2009-04-27 20:10:14 +04:00
bool ret ;
include_depth + + ;
ret = process_registry_globals ( ) ;
include_depth - - ;
return ret ;
2008-04-07 00:23:54 +04:00
} else {
DEBUG ( 1 , ( " \" include = registry \" only effective "
" in %s section \n " , GLOBAL_NAME ) ) ;
return false ;
}
}
2009-11-21 22:23:35 +03:00
fname = talloc_sub_basic ( talloc_tos ( ) , get_current_username ( ) ,
current_user_info . domain ,
pszParmValue ) ;
1996-05-04 11:50:46 +04:00
2001-07-08 17:02:16 +04:00
add_to_file_list ( pszParmValue , fname ) ;
2000-05-29 03:34:34 +04:00
string_set ( ptr , fname ) ;
1996-05-04 11:50:46 +04:00
2008-10-17 14:48:19 +04:00
if ( file_exist ( fname ) ) {
2009-04-27 20:10:14 +04:00
bool ret ;
include_depth + + ;
ret = pm_process ( fname , do_section , do_parameter , NULL ) ;
include_depth - - ;
2009-11-21 22:23:35 +03:00
TALLOC_FREE ( fname ) ;
2007-11-14 05:42:42 +03:00
return ret ;
}
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
DEBUG ( 2 , ( " Can't find include file %s \n " , fname ) ) ;
2009-11-21 22:23:35 +03:00
TALLOC_FREE ( fname ) ;
2008-06-19 19:20:22 +04:00
return true ;
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
2002-11-13 02:20:50 +03:00
Handle the interpretation of the copy parameter .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-29 07:18:57 +04:00
static bool handle_copy ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
1996-05-04 11:50:46 +04:00
{
2007-10-19 04:40:25 +04:00
bool bRetval ;
2000-05-29 03:34:34 +04:00
int iTemp ;
2011-06-28 04:06:05 +04:00
struct loadparm_service serviceTemp ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
string_set ( ptr , pszParmValue ) ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
init_service ( & serviceTemp ) ;
1996-05-04 11:50:46 +04:00
2011-06-29 09:06:49 +04:00
bRetval = false ;
2000-05-29 03:34:34 +04:00
DEBUG ( 3 , ( " Copying service from service %s \n " , pszParmValue ) ) ;
2002-11-13 02:20:50 +03:00
if ( ( iTemp = getservicebyname ( pszParmValue , & serviceTemp ) ) > = 0 ) {
if ( iTemp = = iServiceIndex ) {
DEBUG ( 0 , ( " Can't copy service %s - unable to copy self! \n " , pszParmValue ) ) ;
} else {
2001-05-11 02:10:31 +04:00
copy_service ( ServicePtrs [ iServiceIndex ] ,
2000-05-29 03:34:34 +04:00
& serviceTemp ,
2001-05-11 02:10:31 +04:00
ServicePtrs [ iServiceIndex ] - > copymap ) ;
2011-06-29 09:05:37 +04:00
bRetval = true ;
2000-05-29 03:34:34 +04:00
}
2002-11-13 02:20:50 +03:00
} else {
DEBUG ( 0 , ( " Unable to copy service - source not found: %s \n " , pszParmValue ) ) ;
2011-06-29 09:06:49 +04:00
bRetval = false ;
2000-05-29 03:34:34 +04:00
}
free_service ( & serviceTemp ) ;
return ( bRetval ) ;
1996-05-04 11:50:46 +04:00
}
2011-06-29 07:18:57 +04:00
static bool handle_ldap_debug_level ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2008-01-28 16:47:01 +03:00
{
Globals . ldap_debug_level = lp_int ( pszParmValue ) ;
init_ldap_debugging ( ) ;
return true ;
}
2013-01-28 18:41:13 +04:00
/*
* idmap related parameters
*/
2011-06-29 07:18:57 +04:00
static bool handle_idmap_backend ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2000-05-06 19:06:45 +04:00
{
2011-03-08 09:15:36 +03:00
lp_do_parameter ( snum , " idmap config * : backend " , pszParmValue ) ;
2000-05-06 19:06:45 +04:00
2011-03-08 09:15:36 +03:00
return true ;
}
2000-05-06 19:06:45 +04:00
2011-06-29 07:18:57 +04:00
static bool handle_idmap_uid ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2011-03-08 09:15:36 +03:00
{
lp_do_parameter ( snum , " idmap config * : range " , pszParmValue ) ;
2001-11-26 07:27:51 +03:00
2011-06-29 09:05:37 +04:00
return true ;
2001-11-26 07:27:51 +03:00
}
2011-06-29 07:18:57 +04:00
static bool handle_idmap_gid ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2001-11-26 07:27:51 +03:00
{
2011-03-08 09:15:36 +03:00
lp_do_parameter ( snum , " idmap config * : range " , pszParmValue ) ;
2001-11-26 07:27:51 +03:00
2011-06-29 09:05:37 +04:00
return true ;
2000-05-06 19:06:45 +04:00
}
2013-01-28 19:31:23 +04:00
bool lp_idmap_range ( const char * domain_name , uint32_t * low , uint32_t * high )
{
char * config_option = NULL ;
const char * range = NULL ;
bool ret = false ;
SMB_ASSERT ( low ! = NULL ) ;
SMB_ASSERT ( high ! = NULL ) ;
if ( ( domain_name = = NULL ) | | ( domain_name [ 0 ] = = ' \0 ' ) ) {
domain_name = " * " ;
}
config_option = talloc_asprintf ( talloc_tos ( ) , " idmap config %s " ,
domain_name ) ;
if ( config_option = = NULL ) {
DEBUG ( 0 , ( " out of memory \n " ) ) ;
return false ;
}
range = lp_parm_const_string ( - 1 , config_option , " range " , NULL ) ;
if ( range = = NULL ) {
DEBUG ( 1 , ( " idmap range not specified for domain '%s' \n " , domain_name ) ) ;
goto done ;
}
if ( sscanf ( range , " %u - %u " , low , high ) ! = 2 ) {
DEBUG ( 1 , ( " error parsing idmap range '%s' for domain '%s' \n " ,
range , domain_name ) ) ;
goto done ;
}
ret = true ;
done :
talloc_free ( config_option ) ;
return ret ;
}
2013-01-28 19:35:50 +04:00
bool lp_idmap_default_range ( uint32_t * low , uint32_t * high )
{
return lp_idmap_range ( " * " , low , high ) ;
}
2013-01-29 16:24:20 +04:00
const char * lp_idmap_backend ( const char * domain_name )
{
char * config_option = NULL ;
const char * backend = NULL ;
if ( ( domain_name = = NULL ) | | ( domain_name [ 0 ] = = ' \0 ' ) ) {
domain_name = " * " ;
}
config_option = talloc_asprintf ( talloc_tos ( ) , " idmap config %s " ,
domain_name ) ;
if ( config_option = = NULL ) {
DEBUG ( 0 , ( " out of memory \n " ) ) ;
return false ;
}
backend = lp_parm_const_string ( - 1 , config_option , " backend " , NULL ) ;
if ( backend = = NULL ) {
DEBUG ( 1 , ( " idmap backend not specified for domain '%s' \n " , domain_name ) ) ;
goto done ;
}
done :
talloc_free ( config_option ) ;
return backend ;
}
2013-01-29 16:26:11 +04:00
const char * lp_idmap_default_backend ( void )
{
return lp_idmap_backend ( " * " ) ;
}
2001-02-12 19:18:02 +03:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Handle the DEBUG level list .
2001-02-12 19:18:02 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-29 07:18:57 +04:00
static bool handle_debug_list ( struct loadparm_context * unused , int snum , const char * pszParmValueIn , char * * ptr )
2001-02-12 19:18:02 +03:00
{
2002-08-17 21:00:51 +04:00
string_set ( ptr , pszParmValueIn ) ;
2007-11-14 05:42:42 +03:00
return debug_parse_levels ( pszParmValueIn ) ;
2001-02-12 19:18:02 +03:00
}
2002-03-02 13:16:28 +03:00
/***************************************************************************
2003-11-21 22:11:48 +03:00
Handle ldap suffixes - default to ldapsuffix if sub - suffixes are not defined .
2002-03-02 13:16:28 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2012-07-18 09:37:23 +04:00
static const char * append_ldap_suffix ( TALLOC_CTX * ctx , const char * str )
2002-03-02 13:16:28 +03:00
{
2006-06-21 00:43:05 +04:00
const char * suffix_string ;
2003-06-06 17:48:39 +04:00
2012-07-18 09:37:23 +04:00
suffix_string = talloc_asprintf ( ctx , " %s,%s " , str ,
2013-12-24 07:04:30 +04:00
Globals . ldap_suffix ) ;
2003-11-21 22:11:48 +03:00
if ( ! suffix_string ) {
DEBUG ( 0 , ( " append_ldap_suffix: talloc_asprintf() failed! \n " ) ) ;
2006-06-21 00:43:05 +04:00
return " " ;
2003-11-21 22:11:48 +03:00
}
return suffix_string ;
2002-03-02 13:16:28 +03:00
}
2012-07-18 09:37:23 +04:00
const char * lp_ldap_machine_suffix ( TALLOC_CTX * ctx )
2003-11-21 22:11:48 +03:00
{
if ( Globals . szLdapMachineSuffix [ 0 ] )
2012-07-18 09:37:23 +04:00
return append_ldap_suffix ( ctx , Globals . szLdapMachineSuffix ) ;
2003-11-21 22:11:48 +03:00
2013-12-24 07:04:30 +04:00
return lp_string ( ctx , Globals . ldap_suffix ) ;
2003-11-21 22:11:48 +03:00
}
2002-11-13 02:20:50 +03:00
2012-07-18 09:37:23 +04:00
const char * lp_ldap_user_suffix ( TALLOC_CTX * ctx )
2002-03-02 13:16:28 +03:00
{
2003-11-21 22:11:48 +03:00
if ( Globals . szLdapUserSuffix [ 0 ] )
2012-07-18 09:37:23 +04:00
return append_ldap_suffix ( ctx , Globals . szLdapUserSuffix ) ;
2002-03-02 13:16:28 +03:00
2013-12-24 07:04:30 +04:00
return lp_string ( ctx , Globals . ldap_suffix ) ;
2003-11-21 22:11:48 +03:00
}
2012-07-18 09:37:23 +04:00
const char * lp_ldap_group_suffix ( TALLOC_CTX * ctx )
2003-11-21 22:11:48 +03:00
{
if ( Globals . szLdapGroupSuffix [ 0 ] )
2012-07-18 09:37:23 +04:00
return append_ldap_suffix ( ctx , Globals . szLdapGroupSuffix ) ;
2003-11-21 22:11:48 +03:00
2013-12-24 07:04:30 +04:00
return lp_string ( ctx , Globals . ldap_suffix ) ;
2003-11-21 22:11:48 +03:00
}
2012-07-18 09:37:23 +04:00
const char * lp_ldap_idmap_suffix ( TALLOC_CTX * ctx )
2003-11-21 22:11:48 +03:00
{
if ( Globals . szLdapIdmapSuffix [ 0 ] )
2012-07-18 09:37:23 +04:00
return append_ldap_suffix ( ctx , Globals . szLdapIdmapSuffix ) ;
2003-11-21 22:11:48 +03:00
2013-12-24 07:04:30 +04:00
return lp_string ( ctx , Globals . ldap_suffix ) ;
2002-03-02 13:16:28 +03:00
}
2004-04-11 02:37:47 +04:00
/****************************************************************************
set the value for a P_ENUM
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void lp_set_enum_parm ( struct parm_struct * parm , const char * pszParmValue ,
int * ptr )
{
int i ;
2004-06-15 22:36:45 +04:00
for ( i = 0 ; parm - > enum_list [ i ] . name ; i + + ) {
if ( strequal ( pszParmValue , parm - > enum_list [ i ] . name ) ) {
2004-04-11 02:37:47 +04:00
* ptr = parm - > enum_list [ i ] . value ;
2008-07-30 18:24:20 +04:00
return ;
2004-04-11 02:37:47 +04:00
}
}
2008-07-30 18:24:20 +04:00
DEBUG ( 0 , ( " WARNING: Ignoring invalid value '%s' for parameter '%s' \n " ,
pszParmValue , parm - > label ) ) ;
2004-04-11 02:37:47 +04:00
}
/***************************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-06-29 07:18:57 +04:00
static bool handle_printing ( struct loadparm_context * unused , int snum , const char * pszParmValue , char * * ptr )
2004-04-11 02:37:47 +04:00
{
static int parm_num = - 1 ;
2011-06-28 04:06:05 +04:00
struct loadparm_service * s ;
2004-04-11 02:37:47 +04:00
if ( parm_num = = - 1 )
2014-01-15 05:19:21 +04:00
parm_num = lpcfg_map_parameter ( " printing " ) ;
2004-04-11 02:37:47 +04:00
lp_set_enum_parm ( & parm_table [ parm_num ] , pszParmValue , ( int * ) ptr ) ;
if ( snum < 0 )
s = & sDefault ;
else
s = ServicePtrs [ snum ] ;
init_printer_values ( s ) ;
2011-06-29 09:05:37 +04:00
return true ;
2004-04-11 02:37:47 +04:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Initialise a copymap .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-28 04:06:05 +04:00
static void init_copymap ( struct loadparm_service * pservice )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
int i ;
2010-03-28 16:13:48 +04:00
TALLOC_FREE ( pservice - > copymap ) ;
2010-10-07 23:29:19 +04:00
pservice - > copymap = bitmap_talloc ( NULL , NUMPARAMETERS ) ;
2000-05-29 03:34:34 +04:00
if ( ! pservice - > copymap )
DEBUG ( 0 ,
( " Couldn't allocate copymap!! (size %d) \n " ,
( int ) NUMPARAMETERS ) ) ;
else
for ( i = 0 ; i < NUMPARAMETERS ; i + + )
2007-10-31 17:06:22 +03:00
bitmap_set ( pservice - > copymap , i ) ;
1996-05-04 11:50:46 +04:00
}
2011-06-29 03:52:46 +04:00
/**
return the parameter pointer for a parameter
*/
void * lp_parm_ptr ( struct loadparm_service * service , struct parm_struct * parm )
2008-12-15 16:20:16 +03:00
{
2011-06-29 03:52:46 +04:00
if ( service = = NULL ) {
if ( parm - > p_class = = P_LOCAL )
2011-06-29 04:49:35 +04:00
return ( void * ) ( ( ( char * ) & sDefault ) + parm - > offset ) ;
2011-06-29 03:52:46 +04:00
else if ( parm - > p_class = = P_GLOBAL )
2011-06-29 04:49:35 +04:00
return ( void * ) ( ( ( char * ) & Globals ) + parm - > offset ) ;
2011-06-29 03:52:46 +04:00
else return NULL ;
} else {
2011-06-29 04:49:35 +04:00
return ( void * ) ( ( ( char * ) service ) + parm - > offset ) ;
2011-06-29 03:52:46 +04:00
}
2008-12-15 16:20:16 +03:00
}
1998-03-08 17:14:49 +03:00
/***************************************************************************
2011-06-29 03:52:46 +04:00
Return the local pointer to a parameter given the service number and parameter
1998-03-08 17:14:49 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-29 03:52:46 +04:00
void * lp_local_ptr_by_snum ( int snum , struct parm_struct * parm )
1998-03-08 17:14:49 +03:00
{
2011-06-29 03:52:46 +04:00
return lp_parm_ptr ( ServicePtrs [ snum ] , parm ) ;
1998-03-08 17:14:49 +03:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Process a parameter for a particular service number . If snum < 0
then assume we are in the globals .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
bool lp_do_parameter ( int snum , const char * pszParmName , const char * pszParmValue )
1996-05-04 11:50:46 +04:00
{
2008-07-16 18:08:28 +04:00
int parmnum , i ;
2000-05-29 03:34:34 +04:00
void * parm_ptr = NULL ; /* where we are going to store the result */
2011-07-08 03:18:09 +04:00
struct parmlist_entry * * opt_list ;
2000-05-29 03:34:34 +04:00
2014-01-15 05:19:21 +04:00
parmnum = lpcfg_map_parameter ( pszParmName ) ;
2000-05-29 03:34:34 +04:00
2002-11-13 02:20:50 +03:00
if ( parmnum < 0 ) {
2008-07-16 18:08:28 +04:00
if ( strchr ( pszParmName , ' : ' ) = = NULL ) {
2008-07-16 18:05:46 +04:00
DEBUG ( 0 , ( " Ignoring unknown parameter \" %s \" \n " ,
pszParmName ) ) ;
2011-10-06 09:58:32 +04:00
return true ;
2002-07-15 14:35:28 +04:00
}
2008-07-16 18:05:46 +04:00
/*
* We ' ve got a parametric option
*/
2008-09-25 02:52:11 +04:00
opt_list = ( snum < 0 )
? & Globals . param_opt : & ServicePtrs [ snum ] - > param_opt ;
2010-08-11 07:35:14 +04:00
set_param_opt ( opt_list , pszParmName , pszParmValue , 0 ) ;
2008-07-16 18:05:46 +04:00
2011-10-06 09:58:32 +04:00
return true ;
2000-05-29 03:34:34 +04:00
}
2010-08-11 07:35:14 +04:00
/* if it's already been set by the command line, then we don't
override here */
if ( parm_table [ parmnum ] . flags & FLAG_CMDLINE ) {
return true ;
}
2002-11-13 02:20:50 +03:00
if ( parm_table [ parmnum ] . flags & FLAG_DEPRECATED ) {
2002-07-15 14:35:28 +04:00
DEBUG ( 1 , ( " WARNING: The \" %s \" option is deprecated \n " ,
2000-05-29 03:34:34 +04:00
pszParmName ) ) ;
}
/* we might point at a service, the default service or a global */
2002-11-13 02:20:50 +03:00
if ( snum < 0 ) {
2011-06-29 03:52:46 +04:00
parm_ptr = lp_parm_ptr ( NULL , & parm_table [ parmnum ] ) ;
2002-11-13 02:20:50 +03:00
} else {
2005-06-25 00:25:18 +04:00
if ( parm_table [ parmnum ] . p_class = = P_GLOBAL ) {
2000-05-29 03:34:34 +04:00
DEBUG ( 0 ,
( " Global parameter %s found in service section! \n " ,
pszParmName ) ) ;
2011-10-06 09:58:32 +04:00
return true ;
2000-05-29 03:34:34 +04:00
}
2011-06-29 03:52:46 +04:00
parm_ptr = lp_local_ptr_by_snum ( snum , & parm_table [ parmnum ] ) ;
2007-10-11 00:34:30 +04:00
}
2000-05-29 03:34:34 +04:00
2007-10-11 00:34:30 +04:00
if ( snum > = 0 ) {
2001-05-11 02:10:31 +04:00
if ( ! ServicePtrs [ snum ] - > copymap )
init_copymap ( ServicePtrs [ snum ] ) ;
2000-05-29 03:34:34 +04:00
/* this handles the aliases - set the copymap for other entries with
the same data pointer */
2011-07-07 15:16:24 +04:00
for ( i = 0 ; parm_table [ i ] . label ; i + + ) {
if ( ( parm_table [ i ] . offset = = parm_table [ parmnum ] . offset )
& & ( parm_table [ i ] . p_class = = parm_table [ parmnum ] . p_class ) ) {
2007-10-31 17:06:22 +03:00
bitmap_clear ( ServicePtrs [ snum ] - > copymap , i ) ;
2011-07-07 15:16:24 +04:00
}
}
2000-05-29 03:34:34 +04:00
}
/* if it is a special case then go ahead */
2002-11-13 02:20:50 +03:00
if ( parm_table [ parmnum ] . special ) {
2011-06-29 07:18:57 +04:00
return parm_table [ parmnum ] . special ( NULL , snum , pszParmValue ,
2008-06-19 19:21:04 +04:00
( char * * ) parm_ptr ) ;
2000-05-29 03:34:34 +04:00
}
/* now switch on the type of variable it is */
switch ( parm_table [ parmnum ] . type )
{
case P_BOOL :
2007-10-19 04:40:25 +04:00
* ( bool * ) parm_ptr = lp_bool ( pszParmValue ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_BOOLREV :
2007-10-19 04:40:25 +04:00
* ( bool * ) parm_ptr = ! lp_bool ( pszParmValue ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_INTEGER :
2006-02-28 03:59:14 +03:00
* ( int * ) parm_ptr = lp_int ( pszParmValue ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_CHAR :
* ( char * ) parm_ptr = * pszParmValue ;
break ;
case P_OCTAL :
2005-09-30 21:13:37 +04:00
i = sscanf ( pszParmValue , " %o " , ( int * ) parm_ptr ) ;
if ( i ! = 1 ) {
DEBUG ( 0 , ( " Invalid octal number %s \n " , pszParmName ) ) ;
}
2000-05-29 03:34:34 +04:00
break ;
2011-07-21 19:20:16 +04:00
case P_BYTES :
{
uint64_t val ;
if ( conv_str_size_error ( pszParmValue , & val ) ) {
if ( val < = INT_MAX ) {
* ( int * ) parm_ptr = ( int ) val ;
break ;
}
}
DEBUG ( 0 , ( " lp_do_parameter(%s): value is not "
" a valid size specifier! \n " , pszParmValue ) ) ;
return false ;
}
2001-06-20 20:54:32 +04:00
case P_LIST :
2011-07-21 19:18:40 +04:00
case P_CMDLIST :
2008-02-04 23:05:41 +03:00
TALLOC_FREE ( * ( ( char * * * ) parm_ptr ) ) ;
2008-11-07 05:53:00 +03:00
* ( char * * * ) parm_ptr = str_list_make_v3 (
2010-10-07 23:29:19 +04:00
NULL , pszParmValue , NULL ) ;
2001-06-20 20:54:32 +04:00
break ;
2000-05-29 03:34:34 +04:00
case P_STRING :
2005-06-25 00:25:18 +04:00
string_set ( ( char * * ) parm_ptr , pszParmValue ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_USTRING :
2011-06-10 03:37:06 +04:00
{
char * upper_string = strupper_talloc ( talloc_tos ( ) ,
pszParmValue ) ;
string_set ( ( char * * ) parm_ptr , upper_string ) ;
TALLOC_FREE ( upper_string ) ;
2000-05-29 03:34:34 +04:00
break ;
2011-06-10 03:37:06 +04:00
}
2000-05-29 03:34:34 +04:00
case P_ENUM :
2004-04-11 02:37:47 +04:00
lp_set_enum_parm ( & parm_table [ parmnum ] , pszParmValue , ( int * ) parm_ptr ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_SEP :
break ;
}
2011-10-06 09:58:32 +04:00
return true ;
1996-05-04 11:50:46 +04:00
}
2010-08-11 07:35:14 +04:00
/***************************************************************************
set a parameter , marking it with FLAG_CMDLINE . Parameters marked as
FLAG_CMDLINE won ' t be overridden by loads from smb . conf .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static bool lp_set_cmdline_helper ( const char * pszParmName , const char * pszParmValue , bool store_values )
{
2010-11-27 00:17:09 +03:00
int parmnum , i ;
2014-01-15 05:19:21 +04:00
parmnum = lpcfg_map_parameter ( pszParmName ) ;
2010-08-11 07:35:14 +04:00
if ( parmnum > = 0 ) {
parm_table [ parmnum ] . flags & = ~ FLAG_CMDLINE ;
if ( ! lp_do_parameter ( - 1 , pszParmName , pszParmValue ) ) {
return false ;
}
parm_table [ parmnum ] . flags | = FLAG_CMDLINE ;
2010-11-27 00:17:09 +03:00
/* we have to also set FLAG_CMDLINE on aliases. Aliases must
* be grouped in the table , so we don ' t have to search the
* whole table */
2011-07-07 15:16:24 +04:00
for ( i = parmnum - 1 ;
i > = 0 & & parm_table [ i ] . offset = = parm_table [ parmnum ] . offset
& & parm_table [ i ] . p_class = = parm_table [ parmnum ] . p_class ;
i - - ) {
2010-11-27 00:17:09 +03:00
parm_table [ i ] . flags | = FLAG_CMDLINE ;
}
2011-07-07 15:16:24 +04:00
for ( i = parmnum + 1 ; i < NUMPARAMETERS & & parm_table [ i ] . offset = = parm_table [ parmnum ] . offset
& & parm_table [ i ] . p_class = = parm_table [ parmnum ] . p_class ; i + + ) {
2010-11-27 00:17:09 +03:00
parm_table [ i ] . flags | = FLAG_CMDLINE ;
}
2010-11-02 07:33:42 +03:00
if ( store_values ) {
store_lp_set_cmdline ( pszParmName , pszParmValue ) ;
}
2010-08-11 07:35:14 +04:00
return true ;
}
/* it might be parametric */
if ( strchr ( pszParmName , ' : ' ) ! = NULL ) {
set_param_opt ( & Globals . param_opt , pszParmName , pszParmValue , FLAG_CMDLINE ) ;
2010-11-02 07:33:42 +03:00
if ( store_values ) {
store_lp_set_cmdline ( pszParmName , pszParmValue ) ;
}
2010-08-11 07:35:14 +04:00
return true ;
}
DEBUG ( 0 , ( " Ignoring unknown parameter \" %s \" \n " , pszParmName ) ) ;
return true ;
}
bool lp_set_cmdline ( const char * pszParmName , const char * pszParmValue )
{
return lp_set_cmdline_helper ( pszParmName , pszParmValue , true ) ;
}
1997-09-11 06:19:04 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Process a parameter .
1997-09-11 06:19:04 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2008-03-26 00:53:47 +03:00
static bool do_parameter ( const char * pszParmName , const char * pszParmValue ,
void * userdata )
1997-09-11 06:19:04 +04:00
{
2000-05-29 03:34:34 +04:00
if ( ! bInGlobalSection & & bGlobalOnly )
2011-10-06 09:58:32 +04:00
return true ;
1997-09-11 06:19:04 +04:00
2000-06-10 18:29:31 +04:00
DEBUGADD ( 4 , ( " doing parameter %s = %s \n " , pszParmName , pszParmValue ) ) ;
1997-09-11 06:19:04 +04:00
2000-05-29 03:34:34 +04:00
return ( lp_do_parameter ( bInGlobalSection ? - 2 : iServiceIndex ,
pszParmName , pszParmValue ) ) ;
1997-09-11 06:19:04 +04:00
}
2010-08-11 07:35:14 +04:00
/*
set a option from the commandline in ' a = b ' format . Use to support - - option
*/
bool lp_set_option ( const char * option )
{
char * p , * s ;
bool ret ;
s = talloc_strdup ( NULL , option ) ;
if ( ! s ) {
return false ;
}
p = strchr ( s , ' = ' ) ;
if ( ! p ) {
talloc_free ( s ) ;
return false ;
}
* p = 0 ;
2011-02-09 15:42:38 +03:00
/* skip white spaces after the = sign */
do {
p + + ;
} while ( * p = = ' ' ) ;
ret = lp_set_cmdline ( s , p ) ;
2010-08-11 07:35:14 +04:00
talloc_free ( s ) ;
return ret ;
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Check if two parameters are equal .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
static bool equal_parameter ( parm_type type , void * ptr1 , void * ptr2 )
2000-05-29 03:34:34 +04:00
{
2002-11-13 02:20:50 +03:00
switch ( type ) {
2000-05-29 03:34:34 +04:00
case P_BOOL :
case P_BOOLREV :
2007-10-19 04:40:25 +04:00
return ( * ( ( bool * ) ptr1 ) = = * ( ( bool * ) ptr2 ) ) ;
2000-05-29 03:34:34 +04:00
case P_INTEGER :
case P_ENUM :
case P_OCTAL :
2011-07-21 19:03:58 +04:00
case P_BYTES :
2000-05-29 03:34:34 +04:00
return ( * ( ( int * ) ptr1 ) = = * ( ( int * ) ptr2 ) ) ;
case P_CHAR :
return ( * ( ( char * ) ptr1 ) = = * ( ( char * ) ptr2 ) ) ;
2007-12-07 23:26:32 +03:00
2001-06-20 20:54:32 +04:00
case P_LIST :
2011-07-21 19:04:16 +04:00
case P_CMDLIST :
2008-10-18 17:56:07 +04:00
return str_list_equal ( * ( const char * * * ) ptr1 , * ( const char * * * ) ptr2 ) ;
2000-05-29 03:34:34 +04:00
case P_STRING :
case P_USTRING :
{
char * p1 = * ( char * * ) ptr1 , * p2 = * ( char * * ) ptr2 ;
if ( p1 & & ! * p1 )
p1 = NULL ;
if ( p2 & & ! * p2 )
p2 = NULL ;
return ( p1 = = p2 | | strequal ( p1 , p2 ) ) ;
}
case P_SEP :
break ;
}
2011-10-06 09:58:32 +04:00
return false ;
1996-05-04 11:50:46 +04:00
}
2000-09-20 02:32:56 +04:00
/***************************************************************************
2012-11-16 03:30:44 +04:00
Initialize any local variables in the sDefault table , after parsing a
[ globals ] section .
2000-09-20 02:32:56 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-11-16 04:00:21 +04:00
static void init_locals ( void )
2000-09-20 02:32:56 +04:00
{
2012-11-16 03:30:44 +04:00
/*
* We run this check once the [ globals ] is parsed , to force
* the VFS objects and other per - share settings we need for
* the standard way a AD DC is operated . We may change these
* as our code evolves , which is why we force these settings .
*
* We can ' t do this at the end of lp_load_ex ( ) , as by that
* point the services have been loaded and they will already
* have " " as their vfs objects .
*/
if ( lp_server_role ( ) = = ROLE_ACTIVE_DIRECTORY_DC ) {
const char * * vfs_objects = lp_vfs_objects ( - 1 ) ;
if ( ! vfs_objects | | ! vfs_objects [ 0 ] ) {
if ( lp_parm_const_string ( - 1 , " xattr_tdb " , " file " , NULL ) ) {
lp_do_parameter ( - 1 , " vfs objects " , " dfs_samba4 acl_xattr xattr_tdb " ) ;
} else if ( lp_parm_const_string ( - 1 , " posix " , " eadb " , NULL ) ) {
lp_do_parameter ( - 1 , " vfs objects " , " dfs_samba4 acl_xattr posix_eadb " ) ;
} else {
lp_do_parameter ( - 1 , " vfs objects " , " dfs_samba4 acl_xattr " ) ;
}
}
lp_do_parameter ( - 1 , " map hidden " , " no " ) ;
lp_do_parameter ( - 1 , " map system " , " no " ) ;
lp_do_parameter ( - 1 , " map readonly " , " no " ) ;
2012-11-20 16:50:46 +04:00
lp_do_parameter ( - 1 , " map archive " , " no " ) ;
2012-11-16 03:30:44 +04:00
lp_do_parameter ( - 1 , " store dos attributes " , " yes " ) ;
}
2000-09-20 02:32:56 +04:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Process a new section ( service ) . At this stage all sections are services .
Later we ' ll have special sections that permit server parameters to be set .
2011-06-29 09:06:49 +04:00
Returns true on success , false on failure .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2008-03-26 00:53:47 +03:00
static bool do_section ( const char * pszSectionName , void * userdata )
1996-05-04 11:50:46 +04:00
{
2007-10-19 04:40:25 +04:00
bool bRetval ;
bool isglobal = ( ( strwicmp ( pszSectionName , GLOBAL_NAME ) = = 0 ) | |
2000-05-29 03:34:34 +04:00
( strwicmp ( pszSectionName , GLOBAL_NAME2 ) = = 0 ) ) ;
2011-06-29 09:06:49 +04:00
bRetval = false ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
/* if we were in a global section then do the local inits */
if ( bInGlobalSection & & ! isglobal )
init_locals ( ) ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
/* if we've just struck a global section, note the fact. */
bInGlobalSection = isglobal ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
/* check for multiple global sections */
2002-11-13 02:20:50 +03:00
if ( bInGlobalSection ) {
2000-05-29 03:34:34 +04:00
DEBUG ( 3 , ( " Processing section \" [%s] \" \n " , pszSectionName ) ) ;
2011-10-06 09:58:32 +04:00
return true ;
2000-05-29 03:34:34 +04:00
}
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
if ( ! bInGlobalSection & & bGlobalOnly )
2011-10-06 09:58:32 +04:00
return true ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
/* if we have a current service, tidy it up before moving on */
2011-06-29 09:05:37 +04:00
bRetval = true ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
if ( iServiceIndex > = 0 )
bRetval = service_ok ( iServiceIndex ) ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
/* if all is still well, move to the next record in the services array */
2002-11-13 02:20:50 +03:00
if ( bRetval ) {
2000-05-29 03:34:34 +04:00
/* We put this here to avoid an odd message order if messages are */
/* issued by the post-processing of a previous section. */
DEBUG ( 2 , ( " Processing section \" [%s] \" \n " , pszSectionName ) ) ;
1996-05-04 11:50:46 +04:00
2011-07-20 18:48:07 +04:00
iServiceIndex = add_a_service ( & sDefault , pszSectionName ) ;
if ( iServiceIndex < 0 ) {
2000-05-29 03:34:34 +04:00
DEBUG ( 0 , ( " Failed to add a new service \n " ) ) ;
2011-10-06 09:58:32 +04:00
return false ;
2000-05-29 03:34:34 +04:00
}
2010-10-16 09:27:10 +04:00
/* Clean all parametric options for service */
/* They will be added during parsing again */
free_param_opts ( & ServicePtrs [ iServiceIndex ] - > param_opt ) ;
2000-05-29 03:34:34 +04:00
}
1996-05-04 11:50:46 +04:00
2011-10-06 09:58:32 +04:00
return bRetval ;
1996-05-04 11:50:46 +04:00
}
1998-03-14 11:27:41 +03:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Determine if a partcular base parameter is currentl set to the default value .
1998-03-14 11:27:41 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
static bool is_default ( int i )
1998-03-14 11:27:41 +03:00
{
2000-05-29 03:34:34 +04:00
if ( ! defaults_saved )
2011-06-29 09:06:49 +04:00
return false ;
2002-11-13 02:20:50 +03:00
switch ( parm_table [ i ] . type ) {
2001-06-20 20:54:32 +04:00
case P_LIST :
2011-07-21 19:13:44 +04:00
case P_CMDLIST :
2008-10-18 17:56:07 +04:00
return str_list_equal ( ( const char * * ) parm_table [ i ] . def . lvalue ,
2011-06-29 03:52:46 +04:00
* ( const char * * * ) lp_parm_ptr ( NULL ,
& parm_table [ i ] ) ) ;
2000-05-29 03:34:34 +04:00
case P_STRING :
case P_USTRING :
return strequal ( parm_table [ i ] . def . svalue ,
2011-06-29 03:52:46 +04:00
* ( char * * ) lp_parm_ptr ( NULL ,
& parm_table [ i ] ) ) ;
2000-05-29 03:34:34 +04:00
case P_BOOL :
case P_BOOLREV :
return parm_table [ i ] . def . bvalue = =
2011-06-29 03:52:46 +04:00
* ( bool * ) lp_parm_ptr ( NULL ,
& parm_table [ i ] ) ;
2000-05-29 03:34:34 +04:00
case P_CHAR :
return parm_table [ i ] . def . cvalue = =
2011-06-29 03:52:46 +04:00
* ( char * ) lp_parm_ptr ( NULL ,
& parm_table [ i ] ) ;
2000-05-29 03:34:34 +04:00
case P_INTEGER :
case P_OCTAL :
case P_ENUM :
2011-07-21 19:13:24 +04:00
case P_BYTES :
2000-05-29 03:34:34 +04:00
return parm_table [ i ] . def . ivalue = =
2011-06-29 03:52:46 +04:00
* ( int * ) lp_parm_ptr ( NULL ,
& parm_table [ i ] ) ;
2000-05-29 03:34:34 +04:00
case P_SEP :
break ;
1998-03-14 11:27:41 +03:00
}
2011-06-29 09:06:49 +04:00
return false ;
1998-03-14 11:27:41 +03:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
Display the contents of the global structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2001-07-04 11:15:53 +04:00
static void dump_globals ( FILE * f )
1996-05-04 11:50:46 +04:00
{
1998-03-14 11:27:41 +03:00
int i ;
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data ;
2009-11-21 18:17:16 +03:00
2005-06-12 20:00:29 +04:00
fprintf ( f , " [global] \n " ) ;
2000-05-29 03:34:34 +04:00
for ( i = 0 ; parm_table [ i ] . label ; i + + )
2005-06-25 00:25:18 +04:00
if ( parm_table [ i ] . p_class = = P_GLOBAL & &
2009-05-15 03:46:09 +04:00
! ( parm_table [ i ] . flags & FLAG_META ) & &
2011-06-29 04:48:35 +04:00
( i = = 0 | | ( parm_table [ i ] . offset ! = parm_table [ i - 1 ] . offset ) ) ) {
2000-05-29 03:34:34 +04:00
if ( defaults_saved & & is_default ( i ) )
continue ;
fprintf ( f , " \t %s = " , parm_table [ i ] . label ) ;
2014-01-15 04:39:14 +04:00
lpcfg_print_parameter ( & parm_table [ i ] , lp_parm_ptr ( NULL ,
& parm_table [ i ] ) ,
2011-06-29 03:52:46 +04:00
f ) ;
2000-05-29 03:34:34 +04:00
fprintf ( f , " \n " ) ;
2002-11-13 02:20:50 +03:00
}
2003-04-24 07:46:17 +04:00
if ( Globals . param_opt ! = NULL ) {
data = Globals . param_opt ;
2002-07-15 14:35:28 +04:00
while ( data ) {
2003-04-24 07:46:17 +04:00
fprintf ( f , " \t %s = %s \n " , data - > key , data - > value ) ;
data = data - > next ;
2002-07-15 14:35:28 +04:00
}
}
1996-05-04 11:50:46 +04:00
}
1998-03-14 14:24:01 +03:00
/***************************************************************************
2011-06-29 09:05:37 +04:00
Return true if a local parameter is currently set to the global default .
1998-03-14 14:24:01 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
bool lp_is_default ( int snum , struct parm_struct * parm )
1998-03-14 14:24:01 +03:00
{
return equal_parameter ( parm - > type ,
2011-06-29 03:52:46 +04:00
lp_parm_ptr ( ServicePtrs [ snum ] , parm ) ,
lp_parm_ptr ( NULL , parm ) ) ;
1998-03-14 14:24:01 +03:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Display the contents of a single services record .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-06-28 04:06:05 +04:00
static void dump_a_service ( struct loadparm_service * pService , FILE * f )
1996-05-04 11:50:46 +04:00
{
1998-03-14 11:27:41 +03:00
int i ;
2011-07-08 03:18:09 +04:00
struct parmlist_entry * data ;
2009-11-21 18:17:16 +03:00
1998-03-14 11:27:41 +03:00
if ( pService ! = & sDefault )
2005-06-12 20:00:29 +04:00
fprintf ( f , " [%s] \n " , pService - > szService ) ;
1998-03-14 11:27:41 +03:00
2004-04-11 02:37:47 +04:00
for ( i = 0 ; parm_table [ i ] . label ; i + + ) {
2005-06-25 00:25:18 +04:00
if ( parm_table [ i ] . p_class = = P_LOCAL & &
2009-05-15 03:46:09 +04:00
! ( parm_table [ i ] . flags & FLAG_META ) & &
1998-03-14 11:27:41 +03:00
( * parm_table [ i ] . label ! = ' - ' ) & &
2011-06-29 04:48:35 +04:00
( i = = 0 | | ( parm_table [ i ] . offset ! = parm_table [ i - 1 ] . offset ) ) )
2004-04-11 02:37:47 +04:00
{
2002-11-13 02:20:50 +03:00
if ( pService = = & sDefault ) {
2000-05-29 03:34:34 +04:00
if ( defaults_saved & & is_default ( i ) )
continue ;
2002-11-13 02:20:50 +03:00
} else {
1998-03-14 11:27:41 +03:00
if ( equal_parameter ( parm_table [ i ] . type ,
2011-06-29 03:52:46 +04:00
lp_parm_ptr ( pService , & parm_table [ i ] ) ,
lp_parm_ptr ( NULL , & parm_table [ i ] ) ) )
1998-03-14 11:27:41 +03:00
continue ;
}
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
fprintf ( f , " \t %s = " , parm_table [ i ] . label ) ;
2014-01-15 04:39:14 +04:00
lpcfg_print_parameter ( & parm_table [ i ] ,
2011-06-29 03:52:46 +04:00
lp_parm_ptr ( pService , & parm_table [ i ] ) ,
f ) ;
2000-05-29 03:34:34 +04:00
fprintf ( f , " \n " ) ;
2002-07-15 14:35:28 +04:00
}
2004-07-12 19:30:23 +04:00
}
2004-04-11 02:37:47 +04:00
2005-09-30 21:13:37 +04:00
if ( pService - > param_opt ! = NULL ) {
data = pService - > param_opt ;
while ( data ) {
fprintf ( f , " \t %s = %s \n " , data - > key , data - > value ) ;
data = data - > next ;
}
}
1996-05-04 11:50:46 +04:00
}
2005-06-12 20:00:29 +04:00
/***************************************************************************
Display the contents of a parameter of a single services record .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool dump_a_parameter ( int snum , char * parm_name , FILE * f , bool isGlobal )
2005-06-12 20:00:29 +04:00
{
2011-06-29 09:06:49 +04:00
bool result = false ;
2006-04-03 01:12:23 +04:00
fstring local_parm_name ;
char * parm_opt ;
2006-04-05 11:44:14 +04:00
const char * parm_opt_value ;
2014-01-15 04:48:22 +04:00
struct loadparm_context * lp_ctx ;
2006-04-03 01:12:23 +04:00
/* check for parametrical option */
fstrcpy ( local_parm_name , parm_name ) ;
parm_opt = strchr ( local_parm_name , ' : ' ) ;
if ( parm_opt ) {
* parm_opt = ' \0 ' ;
parm_opt + + ;
if ( strlen ( parm_opt ) ) {
2006-04-05 11:44:14 +04:00
parm_opt_value = lp_parm_const_string ( snum ,
local_parm_name , parm_opt , NULL ) ;
if ( parm_opt_value ) {
printf ( " %s \n " , parm_opt_value ) ;
2011-06-29 09:05:37 +04:00
result = true ;
2006-04-05 11:44:14 +04:00
}
2006-04-03 01:12:23 +04:00
}
return result ;
}
2005-06-12 20:00:29 +04:00
2014-01-15 04:48:22 +04:00
lp_ctx = loadparm_init_s3 ( talloc_tos ( ) , loadparm_s3_helpers ( ) ) ;
if ( lp_ctx = = NULL ) {
2014-01-15 04:42:55 +04:00
return false ;
}
2005-06-12 20:00:29 +04:00
2014-01-15 04:42:55 +04:00
if ( isGlobal ) {
2014-01-15 04:48:22 +04:00
result = lpcfg_dump_a_parameter ( lp_ctx , NULL , parm_name , f ) ;
2014-01-15 04:42:55 +04:00
} else {
2014-01-15 04:48:22 +04:00
result = lpcfg_dump_a_parameter ( lp_ctx , ServicePtrs [ snum ] , parm_name , f ) ;
2005-06-12 20:00:29 +04:00
}
2014-01-15 04:48:22 +04:00
TALLOC_FREE ( lp_ctx ) ;
return result ;
2005-06-12 20:00:29 +04:00
}
1997-09-11 06:19:04 +04:00
2007-08-16 19:27:06 +04:00
/***************************************************************************
Return info about the requested parameter ( given as a string ) .
Return NULL when the string is not a valid parameter name .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct parm_struct * lp_get_parameter ( const char * param_name )
{
2014-01-15 05:19:21 +04:00
int num = lpcfg_map_parameter ( param_name ) ;
2007-08-16 19:27:06 +04:00
if ( num < 0 ) {
return NULL ;
}
return & parm_table [ num ] ;
}
1997-09-11 06:19:04 +04:00
/***************************************************************************
2007-03-24 21:01:39 +03:00
Return info about the next parameter in a service .
snum = = GLOBAL_SECTION_SNUM gives the globals .
2002-11-13 02:20:50 +03:00
Return NULL when out of parameters .
1997-09-11 06:19:04 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
1998-03-08 17:14:49 +03:00
struct parm_struct * lp_next_parameter ( int snum , int * i , int allparameters )
1997-09-11 06:19:04 +04:00
{
2003-04-24 07:46:17 +04:00
if ( snum < 0 ) {
1997-09-11 06:19:04 +04:00
/* do the globals */
2002-11-13 02:20:50 +03:00
for ( ; parm_table [ * i ] . label ; ( * i ) + + ) {
2005-06-25 00:25:18 +04:00
if ( parm_table [ * i ] . p_class = = P_SEPARATOR )
1998-03-08 17:14:49 +03:00
return & parm_table [ ( * i ) + + ] ;
1998-03-14 11:27:41 +03:00
2011-06-29 06:36:06 +04:00
if ( ( * parm_table [ * i ] . label = = ' - ' ) )
1998-03-14 11:27:41 +03:00
continue ;
2000-05-29 03:34:34 +04:00
if ( ( * i ) > 0
2011-06-29 04:48:35 +04:00
& & ( parm_table [ * i ] . offset = =
2011-07-07 15:16:24 +04:00
parm_table [ ( * i ) - 1 ] . offset )
& & ( parm_table [ * i ] . p_class = =
parm_table [ ( * i ) - 1 ] . p_class ) )
1998-03-14 11:27:41 +03:00
continue ;
2009-11-21 18:17:16 +03:00
2007-06-22 03:11:21 +04:00
if ( is_default ( * i ) & & ! allparameters )
continue ;
1998-03-14 11:27:41 +03:00
return & parm_table [ ( * i ) + + ] ;
}
2002-11-13 02:20:50 +03:00
} else {
2011-06-28 04:06:05 +04:00
struct loadparm_service * pService = ServicePtrs [ snum ] ;
1998-03-14 11:27:41 +03:00
2002-11-13 02:20:50 +03:00
for ( ; parm_table [ * i ] . label ; ( * i ) + + ) {
2005-06-25 00:25:18 +04:00
if ( parm_table [ * i ] . p_class = = P_SEPARATOR )
1998-03-14 11:27:41 +03:00
return & parm_table [ ( * i ) + + ] ;
1997-09-11 06:19:04 +04:00
2005-06-25 00:25:18 +04:00
if ( parm_table [ * i ] . p_class = = P_LOCAL & &
1997-09-11 06:19:04 +04:00
( * parm_table [ * i ] . label ! = ' - ' ) & &
2000-05-29 03:34:34 +04:00
( ( * i ) = = 0 | |
2011-06-29 04:48:35 +04:00
( parm_table [ * i ] . offset ! =
parm_table [ ( * i ) - 1 ] . offset ) ) )
2000-05-29 03:34:34 +04:00
{
1998-03-14 11:27:41 +03:00
if ( allparameters | |
1997-09-11 06:19:04 +04:00
! equal_parameter ( parm_table [ * i ] . type ,
2011-06-29 03:52:46 +04:00
lp_parm_ptr ( pService ,
& parm_table [ * i ] ) ,
lp_parm_ptr ( NULL ,
& parm_table [ * i ] ) ) )
2000-05-29 03:34:34 +04:00
{
1998-03-08 17:14:49 +03:00
return & parm_table [ ( * i ) + + ] ;
1997-09-11 06:19:04 +04:00
}
}
1998-03-14 11:27:41 +03:00
}
1997-09-11 06:19:04 +04:00
}
1998-03-14 11:27:41 +03:00
return NULL ;
1997-09-11 06:19:04 +04:00
}
1996-05-04 11:50:46 +04:00
#if 0
/***************************************************************************
2002-11-13 02:20:50 +03:00
Display the contents of a single copy structure .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static void dump_copy_map ( bool * pcopymap )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
int i ;
if ( ! pcopymap )
return ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
printf ( " \n \t Non-Copied parameters: \n " ) ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
for ( i = 0 ; parm_table [ i ] . label ; i + + )
2005-06-25 00:25:18 +04:00
if ( parm_table [ i ] . p_class = = P_LOCAL & &
2000-05-29 03:34:34 +04:00
parm_table [ i ] . ptr & & ! pcopymap [ i ] & &
( i = = 0 | | ( parm_table [ i ] . ptr ! = parm_table [ i - 1 ] . ptr ) ) )
{
printf ( " \t \t %s \n " , parm_table [ i ] . label ) ;
}
1996-05-04 11:50:46 +04:00
}
# endif
/***************************************************************************
2002-11-13 02:20:50 +03:00
Return TRUE if the passed service number is within range .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-17 02:53:10 +03:00
2007-10-19 04:40:25 +04:00
bool lp_snum_ok ( int iService )
1996-05-04 11:50:46 +04:00
{
2001-05-11 02:10:31 +04:00
return ( LP_SNUM_OK ( iService ) & & ServicePtrs [ iService ] - > bAvailable ) ;
1996-05-04 11:50:46 +04:00
}
2000-06-17 03:57:09 +04:00
/***************************************************************************
2002-01-17 02:53:10 +03:00
Auto - load some home services .
2000-06-17 03:57:09 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-17 02:53:10 +03:00
2000-06-17 03:57:09 +04:00
static void lp_add_auto_services ( char * str )
{
char * s ;
char * p ;
int homes ;
2008-01-23 13:04:10 +03:00
char * saveptr ;
2000-06-17 03:57:09 +04:00
if ( ! str )
return ;
2004-12-07 21:25:53 +03:00
s = SMB_STRDUP ( str ) ;
2000-06-17 03:57:09 +04:00
if ( ! s )
return ;
homes = lp_servicenumber ( HOMES_NAME ) ;
2008-01-23 13:04:10 +03:00
for ( p = strtok_r ( s , LIST_SEP , & saveptr ) ; p ;
p = strtok_r ( NULL , LIST_SEP , & saveptr ) ) {
2007-12-19 17:02:59 +03:00
char * home ;
2000-06-17 03:57:09 +04:00
if ( lp_servicenumber ( p ) > = 0 )
continue ;
2007-12-19 17:02:59 +03:00
home = get_user_home_dir ( talloc_tos ( ) , p ) ;
2009-10-01 21:23:29 +04:00
if ( home & & home [ 0 ] & & homes > = 0 )
2002-07-15 14:35:28 +04:00
lp_add_home ( p , homes , p , home ) ;
2007-12-19 17:02:59 +03:00
TALLOC_FREE ( home ) ;
2000-06-17 03:57:09 +04:00
}
2001-09-17 08:58:38 +04:00
SAFE_FREE ( s ) ;
2000-06-17 03:57:09 +04:00
}
/***************************************************************************
2002-01-17 02:53:10 +03:00
Auto - load one printer .
2000-06-17 03:57:09 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-17 02:53:10 +03:00
2011-05-13 12:02:42 +04:00
void lp_add_one_printer ( const char * name , const char * comment ,
const char * location , void * pdata )
2000-06-17 03:57:09 +04:00
{
int printers = lp_servicenumber ( PRINTERS_NAME ) ;
int i ;
2002-01-17 02:53:10 +03:00
if ( lp_servicenumber ( name ) < 0 ) {
2000-06-17 03:57:09 +04:00
lp_add_printer ( name , printers ) ;
2002-01-17 02:53:10 +03:00
if ( ( i = lp_servicenumber ( name ) ) > = 0 ) {
2001-05-11 02:10:31 +04:00
string_set ( & ServicePtrs [ i ] - > comment , comment ) ;
2011-06-29 09:05:37 +04:00
ServicePtrs [ i ] - > autoloaded = true ;
2000-06-17 03:57:09 +04:00
}
}
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-01-17 02:53:10 +03:00
Have we loaded a services file yet ?
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-17 02:53:10 +03:00
2007-10-19 04:40:25 +04:00
bool lp_loaded ( void )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
return ( bLoaded ) ;
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
2002-01-17 02:53:10 +03:00
Unload unused services .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-17 02:53:10 +03:00
2011-05-25 07:00:22 +04:00
void lp_killunused ( struct smbd_server_connection * sconn ,
bool ( * snumused ) ( struct smbd_server_connection * , int ) )
1996-05-04 11:50:46 +04:00
{
2000-05-10 15:20:46 +04:00
int i ;
2002-01-17 02:53:10 +03:00
for ( i = 0 ; i < iNumServices ; i + + ) {
2000-05-29 03:34:34 +04:00
if ( ! VALID ( i ) )
continue ;
2000-05-10 15:20:46 +04:00
2006-02-04 01:19:41 +03:00
/* don't kill autoloaded or usershare services */
if ( ServicePtrs [ i ] - > autoloaded | |
ServicePtrs [ i ] - > usershare = = USERSHARE_VALID ) {
2004-06-21 21:51:06 +04:00
continue ;
2006-02-04 01:19:41 +03:00
}
2004-06-21 21:51:06 +04:00
2011-05-25 07:00:22 +04:00
if ( ! snumused | | ! snumused ( sconn , i ) ) {
2005-10-23 20:29:02 +04:00
free_service_byindex ( i ) ;
2000-05-10 15:20:46 +04:00
}
}
1996-05-04 11:50:46 +04:00
}
2008-03-12 02:54:48 +03:00
/**
* Kill all except autoloaded and usershare services - convenience wrapper
*/
void lp_kill_all_services ( void )
{
2011-05-25 07:00:22 +04:00
lp_killunused ( NULL , NULL ) ;
2008-03-12 02:54:48 +03:00
}
2000-08-01 00:41:51 +04:00
/***************************************************************************
2002-01-17 02:53:10 +03:00
Unload a service .
2000-08-01 00:41:51 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-17 02:53:10 +03:00
2000-08-01 00:41:51 +04:00
void lp_killservice ( int iServiceIn )
{
2002-01-17 02:53:10 +03:00
if ( VALID ( iServiceIn ) ) {
2005-10-23 20:29:02 +04:00
free_service_byindex ( iServiceIn ) ;
2000-08-01 00:41:51 +04:00
}
}
1998-03-14 11:27:41 +03:00
/***************************************************************************
2002-01-17 02:53:10 +03:00
Save the curent values of all global and sDefault parameters into the
2013-05-17 16:16:26 +04:00
defaults union . This allows testparm to show only the
2002-01-17 02:53:10 +03:00
changed ( ie . non - default ) parameters .
1998-03-14 11:27:41 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-17 02:53:10 +03:00
1998-03-14 11:27:41 +03:00
static void lp_save_defaults ( void )
{
int i ;
2002-01-17 02:53:10 +03:00
for ( i = 0 ; parm_table [ i ] . label ; i + + ) {
2011-07-07 15:16:24 +04:00
if ( i > 0 & & parm_table [ i ] . offset = = parm_table [ i - 1 ] . offset
& & parm_table [ i ] . p_class = = parm_table [ i - 1 ] . p_class )
2000-05-29 03:34:34 +04:00
continue ;
2002-01-17 02:53:10 +03:00
switch ( parm_table [ i ] . type ) {
2001-06-20 20:54:32 +04:00
case P_LIST :
2011-07-21 19:15:31 +04:00
case P_CMDLIST :
2008-10-12 03:46:15 +04:00
parm_table [ i ] . def . lvalue = str_list_copy (
2011-06-29 03:52:46 +04:00
NULL , * ( const char * * * ) lp_parm_ptr ( NULL , & parm_table [ i ] ) ) ;
2001-06-20 20:54:32 +04:00
break ;
2000-05-29 03:34:34 +04:00
case P_STRING :
case P_USTRING :
2011-06-29 06:36:06 +04:00
parm_table [ i ] . def . svalue = SMB_STRDUP ( * ( char * * ) lp_parm_ptr ( NULL , & parm_table [ i ] ) ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_BOOL :
case P_BOOLREV :
parm_table [ i ] . def . bvalue =
2011-06-29 03:52:46 +04:00
* ( bool * ) lp_parm_ptr ( NULL , & parm_table [ i ] ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_CHAR :
parm_table [ i ] . def . cvalue =
2011-06-29 03:52:46 +04:00
* ( char * ) lp_parm_ptr ( NULL , & parm_table [ i ] ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_INTEGER :
case P_OCTAL :
case P_ENUM :
2011-07-21 19:14:56 +04:00
case P_BYTES :
2000-05-29 03:34:34 +04:00
parm_table [ i ] . def . ivalue =
2011-06-29 03:52:46 +04:00
* ( int * ) lp_parm_ptr ( NULL , & parm_table [ i ] ) ;
2000-05-29 03:34:34 +04:00
break ;
case P_SEP :
break ;
}
}
2011-06-29 09:05:37 +04:00
defaults_saved = true ;
2000-05-29 03:34:34 +04:00
}
2003-06-08 16:49:31 +04:00
/***********************************************************
If we should send plaintext / LANMAN passwords in the clinet
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-04 01:19:41 +03:00
2003-06-08 16:49:31 +04:00
static void set_allowed_client_auth ( void )
{
2013-12-24 07:03:43 +04:00
if ( Globals . client_ntlmv2_auth ) {
2013-12-24 07:03:43 +04:00
Globals . client_lanman_auth = false ;
2003-06-08 16:49:31 +04:00
}
2013-12-24 07:03:43 +04:00
if ( ! Globals . client_lanman_auth ) {
2013-12-24 07:03:44 +04:00
Globals . client_plaintext_auth = false ;
2003-06-08 16:49:31 +04:00
}
}
2006-02-04 01:19:41 +03:00
/***************************************************************************
JRA .
The following code allows smbd to read a user defined share file .
Yes , this is my intent . Yes , I ' m comfortable with that . . .
THE FOLLOWING IS SECURITY CRITICAL CODE .
It washes your clothes , it cleans your house , it guards you while you sleep . . .
Do not f % ^ k with it . . . .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# define MAX_USERSHARE_FILE_SIZE (10*1024)
/***************************************************************************
Check allowed stat state of a usershare file .
Ensure we print out who is dicking with us so the admin can
get their sorry ass fired .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-14 13:47:09 +04:00
static bool check_usershare_stat ( const char * fname ,
const SMB_STRUCT_STAT * psbuf )
2006-02-04 01:19:41 +03:00
{
2009-05-14 17:34:42 +04:00
if ( ! S_ISREG ( psbuf - > st_ex_mode ) ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " check_usershare_stat: file %s owned by uid %u is "
" not a regular file \n " ,
2009-05-14 17:34:42 +04:00
fname , ( unsigned int ) psbuf - > st_ex_uid ) ) ;
2011-06-29 09:06:49 +04:00
return false ;
2006-02-04 01:19:41 +03:00
}
/* Ensure this doesn't have the other write bit set. */
2009-05-14 17:34:42 +04:00
if ( psbuf - > st_ex_mode & S_IWOTH ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " check_usershare_stat: file %s owned by uid %u allows "
" public write. Refusing to allow as a usershare file. \n " ,
2009-05-14 17:34:42 +04:00
fname , ( unsigned int ) psbuf - > st_ex_uid ) ) ;
2011-06-29 09:06:49 +04:00
return false ;
2006-02-04 01:19:41 +03:00
}
/* Should be 10k or less. */
2009-05-14 17:34:42 +04:00
if ( psbuf - > st_ex_size > MAX_USERSHARE_FILE_SIZE ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " check_usershare_stat: file %s owned by uid %u is "
" too large (%u) to be a user share file. \n " ,
2009-05-14 17:34:42 +04:00
fname , ( unsigned int ) psbuf - > st_ex_uid ,
( unsigned int ) psbuf - > st_ex_size ) ) ;
2011-06-29 09:06:49 +04:00
return false ;
2006-02-04 01:19:41 +03:00
}
2011-06-29 09:05:37 +04:00
return true ;
2006-02-04 01:19:41 +03:00
}
/***************************************************************************
Parse the contents of a usershare file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-14 05:42:42 +03:00
enum usershare_err parse_usershare_file ( TALLOC_CTX * ctx ,
2006-02-04 01:19:41 +03:00
SMB_STRUCT_STAT * psbuf ,
const char * servicename ,
int snum ,
char * * lines ,
int numlines ,
2007-11-14 05:42:42 +03:00
char * * pp_sharepath ,
char * * pp_comment ,
2010-03-27 03:09:58 +03:00
char * * pp_cp_servicename ,
2010-05-18 12:29:34 +04:00
struct security_descriptor * * ppsd ,
2007-10-19 04:40:25 +04:00
bool * pallow_guest )
2006-02-04 01:19:41 +03:00
{
const char * * prefixallowlist = lp_usershare_prefix_allow_list ( ) ;
const char * * prefixdenylist = lp_usershare_prefix_deny_list ( ) ;
2006-04-30 04:36:26 +04:00
int us_vers ;
2012-03-28 06:22:03 +04:00
DIR * dp ;
2006-02-04 01:19:41 +03:00
SMB_STRUCT_STAT sbuf ;
2007-11-14 05:42:42 +03:00
char * sharepath = NULL ;
char * comment = NULL ;
* pp_sharepath = NULL ;
* pp_comment = NULL ;
2006-02-04 01:19:41 +03:00
2011-06-29 09:06:49 +04:00
* pallow_guest = false ;
2006-04-30 04:36:26 +04:00
2006-02-04 01:19:41 +03:00
if ( numlines < 4 ) {
return USERSHARE_MALFORMED_FILE ;
}
2006-04-30 04:36:26 +04:00
if ( strcmp ( lines [ 0 ] , " #VERSION 1 " ) = = 0 ) {
us_vers = 1 ;
} else if ( strcmp ( lines [ 0 ] , " #VERSION 2 " ) = = 0 ) {
us_vers = 2 ;
if ( numlines < 5 ) {
return USERSHARE_MALFORMED_FILE ;
}
} else {
2006-02-04 01:19:41 +03:00
return USERSHARE_BAD_VERSION ;
}
2006-04-30 04:36:26 +04:00
if ( strncmp ( lines [ 1 ] , " path= " , 5 ) ! = 0 ) {
2006-02-04 01:19:41 +03:00
return USERSHARE_MALFORMED_PATH ;
}
2007-11-14 05:42:42 +03:00
sharepath = talloc_strdup ( ctx , & lines [ 1 ] [ 5 ] ) ;
if ( ! sharepath ) {
return USERSHARE_POSIX_ERR ;
}
2006-02-04 01:19:41 +03:00
trim_string ( sharepath , " " , " " ) ;
2006-04-30 04:36:26 +04:00
if ( strncmp ( lines [ 2 ] , " comment= " , 8 ) ! = 0 ) {
2006-02-04 01:19:41 +03:00
return USERSHARE_MALFORMED_COMMENT_DEF ;
}
2007-11-14 05:42:42 +03:00
comment = talloc_strdup ( ctx , & lines [ 2 ] [ 8 ] ) ;
if ( ! comment ) {
return USERSHARE_POSIX_ERR ;
}
2006-02-04 01:19:41 +03:00
trim_string ( comment , " " , " " ) ;
trim_char ( comment , ' " ' , ' " ' ) ;
2006-04-30 04:36:26 +04:00
if ( strncmp ( lines [ 3 ] , " usershare_acl= " , 14 ) ! = 0 ) {
2006-02-04 01:19:41 +03:00
return USERSHARE_MALFORMED_ACL_DEF ;
}
if ( ! parse_usershare_acl ( ctx , & lines [ 3 ] [ 14 ] , ppsd ) ) {
return USERSHARE_ACL_ERR ;
}
2006-04-30 04:36:26 +04:00
if ( us_vers = = 2 ) {
if ( strncmp ( lines [ 4 ] , " guest_ok= " , 9 ) ! = 0 ) {
return USERSHARE_MALFORMED_ACL_DEF ;
}
if ( lines [ 4 ] [ 9 ] = = ' y ' ) {
2011-06-29 09:05:37 +04:00
* pallow_guest = true ;
2006-04-30 04:36:26 +04:00
}
2010-03-27 03:09:58 +03:00
/* Backwards compatible extension to file version #2. */
if ( numlines > 5 ) {
if ( strncmp ( lines [ 5 ] , " sharename= " , 10 ) ! = 0 ) {
return USERSHARE_MALFORMED_SHARENAME_DEF ;
}
if ( ! strequal ( & lines [ 5 ] [ 10 ] , servicename ) ) {
return USERSHARE_BAD_SHARENAME ;
}
* pp_cp_servicename = talloc_strdup ( ctx , & lines [ 5 ] [ 10 ] ) ;
if ( ! * pp_cp_servicename ) {
return USERSHARE_POSIX_ERR ;
}
}
}
if ( * pp_cp_servicename = = NULL ) {
* pp_cp_servicename = talloc_strdup ( ctx , servicename ) ;
if ( ! * pp_cp_servicename ) {
return USERSHARE_POSIX_ERR ;
}
2006-04-30 04:36:26 +04:00
}
2013-12-24 07:03:16 +04:00
if ( snum ! = - 1 & & ( strcmp ( sharepath , ServicePtrs [ snum ] - > pathname ) = = 0 ) ) {
2006-02-04 01:19:41 +03:00
/* Path didn't change, no checks needed. */
2007-11-14 05:42:42 +03:00
* pp_sharepath = sharepath ;
* pp_comment = comment ;
2006-02-04 01:19:41 +03:00
return USERSHARE_OK ;
}
/* The path *must* be absolute. */
if ( sharepath [ 0 ] ! = ' / ' ) {
DEBUG ( 2 , ( " parse_usershare_file: share %s: path %s is not an absolute path. \n " ,
servicename , sharepath ) ) ;
return USERSHARE_PATH_NOT_ABSOLUTE ;
}
/* If there is a usershare prefix deny list ensure one of these paths
doesn ' t match the start of the user given path . */
if ( prefixdenylist ) {
int i ;
for ( i = 0 ; prefixdenylist [ i ] ; i + + ) {
DEBUG ( 10 , ( " parse_usershare_file: share %s : checking prefixdenylist[%d]='%s' against %s \n " ,
servicename , i , prefixdenylist [ i ] , sharepath ) ) ;
if ( memcmp ( sharepath , prefixdenylist [ i ] , strlen ( prefixdenylist [ i ] ) ) = = 0 ) {
DEBUG ( 2 , ( " parse_usershare_file: share %s path %s starts with one of the "
" usershare prefix deny list entries. \n " ,
servicename , sharepath ) ) ;
return USERSHARE_PATH_IS_DENIED ;
}
}
}
/* If there is a usershare prefix allow list ensure one of these paths
does match the start of the user given path . */
if ( prefixallowlist ) {
int i ;
for ( i = 0 ; prefixallowlist [ i ] ; i + + ) {
DEBUG ( 10 , ( " parse_usershare_file: share %s checking prefixallowlist[%d]='%s' against %s \n " ,
servicename , i , prefixallowlist [ i ] , sharepath ) ) ;
if ( memcmp ( sharepath , prefixallowlist [ i ] , strlen ( prefixallowlist [ i ] ) ) = = 0 ) {
break ;
}
}
if ( prefixallowlist [ i ] = = NULL ) {
DEBUG ( 2 , ( " parse_usershare_file: share %s path %s doesn't start with one of the "
" usershare prefix allow list entries. \n " ,
servicename , sharepath ) ) ;
return USERSHARE_PATH_NOT_ALLOWED ;
}
}
/* Ensure this is pointing to a directory. */
2012-03-28 06:01:19 +04:00
dp = opendir ( sharepath ) ;
2006-02-04 01:19:41 +03:00
if ( ! dp ) {
DEBUG ( 2 , ( " parse_usershare_file: share %s path %s is not a directory. \n " ,
servicename , sharepath ) ) ;
return USERSHARE_PATH_NOT_DIRECTORY ;
}
/* Ensure the owner of the usershare file has permission to share
this directory . */
2009-11-27 14:49:42 +03:00
if ( sys_stat ( sharepath , & sbuf , false ) = = - 1 ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 2 , ( " parse_usershare_file: share %s : stat failed on path %s. %s \n " ,
servicename , sharepath , strerror ( errno ) ) ) ;
2012-03-28 06:08:27 +04:00
closedir ( dp ) ;
2006-02-04 01:19:41 +03:00
return USERSHARE_POSIX_ERR ;
}
2012-03-28 06:08:27 +04:00
closedir ( dp ) ;
2006-02-04 01:19:41 +03:00
2009-05-14 17:34:42 +04:00
if ( ! S_ISDIR ( sbuf . st_ex_mode ) ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 2 , ( " parse_usershare_file: share %s path %s is not a directory. \n " ,
servicename , sharepath ) ) ;
return USERSHARE_PATH_NOT_DIRECTORY ;
}
/* Check if sharing is restricted to owner-only. */
/* psbuf is the stat of the usershare definition file,
sbuf is the stat of the target directory to be shared . */
if ( lp_usershare_owner_only ( ) ) {
/* root can share anything. */
2009-05-14 17:34:42 +04:00
if ( ( psbuf - > st_ex_uid ! = 0 ) & & ( sbuf . st_ex_uid ! = psbuf - > st_ex_uid ) ) {
2006-02-04 01:19:41 +03:00
return USERSHARE_PATH_NOT_ALLOWED ;
}
}
2007-11-14 05:42:42 +03:00
* pp_sharepath = sharepath ;
* pp_comment = comment ;
2006-02-04 01:19:41 +03:00
return USERSHARE_OK ;
}
/***************************************************************************
Deal with a usershare file .
Returns :
> = 0 - snum
- 1 - Bad name , invalid contents .
- service name already existed and not a usershare , problem
with permissions to share directory etc .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int process_usershare_file ( const char * dir_name , const char * file_name , int snum_template )
{
SMB_STRUCT_STAT sbuf ;
SMB_STRUCT_STAT lsbuf ;
2007-11-14 05:42:42 +03:00
char * fname = NULL ;
char * sharepath = NULL ;
char * comment = NULL ;
2010-03-27 03:09:58 +03:00
char * cp_service_name = NULL ;
2006-02-04 01:19:41 +03:00
char * * lines = NULL ;
int numlines = 0 ;
int fd = - 1 ;
int iService = - 1 ;
2010-03-27 03:09:58 +03:00
TALLOC_CTX * ctx = talloc_stackframe ( ) ;
2010-05-18 12:29:34 +04:00
struct security_descriptor * psd = NULL ;
2011-06-29 09:06:49 +04:00
bool guest_ok = false ;
2010-03-27 03:09:58 +03:00
char * canon_name = NULL ;
bool added_service = false ;
int ret = - 1 ;
2006-02-04 01:19:41 +03:00
/* Ensure share name doesn't contain invalid characters. */
if ( ! validate_net_name ( file_name , INVALID_SHARENAME_CHARS , strlen ( file_name ) ) ) {
DEBUG ( 0 , ( " process_usershare_file: share name %s contains "
" invalid characters (any of %s) \n " ,
file_name , INVALID_SHARENAME_CHARS ) ) ;
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
2010-03-27 03:09:58 +03:00
canon_name = canonicalize_servicename ( ctx , file_name ) ;
if ( ! canon_name ) {
goto out ;
}
2006-02-04 01:19:41 +03:00
2010-03-27 03:09:58 +03:00
fname = talloc_asprintf ( ctx , " %s/%s " , dir_name , file_name ) ;
if ( ! fname ) {
goto out ;
2007-11-14 05:42:42 +03:00
}
2006-02-04 01:19:41 +03:00
/* Minimize the race condition by doing an lstat before we
open and fstat . Ensure this isn ' t a symlink link . */
2009-11-27 14:51:04 +03:00
if ( sys_lstat ( fname , & lsbuf , false ) ! = 0 ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " process_usershare_file: stat of %s failed. %s \n " ,
fname , strerror ( errno ) ) ) ;
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
/* This must be a regular file, not a symlink, directory or
other strange filetype . */
if ( ! check_usershare_stat ( fname , & lsbuf ) ) {
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
2007-11-24 21:56:41 +03:00
{
2011-08-24 15:08:13 +04:00
TDB_DATA data ;
NTSTATUS status ;
status = dbwrap_fetch_bystring ( ServiceHash , canon_name ,
canon_name , & data ) ;
2007-11-24 21:56:41 +03:00
iService = - 1 ;
2011-08-24 15:08:13 +04:00
if ( NT_STATUS_IS_OK ( status ) & &
( data . dptr ! = NULL ) & &
2012-01-06 19:38:44 +04:00
( data . dsize = = sizeof ( iService ) ) ) {
memcpy ( & iService , data . dptr , sizeof ( iService ) ) ;
2007-11-24 21:56:41 +03:00
}
}
2006-02-04 01:19:41 +03:00
2009-05-14 17:34:42 +04:00
if ( iService ! = - 1 & &
timespec_compare ( & ServicePtrs [ iService ] - > usershare_last_mod ,
& lsbuf . st_ex_mtime ) = = 0 ) {
2006-02-04 01:19:41 +03:00
/* Nothing changed - Mark valid and return. */
DEBUG ( 10 , ( " process_usershare_file: service %s not changed. \n " ,
2010-03-27 03:09:58 +03:00
canon_name ) ) ;
2006-02-04 01:19:41 +03:00
ServicePtrs [ iService ] - > usershare = USERSHARE_VALID ;
2010-03-27 03:09:58 +03:00
ret = iService ;
goto out ;
2006-02-04 01:19:41 +03:00
}
/* Try and open the file read only - no symlinks allowed. */
# ifdef O_NOFOLLOW
2012-03-28 05:48:00 +04:00
fd = open ( fname , O_RDONLY | O_NOFOLLOW , 0 ) ;
2006-02-04 01:19:41 +03:00
# else
2012-03-28 05:48:00 +04:00
fd = open ( fname , O_RDONLY , 0 ) ;
2006-02-04 01:19:41 +03:00
# endif
if ( fd = = - 1 ) {
DEBUG ( 0 , ( " process_usershare_file: unable to open %s. %s \n " ,
fname , strerror ( errno ) ) ) ;
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
/* Now fstat to be *SURE* it's a regular file. */
2009-11-27 14:51:56 +03:00
if ( sys_fstat ( fd , & sbuf , false ) ! = 0 ) {
2006-02-04 01:19:41 +03:00
close ( fd ) ;
DEBUG ( 0 , ( " process_usershare_file: fstat of %s failed. %s \n " ,
fname , strerror ( errno ) ) ) ;
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
/* Is it the same dev/inode as was lstated ? */
2012-07-09 23:28:48 +04:00
if ( ! check_same_stat ( & lsbuf , & sbuf ) ) {
2006-02-04 01:19:41 +03:00
close ( fd ) ;
DEBUG ( 0 , ( " process_usershare_file: fstat of %s is a different file from lstat. "
" Symlink spoofing going on ? \n " , fname ) ) ;
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
/* This must be a regular file, not a symlink, directory or
other strange filetype . */
if ( ! check_usershare_stat ( fname , & sbuf ) ) {
2013-02-20 12:15:26 +04:00
close ( fd ) ;
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
2008-10-12 19:34:43 +04:00
lines = fd_lines_load ( fd , & numlines , MAX_USERSHARE_FILE_SIZE , NULL ) ;
2006-02-04 01:19:41 +03:00
close ( fd ) ;
if ( lines = = NULL ) {
DEBUG ( 0 , ( " process_usershare_file: loading file %s owned by %u failed. \n " ,
2009-05-14 17:34:42 +04:00
fname , ( unsigned int ) sbuf . st_ex_uid ) ) ;
2010-03-27 03:09:58 +03:00
goto out ;
2006-02-04 01:19:41 +03:00
}
2010-03-27 03:09:58 +03:00
if ( parse_usershare_file ( ctx , & sbuf , file_name ,
2007-11-14 05:42:42 +03:00
iService , lines , numlines , & sharepath ,
2010-03-27 03:09:58 +03:00
& comment , & cp_service_name ,
& psd , & guest_ok ) ! = USERSHARE_OK ) {
goto out ;
2006-02-04 01:19:41 +03:00
}
/* Everything ok - add the service possibly using a template. */
if ( iService < 0 ) {
2011-06-28 04:06:05 +04:00
const struct loadparm_service * sp = & sDefault ;
2006-02-04 01:19:41 +03:00
if ( snum_template ! = - 1 ) {
sp = ServicePtrs [ snum_template ] ;
}
2010-03-27 03:09:58 +03:00
if ( ( iService = add_a_service ( sp , cp_service_name ) ) < 0 ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " process_usershare_file: Failed to add "
2010-03-27 03:09:58 +03:00
" new service %s \n " , cp_service_name ) ) ;
goto out ;
2006-02-04 01:19:41 +03:00
}
2010-03-27 03:09:58 +03:00
added_service = true ;
2006-02-04 01:19:41 +03:00
/* Read only is controlled by usershare ACL below. */
2013-12-24 07:03:17 +04:00
ServicePtrs [ iService ] - > readonly = false ;
2006-02-04 01:19:41 +03:00
}
/* Write the ACL of the new/modified share. */
2010-03-27 03:09:58 +03:00
if ( ! set_share_security ( canon_name , psd ) ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " process_usershare_file: Failed to set share "
" security for user share %s \n " ,
2010-03-27 03:09:58 +03:00
canon_name ) ) ;
goto out ;
2006-02-04 01:19:41 +03:00
}
/* If from a template it may be marked invalid. */
2011-06-29 09:05:37 +04:00
ServicePtrs [ iService ] - > valid = true ;
2006-02-04 01:19:41 +03:00
/* Set the service as a valid usershare. */
ServicePtrs [ iService ] - > usershare = USERSHARE_VALID ;
2006-04-30 04:36:26 +04:00
/* Set guest access. */
if ( lp_usershare_allow_guests ( ) ) {
2013-12-24 07:03:29 +04:00
ServicePtrs [ iService ] - > guest_ok = guest_ok ;
2006-04-30 04:36:26 +04:00
}
2006-02-04 01:19:41 +03:00
/* And note when it was loaded. */
2009-05-14 17:34:42 +04:00
ServicePtrs [ iService ] - > usershare_last_mod = sbuf . st_ex_mtime ;
2013-12-24 07:03:16 +04:00
string_set ( & ServicePtrs [ iService ] - > pathname , sharepath ) ;
2006-02-04 01:19:41 +03:00
string_set ( & ServicePtrs [ iService ] - > comment , comment ) ;
2010-03-27 03:09:58 +03:00
ret = iService ;
2007-11-14 05:42:42 +03:00
2010-03-27 03:09:58 +03:00
out :
if ( ret = = - 1 & & iService ! = - 1 & & added_service ) {
lp_remove_service ( iService ) ;
}
TALLOC_FREE ( lines ) ;
TALLOC_FREE ( ctx ) ;
return ret ;
2006-02-04 01:19:41 +03:00
}
/***************************************************************************
Checks if a usershare entry has been modified since last load .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-14 17:34:42 +04:00
static bool usershare_exists ( int iService , struct timespec * last_mod )
2006-02-04 01:19:41 +03:00
{
SMB_STRUCT_STAT lsbuf ;
2013-12-24 07:04:35 +04:00
const char * usersharepath = Globals . usershare_path ;
2007-11-14 05:42:42 +03:00
char * fname ;
2006-02-04 01:19:41 +03:00
2007-11-14 05:42:42 +03:00
if ( asprintf ( & fname , " %s/%s " ,
usersharepath ,
ServicePtrs [ iService ] - > szService ) < 0 ) {
return false ;
}
2006-02-04 01:19:41 +03:00
2009-11-27 14:52:31 +03:00
if ( sys_lstat ( fname , & lsbuf , false ) ! = 0 ) {
2007-11-14 05:42:42 +03:00
SAFE_FREE ( fname ) ;
return false ;
2006-02-04 01:19:41 +03:00
}
2009-05-14 17:34:42 +04:00
if ( ! S_ISREG ( lsbuf . st_ex_mode ) ) {
2007-11-14 05:42:42 +03:00
SAFE_FREE ( fname ) ;
return false ;
2006-02-04 01:19:41 +03:00
}
2007-11-14 05:42:42 +03:00
SAFE_FREE ( fname ) ;
2009-05-14 17:34:42 +04:00
* last_mod = lsbuf . st_ex_mtime ;
2007-11-14 05:42:42 +03:00
return true ;
2006-02-04 01:19:41 +03:00
}
/***************************************************************************
Load a usershare service by name . Returns a valid servicenumber or - 1.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int load_usershare_service ( const char * servicename )
{
SMB_STRUCT_STAT sbuf ;
2013-12-24 07:04:35 +04:00
const char * usersharepath = Globals . usershare_path ;
2013-12-24 07:04:20 +04:00
int max_user_shares = Globals . usershare_max_shares ;
2006-02-04 01:19:41 +03:00
int snum_template = - 1 ;
if ( * usersharepath = = 0 | | max_user_shares = = 0 ) {
return - 1 ;
}
2009-11-27 14:53:23 +03:00
if ( sys_stat ( usersharepath , & sbuf , false ) ! = 0 ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " load_usershare_service: stat of %s failed. %s \n " ,
usersharepath , strerror ( errno ) ) ) ;
return - 1 ;
}
2009-05-14 17:34:42 +04:00
if ( ! S_ISDIR ( sbuf . st_ex_mode ) ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " load_usershare_service: %s is not a directory. \n " ,
usersharepath ) ) ;
return - 1 ;
}
/*
* This directory must be owned by root , and have the ' t ' bit set .
* It also must not be writable by " other " .
*/
# ifdef S_ISVTX
2009-05-14 17:34:42 +04:00
if ( sbuf . st_ex_uid ! = 0 | | ! ( sbuf . st_ex_mode & S_ISVTX ) | | ( sbuf . st_ex_mode & S_IWOTH ) ) {
2006-02-04 01:19:41 +03:00
# else
2009-05-14 17:34:42 +04:00
if ( sbuf . st_ex_uid ! = 0 | | ( sbuf . st_ex_mode & S_IWOTH ) ) {
2006-02-04 01:19:41 +03:00
# endif
DEBUG ( 0 , ( " load_usershare_service: directory %s is not owned by root "
" or does not have the sticky bit 't' set or is writable by anyone. \n " ,
usersharepath ) ) ;
return - 1 ;
}
/* Ensure the template share exists if it's set. */
if ( Globals . szUsershareTemplateShare [ 0 ] ) {
/* We can't use lp_servicenumber here as we are recommending that
2011-06-29 09:06:49 +04:00
template shares have - valid = false set . */
2006-02-04 01:19:41 +03:00
for ( snum_template = iNumServices - 1 ; snum_template > = 0 ; snum_template - - ) {
if ( ServicePtrs [ snum_template ] - > szService & &
strequal ( ServicePtrs [ snum_template ] - > szService ,
Globals . szUsershareTemplateShare ) ) {
break ;
}
}
if ( snum_template = = - 1 ) {
DEBUG ( 0 , ( " load_usershare_service: usershare template share %s "
" does not exist. \n " ,
Globals . szUsershareTemplateShare ) ) ;
return - 1 ;
}
}
return process_usershare_file ( usersharepath , servicename , snum_template ) ;
}
/***************************************************************************
Load all user defined shares from the user share directory .
We only do this if we ' re enumerating the share list .
This is the function that can delete usershares that have
been removed .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-12-13 14:50:04 +04:00
int load_usershare_shares ( struct smbd_server_connection * sconn ,
bool ( * snumused ) ( struct smbd_server_connection * , int ) )
2006-02-04 01:19:41 +03:00
{
2012-03-28 06:22:03 +04:00
DIR * dp ;
2006-02-04 01:19:41 +03:00
SMB_STRUCT_STAT sbuf ;
2012-03-28 06:18:14 +04:00
struct dirent * de ;
2006-02-04 01:19:41 +03:00
int num_usershares = 0 ;
2013-12-24 07:04:20 +04:00
int max_user_shares = Globals . usershare_max_shares ;
2006-02-04 01:19:41 +03:00
unsigned int num_dir_entries , num_bad_dir_entries , num_tmp_dir_entries ;
unsigned int allowed_bad_entries = ( ( 2 * max_user_shares ) / 10 ) ;
unsigned int allowed_tmp_entries = ( ( 2 * max_user_shares ) / 10 ) ;
int iService ;
int snum_template = - 1 ;
2013-12-24 07:04:35 +04:00
const char * usersharepath = Globals . usershare_path ;
2006-02-04 01:19:41 +03:00
int ret = lp_numservices ( ) ;
2012-07-18 09:37:23 +04:00
TALLOC_CTX * tmp_ctx ;
2006-02-04 01:19:41 +03:00
if ( max_user_shares = = 0 | | * usersharepath = = ' \0 ' ) {
return lp_numservices ( ) ;
}
2009-11-27 14:53:48 +03:00
if ( sys_stat ( usersharepath , & sbuf , false ) ! = 0 ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 0 , ( " load_usershare_shares: stat of %s failed. %s \n " ,
usersharepath , strerror ( errno ) ) ) ;
return ret ;
}
/*
* This directory must be owned by root , and have the ' t ' bit set .
* It also must not be writable by " other " .
*/
# ifdef S_ISVTX
2009-05-14 17:34:42 +04:00
if ( sbuf . st_ex_uid ! = 0 | | ! ( sbuf . st_ex_mode & S_ISVTX ) | | ( sbuf . st_ex_mode & S_IWOTH ) ) {
2006-02-04 01:19:41 +03:00
# else
2009-05-14 17:34:42 +04:00
if ( sbuf . st_ex_uid ! = 0 | | ( sbuf . st_ex_mode & S_IWOTH ) ) {
2006-02-04 01:19:41 +03:00
# endif
DEBUG ( 0 , ( " load_usershare_shares: directory %s is not owned by root "
" or does not have the sticky bit 't' set or is writable by anyone. \n " ,
usersharepath ) ) ;
return ret ;
}
/* Ensure the template share exists if it's set. */
if ( Globals . szUsershareTemplateShare [ 0 ] ) {
/* We can't use lp_servicenumber here as we are recommending that
2011-06-29 09:06:49 +04:00
template shares have - valid = false set . */
2006-02-04 01:19:41 +03:00
for ( snum_template = iNumServices - 1 ; snum_template > = 0 ; snum_template - - ) {
if ( ServicePtrs [ snum_template ] - > szService & &
strequal ( ServicePtrs [ snum_template ] - > szService ,
Globals . szUsershareTemplateShare ) ) {
break ;
}
}
if ( snum_template = = - 1 ) {
DEBUG ( 0 , ( " load_usershare_shares: usershare template share %s "
" does not exist. \n " ,
Globals . szUsershareTemplateShare ) ) ;
return ret ;
}
}
/* Mark all existing usershares as pending delete. */
for ( iService = iNumServices - 1 ; iService > = 0 ; iService - - ) {
if ( VALID ( iService ) & & ServicePtrs [ iService ] - > usershare ) {
ServicePtrs [ iService ] - > usershare = USERSHARE_PENDING_DELETE ;
}
}
2012-03-28 06:01:19 +04:00
dp = opendir ( usersharepath ) ;
2006-02-04 01:19:41 +03:00
if ( ! dp ) {
DEBUG ( 0 , ( " load_usershare_shares:: failed to open directory %s. %s \n " ,
usersharepath , strerror ( errno ) ) ) ;
return ret ;
}
for ( num_dir_entries = 0 , num_bad_dir_entries = 0 , num_tmp_dir_entries = 0 ;
2012-03-28 06:03:00 +04:00
( de = readdir ( dp ) ) ;
2006-02-04 01:19:41 +03:00
num_dir_entries + + ) {
int r ;
const char * n = de - > d_name ;
/* Ignore . and .. */
if ( * n = = ' . ' ) {
if ( ( n [ 1 ] = = ' \0 ' ) | | ( n [ 1 ] = = ' . ' & & n [ 2 ] = = ' \0 ' ) ) {
continue ;
}
}
if ( n [ 0 ] = = ' : ' ) {
/* Temporary file used when creating a share. */
num_tmp_dir_entries + + ;
}
/* Allow 20% tmp entries. */
if ( num_tmp_dir_entries > allowed_tmp_entries ) {
DEBUG ( 0 , ( " load_usershare_shares: too many temp entries (%u) "
" in directory %s \n " ,
num_tmp_dir_entries , usersharepath ) ) ;
break ;
}
r = process_usershare_file ( usersharepath , n , snum_template ) ;
if ( r = = 0 ) {
/* Update the services count. */
num_usershares + + ;
if ( num_usershares > = max_user_shares ) {
DEBUG ( 0 , ( " load_usershare_shares: max user shares reached "
" on file %s in directory %s \n " ,
n , usersharepath ) ) ;
break ;
}
} else if ( r = = - 1 ) {
num_bad_dir_entries + + ;
}
/* Allow 20% bad entries. */
if ( num_bad_dir_entries > allowed_bad_entries ) {
DEBUG ( 0 , ( " load_usershare_shares: too many bad entries (%u) "
" in directory %s \n " ,
num_bad_dir_entries , usersharepath ) ) ;
break ;
}
/* Allow 20% bad entries. */
if ( num_dir_entries > max_user_shares + allowed_bad_entries ) {
DEBUG ( 0 , ( " load_usershare_shares: too many total entries (%u) "
" in directory %s \n " ,
num_dir_entries , usersharepath ) ) ;
break ;
}
}
2012-03-28 06:08:27 +04:00
closedir ( dp ) ;
2006-02-04 01:19:41 +03:00
/* Sweep through and delete any non-refreshed usershares that are
not currently in use . */
2012-07-18 09:37:23 +04:00
tmp_ctx = talloc_stackframe ( ) ;
2006-02-04 01:19:41 +03:00
for ( iService = iNumServices - 1 ; iService > = 0 ; iService - - ) {
if ( VALID ( iService ) & & ( ServicePtrs [ iService ] - > usershare = = USERSHARE_PENDING_DELETE ) ) {
2012-07-18 09:37:23 +04:00
char * servname ;
2011-12-13 14:50:04 +04:00
if ( snumused & & snumused ( sconn , iService ) ) {
2006-02-04 01:19:41 +03:00
continue ;
}
2012-07-18 09:37:23 +04:00
servname = lp_servicename ( tmp_ctx , iService ) ;
2006-02-04 01:19:41 +03:00
/* Remove from the share ACL db. */
DEBUG ( 10 , ( " load_usershare_shares: Removing deleted usershare %s \n " ,
2012-07-18 09:37:23 +04:00
servname ) ) ;
delete_share_security ( servname ) ;
2006-02-04 01:19:41 +03:00
free_service_byindex ( iService ) ;
}
}
2012-07-18 09:37:23 +04:00
talloc_free ( tmp_ctx ) ;
2006-02-04 01:19:41 +03:00
return lp_numservices ( ) ;
}
2006-04-08 21:25:31 +04:00
/********************************************************
Destroy global resources allocated in this file
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void gfree_loadparm ( void )
{
int i ;
2009-05-06 04:09:56 +04:00
free_file_list ( ) ;
2006-04-08 21:25:31 +04:00
/* Free resources allocated to services */
for ( i = 0 ; i < iNumServices ; i + + ) {
if ( VALID ( i ) ) {
free_service_byindex ( i ) ;
}
}
SAFE_FREE ( ServicePtrs ) ;
iNumServices = 0 ;
/* Now release all resources allocated to global
parameters and the default service */
2008-09-28 00:19:56 +04:00
free_global_parameters ( ) ;
2006-04-08 21:25:31 +04:00
}
2008-03-06 18:41:42 +03:00
/***************************************************************************
Allow client apps to specify that they are a client
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-07-26 14:53:52 +04:00
static void lp_set_in_client ( bool b )
2008-03-06 18:41:42 +03:00
{
in_client = b ;
}
/***************************************************************************
Determine if we ' re running in a client app
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-07-22 19:24:38 +04:00
static bool lp_is_in_client ( void )
2008-03-06 18:41:42 +03:00
{
return in_client ;
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2011-06-29 09:05:37 +04:00
Load the services array from the services file . Return true on success ,
2011-06-29 09:06:49 +04:00
false on failure .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2010-08-20 13:14:06 +04:00
static bool lp_load_ex ( const char * pszFname ,
bool global_only ,
bool save_defaults ,
bool add_ipc ,
bool initialize_globals ,
bool allow_include_registry ,
2011-07-21 16:05:24 +04:00
bool load_all_shares )
1996-05-04 11:50:46 +04:00
{
2007-11-14 05:42:42 +03:00
char * n2 = NULL ;
2007-10-19 04:40:25 +04:00
bool bRetval ;
2000-01-05 09:36:36 +03:00
2011-06-29 09:06:49 +04:00
bRetval = false ;
1996-05-04 11:50:46 +04:00
2008-04-18 12:20:01 +04:00
DEBUG ( 3 , ( " lp_load_ex: refreshing parameters \n " ) ) ;
2007-11-14 05:42:42 +03:00
2011-06-29 09:05:37 +04:00
bInGlobalSection = true ;
2000-05-29 03:34:34 +04:00
bGlobalOnly = global_only ;
2008-04-21 02:17:49 +04:00
bAllowIncludeRegistry = allow_include_registry ;
1998-03-14 11:27:41 +03:00
2010-08-20 11:51:48 +04:00
init_globals ( initialize_globals ) ;
1996-05-04 11:50:46 +04:00
2009-05-06 04:25:08 +04:00
free_file_list ( ) ;
2004-06-15 22:36:45 +04:00
if ( save_defaults ) {
2000-05-29 03:34:34 +04:00
init_locals ( ) ;
lp_save_defaults ( ) ;
}
1996-05-04 11:50:46 +04:00
2011-07-26 06:21:00 +04:00
if ( ! initialize_globals ) {
free_param_opts ( & Globals . param_opt ) ;
apply_lp_set_cmdline ( ) ;
}
2008-09-24 23:59:34 +04:00
2011-03-11 01:40:19 +03:00
lp_do_parameter ( - 1 , " idmap config * : backend " , Globals . szIdmapBackend ) ;
2008-05-26 13:58:11 +04:00
/* We get sections first, so have to start 'behind' to make up */
iServiceIndex = - 1 ;
2008-03-11 14:41:20 +03:00
if ( lp_config_backend_is_file ( ) ) {
2009-11-21 22:23:35 +03:00
n2 = talloc_sub_basic ( talloc_tos ( ) , get_current_username ( ) ,
2008-01-16 18:18:28 +03:00
current_user_info . domain ,
pszFname ) ;
if ( ! n2 ) {
2008-04-18 12:20:01 +04:00
smb_panic ( " lp_load_ex: out of memory " ) ;
2008-01-16 18:18:28 +03:00
}
1996-05-04 11:50:46 +04:00
2008-01-16 18:18:28 +03:00
add_to_file_list ( pszFname , n2 ) ;
2008-03-26 00:53:47 +03:00
bRetval = pm_process ( n2 , do_section , do_parameter , NULL ) ;
2009-11-21 22:23:35 +03:00
TALLOC_FREE ( n2 ) ;
2008-01-16 18:18:28 +03:00
/* finish up the last section */
DEBUG ( 4 , ( " pm_process() returned %s \n " , BOOLSTR ( bRetval ) ) ) ;
if ( bRetval ) {
if ( iServiceIndex > = 0 ) {
bRetval = service_ok ( iServiceIndex ) ;
}
2007-11-14 05:42:42 +03:00
}
2008-01-16 18:18:28 +03:00
2008-03-11 14:36:18 +03:00
if ( lp_config_backend_is_registry ( ) ) {
2008-03-12 02:43:19 +03:00
/* config backend changed to registry in config file */
2008-01-16 18:58:29 +03:00
/*
* We need to use this extra global variable here to
2008-03-12 02:42:06 +03:00
* survive restart : init_globals uses this as a default
2013-12-24 07:04:08 +04:00
* for config_backend . Otherwise , init_globals would
2008-01-16 18:58:29 +03:00
* send us into an endless loop here .
*/
2008-01-16 18:18:28 +03:00
config_backend = CONFIG_BACKEND_REGISTRY ;
/* start over */
2008-04-18 12:20:01 +04:00
DEBUG ( 1 , ( " lp_load_ex: changing to config backend "
2008-03-12 03:03:26 +03:00
" registry \n " ) ) ;
2010-08-20 11:51:48 +04:00
init_globals ( true ) ;
2008-03-12 02:56:33 +03:00
lp_kill_all_services ( ) ;
2008-04-18 12:20:01 +04:00
return lp_load_ex ( pszFname , global_only , save_defaults ,
2008-04-21 02:20:35 +04:00
add_ipc , initialize_globals ,
2008-05-15 04:25:34 +04:00
allow_include_registry ,
2011-07-21 16:05:24 +04:00
load_all_shares ) ;
2008-01-16 18:18:28 +03:00
}
2008-03-11 14:36:18 +03:00
} else if ( lp_config_backend_is_registry ( ) ) {
2008-04-13 23:57:55 +04:00
bRetval = process_registry_globals ( ) ;
2008-01-16 18:18:28 +03:00
} else {
DEBUG ( 0 , ( " Illegal config backend given: %d \n " ,
2008-01-16 18:58:29 +03:00
lp_config_backend ( ) ) ) ;
2008-01-16 18:18:28 +03:00
bRetval = false ;
2007-11-14 05:42:42 +03:00
}
1997-07-30 23:17:51 +04:00
2011-07-22 12:11:52 +04:00
if ( bRetval & & lp_registry_shares ( ) ) {
2011-07-21 16:05:24 +04:00
if ( load_all_shares ) {
2011-07-22 12:11:52 +04:00
bRetval = process_registry_shares ( ) ;
} else {
bRetval = reload_registry_shares ( ) ;
}
2008-05-15 04:25:34 +04:00
}
2012-06-01 02:06:58 +04:00
{
2012-07-18 09:37:23 +04:00
char * serv = lp_auto_services ( talloc_tos ( ) ) ;
2012-06-01 02:06:58 +04:00
lp_add_auto_services ( serv ) ;
TALLOC_FREE ( serv ) ;
}
2000-06-17 03:57:09 +04:00
2001-03-13 03:31:07 +03:00
if ( add_ipc ) {
2002-11-22 05:53:42 +03:00
/* When 'restrict anonymous = 2' guest connections to ipc$
are denied */
lp_add_ipc ( " IPC$ " , ( lp_restrict_anonymous ( ) < 2 ) ) ;
2007-11-14 05:42:42 +03:00
if ( lp_enable_asu_support ( ) ) {
lp_add_ipc ( " ADMIN$ " , false ) ;
}
2001-03-13 03:31:07 +03:00
}
1998-09-29 08:43:40 +04:00
2003-06-08 16:49:31 +04:00
set_allowed_client_auth ( ) ;
1998-09-29 08:43:40 +04:00
2011-05-23 04:42:57 +04:00
if ( lp_security ( ) = = SEC_ADS & & strchr ( lp_passwordserver ( ) , ' : ' ) ) {
DEBUG ( 1 , ( " WARNING: The optional ':port' in password server = %s is deprecated \n " ,
lp_passwordserver ( ) ) ) ;
}
2011-06-29 09:05:37 +04:00
bLoaded = true ;
1998-09-29 08:43:40 +04:00
2013-12-24 07:03:57 +04:00
/* Now we check we_are_a_wins_server and set szWINSserver to 127.0.0.1 */
/* if we_are_a_wins_server is true and we are in the client */
if ( lp_is_in_client ( ) & & Globals . we_are_a_wins_server ) {
2003-04-24 07:46:17 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " wins server " , " 127.0.0.1 " ) ;
2000-05-29 03:34:34 +04:00
}
2001-09-07 18:14:57 +04:00
init_iconv ( ) ;
2001-07-04 11:15:53 +04:00
2011-03-22 08:17:39 +03:00
fault_configure ( smb_panic_s3 ) ;
2012-11-16 03:30:44 +04:00
/*
* We run this check once the whole smb . conf is parsed , to
* force some settings for the standard way a AD DC is
* operated . We may changed these as our code evolves , which
* is why we force these settings .
*/
2012-08-22 17:34:24 +04:00
if ( lp_server_role ( ) = = ROLE_ACTIVE_DIRECTORY_DC ) {
2012-09-04 04:27:50 +04:00
lp_do_parameter ( - 1 , " passdb backend " , " samba_dsdb " ) ;
2012-11-01 04:26:16 +04:00
lp_do_parameter ( - 1 , " rpc_server:default " , " external " ) ;
lp_do_parameter ( - 1 , " rpc_server:svcctl " , " embedded " ) ;
lp_do_parameter ( - 1 , " rpc_server:srvsvc " , " embedded " ) ;
lp_do_parameter ( - 1 , " rpc_server:eventlog " , " embedded " ) ;
lp_do_parameter ( - 1 , " rpc_server:ntsvcs " , " embedded " ) ;
lp_do_parameter ( - 1 , " rpc_server:winreg " , " embedded " ) ;
lp_do_parameter ( - 1 , " rpc_server:spoolss " , " embedded " ) ;
lp_do_parameter ( - 1 , " rpc_daemon:spoolssd " , " embedded " ) ;
lp_do_parameter ( - 1 , " rpc_server:tcpip " , " no " ) ;
2012-08-22 17:34:24 +04:00
}
2008-04-21 02:17:49 +04:00
bAllowIncludeRegistry = true ;
2008-04-18 12:20:01 +04:00
2000-05-29 03:34:34 +04:00
return ( bRetval ) ;
1996-05-04 11:50:46 +04:00
}
2008-04-18 12:20:01 +04:00
bool lp_load ( const char * pszFname ,
bool global_only ,
bool save_defaults ,
bool add_ipc ,
bool initialize_globals )
{
return lp_load_ex ( pszFname ,
global_only ,
save_defaults ,
add_ipc ,
initialize_globals ,
2010-08-09 16:50:12 +04:00
true , /* allow_include_registry */
2011-07-21 16:05:24 +04:00
false ) ; /* load_all_shares*/
2008-04-18 12:20:01 +04:00
}
bool lp_load_initial_only ( const char * pszFname )
{
return lp_load_ex ( pszFname ,
2010-08-09 16:50:12 +04:00
true , /* global only */
false , /* save_defaults */
false , /* add_ipc */
true , /* initialize_globals */
false , /* allow_include_registry */
2011-07-21 16:05:24 +04:00
false ) ; /* load_all_shares*/
2011-07-22 19:16:02 +04:00
}
/**
* most common lp_load wrapper , loading only the globals
*/
bool lp_load_global ( const char * file_name )
{
return lp_load_ex ( file_name ,
true , /* global_only */
false , /* save_defaults */
false , /* add_ipc */
true , /* initialize_globals */
true , /* allow_include_registry */
false ) ; /* load_all_shares*/
2008-04-18 12:20:01 +04:00
}
2011-07-22 19:23:31 +04:00
/**
* lp_load wrapper , especially for clients
*/
bool lp_load_client ( const char * file_name )
{
lp_set_in_client ( true ) ;
2011-07-22 19:28:46 +04:00
return lp_load_global ( file_name ) ;
2011-07-22 19:23:31 +04:00
}
2011-07-26 14:42:29 +04:00
/**
* lp_load wrapper , loading only globals , but intended
* for subsequent calls , not reinitializing the globals
* to default values
*/
bool lp_load_global_no_reinit ( const char * file_name )
{
return lp_load_ex ( file_name ,
true , /* global_only */
false , /* save_defaults */
false , /* add_ipc */
false , /* initialize_globals */
true , /* allow_include_registry */
false ) ; /* load_all_shares*/
}
2011-07-26 14:44:44 +04:00
/**
* lp_load wrapper , especially for clients , no reinitialization
*/
bool lp_load_client_no_reinit ( const char * file_name )
{
lp_set_in_client ( true ) ;
return lp_load_global_no_reinit ( file_name ) ;
}
2008-05-15 04:39:45 +04:00
bool lp_load_with_registry_shares ( const char * pszFname ,
bool global_only ,
bool save_defaults ,
bool add_ipc ,
bool initialize_globals )
{
return lp_load_ex ( pszFname ,
global_only ,
save_defaults ,
add_ipc ,
initialize_globals ,
2010-08-09 16:50:12 +04:00
true , /* allow_include_registry */
2011-07-21 16:05:24 +04:00
true ) ; /* load_all_shares*/
2008-05-15 04:39:45 +04:00
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2002-11-13 02:20:50 +03:00
Return the max number of services .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
1996-05-04 11:50:46 +04:00
int lp_numservices ( void )
{
2000-05-29 03:34:34 +04:00
return ( iNumServices ) ;
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
Display the contents of the services array in human - readable form .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
void lp_dump ( FILE * f , bool show_defaults , int maxtoprint )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
int iService ;
1996-05-04 11:50:46 +04:00
2000-05-29 03:34:34 +04:00
if ( show_defaults )
2011-06-29 09:06:49 +04:00
defaults_saved = false ;
1998-03-17 14:44:16 +03:00
2001-07-04 11:15:53 +04:00
dump_globals ( f ) ;
1996-05-04 11:50:46 +04:00
2001-07-04 11:15:53 +04:00
dump_a_service ( & sDefault , f ) ;
2000-05-29 03:34:34 +04:00
2005-06-12 20:00:29 +04:00
for ( iService = 0 ; iService < maxtoprint ; iService + + ) {
fprintf ( f , " \n " ) ;
2001-07-04 11:15:53 +04:00
lp_dump_one ( f , show_defaults , iService ) ;
2005-06-12 20:00:29 +04:00
}
1999-12-13 16:27:58 +03:00
}
/***************************************************************************
Display the contents of one service in human - readable form .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2007-10-19 04:40:25 +04:00
void lp_dump_one ( FILE * f , bool show_defaults , int snum )
1999-12-13 16:27:58 +03:00
{
2002-11-13 02:20:50 +03:00
if ( VALID ( snum ) ) {
2001-05-11 02:10:31 +04:00
if ( ServicePtrs [ snum ] - > szService [ 0 ] = = ' \0 ' )
2000-05-29 03:34:34 +04:00
return ;
2001-07-04 11:15:53 +04:00
dump_a_service ( ServicePtrs [ snum ] , f ) ;
2000-05-29 03:34:34 +04:00
}
1996-05-04 11:50:46 +04:00
}
/***************************************************************************
Return the number of the service with the given name , or - 1 if it doesn ' t
exist . Note that this is a DIFFERENT ANIMAL from the internal function
getservicebyname ( ) ! This works ONLY if all services have been loaded , and
does not copy the found service .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2001-10-31 09:22:19 +03:00
int lp_servicenumber ( const char * pszServiceName )
1996-05-04 11:50:46 +04:00
{
2000-05-29 03:34:34 +04:00
int iService ;
2001-11-05 08:28:03 +03:00
fstring serviceName ;
2009-11-21 18:17:16 +03:00
2006-02-04 01:19:41 +03:00
if ( ! pszServiceName ) {
2003-04-24 07:46:17 +04:00
return GLOBAL_SECTION_SNUM ;
2006-02-04 01:19:41 +03:00
}
2009-11-21 18:17:16 +03:00
2002-11-13 02:20:50 +03:00
for ( iService = iNumServices - 1 ; iService > = 0 ; iService - - ) {
if ( VALID ( iService ) & & ServicePtrs [ iService ] - > szService ) {
2001-11-05 08:28:03 +03:00
/*
* The substitution here is used to support % U is
* service names
*/
fstrcpy ( serviceName , ServicePtrs [ iService ] - > szService ) ;
2006-07-11 22:01:26 +04:00
standard_sub_basic ( get_current_username ( ) ,
current_user_info . domain ,
serviceName , sizeof ( serviceName ) ) ;
2006-02-04 01:19:41 +03:00
if ( strequal ( serviceName , pszServiceName ) ) {
2001-11-05 08:28:03 +03:00
break ;
2006-02-04 01:19:41 +03:00
}
}
}
if ( iService > = 0 & & ServicePtrs [ iService ] - > usershare = = USERSHARE_VALID ) {
2009-05-14 17:34:42 +04:00
struct timespec last_mod ;
2006-02-04 01:19:41 +03:00
if ( ! usershare_exists ( iService , & last_mod ) ) {
/* Remove the share security tdb entry for it. */
2012-07-18 09:37:23 +04:00
delete_share_security ( lp_servicename ( talloc_tos ( ) , iService ) ) ;
2006-02-04 01:19:41 +03:00
/* Remove it from the array. */
free_service_byindex ( iService ) ;
/* Doesn't exist anymore. */
return GLOBAL_SECTION_SNUM ;
}
/* Has it been modified ? If so delete and reload. */
2009-05-14 17:34:42 +04:00
if ( timespec_compare ( & ServicePtrs [ iService ] - > usershare_last_mod ,
& last_mod ) < 0 ) {
2006-02-04 01:19:41 +03:00
/* Remove it from the array. */
free_service_byindex ( iService ) ;
/* and now reload it. */
iService = load_usershare_service ( pszServiceName ) ;
2001-11-05 08:28:03 +03:00
}
}
2003-04-24 07:46:17 +04:00
if ( iService < 0 ) {
2001-11-05 08:28:03 +03:00
DEBUG ( 7 , ( " lp_servicenumber: couldn't find %s \n " , pszServiceName ) ) ;
2003-04-24 07:46:17 +04:00
return GLOBAL_SECTION_SNUM ;
}
2000-05-29 03:34:34 +04:00
return ( iService ) ;
1996-05-04 11:50:46 +04:00
}
/*******************************************************************
2002-07-15 14:35:28 +04:00
A useful volume label function .
2001-06-29 03:21:43 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-07-18 09:37:23 +04:00
const char * volume_label ( TALLOC_CTX * ctx , int snum )
1996-05-04 11:50:46 +04:00
{
2007-04-16 23:10:16 +04:00
char * ret ;
2012-07-18 09:37:23 +04:00
const char * label = lp_volume ( ctx , snum ) ;
2007-04-16 23:10:16 +04:00
if ( ! * label ) {
2012-07-18 09:37:23 +04:00
label = lp_servicename ( ctx , snum ) ;
2007-04-16 23:10:16 +04:00
}
2009-11-21 18:17:16 +03:00
2007-04-16 23:10:16 +04:00
/* This returns a 33 byte guarenteed null terminated string. */
2012-07-18 09:37:23 +04:00
ret = talloc_strndup ( ctx , label , 32 ) ;
2007-04-16 23:10:16 +04:00
if ( ! ret ) {
return " " ;
}
return ret ;
1996-05-04 11:50:46 +04:00
}
1997-07-30 23:17:51 +04:00
/*******************************************************************
2011-07-07 08:10:54 +04:00
Get the default server type we will announce as via nmbd .
1997-07-30 23:17:51 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2011-07-07 08:10:54 +04:00
int lp_default_server_announce ( void )
1997-07-30 23:17:51 +04:00
{
2011-07-07 08:10:54 +04:00
int default_server_announce = 0 ;
2000-05-29 03:34:34 +04:00
default_server_announce | = SV_TYPE_WORKSTATION ;
default_server_announce | = SV_TYPE_SERVER ;
default_server_announce | = SV_TYPE_SERVER_UNIX ;
2004-01-31 21:25:57 +03:00
/* note that the flag should be set only if we have a
printer service but nmbd doesn ' t actually load the
services so we can ' t tell - - jerry */
default_server_announce | = SV_TYPE_PRINTQ_SERVER ;
2011-06-21 04:20:05 +04:00
default_server_announce | = SV_TYPE_SERVER_NT ;
default_server_announce | = SV_TYPE_NT ;
2000-05-29 03:34:34 +04:00
2002-11-13 02:20:50 +03:00
switch ( lp_server_role ( ) ) {
2000-05-29 03:34:34 +04:00
case ROLE_DOMAIN_MEMBER :
default_server_announce | = SV_TYPE_DOMAIN_MEMBER ;
break ;
case ROLE_DOMAIN_PDC :
default_server_announce | = SV_TYPE_DOMAIN_CTRL ;
break ;
case ROLE_DOMAIN_BDC :
default_server_announce | = SV_TYPE_DOMAIN_BAKCTRL ;
break ;
case ROLE_STANDALONE :
default :
break ;
}
if ( lp_time_server ( ) )
default_server_announce | = SV_TYPE_TIME_SOURCE ;
if ( lp_host_msdfs ( ) )
default_server_announce | = SV_TYPE_DFS_SERVER ;
2011-07-07 08:10:54 +04:00
return default_server_announce ;
2000-05-29 03:34:34 +04:00
}
/***********************************************************
If we are PDC then prefer us as DMB
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_domain_master ( void )
2000-05-29 03:34:34 +04:00
{
2014-01-10 02:21:46 +04:00
if ( Globals . _domain_master = = Auto )
2000-05-29 03:34:34 +04:00
return ( lp_server_role ( ) = = ROLE_DOMAIN_PDC ) ;
2014-01-10 02:21:46 +04:00
return ( bool ) Globals . _domain_master ;
1997-07-30 23:17:51 +04:00
}
2010-05-18 16:07:48 +04:00
/***********************************************************
If we are PDC then prefer us as DMB
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-11-10 05:45:54 +04:00
static bool lp_domain_master_true_or_auto ( void )
2010-05-18 16:07:48 +04:00
{
2014-01-10 02:21:46 +04:00
if ( Globals . _domain_master ) /* auto or yes */
2010-05-18 16:07:48 +04:00
return true ;
return false ;
}
2000-05-29 03:34:34 +04:00
/***********************************************************
If we are DMB then prefer us as LMB
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool lp_preferred_master ( void )
2000-05-29 03:34:34 +04:00
{
2007-10-19 04:40:25 +04:00
if ( Globals . iPreferredMaster = = Auto )
2000-05-29 03:34:34 +04:00
return ( lp_local_master ( ) & & lp_domain_master ( ) ) ;
2007-10-19 04:40:25 +04:00
return ( bool ) Globals . iPreferredMaster ;
2000-05-29 03:34:34 +04:00
}
1997-09-11 06:19:04 +04:00
/*******************************************************************
2002-11-13 02:20:50 +03:00
Remove a service .
1997-09-11 06:19:04 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
1997-09-11 06:19:04 +04:00
void lp_remove_service ( int snum )
{
2011-06-29 09:06:49 +04:00
ServicePtrs [ snum ] - > valid = false ;
1997-09-11 06:19:04 +04:00
}
/*******************************************************************
2002-11-13 02:20:50 +03:00
Copy a service .
1997-09-11 06:19:04 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
2003-01-03 11:28:12 +03:00
void lp_copy_service ( int snum , const char * new_name )
1997-09-11 06:19:04 +04:00
{
2008-03-26 00:53:47 +03:00
do_section ( new_name , NULL ) ;
2002-11-13 02:20:50 +03:00
if ( snum > = 0 ) {
1997-09-11 06:19:04 +04:00
snum = lp_servicenumber ( new_name ) ;
2012-07-18 09:37:23 +04:00
if ( snum > = 0 ) {
char * name = lp_servicename ( talloc_tos ( ) , snum ) ;
lp_do_parameter ( snum , " copy " , name ) ;
}
1997-09-11 06:19:04 +04:00
}
}
2012-07-18 09:37:23 +04:00
const char * lp_printername ( TALLOC_CTX * ctx , int snum )
2000-06-23 03:59:22 +04:00
{
2013-10-16 23:52:29 +04:00
const char * ret = lp__printername ( ctx , snum ) ;
2012-07-18 09:37:23 +04:00
if ( ret = = NULL | | * ret = = ' \0 ' ) {
2002-07-15 14:35:28 +04:00
ret = lp_const_servicename ( snum ) ;
2012-07-18 09:37:23 +04:00
}
2000-06-23 03:59:22 +04:00
return ret ;
}
2001-06-20 20:54:32 +04:00
2001-12-21 01:27:05 +03:00
/***********************************************************
Allow daemons such as winbindd to fix their logfile name .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-26 09:47:04 +03:00
2001-12-21 01:27:05 +03:00
void lp_set_logfile ( const char * name )
{
2012-04-12 10:51:54 +04:00
string_set ( & Globals . logfile , name ) ;
2007-11-16 01:19:52 +03:00
debug_set_logfile ( name ) ;
2001-12-21 01:27:05 +03:00
}
2002-01-08 03:46:56 +03:00
2002-10-05 02:53:18 +04:00
/*******************************************************************
Return the max print jobs per queue .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int lp_maxprintjobs ( int snum )
{
int maxjobs = LP_SNUM_OK ( snum ) ? ServicePtrs [ snum ] - > iMaxPrintJobs : sDefault . iMaxPrintJobs ;
if ( maxjobs < = 0 | | maxjobs > = PRINT_MAX_JOBID )
maxjobs = PRINT_MAX_JOBID - 1 ;
return maxjobs ;
}
2003-07-17 04:48:21 +04:00
2004-11-19 15:11:13 +03:00
const char * lp_printcapname ( void )
{
if ( ( Globals . szPrintcapname ! = NULL ) & &
( Globals . szPrintcapname [ 0 ] ! = ' \0 ' ) )
return Globals . szPrintcapname ;
2013-12-24 07:03:38 +04:00
if ( sDefault . printing = = PRINT_CUPS ) {
2004-11-19 15:11:13 +03:00
return " cups " ;
}
2013-12-24 07:03:38 +04:00
if ( sDefault . printing = = PRINT_BSD )
2004-11-19 15:11:13 +03:00
return " /etc/printcap " ;
return PRINTCAP_NAME ;
}
2005-06-15 19:18:18 +04:00
static uint32 spoolss_state ;
2007-10-19 04:40:25 +04:00
bool lp_disable_spoolss ( void )
2005-06-15 19:18:18 +04:00
{
if ( spoolss_state = = SVCCTL_STATE_UNKNOWN )
2012-04-12 11:03:38 +04:00
spoolss_state = lp__disable_spoolss ( ) ? SVCCTL_STOPPED : SVCCTL_RUNNING ;
2005-06-15 19:18:18 +04:00
2011-06-29 09:06:49 +04:00
return spoolss_state = = SVCCTL_STOPPED ? true : false ;
2005-06-15 19:18:18 +04:00
}
void lp_set_spoolss_state ( uint32 state )
{
SMB_ASSERT ( ( state = = SVCCTL_STOPPED ) | | ( state = = SVCCTL_RUNNING ) ) ;
spoolss_state = state ;
}
uint32 lp_get_spoolss_state ( void )
{
return lp_disable_spoolss ( ) ? SVCCTL_STOPPED : SVCCTL_RUNNING ;
}
/*******************************************************************
2008-01-04 23:56:23 +03:00
Ensure we don ' t use sendfile if server smb signing is active .
2005-06-15 19:18:18 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-17 04:48:21 +04:00
2009-11-23 18:33:45 +03:00
bool lp_use_sendfile ( int snum , struct smb_signing_state * signing_state )
2003-07-17 04:48:21 +04:00
{
2009-03-09 11:47:59 +03:00
bool sign_active = false ;
2004-08-17 01:27:26 +04:00
/* Using sendfile blows the brains out of any DOS or Win9x TCP stack... JRA. */
2009-11-23 18:33:45 +03:00
if ( get_Protocol ( ) < PROTOCOL_NT1 ) {
2009-03-09 11:47:59 +03:00
return false ;
}
if ( signing_state ) {
sign_active = smb_signing_is_active ( signing_state ) ;
2004-08-17 01:27:26 +04:00
}
2011-07-08 03:19:43 +04:00
return ( lp__use_sendfile ( snum ) & &
2007-12-27 04:12:36 +03:00
( get_remote_arch ( ) ! = RA_WIN95 ) & &
2009-03-09 11:47:59 +03:00
! sign_active ) ;
2003-07-17 04:48:21 +04:00
}
2004-06-02 00:43:32 +04:00
2004-08-06 21:49:00 +04:00
/*******************************************************************
Turn off sendfile if we find the underlying OS doesn ' t support it .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
void set_use_sendfile ( int snum , bool val )
2004-08-06 21:49:00 +04:00
{
if ( LP_SNUM_OK ( snum ) )
2013-12-24 07:03:36 +04:00
ServicePtrs [ snum ] - > _use_sendfile = val ;
2004-08-06 21:49:00 +04:00
else
2013-12-24 07:03:36 +04:00
sDefault . _use_sendfile = val ;
2004-08-06 21:49:00 +04:00
}
2004-06-02 00:43:32 +04:00
/*******************************************************************
Turn off storing DOS attributes if this share doesn ' t support it .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
void set_store_dos_attributes ( int snum , bool val )
2004-06-02 00:43:32 +04:00
{
if ( ! LP_SNUM_OK ( snum ) )
return ;
2013-12-24 07:03:30 +04:00
ServicePtrs [ ( snum ) ] - > store_dos_attributes = val ;
2004-06-02 00:43:32 +04:00
}
2005-06-23 01:20:41 +04:00
void lp_set_mangling_method ( const char * new_method )
{
2013-12-24 07:04:31 +04:00
string_set ( & Globals . mangling_method , new_method ) ;
2005-06-23 01:20:41 +04:00
}
/*******************************************************************
Global state for POSIX pathname processing .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool posix_pathnames ;
2005-06-23 01:20:41 +04:00
2007-10-19 04:40:25 +04:00
bool lp_posix_pathnames ( void )
2005-06-23 01:20:41 +04:00
{
return posix_pathnames ;
}
/*******************************************************************
Change everything needed to ensure POSIX pathname processing ( currently
not much ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void lp_set_posix_pathnames ( void )
{
2011-06-29 09:05:37 +04:00
posix_pathnames = true ;
2005-06-23 01:20:41 +04:00
}
2006-04-10 19:33:04 +04:00
/*******************************************************************
Global state for POSIX lock processing - CIFS unix extensions .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool posix_default_lock_was_set ;
2006-04-10 19:33:04 +04:00
static enum brl_flavour posix_cifsx_locktype ; /* By default 0 == WINDOWS_LOCK */
2007-02-07 00:05:34 +03:00
enum brl_flavour lp_posix_cifsu_locktype ( files_struct * fsp )
2006-04-10 19:33:04 +04:00
{
2007-02-07 00:05:34 +03:00
if ( posix_default_lock_was_set ) {
return posix_cifsx_locktype ;
} else {
return fsp - > posix_open ? POSIX_LOCK : WINDOWS_LOCK ;
}
2006-04-10 19:33:04 +04:00
}
/*******************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-02-07 00:05:34 +03:00
void lp_set_posix_default_cifsx_readwrite_locktype ( enum brl_flavour val )
2006-04-10 19:33:04 +04:00
{
2011-06-29 09:05:37 +04:00
posix_default_lock_was_set = true ;
2006-04-10 19:33:04 +04:00
posix_cifsx_locktype = val ;
}
2007-11-08 08:47:00 +03:00
int lp_min_receive_file_size ( void )
{
if ( Globals . iminreceivefile < 0 ) {
return 0 ;
}
return MIN ( Globals . iminreceivefile , BUFFER_SIZE ) ;
}
2008-12-06 00:37:51 +03:00
2010-02-12 00:12:29 +03:00
/*******************************************************************
Safe wide links checks .
This helper function always verify the validity of wide links ,
even after a configuration file reload .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-02-12 02:16:23 +03:00
static bool lp_widelinks_internal ( int snum )
{
return ( bool ) ( LP_SNUM_OK ( snum ) ? ServicePtrs [ ( snum ) ] - > bWidelinks :
sDefault . bWidelinks ) ;
}
void widelinks_warning ( int snum )
{
2011-09-14 03:42:09 +04:00
if ( lp_allow_insecure_widelinks ( ) ) {
return ;
}
2010-02-12 02:16:23 +03:00
if ( lp_unix_extensions ( ) & & lp_widelinks_internal ( snum ) ) {
DEBUG ( 0 , ( " Share '%s' has wide links and unix extensions enabled. "
" These parameters are incompatible. "
" Wide links will be disabled for this share. \n " ,
2012-07-18 09:37:23 +04:00
lp_servicename ( talloc_tos ( ) , snum ) ) ) ;
2010-02-12 02:16:23 +03:00
}
}
bool lp_widelinks ( int snum )
2010-02-12 00:12:29 +03:00
{
/* wide links is always incompatible with unix extensions */
if ( lp_unix_extensions ( ) ) {
2011-09-14 03:42:09 +04:00
/*
* Unless we have " allow insecure widelinks "
* turned on .
*/
if ( ! lp_allow_insecure_widelinks ( ) ) {
return false ;
}
2010-02-12 00:12:29 +03:00
}
2010-02-12 02:16:23 +03:00
return lp_widelinks_internal ( snum ) ;
2010-02-12 00:12:29 +03:00
}
2010-05-26 19:47:37 +04:00
bool lp_writeraw ( void )
{
if ( lp_async_smb_echo_handler ( ) ) {
return false ;
}
2012-04-12 11:03:38 +04:00
return lp__writeraw ( ) ;
2010-05-26 19:47:37 +04:00
}
bool lp_readraw ( void )
{
if ( lp_async_smb_echo_handler ( ) ) {
return false ;
}
2012-04-12 11:03:38 +04:00
return lp__readraw ( ) ;
2010-05-26 19:47:37 +04:00
}
2011-11-08 05:12:06 +04:00
2011-11-10 05:45:54 +04:00
int lp_server_role ( void )
2011-11-08 05:12:06 +04:00
{
2011-11-10 05:45:54 +04:00
return lp_find_server_role ( lp__server_role ( ) ,
2012-07-23 07:32:31 +04:00
lp__security ( ) ,
lp__domain_logons ( ) ,
2011-11-10 05:45:54 +04:00
lp_domain_master_true_or_auto ( ) ) ;
2011-11-08 05:12:06 +04:00
}
2012-07-23 07:32:31 +04:00
int lp_security ( void )
{
return lp_find_security ( lp__server_role ( ) ,
lp__security ( ) ) ;
}