]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
c92998719147c5c0f246ced560cbc00bb250708d
[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
44 #ifdef SLAPD_SCHEMA_NOT_COMPAT
45         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
46         const char *group_oc_name = NULL;
47         const char *group_at_name = group_at->ad_cname->bv_val;
48
49         if( group_oc->soc_names && group_oc->soc_names[0] ) {
50                 group_oc_name = group_oc->soc_names[0];
51         } else {
52                 group_oc_name = group_oc->soc_oid;
53         }
54 #else
55         struct berval bv;
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         if ((attr = attr_find(e->e_attrs, ad_objectClass)) == NULL)  {
104                 Debug( LDAP_DEBUG_ACL,
105                         "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 );
106                 goto return_results;
107         }
108         
109 #ifdef SLAPD_SCHEMA_NOT_COMPAT
110         /* not yet implemented */
111 #else
112
113         bv.bv_val = "ALIAS";
114         bv.bv_len = sizeof("ALIAS")-1;
115
116         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
117                 Debug( LDAP_DEBUG_ACL,
118                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
119                 goto return_results;
120         }
121
122         bv.bv_val = "REFERRAL";
123         bv.bv_len = sizeof("REFERRAL")-1;
124
125         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
126                 Debug( LDAP_DEBUG_ACL,
127                         "<= ldbm_back_group: group is a referral\n",
128                         0, 0, 0 );
129                 goto return_results;
130         }
131
132         bv.bv_val = (char *) group_oc_name;
133         bv.bv_len = strlen( bv.bv_val );         
134
135         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
136                 Debug( LDAP_DEBUG_ACL,
137                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
138                                 group_oc_name, 0, 0 ); 
139                 goto return_results;
140         }
141
142         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
143                 Debug( LDAP_DEBUG_ACL,
144                         "<= ldbm_back_group: failed to find %s\n",
145                         group_at_name, 0, 0 ); 
146                 goto return_results;
147         }
148
149         Debug( LDAP_DEBUG_ACL,
150                 "<= ldbm_back_group: found objectClass %s and %s\n",
151                 group_oc_name, group_at_name, 0 ); 
152
153         bv.bv_val = (char *) op_ndn;
154         bv.bv_len = strlen( op_ndn );         
155
156         if( value_find( attr->a_vals, &bv, attr->a_syntax, 1) != 0 )
157         {
158                 Debug( LDAP_DEBUG_ACL,
159                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
160                         op_ndn, gr_ndn, group_at_name ); 
161                 goto return_results;
162         }
163 #endif
164
165         Debug( LDAP_DEBUG_ACL,
166                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
167                 op_ndn, gr_ndn, group_at_name ); 
168
169         rc = 0;
170
171 return_results:
172         if( target != e ) {
173                 /* free entry and reader lock */
174                 cache_return_entry_r( &li->li_cache, e );                 
175         }
176
177         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
178         return(rc);
179 }
180