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