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 group_at (member) attribute
20 * of entry with gr_dn AND that entry has an objectClass
21 * value of group_oc (groupOfNames)
31 ObjectClass* group_oc,
32 AttributeDescription* group_at
35 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
44 char *mop_ndn, *mgr_ndn;
46 AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
47 char *group_oc_name = NULL;
48 char *group_at_name = group_at->ad_cname->bv_val;
50 if( group_oc->soc_names && group_oc->soc_names[0] ) {
51 group_oc_name = group_oc->soc_names[0];
53 group_oc_name = group_oc->soc_oid;
56 if (target != NULL && strcmp(target->e_ndn, gr_ndn) == 0) {
57 /* we already have a copy of the entry */
58 /* attribute and objectclass mapping has already been done */
61 * first we need to check if the objectClass attribute
62 * has been retieved; otherwise we need to repeat the search
64 attr = attr_find( target->e_attrs, ad_objectClass );
68 * Now we can check for the group objectClass value
70 if( !is_entry_objectclass( target, group_oc ) ) {
75 * This part has been reworked: the group attr compare
76 * fails only if the attribute is PRESENT but the value
77 * is NOT PRESENT; if the attribute is NOT PRESENT, the
78 * search must be repeated as well.
79 * This may happen if a search for an entry has already
80 * been performed (target is not null) but the group
81 * attribute has not been required
83 if ((attr = attr_find(target->e_attrs, group_at)) != NULL) {
84 bv.bv_val = (char *) op_ndn;
85 bv.bv_len = strlen( op_ndn );
86 if( value_find( group_at, attr->a_vals, &bv ) != LDAP_SUCCESS )
89 } /* else: repeat the search */
90 } /* else: repeat the search */
91 } /* else: do the search */
94 * Rewrite the op ndn if needed
97 switch ( rewrite_session( li->rwinfo, "bindDn",
98 op_ndn, conn, &mop_ndn ) ) {
99 case REWRITE_REGEXEC_OK:
100 if ( mop_ndn == NULL ) {
101 mop_ndn = ( char * )op_ndn;
103 Debug( LDAP_DEBUG_ARGS,
104 "rw> bindDn (op ndn in group): \"%s\" -> \"%s\"\n%s",
105 op_ndn, mop_ndn, "" );
108 case REWRITE_REGEXEC_UNWILLING:
110 case REWRITE_REGEXEC_ERR:
115 * Rewrite the gr ndn if needed
117 switch ( rewrite_session( li->rwinfo, "searchBase",
118 gr_ndn, conn, &mgr_ndn ) ) {
119 case REWRITE_REGEXEC_OK:
120 if ( mgr_ndn == NULL ) {
121 mgr_ndn = ( char * )gr_ndn;
123 Debug( LDAP_DEBUG_ARGS,
124 "rw> searchBase (gr ndn in group):"
125 " \"%s\" -> \"%s\"\n%s",
126 gr_ndn, mgr_ndn, "" );
129 case REWRITE_REGEXEC_UNWILLING:
131 case REWRITE_REGEXEC_ERR:
134 #else /* !ENABLE_REWRITE */
135 mop_ndn = ldap_back_dn_massage( li, ch_strdup( op_ndn ), 1 );
136 if ( mop_ndn == NULL ) {
139 mgr_ndn = ldap_back_dn_massage( li, ch_strdup( gr_ndn ), 1 );
140 if ( mgr_ndn == NULL ) {
143 #endif /* !ENABLE_REWRITE */
145 group_oc_name = ldap_back_map(&li->oc_map, group_oc_name, 0);
146 if (group_oc_name == NULL)
148 group_at_name = ldap_back_map(&li->at_map, group_at_name, 0);
149 if (group_at_name == NULL)
152 filter = ch_malloc(sizeof("(&(objectclass=)(=))")
153 + strlen(group_oc_name)
154 + strlen(group_at_name)
155 + strlen(mop_ndn) + 1);
159 if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
163 if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE)
168 strcpy(filter, "(&(objectclass=");
169 strcat(filter, group_oc_name);
170 strcat(filter, ")(");
171 strcat(filter, group_at_name);
173 strcat(filter, mop_ndn);
174 strcat(filter, "))");
176 gattr[0] = "objectclass";
178 if (ldap_search_ext_s(ld, mgr_ndn, LDAP_SCOPE_BASE, filter,
179 gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
180 LDAP_NO_LIMIT, &result) == LDAP_SUCCESS) {
181 if (ldap_first_entry(ld, result) != NULL)
183 ldap_msgfree(result);
191 #ifdef ENABLE_REWRITE
192 if ( mop_ndn != op_ndn ) {
193 #endif /* ENABLE_REWRITE */
195 #ifdef ENABLE_REWRITE
197 if ( mgr_ndn != gr_ndn ) {
198 #endif /* ENABLE_REWRITE */
200 #ifdef ENABLE_REWRITE
202 #endif /* ENABLE_REWRITE */