📄 init.c
字号:
Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_parent(\"\"): " "base=%s scope=%d filter=%s : " "unable to find entry\n", base->bv_val ? base->bv_val : "\"\"", scope, filter->bv_val ); return -1; } if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) { /* entry does not exist */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_parent(\"%s\"): " "parent entry does not exist\n", ndn.bv_val, 0, 0 ); rc = -1; goto done; } assert( e_parent->e_private != NULL ); mp_parent = ( monitor_entry_t * )e_parent->e_private; if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) { /* entry is volatile; cannot append callback */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_parent(\"%s\"): " "entry is volatile\n", e_parent->e_name.bv_val, 0, 0 ); rc = -1; goto done; } build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL ); build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL ); if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) { /* entry already exists */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_parent(\"%s\"): " "entry already exists\n", e_name.bv_val, 0, 0 ); monitor_cache_release( mi, e_new ); rc = -1; goto done; } mp = monitor_entrypriv_create(); if ( mp == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_parent(\"%s\"): " "monitor_entrypriv_create() failed\n", e->e_name.bv_val, 0, 0 ); rc = -1; goto done; } e_new = entry_dup( e ); if ( e_new == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "entry_dup() failed\n", e->e_name.bv_val, 0, 0 ); rc = -1; goto done; } ch_free( e_new->e_name.bv_val ); ch_free( e_new->e_nname.bv_val ); e_new->e_name = e_name; e_new->e_nname = e_nname; e_new->e_private = ( void * )mp; mp->mp_info = mp_parent->mp_info; mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB; mp->mp_cb = cb; ep = &mp_parent->mp_children; for ( ; *ep; ) { mp_parent = ( monitor_entry_t * )(*ep)->e_private; ep = &mp_parent->mp_next; } *ep = e_new; if ( monitor_cache_add( mi, e_new ) ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "unable to add entry\n", e->e_name.bv_val, 0, 0 ); rc = -1; goto done; }done:; if ( !BER_BVISNULL( &ndn ) ) { ch_free( ndn.bv_val ); } if ( rc ) { if ( mp ) { ch_free( mp ); } if ( e_new ) { e_new->e_private = NULL; entry_free( e_new ); } } if ( e_parent ) { monitor_cache_release( mi, e_parent ); } } else { entry_limbo_t **elpp, el = { 0 }; el.el_type = LIMBO_ENTRY_PARENT; el.el_e = entry_dup( e ); if ( el.el_e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "entry_dup() failed\n", e->e_name.bv_val, 0, 0 ); return -1; } if ( !BER_BVISNULL( base ) ) { ber_dupbv( &el.el_base, base ); } el.el_scope = scope; if ( !BER_BVISNULL( filter ) ) { ber_dupbv( &el.el_filter, filter ); } el.el_cb = cb; for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo; *elpp; elpp = &(*elpp)->el_next ) /* go to last */; *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) ); if ( *elpp == NULL ) { el.el_e->e_private = NULL; entry_free( el.el_e ); return -1; } el.el_next = NULL; **elpp = el; } return 0;}static intmonitor_filter2ndn_cb( Operation *op, SlapReply *rs ){ if ( rs->sr_type == REP_SEARCH ) { struct berval *ndn = op->o_callback->sc_private; ber_dupbv( ndn, &rs->sr_entry->e_nname ); } return 0;}intmonitor_filter2ndn( struct berval *base, int scope, struct berval *filter, struct berval *ndn ){ Connection conn = { 0 }; OperationBuffer opbuf; Operation *op; void *thrctx; SlapReply rs = { 0 }; slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL }; int rc; BER_BVZERO( ndn ); if ( be_monitor == NULL ) { return -1; } op = (Operation *) &opbuf; thrctx = ldap_pvt_thread_pool_context(); connection_fake_init( &conn, op, thrctx ); op->o_tag = LDAP_REQ_SEARCH; op->o_bd = be_monitor; if ( base == NULL || BER_BVISNULL( base ) ) { ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ], op->o_tmpmemctx ); ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ], op->o_tmpmemctx ); } else { if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx ) ) { return -1; } } op->o_callback = &cb; cb.sc_private = (void *)ndn; op->ors_scope = scope; ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx ); op->ors_filter = str2filter_x( op, filter->bv_val ); op->ors_attrs = slap_anlist_no_attrs; op->ors_attrsonly = 0; op->ors_tlimit = SLAP_NO_LIMIT; op->ors_slimit = 1; op->ors_limit = NULL; op->ors_deref = LDAP_DEREF_NEVER; op->o_nocaching = 1; op->o_managedsait = SLAP_CONTROL_NONCRITICAL; op->o_dn = be_monitor->be_rootdn; op->o_ndn = be_monitor->be_rootndn; rc = op->o_bd->be_search( op, &rs ); filter_free_x( op, op->ors_filter ); op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx ); op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx ); op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx ); if ( rc != 0 ) { return rc; } switch ( rs.sr_err ) { case LDAP_SUCCESS: if ( BER_BVISNULL( ndn ) ) { rc = -1; } break; case LDAP_SIZELIMIT_EXCEEDED: default: if ( !BER_BVISNULL( ndn ) ) { ber_memfree( ndn->bv_val ); BER_BVZERO( ndn ); } rc = -1; break; } return rc;}intmonitor_back_register_entry_attrs( struct berval *ndn_in, Attribute *a, monitor_callback_t *cb, struct berval *base, int scope, struct berval *filter ){ monitor_info_t *mi; struct berval ndn = BER_BVNULL; char *fname = ( a == NULL ? "callback" : "attrs" ); if ( be_monitor == NULL ) { char buf[ SLAP_TEXT_BUFLEN ]; snprintf( buf, sizeof( buf ), "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): " "monitor database not configured.\n", fname, BER_BVISNULL( base ) ? "" : base->bv_val, scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ), BER_BVISNULL( filter ) ? "" : filter->bv_val ); Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 ); return -1; } mi = ( monitor_info_t * )be_monitor->be_private; assert( mi != NULL ); if ( ndn_in != NULL ) { ndn = *ndn_in; } if ( a == NULL && cb == NULL ) { /* nothing to do */ return -1; } if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) ) && BER_BVISNULL( filter ) ) { /* need a filter */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_%s(\"\"): " "need a valid filter\n", fname, 0, 0 ); return -1; } if ( monitor_subsys_opened ) { Entry *e = NULL; Attribute **atp = NULL; monitor_entry_t *mp = NULL; monitor_callback_t **mcp = NULL; int rc = 0; int freeit = 0; if ( BER_BVISNULL( &ndn ) ) { if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) { char buf[ SLAP_TEXT_BUFLEN ]; snprintf( buf, sizeof( buf ), "monitor_back_register_entry_%s(\"\"): " "base=%s scope=%d filter=%s : " "unable to find entry\n", fname, base->bv_val ? base->bv_val : "\"\"", scope, filter->bv_val ); /* entry does not exist */ Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 ); return -1; } freeit = 1; } if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) { /* entry does not exist */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_%s(\"%s\"): " "entry does not exist\n", fname, ndn.bv_val, 0 ); rc = -1; goto done; } assert( e->e_private != NULL ); mp = ( monitor_entry_t * )e->e_private; if ( mp->mp_flags & MONITOR_F_VOLATILE ) { /* entry is volatile; cannot append callback */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_%s(\"%s\"): " "entry is volatile\n", fname, e->e_name.bv_val, 0 ); rc = -1; goto done; } if ( a ) { for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next ) /* just get to last */ ; *atp = attrs_dup( a ); if ( *atp == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_%s(\"%s\"): " "attrs_dup() failed\n", fname, e->e_name.bv_val, 0 ); rc = -1; goto done; } } if ( cb ) { for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next ) /* go to tail */ ; /* NOTE: we do not clear cb->mc_next, so this function * can be used to append a list of callbacks */ (*mcp) = cb; }done:; if ( rc ) { if ( *atp ) { attrs_free( *atp ); *atp = NULL; } } if ( freeit ) { ber_memfree( ndn.bv_val ); } if ( e ) { monitor_cache_release( mi, e ); } } else { entry_limbo_t **elpp, el = { 0 }; el.el_type = LIMBO_ATTRS; if ( !BER_BVISNULL( &ndn ) ) { ber_dupbv( &el.el_ndn, &ndn ); } if ( !BER_BVISNULL( base ) ) { ber_dupbv( &el.el_base, base); } el.el_scope = scope; if ( !BER_BVISNULL( filter ) ) { ber_dupbv( &el.el_filter, filter ); } el.el_a = attrs_dup( a ); el.el_cb = cb; for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo; *elpp; elpp = &(*elpp)->el_next ) /* go to last */; *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) ); if ( *elpp == NULL ) { el.el_e->e_private = NULL; entry_free( el.el_e ); return -1; } el.el_next = NULL; **elpp = el; } return 0;}intmonitor_back_register_entry_callback( struct berval *ndn, monitor_callback_t *cb, struct berval *base, int scope, struct berval *filter ){ return monitor_back_register_entry_attrs( ndn, NULL, cb, base, scope, filter );}monitor_subsys_t *monitor_back_get_subsys( const char *name ){ if ( monitor_subsys != NULL ) { int i; for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) { if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) { return monitor_subsys[ i ]; } } } return NULL;}monitor_subsys_t *monitor_back_get_subsys_by_dn( struct berval *ndn, int sub ){ if ( monitor_subsys != NULL ) { int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -