]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/group.c
add new ber dump routine (behind NEW_LOGGING)
[openldap] / servers / slapd / back-ldbm / group.c
1 /* group.c - ldbm backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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         const char      *gr_ndn,
31         const char      *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         struct berval bv;
41
42         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
43         const char *group_oc_name = NULL;
44         const char *group_at_name = group_at->ad_cname->bv_val;
45
46         if( group_oc->soc_names && group_oc->soc_names[0] ) {
47                 group_oc_name = group_oc->soc_names[0];
48         } else {
49                 group_oc_name = group_oc->soc_oid;
50         }
51
52         Debug( LDAP_DEBUG_ARGS,
53                 "=> ldbm_back_group: gr dn: \"%s\"\n",
54                 gr_ndn, 0, 0 ); 
55         Debug( LDAP_DEBUG_ARGS,
56                 "=> ldbm_back_group: op dn: \"%s\"\n",
57                 op_ndn, 0, 0 ); 
58         Debug( LDAP_DEBUG_ARGS,
59                 "=> ldbm_back_group: oc: \"%s\" at: \"%s\"\n", 
60                 group_oc_name, group_at_name, 0 ); 
61
62         Debug( LDAP_DEBUG_ARGS,
63                 "=> ldbm_back_group: tr dn: \"%s\"\n",
64                 target->e_ndn, 0, 0 ); 
65
66         if (strcmp(target->e_ndn, gr_ndn) == 0) {
67                 /* we already have a LOCKED copy of the entry */
68                 e = target;
69                 Debug( LDAP_DEBUG_ARGS,
70                         "=> ldbm_back_group: target is group: \"%s\"\n",
71                         gr_ndn, 0, 0 );
72
73         } else {
74                 /* can we find group entry with reader lock */
75                 if ((e = dn2entry_r(be, gr_ndn, NULL )) == NULL) {
76                         Debug( LDAP_DEBUG_ACL,
77                                 "=> ldbm_back_group: cannot find group: \"%s\"\n",
78                                         gr_ndn, 0, 0 ); 
79                         return( 1 );
80                 }
81                 
82                 Debug( LDAP_DEBUG_ACL,
83                         "=> ldbm_back_group: found group: \"%s\"\n",
84                         gr_ndn, 0, 0 ); 
85     }
86
87         /* find it's objectClass and member attribute values
88          * make sure this is a group entry
89          * finally test if we can find op_dn in the member attribute value list *
90          */
91         
92         rc = 1;
93         
94         
95         if( is_entry_alias( e ) ) {
96                 Debug( LDAP_DEBUG_ACL,
97                         "<= ldbm_back_group: group is an alias\n", 0, 0, 0 );
98                 goto return_results;
99         }
100
101         if( is_entry_referral( e ) ) {
102                 Debug( LDAP_DEBUG_ACL,
103                         "<= ldbm_back_group: group is an referral\n", 0, 0, 0 );
104                 goto return_results;
105         }
106
107         if( !is_entry_objectclass( e, group_oc ) ) {
108                 Debug( LDAP_DEBUG_ACL,
109                         "<= ldbm_back_group: failed to find %s in objectClass\n", 
110                                 group_oc_name, 0, 0 ); 
111                 goto return_results;
112         }
113
114         if ((attr = attr_find(e->e_attrs, group_at)) == NULL) {
115                 Debug( LDAP_DEBUG_ACL,
116                         "<= ldbm_back_group: failed to find %s\n",
117                         group_at_name, 0, 0 ); 
118                 goto return_results;
119         }
120
121         Debug( LDAP_DEBUG_ACL,
122                 "<= ldbm_back_group: found objectClass %s and %s\n",
123                 group_oc_name, group_at_name, 0 ); 
124
125         bv.bv_val = (char *) op_ndn;
126         bv.bv_len = strlen( op_ndn );         
127
128         if( value_find( group_at, attr->a_vals, &bv ) != LDAP_SUCCESS ) {
129                 Debug( LDAP_DEBUG_ACL,
130                         "<= ldbm_back_group: \"%s\" not in \"%s\": %s\n", 
131                         op_ndn, gr_ndn, group_at_name ); 
132                 goto return_results;
133         }
134
135
136
137         Debug( LDAP_DEBUG_ACL,
138                 "<= ldbm_back_group: \"%s\" is in \"%s\": %s\n", 
139                 op_ndn, gr_ndn, group_at_name ); 
140
141         rc = 0;
142
143 return_results:
144         if( target != e ) {
145                 /* free entry and reader lock */
146                 cache_return_entry_r( &li->li_cache, e );                 
147         }
148
149         Debug( LDAP_DEBUG_TRACE, "ldbm_back_group: rc=%d\n", rc, 0, 0 ); 
150         return(rc);
151 }
152