1 /* group.c - ldap backend acl group routine */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
16 #include "back-ldap.h"
19 /* return 0 IFF we can retrieve the attributes
29 AttributeDescription *entry_at,
33 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
34 int rc = 1, i, j, count, is_oc;
35 Attribute *attr = NULL;
37 struct berval mapped = { 0, NULL };
39 LDAPMessage *result = NULL, *e = NULL;
44 if (target != NULL && dn_match( &target->e_nname, ndn )) {
45 /* we already have a copy of the entry */
46 /* attribute and objectclass mapping has already been done */
47 if ((attr = attr_find(target->e_attrs, entry_at)) == NULL)
50 for ( count = 0; attr->a_vals[count].bv_val != NULL; count++ ) { }
51 v = (BerVarray) ch_calloc( (count + 1), sizeof(struct berval) );
53 for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
54 if ( abv->bv_len > 0 ) {
55 ber_dupbv( &v[j], abv );
56 if( v[j].bv_val == NULL )
66 ldap_back_map(&li->at_map, &entry_at->ad_cname, &mapped, 0);
67 if (mapped.bv_val == NULL) {
71 if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
75 if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) {
79 gattr[0] = mapped.bv_val;
81 if (ldap_search_ext_s(ld, ndn->bv_val, LDAP_SCOPE_BASE, "(objectclass=*)",
82 gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
83 LDAP_NO_LIMIT, &result) != LDAP_SUCCESS)
88 if ((e = ldap_first_entry(ld, result)) == NULL) {
92 vs = ldap_get_values(ld, e, mapped.bv_val);
97 for ( count = 0; vs[count] != NULL; count++ ) { }
98 v = (BerVarray) ch_calloc( (count + 1), sizeof(struct berval) );
103 is_oc = (strcasecmp("objectclass", mapped.bv_val) == 0);
104 for ( i = 0, j = 0; i < count; i++) {
105 ber_str2bv(vs[i], 0, 0, &v[j] );
107 if( v[j].bv_val == NULL )
112 ldap_back_map(&li->oc_map, &v[j], &mapped, 1);
114 ber_dupbv( &v[j], &mapped );
132 ldap_msgfree(result);