2000-06-22 02:23:38 +08:00
|
|
|
/* group.c - ldap backend acl group routine */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldap.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* return 0 IFF we can retrieve the attributes
|
|
|
|
* of entry with e_ndn
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_back_attribute(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
Entry *target,
|
|
|
|
const char *e_ndn,
|
|
|
|
AttributeDescription *entry_at,
|
2000-06-28 13:26:17 +08:00
|
|
|
struct berval ***vals
|
2000-06-22 02:23:38 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
|
2001-02-20 03:14:12 +08:00
|
|
|
int rc = 1, i, j, count, is_oc;
|
2000-06-22 02:23:38 +08:00
|
|
|
Attribute *attr;
|
2000-06-28 13:26:17 +08:00
|
|
|
struct berval **abv, **v;
|
2001-02-20 03:14:12 +08:00
|
|
|
char **vs, *mapped;
|
2000-06-22 02:23:38 +08:00
|
|
|
LDAPMessage *result, *e;
|
|
|
|
char *gattr[2];
|
|
|
|
LDAP *ld;
|
|
|
|
|
|
|
|
*vals = NULL;
|
|
|
|
if (target != NULL && strcmp(target->e_ndn, e_ndn) == 0) {
|
|
|
|
/* we already have a copy of the entry */
|
2001-02-20 03:14:12 +08:00
|
|
|
/* attribute and objectclass mapping has already been done */
|
2000-06-22 02:23:38 +08:00
|
|
|
if ((attr = attr_find(target->e_attrs, entry_at)) == NULL)
|
|
|
|
return(1);
|
|
|
|
|
2000-06-28 13:26:17 +08:00
|
|
|
for ( count = 0; attr->a_vals[count] != NULL; count++ ) { }
|
|
|
|
v = (struct berval **) ch_calloc( (count + 1), sizeof(struct berval *) );
|
2000-06-22 02:23:38 +08:00
|
|
|
if (v != NULL) {
|
2000-06-28 13:26:17 +08:00
|
|
|
for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
|
2000-06-22 02:23:38 +08:00
|
|
|
if ( (*abv)->bv_len > 0 ) {
|
2000-06-28 13:26:17 +08:00
|
|
|
v[j] = ber_bvdup( *abv );
|
|
|
|
if( v[j] == NULL )
|
2000-06-22 02:23:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v[j] = NULL;
|
|
|
|
*vals = v;
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2001-02-20 03:14:12 +08:00
|
|
|
mapped = ldap_back_map(&li->at_map, entry_at->ad_cname->bv_val, 0);
|
|
|
|
if (mapped == NULL)
|
|
|
|
return(1);
|
|
|
|
|
2000-06-22 02:23:38 +08:00
|
|
|
if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE) == LDAP_SUCCESS) {
|
2001-02-20 03:14:12 +08:00
|
|
|
gattr[0] = mapped;
|
2000-06-22 02:23:38 +08:00
|
|
|
gattr[1] = NULL;
|
|
|
|
if (ldap_search_ext_s(ld, e_ndn, LDAP_SCOPE_BASE, "(objectclass=*)",
|
|
|
|
gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
|
|
|
|
LDAP_NO_LIMIT, &result) == LDAP_SUCCESS)
|
|
|
|
{
|
|
|
|
if ((e = ldap_first_entry(ld, result)) != NULL) {
|
2001-02-20 03:14:12 +08:00
|
|
|
vs = ldap_get_values(ld, e, mapped);
|
2000-06-28 13:26:17 +08:00
|
|
|
if (vs != NULL) {
|
|
|
|
for ( count = 0; vs[count] != NULL; count++ ) { }
|
|
|
|
v = (struct berval **) ch_calloc( (count + 1), sizeof(struct berval *) );
|
|
|
|
if (v == NULL) {
|
|
|
|
ldap_value_free(vs);
|
|
|
|
} else {
|
2001-02-20 03:14:12 +08:00
|
|
|
is_oc = (strcasecmp("objectclass", mapped) == 0);
|
2000-06-28 13:26:17 +08:00
|
|
|
for ( i = 0, j = 0; i < count; i++) {
|
2001-02-20 03:14:12 +08:00
|
|
|
if (!is_oc) {
|
|
|
|
v[j] = ber_bvstr( vs[i] );
|
|
|
|
if( v[j] == NULL )
|
|
|
|
ch_free(vs[i]);
|
|
|
|
else
|
|
|
|
j++;
|
|
|
|
} else {
|
|
|
|
mapped = ldap_back_map(&li->oc_map, vs[i], 1);
|
|
|
|
if (mapped) {
|
|
|
|
mapped = ch_strdup( mapped );
|
|
|
|
if (mapped) {
|
|
|
|
v[j] = ber_bvstr( mapped );
|
|
|
|
if (v[j])
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
2000-06-28 13:26:17 +08:00
|
|
|
ch_free(vs[i]);
|
2001-02-20 03:14:12 +08:00
|
|
|
}
|
2000-06-28 13:26:17 +08:00
|
|
|
}
|
|
|
|
v[j] = NULL;
|
|
|
|
*vals = v;
|
|
|
|
rc = 0;
|
|
|
|
ch_free(vs);
|
|
|
|
}
|
|
|
|
}
|
2000-06-22 02:23:38 +08:00
|
|
|
}
|
|
|
|
ldap_msgfree(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ldap_unbind(ld);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(rc);
|
|
|
|
}
|
|
|
|
|