]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
5cbebd1b0eb910af33c91e5ed292e6c22821dd8b
[openldap] / servers / slapd / back-ldbm / group.c
1 /* compare.c - ldbm backend compare routine */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9
10 #include "slap.h"
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
13
14 extern Attribute        *attr_find();
15
16
17 #ifdef SLAPD_ACLGROUPS
18 /* return 0 IFF edn is a value in uniqueMember attribute
19  * of entry with bdn AND that entry has an objectClass
20  * value of groupOfNames
21  */
22 int
23 ldbm_back_group(
24         Backend     *be,
25         char        *bdn,
26         char        *edn
27 )
28 {
29         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
30         Entry        *e;
31         char        *matched;
32         Attribute   *objectClass;
33         Attribute   *member;
34         int          rc;
35
36         Debug( LDAP_DEBUG_TRACE, "=> ldbm_back_group: bdn: %s\n", bdn, 0, 0 ); 
37         Debug( LDAP_DEBUG_TRACE, "=> ldbm_back_group: edn: %s\n", edn, 0, 0 ); 
38
39         /* can we find bdn entry with reader lock */
40         if ((e = dn2entry_r(be, bdn, &matched )) == NULL) {
41                 Debug( LDAP_DEBUG_TRACE, "=> ldbm_back_group: cannot find bdn: %s matched: %x\n", bdn, matched, 0 ); 
42                 if (matched != NULL)
43                         free(matched);
44                 return( 1 );
45         }
46         Debug( LDAP_DEBUG_ARGS, "=> ldbm_back_group: found bdn: %s matched: %x\n", bdn, matched, 0 ); 
47
48         /* check for deleted */
49
50         /* find it's objectClass and member attribute values
51          * make sure this is a group entry
52          * finally test if we can find edn in the member attribute value list *
53          */
54         
55         rc = 1;
56         if ((objectClass = attr_find(e->e_attrs, "objectclass")) == NULL)  {
57             Debug( LDAP_DEBUG_TRACE, "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 ); 
58         }
59         else if ((member = attr_find(e->e_attrs, "member")) == NULL) {
60             Debug( LDAP_DEBUG_TRACE, "<= ldbm_back_group: failed to find member\n", 0, 0, 0 ); 
61         }
62         else {
63             struct berval bvObjectClass;
64             struct berval bvMembers;
65
66             Debug( LDAP_DEBUG_ARGS, "<= ldbm_back_group: found objectClass and members\n", 0, 0, 0 ); 
67
68             bvObjectClass.bv_val = "groupofnames";
69             bvObjectClass.bv_len = strlen( bvObjectClass.bv_val );         
70             bvMembers.bv_val = edn;
71             bvMembers.bv_len = strlen( edn );         
72
73             if (value_find(objectClass->a_vals, &bvObjectClass, SYNTAX_CIS, 1) != 0) {
74                 Debug( LDAP_DEBUG_TRACE,
75                                         "<= ldbm_back_group: failed to find objectClass in groupOfNames\n", 
76                         0, 0, 0 ); 
77             }
78             else if (value_find(member->a_vals, &bvMembers, SYNTAX_CIS, 1) != 0) {
79                 Debug( LDAP_DEBUG_ACL, "<= ldbm_back_group: %s not in %s: groupOfNames\n", 
80                         edn, bdn, 0 ); 
81             }
82             else {
83                 Debug( LDAP_DEBUG_ACL, "<= ldbm_back_group: %s is in %s: groupOfNames\n", 
84                         edn, bdn, 0 ); 
85                 rc = 0;
86             }
87         }
88
89         /* free entry and reader lock */
90         cache_return_entry_r( &li->li_cache, e );                 
91         Debug( LDAP_DEBUG_ARGS, "ldbm_back_group: rc: %d\n", rc, 0, 0 ); 
92         return(rc);
93 }
94 #endif
95