📄 init.c
字号:
return 0;}intmonitor_back_db_init( BackendDB *be ){ int rc; struct berval dn = BER_BVC( SLAPD_MONITOR_DN ), pdn, ndn; BackendDB *be2; monitor_subsys_t *ms; /* * register subsys */ for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) { if ( monitor_back_register_subsys( ms ) ) { return -1; } } /* * database monitor can be defined once only */ if ( be_monitor != NULL ) { Debug( LDAP_DEBUG_ANY, "only one monitor database is allowed\n", 0, 0, 0 ); return( -1 ); } be_monitor = be; /* indicate system schema supported */ SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR; rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL ); if( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "unable to normalize/pretty monitor DN \"%s\" (%d)\n", dn.bv_val, rc, 0 ); return -1; } ber_bvarray_add( &be->be_suffix, &pdn ); ber_bvarray_add( &be->be_nsuffix, &ndn ); /* NOTE: only one monitor database is allowed, * so we use static storage */ ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex ); be->be_private = &monitor_info; be2 = select_backend( &ndn, 0, 0 ); if ( be2 != be ) { char *type = be2->bd_info->bi_type; if ( overlay_is_over( be2 ) ) { slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private; type = oi->oi_orig->bi_type; } Debug( LDAP_DEBUG_ANY, "\"monitor\" database serving namingContext \"%s\" " "is hidden by \"%s\" database serving namingContext \"%s\".\n", pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val ); return -1; } return 0;}intmonitor_back_db_open( BackendDB *be ){ monitor_info_t *mi = (monitor_info_t *)be->be_private; struct monitor_subsys_t **ms; Entry *e, **ep; monitor_entry_t *mp; int i; char buf[ BACKMONITOR_BUFSIZE ]; struct berval bv; struct tm *tms;#ifdef HAVE_GMTIME_R struct tm tm_buf;#endif static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ]; assert( be_monitor != NULL ); if ( be != be_monitor ) { be_monitor = be; } /* * Start */#ifndef HAVE_GMTIME_R ldap_pvt_thread_mutex_lock( &gmtime_mutex );#endif#ifdef HACK_LOCAL_TIME# ifdef HAVE_LOCALTIME_R tms = localtime_r( &starttime, &tm_buf );# else tms = localtime( &starttime );# endif /* HAVE_LOCALTIME_R */ lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );#else /* !HACK_LOCAL_TIME */# ifdef HAVE_GMTIME_R tms = gmtime_r( &starttime, &tm_buf );# else tms = gmtime( &starttime );# endif /* HAVE_GMTIME_R */ lutil_gentime( tmbuf, sizeof(tmbuf), tms );#endif /* !HACK_LOCAL_TIME */#ifndef HAVE_GMTIME_R ldap_pvt_thread_mutex_unlock( &gmtime_mutex );#endif mi->mi_startTime.bv_val = tmbuf; mi->mi_startTime.bv_len = strlen( tmbuf ); if ( BER_BVISEMPTY( &be->be_rootdn ) ) { BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS ); } else { mi->mi_creatorsName = be->be_rootdn; } /* * creates the "cn=Monitor" entry */ snprintf( buf, sizeof( buf ), "dn: %s\n" "objectClass: %s\n" "structuralObjectClass: %s\n" "cn: Monitor\n" "description: This subtree contains monitoring/managing objects.\n" "description: This object contains information about this server.\n" "description: Most of the information is held in operational" " attributes, which must be explicitly requested.\n" "creatorsName: %s\n" "modifiersName: %s\n" "createTimestamp: %s\n" "modifyTimestamp: %s\n", SLAPD_MONITOR_DN, mi->mi_oc_monitorServer->soc_cname.bv_val, mi->mi_oc_monitorServer->soc_cname.bv_val, mi->mi_creatorsName.bv_val, mi->mi_creatorsName.bv_val, mi->mi_startTime.bv_val, mi->mi_startTime.bv_val ); e = str2entry( buf ); if ( e == NULL) { Debug( LDAP_DEBUG_ANY, "unable to create \"%s\" entry\n", SLAPD_MONITOR_DN, 0, 0 ); return( -1 ); } bv.bv_val = strchr( (char *) Versionstr, '$' ); if ( bv.bv_val != NULL ) { char *end; bv.bv_val++; for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ ) ; end = strchr( bv.bv_val, '$' ); if ( end != NULL ) { end--; for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- ) ; end++; bv.bv_len = end - bv.bv_val; } else { bv.bv_len = strlen( bv.bv_val ); } if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ) ) { Debug( LDAP_DEBUG_ANY, "unable to add monitoredInfo to \"%s\" entry\n", SLAPD_MONITOR_DN, 0, 0 ); return( -1 ); } } mp = monitor_entrypriv_create(); if ( mp == NULL ) { return -1; } e->e_private = ( void * )mp; ep = &mp->mp_children; if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "unable to add entry \"%s\" to cache\n", SLAPD_MONITOR_DN, 0, 0 ); return -1; } /* * Create all the subsystem specific entries */ for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) { int len = strlen( monitor_subsys[ i ]->mss_name ); struct berval dn; int rc; dn.bv_len = len + sizeof( "cn=" ) - 1; dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 ); strcpy( dn.bv_val, "cn=" ); strcat( dn.bv_val, monitor_subsys[ i ]->mss_name ); rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL ); free( dn.bv_val ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "monitor RDN \"%s\" is invalid\n", dn.bv_val, 0, 0 ); return( -1 ); } dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */ dn.bv_val = ch_malloc( dn.bv_len + 1 ); strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val ); strcat( dn.bv_val, "," SLAPD_MONITOR_DN ); rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn, &monitor_subsys[ i ]->mss_ndn, NULL ); free( dn.bv_val ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "monitor DN \"%s\" is invalid\n", dn.bv_val, 0, 0 ); return( -1 ); } snprintf( buf, sizeof( buf ), "dn: %s\n" "objectClass: %s\n" "structuralObjectClass: %s\n" "cn: %s\n" "creatorsName: %s\n" "modifiersName: %s\n" "createTimestamp: %s\n" "modifyTimestamp: %s\n", monitor_subsys[ i ]->mss_dn.bv_val, mi->mi_oc_monitorContainer->soc_cname.bv_val, mi->mi_oc_monitorContainer->soc_cname.bv_val, monitor_subsys[ i ]->mss_name, mi->mi_creatorsName.bv_val, mi->mi_creatorsName.bv_val, mi->mi_startTime.bv_val, mi->mi_startTime.bv_val ); e = str2entry( buf ); if ( e == NULL) { Debug( LDAP_DEBUG_ANY, "unable to create \"%s\" entry\n", monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 ); return( -1 ); } if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) { attr_merge_normalize( e, slap_schema.si_ad_description, monitor_subsys[ i ]->mss_desc, NULL ); } mp = monitor_entrypriv_create(); if ( mp == NULL ) { return -1; } e->e_private = ( void * )mp; mp->mp_info = monitor_subsys[ i ]; mp->mp_flags = monitor_subsys[ i ]->mss_flags; if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "unable to add entry \"%s\" to cache\n", monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 ); return -1; } *ep = e; ep = &mp->mp_next; } assert( be != NULL ); be->be_private = mi; /* * opens the monitor backend subsystems */ for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) { if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) ) { return( -1 ); } ms[ 0 ]->mss_flags |= MONITOR_F_OPENED; } monitor_subsys_opened = 1; if ( mi->mi_entry_limbo ) { entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo; for ( ; el; ) { entry_limbo_t *tmp; switch ( el->el_type ) { case LIMBO_ENTRY: monitor_back_register_entry( el->el_e, el->el_cb ); break; case LIMBO_ENTRY_PARENT: monitor_back_register_entry_parent( el->el_e, el->el_cb, &el->el_base, el->el_scope, &el->el_filter ); break; case LIMBO_ATTRS: monitor_back_register_entry_attrs( &el->el_ndn, el->el_a, el->el_cb, &el->el_base, el->el_scope, &el->el_filter ); break; case LIMBO_CB: monitor_back_register_entry_callback( &el->el_ndn, el->el_cb, &el->el_base, el->el_scope, &el->el_filter ); break; default: assert( 0 ); } if ( el->el_e ) { entry_free( el->el_e ); } if ( el->el_a ) { attrs_free( el->el_a ); } if ( !BER_BVISNULL( &el->el_ndn ) ) { ber_memfree( el->el_ndn.bv_val ); } if ( !BER_BVISNULL( &el->el_base ) ) { ber_memfree( el->el_base.bv_val ); } if ( !BER_BVISNULL( &el->el_filter ) ) { ber_memfree( el->el_filter.bv_val ); } tmp = el; el = el->el_next; ch_free( tmp ); } mi->mi_entry_limbo = NULL; } return( 0 );}intmonitor_back_config( BackendInfo *bi, const char *fname, int lineno, int argc, char **argv ){ /* * eventually, will hold backend specific configuration parameters */ return SLAP_CONF_UNKNOWN;}#if 0intmonitor_back_db_config( Backend *be, const char *fname, int lineno, int argc, char **argv ){ monitor_info_t *mi = ( monitor_info_t * )be->be_private; /* * eventually, will hold database specific configuration parameters */ return SLAP_CONF_UNKNOWN;}#endifintmonitor_back_db_destroy( BackendDB *be ){ monitor_info_t *mi = ( monitor_info_t * )be->be_private; if ( mi == NULL ) { return -1; } /* * FIXME: destroys all the data */ /* NOTE: mi points to static storage; don't free it */ (void)monitor_cache_destroy( mi ); if ( monitor_subsys ) { int i; for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) { if ( monitor_subsys[ i ]->mss_destroy ) { monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] ); } if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) { ch_free( monitor_subsys[ i ]->mss_rdn.bv_val ); } if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_dn ) ) { ch_free( monitor_subsys[ i ]->mss_dn.bv_val ); } if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_ndn ) ) { ch_free( monitor_subsys[ i ]->mss_ndn.bv_val ); } } ch_free( monitor_subsys ); } ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex ); be->be_private = NULL; return 0;}#if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC/* conditionally define the init_module() function */SLAP_BACKEND_INIT_MODULE( monitor )#endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -