2006-01-13 16:58:04 +00: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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2006-01-13 16:58:04 +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-01-13 16:58:04 +00:00
*/
/*
* Name : ldb
*
* Component : ldb winsdb module
*
* Description : verify winsdb records before they ' re written to disk
*
* Author : Stefan Metzmacher
*/
# include "includes.h"
2009-01-29 18:39:30 -05:00
# include "lib/events/events.h"
2006-01-13 16:58:04 +00:00
# include "nbt_server/nbt_server.h"
# include "nbt_server/wins/winsdb.h"
2009-01-30 16:31:19 -05:00
# include "lib/ldb/include/ldb_module.h"
2006-03-07 11:07:23 +00:00
# include "system/network.h"
2006-08-17 13:37:04 +00:00
# include "lib/socket/netif.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2006-01-13 16:58:04 +00:00
2006-05-29 01:30:02 +00:00
static int wins_ldb_verify ( struct ldb_module * module , struct ldb_request * req )
2006-01-13 16:58:04 +00:00
{
2009-01-30 16:31:19 -05:00
struct ldb_context * ldb = ldb_module_get_ctx ( module ) ;
struct winsdb_handle * h = talloc_get_type ( ldb_get_opaque ( ldb , " winsdb_handle " ) ,
2006-01-13 16:58:04 +00:00
struct winsdb_handle ) ;
2006-05-29 01:30:02 +00:00
const struct ldb_message * msg ;
2006-01-13 16:58:04 +00:00
2006-05-29 01:30:02 +00:00
switch ( req - > operation ) {
2006-05-30 00:33:52 +00:00
case LDB_ADD :
2006-05-29 01:30:02 +00:00
msg = req - > op . add . message ;
break ;
2006-05-30 00:33:52 +00:00
case LDB_MODIFY :
2006-05-29 01:30:02 +00:00
msg = req - > op . mod . message ;
break ;
default :
return ldb_next_request ( module , req ) ;
}
2006-03-15 21:23:17 +00:00
/* do not manipulate our control entries */
if ( ldb_dn_is_special ( msg - > dn ) ) {
return ldb_next_request ( module , req ) ;
}
2006-01-13 16:58:04 +00:00
if ( ! h ) {
2009-01-30 16:31:19 -05:00
ldb_debug_set ( ldb , LDB_DEBUG_FATAL , " %s " , " WINS_LDB: INTERNAL ERROR: no winsdb_handle present! " ) ;
2006-01-13 16:58:04 +00: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 :
2009-01-30 16:31:19 -05:00
ldb_debug ( ldb , LDB_DEBUG_WARNING , " %s \n " , " WINS_LDB: TODO verify add/modify for WINSDB_HANDLE_CALLER_ADMIN " ) ;
2006-01-13 16:58:04 +00:00
return ldb_next_request ( module , req ) ;
}
return LDB_ERR_OTHER ;
}
2009-01-30 16:31:19 -05:00
static int wins_ldb_init ( struct ldb_module * module )
2006-01-13 16:58:04 +00:00
{
2009-01-30 16:31:19 -05:00
struct ldb_context * ldb = ldb_module_get_ctx ( module ) ;
2006-01-13 16:58:04 +00:00
struct winsdb_handle * h ;
const char * owner ;
2009-01-30 16:31:19 -05:00
struct loadparm_context * lp_ctx = ldb_get_opaque ( ldb , " loadparm " ) ;
2006-01-13 16:58:04 +00:00
2009-01-30 16:31:19 -05:00
ldb_module_set_private ( module , NULL ) ;
2006-01-13 16:58:04 +00:00
2007-12-06 23:57:22 +01:00
owner = lp_parm_string ( lp_ctx , NULL , " winsdb " , " local_owner " ) ;
2006-01-13 16:58:04 +00:00
if ( ! owner ) {
2007-12-11 22:23:14 +01:00
struct interface * ifaces ;
2009-01-30 16:31:19 -05:00
load_interfaces ( module , lp_interfaces ( lp_ctx ) , & ifaces ) ;
2007-12-11 22:23:14 +01:00
owner = iface_n_ip ( ifaces , 0 ) ;
2006-01-13 16:58:04 +00:00
if ( ! owner ) {
owner = " 0.0.0.0 " ;
}
}
2009-01-30 16:31:19 -05:00
h = talloc_zero ( module , struct winsdb_handle ) ;
2006-01-13 16:58:04 +00:00
if ( ! h ) goto failed ;
2009-01-30 16:31:19 -05:00
h - > ldb = ldb ;
2006-01-13 16:58:04 +00:00
h - > caller = WINSDB_HANDLE_CALLER_ADMIN ;
h - > local_owner = talloc_strdup ( h , owner ) ;
if ( ! h - > local_owner ) goto failed ;
2009-01-30 16:31:19 -05:00
return ldb_set_opaque ( ldb , " winsdb_handle " , h ) ;
2006-01-13 16:58:04 +00:00
failed :
2006-03-02 16:32:53 +00:00
talloc_free ( h ) ;
return LDB_ERR_OTHER ;
}
2008-02-20 04:33:43 +01:00
_PUBLIC_ const struct ldb_module_ops ldb_wins_ldb_module_ops = {
2006-03-02 16:32:53 +00:00
. name = " wins_ldb " ,
2006-05-29 01:30:02 +00:00
. add = wins_ldb_verify ,
. modify = wins_ldb_verify ,
2006-03-02 16:32:53 +00:00
. init_context = wins_ldb_init
} ;