2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
27 #include <ac/socket.h>
28 #include <ac/string.h>
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
35 /* return 0 IFF we can retrieve the attributes
40 * FIXME: I never testd this function; I know it compiles ... :)
49 AttributeDescription *entry_at,
53 struct metainfo *li = ( struct metainfo * )be->be_private;
54 int rc = 1, i, j, count, is_oc, candidate;
59 LDAPMessage *result, *e;
64 if ( target != NULL && dn_match( &target->e_nname, ndn ) ) {
65 /* we already have a copy of the entry */
66 /* attribute and objectclass mapping has already been done */
67 attr = attr_find( target->e_attrs, entry_at );
72 for ( count = 0; attr->a_vals[ count ].bv_val != NULL; count++ )
74 v = ( BerVarray )ch_calloc( ( count + 1 ), sizeof( struct berval ) );
79 for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
80 if ( abv->bv_len > 0 ) {
81 ber_dupbv( &v[ j ], abv );
82 if ( v[ j ].bv_val == NULL ) {
93 candidate = meta_back_select_unique_candidate( li, ndn );
94 if ( candidate == META_TARGET_NONE ) {
98 ldap_back_map( &li->targets[ candidate ]->at_map,
99 &entry_at->ad_cname, &mapped, BACKLDAP_MAP );
100 if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' )
103 rc = ldap_initialize( &ld, li->targets[ candidate ]->uri );
104 if ( rc != LDAP_SUCCESS ) {
108 rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn.bv_val,
109 li->targets[ candidate ]->bindpw.bv_val, LDAP_AUTH_SIMPLE );
110 if ( rc != LDAP_SUCCESS) {
114 gattr[ 0 ] = mapped.bv_val;
116 if ( ldap_search_ext_s( ld, ndn->bv_val, LDAP_SCOPE_BASE,
118 gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
119 LDAP_NO_LIMIT, &result) == LDAP_SUCCESS) {
120 if ( ( e = ldap_first_entry( ld, result ) ) != NULL ) {
121 vs = ldap_get_values( ld, e, mapped.bv_val );
123 for ( count = 0; vs[ count ] != NULL;
125 v = ( BerVarray )ch_calloc( ( count + 1 ),
126 sizeof( struct berval ) );
128 ldap_value_free( vs );
130 is_oc = ( strcasecmp( "objectclass", mapped.bv_val ) == 0 );
131 for ( i = 0, j = 0; i < count; i++ ) {
132 ber_str2bv( vs[ i ], 0, 0, &v[ j ] );
134 if ( v[ j ].bv_val == NULL ) {
140 ldap_back_map( &li->targets[ candidate ]->oc_map, &v[ j ], &mapped, BACKLDAP_REMAP );
141 if ( mapped.bv_val && mapped.bv_val[0] != '\0' ) {
142 ber_dupbv( &v[ j ], &mapped );
143 if ( v[ j ].bv_val ) {
150 v[ j ].bv_val = NULL;
157 ldap_msgfree( result );