2006-07-23 22:47:56 +04:00
/*
Unix SMB / CIFS implementation .
2008-02-21 18:18:01 +03:00
LDB based shares configuration
2006-07-23 22:47:56 +04: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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-07-23 22:47:56 +04: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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-07-23 22:47:56 +04:00
*/
# include "includes.h"
2011-02-10 06:12:51 +03:00
# include <ldb.h>
# include <ldb_errors.h>
2006-07-23 22:47:56 +04:00
# include "auth/auth.h"
2007-11-16 22:12:00 +03:00
# include "ldb_wrap.h"
2006-07-23 22:47:56 +04:00
# include "param/share.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2006-07-23 22:47:56 +04:00
2020-08-07 23:27:39 +03:00
# undef strcasecmp
2017-04-20 22:24:43 +03:00
NTSTATUS share_ldb_init ( TALLOC_CTX * ) ;
2011-03-19 02:44:36 +03:00
2008-04-17 14:23:44 +04:00
static NTSTATUS sldb_init ( TALLOC_CTX * mem_ctx , const struct share_ops * ops ,
2008-12-29 22:24:57 +03:00
struct tevent_context * ev_ctx ,
2008-04-17 14:23:44 +04:00
struct loadparm_context * lp_ctx ,
2007-12-14 00:46:55 +03:00
struct share_context * * ctx )
2006-07-23 22:47:56 +04:00
{
struct ldb_context * sdb ;
* ctx = talloc ( mem_ctx , struct share_context ) ;
if ( ! * ctx ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
2010-07-16 08:32:42 +04:00
sdb = ldb_wrap_connect ( * ctx , ev_ctx , lp_ctx ,
2011-04-29 06:47:11 +04:00
lpcfg_private_path ( * ctx , lp_ctx , " share.ldb " ) ,
2009-10-23 07:19:28 +04:00
system_session ( lp_ctx ) ,
NULL , 0 ) ;
2006-07-23 22:47:56 +04:00
if ( ! sdb ) {
talloc_free ( * ctx ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
( * ctx ) - > ops = ops ;
( * ctx ) - > priv_data = ( void * ) sdb ;
return NT_STATUS_OK ;
}
2014-01-17 01:16:12 +04:00
static char * sldb_string_option ( TALLOC_CTX * mem_ctx , struct share_config * scfg , const char * opt_name , const char * defval )
2006-07-23 22:47:56 +04:00
{
struct ldb_message * msg ;
struct ldb_message_element * el ;
2013-12-16 00:28:08 +04:00
const char * colon ;
2006-07-23 22:47:56 +04:00
2014-01-17 01:16:12 +04:00
if ( scfg = = NULL ) return talloc_strdup ( mem_ctx , defval ) ;
2006-07-23 22:47:56 +04:00
msg = talloc_get_type ( scfg - > opaque , struct ldb_message ) ;
2013-12-16 00:28:08 +04:00
colon = strchr ( opt_name , ' : ' ) ;
if ( colon ! = NULL ) {
char * name ;
2006-07-23 22:47:56 +04:00
name = talloc_strdup ( scfg , opt_name ) ;
if ( ! name ) {
return NULL ;
}
2013-12-16 00:28:08 +04:00
name [ colon - opt_name ] = ' - ' ;
2006-07-23 22:47:56 +04:00
el = ldb_msg_find_element ( msg , name ) ;
2013-12-16 00:29:59 +04:00
TALLOC_FREE ( name ) ;
2006-07-23 22:47:56 +04:00
} else {
el = ldb_msg_find_element ( msg , opt_name ) ;
}
if ( el = = NULL ) {
2014-01-17 01:16:12 +04:00
return talloc_strdup ( mem_ctx , defval ) ;
2006-07-23 22:47:56 +04:00
}
2014-01-17 01:16:12 +04:00
return ( char * ) ( el - > values [ 0 ] . data ) ;
2006-07-23 22:47:56 +04:00
}
static int sldb_int_option ( struct share_config * scfg , const char * opt_name , int defval )
{
2014-01-17 01:16:12 +04:00
char * val ;
2006-07-23 22:47:56 +04:00
int ret ;
2014-01-17 01:16:12 +04:00
val = sldb_string_option ( scfg , scfg , opt_name , NULL ) ;
2006-07-23 22:47:56 +04:00
if ( val = = NULL ) return defval ;
errno = 0 ;
ret = ( int ) strtol ( val , NULL , 10 ) ;
2014-01-17 01:16:12 +04:00
TALLOC_FREE ( val ) ;
2006-07-23 22:47:56 +04:00
if ( errno ) return - 1 ;
return ret ;
}
2007-10-07 01:39:52 +04:00
static bool sldb_bool_option ( struct share_config * scfg , const char * opt_name , bool defval )
2006-07-23 22:47:56 +04:00
{
2014-01-17 01:16:12 +04:00
char * val ;
2006-07-23 22:47:56 +04:00
2014-01-17 01:16:12 +04:00
val = sldb_string_option ( scfg , scfg , opt_name , NULL ) ;
2006-07-23 22:47:56 +04:00
if ( val = = NULL ) return defval ;
2014-01-17 01:16:12 +04:00
if ( strcasecmp ( val , " true " ) = = 0 ) {
TALLOC_FREE ( val ) ;
return true ;
}
2006-07-23 22:47:56 +04:00
2014-01-17 01:16:12 +04:00
TALLOC_FREE ( val ) ;
2007-10-07 01:39:52 +04:00
return false ;
2006-07-23 22:47:56 +04:00
}
static const char * * sldb_string_list_option ( TALLOC_CTX * mem_ctx , struct share_config * scfg , const char * opt_name )
{
struct ldb_message * msg ;
struct ldb_message_element * el ;
const char * * list ;
2013-12-16 00:28:08 +04:00
const char * colon ;
2006-07-23 22:47:56 +04:00
int i ;
if ( scfg = = NULL ) return NULL ;
msg = talloc_get_type ( scfg - > opaque , struct ldb_message ) ;
2013-12-16 00:28:08 +04:00
colon = strchr ( opt_name , ' : ' ) ;
if ( colon ! = NULL ) {
char * name ;
2006-07-23 22:47:56 +04:00
name = talloc_strdup ( scfg , opt_name ) ;
if ( ! name ) {
return NULL ;
}
2013-12-16 00:28:08 +04:00
name [ colon - opt_name ] = ' - ' ;
2006-07-23 22:47:56 +04:00
el = ldb_msg_find_element ( msg , name ) ;
2013-12-16 00:28:08 +04:00
TALLOC_FREE ( name ) ;
2006-07-23 22:47:56 +04:00
} else {
el = ldb_msg_find_element ( msg , opt_name ) ;
}
if ( el = = NULL ) {
return NULL ;
}
list = talloc_array ( mem_ctx , const char * , el - > num_values + 1 ) ;
if ( ! list ) return NULL ;
for ( i = 0 ; i < el - > num_values ; i + + ) {
list [ i ] = ( const char * ) ( el - > values [ i ] . data ) ;
}
list [ i ] = NULL ;
return list ;
}
static NTSTATUS sldb_list_all ( TALLOC_CTX * mem_ctx ,
struct share_context * ctx ,
int * count ,
const char * * * names )
{
int ret , i , j ;
const char * * n ;
struct ldb_context * ldb ;
struct ldb_result * res ;
TALLOC_CTX * tmp_ctx ;
tmp_ctx = talloc_new ( mem_ctx ) ;
if ( ! tmp_ctx ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
ldb = talloc_get_type ( ctx - > priv_data , struct ldb_context ) ;
2008-09-23 22:30:06 +04:00
ret = ldb_search ( ldb , tmp_ctx , & res , ldb_dn_new ( tmp_ctx , ldb , " CN=SHARES " ) ,
LDB_SCOPE_SUBTREE , NULL , " (name=*) " ) ;
2006-07-23 22:47:56 +04:00
if ( ret ! = LDB_SUCCESS ) {
talloc_free ( tmp_ctx ) ;
2007-04-28 12:37:36 +04:00
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
2006-07-23 22:47:56 +04:00
}
n = talloc_array ( mem_ctx , const char * , res - > count ) ;
if ( ! n ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
talloc_free ( tmp_ctx ) ;
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 , j = 0 ; i < res - > count ; i + + ) {
2006-08-13 12:00:36 +04:00
n [ j ] = talloc_strdup ( n , ldb_msg_find_attr_as_string ( res - > msgs [ i ] , " name " , NULL ) ) ;
2006-07-23 22:47:56 +04:00
if ( ! n [ j ] ) {
DEBUG ( 0 , ( " WARNING: Malformed share object in share database \n ! " ) ) ;
continue ;
}
j + + ;
}
* names = n ;
* count = j ;
talloc_free ( tmp_ctx ) ;
return NT_STATUS_OK ;
}
static NTSTATUS sldb_get_config ( TALLOC_CTX * mem_ctx ,
struct share_context * ctx ,
const char * name ,
struct share_config * * scfg )
{
int ret ;
struct share_config * s ;
struct ldb_context * ldb ;
struct ldb_result * res ;
TALLOC_CTX * tmp_ctx ;
tmp_ctx = talloc_new ( mem_ctx ) ;
if ( ! tmp_ctx ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
ldb = talloc_get_type ( ctx - > priv_data , struct ldb_context ) ;
2008-09-23 22:30:06 +04:00
ret = ldb_search ( ldb , tmp_ctx , & res ,
2006-12-05 07:25:27 +03:00
ldb_dn_new ( tmp_ctx , ldb , " CN=SHARES " ) , LDB_SCOPE_SUBTREE , NULL ,
" (name=%s) " , name ) ;
2007-04-28 12:37:36 +04:00
if ( ret ! = LDB_SUCCESS | | res - > count > 1 ) {
2006-07-23 22:47:56 +04:00
talloc_free ( tmp_ctx ) ;
2007-04-28 12:37:36 +04:00
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
} else if ( res - > count ! = 1 ) {
talloc_free ( tmp_ctx ) ;
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2006-07-23 22:47:56 +04:00
}
s = talloc ( tmp_ctx , struct share_config ) ;
if ( ! s ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
talloc_free ( tmp_ctx ) ;
return NT_STATUS_NO_MEMORY ;
}
2006-08-13 12:00:36 +04:00
s - > name = talloc_strdup ( s , ldb_msg_find_attr_as_string ( res - > msgs [ 0 ] , " name " , NULL ) ) ;
2006-07-23 22:47:56 +04:00
if ( ! s - > name ) {
DEBUG ( 0 , ( " ERROR: Invalid share object! \n " ) ) ;
talloc_free ( tmp_ctx ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
s - > opaque = talloc_steal ( s , res - > msgs [ 0 ] ) ;
if ( ! s - > opaque ) {
DEBUG ( 0 , ( " ERROR: Invalid share object! \n " ) ) ;
talloc_free ( tmp_ctx ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
s - > ctx = ctx ;
* scfg = talloc_steal ( mem_ctx , s ) ;
talloc_free ( tmp_ctx ) ;
return NT_STATUS_OK ;
}
2006-09-17 04:15:13 +04:00
# define SHARE_ADD_STRING(name, value) do { \
err = ldb_msg_add_string ( msg , name , value ) ; \
2006-09-15 09:18:53 +04:00
if ( err ! = LDB_SUCCESS ) { \
2006-09-17 04:15:13 +04:00
DEBUG ( 2 , ( " ERROR: unable to add string share option %s to ldb msg \n " , name ) ) ; \
2006-09-15 09:18:53 +04:00
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} } while ( 0 )
2006-09-17 04:15:13 +04:00
# define SHARE_ADD_INT(name, value) do { \
err = ldb_msg_add_fmt ( msg , name , " %d " , value ) ; \
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add integer share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} } while ( 0 )
# define SHARE_ADD_BLOB(name, value) do { \
2006-10-25 05:42:59 +04:00
err = ldb_msg_add_value ( msg , name , value , NULL ) ; \
2006-09-17 04:15:13 +04:00
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add blob share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} } while ( 0 )
2008-10-20 20:59:51 +04:00
static NTSTATUS sldb_create ( struct share_context * ctx , const char * name , struct share_info * info , int count )
2006-09-15 09:18:53 +04:00
{
struct ldb_context * ldb ;
struct ldb_message * msg ;
TALLOC_CTX * tmp_ctx ;
NTSTATUS ret ;
2006-09-17 04:15:13 +04:00
int err , i , j ;
2007-04-18 17:28:04 +04:00
for ( i = 0 , j = 0 ; i < count & & j ! = 0x03 ; i + + ) {
2006-09-17 04:15:13 +04:00
if ( strcasecmp ( info [ i ] . name , SHARE_TYPE ) = = 0 ) j | = 0x02 ;
if ( strcasecmp ( info [ i ] . name , SHARE_PATH ) = = 0 ) j | = 0x01 ;
if ( strcasecmp ( info [ i ] . name , SHARE_NAME ) = = 0 ) {
if ( strcasecmp ( name , ( char * ) info [ i ] . value ) ! = 0 ) {
return NT_STATUS_INVALID_PARAMETER ;
}
}
}
if ( ! name | | j ! = 0x03 ) {
2006-09-15 09:18:53 +04:00
return NT_STATUS_INVALID_PARAMETER ;
}
tmp_ctx = talloc_new ( NULL ) ;
if ( ! tmp_ctx ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
ldb = talloc_get_type ( ctx - > priv_data , struct ldb_context ) ;
msg = ldb_msg_new ( tmp_ctx ) ;
if ( ! msg ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
ret = NT_STATUS_NO_MEMORY ;
goto done ;
}
/* TODO: escape info->name */
2006-11-22 03:59:34 +03:00
msg - > dn = ldb_dn_new_fmt ( tmp_ctx , ldb , " CN=%s,CN=SHARES " , name ) ;
2006-09-15 09:18:53 +04:00
if ( ! msg - > dn ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
ret = NT_STATUS_NO_MEMORY ;
goto done ;
}
SHARE_ADD_STRING ( " objectClass " , " top " ) ;
SHARE_ADD_STRING ( " objectClass " , " share " ) ;
2006-09-17 04:15:13 +04:00
SHARE_ADD_STRING ( " cn " , name ) ;
SHARE_ADD_STRING ( SHARE_NAME , name ) ;
for ( i = 0 ; i < count ; i + + ) {
if ( strcasecmp ( info [ i ] . name , SHARE_NAME ) = = 0 ) continue ;
switch ( info [ i ] . type ) {
case SHARE_INFO_STRING :
SHARE_ADD_STRING ( info [ i ] . name , ( char * ) info [ i ] . value ) ;
break ;
case SHARE_INFO_INT :
SHARE_ADD_INT ( info [ i ] . name , * ( ( int * ) info [ i ] . value ) ) ;
break ;
case SHARE_INFO_BLOB :
SHARE_ADD_BLOB ( info [ i ] . name , ( DATA_BLOB * ) info [ i ] . value ) ;
break ;
default :
DEBUG ( 2 , ( " ERROR: Invalid share info type for %s \n " , info [ i ] . name ) ) ;
ret = NT_STATUS_INVALID_PARAMETER ;
goto done ;
}
2006-09-15 09:18:53 +04:00
}
/* TODO: Security Descriptor */
2007-10-07 01:39:52 +04:00
SHARE_ADD_STRING ( SHARE_AVAILABLE , " true " ) ;
SHARE_ADD_STRING ( SHARE_BROWSEABLE , " true " ) ;
SHARE_ADD_STRING ( SHARE_READONLY , " false " ) ;
2006-09-17 07:00:05 +04:00
SHARE_ADD_STRING ( SHARE_NTVFS_HANDLER , " unixuid " ) ;
SHARE_ADD_STRING ( SHARE_NTVFS_HANDLER , " posix " ) ;
2006-09-15 09:18:53 +04:00
err = ldb_add ( ldb , msg ) ;
if ( err ! = LDB_SUCCESS ) {
DEBUG ( 2 , ( " ERROR: unable to add share %s to share.ldb \n "
2006-09-17 04:15:13 +04:00
" err=%d [%s] \n " , name , err , ldb_errstring ( ldb ) ) ) ;
if ( err = = LDB_ERR_NO_SUCH_OBJECT ) {
2007-04-28 12:37:36 +04:00
ret = NT_STATUS_OBJECT_NAME_NOT_FOUND ;
} else if ( err = = LDB_ERR_ENTRY_ALREADY_EXISTS ) {
ret = NT_STATUS_OBJECT_NAME_COLLISION ;
2006-09-17 04:15:13 +04:00
} else {
ret = NT_STATUS_UNSUCCESSFUL ;
}
goto done ;
}
ret = NT_STATUS_OK ;
done :
talloc_free ( tmp_ctx ) ;
return ret ;
}
# define SHARE_MOD_STRING(name, value) do { \
2006-10-25 05:42:59 +04:00
err = ldb_msg_add_empty ( msg , name , LDB_FLAG_MOD_REPLACE , NULL ) ; \
2006-09-17 04:15:13 +04:00
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add string share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} \
err = ldb_msg_add_string ( msg , name , value ) ; \
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add string share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} } while ( 0 )
# define SHARE_MOD_INT(name, value) do { \
2006-10-25 05:42:59 +04:00
err = ldb_msg_add_empty ( msg , name , LDB_FLAG_MOD_REPLACE , NULL ) ; \
2006-09-17 04:15:13 +04:00
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add string share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} \
err = ldb_msg_add_fmt ( msg , name , " %d " , value ) ; \
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add integer share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} } while ( 0 )
# define SHARE_MOD_BLOB(name, value) do { \
2006-10-25 05:42:59 +04:00
err = ldb_msg_add_empty ( msg , name , LDB_FLAG_MOD_REPLACE , NULL ) ; \
2006-09-17 04:15:13 +04:00
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add string share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} \
2006-10-25 05:42:59 +04:00
err = ldb_msg_add_value ( msg , name , value , NULL ) ; \
2006-09-17 04:15:13 +04:00
if ( err ! = LDB_SUCCESS ) { \
DEBUG ( 2 , ( " ERROR: unable to add blob share option %s to ldb msg \n " , name ) ) ; \
ret = NT_STATUS_UNSUCCESSFUL ; \
goto done ; \
} } while ( 0 )
2008-10-20 20:59:51 +04:00
static NTSTATUS sldb_set ( struct share_context * ctx , const char * name , struct share_info * info , int count )
2006-09-17 04:15:13 +04:00
{
struct ldb_context * ldb ;
struct ldb_message * msg ;
TALLOC_CTX * tmp_ctx ;
NTSTATUS ret ;
2007-10-07 01:39:52 +04:00
bool do_rename = false ;
2015-11-13 15:40:25 +03:00
char * newname = NULL ;
2006-09-17 04:15:13 +04:00
int err , i ;
if ( ! name ) {
return NT_STATUS_INVALID_PARAMETER ;
}
tmp_ctx = talloc_new ( NULL ) ;
if ( ! tmp_ctx ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
ldb = talloc_get_type ( ctx - > priv_data , struct ldb_context ) ;
msg = ldb_msg_new ( tmp_ctx ) ;
if ( ! msg ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
ret = NT_STATUS_NO_MEMORY ;
goto done ;
}
/* TODO: escape name */
2006-11-22 03:59:34 +03:00
msg - > dn = ldb_dn_new_fmt ( tmp_ctx , ldb , " CN=%s,CN=SHARES " , name ) ;
2006-09-17 04:15:13 +04:00
if ( ! msg - > dn ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
ret = NT_STATUS_NO_MEMORY ;
goto done ;
}
for ( i = 0 ; i < count ; i + + ) {
if ( strcasecmp ( info [ i ] . name , SHARE_NAME ) = = 0 ) {
if ( strcasecmp ( name , ( char * ) info [ i ] . value ) ! = 0 ) {
2007-10-07 01:39:52 +04:00
do_rename = true ;
2006-09-17 04:15:13 +04:00
newname = ( char * ) info [ i ] . value ;
SHARE_MOD_STRING ( " cn " , ( char * ) info [ i ] . value ) ;
}
}
switch ( info [ i ] . type ) {
case SHARE_INFO_STRING :
SHARE_MOD_STRING ( info [ i ] . name , ( char * ) info [ i ] . value ) ;
break ;
case SHARE_INFO_INT :
SHARE_MOD_INT ( info [ i ] . name , * ( ( int * ) info [ i ] . value ) ) ;
break ;
case SHARE_INFO_BLOB :
SHARE_MOD_BLOB ( info [ i ] . name , ( DATA_BLOB * ) info [ i ] . value ) ;
break ;
default :
DEBUG ( 2 , ( " ERROR: Invalid share info type for %s \n " , info [ i ] . name ) ) ;
ret = NT_STATUS_INVALID_PARAMETER ;
goto done ;
}
}
2006-09-17 07:00:05 +04:00
if ( do_rename ) {
2006-09-17 04:15:13 +04:00
struct ldb_dn * olddn , * newdn ;
olddn = msg - > dn ;
/* TODO: escape newname */
2006-11-22 03:59:34 +03:00
newdn = ldb_dn_new_fmt ( tmp_ctx , ldb , " CN=%s,CN=SHARES " , newname ) ;
2006-09-17 04:15:13 +04:00
if ( ! newdn ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
ret = NT_STATUS_NO_MEMORY ;
goto done ;
}
err = ldb_rename ( ldb , olddn , newdn ) ;
if ( err ! = LDB_SUCCESS ) {
DEBUG ( 2 , ( " ERROR: unable to rename share %s (to %s) \n "
" err=%d [%s] \n " , name , newname , err , ldb_errstring ( ldb ) ) ) ;
if ( err = = LDB_ERR_NO_SUCH_OBJECT ) {
2007-04-28 12:37:36 +04:00
ret = NT_STATUS_OBJECT_NAME_COLLISION ;
2006-09-17 04:15:13 +04:00
} else {
ret = NT_STATUS_UNSUCCESSFUL ;
}
goto done ;
}
msg - > dn = newdn ;
}
err = ldb_modify ( ldb , msg ) ;
if ( err ! = LDB_SUCCESS ) {
DEBUG ( 2 , ( " ERROR: unable to add share %s to share.ldb \n "
" err=%d [%s] \n " , name , err , ldb_errstring ( ldb ) ) ) ;
if ( err = = LDB_ERR_NO_SUCH_OBJECT ) {
2007-04-28 12:37:36 +04:00
ret = NT_STATUS_OBJECT_NAME_COLLISION ;
2006-09-17 04:15:13 +04:00
} else {
ret = NT_STATUS_UNSUCCESSFUL ;
}
2006-09-15 09:18:53 +04:00
goto done ;
}
ret = NT_STATUS_OK ;
done :
talloc_free ( tmp_ctx ) ;
return ret ;
}
2008-10-20 20:59:51 +04:00
static NTSTATUS sldb_remove ( struct share_context * ctx , const char * name )
2006-09-15 09:18:53 +04:00
{
struct ldb_context * ldb ;
struct ldb_dn * dn ;
TALLOC_CTX * tmp_ctx ;
NTSTATUS ret ;
int err ;
tmp_ctx = talloc_new ( NULL ) ;
if ( ! tmp_ctx ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
ldb = talloc_get_type ( ctx - > priv_data , struct ldb_context ) ;
2006-11-22 03:59:34 +03:00
dn = ldb_dn_new_fmt ( tmp_ctx , ldb , " CN=%s,CN=SHARES " , name ) ;
2006-09-15 09:18:53 +04:00
if ( ! dn ) {
DEBUG ( 0 , ( " ERROR: Out of memory! \n " ) ) ;
ret = NT_STATUS_NO_MEMORY ;
goto done ;
}
err = ldb_delete ( ldb , dn ) ;
if ( err ! = LDB_SUCCESS ) {
DEBUG ( 2 , ( " ERROR: unable to remove share %s from share.ldb \n "
" err=%d [%s] \n " , name , err , ldb_errstring ( ldb ) ) ) ;
ret = NT_STATUS_UNSUCCESSFUL ;
goto done ;
}
ret = NT_STATUS_OK ;
done :
talloc_free ( tmp_ctx ) ;
return ret ;
}
2007-10-01 22:52:55 +04:00
static const struct share_ops ops = {
. name = " ldb " ,
. init = sldb_init ,
. string_option = sldb_string_option ,
. int_option = sldb_int_option ,
. bool_option = sldb_bool_option ,
. string_list_option = sldb_string_list_option ,
. list_all = sldb_list_all ,
. get_config = sldb_get_config ,
. create = sldb_create ,
. set = sldb_set ,
. remove = sldb_remove
} ;
2017-04-20 22:24:43 +03:00
NTSTATUS share_ldb_init ( TALLOC_CTX * ctx )
2006-07-23 22:47:56 +04:00
{
return share_register ( & ops ) ;
}