From db4f223c6636a79ceeac832b1ff3a3377a5f69f1 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 13 Nov 2004 17:20:24 +0000 Subject: [PATCH] improve overlay helpers --- servers/slapd/back-ldap/back-ldap.h | 6 ++- servers/slapd/back-ldap/config.c | 31 ++++++++++++ servers/slapd/back-ldap/init.c | 2 +- servers/slapd/back-monitor/database.c | 3 +- servers/slapd/back-monitor/overlay.c | 14 +---- servers/slapd/backover.c | 73 +++++++++++++++++++++++++-- servers/slapd/proto-slap.h | 9 ++-- 7 files changed, 113 insertions(+), 25 deletions(-) diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h index 60ffa0ac1c..01a466a5be 100644 --- a/servers/slapd/back-ldap/back-ldap.h +++ b/servers/slapd/back-ldap/back-ldap.h @@ -98,8 +98,10 @@ struct ldapinfo { #endif /* LDAP_BACK_PROXY_AUTHZ */ ldap_pvt_thread_mutex_t conn_mutex; - int savecred; - Avlnode *conntree; + int savecred; + Avlnode *conntree; + + int rwm_started; }; int ldap_back_freeconn( Operation *op, struct ldapconn *lc ); diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index 848464b7ac..810f23c268 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -258,6 +258,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 { diff --git a/servers/slapd/back-ldap/init.c b/servers/slapd/back-ldap/init.c index 26db3c83b7..240fdcd654 100644 --- a/servers/slapd/back-ldap/init.c +++ b/servers/slapd/back-ldap/init.c @@ -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" ); diff --git a/servers/slapd/back-monitor/database.c b/servers/slapd/back-monitor/database.c index 785305ca17..ed45ca301a 100644 --- a/servers/slapd/back-monitor/database.c +++ b/servers/slapd/back-monitor/database.c @@ -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; diff --git a/servers/slapd/back-monitor/overlay.c b/servers/slapd/back-monitor/overlay.c index 32bc0d9831..9eaa5876ec 100644 --- a/servers/slapd/back-monitor/overlay.c +++ b/servers/slapd/back-monitor/overlay.c @@ -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; } diff --git a/servers/slapd/backover.c b/servers/slapd/backover.c index 02f0ea32ec..7ce420f40d 100644 --- a/servers/slapd/backover.c +++ b/servers/slapd/backover.c @@ -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; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 82d0596b6a..8487be92e0 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 -- 2.39.5