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