]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
252b584166d024f8560a7e7e72662a4323c579cc
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/socket.h>
12 #include <ac/string.h>
13
14 #include "slap.h"
15 #include "back-ldbm.h"
16 #include "proto-back-ldbm.h"
17
18
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
22  */
23 int
24 ldbm_back_group(
25         Backend *be,
26         Entry   *target,
27         char    *gr_ndn,
28         char    *op_ndn,
29         char    *objectclassValue,
30         char    *groupattrName
31 )
32 {
33         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
34         Entry        *e;
35         int          rc = 1;
36
37         Attribute   *attr;
38         struct berval bv;
39
40         Debug( LDAP_DEBUG_ARGS,
41                 "=> ldbm_back_group: gr dn: \"%s\"\n",
42                 gr_ndn, 0, 0 ); 
43         Debug( LDAP_DEBUG_ARGS,
44                 "=> ldbm_back_group: op dn: \"%s\"\n",
45                 op_ndn, 0, 0 ); 
46         Debug( LDAP_DEBUG_ARGS,
47                 "=> ldbm_back_group: objectClass: \"%s\" attrName: \"%s\"\n", 
48                 objectclassValue, groupattrName, 0 ); 
49
50         Debug( LDAP_DEBUG_ARGS,
51                 "=> ldbm_back_group: tr dn: \"%s\"\n",
52                 target->e_ndn, 0, 0 ); 
53
54         if (strcmp(target->e_ndn, gr_ndn) == 0) {
55                 /* we already have a LOCKED copy of the entry */
56                 e = target;
57                 Debug( LDAP_DEBUG_ARGS,
58                         "=> ldbm_back_group: target is group: \"%s\"\n",
59                         gr_ndn, 0, 0 );
60
61         } else {
62                 /* can we find group entry with reader lock */
63                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
64                         Debug( LDAP_DEBUG_ACL,
65                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
66                                         gr_ndn, 0, 0 ); 
67                         return( 1 );
68                 }
69                 
70                 Debug( LDAP_DEBUG_ACL,
71                         "=> ldbm_back_group: found group: \"%s\"\n",
72                         gr_ndn, 0, 0 ); 
73     }
74
75         /* find it's objectClass and member attribute values
76          * make sure this is a group entry
77          * finally test if we can find op_dn in the member attribute value list *
78          */
79         
80         rc = 1;
81         
82         if ((attr = attr_find(e->e_attrs, "objectclass")) == NULL)  {
83                 Debug( LDAP_DEBUG_ACL,
84                         "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 );
85                 goto return_results;
86         }
87         
88         bv.bv_val = "ALIAS";
89         bv.bv_len = sizeof("ALIAS")-1;
90
91         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
92                 Debug( LDAP_DEBUG_ACL,
93                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
94                 goto return_results;
95         }
96
97         bv.bv_val = "REFERRAL";
98         bv.bv_len = sizeof("REFERRAL")-1;
99
100         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
101                 Debug( LDAP_DEBUG_ACL,
102                         "<= ldbm_back_group: group is a referral\n",
103                         0, 0, 0 );
104                 goto return_results;
105         }
106
107         bv.bv_val = objectclassValue;
108         bv.bv_len = strlen( bv.bv_val );         
109
110         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
111                 Debug( LDAP_DEBUG_ACL,
112                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
113                                 objectclassValue, 0, 0 ); 
114                 goto return_results;
115         }
116
117         if ((attr = attr_find(e->e_attrs, groupattrName)) == NULL) {
118                 Debug( LDAP_DEBUG_ACL,
119                         "<= ldbm_back_group: failed to find %s\n",
120                         groupattrName, 0, 0 ); 
121                 goto return_results;
122         }
123
124         Debug( LDAP_DEBUG_ACL,
125                 "<= ldbm_back_group: found objectClass %s and %s\n",
126                 objectclassValue, groupattrName, 0 ); 
127
128         bv.bv_val = op_ndn;
129         bv.bv_len = strlen( op_ndn );         
130
131         if( value_find( attr->a_vals, &bv, attr->a_syntax, 1) != 0 )
132         {
133                 Debug( LDAP_DEBUG_ACL,
134                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
135                         op_ndn, gr_ndn, groupattrName ); 
136                 goto return_results;
137         }
138
139         Debug( LDAP_DEBUG_ACL,
140                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
141                 op_ndn, gr_ndn, groupattrName ); 
142
143         rc = 0;
144
145 return_results:
146         if( target != e ) {
147                 /* free entry and reader lock */
148                 cache_return_entry_r( &li->li_cache, e );                 
149         }
150
151         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
152         return(rc);
153 }
154