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 "slap.h"
|
|
|
|
#include "../back-ldap/back-ldap.h"
|
|
|
|
#include "back-meta.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* return 0 IFF we can retrieve the attributes
|
|
|
|
* of entry with e_ndn
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: I never testd this function; I know it compiles ... :)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
meta_back_attribute(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
Entry *target,
|
2001-12-27 20:17:54 +08:00
|
|
|
struct berval *ndn,
|
2001-05-12 08:51:28 +08:00
|
|
|
AttributeDescription *entry_at,
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray *vals
|
2001-05-12 08:51:28 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct metainfo *li = ( struct metainfo * )be->be_private;
|
|
|
|
int rc = 1, i, j, count, is_oc, candidate;
|
|
|
|
Attribute *attr;
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray abv, v;
|
2002-01-04 00:29:38 +08:00
|
|
|
char **vs;
|
|
|
|
struct berval mapped;
|
2001-05-12 08:51:28 +08:00
|
|
|
LDAPMessage *result, *e;
|
|
|
|
char *gattr[ 2 ];
|
|
|
|
LDAP *ld;
|
|
|
|
|
|
|
|
*vals = NULL;
|
2002-01-13 02:17:13 +08:00
|
|
|
if ( target != NULL && dn_match( &target->e_nname, ndn ) ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
/* we already have a copy of the entry */
|
|
|
|
/* attribute and objectclass mapping has already been done */
|
|
|
|
attr = attr_find( target->e_attrs, entry_at );
|
|
|
|
if ( attr == NULL ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-01-04 00:29:38 +08:00
|
|
|
for ( count = 0; attr->a_vals[ count ].bv_val != NULL; count++ )
|
2001-05-12 08:51:28 +08:00
|
|
|
;
|
2002-01-14 09:43:17 +08:00
|
|
|
v = ( BerVarray )ch_calloc( ( count + 1 ), sizeof( struct berval ) );
|
2002-01-04 00:29:38 +08:00
|
|
|
if ( v == NULL ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
|
|
|
|
if ( abv->bv_len > 0 ) {
|
|
|
|
ber_dupbv( &v[ j ], abv );
|
|
|
|
if ( v[ j ].bv_val == NULL ) {
|
|
|
|
break;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-01-04 00:29:38 +08:00
|
|
|
v[ j ].bv_val = NULL;
|
|
|
|
*vals = v;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2002-01-04 00:29:38 +08:00
|
|
|
return 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
} /* else */
|
|
|
|
|
2001-12-25 01:24:07 +08:00
|
|
|
candidate = meta_back_select_unique_candidate( li, ndn );
|
2005-01-08 17:20:54 +08:00
|
|
|
if ( candidate == META_TARGET_NONE ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-01-04 00:29:38 +08:00
|
|
|
ldap_back_map( &li->targets[ candidate ]->at_map,
|
2003-01-28 00:39:56 +08:00
|
|
|
&entry_at->ad_cname, &mapped, BACKLDAP_MAP );
|
2003-01-28 05:34:25 +08:00
|
|
|
if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' )
|
2001-05-12 08:51:28 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
rc = ldap_initialize( &ld, li->targets[ candidate ]->uri );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-12-29 12:48:00 +08:00
|
|
|
rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn.bv_val,
|
|
|
|
li->targets[ candidate ]->bindpw.bv_val, LDAP_AUTH_SIMPLE );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( rc != LDAP_SUCCESS) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-01-04 00:29:38 +08:00
|
|
|
gattr[ 0 ] = mapped.bv_val;
|
2001-05-12 08:51:28 +08:00
|
|
|
gattr[ 1 ] = NULL;
|
2001-12-27 20:17:54 +08:00
|
|
|
if ( ldap_search_ext_s( ld, ndn->bv_val, LDAP_SCOPE_BASE,
|
2002-01-04 00:29:38 +08:00
|
|
|
"(objectClass=*)",
|
2001-05-12 08:51:28 +08:00
|
|
|
gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
|
|
|
|
LDAP_NO_LIMIT, &result) == LDAP_SUCCESS) {
|
|
|
|
if ( ( e = ldap_first_entry( ld, result ) ) != NULL ) {
|
2002-01-04 00:29:38 +08:00
|
|
|
vs = ldap_get_values( ld, e, mapped.bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( vs != NULL ) {
|
|
|
|
for ( count = 0; vs[ count ] != NULL;
|
|
|
|
count++ ) { }
|
2002-01-14 09:43:17 +08:00
|
|
|
v = ( BerVarray )ch_calloc( ( count + 1 ),
|
2002-01-04 00:29:38 +08:00
|
|
|
sizeof( struct berval ) );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( v == NULL ) {
|
|
|
|
ldap_value_free( vs );
|
|
|
|
} else {
|
2002-01-04 00:29:38 +08:00
|
|
|
is_oc = ( strcasecmp( "objectclass", mapped.bv_val ) == 0 );
|
2001-05-12 08:51:28 +08:00
|
|
|
for ( i = 0, j = 0; i < count; i++ ) {
|
2002-01-04 00:29:38 +08:00
|
|
|
ber_str2bv( vs[ i ], 0, 0, &v[ j ] );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( !is_oc ) {
|
2002-01-04 00:29:38 +08:00
|
|
|
if ( v[ j ].bv_val == NULL ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
ch_free( vs[ i ] );
|
|
|
|
} else {
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
} else {
|
2003-01-28 00:39:56 +08:00
|
|
|
ldap_back_map( &li->targets[ candidate ]->oc_map, &v[ j ], &mapped, BACKLDAP_REMAP );
|
2003-01-28 05:34:25 +08:00
|
|
|
if ( mapped.bv_val && mapped.bv_val[0] != '\0' ) {
|
2002-01-04 00:29:38 +08:00
|
|
|
ber_dupbv( &v[ j ], &mapped );
|
|
|
|
if ( v[ j ].bv_val ) {
|
|
|
|
j++;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ch_free( vs[ i ] );
|
|
|
|
}
|
|
|
|
}
|
2002-01-04 00:29:38 +08:00
|
|
|
v[ j ].bv_val = NULL;
|
2001-05-12 08:51:28 +08:00
|
|
|
*vals = v;
|
|
|
|
rc = 0;
|
|
|
|
ch_free( vs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ldap_msgfree( result );
|
|
|
|
}
|
2002-01-04 00:29:38 +08:00
|
|
|
ldap_unbind( ld );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
return(rc);
|
|
|
|
}
|
|
|
|
|