2007-01-17 23:58:14 +00:00
/*
Unix SMB / CIFS mplementation .
The module that handles the PDC FSMO Role Owner checkings
Copyright ( C ) Stefan Metzmacher 2007
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
2007-01-17 23:58:14 +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/>.
2007-01-17 23:58:14 +00:00
*/
# include "includes.h"
2009-01-30 16:31:19 -05:00
# include "ldb_module.h"
2007-01-17 23:58:14 +00:00
# include "dsdb/samdb/samdb.h"
# include "librpc/gen_ndr/ndr_misc.h"
# include "librpc/gen_ndr/ndr_drsuapi.h"
# include "librpc/gen_ndr/ndr_drsblobs.h"
2008-10-11 21:31:42 +02:00
# include "../lib/util/dlinklist.h"
2009-10-10 09:06:07 +11:00
# include "dsdb/samdb/ldb_modules/util.h"
2007-01-17 23:58:14 +00:00
static int pdc_fsmo_init ( struct ldb_module * module )
{
2009-01-30 16:31:19 -05:00
struct ldb_context * ldb ;
2007-01-17 23:58:14 +00:00
TALLOC_CTX * mem_ctx ;
struct ldb_dn * pdc_dn ;
struct dsdb_pdc_fsmo * pdc_fsmo ;
struct ldb_result * pdc_res ;
int ret ;
2007-12-20 00:02:15 +01:00
static const char * pdc_attrs [ ] = {
2007-01-17 23:58:14 +00:00
" fSMORoleOwner " ,
NULL
} ;
2009-01-30 16:31:19 -05:00
ldb = ldb_module_get_ctx ( module ) ;
2007-01-17 23:58:14 +00:00
mem_ctx = talloc_new ( module ) ;
if ( ! mem_ctx ) {
2009-01-30 16:31:19 -05:00
ldb_oom ( ldb ) ;
2007-01-17 23:58:14 +00:00
return LDB_ERR_OPERATIONS_ERROR ;
}
2009-01-30 16:31:19 -05:00
pdc_dn = samdb_base_dn ( ldb ) ;
2007-01-17 23:58:14 +00:00
if ( ! pdc_dn ) {
2009-01-30 16:31:19 -05:00
ldb_debug ( ldb , LDB_DEBUG_WARNING ,
2007-12-18 02:21:24 +01:00
" pdc_fsmo_init: no domain dn present: (skip loading of domain details) \n " ) ;
2007-01-17 23:58:14 +00:00
talloc_free ( mem_ctx ) ;
return ldb_next_init ( module ) ;
}
pdc_fsmo = talloc_zero ( mem_ctx , struct dsdb_pdc_fsmo ) ;
if ( ! pdc_fsmo ) {
2009-01-30 16:31:19 -05:00
ldb_oom ( ldb ) ;
2007-01-17 23:58:14 +00:00
return LDB_ERR_OPERATIONS_ERROR ;
}
2009-01-30 16:31:19 -05:00
ldb_module_set_private ( module , pdc_fsmo ) ;
2007-01-17 23:58:14 +00:00
2009-10-10 09:06:07 +11:00
ret = dsdb_module_search_dn ( module , mem_ctx , & pdc_res ,
pdc_dn ,
2009-11-16 18:32:17 +11:00
pdc_attrs , 0 ) ;
2007-11-13 22:54:52 +01:00
if ( ret = = LDB_ERR_NO_SUCH_OBJECT ) {
2009-01-30 16:31:19 -05:00
ldb_debug ( ldb , LDB_DEBUG_WARNING ,
2007-12-18 02:21:24 +01:00
" pdc_fsmo_init: no domain object present: (skip loading of domain details) \n " ) ;
2007-11-13 22:54:52 +01:00
talloc_free ( mem_ctx ) ;
return ldb_next_init ( module ) ;
} else if ( ret ! = LDB_SUCCESS ) {
2009-01-30 16:31:19 -05:00
ldb_debug_set ( ldb , LDB_DEBUG_FATAL ,
2007-08-06 03:48:56 +00:00
" pdc_fsmo_init: failed to search the domain object: %d:%s " ,
2007-01-17 23:58:14 +00:00
ret , ldb_strerror ( ret ) ) ;
talloc_free ( mem_ctx ) ;
return ret ;
}
2009-01-30 16:31:19 -05:00
pdc_fsmo - > master_dn = ldb_msg_find_attr_as_dn ( ldb , mem_ctx , pdc_res - > msgs [ 0 ] , " fSMORoleOwner " ) ;
if ( ldb_dn_compare ( samdb_ntds_settings_dn ( ldb ) , pdc_fsmo - > master_dn ) = = 0 ) {
2007-01-17 23:58:14 +00:00
pdc_fsmo - > we_are_master = true ;
} else {
pdc_fsmo - > we_are_master = false ;
}
2009-01-30 16:31:19 -05:00
if ( ldb_set_opaque ( ldb , " dsdb_pdc_fsmo " , pdc_fsmo ) ! = LDB_SUCCESS ) {
ldb_oom ( ldb ) ;
2007-01-18 01:31:09 +00:00
return LDB_ERR_OPERATIONS_ERROR ;
}
talloc_steal ( module , pdc_fsmo ) ;
2009-01-30 16:31:19 -05:00
ldb_debug ( ldb , LDB_DEBUG_TRACE ,
2007-12-18 02:21:24 +01:00
" pdc_fsmo_init: we are master: %s \n " ,
2007-01-17 23:58:14 +00:00
( pdc_fsmo - > we_are_master ? " yes " : " no " ) ) ;
talloc_free ( mem_ctx ) ;
return ldb_next_init ( module ) ;
}
2008-02-20 04:33:43 +01:00
_PUBLIC_ const struct ldb_module_ops ldb_pdc_fsmo_module_ops = {
2007-01-17 23:58:14 +00:00
. name = " pdc_fsmo " ,
. init_context = pdc_fsmo_init
} ;