]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
Another round of changes behind -DSLAPD_SCHEMA_NOT_COMPAT
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 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         const char      *objectclassValue,
31 #ifdef SLAPD_SCHEMA_NOT_COMPAT
32         AttributeDescription *group_at
33 #else
34         const char      *group_at
35 #endif
36 )
37 {
38         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
39         Entry        *e;
40         int          rc = 1;
41         Attribute   *attr;
42
43 #ifdef SLAPD_SCHEMA_NOT_COMPAT
44         static AttributeDescription *objectClass = NULL;
45         const char *groupattrName = group_at->ad_cname->bv_val;
46 #else
47         struct berval bv;
48         const char *objectClass = "objectclass";
49         const char *groupattrName = group_at;
50 #endif
51
52         Debug( LDAP_DEBUG_ARGS,
53                 "=> ldbm_back_group: gr dn: \"%s\"\n",
54                 gr_ndn, 0, 0 ); 
55         Debug( LDAP_DEBUG_ARGS,
56                 "=> ldbm_back_group: op dn: \"%s\"\n",
57                 op_ndn, 0, 0 ); 
58         Debug( LDAP_DEBUG_ARGS,
59                 "=> ldbm_back_group: objectClass: \"%s\" attrName: \"%s\"\n", 
60                 objectclassValue, groupattrName, 0 ); 
61
62         Debug( LDAP_DEBUG_ARGS,
63                 "=> ldbm_back_group: tr dn: \"%s\"\n",
64                 target->e_ndn, 0, 0 ); 
65
66         if (strcmp(target->e_ndn, gr_ndn) == 0) {
67                 /* we already have a LOCKED copy of the entry */
68                 e = target;
69                 Debug( LDAP_DEBUG_ARGS,
70                         "=> ldbm_back_group: target is group: \"%s\"\n",
71                         gr_ndn, 0, 0 );
72
73         } else {
74                 /* can we find group entry with reader lock */
75                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
76                         Debug( LDAP_DEBUG_ACL,
77                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
78                                         gr_ndn, 0, 0 ); 
79                         return( 1 );
80                 }
81                 
82                 Debug( LDAP_DEBUG_ACL,
83                         "=> ldbm_back_group: found group: \"%s\"\n",
84                         gr_ndn, 0, 0 ); 
85     }
86
87         /* find it's objectClass and member attribute values
88          * make sure this is a group entry
89          * finally test if we can find op_dn in the member attribute value list *
90          */
91         
92         rc = 1;
93         
94         if ((attr = attr_find(e->e_attrs, objectClass)) == NULL)  {
95                 Debug( LDAP_DEBUG_ACL,
96                         "<= ldbm_back_group: failed to find objectClass\n", 0, 0, 0 );
97                 goto return_results;
98         }
99         
100 #ifdef SLAPD_SCHEMA_NOT_COMPAT
101         /* not yet implemented */
102 #else
103
104         bv.bv_val = "ALIAS";
105         bv.bv_len = sizeof("ALIAS")-1;
106
107         if ( value_find(attr->a_vals, &bv, attr->a_syntax, 1) == 0) {
108                 Debug( LDAP_DEBUG_ACL,
109                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
110                 goto return_results;
111         }
112
113         bv.bv_val = "REFERRAL";
114         bv.bv_len = sizeof("REFERRAL")-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 a referral\n",
119                         0, 0, 0 );
120                 goto return_results;
121         }
122
123         bv.bv_val = (char *) objectclassValue;
124         bv.bv_len = strlen( bv.bv_val );         
125
126         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
127                 Debug( LDAP_DEBUG_ACL,
128                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
129                                 objectclassValue, 0, 0 ); 
130                 goto return_results;
131         }
132
133         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
134                 Debug( LDAP_DEBUG_ACL,
135                         "<= ldbm_back_group: failed to find %s\n",
136                         groupattrName, 0, 0 ); 
137                 goto return_results;
138         }
139
140         Debug( LDAP_DEBUG_ACL,
141                 "<= ldbm_back_group: found objectClass %s and %s\n",
142                 objectclassValue, groupattrName, 0 ); 
143
144         bv.bv_val = (char *) op_ndn;
145         bv.bv_len = strlen( op_ndn );         
146
147         if( value_find( attr->a_vals, &bv, attr->a_syntax, 1) != 0 )
148         {
149                 Debug( LDAP_DEBUG_ACL,
150                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
151                         op_ndn, gr_ndn, groupattrName ); 
152                 goto return_results;
153         }
154 #endif
155
156         Debug( LDAP_DEBUG_ACL,
157                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
158                 op_ndn, gr_ndn, groupattrName ); 
159
160         rc = 0;
161
162 return_results:
163         if( target != e ) {
164                 /* free entry and reader lock */
165                 cache_return_entry_r( &li->li_cache, e );                 
166         }
167
168         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
169         return(rc);
170 }
171