X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-monitor%2Fdatabase.c;h=eb75a340f08eff109d0ec119c264fed33f0c14e2;hb=0121f8c01dcdef0827c8e6a1770d0a5ae3b0806e;hp=77fab28db813c514ec664ba70b43c8ea6be30b62;hpb=0e385af9759eced1c187a75aafe7ce48559dcf74;p=openldap diff --git a/servers/slapd/back-monitor/database.c b/servers/slapd/back-monitor/database.c index 77fab28db8..eb75a340f0 100644 --- a/servers/slapd/back-monitor/database.c +++ b/servers/slapd/back-monitor/database.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2001-2006 The OpenLDAP Foundation. + * Copyright 2001-2009 The OpenLDAP Foundation. * Portions Copyright 2001-2003 Pierangelo Masarati. * All rights reserved. * @@ -33,14 +33,6 @@ static int monitor_back_add_plugin( monitor_info_t *mi, Backend *be, Entry *e ); #endif /* defined(LDAP_SLAPI) */ -/* for PATH_MAX on some systems (e.g. Solaris) */ -#ifdef HAVE_LIMITS_H -#include -#endif /* HAVE_LIMITS_H */ -#ifndef PATH_MAX -#define PATH_MAX 4095 -#endif /* ! PATH_MAX */ - static int monitor_subsys_database_modify( Operation *op, @@ -74,7 +66,7 @@ init_readOnly( monitor_info_t *mi, Entry *e, slap_mask_t restrictops ) struct berval *tf = ( ( restrictops & SLAP_RESTRICT_OP_MASK ) == SLAP_RESTRICT_OP_WRITES ) ? (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv; - return attr_merge_one( e, mi->mi_ad_readOnly, tf, tf ); + return attr_merge_one( e, mi->mi_ad_readOnly, tf, NULL ); } static int @@ -107,18 +99,372 @@ init_restrictedOperation( monitor_info_t *mi, Entry *e, slap_mask_t restrictops return LDAP_SUCCESS; } +static int +monitor_subsys_database_init_one( + monitor_info_t *mi, + BackendDB *be, + monitor_subsys_t *ms, + monitor_subsys_t *ms_backend, + monitor_subsys_t *ms_overlay, + struct berval *rdn, + Entry *e_database, + Entry ***epp ) +{ + char buf[ BACKMONITOR_BUFSIZE ]; + int j; + slap_overinfo *oi = NULL; + BackendInfo *bi, *bi2; + Entry *e; + monitor_entry_t *mp; + char *rdnval = strchr( rdn->bv_val, '=' ) + 1; + struct berval bv; + + bi = be->bd_info; + + if ( overlay_is_over( be ) ) { + oi = (slap_overinfo *)be->bd_info->bi_private; + bi = oi->oi_orig; + } + + /* Subordinates are not exposed as their own naming context */ + if ( SLAP_GLUE_SUBORDINATE( be ) ) { + return 0; + } + + e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, rdn, + mi->mi_oc_monitoredObject, mi, NULL, NULL ); + + if ( e == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_database_init: " + "unable to create entry \"%s,%s\"\n", + rdn->bv_val, ms->mss_dn.bv_val, 0 ); + return( -1 ); + } + + ber_str2bv( bi->bi_type, 0, 0, &bv ); + attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); + attr_merge_one( e, mi->mi_ad_monitorIsShadow, + SLAP_SHADOW( be ) ? (struct berval *)&slap_true_bv : + (struct berval *)&slap_false_bv, NULL ); + + if ( SLAP_MONITOR( be ) ) { + attr_merge( e, slap_schema.si_ad_monitorContext, + be->be_suffix, be->be_nsuffix ); + attr_merge( e_database, slap_schema.si_ad_monitorContext, + be->be_suffix, be->be_nsuffix ); + + } else { + if ( be->be_suffix == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_database_init: " + "missing suffix for %s\n", + rdnval, 0, 0 ); + } else { + attr_merge( e, slap_schema.si_ad_namingContexts, + be->be_suffix, NULL ); + attr_merge( e_database, slap_schema.si_ad_namingContexts, + be->be_suffix, NULL ); + } + } + + (void)init_readOnly( mi, e, be->be_restrictops ); + (void)init_restrictedOperation( mi, e, be->be_restrictops ); + + if ( SLAP_SHADOW( be ) && be->be_update_refs ) { + attr_merge_normalize( e, mi->mi_ad_monitorUpdateRef, + be->be_update_refs, NULL ); + } + + if ( oi != NULL ) { + slap_overinst *on = oi->oi_list, + *on1 = on; + + for ( ; on; on = on->on_next ) { + slap_overinst *on2; + + for ( on2 = on1; on2 != on; on2 = on2->on_next ) { + if ( on2->on_bi.bi_type == on->on_bi.bi_type ) { + break; + } + } + + if ( on2 != on ) { + break; + } + + ber_str2bv( on->on_bi.bi_type, 0, 0, &bv ); + 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; + } + } + assert( on2 != NULL ); + + snprintf( buf, sizeof( buf ), + "cn=Overlay %d,%s", + j, ms_overlay->mss_dn.bv_val ); + ber_str2bv( buf, 0, 0, &bv ); + attr_merge_normalize_one( e, + slap_schema.si_ad_seeAlso, + &bv, NULL ); + } + } + + j = -1; + LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) { + j++; + if ( bi2->bi_type == bi->bi_type ) { + snprintf( buf, sizeof( buf ), + "cn=Backend %d,%s", + j, ms_backend->mss_dn.bv_val ); + bv.bv_val = buf; + bv.bv_len = strlen( buf ); + attr_merge_normalize_one( e, + slap_schema.si_ad_seeAlso, + &bv, NULL ); + break; + } + } + /* we must find it! */ + assert( j >= 0 ); + + mp = monitor_entrypriv_create(); + if ( mp == NULL ) { + return -1; + } + e->e_private = ( void * )mp; + mp->mp_info = ms; + mp->mp_flags = ms->mss_flags + | MONITOR_F_SUB; + + if ( monitor_cache_add( mi, e ) ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_database_init: " + "unable to add entry \"%s,%s\"\n", + rdn->bv_val, ms->mss_dn.bv_val, 0 ); + return( -1 ); + } + +#if defined(LDAP_SLAPI) + monitor_back_add_plugin( mi, be, e ); +#endif /* defined(LDAP_SLAPI) */ + + if ( oi != NULL ) { + Entry **ep_overlay = &mp->mp_children; + monitor_entry_t *mp_overlay; + slap_overinst *on = oi->oi_list; + int o; + + for ( o = 0; on; o++, on = on->on_next ) { + Entry *e_overlay; + slap_overinst *on2; + + /* 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; + } + } + assert( on2 != NULL ); + + bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o ); + bv.bv_val = buf; + + e_overlay = monitor_entry_stub( &e->e_name, &e->e_nname, &bv, + mi->mi_oc_monitoredObject, mi, NULL, NULL ); + + if ( e_overlay == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_database_init: " + "unable to create entry " + "\"cn=Overlay %d,%s,%s\"\n", + o, rdn->bv_val, ms->mss_dn.bv_val ); + return( -1 ); + } + ber_str2bv( on->on_bi.bi_type, 0, 0, &bv ); + attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo, &bv, NULL ); + + bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d,%s", + j, ms_overlay->mss_dn.bv_val ); + bv.bv_val = buf; + attr_merge_normalize_one( e_overlay, slap_schema.si_ad_seeAlso, + &bv, NULL ); + + if ( SLAP_MONITOR( be ) ) { + attr_merge( e_overlay, slap_schema.si_ad_monitorContext, + be->be_suffix, be->be_nsuffix ); + + } else { + attr_merge( e_overlay, slap_schema.si_ad_namingContexts, + be->be_suffix, NULL ); + } + + mp_overlay = monitor_entrypriv_create(); + if ( mp_overlay == NULL ) { + return -1; + } + e_overlay->e_private = ( void * )mp_overlay; + mp_overlay->mp_info = ms; + mp_overlay->mp_flags = ms->mss_flags + | MONITOR_F_SUB; + + if ( monitor_cache_add( mi, e_overlay ) ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_database_init: " + "unable to add entry " + "\"cn=Overlay %d,%s,%s\"\n", + o, rdn->bv_val, ms->mss_dn.bv_val ); + return( -1 ); + } + + *ep_overlay = e_overlay; + ep_overlay = &mp_overlay->mp_next; + } + } + + **epp = e; + *epp = &mp->mp_next; + + return 0; +} + +int +monitor_back_register_database( + BackendDB *be, + struct berval *ndn ) +{ + monitor_info_t *mi; + Entry *e_database, **ep; + int i, rc; + monitor_entry_t *mp; + monitor_subsys_t *ms_backend, + *ms_database, + *ms_overlay; + struct berval bv; + char buf[ BACKMONITOR_BUFSIZE ]; + + assert( be_monitor != NULL ); + + if ( !monitor_subsys_is_opened() ) { + return monitor_back_register_database_limbo( be, ndn ); + } + + mi = ( monitor_info_t * )be_monitor->be_private; + + ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME ); + if ( ms_backend == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_back_register_database: " + "unable to get " + "\"" SLAPD_MONITOR_BACKEND_NAME "\" " + "subsystem\n", + 0, 0, 0 ); + return -1; + } + + ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME ); + if ( ms_database == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_back_register_database: " + "unable to get " + "\"" SLAPD_MONITOR_DATABASE_NAME "\" " + "subsystem\n", + 0, 0, 0 ); + return -1; + } + + ms_overlay = monitor_back_get_subsys( SLAPD_MONITOR_OVERLAY_NAME ); + if ( ms_overlay == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_back_register_database: " + "unable to get " + "\"" SLAPD_MONITOR_OVERLAY_NAME "\" " + "subsystem\n", + 0, 0, 0 ); + return -1; + } + + if ( monitor_cache_get( mi, &ms_database->mss_ndn, &e_database ) ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_database_init: " + "unable to get entry \"%s\"\n", + ms_database->mss_ndn.bv_val, 0, 0 ); + return( -1 ); + } + + mp = ( monitor_entry_t * )e_database->e_private; + for ( i = -1, ep = &mp->mp_children; *ep; i++ ) { + Attribute *a; + + a = attr_find( (*ep)->e_attrs, slap_schema.si_ad_namingContexts ); + if ( a ) { + int j, k; + + /* FIXME: RFC 4512 defines namingContexts without an + * equality matching rule, making comparisons + * like this one tricky. We use a_vals and + * be_suffix instead for now. + */ + for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); j++ ) { + for ( k = 0; !BER_BVISNULL( &be->be_suffix[ k ] ); k++ ) { + if ( dn_match( &a->a_vals[ j ], + &be->be_suffix[ k ] ) ) { + rc = 0; + goto done; + } + } + } + } + + mp = ( monitor_entry_t * )(*ep)->e_private; + + assert( mp != NULL ); + ep = &mp->mp_next; + } + + bv.bv_val = buf; + bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Database %d", i ); + if ( bv.bv_len >= sizeof( buf ) ) { + rc = -1; + goto done; + } + + rc = monitor_subsys_database_init_one( mi, be, + ms_database, ms_backend, ms_overlay, &bv, e_database, &ep ); + if ( rc != 0 ) { + goto done; + } + /* database_init_one advanced ep past where we want. + * But it stored the entry we want in mp->mp_next. + */ + ep = &mp->mp_next; + +done:; + monitor_cache_release( mi, e_database ); + if ( rc == 0 && ndn && ep && *ep ) { + *ndn = (*ep)->e_nname; + } + + return rc; +} + int monitor_subsys_database_init( BackendDB *be, - monitor_subsys_t *ms -) + monitor_subsys_t *ms ) { monitor_info_t *mi; Entry *e_database, **ep; - int i; + int i, rc; monitor_entry_t *mp; monitor_subsys_t *ms_backend, *ms_overlay; + struct berval bv; assert( be != NULL ); @@ -163,224 +509,28 @@ monitor_subsys_database_init( mp->mp_children = NULL; ep = &mp->mp_children; + BER_BVSTR( &bv, "cn=Frontend" ); + rc = monitor_subsys_database_init_one( mi, frontendDB, + ms, ms_backend, ms_overlay, &bv, e_database, &ep ); + if ( rc != 0 ) { + return rc; + } + i = -1; LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { char buf[ BACKMONITOR_BUFSIZE ]; - int j; - slap_overinfo *oi = NULL; - BackendInfo *bi, *bi2; - Entry *e; - struct berval bv; - - i++; - - bi = be->bd_info; - - if ( overlay_is_over( be ) ) { - oi = (slap_overinfo *)be->bd_info->bi_private; - bi = oi->oi_orig; - } - - /* Subordinates are not exposed as their own naming context */ - if ( SLAP_GLUE_SUBORDINATE( be ) ) { - continue; - } - bv.bv_len = snprintf( buf, sizeof( buf ), - "cn=Database %d", i ); bv.bv_val = buf; - e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv, - mi->mi_oc_monitoredObject, mi, NULL, NULL ); - - if ( e == NULL ) { - Debug( LDAP_DEBUG_ANY, - "monitor_subsys_database_init: " - "unable to create entry \"cn=Database %d,%s\"\n", - i, ms->mss_dn.bv_val, 0 ); - return( -1 ); - } - - ber_str2bv( bi->bi_type, 0, 0, &bv ); - attr_merge_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); - attr_merge_one( e, mi->mi_ad_monitorIsShadow, - SLAP_SHADOW( be ) ? (struct berval *)&slap_true_bv : - (struct berval *)&slap_false_bv, NULL ); - - if ( SLAP_MONITOR( be ) ) { - attr_merge( e, slap_schema.si_ad_monitorContext, - be->be_suffix, be->be_nsuffix ); - attr_merge( e_database, slap_schema.si_ad_monitorContext, - be->be_suffix, be->be_nsuffix ); - - } else { - if ( be->be_suffix == NULL ) { - Debug( LDAP_DEBUG_ANY, - "monitor_subsys_database_init: " - "missing suffix for database %d\n", - i, 0, 0 ); - return -1; - } - attr_merge( e, slap_schema.si_ad_namingContexts, - be->be_suffix, be->be_nsuffix ); - attr_merge( e_database, slap_schema.si_ad_namingContexts, - be->be_suffix, be->be_nsuffix ); - } - - (void)init_readOnly( mi, e, be->be_restrictops ); - (void)init_restrictedOperation( mi, e, be->be_restrictops ); - - if ( SLAP_SHADOW( be ) && be->be_update_refs ) { - attr_merge_normalize( e, mi->mi_ad_monitorUpdateRef, - be->be_update_refs, NULL ); - } - - if ( oi != NULL ) { - slap_overinst *on = oi->oi_list, - *on1 = on; - - for ( ; on; on = on->on_next ) { - struct berval bv; - slap_overinst *on2; - - for ( on2 = on1; on2 != on; on2 = on2->on_next ) { - if ( on2->on_bi.bi_type == on->on_bi.bi_type ) { - break; - } - } - - if ( on2 != on ) { - break; - } - - ber_str2bv( on->on_bi.bi_type, 0, 0, &bv ); - 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; - } - } - assert( on2 != NULL ); - - snprintf( buf, sizeof( buf ), - "cn=Overlay %d,%s", - j, ms_overlay->mss_dn.bv_val ); - ber_str2bv( buf, 0, 0, &bv ); - attr_merge_normalize_one( e, - slap_schema.si_ad_seeAlso, - &bv, NULL ); - } - } - - j = -1; - LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) { - j++; - if ( bi2->bi_type == bi->bi_type ) { - struct berval bv; - - snprintf( buf, sizeof( buf ), - "cn=Backend %d,%s", - j, ms_backend->mss_dn.bv_val ); - bv.bv_val = buf; - bv.bv_len = strlen( buf ); - attr_merge_normalize_one( e, - slap_schema.si_ad_seeAlso, - &bv, NULL ); - break; - } - } - /* we must find it! */ - assert( j >= 0 ); - - mp = monitor_entrypriv_create(); - if ( mp == NULL ) { + bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Database %d", ++i ); + if ( bv.bv_len >= sizeof( buf ) ) { return -1; } - e->e_private = ( void * )mp; - mp->mp_info = ms; - mp->mp_flags = ms->mss_flags - | MONITOR_F_SUB; - - if ( monitor_cache_add( mi, e ) ) { - Debug( LDAP_DEBUG_ANY, - "monitor_subsys_database_init: " - "unable to add entry \"cn=Database %d,%s\"\n", - i, ms->mss_dn.bv_val, 0 ); - return( -1 ); - } - -#if defined(LDAP_SLAPI) - monitor_back_add_plugin( mi, be, e ); -#endif /* defined(LDAP_SLAPI) */ - - if ( oi != NULL ) { - Entry **ep_overlay = &mp->mp_children; - monitor_entry_t *mp_overlay; - slap_overinst *on = oi->oi_list; - int o; - - for ( o = 0; on; o++, on = on->on_next ) { - Entry *e_overlay; - slap_overinst *on2; - - /* 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; - } - } - assert( on2 != NULL ); - - bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o ); - bv.bv_val = buf; - - e_overlay = monitor_entry_stub( &e->e_name, &e->e_nname, &bv, - mi->mi_oc_monitoredObject, mi, NULL, NULL ); - - if ( e_overlay == NULL ) { - Debug( LDAP_DEBUG_ANY, - "monitor_subsys_database_init: " - "unable to create entry " - "\"cn=Overlay %d,cn=Database %d,%s\"\n", - o, i, ms->mss_dn.bv_val ); - return( -1 ); - } - ber_str2bv( on->on_bi.bi_type, 0, 0, &bv ); - attr_merge_one( e_overlay, mi->mi_ad_monitoredInfo, &bv, NULL ); - - bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d,%s", - j, ms_overlay->mss_dn.bv_val ); - bv.bv_val = buf; - attr_merge_normalize_one( e_overlay, slap_schema.si_ad_seeAlso, - &bv, NULL ); - - mp_overlay = monitor_entrypriv_create(); - if ( mp_overlay == NULL ) { - return -1; - } - e_overlay->e_private = ( void * )mp_overlay; - mp_overlay->mp_info = ms; - mp_overlay->mp_flags = ms->mss_flags - | MONITOR_F_SUB; - if ( monitor_cache_add( mi, e_overlay ) ) { - Debug( LDAP_DEBUG_ANY, - "monitor_subsys_database_init: " - "unable to add entry " - "\"cn=Overlay %d,cn=Database %d,%s\"\n", - o, i, ms->mss_dn.bv_val ); - return( -1 ); - } - - *ep_overlay = e_overlay; - ep_overlay = &mp_overlay->mp_next; - } + rc = monitor_subsys_database_init_one( mi, be, + ms, ms_backend, ms_overlay, &bv, e_database, &ep ); + if ( rc != 0 ) { + return rc; } - - *ep = e; - ep = &mp->mp_next; } monitor_cache_release( mi, e_database ); @@ -683,6 +833,7 @@ monitor_subsys_database_modify( BER_BVZERO( &a->a_vals[ k - 1 ] ); BER_BVZERO( &a->a_nvals[ k - 1 ] ); + a->a_numvals--; } } } @@ -708,9 +859,16 @@ monitor_subsys_database_modify( BER_BVZERO( &a->a_vals[ k - 1 ] ); BER_BVZERO( &a->a_nvals[ k - 1 ] ); + a->a_numvals--; } } } + + if ( a->a_vals == NULL ) { + assert( a->a_numvals == 0 ); + + attr_delete( &e->e_attrs, mi->mi_ad_restrictedOperation ); + } } } @@ -774,17 +932,21 @@ monitor_back_add_plugin( monitor_info_t *mi, Backend *be, Entry *e_database ) if ( rc != LDAP_SUCCESS ) { goto done; } - - snprintf( buf, sizeof(buf), - "plugin %d name: %s; " - "vendor: %s; " - "version: %s; " - "description: %s", - i, - srchdesc->spd_id, - srchdesc->spd_vendor, - srchdesc->spd_version, - srchdesc->spd_description ); + if ( srchdesc ) { + snprintf( buf, sizeof(buf), + "plugin %d name: %s; " + "vendor: %s; " + "version: %s; " + "description: %s", + i, + srchdesc->spd_id, + srchdesc->spd_vendor, + srchdesc->spd_version, + srchdesc->spd_description ); + } else { + snprintf( buf, sizeof(buf), + "plugin %d name: ", i ); + } ber_str2bv( buf, 0, 0, &bv ); attr_merge_normalize_one( e_database,