📄 search.c
字号:
rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ), op->o_tmpmemctx ); for ( cnt = 0; references[ cnt ]; cnt++ ) { /* duplicating ...*/ ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] ); } BER_BVZERO( &rs->sr_ref[ cnt ] ); } if ( match.bv_val != NULL ) {#ifndef LDAP_NULL_IS_NULL if ( match.bv_val[ 0 ] == '\0' ) { LDAP_FREE( match.bv_val ); BER_BVZERO( &match ); } else#endif /* LDAP_NULL_IS_NULL */ { match.bv_len = strlen( match.bv_val ); } }#ifndef LDAP_NULL_IS_NULL if ( rs->sr_text != NULL && rs->sr_text[ 0 ] == '\0' ) { LDAP_FREE( (char *)rs->sr_text ); rs->sr_text = NULL; }#endif /* LDAP_NULL_IS_NULL */ /* cleanup */ if ( references ) { ber_memvfree( (void **)references ); } rc = 0; break; } /* if needed, restore timeout */ if ( li->li_timeout[ SLAP_OP_SEARCH ] ) { if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) { tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ]; tv.tv_usec = 0; } } } if ( rc == -1 && dont_retry == 0 ) { if ( do_retry ) { do_retry = 0; if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) { goto retry; } } rs->sr_err = LDAP_SERVER_DOWN; rs->sr_err = slap_map_api2result( rs ); goto finish; } /* * Rewrite the matched portion of the search base, if required */ if ( !BER_BVISNULL( &match ) && !BER_BVISEMPTY( &match ) ) { struct berval pmatch; if ( dnPretty( NULL, &match, &pmatch, op->o_tmpmemctx ) == LDAP_SUCCESS ) { rs->sr_matched = pmatch.bv_val; LDAP_FREE( match.bv_val ); } else { rs->sr_matched = match.bv_val; } } if ( rs->sr_v2ref ) { rs->sr_err = LDAP_REFERRAL; }finish:; if ( LDAP_BACK_QUARANTINE( li ) ) { ldap_back_quarantine( op, rs ); }#if 0 /* let send_ldap_result play cleanup handlers (ITS#4645) */ if ( rc != SLAPD_ABANDON )#endif { send_ldap_result( op, rs ); } (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls ); if ( rs->sr_ctrls ) { ldap_controls_free( rs->sr_ctrls ); rs->sr_ctrls = NULL; } if ( rs->sr_matched != NULL && rs->sr_matched != save_matched ) { if ( rs->sr_matched != match.bv_val ) { ber_memfree_x( (char *)rs->sr_matched, op->o_tmpmemctx ); } else { LDAP_FREE( match.bv_val ); } rs->sr_matched = save_matched; } if ( free_filter ) { op->o_tmpfree( filter.bv_val, op->o_tmpmemctx ); } if ( rs->sr_text ) { if ( freetext ) { LDAP_FREE( (char *)rs->sr_text ); } rs->sr_text = NULL; } if ( rs->sr_ref ) { ber_bvarray_free_x( rs->sr_ref, op->o_tmpmemctx ); rs->sr_ref = NULL; } if ( attrs ) { ch_free( attrs ); } if ( lc != NULL ) { ldap_back_release_conn( li, lc ); } return rs->sr_err;}static intldap_build_entry( Operation *op, LDAPMessage *e, Entry *ent, struct berval *bdn ){ struct berval a; BerElement ber = *e->lm_ber; Attribute *attr, **attrp; const char *text; int last; /* safe assumptions ... */ assert( ent != NULL ); BER_BVZERO( &ent->e_bv ); if ( ber_scanf( &ber, "{m{", bdn ) == LBER_ERROR ) { return LDAP_DECODING_ERROR; } /* * Note: this may fail if the target host(s) schema differs * from the one known to the meta, and a DN with unknown * attributes is returned. * * FIXME: should we log anything, or delegate to dnNormalize? */ /* Note: if the distinguished values or the naming attributes * change, should we massage them as well? */ if ( dnPrettyNormal( NULL, bdn, &ent->e_name, &ent->e_nname, op->o_tmpmemctx ) != LDAP_SUCCESS ) { return LDAP_INVALID_DN_SYNTAX; } attrp = &ent->e_attrs; while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) { int i; slap_syntax_validate_func *validate; slap_syntax_transform_func *pretty; attr = (Attribute *)ch_malloc( sizeof( Attribute ) ); if ( attr == NULL ) { continue; } attr->a_flags = 0; attr->a_next = 0; attr->a_desc = NULL; if ( slap_bv2ad( &a, &attr->a_desc, &text ) != LDAP_SUCCESS ) { if ( slap_bv2undef_ad( &a, &attr->a_desc, &text, SLAP_AD_PROXIED ) != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "%s ldap_build_entry: " "slap_bv2undef_ad(%s): %s\n", op->o_log_prefix, a.bv_val, text ); ch_free( attr ); continue; } } /* no subschemaSubentry */ if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry || attr->a_desc == slap_schema.si_ad_entryDN ) { /* * We eat target's subschemaSubentry because * a search for this value is likely not * to resolve to the appropriate backend; * later, the local subschemaSubentry is * added. * * We also eat entryDN because the frontend * will reattach it without checking if already * present... */ ( void )ber_scanf( &ber, "x" /* [W] */ ); ch_free( attr ); continue; } if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR || attr->a_vals == NULL ) { /* * Note: attr->a_vals can be null when using * values result filter */ attr->a_vals = (struct berval *)&slap_dummy_bv; last = 0; } else { for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); last++ ) /* just count vals */ ; } validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate; pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty; if ( !validate && !pretty ) { attr->a_nvals = NULL; attr_free( attr ); goto next_attr; } for ( i = 0; i < last; i++ ) { struct berval pval; int rc; if ( pretty ) { rc = pretty( attr->a_desc->ad_type->sat_syntax, &attr->a_vals[i], &pval, NULL ); } else { rc = validate( attr->a_desc->ad_type->sat_syntax, &attr->a_vals[i] ); } if ( rc != LDAP_SUCCESS ) { /* check if, by chance, it's an undefined objectClass */ if ( attr->a_desc == slap_schema.si_ad_objectClass && oc_bvfind_undef( &attr->a_vals[i] ) != NULL ) { ber_dupbv( &pval, &attr->a_vals[i] ); } else { attr->a_nvals = NULL; attr_free( attr ); goto next_attr; } } if ( pretty ) { LBER_FREE( attr->a_vals[i].bv_val ); attr->a_vals[i] = pval; } } if ( last && attr->a_desc->ad_type->sat_equality && attr->a_desc->ad_type->sat_equality->smr_normalize ) { attr->a_nvals = ch_malloc( ( last + 1 )*sizeof( struct berval ) ); for ( i = 0; i < last; i++ ) { int rc; /* * check that each value is valid per syntax * and pretty if appropriate */ rc = attr->a_desc->ad_type->sat_equality->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, attr->a_desc->ad_type->sat_syntax, attr->a_desc->ad_type->sat_equality, &attr->a_vals[i], &attr->a_nvals[i], NULL ); if ( rc != LDAP_SUCCESS ) { BER_BVZERO( &attr->a_nvals[i] ); ch_free( attr ); goto next_attr; } } BER_BVZERO( &attr->a_nvals[i] ); } else { attr->a_nvals = attr->a_vals; } *attrp = attr; attrp = &attr->a_next;next_attr:; } return LDAP_SUCCESS;}/* return 0 IFF we can retrieve the entry with ndn */intldap_back_entry_get( Operation *op, struct berval *ndn, ObjectClass *oc, AttributeDescription *at, int rw, Entry **ent ){ ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private; ldapconn_t *lc = NULL; int rc = 1, do_not_cache; struct berval bdn; LDAPMessage *result = NULL, *e = NULL; char *attr[3], **attrp = NULL; char *filter = NULL; SlapReply rs; int do_retry = 1; LDAPControl **ctrls = NULL; *ent = NULL; /* Tell getconn this is a privileged op */ do_not_cache = op->o_do_not_cache; op->o_do_not_cache = 1; if ( !ldap_back_dobind( &lc, op, &rs, LDAP_BACK_DONTSEND ) ) { op->o_do_not_cache = do_not_cache; return rs.sr_err; } op->o_do_not_cache = do_not_cache; if ( at ) { attrp = attr; if ( oc && at != slap_schema.si_ad_objectClass ) { attr[0] = slap_schema.si_ad_objectClass->ad_cname.bv_val; attr[1] = at->ad_cname.bv_val; attr[2] = NULL; } else { attr[0] = at->ad_cname.bv_val; attr[1] = NULL; } } if ( oc ) { char *ptr; filter = ch_malloc( STRLENOF( "(objectclass=)" ) + oc->soc_cname.bv_len + 1 ); ptr = lutil_strcopy( filter, "(objectclass=" ); ptr = lutil_strcopy( ptr, oc->soc_cname.bv_val ); *ptr++ = ')'; *ptr++ = '\0'; }retry: ctrls = op->o_ctrls; rc = ldap_back_proxy_authz_ctrl( &lc->lc_bound_ndn, li->li_version, &li->li_idassert, op, &rs, &ctrls ); if ( rc != LDAP_SUCCESS ) { goto cleanup; } rc = ldap_search_ext_s( lc->lc_ld, ndn->bv_val, LDAP_SCOPE_BASE, filter, attrp, 0, ctrls, NULL, NULL, LDAP_NO_LIMIT, &result ); if ( rc != LDAP_SUCCESS ) { if ( rc == LDAP_SERVER_DOWN && do_retry ) { do_retry = 0; if ( ldap_back_retry( &lc, op, &rs, LDAP_BACK_DONTSEND ) ) { /* if the identity changed, there might be need to re-authz */ (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls ); goto retry; } } goto cleanup; } e = ldap_first_entry( lc->lc_ld, result ); if ( e == NULL ) { /* the entry exists, but it doesn't match the filter? */ goto cleanup; } *ent = ch_calloc( 1, sizeof( Entry ) ); if ( *ent == NULL ) { rc = LDAP_NO_MEMORY; goto cleanup; } rc = ldap_build_entry( op, e, *ent, &bdn ); if ( rc != LDAP_SUCCESS ) { entry_free( *ent ); *ent = NULL; }cleanup: (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls ); if ( result ) { ldap_msgfree( result ); } if ( filter ) { ch_free( filter ); } if ( lc != NULL ) { ldap_back_release_conn( li, lc ); } return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -