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