2003-11-27 14:35:14 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 1999-2005 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 2001-2003 Pierangelo Masarati.
|
|
|
|
* Portions Copyright 1999-2003 Howard Chu.
|
2003-11-27 14:35:14 +08:00
|
|
|
* All rights reserved.
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
2003-11-27 14:35:14 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "../back-ldap/back-ldap.h"
|
|
|
|
#include "back-meta.h"
|
2002-04-08 17:43:22 +08:00
|
|
|
#undef ldap_debug /* silence a warning in ldap-int.h */
|
2002-07-12 04:33:24 +08:00
|
|
|
#include "ldap_log.h"
|
2002-01-04 00:29:38 +08:00
|
|
|
#include "../../../libraries/libldap/ldap-int.h"
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2002-08-14 01:00:33 +08:00
|
|
|
static int
|
2001-05-12 08:51:28 +08:00
|
|
|
meta_send_entry(
|
2005-04-21 11:17:31 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
2005-04-23 05:43:52 +08:00
|
|
|
metaconn_t *mc,
|
2005-04-21 11:17:31 +08:00
|
|
|
int i,
|
|
|
|
LDAPMessage *e );
|
|
|
|
|
|
|
|
static int
|
|
|
|
meta_back_search_start(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
dncookie *dc,
|
2005-04-23 05:43:52 +08:00
|
|
|
metasingleconn_t *msc,
|
2005-04-21 11:17:31 +08:00
|
|
|
int candidate,
|
2005-04-23 05:43:52 +08:00
|
|
|
SlapReply *candidates
|
2005-04-21 11:17:31 +08:00
|
|
|
)
|
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
2005-06-14 03:14:40 +08:00
|
|
|
struct berval realbase = op->o_req_dn;
|
|
|
|
int realscope = op->ors_scope;
|
|
|
|
ber_len_t suffixlen = 0;
|
|
|
|
struct berval mbase = BER_BVNULL;
|
|
|
|
struct berval mfilter = BER_BVNULL;
|
|
|
|
char **mapped_attrs = NULL;
|
|
|
|
int rc;
|
2005-04-21 11:17:31 +08:00
|
|
|
|
|
|
|
/* should we check return values? */
|
|
|
|
if ( op->ors_deref != -1 ) {
|
|
|
|
ldap_set_option( msc->msc_ld, LDAP_OPT_DEREF,
|
|
|
|
( void * )&op->ors_deref);
|
|
|
|
}
|
|
|
|
if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
|
|
|
|
ldap_set_option( msc->msc_ld, LDAP_OPT_TIMELIMIT,
|
|
|
|
( void * )&op->ors_tlimit);
|
|
|
|
}
|
|
|
|
if ( op->ors_slimit != SLAP_NO_LIMIT ) {
|
|
|
|
ldap_set_option( msc->msc_ld, LDAP_OPT_SIZELIMIT,
|
|
|
|
( void * )&op->ors_slimit);
|
|
|
|
}
|
|
|
|
|
2005-05-05 07:57:55 +08:00
|
|
|
dc->target = &mi->mi_targets[ candidate ];
|
2005-04-21 11:17:31 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* modifies the base according to the scope, if required
|
|
|
|
*/
|
2005-05-05 07:57:55 +08:00
|
|
|
suffixlen = mi->mi_targets[ candidate ].mt_nsuffix.bv_len;
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( suffixlen > op->o_req_ndn.bv_len ) {
|
|
|
|
switch ( op->ors_scope ) {
|
|
|
|
case LDAP_SCOPE_SUBTREE:
|
|
|
|
/*
|
|
|
|
* make the target suffix the new base
|
|
|
|
* FIXME: this is very forgiving, because
|
|
|
|
* "illegal" searchBases may be turned
|
|
|
|
* into the suffix of the target; however,
|
|
|
|
* the requested searchBase already passed
|
|
|
|
* thru the candidate analyzer...
|
|
|
|
*/
|
2005-05-05 07:57:55 +08:00
|
|
|
if ( dnIsSuffix( &mi->mi_targets[ candidate ].mt_nsuffix,
|
2005-04-21 11:17:31 +08:00
|
|
|
&op->o_req_ndn ) )
|
|
|
|
{
|
2005-05-05 07:57:55 +08:00
|
|
|
realbase = mi->mi_targets[ candidate ].mt_nsuffix;
|
2005-04-21 11:17:31 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* this target is no longer candidate
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-05-06 18:21:00 +08:00
|
|
|
#ifdef LDAP_SCOPE_SUBORDINATE
|
|
|
|
case LDAP_SCOPE_SUBORDINATE:
|
|
|
|
#endif /* LDAP_SCOPE_SUBORDINATE */
|
2005-04-21 11:17:31 +08:00
|
|
|
case LDAP_SCOPE_ONELEVEL:
|
|
|
|
{
|
2005-05-05 07:57:55 +08:00
|
|
|
struct berval rdn = mi->mi_targets[ candidate ].mt_nsuffix;
|
2005-04-21 11:17:31 +08:00
|
|
|
rdn.bv_len -= op->o_req_ndn.bv_len + STRLENOF( "," );
|
|
|
|
if ( dnIsOneLevelRDN( &rdn )
|
2005-05-05 07:57:55 +08:00
|
|
|
&& dnIsSuffix( &mi->mi_targets[ candidate ].mt_nsuffix, &op->o_req_ndn ) )
|
2005-04-21 11:17:31 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* if there is exactly one level,
|
|
|
|
* make the target suffix the new
|
|
|
|
* base, and make scope "base"
|
|
|
|
*/
|
2005-05-05 07:57:55 +08:00
|
|
|
realbase = mi->mi_targets[ candidate ].mt_nsuffix;
|
2005-05-06 18:21:00 +08:00
|
|
|
#ifdef LDAP_SCOPE_SUBORDINATE
|
|
|
|
if ( op->ors_scope == LDAP_SCOPE_SUBORDINATE ) {
|
|
|
|
realscope = LDAP_SCOPE_SUBTREE;
|
|
|
|
} else
|
|
|
|
#endif /* LDAP_SCOPE_SUBORDINATE */
|
|
|
|
{
|
|
|
|
realscope = LDAP_SCOPE_BASE;
|
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
break;
|
|
|
|
} /* else continue with the next case */
|
|
|
|
}
|
|
|
|
|
|
|
|
case LDAP_SCOPE_BASE:
|
|
|
|
/*
|
|
|
|
* this target is no longer candidate
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rewrite the search base, if required
|
|
|
|
*/
|
|
|
|
dc->ctx = "searchBase";
|
|
|
|
switch ( ldap_back_dn_massage( dc, &realbase, &mbase ) ) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_REGEXEC_UNWILLING:
|
|
|
|
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
rs->sr_text = "Operation not allowed";
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case REWRITE_REGEXEC_ERR:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this target is no longer candidate
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maps filter
|
|
|
|
*/
|
|
|
|
rc = ldap_back_filter_map_rewrite( dc, op->ors_filter,
|
|
|
|
&mfilter, BACKLDAP_MAP );
|
|
|
|
switch ( rc ) {
|
|
|
|
case LDAP_SUCCESS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_COMPARE_FALSE:
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* this target is no longer candidate
|
|
|
|
*/
|
|
|
|
rc = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maps required attributes
|
|
|
|
*/
|
2005-05-05 07:57:55 +08:00
|
|
|
rc = ldap_back_map_attrs( &mi->mi_targets[ candidate ].mt_rwmap.rwm_at,
|
2005-04-23 05:43:52 +08:00
|
|
|
op->ors_attrs, BACKLDAP_MAP, &mapped_attrs );
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
/*
|
|
|
|
* this target is no longer candidate
|
|
|
|
*/
|
|
|
|
rc = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Starts the search
|
|
|
|
*/
|
|
|
|
rc = ldap_search_ext( msc->msc_ld,
|
|
|
|
mbase.bv_val, realscope, mfilter.bv_val,
|
|
|
|
mapped_attrs, op->ors_attrsonly,
|
2005-04-23 05:43:52 +08:00
|
|
|
op->o_ctrls, NULL, NULL, op->ors_slimit,
|
|
|
|
&candidates[ candidate ].sr_msgid );
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
rc = 1;
|
|
|
|
|
|
|
|
} else {
|
2005-04-23 05:43:52 +08:00
|
|
|
candidates[ candidate ].sr_msgid = -1;
|
2005-04-21 11:17:31 +08:00
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:;
|
|
|
|
if ( mapped_attrs ) {
|
|
|
|
free( mapped_attrs );
|
|
|
|
}
|
|
|
|
if ( mfilter.bv_val != op->ors_filterstr.bv_val ) {
|
|
|
|
free( mfilter.bv_val );
|
|
|
|
}
|
|
|
|
if ( mbase.bv_val != realbase.bv_val ) {
|
|
|
|
free( mbase.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
int
|
2003-04-04 05:35:54 +08:00
|
|
|
meta_back_search( Operation *op, SlapReply *rs )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-06-14 03:14:40 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
|
|
|
metaconn_t *mc;
|
|
|
|
struct timeval tv = { 0, 0 };
|
|
|
|
time_t stoptime;
|
|
|
|
LDAPMessage *res = NULL, *e;
|
|
|
|
int rc = 0, sres = LDAP_SUCCESS;
|
|
|
|
char *matched = NULL;
|
|
|
|
int i, last = 0, ncandidates = 0,
|
|
|
|
initial_candidates = 0, candidate_match = 0;
|
|
|
|
dncookie dc;
|
|
|
|
int is_ok = 0;
|
|
|
|
void *savepriv;
|
|
|
|
SlapReply *candidates = meta_back_candidates_get( op );
|
2004-02-29 00:05:59 +08:00
|
|
|
|
2002-08-31 18:35:23 +08:00
|
|
|
/*
|
|
|
|
* controls are set in ldap_back_dobind()
|
|
|
|
*
|
|
|
|
* FIXME: in case of values return filter, we might want
|
|
|
|
* to map attrs and maybe rewrite value
|
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_SENDERR );
|
|
|
|
if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
|
2005-02-05 23:55:27 +08:00
|
|
|
return rs->sr_err;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2003-04-08 01:04:14 +08:00
|
|
|
dc.conn = op->o_conn;
|
|
|
|
dc.rs = rs;
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* Inits searches
|
|
|
|
*/
|
2005-05-06 01:34:11 +08:00
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
|
|
|
metasingleconn_t *msc = &mc->mc_conns[ i ];
|
|
|
|
|
2005-04-22 06:22:43 +08:00
|
|
|
candidates[ i ].sr_msgid = -1;
|
2003-02-11 05:37:30 +08:00
|
|
|
|
2005-04-22 06:22:43 +08:00
|
|
|
if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-23 05:43:52 +08:00
|
|
|
candidates[ i ].sr_err = LDAP_SUCCESS;
|
|
|
|
candidates[ i ].sr_matched = NULL;
|
|
|
|
candidates[ i ].sr_text = NULL;
|
|
|
|
candidates[ i ].sr_ref = NULL;
|
|
|
|
candidates[ i ].sr_ctrls = NULL;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-23 05:43:52 +08:00
|
|
|
switch ( meta_back_search_start( op, rs, &dc, msc, i, candidates ) )
|
2005-04-21 11:17:31 +08:00
|
|
|
{
|
|
|
|
case 0:
|
2003-04-08 01:04:14 +08:00
|
|
|
break;
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
case 1:
|
|
|
|
++ncandidates;
|
|
|
|
break;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
case -1:
|
2001-05-12 08:51:28 +08:00
|
|
|
rc = -1;
|
|
|
|
goto finish;
|
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
initial_candidates = ncandidates;
|
2004-02-29 00:05:59 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
char cnd[BUFSIZ];
|
|
|
|
int i;
|
2003-03-01 19:08:53 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
2005-04-22 06:22:43 +08:00
|
|
|
if ( candidates[ i ].sr_tag == META_CANDIDATE ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
cnd[ i ] = '*';
|
|
|
|
} else {
|
|
|
|
cnd[ i ] = ' ';
|
|
|
|
}
|
2003-04-06 00:53:57 +08:00
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
cnd[ i ] = '\0';
|
2003-04-06 00:53:57 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "%s meta_back_search: ncandidates=%d "
|
|
|
|
"cnd=\"%s\"\n", op->o_log_prefix, ncandidates, cnd );
|
|
|
|
}
|
|
|
|
#endif
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( initial_candidates == 0 ) {
|
|
|
|
send_ldap_error( op, rs, LDAP_NO_SUCH_OBJECT, NULL );
|
|
|
|
/* FIXME: find a way to look up the best match */
|
2003-02-11 05:37:30 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
rc = LDAP_NO_SUCH_OBJECT;
|
|
|
|
goto finish;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2005-06-14 03:14:40 +08:00
|
|
|
if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
|
|
|
|
stoptime = op->o_time + op->ors_tlimit;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* In case there are no candidates, no cycle takes place...
|
2002-08-31 18:35:23 +08:00
|
|
|
*
|
2005-04-21 11:17:31 +08:00
|
|
|
* FIXME: we might use a queue, to better balance the load
|
2002-08-31 18:35:23 +08:00
|
|
|
* among the candidates
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
2005-04-16 10:25:41 +08:00
|
|
|
for ( rc = 0; ncandidates > 0; ) {
|
2005-04-23 05:43:52 +08:00
|
|
|
int gotit = 0, doabandon = 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-05-06 01:34:11 +08:00
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
|
|
|
metasingleconn_t *msc = &mc->mc_conns[ i ];
|
|
|
|
|
2005-04-22 06:22:43 +08:00
|
|
|
if ( candidates[ i ].sr_msgid == -1 ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
|
|
|
|
/* check for abandon */
|
|
|
|
if ( op->o_abandon ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2002-08-31 18:35:23 +08:00
|
|
|
/*
|
|
|
|
* FIXME: handle time limit as well?
|
|
|
|
* Note that target servers are likely
|
|
|
|
* to handle it, so at some time we'll
|
|
|
|
* get a LDAP_TIMELIMIT_EXCEEDED from
|
|
|
|
* one of them ...
|
|
|
|
*/
|
2005-04-22 06:22:43 +08:00
|
|
|
rc = ldap_result( msc->msc_ld, candidates[ i ].sr_msgid,
|
2001-05-12 08:51:28 +08:00
|
|
|
0, &tv, &res );
|
|
|
|
|
|
|
|
if ( rc == 0 ) {
|
2004-03-06 23:01:16 +08:00
|
|
|
/* timeout exceeded */
|
|
|
|
|
|
|
|
/* FIXME: res should not need to be freed */
|
|
|
|
assert( res == NULL );
|
|
|
|
|
2005-06-14 03:14:40 +08:00
|
|
|
/* check time limit */
|
|
|
|
if ( op->ors_tlimit != SLAP_NO_LIMIT
|
|
|
|
&& slap_get_time() > stoptime )
|
|
|
|
{
|
|
|
|
doabandon = 1;
|
|
|
|
rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
|
|
|
|
savepriv = op->o_private;
|
|
|
|
op->o_private = (void *)i;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
op->o_private = savepriv;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
2002-08-31 18:35:23 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else if ( rc == -1 ) {
|
2005-01-08 17:20:54 +08:00
|
|
|
really_bad:;
|
2001-05-12 08:51:28 +08:00
|
|
|
/* something REALLY bad happened! */
|
2005-04-23 05:43:52 +08:00
|
|
|
( void )meta_clear_unused_candidates( op, -1 );
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
2005-04-16 10:25:41 +08:00
|
|
|
savepriv = op->o_private;
|
|
|
|
op->o_private = (void *)i;
|
2003-04-04 05:35:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2005-04-16 10:25:41 +08:00
|
|
|
op->o_private = savepriv;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/* anything else needs be done? */
|
2004-03-06 23:01:16 +08:00
|
|
|
|
|
|
|
/* FIXME: res should not need to be freed */
|
|
|
|
assert( res == NULL );
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
goto finish;
|
2002-08-31 18:35:23 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
|
2005-05-13 21:10:33 +08:00
|
|
|
if ( --op->ors_slimit == -1 ) {
|
2005-05-13 06:37:56 +08:00
|
|
|
ldap_msgfree( res );
|
|
|
|
res = NULL;
|
|
|
|
|
|
|
|
rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
|
|
|
|
savepriv = op->o_private;
|
|
|
|
op->o_private = (void *)i;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
op->o_private = savepriv;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
is_ok++;
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
e = ldap_first_entry( msc->msc_ld, res );
|
2005-04-16 10:25:41 +08:00
|
|
|
savepriv = op->o_private;
|
|
|
|
op->o_private = (void *)i;
|
2005-04-23 05:43:52 +08:00
|
|
|
meta_send_entry( op, rs, mc, i, e );
|
2005-04-16 10:25:41 +08:00
|
|
|
op->o_private = savepriv;
|
2003-02-11 05:37:30 +08:00
|
|
|
|
2004-03-06 23:01:16 +08:00
|
|
|
ldap_msgfree( res );
|
|
|
|
res = NULL;
|
|
|
|
|
2005-04-26 07:54:51 +08:00
|
|
|
gotit = 1;
|
|
|
|
|
2005-04-27 05:48:43 +08:00
|
|
|
#if 0
|
2003-02-11 05:37:30 +08:00
|
|
|
/*
|
|
|
|
* If scope is BASE, we need to jump out
|
|
|
|
* as soon as one entry is found; if
|
|
|
|
* the target pool is properly crafted,
|
|
|
|
* this should correspond to the sole
|
|
|
|
* entry that has the base DN
|
|
|
|
*/
|
2005-04-27 05:48:43 +08:00
|
|
|
/* FIXME: this defeats the purpose of
|
|
|
|
* doing a search with scope == base and
|
|
|
|
* sizelimit = 1 to determine if a
|
|
|
|
* candidate is actually unique */
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( op->ors_scope == LDAP_SCOPE_BASE
|
2005-04-16 10:25:41 +08:00
|
|
|
&& rs->sr_nentries > 0 )
|
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
doabandon = 1;
|
2005-04-16 10:25:41 +08:00
|
|
|
ncandidates = 0;
|
2003-02-11 05:37:30 +08:00
|
|
|
sres = LDAP_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-27 05:48:43 +08:00
|
|
|
#endif
|
2004-03-06 23:01:16 +08:00
|
|
|
|
2002-08-31 18:35:23 +08:00
|
|
|
} else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
|
|
|
|
char **references = NULL;
|
|
|
|
int cnt;
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
is_ok++;
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
rc = ldap_parse_reference( msc->msc_ld, res,
|
2003-04-04 05:35:54 +08:00
|
|
|
&references, &rs->sr_ctrls, 1 );
|
2004-06-18 02:27:51 +08:00
|
|
|
res = NULL;
|
2002-08-31 18:35:23 +08:00
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( references == NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-12-31 01:45:07 +08:00
|
|
|
#ifdef ENABLE_REWRITE
|
|
|
|
dc.ctx = "referralDN";
|
|
|
|
#else /* ! ENABLE_REWRITE */
|
|
|
|
dc.tofrom = 0;
|
|
|
|
dc.normalized = 0;
|
|
|
|
#endif /* ! ENABLE_REWRITE */
|
2005-04-23 05:43:52 +08:00
|
|
|
|
|
|
|
/* FIXME: merge all and return at the end */
|
|
|
|
|
2002-08-31 18:35:23 +08:00
|
|
|
for ( cnt = 0; references[ cnt ]; cnt++ )
|
2004-12-31 01:45:07 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
rs->sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
|
2002-08-31 18:35:23 +08:00
|
|
|
|
|
|
|
for ( cnt = 0; references[ cnt ]; cnt++ ) {
|
2004-12-31 01:45:07 +08:00
|
|
|
ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] );
|
2002-08-31 18:35:23 +08:00
|
|
|
}
|
2004-12-31 01:45:07 +08:00
|
|
|
BER_BVZERO( &rs->sr_ref[ cnt ] );
|
|
|
|
|
|
|
|
( void )ldap_back_referral_result_rewrite( &dc, rs->sr_ref );
|
2002-08-31 18:35:23 +08:00
|
|
|
|
2004-12-31 01:45:07 +08:00
|
|
|
if ( rs->sr_ref != NULL && !BER_BVISNULL( &rs->sr_ref[ 0 ] ) ) {
|
|
|
|
/* ignore return value by now */
|
2005-04-16 10:25:41 +08:00
|
|
|
savepriv = op->o_private;
|
|
|
|
op->o_private = (void *)i;
|
2004-12-31 01:45:07 +08:00
|
|
|
( void )send_search_reference( op, rs );
|
2005-04-16 10:25:41 +08:00
|
|
|
op->o_private = savepriv;
|
2004-12-31 01:45:07 +08:00
|
|
|
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
}
|
2002-08-31 18:35:23 +08:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
if ( references ) {
|
|
|
|
ldap_value_free( references );
|
|
|
|
}
|
|
|
|
|
2003-04-04 05:35:54 +08:00
|
|
|
if ( rs->sr_ctrls ) {
|
|
|
|
ldap_controls_free( rs->sr_ctrls );
|
|
|
|
rs->sr_ctrls = NULL;
|
2002-08-31 18:35:23 +08:00
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
} else if ( rc == LDAP_RES_SEARCH_RESULT ) {
|
2005-04-23 05:43:52 +08:00
|
|
|
char buf[ SLAP_TEXT_BUFLEN ];
|
|
|
|
char **references = NULL;
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-04-23 05:43:52 +08:00
|
|
|
if ( ldap_parse_result( msc->msc_ld,
|
|
|
|
res,
|
|
|
|
&candidates[ i ].sr_err,
|
|
|
|
(char **)&candidates[ i ].sr_matched,
|
|
|
|
NULL /* (char **)&candidates[ i ].sr_text */ ,
|
|
|
|
&references,
|
|
|
|
&candidates[ i ].sr_ctrls, 1 ) )
|
2005-01-08 17:20:54 +08:00
|
|
|
{
|
|
|
|
res = NULL;
|
2005-04-23 05:43:52 +08:00
|
|
|
ldap_get_option( msc->msc_ld,
|
|
|
|
LDAP_OPT_ERROR_NUMBER,
|
|
|
|
&rs->sr_err );
|
|
|
|
sres = slap_map_api2result( rs );
|
2005-01-08 17:20:54 +08:00
|
|
|
goto really_bad;
|
|
|
|
}
|
2005-04-23 05:43:52 +08:00
|
|
|
rs->sr_err = candidates[ i ].sr_err;
|
|
|
|
sres = slap_map_api2result( rs );
|
2004-03-06 23:01:16 +08:00
|
|
|
res = NULL;
|
|
|
|
|
2005-04-23 05:43:52 +08:00
|
|
|
/* massage matchedDN if need be */
|
|
|
|
if ( candidates[ i ].sr_matched != NULL ) {
|
|
|
|
if ( candidates[ i ].sr_matched[ 0 ] == '\0' ) {
|
|
|
|
ldap_memfree( (char *)candidates[ i ].sr_matched );
|
|
|
|
candidates[ i ].sr_matched = NULL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
struct berval match, mmatch;
|
|
|
|
|
|
|
|
ber_str2bv( candidates[ i ].sr_matched,
|
|
|
|
0, 0, &match );
|
|
|
|
|
|
|
|
dc.ctx = "matchedDN";
|
2005-05-05 07:57:55 +08:00
|
|
|
dc.target = &mi->mi_targets[ i ];
|
2005-04-23 05:43:52 +08:00
|
|
|
|
|
|
|
if ( !ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
|
|
|
|
if ( mmatch.bv_val == match.bv_val ) {
|
|
|
|
candidates[ i ].sr_matched = ch_strdup( mmatch.bv_val );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
candidates[ i ].sr_matched = mmatch.bv_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
candidate_match++;
|
|
|
|
}
|
|
|
|
ldap_memfree( match.bv_val );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* just get rid of the error message, if any */
|
|
|
|
if ( candidates[ i ].sr_text && candidates[ i ].sr_text[ 0 ] == '\0' )
|
|
|
|
{
|
|
|
|
ldap_memfree( (char *)candidates[ i ].sr_text );
|
|
|
|
candidates[ i ].sr_text = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add references to array */
|
|
|
|
if ( references ) {
|
|
|
|
BerVarray sr_ref;
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
for ( cnt = 0; references[ cnt ]; cnt++ )
|
|
|
|
;
|
|
|
|
|
|
|
|
sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
|
|
|
|
|
|
|
|
for ( cnt = 0; references[ cnt ]; cnt++ ) {
|
|
|
|
ber_str2bv( references[ cnt ], 0, 1, &sr_ref[ cnt ] );
|
|
|
|
}
|
|
|
|
BER_BVZERO( &sr_ref[ cnt ] );
|
|
|
|
|
|
|
|
( void )ldap_back_referral_result_rewrite( &dc, sr_ref );
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
ldap_value_free( references );
|
|
|
|
|
2005-04-26 07:54:51 +08:00
|
|
|
if ( rs->sr_v2ref == NULL ) {
|
|
|
|
rs->sr_v2ref = sr_ref;
|
2005-04-23 05:43:52 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) {
|
2005-04-26 07:54:51 +08:00
|
|
|
ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] );
|
2005-04-23 05:43:52 +08:00
|
|
|
}
|
|
|
|
ber_memfree( sr_ref );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->sr_err = candidates[ i ].sr_err;
|
2004-04-06 01:32:59 +08:00
|
|
|
sres = slap_map_api2result( rs );
|
2005-04-16 10:25:41 +08:00
|
|
|
switch ( sres ) {
|
|
|
|
case LDAP_NO_SUCH_OBJECT:
|
|
|
|
/* is_ok is touched any time a valid
|
|
|
|
* (even intermediate) result is
|
|
|
|
* returned; as a consequence, if
|
|
|
|
* a candidate returns noSuchObject
|
|
|
|
* it is ignored and the candidate
|
|
|
|
* is simply demoted. */
|
|
|
|
if ( is_ok ) {
|
|
|
|
sres = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_SUCCESS:
|
2005-04-26 07:54:51 +08:00
|
|
|
case LDAP_REFERRAL:
|
2005-04-16 10:25:41 +08:00
|
|
|
is_ok++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
snprintf( buf, sizeof( buf ),
|
|
|
|
"%s meta_back_search[%d] "
|
2005-04-23 05:43:52 +08:00
|
|
|
"match=\"%s\" err=%d\n",
|
2005-04-21 11:17:31 +08:00
|
|
|
op->o_log_prefix, i,
|
2005-04-23 05:43:52 +08:00
|
|
|
candidates[ i ].sr_matched ? candidates[ i ].sr_matched : "",
|
|
|
|
candidates[ i ].sr_err );
|
2005-04-21 11:17:31 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "%s", buf, 0, 0 );
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
last = i;
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When no candidates are left,
|
|
|
|
* the outer cycle finishes
|
|
|
|
*/
|
2005-04-22 06:22:43 +08:00
|
|
|
candidates[ i ].sr_msgid = -1;
|
2005-04-16 10:25:41 +08:00
|
|
|
--ncandidates;
|
2005-04-21 11:17:31 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
assert( 0 );
|
|
|
|
goto really_bad;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
/* check for abandon */
|
2005-04-23 05:43:52 +08:00
|
|
|
if ( op->o_abandon || doabandon ) {
|
2005-05-06 01:34:11 +08:00
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
|
|
|
metasingleconn_t *msc = &mc->mc_conns[ i ];
|
|
|
|
|
2005-04-23 05:43:52 +08:00
|
|
|
if ( candidates[ i ].sr_msgid != -1 ) {
|
|
|
|
ldap_abandon_ext( msc->msc_ld,
|
|
|
|
candidates[ i ].sr_msgid,
|
|
|
|
NULL, NULL );
|
2005-04-26 07:54:51 +08:00
|
|
|
candidates[ i ].sr_msgid = -1;
|
2005-04-23 05:43:52 +08:00
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-23 05:43:52 +08:00
|
|
|
if ( op->o_abandon ) {
|
|
|
|
rc = SLAPD_ABANDON;
|
|
|
|
goto finish;
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( gotit == 0 ) {
|
|
|
|
tv.tv_sec = 0;
|
2005-01-08 17:20:54 +08:00
|
|
|
tv.tv_usec = 100000; /* 0.1 s */
|
2001-05-12 08:51:28 +08:00
|
|
|
ldap_pvt_thread_yield();
|
2005-01-08 17:20:54 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc == -1 ) {
|
|
|
|
/*
|
2005-04-21 11:17:31 +08:00
|
|
|
* FIXME: need a better strategy to handle errors
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
rc = meta_back_op_result( mc, op, rs, META_TARGET_NONE );
|
2001-05-12 08:51:28 +08:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rewrite the matched portion of the search base, if required
|
|
|
|
*
|
|
|
|
* FIXME: only the last one gets caught!
|
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
if ( candidate_match > 0 && rs->sr_nentries > 0 ) {
|
|
|
|
/* we use the first one */
|
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
|
|
|
if ( candidates[ i ].sr_tag == META_CANDIDATE
|
|
|
|
&& candidates[ i ].sr_matched )
|
|
|
|
{
|
|
|
|
matched = (char *)candidates[ i ].sr_matched;
|
|
|
|
candidates[ i ].sr_matched = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
char cnd[BUFSIZ];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
2005-04-22 06:22:43 +08:00
|
|
|
if ( candidates[ i ].sr_tag == META_CANDIDATE ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
cnd[ i ] = '*';
|
|
|
|
} else {
|
|
|
|
cnd[ i ] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cnd[ i ] = '\0';
|
|
|
|
|
|
|
|
snprintf( buf, sizeof( buf ), "%s meta_back_search: is_scope=%d is_ok=%d cnd=\"%s\"\n",
|
|
|
|
op->o_log_prefix, initial_candidates, is_ok, cnd );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "%s", buf, 0, 0 );
|
2004-02-29 00:05:59 +08:00
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
#endif
|
2004-02-29 00:05:59 +08:00
|
|
|
|
2005-04-23 05:43:52 +08:00
|
|
|
/*
|
|
|
|
* In case we returned at least one entry, we return LDAP_SUCCESS
|
|
|
|
* otherwise, the latter error code we got
|
|
|
|
*
|
|
|
|
* FIXME: we should handle error codes and return the more
|
|
|
|
* important/reasonable
|
|
|
|
*/
|
|
|
|
|
2005-04-26 07:54:51 +08:00
|
|
|
if ( sres == LDAP_SUCCESS && rs->sr_v2ref ) {
|
2002-08-31 18:35:23 +08:00
|
|
|
sres = LDAP_REFERRAL;
|
|
|
|
}
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_err = sres;
|
2005-04-23 05:43:52 +08:00
|
|
|
rs->sr_matched = matched;
|
2005-04-26 07:54:51 +08:00
|
|
|
rs->sr_ref = ( sres == LDAP_REFERRAL ? rs->sr_v2ref : NULL );
|
2005-04-16 10:25:41 +08:00
|
|
|
savepriv = op->o_private;
|
2005-04-21 11:17:31 +08:00
|
|
|
op->o_private = (void *)mi->mi_ntargets;
|
2003-04-04 05:35:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2005-04-16 10:25:41 +08:00
|
|
|
op->o_private = savepriv;
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_matched = NULL;
|
2005-04-23 05:43:52 +08:00
|
|
|
rs->sr_ref = NULL;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2001-06-03 16:55:17 +08:00
|
|
|
finish:;
|
2005-04-23 05:43:52 +08:00
|
|
|
if ( matched ) {
|
|
|
|
free( matched );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2005-04-23 05:43:52 +08:00
|
|
|
|
2005-04-26 07:54:51 +08:00
|
|
|
if ( rs->sr_v2ref ) {
|
|
|
|
ber_bvarray_free( rs->sr_v2ref );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2005-04-23 05:43:52 +08:00
|
|
|
|
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
|
|
|
if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( candidates[ i ].sr_matched ) {
|
|
|
|
free( (char *)candidates[ i ].sr_matched );
|
|
|
|
candidates[ i ].sr_matched = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( candidates[ i ].sr_text ) {
|
|
|
|
ldap_memfree( (char *)candidates[ i ].sr_text );
|
|
|
|
candidates[ i ].sr_text = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( candidates[ i ].sr_ref ) {
|
|
|
|
ber_bvarray_free( candidates[ i ].sr_ref );
|
|
|
|
candidates[ i ].sr_ref = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( candidates[ i ].sr_ctrls ) {
|
|
|
|
ldap_controls_free( candidates[ i ].sr_ctrls );
|
|
|
|
candidates[ i ].sr_ctrls = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:00:33 +08:00
|
|
|
static int
|
2001-05-12 08:51:28 +08:00
|
|
|
meta_send_entry(
|
2005-04-21 11:17:31 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
2005-04-23 05:43:52 +08:00
|
|
|
metaconn_t *mc,
|
2005-04-21 11:17:31 +08:00
|
|
|
int target,
|
|
|
|
LDAPMessage *e )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
2002-01-04 00:29:38 +08:00
|
|
|
struct berval a, mapped;
|
2005-04-21 11:17:31 +08:00
|
|
|
Entry ent = { 0 };
|
2002-01-04 00:29:38 +08:00
|
|
|
BerElement ber = *e->lm_ber;
|
2001-12-27 20:17:54 +08:00
|
|
|
Attribute *attr, **attrp;
|
2002-01-04 00:29:38 +08:00
|
|
|
struct berval *bv, bdn;
|
2001-12-27 20:17:54 +08:00
|
|
|
const char *text;
|
2003-04-08 01:04:14 +08:00
|
|
|
dncookie dc;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2002-01-06 14:11:01 +08:00
|
|
|
if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) {
|
2002-08-14 01:00:33 +08:00
|
|
|
return LDAP_DECODING_ERROR;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rewrite the dn of the result, if needed
|
|
|
|
*/
|
2005-05-05 07:57:55 +08:00
|
|
|
dc.target = &mi->mi_targets[ target ];
|
2003-04-08 01:04:14 +08:00
|
|
|
dc.conn = op->o_conn;
|
|
|
|
dc.rs = rs;
|
|
|
|
dc.ctx = "searchResult";
|
|
|
|
|
|
|
|
rs->sr_err = ldap_back_dn_massage( &dc, &bdn, &ent.e_name );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS) {
|
|
|
|
return rs->sr_err;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2002-08-10 22:13:46 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
2003-04-30 02:28:14 +08:00
|
|
|
* FIXME: should we log anything, or delegate to dnNormalize?
|
2002-08-10 22:13:46 +08:00
|
|
|
*/
|
2003-04-30 02:28:14 +08:00
|
|
|
if ( dnNormalize( 0, NULL, NULL, &ent.e_name, &ent.e_nname,
|
2004-12-23 18:43:58 +08:00
|
|
|
op->o_tmpmemctx ) != LDAP_SUCCESS )
|
2003-04-30 02:28:14 +08:00
|
|
|
{
|
2002-08-14 01:00:33 +08:00
|
|
|
return LDAP_INVALID_DN_SYNTAX;
|
2002-08-10 22:13:46 +08:00
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* cache dn
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED ) {
|
|
|
|
( void )meta_dncache_update_entry( &mi->mi_cache,
|
2003-04-08 01:04:14 +08:00
|
|
|
&ent.e_nname, target );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attrp = &ent.e_attrs;
|
|
|
|
|
2003-04-08 03:01:48 +08:00
|
|
|
dc.ctx = "searchAttrDN";
|
2002-01-06 14:11:01 +08:00
|
|
|
while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
|
2003-10-05 01:18:25 +08:00
|
|
|
int last = 0;
|
|
|
|
|
2005-05-05 07:57:55 +08:00
|
|
|
ldap_back_map( &mi->mi_targets[ target ].mt_rwmap.rwm_at,
|
2003-01-28 00:39:56 +08:00
|
|
|
&a, &mapped, BACKLDAP_REMAP );
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
attr = ( Attribute * )ch_malloc( sizeof( Attribute ) );
|
|
|
|
if ( attr == NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
2002-01-14 07:23:23 +08:00
|
|
|
attr->a_flags = 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
attr->a_next = 0;
|
|
|
|
attr->a_desc = NULL;
|
2002-01-04 00:29:38 +08:00
|
|
|
if ( slap_bv2ad( &mapped, &attr->a_desc, &text )
|
2001-05-12 08:51:28 +08:00
|
|
|
!= LDAP_SUCCESS) {
|
2002-01-04 00:29:38 +08:00
|
|
|
if ( slap_bv2undef_ad( &mapped, &attr->a_desc, &text )
|
2005-04-21 11:17:31 +08:00
|
|
|
!= LDAP_SUCCESS )
|
|
|
|
{
|
|
|
|
char buf[ SLAP_TEXT_BUFLEN ];
|
|
|
|
|
|
|
|
snprintf( buf, sizeof( buf ),
|
|
|
|
"%s meta_send_entry(\"%s\"): "
|
|
|
|
"slap_bv2undef_ad(%s): %s\n",
|
|
|
|
op->o_log_prefix, ent.e_name.bv_val,
|
|
|
|
mapped.bv_val, text );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "%s", buf, 0, 0 );
|
2002-01-04 00:29:38 +08:00
|
|
|
ch_free( attr );
|
2001-10-04 02:17:08 +08:00
|
|
|
continue;
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2002-01-04 00:29:38 +08:00
|
|
|
|
2002-01-05 03:23:10 +08:00
|
|
|
/* no subschemaSubentry */
|
|
|
|
if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry ) {
|
2003-04-08 03:01:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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] */ );
|
|
|
|
|
2002-01-05 03:23:10 +08:00
|
|
|
ch_free(attr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-07-22 22:24:32 +08:00
|
|
|
if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
|
2005-04-27 05:48:43 +08:00
|
|
|
|| attr->a_vals == NULL )
|
|
|
|
{
|
2005-01-08 17:20:54 +08:00
|
|
|
attr->a_vals = (struct berval *)&slap_dummy_bv;
|
2002-07-22 22:24:32 +08:00
|
|
|
|
2002-01-05 03:23:10 +08:00
|
|
|
} else if ( attr->a_desc == slap_schema.si_ad_objectClass
|
2005-04-27 05:48:43 +08:00
|
|
|
|| attr->a_desc == slap_schema.si_ad_structuralObjectClass )
|
|
|
|
{
|
2005-04-16 10:25:41 +08:00
|
|
|
for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); ++last );
|
2003-03-01 19:08:53 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
for ( bv = attr->a_vals; !BER_BVISNULL( bv ); bv++ ) {
|
2005-05-05 07:57:55 +08:00
|
|
|
ldap_back_map( &mi->mi_targets[ target ].mt_rwmap.rwm_oc,
|
2003-01-28 00:39:56 +08:00
|
|
|
bv, &mapped, BACKLDAP_REMAP );
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0') {
|
2002-01-04 23:26:45 +08:00
|
|
|
free( bv->bv_val );
|
2005-04-16 10:25:41 +08:00
|
|
|
BER_BVZERO( bv );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( --last < 0 ) {
|
|
|
|
break;
|
|
|
|
}
|
2002-01-04 23:26:45 +08:00
|
|
|
*bv = attr->a_vals[ last ];
|
2005-04-16 10:25:41 +08:00
|
|
|
BER_BVZERO( &attr->a_vals[ last ] );
|
2003-03-01 19:08:53 +08:00
|
|
|
bv--;
|
2002-01-04 23:26:45 +08:00
|
|
|
|
2002-01-04 00:29:38 +08:00
|
|
|
} else if ( mapped.bv_val != bv->bv_val ) {
|
2002-01-06 14:11:01 +08:00
|
|
|
free( bv->bv_val );
|
2002-01-04 00:29:38 +08:00
|
|
|
ber_dupbv( bv, &mapped );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It is necessary to try to rewrite attributes with
|
|
|
|
* dn syntax because they might be used in ACLs as
|
|
|
|
* members of groups; since ACLs are applied to the
|
|
|
|
* rewritten stuff, no dn-based subecj clause could
|
|
|
|
* be used at the ldap backend side (see
|
|
|
|
* http://www.OpenLDAP.org/faq/data/cache/452.html)
|
|
|
|
* The problem can be overcome by moving the dn-based
|
|
|
|
* ACLs to the target directory server, and letting
|
|
|
|
* everything pass thru the ldap backend.
|
|
|
|
*/
|
2003-04-08 03:01:48 +08:00
|
|
|
} else if ( attr->a_desc->ad_type->sat_syntax ==
|
2005-01-21 01:44:53 +08:00
|
|
|
slap_schema.si_syn_distinguishedName )
|
|
|
|
{
|
2003-04-08 03:01:48 +08:00
|
|
|
ldap_dnattr_result_rewrite( &dc, attr->a_vals );
|
2004-12-31 01:45:07 +08:00
|
|
|
|
|
|
|
} else if ( attr->a_desc == slap_schema.si_ad_ref ) {
|
|
|
|
ldap_back_referral_result_rewrite( &dc, attr->a_vals );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-03-01 19:08:53 +08:00
|
|
|
|
2003-10-05 01:18:25 +08:00
|
|
|
if ( last && attr->a_desc->ad_type->sat_equality &&
|
|
|
|
attr->a_desc->ad_type->sat_equality->smr_normalize ) {
|
|
|
|
int i;
|
|
|
|
|
2005-04-23 05:43:52 +08:00
|
|
|
attr->a_nvals = ch_malloc( ( last + 1 ) * sizeof( struct berval ) );
|
2003-10-05 01:18:25 +08:00
|
|
|
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],
|
2004-12-23 18:43:58 +08:00
|
|
|
NULL );
|
2003-10-05 01:18:25 +08:00
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
BER_BVZERO( &attr->a_nvals[i] );
|
2005-04-19 22:31:07 +08:00
|
|
|
|
2003-10-05 01:18:25 +08:00
|
|
|
} else {
|
|
|
|
attr->a_nvals = attr->a_vals;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
*attrp = attr;
|
|
|
|
attrp = &attr->a_next;
|
|
|
|
}
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_entry = &ent;
|
2004-03-09 02:12:45 +08:00
|
|
|
rs->sr_attrs = op->ors_attrs;
|
2004-03-17 19:50:15 +08:00
|
|
|
rs->sr_flags = 0;
|
2003-04-04 05:35:54 +08:00
|
|
|
send_search_entry( op, rs );
|
|
|
|
rs->sr_entry = NULL;
|
|
|
|
rs->sr_attrs = NULL;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-05-21 22:53:05 +08:00
|
|
|
if ( !BER_BVISNULL( &ent.e_name ) ) {
|
|
|
|
if ( ent.e_name.bv_val != bdn.bv_val ) {
|
|
|
|
free( ent.e_name.bv_val );
|
|
|
|
}
|
2005-05-13 17:06:28 +08:00
|
|
|
BER_BVZERO( &ent.e_name );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2005-05-13 17:06:28 +08:00
|
|
|
if ( !BER_BVISNULL( &ent.e_nname ) ) {
|
|
|
|
free( ent.e_nname.bv_val );
|
|
|
|
BER_BVZERO( &ent.e_nname );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2005-05-13 17:06:28 +08:00
|
|
|
entry_clean( &ent );
|
2002-08-14 01:00:33 +08:00
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|