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