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