]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
cleanup bind
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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         Connection *conn,
28         Operation *op,
29         Entry   *target,
30         struct berval   *gr_ndn,
31         struct berval   *op_ndn,
32         ObjectClass *group_oc,
33         AttributeDescription *group_at
34 )
35 {
36         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
37         Entry        *e;
38         int          rc = 1;
39         Attribute   *attr;
40
41         const char *group_oc_name = NULL;
42         const char *group_at_name = group_at->ad_cname.bv_val;
43
44         if( group_oc->soc_names && group_oc->soc_names[0] ) {
45                 group_oc_name = group_oc->soc_names[0];
46         } else {
47                 group_oc_name = group_oc->soc_oid;
48         }
49
50 #ifdef NEW_LOGGING
51         LDAP_LOG( BACK_LDBM, ENTRY, 
52                 "ldbm_back_group: check (%s) member of (%s), oc %s\n",
53                 op_ndn->bv_val, gr_ndn->bv_val, group_oc_name );
54 #else
55         Debug( LDAP_DEBUG_ARGS,
56                 "=> ldbm_back_group: gr dn: \"%s\"\n",
57                 gr_ndn->bv_val, 0, 0 ); 
58
59         Debug( LDAP_DEBUG_ARGS,
60                 "=> ldbm_back_group: op dn: \"%s\"\n",
61                 op_ndn->bv_val, 0, 0 ); 
62         Debug( LDAP_DEBUG_ARGS,
63                 "=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n", 
64                 group_oc_name, group_at_name, 0 ); 
65
66         Debug( LDAP_DEBUG_ARGS,
67                 "=> ldbm_back_group: tr dn: \"%s\"\n",
68                 target->e_ndn, 0, 0 ); 
69 #endif
70
71         if (dn_match(&target->e_nname, gr_ndn)) {
72                 /* we already have a LOCKED copy of the entry */
73                 e = target;
74 #ifdef NEW_LOGGING
75                 LDAP_LOG( BACK_LDBM, DETAIL1, 
76                         "ldbm_back_group: target is group (%s)\n", gr_ndn->bv_val, 0, 0 );
77 #else
78                 Debug( LDAP_DEBUG_ARGS,
79                         "=> ldbm_back_group: target is group: \"%s\"\n",
80                         gr_ndn->bv_val, 0, 0 );
81 #endif
82
83
84         } else {
85                 /* can we find group entry with reader lock */
86                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
87 #ifdef NEW_LOGGING
88                         LDAP_LOG( BACK_LDBM, DETAIL1, 
89                                 "ldbm_back_group: cannot find group (%s)\n", 
90                                 gr_ndn->bv_val, 0, 0 );
91 #else
92                         Debug( LDAP_DEBUG_ACL,
93                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
94                                 gr_ndn->bv_val, 0, 0 ); 
95 #endif
96
97                         return( 1 );
98                 }
99                 
100 #ifdef NEW_LOGGING
101                 LDAP_LOG( BACK_LDBM, DETAIL1, 
102                         "ldbm_back_group: found group (%s)\n", gr_ndn->bv_val, 0, 0 );
103 #else
104                 Debug( LDAP_DEBUG_ACL,
105                         "=> ldbm_back_group: found group: \"%s\"\n",
106                         gr_ndn->bv_val, 0, 0 ); 
107 #endif
108
109     }
110
111         /* find it's objectClass and member attribute values
112          * make sure this is a group entry
113          * finally test if we can find op_dn in the member attribute value list *
114          */
115         
116         rc = 1;
117         
118         
119         if( is_entry_alias( e ) ) {
120 #ifdef NEW_LOGGING
121                 LDAP_LOG( BACK_LDBM, INFO, 
122                         "ldbm_back_group: group (%s) is an alias\n", gr_ndn->bv_val, 0, 0 );
123 #else
124                 Debug( LDAP_DEBUG_ACL,
125                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
126 #endif
127
128                 goto return_results;
129         }
130
131         if( is_entry_referral( e ) ) {
132 #ifdef NEW_LOGGING
133                 LDAP_LOG( BACK_LDBM, INFO, 
134                         "ldbm_back_group: group (%s) is a referral.\n", gr_ndn->bv_val,0,0);
135 #else
136                 Debug( LDAP_DEBUG_ACL,
137                         "<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
138 #endif
139
140                 goto return_results;
141         }
142
143         if( !is_entry_objectclass( e, group_oc, 0 ) ) {
144 #ifdef NEW_LOGGING
145                 LDAP_LOG( BACK_LDBM, ERR, 
146                         "ldbm_back_group: failed to find %s in objectClass.\n",
147                         group_oc_name, 0, 0 );
148 #else
149                 Debug( LDAP_DEBUG_ACL,
150                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
151                                 group_oc_name, 0, 0 ); 
152 #endif
153
154                 goto return_results;
155         }
156
157         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
158 #ifdef NEW_LOGGING
159                 LDAP_LOG( BACK_LDBM, INFO, 
160                         "ldbm_back_group: failed to find %s\n", group_at_name, 0, 0 );
161 #else
162                 Debug( LDAP_DEBUG_ACL,
163                         "<= ldbm_back_group: failed to find %s\n",
164                         group_at_name, 0, 0 ); 
165 #endif
166
167                 goto return_results;
168         }
169
170 #ifdef NEW_LOGGING
171         LDAP_LOG( BACK_LDBM, ENTRY, 
172                    "ldbm_back_group: found objectClass %s and %s\n",
173                    group_oc_name, group_at_name, 0 );
174 #else
175         Debug( LDAP_DEBUG_ACL,
176                 "<= ldbm_back_group: found objectClass %s and %s\n",
177                 group_oc_name, group_at_name, 0 ); 
178 #endif
179
180
181         if( value_find_ex( group_at, 0, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) {
182 #ifdef NEW_LOGGING
183                 LDAP_LOG( BACK_LDBM, DETAIL1, 
184                         "ldbm_back_group: \"%s\" not in \"%s\": %s\n",
185                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
186 #else
187                 Debug( LDAP_DEBUG_ACL,
188                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
189                         op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
190 #endif
191
192                 goto return_results;
193         }
194
195
196 #ifdef NEW_LOGGING
197         LDAP_LOG( BACK_LDBM, DETAIL1, 
198                 "ldbm_back_group: %s is in %s: %s\n",
199                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name );
200 #else
201         Debug( LDAP_DEBUG_ACL,
202                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
203                 op_ndn->bv_val, gr_ndn->bv_val, group_at_name ); 
204 #endif
205
206
207         rc = 0;
208
209 return_results:
210         if( target != e ) {
211                 /* free entry and reader lock */
212                 cache_return_entry_r( &li->li_cache, e );                 
213         }
214
215 #ifdef NEW_LOGGING
216         LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_group: rc=%d\n", rc, 0, 0 );
217 #else
218         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
219 #endif
220
221         return(rc);
222 }
223