improve overlay helpers

This commit is contained in:
Pierangelo Masarati 2004-11-13 17:20:24 +00:00
parent 0602be7c8e
commit db4f223c66
7 changed files with 113 additions and 25 deletions

View File

@ -100,6 +100,8 @@ struct ldapinfo {
ldap_pvt_thread_mutex_t conn_mutex;
int savecred;
Avlnode *conntree;
int rwm_started;
};
int ldap_back_freeconn( Operation *op, struct ldapconn *lc );

View File

@ -259,6 +259,37 @@ ldap_back_db_config(
load_extop( (struct berval *)&slap_EXOP_WHOAMI,
0, ldap_back_exop_whoami );
/* FIXME: legacy: intercept old rewrite/remap directives
* and try to start the rwm overlay */
} else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
|| strcasecmp( argv[0], "map" ) == 0
|| strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
{
if ( li->rwm_started == 0 && !overlay_is_inst( be, "rwm" ) ) {
if ( overlay_config( be, "rwm" ) ) {
fprintf( stderr, "%s: line %d: "
"unable to configure the \"rwm\" "
"overlay, required by directive "
"\"%s\".\n",
fname, lineno, argv[0] );
#if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
#endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
return( 1 );
}
fprintf( stderr, "%s: line %d: back-ldap: "
"automatically starting \"rwm\" overlay, "
"triggered by \"%s\" directive.\n",
fname, lineno, argv[ 0 ] );
li->rwm_started = 1;
return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
}
return SLAP_CONF_UNKNOWN;
/* anything else */
} else {
return SLAP_CONF_UNKNOWN;

View File

@ -156,7 +156,7 @@ ldap_back_db_open( BackendDB *be )
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
#ifdef SLAPD_MONITOR
#if 0 && defined(SLAPD_MONITOR)
{
struct berval filter,
base = BER_BVC( "cn=Databases,cn=Monitor" );

View File

@ -159,7 +159,7 @@ monitor_subsys_database_init(
bi = be->bd_info;
if ( strcmp( be->bd_info->bi_type, "over" ) == 0 ) {
if ( overlay_is_over( be ) ) {
oi = (slap_overinfo *)be->bd_info->bi_private;
bi = oi->oi_orig;
}
@ -228,6 +228,7 @@ monitor_subsys_database_init(
attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
&bv, NULL );
/* find the overlay number, j */
for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
break;

View File

@ -114,20 +114,8 @@ monitor_subsys_overlay_init(
BackendDB *be = &backendDB[ j ];
char buf[ SLAP_LDAPDN_MAXLEN ];
struct berval dn;
slap_overinst *on2;
if ( strcmp( be->bd_info->bi_type, "over" ) != 0 ) {
continue;
}
on2 = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
for ( ; on2; on2 = on2->on_next ) {
if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
break;
}
}
if ( on2 == NULL ) {
if ( !overlay_is_inst( be, on->on_bi.bi_type ) ) {
continue;
}

View File

@ -315,6 +315,13 @@ overlay_register(
return 0;
}
/*
* iterator on registered overlays; overlay_next( NULL ) returns the first
* overlay; * subsequent calls with the previously returned value allow to
* iterate * over the entire list; returns NULL when no more overlays are
* registered.
*/
slap_overinst *
overlay_next(
slap_overinst *on
@ -327,8 +334,67 @@ overlay_next(
return on->on_next;
}
/*
* returns a specific registered overlay based on the type; NULL if not
* registered.
*/
slap_overinst *
overlay_find( const char *over_type )
{
slap_overinst *on = overlays;
assert( over_type );
for ( ; on; on = on->on_next ) {
if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
break;
}
}
return on;
}
static const char overtype[] = "over";
/*
* returns TRUE (1) if the database is actually an overlay instance;
* FALSE (0) otherwise.
*/
int
overlay_is_over( BackendDB *be )
{
return be->bd_info->bi_type == overtype;
}
/*
* returns TRUE (1) if the given database is actually an overlay
* instance and, somewhere in the list, contains the requested overlay;
* FALSE (0) otherwise.
*/
int
overlay_is_inst( BackendDB *be, const char *over_type )
{
slap_overinst *on;
assert( be );
if ( !overlay_is_over( be ) ) {
return 0;
}
on = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
for ( ; on; on = on->on_next ) {
if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
return 1;
}
}
return 0;
}
/* add an overlay to a particular backend. */
int
overlay_config( BackendDB *be, const char *ov )
@ -337,10 +403,7 @@ overlay_config( BackendDB *be, const char *ov )
slap_overinfo *oi = NULL;
BackendInfo *bi = NULL;
for ( on = overlays; on; on=on->on_next ) {
if (!strcmp( ov, on->on_bi.bi_type ) )
break;
}
on = overlay_find( ov );
if (!on) {
Debug( LDAP_DEBUG_ANY, "overlay %s not found\n", ov, 0, 0 );
return 1;
@ -349,7 +412,7 @@ overlay_config( BackendDB *be, const char *ov )
/* If this is the first overlay on this backend, set up the
* overlay info structure
*/
if ( be->bd_info->bi_type != overtype ) {
if ( !overlay_is_over( be ) ) {
oi = ch_malloc( sizeof(slap_overinfo) );
oi->oi_orig = be->bd_info;
oi->oi_bi = *be->bd_info;

View File

@ -300,9 +300,12 @@ LDAP_SLAPD_F (int) glue_sub_init( void );
* backover.c
*/
LDAP_SLAPD_F (int) overlay_register( slap_overinst *on );
LDAP_SLAPD_F (int) overlay_config( BackendDB *be, const char *ov );
LDAP_SLAPD_F (slap_overinst *) overlay_next( slap_overinst *on );
LDAP_SLAPD_F (int) overlay_register LDAP_P(( slap_overinst *on ));
LDAP_SLAPD_F (int) overlay_config LDAP_P(( BackendDB *be, const char *ov ));
LDAP_SLAPD_F (slap_overinst *) overlay_next LDAP_P(( slap_overinst *on ));
LDAP_SLAPD_F (slap_overinst *) overlay_find LDAP_P(( const char *name ));
LDAP_SLAPD_F (int) overlay_is_over LDAP_P(( BackendDB *be ));
LDAP_SLAPD_F (int) overlay_is_inst LDAP_P(( BackendDB *be, const char *name ));
/*
* ch_malloc.c