-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1999-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
*
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati.
+ */
+/* This is an altered version */
+/*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has been developed to fulfill the requirements
struct timeval tv = { 0, 0 };
LDAPMessage *res, *e;
int rc = 0, *msgid, sres = LDAP_NO_SUCH_OBJECT;
- char *match = NULL, *err = NULL;
- char *mmatch = NULL;
+ char *err = NULL;
+ struct berval match = { 0, NULL }, mmatch = { 0, NULL };
BerVarray v2refs = NULL;
- int i, last = 0, candidates = 0;
+ int i, last = 0, candidates = 0, initial_candidates = 0,
+ candidate_match = 0;
struct slap_limits_set *limit = NULL;
int isroot = 0;
dncookie dc;
-#ifdef LDAP_CACHING
cache_manager* cm = li->cm;
if (cm->caching) {
- return meta_back_cache_search(op->o_bd, op->o_conn, op,
- &op->o_req_dn, &op->o_req_ndn,
- op->oq_search.rs_scope,
- op->oq_search.rs_deref,
- op->oq_search.rs_slimit,
- op->oq_search.rs_tlimit,
- op->oq_search.rs_filter,
- &op->oq_search.rs_filterstr,
- op->oq_search.rs_attrs,
- op->oq_search.rs_attrsonly);
+ return meta_back_cache_search(op, rs);
}
-#endif /* LDAP_CACHING */
/*
* controls are set in ldap_back_dobind()
new_candidate:;
}
+ initial_candidates = candidates;
+
/* We pull apart the ber result, stuff it into a slapd entry, and
* let send_search_entry stuff it back into ber format. Slow & ugly,
* but this is necessary for version matching, and for ACL processing.
}
ldap_get_option( lsc->ld,
LDAP_OPT_ERROR_STRING, &err );
- if ( match != NULL ) {
- free( match );
+ if ( match.bv_val != NULL ) {
+ free( match.bv_val );
}
ldap_get_option( lsc->ld,
- LDAP_OPT_MATCHED_DN, &match );
+ LDAP_OPT_MATCHED_DN, &match.bv_val );
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, ERR,
"meta_back_search [%d] "
"match=\"%s\" err=\"%s\"\n",
- i, match, err );
+ i, match.bv_val, err );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ANY,
"=>meta_back_search [%d] "
"match=\"%s\" err=\"%s\"\n",
- i, match, err );
+ i, match.bv_val, err );
#endif /* !NEW_LOGGING */
-
+ candidate_match++;
last = i;
rc = 0;
*
* FIXME: only the last one gets caught!
*/
- if ( match != NULL ) {
- switch ( rewrite_session( li->targets[ last ]->rwmap.rwm_rw,
- "matchedDn", match, op->o_conn,
- &mmatch ) ) {
- case REWRITE_REGEXEC_OK:
- if ( mmatch == NULL ) {
- mmatch = ( char * )match;
- }
-#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1,
- "[rw] matchedDn: \"%s\" -> \"%s\"\n",
- match, mmatch, 0 );
-#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ARGS,
- "rw> matchedDn: \"%s\" -> \"%s\"\n",
- match, mmatch, 0 );
-#endif /* !NEW_LOGGING */
- break;
-
- case REWRITE_REGEXEC_UNWILLING:
-
- case REWRITE_REGEXEC_ERR:
- /* FIXME: no error, but no matched ... */
- mmatch = NULL;
- break;
+ if ( candidate_match == initial_candidates
+ && match.bv_val != NULL && *match.bv_val ) {
+ dc.ctx = "matchedDn";
+ dc.rwmap = &li->targets[ last ]->rwmap;
+
+ if ( ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
+ mmatch.bv_val = NULL;
}
}
sres = LDAP_REFERRAL;
}
rs->sr_err = sres;
- rs->sr_matched = mmatch;
+ rs->sr_matched = mmatch.bv_val;
rs->sr_v2ref = v2refs;
send_ldap_result( op, rs );
rs->sr_matched = NULL;
finish:;
- if ( match ) {
- if ( mmatch != match ) {
- free( mmatch );
+ if ( match.bv_val ) {
+ if ( mmatch.bv_val != match.bv_val ) {
+ free( mmatch.bv_val );
}
- free(match);
+ free( match.bv_val );
}
if ( err ) {
* from the one known to the meta, and a DN with unknown
* attributes is returned.
*
- * FIXME: should we log anything, or delegate to dnNormalize2?
+ * FIXME: should we log anything, or delegate to dnNormalize?
*/
- if ( dnNormalize2( NULL, &ent.e_name, &ent.e_nname ) != LDAP_SUCCESS ) {
+ if ( dnNormalize( 0, NULL, NULL, &ent.e_name, &ent.e_nname,
+ &op->o_tmpmemctx ) != LDAP_SUCCESS )
+ {
return LDAP_INVALID_DN_SYNTAX;
}
ent.e_private = 0;
attrp = &ent.e_attrs;
+ dc.ctx = "searchAttrDN";
while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
+ int last = 0;
+
ldap_back_map( &li->targets[ target ]->rwmap.rwm_at,
&a, &mapped, BACKLDAP_REMAP );
if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
/* no subschemaSubentry */
if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry ) {
+
+ /*
+ * 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.
+ */
+ ( void )ber_scanf( &ber, "x" /* [W] */ );
+
ch_free(attr);
continue;
}
} else if ( attr->a_desc == slap_schema.si_ad_objectClass
|| attr->a_desc == slap_schema.si_ad_structuralObjectClass ) {
- int last;
for ( last = 0; attr->a_vals[ last ].bv_val; ++last );
* ACLs to the target directory server, and letting
* everything pass thru the ldap backend.
*/
- } else if ( strcmp( attr->a_desc->ad_type->sat_syntax->ssyn_oid,
- SLAPD_DN_SYNTAX ) == 0 ) {
- int last;
-
- for ( last = 0; attr->a_vals[ last ].bv_val; ++last );
-
- for ( bv = attr->a_vals; bv->bv_val; bv++ ) {
- char *newval;
-
- switch ( rewrite_session( li->targets[ target ]->rwmap.rwm_rw,
- "searchResult",
- bv->bv_val,
- lc->conn, &newval )) {
- case REWRITE_REGEXEC_OK:
- /* left as is */
- if ( newval == NULL ) {
- break;
- }
-#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1,
- "[rw] searchResult on attr=%s: \"%s\" -> \"%s\"\n",
- attr->a_desc->ad_type->sat_cname.bv_val,
- bv->bv_val, newval );
-#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ARGS,
- "rw> searchResult on attr=%s:"
- " \"%s\" -> \"%s\"\n",
- attr->a_desc->ad_type->sat_cname.bv_val,
- bv->bv_val, newval );
-#endif /* !NEW_LOGGING */
- free( bv->bv_val );
- bv->bv_val = newval;
- bv->bv_len = strlen( newval );
-
- break;
-
- case REWRITE_REGEXEC_UNWILLING:
- LBER_FREE(bv->bv_val);
- bv->bv_val = NULL;
- if (--last < 0)
- goto next_attr;
- *bv = attr->a_vals[last];
- attr->a_vals[last].bv_val = NULL;
- bv--;
- break;
+ } else if ( attr->a_desc->ad_type->sat_syntax ==
+ slap_schema.si_syn_distinguishedName ) {
+ ldap_dnattr_result_rewrite( &dc, attr->a_vals );
+ }
- case REWRITE_REGEXEC_ERR:
- /*
- * FIXME: better give up,
- * skip the attribute
- * or leave it untouched?
- */
- break;
- }
+ if ( last && attr->a_desc->ad_type->sat_equality &&
+ attr->a_desc->ad_type->sat_equality->smr_normalize ) {
+ int i;
+
+ attr->a_nvals = ch_malloc((last + 1)*sizeof(struct berval));
+ for ( i = 0; i<last; i++ ) {
+ 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],
+ op->o_tmpmemctx );
}
+ attr->a_nvals[i].bv_val = NULL;
+ attr->a_nvals[i].bv_len = 0;
+ } else {
+ attr->a_nvals = attr->a_vals;
}
-next_attr:;
*attrp = attr;
attrp = &attr->a_next;