2006-01-13 19:58:04 +03:00
/*
ldb database module
Copyright ( C ) Stefan Metzmacher 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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
/*
* Name : ldb
*
* Component : ldb winsdb module
*
* Description : verify winsdb records before they ' re written to disk
*
* Author : Stefan Metzmacher
*/
# include "includes.h"
# include "nbt_server/nbt_server.h"
# include "nbt_server/wins/winsdb.h"
# include "lib/ldb/include/ldb.h"
# include "lib/ldb/include/ldb_errors.h"
# include "lib/ldb/include/ldb_private.h"
2006-03-07 14:07:23 +03:00
# include "system/network.h"
# include "netif/netif.h"
2006-01-13 19:58:04 +03:00
/* add_record: do things with the sambaPassword attribute */
static int wins_ldb_verify ( struct ldb_module * module , struct ldb_request * req , const struct ldb_message * msg )
{
struct winsdb_handle * h = talloc_get_type ( ldb_get_opaque ( module - > ldb , " winsdb_handle " ) ,
struct winsdb_handle ) ;
char * error = NULL ;
2006-03-16 00:23:17 +03:00
/* do not manipulate our control entries */
if ( ldb_dn_is_special ( msg - > dn ) ) {
return ldb_next_request ( module , req ) ;
}
2006-01-13 19:58:04 +03:00
if ( ! h ) {
error = talloc_strdup ( module , " WINS_LDB: INTERNAL ERROR: no winsdb_handle present! " ) ;
ldb_debug ( module - > ldb , LDB_DEBUG_FATAL , " %s " , error ) ;
2006-02-22 08:21:43 +03:00
ldb_set_errstring ( module - > ldb , error ) ;
2006-01-13 19:58:04 +03:00
return LDB_ERR_OTHER ;
}
switch ( h - > caller ) {
case WINSDB_HANDLE_CALLER_NBTD :
case WINSDB_HANDLE_CALLER_WREPL :
/* we trust our nbt and wrepl code ... */
return ldb_next_request ( module , req ) ;
case WINSDB_HANDLE_CALLER_ADMIN :
error = talloc_strdup ( module , " WINS_LDB: TODO verify add/modify for WINSDB_HANDLE_CALLER_ADMIN " ) ;
ldb_debug ( module - > ldb , LDB_DEBUG_WARNING , " %s \n " , error ) ;
return ldb_next_request ( module , req ) ;
}
return LDB_ERR_OTHER ;
}
static int wins_ldb_request ( struct ldb_module * module , struct ldb_request * req )
{
2006-03-16 00:23:17 +03:00
const struct ldb_message * msg ;
2006-01-13 19:58:04 +03:00
switch ( req - > operation ) {
case LDB_REQ_ADD :
2006-03-16 00:23:17 +03:00
case LDB_ASYNC_ADD :
2006-01-13 19:58:04 +03:00
msg = req - > op . add . message ;
break ;
2006-03-16 00:23:17 +03:00
2006-01-13 19:58:04 +03:00
case LDB_REQ_MODIFY :
2006-03-16 00:23:17 +03:00
case LDB_ASYNC_MODIFY :
2006-01-13 19:58:04 +03:00
msg = req - > op . mod . message ;
break ;
default :
2006-03-16 00:23:17 +03:00
return ldb_next_request ( module , req ) ;
2006-01-13 19:58:04 +03:00
}
return wins_ldb_verify ( module , req , msg ) ;
}
2006-03-16 00:23:17 +03:00
2006-01-13 19:58:04 +03:00
2006-03-02 19:32:53 +03:00
static int wins_ldb_init ( struct ldb_module * ctx )
2006-01-13 19:58:04 +03:00
{
struct winsdb_handle * h ;
const char * owner ;
ctx - > private_data = NULL ;
owner = lp_parm_string ( - 1 , " winsdb " , " local_owner " ) ;
if ( ! owner ) {
owner = iface_n_ip ( 0 ) ;
if ( ! owner ) {
owner = " 0.0.0.0 " ;
}
}
h = talloc ( ctx , struct winsdb_handle ) ;
if ( ! h ) goto failed ;
2006-03-02 19:32:53 +03:00
h - > ldb = ctx - > ldb ;
2006-01-13 19:58:04 +03:00
h - > caller = WINSDB_HANDLE_CALLER_ADMIN ;
h - > local_owner = talloc_strdup ( h , owner ) ;
if ( ! h - > local_owner ) goto failed ;
2006-03-02 19:32:53 +03:00
return ldb_set_opaque ( ctx - > ldb , " winsdb_handle " , h ) ;
2006-01-13 19:58:04 +03:00
failed :
2006-03-02 19:32:53 +03:00
talloc_free ( h ) ;
return LDB_ERR_OTHER ;
}
static const struct ldb_module_ops wins_ldb_ops = {
. name = " wins_ldb " ,
. request = wins_ldb_request ,
. init_context = wins_ldb_init
} ;
/* the init function */
int wins_ldb_module_init ( void )
{
return ldb_register_module ( & wins_ldb_ops ) ;
2006-01-13 19:58:04 +03:00
}