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 op_dn is a value in member attribute
20 * of entry with gr_dn AND that entry has an objectClass
21 * value of groupOfNames
31 ObjectClass* group_oc,
32 AttributeDescription* group_at
35 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
45 AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
46 char *group_oc_name = NULL;
47 char *group_at_name = group_at->ad_cname->bv_val;
49 if( group_oc->soc_names && group_oc->soc_names[0] ) {
50 group_oc_name = group_oc->soc_names[0];
52 group_oc_name = group_oc->soc_oid;
55 if (target != NULL && strcmp(target->e_ndn, gr_ndn) == 0) {
56 /* we already have a copy of the entry */
57 /* attribute and objectclass mapping has already been done */
60 if( is_entry_objectclass( e, group_oc ) ) {
64 if ((attr = attr_find(e->e_attrs, group_at)) == NULL)
67 bv.bv_val = (char *) op_ndn;
68 bv.bv_len = strlen( op_ndn );
69 if( value_find( group_at, attr->a_vals, &bv ) == 0 )
73 group_oc_name = ldap_back_map(&li->oc_map, group_oc_name, 0);
74 if (group_oc_name == NULL)
76 group_at_name = ldap_back_map(&li->at_map, group_at_name, 0);
77 if (group_at_name == NULL)
80 filter = ch_malloc(sizeof("(&(objectclass=)(=))")
81 + strlen(group_oc_name)
82 + strlen(group_at_name)
83 + strlen(op_ndn) + 1);
87 if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
92 if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE) == LDAP_SUCCESS) {
93 strcpy(filter, "(&(objectclass=");
94 strcat(filter, group_oc_name);
96 strcat(filter, group_at_name);
98 strcat(filter, op_ndn);
101 gattr[0] = "objectclass";
103 if (ldap_search_ext_s(ld, gr_ndn, LDAP_SCOPE_BASE, filter,
104 gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
105 LDAP_NO_LIMIT, &result) == LDAP_SUCCESS)
107 if (ldap_first_entry(ld, result) != NULL)
109 ldap_msgfree(result);