]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
Complete group ACL impl. under new schema code
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
18
19
20 /* return 0 IFF op_dn is a value in member attribute
21  * of entry with gr_dn AND that entry has an objectClass
22  * value of groupOfNames
23  */
24 int
25 ldbm_back_group(
26         Backend *be,
27         Entry   *target,
28         const char      *gr_ndn,
29         const char      *op_ndn,
30 #ifdef SLAPD_SCHEMA_NOT_COMPAT
31         ObjectClass *group_oc,
32         AttributeDescription *group_at
33 #else
34         const char      *group_oc,
35         const char      *group_at
36 #endif
37 )
38 {
39         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
40         Entry        *e;
41         int          rc = 1;
42         Attribute   *attr;
43         struct berval bv;
44
45 #ifdef SLAPD_SCHEMA_NOT_COMPAT
46         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
47         const char *group_oc_name = NULL;
48         const char *group_at_name = group_at->ad_cname->bv_val;
49
50         if( group_oc->soc_names && group_oc->soc_names[0] ) {
51                 group_oc_name = group_oc->soc_names[0];
52         } else {
53                 group_oc_name = group_oc->soc_oid;
54         }
55 #else
56         const char *ad_objectClass = "objectclass";
57         const char *group_oc_name = group_oc;
58         const char *group_at_name = group_at;
59 #endif
60
61         Debug( LDAP_DEBUG_ARGS,
62                 "=> ldbm_back_group: gr dn: \"%s\"\n",
63                 gr_ndn, 0, 0 ); 
64         Debug( LDAP_DEBUG_ARGS,
65                 "=> ldbm_back_group: op dn: \"%s\"\n",
66                 op_ndn, 0, 0 ); 
67         Debug( LDAP_DEBUG_ARGS,
68                 "=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n", 
69                 group_oc_name, group_at_name, 0 ); 
70
71         Debug( LDAP_DEBUG_ARGS,
72                 "=> ldbm_back_group: tr dn: \"%s\"\n",
73                 target->e_ndn, 0, 0 ); 
74
75         if (strcmp(target->e_ndn, gr_ndn) == 0) {
76                 /* we already have a LOCKED copy of the entry */
77                 e = target;
78                 Debug( LDAP_DEBUG_ARGS,
79                         "=> ldbm_back_group: target is group: \"%s\"\n",
80                         gr_ndn, 0, 0 );
81
82         } else {
83                 /* can we find group entry with reader lock */
84                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
85                         Debug( LDAP_DEBUG_ACL,
86                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
87                                         gr_ndn, 0, 0 ); 
88                         return( 1 );
89                 }
90                 
91                 Debug( LDAP_DEBUG_ACL,
92                         "=> ldbm_back_group: found group: \"%s\"\n",
93                         gr_ndn, 0, 0 ); 
94     }
95
96         /* find it's objectClass and member attribute values
97          * make sure this is a group entry
98          * finally test if we can find op_dn in the member attribute value list *
99          */
100         
101         rc = 1;
102         
103         
104 #ifdef SLAPD_SCHEMA_NOT_COMPAT
105         if( is_entry_alias( e ) ) {
106                 Debug( LDAP_DEBUG_ACL,
107                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
108                 goto return_results;
109         }
110
111         if( is_entry_referral( e ) ) {
112                 Debug( LDAP_DEBUG_ACL,
113                         "<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
114                 goto return_results;
115         }
116
117         if( is_entry_objectclass( e, group_oc ) ) {
118                 Debug( LDAP_DEBUG_ACL,
119                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
120                                 group_oc_name, 0, 0 ); 
121                 goto return_results;
122         }
123
124         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
125                 Debug( LDAP_DEBUG_ACL,
126                         "<= ldbm_back_group: failed to find %s\n",
127                         group_at_name, 0, 0 ); 
128                 goto return_results;
129         }
130
131         Debug( LDAP_DEBUG_ACL,
132                 "<= ldbm_back_group: found objectClass %s and %s\n",
133                 group_oc_name, group_at_name, 0 ); 
134
135         bv.bv_val = (char *) op_ndn;
136         bv.bv_len = strlen( op_ndn );         
137
138         if( value_find( group_at, attr->a_vals, &bv ) == 0 ) {
139                 Debug( LDAP_DEBUG_ACL,
140                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
141                         op_ndn, gr_ndn, group_at_name ); 
142                 goto return_results;
143         }
144
145 #else
146         if ((attr = attr_find(e->e_attrs, ad_objectClass)) == NULL)  {
147                 Debug( LDAP_DEBUG_ACL,
148                         "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 );
149                 goto return_results;
150         }
151
152         bv.bv_val = "ALIAS";
153         bv.bv_len = sizeof("ALIAS")-1;
154
155         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
156                 Debug( LDAP_DEBUG_ACL,
157                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
158                 goto return_results;
159         }
160
161         bv.bv_val = "REFERRAL";
162         bv.bv_len = sizeof("REFERRAL")-1;
163
164         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
165                 Debug( LDAP_DEBUG_ACL,
166                         "<= ldbm_back_group: group is a referral\n",
167                         0, 0, 0 );
168                 goto return_results;
169         }
170
171         bv.bv_val = (char *) group_oc_name;
172         bv.bv_len = strlen( bv.bv_val );         
173
174         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
175                 Debug( LDAP_DEBUG_ACL,
176                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
177                                 group_oc_name, 0, 0 ); 
178                 goto return_results;
179         }
180
181         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
182                 Debug( LDAP_DEBUG_ACL,
183                         "<= ldbm_back_group: failed to find %s\n",
184                         group_at_name, 0, 0 ); 
185                 goto return_results;
186         }
187
188         Debug( LDAP_DEBUG_ACL,
189                 "<= ldbm_back_group: found objectClass %s and %s\n",
190                 group_oc_name, group_at_name, 0 ); 
191
192         bv.bv_val = (char *) op_ndn;
193         bv.bv_len = strlen( op_ndn );         
194
195         if( value_find( attr->a_vals, &bv, attr->a_syntax, 1) != 0 )
196         {
197                 Debug( LDAP_DEBUG_ACL,
198                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
199                         op_ndn, gr_ndn, group_at_name ); 
200                 goto return_results;
201         }
202 #endif
203
204
205         Debug( LDAP_DEBUG_ACL,
206                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
207                 op_ndn, gr_ndn, group_at_name ); 
208
209         rc = 0;
210
211 return_results:
212         if( target != e ) {
213                 /* free entry and reader lock */
214                 cache_return_entry_r( &li->li_cache, e );                 
215         }
216
217         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
218         return(rc);
219 }
220