1 /* group.c - ldap backend acl group routine */
4 * Copyright 1998-1999 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;
36 struct berval **abv, **v;
38 LDAPMessage *result, *e;
43 if (target != NULL && strcmp(target->e_ndn, e_ndn) == 0) {
44 /* we already have a copy of the entry */
45 /* attribute and objectclass mapping has already been done */
46 if ((attr = attr_find(target->e_attrs, entry_at)) == NULL)
49 for ( count = 0; attr->a_vals[count] != NULL; count++ ) { }
50 v = (struct berval **) ch_calloc( (count + 1), sizeof(struct berval *) );
52 for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
53 if ( (*abv)->bv_len > 0 ) {
54 v[j] = ber_bvdup( *abv );
65 mapped = ldap_back_map(&li->at_map, entry_at->ad_cname->bv_val, 0);
69 if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
73 if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE) == LDAP_SUCCESS) {
76 if (ldap_search_ext_s(ld, e_ndn, LDAP_SCOPE_BASE, "(objectclass=*)",
77 gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
78 LDAP_NO_LIMIT, &result) == LDAP_SUCCESS)
80 if ((e = ldap_first_entry(ld, result)) != NULL) {
81 vs = ldap_get_values(ld, e, mapped);
83 for ( count = 0; vs[count] != NULL; count++ ) { }
84 v = (struct berval **) ch_calloc( (count + 1), sizeof(struct berval *) );
88 is_oc = (strcasecmp("objectclass", mapped) == 0);
89 for ( i = 0, j = 0; i < count; i++) {
91 v[j] = ber_bvstr( vs[i] );
97 mapped = ldap_back_map(&li->oc_map, vs[i], 1);
99 mapped = ch_strdup( mapped );
101 v[j] = ber_bvstr( mapped );
116 ldap_msgfree(result);