]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/group.c
Move the input data exhaustion loop to connection.c from daemon.c
[openldap] / servers / slapd / back-bdb2 / group.c
1 /* group.c - bdb2 backend acl group routine */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9
10 #include "slap.h"
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
13
14
15 /* return 0 IFF op_dn is a value in member attribute
16  * of entry with gr_dn AND that entry has an objectClass
17  * value of groupOfNames
18  */
19 static int
20 bdb2i_back_group_internal(
21         BackendDB       *be,
22         Entry   *target,
23         char    *gr_ndn,
24         char    *op_ndn,
25         char    *objectclassValue,
26         char    *groupattrName
27 )
28 {
29         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
30         Entry *e;
31         int rc = 1;
32         Attribute *attr;
33         struct berval bv;
34
35         Debug( LDAP_DEBUG_ARGS,
36                 "=> bdb2i_back_group: gr dn: \"%s\"\n",
37                 gr_ndn, 0, 0 ); 
38         Debug( LDAP_DEBUG_ARGS,
39                 "=> bdb2i_back_group: op dn: \"%s\"\n",
40                 op_ndn, 0, 0 ); 
41         Debug( LDAP_DEBUG_ARGS,
42                 "=> bdb2i_back_group: objectClass: \"%s\" attrName: \"%s\"\n", 
43                 objectclassValue, groupattrName, 0 ); 
44
45         Debug( LDAP_DEBUG_ARGS,
46                 "=> bdb2i_back_group: tr dn: \"%s\"\n",
47                 target->e_ndn, 0, 0 ); 
48
49         if (strcmp(target->e_ndn, gr_ndn) == 0) {
50                 /* we already have a LOCKED copy of the entry */
51                 e = target;
52                 Debug( LDAP_DEBUG_ARGS,
53                         "=> bdb2i_back_group: target is group: \"%s\"\n",
54                         gr_ndn, 0, 0 ); 
55
56         } else {
57                 /* can we find group entry with reader lock */
58                 if ((e = bdb2i_dn2entry_r(be, gr_ndn, NULL )) == NULL) {
59                         Debug( LDAP_DEBUG_ACL,
60                                 "=> bdb2i_back_group: cannot find group: \"%s\"\n",
61                                         gr_ndn, 0, 0 ); 
62                         return( 1 );
63                 }
64
65                 Debug( LDAP_DEBUG_ACL,
66                         "=> bdb2i_back_group: found group: \"%s\"\n",
67                         gr_ndn, 0, 0 ); 
68         }
69
70         /* find it's objectClass and member attribute values
71          * make sure this is a group entry
72          * finally test if we can find op_dn in the member attribute value list
73          */
74         
75         rc = 1;
76
77         if ((attr = attr_find(e->e_attrs, "objectclass")) == NULL)  {
78                 Debug( LDAP_DEBUG_ACL,
79                         "<= bdb2i_back_group: failed to find objectClass\n", 0, 0, 0 ); 
80                 goto return_results;
81         }
82
83         bv.bv_val = "ALIAS";
84         bv.bv_len = sizeof("ALIAS")-1;
85
86         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
87                 Debug( LDAP_DEBUG_ACL,
88                         "<= bdb2i_back_group: group is an alias\n", 0, 0, 0 ); 
89                 goto return_results;
90         }
91
92         bv.bv_val = "REFERRAL";
93         bv.bv_len = sizeof("REFERRAL")-1;
94
95         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
96                 Debug( LDAP_DEBUG_ACL,
97                         "<= bdb2i_back_group: group is a referral\n", 0, 0, 0 ); 
98                 goto return_results;
99         }
100
101         bv.bv_val = objectclassValue;
102         bv.bv_len = strlen( bv.bv_val );
103
104         if (value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
105                 Debug( LDAP_DEBUG_ACL,
106                         "<= bdb2i_back_group: failed to find %s in objectClass\n",
107                         objectclassValue, 0, 0 ); 
108                 goto return_results;
109         }
110
111         if ((attr = attr_find(e->e_attrs, groupattrName)) == NULL) {
112                 Debug( LDAP_DEBUG_ACL,
113                         "<= bdb2i_back_group: failed to find %s\n",
114                         groupattrName, 0, 0 ); 
115                 goto return_results;
116         }
117
118         Debug( LDAP_DEBUG_ACL,
119                 "<= bdb2i_back_group: found objectClass %s and %s\n",
120                 objectclassValue, groupattrName, 0 ); 
121
122
123         bv.bv_val = op_ndn;
124         bv.bv_len = strlen( op_ndn );         
125
126         if (value_find( attr->a_vals, &bv, attr->a_syntax, 1) != 0 ) {
127                 Debug( LDAP_DEBUG_ACL,
128                         "<= bdb2i_back_group: \"%s\" not in \"%s\": %s\n", 
129                         op_ndn, gr_ndn, groupattrName ); 
130                 goto return_results;
131         }
132
133         Debug( LDAP_DEBUG_ACL,
134                 "<= bdb2i_back_group: \"%s\" is in \"%s\": %s\n", 
135                 op_ndn, gr_ndn, groupattrName ); 
136         rc = 0;
137
138 return_results:
139         if( target != e ) {
140                 /* free entry and reader lock */
141                 bdb2i_cache_return_entry_r( &li->li_cache, e );                 
142         }
143
144         Debug( LDAP_DEBUG_ARGS, "bdb2i_back_group: rc: %d\n", rc, 0, 0 ); 
145         return(rc);
146 }
147
148
149 int
150 bdb2_back_group(
151         BackendDB       *be,
152         Entry   *target,
153         char    *gr_ndn,
154         char    *op_ndn,
155         char    *objectclassValue,
156         char    *groupattrName
157 )
158 {
159         DB_LOCK         lock;
160         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
161         struct timeval  time1;
162         int             ret;
163
164         bdb2i_start_timing( be->bd_info, &time1 );
165
166         if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
167
168                 return( 1 );
169
170         }
171
172         ret = bdb2i_back_group_internal( be, target, gr_ndn, op_ndn,
173                                         objectclassValue, groupattrName );
174
175         (void) bdb2i_leave_backend_r( lock );
176         bdb2i_stop_timing( be->bd_info, time1, "GRP", NULL, NULL );
177
178         return( ret );
179 }
180
181