2006-07-23 18:43:07 +00:00
/*
Unix SMB / CIFS implementation .
2008-02-21 16:18:01 +01:00
Modular shares configuration system
2006-07-23 18:43:07 +00:00
Copyright ( C ) Simo Sorce 2006
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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2006-07-23 18:43:07 +00:00
( at your option ) any later version .
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 .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-07-23 18:43:07 +00:00
*/
# include "includes.h"
# include "param/share.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2011-12-03 07:03:35 +01:00
# include "lib/util/samba_modules.h"
2006-07-23 18:43:07 +00:00
2014-01-17 10:16:12 +13:00
char * share_string_option ( TALLOC_CTX * mem_ctx , struct share_config * scfg , const char * opt_name , const char * defval )
2006-07-23 18:43:07 +00:00
{
2014-01-17 10:16:12 +13:00
return scfg - > ctx - > ops - > string_option ( mem_ctx , scfg , opt_name , defval ) ;
2006-07-23 18:43:07 +00:00
}
int share_int_option ( struct share_config * scfg , const char * opt_name , int defval )
{
return scfg - > ctx - > ops - > int_option ( scfg , opt_name , defval ) ;
}
2007-10-06 21:39:52 +00:00
bool share_bool_option ( struct share_config * scfg , const char * opt_name , bool defval )
2006-07-23 18:43:07 +00:00
{
return scfg - > ctx - > ops - > bool_option ( scfg , opt_name , defval ) ;
}
const char * * share_string_list_option ( TALLOC_CTX * mem_ctx , struct share_config * scfg , const char * opt_name )
{
return scfg - > ctx - > ops - > string_list_option ( mem_ctx , scfg , opt_name ) ;
}
NTSTATUS share_list_all ( TALLOC_CTX * mem_ctx , struct share_context * sctx , int * count , const char * * * names )
{
return sctx - > ops - > list_all ( mem_ctx , sctx , count , names ) ;
}
NTSTATUS share_get_config ( TALLOC_CTX * mem_ctx , struct share_context * sctx , const char * name , struct share_config * * scfg )
{
return sctx - > ops - > get_config ( mem_ctx , sctx , name , scfg ) ;
}
2006-09-17 00:15:13 +00:00
NTSTATUS share_create ( struct share_context * sctx , const char * name , struct share_info * info , int count )
2006-09-15 05:18:53 +00:00
{
if ( sctx - > ops - > create ) {
2006-09-17 00:15:13 +00:00
return sctx - > ops - > create ( sctx , name , info , count ) ;
}
return NT_STATUS_NOT_IMPLEMENTED ;
}
NTSTATUS share_set ( struct share_context * sctx , const char * name , struct share_info * info , int count )
{
if ( sctx - > ops - > set ) {
return sctx - > ops - > set ( sctx , name , info , count ) ;
2006-09-15 05:18:53 +00:00
}
return NT_STATUS_NOT_IMPLEMENTED ;
}
NTSTATUS share_remove ( struct share_context * sctx , const char * name )
{
if ( sctx - > ops - > remove ) {
return sctx - > ops - > remove ( sctx , name ) ;
}
return NT_STATUS_NOT_IMPLEMENTED ;
}
2006-07-23 18:43:07 +00:00
/* List of currently available share backends */
static struct share_ops * * backends = NULL ;
static const struct share_ops * share_backend_by_name ( const char * name )
{
int i ;
for ( i = 0 ; backends & & backends [ i ] ; i + + ) {
if ( strcmp ( backends [ i ] - > name , name ) = = 0 ) {
return backends [ i ] ;
}
}
return NULL ;
}
/*
Register the share backend
*/
NTSTATUS share_register ( const struct share_ops * ops )
{
int i ;
if ( share_backend_by_name ( ops - > name ) ! = NULL ) {
DEBUG ( 0 , ( " SHARE backend [%s] already registered \n " , ops - > name ) ) ;
return NT_STATUS_OBJECT_NAME_COLLISION ;
}
i = 0 ;
while ( backends & & backends [ i ] ) {
i + + ;
}
backends = realloc_p ( backends , struct share_ops * , i + 2 ) ;
if ( ! backends ) {
smb_panic ( " out of memory in share_register " ) ;
}
2007-09-09 19:34:30 +00:00
backends [ i ] = ( struct share_ops * ) smb_xmemdup ( ops , sizeof ( * ops ) ) ;
2006-07-23 18:43:07 +00:00
backends [ i ] - > name = smb_xstrdup ( ops - > name ) ;
backends [ i + 1 ] = NULL ;
DEBUG ( 3 , ( " SHARE backend [%s] registered. \n " , ops - > name ) ) ;
return NT_STATUS_OK ;
}
2007-12-10 18:41:55 +01:00
NTSTATUS share_get_context_by_name ( TALLOC_CTX * mem_ctx , const char * backend_name ,
2008-12-29 20:24:57 +01:00
struct tevent_context * event_ctx ,
2007-12-13 22:46:55 +01:00
struct loadparm_context * lp_ctx ,
2007-12-10 18:41:55 +01:00
struct share_context * * ctx )
2006-07-23 18:43:07 +00:00
{
const struct share_ops * ops ;
2007-04-18 01:17:30 +00:00
ops = share_backend_by_name ( backend_name ) ;
2006-07-23 18:43:07 +00:00
if ( ! ops ) {
2007-12-03 15:53:17 +01:00
DEBUG ( 0 , ( " share_init_connection: share backend [%s] not found! \n " , backend_name ) ) ;
2006-07-23 18:43:07 +00:00
return NT_STATUS_INTERNAL_ERROR ;
}
2008-04-17 12:23:44 +02:00
return ops - > init ( mem_ctx , ops , event_ctx , lp_ctx , ctx ) ;
2006-07-23 18:43:07 +00:00
}
/*
initialise the SHARE subsystem
*/
2007-12-10 04:33:16 +01:00
NTSTATUS share_init ( void )
2006-07-23 18:43:07 +00:00
{
2017-04-20 12:24:43 -07:00
# define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *);
2010-11-01 15:38:37 +11:00
STATIC_share_MODULES_PROTO ;
2011-12-03 07:03:35 +01:00
init_module_fn static_init [ ] = { STATIC_share_MODULES } ;
2006-07-23 18:43:07 +00:00
2017-04-20 12:24:43 -07:00
run_init_functions ( NULL , static_init ) ;
2006-07-23 18:43:07 +00:00
return NT_STATUS_OK ;
}