mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-30 13:30:57 +08:00
improve overlay helpers
This commit is contained in:
parent
0602be7c8e
commit
db4f223c66
@ -100,6 +100,8 @@ struct ldapinfo {
|
|||||||
ldap_pvt_thread_mutex_t conn_mutex;
|
ldap_pvt_thread_mutex_t conn_mutex;
|
||||||
int savecred;
|
int savecred;
|
||||||
Avlnode *conntree;
|
Avlnode *conntree;
|
||||||
|
|
||||||
|
int rwm_started;
|
||||||
};
|
};
|
||||||
|
|
||||||
int ldap_back_freeconn( Operation *op, struct ldapconn *lc );
|
int ldap_back_freeconn( Operation *op, struct ldapconn *lc );
|
||||||
|
@ -259,6 +259,37 @@ ldap_back_db_config(
|
|||||||
load_extop( (struct berval *)&slap_EXOP_WHOAMI,
|
load_extop( (struct berval *)&slap_EXOP_WHOAMI,
|
||||||
0, ldap_back_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 */
|
/* anything else */
|
||||||
} else {
|
} else {
|
||||||
return SLAP_CONF_UNKNOWN;
|
return SLAP_CONF_UNKNOWN;
|
||||||
|
@ -156,7 +156,7 @@ ldap_back_db_open( BackendDB *be )
|
|||||||
}
|
}
|
||||||
#endif /* LDAP_BACK_PROXY_AUTHZ */
|
#endif /* LDAP_BACK_PROXY_AUTHZ */
|
||||||
|
|
||||||
#ifdef SLAPD_MONITOR
|
#if 0 && defined(SLAPD_MONITOR)
|
||||||
{
|
{
|
||||||
struct berval filter,
|
struct berval filter,
|
||||||
base = BER_BVC( "cn=Databases,cn=Monitor" );
|
base = BER_BVC( "cn=Databases,cn=Monitor" );
|
||||||
|
@ -159,7 +159,7 @@ monitor_subsys_database_init(
|
|||||||
|
|
||||||
bi = be->bd_info;
|
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;
|
oi = (slap_overinfo *)be->bd_info->bi_private;
|
||||||
bi = oi->oi_orig;
|
bi = oi->oi_orig;
|
||||||
}
|
}
|
||||||
@ -228,6 +228,7 @@ monitor_subsys_database_init(
|
|||||||
attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
|
attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
|
||||||
&bv, NULL );
|
&bv, NULL );
|
||||||
|
|
||||||
|
/* find the overlay number, j */
|
||||||
for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), 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 ) {
|
if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
|
||||||
break;
|
break;
|
||||||
|
@ -114,20 +114,8 @@ monitor_subsys_overlay_init(
|
|||||||
BackendDB *be = &backendDB[ j ];
|
BackendDB *be = &backendDB[ j ];
|
||||||
char buf[ SLAP_LDAPDN_MAXLEN ];
|
char buf[ SLAP_LDAPDN_MAXLEN ];
|
||||||
struct berval dn;
|
struct berval dn;
|
||||||
slap_overinst *on2;
|
|
||||||
|
|
||||||
if ( strcmp( be->bd_info->bi_type, "over" ) != 0 ) {
|
if ( !overlay_is_inst( be, on->on_bi.bi_type ) ) {
|
||||||
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 ) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,6 +315,13 @@ overlay_register(
|
|||||||
return 0;
|
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 *
|
slap_overinst *
|
||||||
overlay_next(
|
overlay_next(
|
||||||
slap_overinst *on
|
slap_overinst *on
|
||||||
@ -327,8 +334,67 @@ overlay_next(
|
|||||||
return on->on_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";
|
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. */
|
/* add an overlay to a particular backend. */
|
||||||
int
|
int
|
||||||
overlay_config( BackendDB *be, const char *ov )
|
overlay_config( BackendDB *be, const char *ov )
|
||||||
@ -337,10 +403,7 @@ overlay_config( BackendDB *be, const char *ov )
|
|||||||
slap_overinfo *oi = NULL;
|
slap_overinfo *oi = NULL;
|
||||||
BackendInfo *bi = NULL;
|
BackendInfo *bi = NULL;
|
||||||
|
|
||||||
for ( on = overlays; on; on=on->on_next ) {
|
on = overlay_find( ov );
|
||||||
if (!strcmp( ov, on->on_bi.bi_type ) )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!on) {
|
if (!on) {
|
||||||
Debug( LDAP_DEBUG_ANY, "overlay %s not found\n", ov, 0, 0 );
|
Debug( LDAP_DEBUG_ANY, "overlay %s not found\n", ov, 0, 0 );
|
||||||
return 1;
|
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
|
/* If this is the first overlay on this backend, set up the
|
||||||
* overlay info structure
|
* overlay info structure
|
||||||
*/
|
*/
|
||||||
if ( be->bd_info->bi_type != overtype ) {
|
if ( !overlay_is_over( be ) ) {
|
||||||
oi = ch_malloc( sizeof(slap_overinfo) );
|
oi = ch_malloc( sizeof(slap_overinfo) );
|
||||||
oi->oi_orig = be->bd_info;
|
oi->oi_orig = be->bd_info;
|
||||||
oi->oi_bi = *be->bd_info;
|
oi->oi_bi = *be->bd_info;
|
||||||
|
@ -300,9 +300,12 @@ LDAP_SLAPD_F (int) glue_sub_init( void );
|
|||||||
* backover.c
|
* backover.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LDAP_SLAPD_F (int) overlay_register( slap_overinst *on );
|
LDAP_SLAPD_F (int) overlay_register LDAP_P(( slap_overinst *on ));
|
||||||
LDAP_SLAPD_F (int) overlay_config( BackendDB *be, const char *ov );
|
LDAP_SLAPD_F (int) overlay_config LDAP_P(( BackendDB *be, const char *ov ));
|
||||||
LDAP_SLAPD_F (slap_overinst *) overlay_next( slap_overinst *on );
|
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
|
* ch_malloc.c
|
||||||
|
Loading…
Reference in New Issue
Block a user