]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attribute.c
error message from be_entry_put tool backend function
[openldap] / servers / slapd / back-ldbm / attribute.c
1 /* attribute.c - ldbm backend acl attribute routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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 LDAP_SUCCESS IFF we can retrieve the attributes
21  * of entry with e_ndn
22  */
23 int
24 ldbm_back_attribute(
25         Backend *be,
26         Connection *conn,
27         Operation *op,
28         Entry   *target,
29         struct berval   *entry_ndn,
30         AttributeDescription *entry_at,
31         BVarray *vals )
32 {
33         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
34         Entry        *e;
35         int          rc;
36         Attribute   *attr;
37         BVarray v;
38         const char *entry_at_name = entry_at->ad_cname.bv_val;
39         struct berval *iv, *jv;
40
41 #ifdef NEW_LOGGING
42         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
43                 "ldbm_back_attribute: gr dn: \"%s\"\n", entry_ndn->bv_val ));
44         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
45                 "ldbm_back_attribute: at: \"%s\"\n", entry_at_name));
46         LDAP_LOG(( "backend", LDAP_LEVEL_ARGS,
47                 "ldbm_back_attribute: tr dn: \"%s\"\n",
48                 target ? target->e_ndn : "" ));
49 #else
50         Debug( LDAP_DEBUG_ARGS,
51                 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
52                 entry_ndn->bv_val, 0, 0 ); 
53         Debug( LDAP_DEBUG_ARGS,
54                 "=> ldbm_back_attribute: at: \"%s\"\n", 
55                 entry_at_name, 0, 0 ); 
56
57         Debug( LDAP_DEBUG_ARGS,
58                 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
59                 target ? target->e_ndn : "", 0, 0 ); 
60 #endif
61
62         if (target != NULL && strcmp(target->e_ndn, entry_ndn->bv_val) == 0) {
63                 /* we already have a LOCKED copy of the entry */
64                 e = target;
65 #ifdef NEW_LOGGING
66                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
67                         "ldbm_back_attribute: target is LOCKED (%s)\n",
68                         entry_ndn->bv_val ));
69 #else
70                 Debug( LDAP_DEBUG_ARGS,
71                         "=> ldbm_back_attribute: target is entry: \"%s\"\n",
72                         entry_ndn->bv_val, 0, 0 );
73 #endif
74
75
76         } else {
77                 /* can we find entry with reader lock */
78                 if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
79 #ifdef NEW_LOGGING
80                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
81                                 "ldbm_back_attribute: cannot find entry (%s)\n",
82                                 entry_ndn->bv_val ));
83 #else
84                         Debug( LDAP_DEBUG_ACL,
85                                 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
86                                         entry_ndn->bv_val, 0, 0 ); 
87 #endif
88
89                         return LDAP_NO_SUCH_OBJECT; 
90                 }
91                 
92 #ifdef NEW_LOGGING
93                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
94                         "ldbm_back_attribute: found entry (%s)\n",
95                         entry_ndn->bv_val ));
96 #else
97                 Debug( LDAP_DEBUG_ACL,
98                         "=> ldbm_back_attribute: found entry: \"%s\"\n",
99                         entry_ndn->bv_val, 0, 0 ); 
100 #endif
101
102     }
103
104         /* find attribute values */
105         
106         if( is_entry_alias( e ) ) {
107 #ifdef NEW_LOGGING
108                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
109                         "ldbm_back_attribute: entry (%s) is an alias\n", e->e_dn ));
110 #else
111                 Debug( LDAP_DEBUG_ACL,
112                         "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
113 #endif
114
115                 rc = LDAP_ALIAS_PROBLEM;
116                 goto return_results;
117         }
118
119         if( is_entry_referral( e ) ) {
120 #ifdef NEW_LOGGING
121                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
122                         "ldbm_back_attribute: entry (%s) is a referral.\n", e->e_dn ));
123 #else
124                 Debug( LDAP_DEBUG_ACL,
125                         "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
126 #endif
127
128                 rc = LDAP_REFERRAL;
129                 goto return_results;
130         }
131
132         if (conn != NULL && op != NULL
133                 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
134                         NULL, ACL_READ) == 0)
135         {
136                 rc = LDAP_INSUFFICIENT_ACCESS;
137                 goto return_results;
138         }
139
140         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
141 #ifdef NEW_LOGGING
142                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
143                         "ldbm_back_attribute: failed to find %s.\n", entry_at_name ));
144 #else
145                 Debug( LDAP_DEBUG_ACL,
146                         "<= ldbm_back_attribute: failed to find %s\n",
147                         entry_at_name, 0, 0 ); 
148 #endif
149
150                 rc = LDAP_NO_SUCH_ATTRIBUTE;
151                 goto return_results;
152         }
153
154         if (conn != NULL && op != NULL
155                 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
156         {
157                 rc = LDAP_INSUFFICIENT_ACCESS;
158                 goto return_results;
159         }
160
161         for ( iv = attr->a_vals; iv->bv_val != NULL; iv++ ) {
162                 /* count them */
163         }
164
165         v = (BVarray) ch_malloc( sizeof(struct berval) * ((iv - attr->a_vals)+1) );
166
167         for ( iv=attr->a_vals, jv=v; iv->bv_val; iv++ ) {
168                 if( conn != NULL
169                         && op != NULL
170                         && access_allowed(be, conn, op, e, entry_at,
171                                 iv, ACL_READ) == 0)
172                 {
173                         continue;
174                 }
175                 ber_dupbv( jv, iv );
176
177                 if( jv->bv_val != NULL ) jv++;
178         }
179
180         if( jv == v ) {
181                 ch_free( v );
182                 *vals = NULL;
183                 rc = LDAP_INSUFFICIENT_ACCESS;
184         } else {
185                 jv->bv_val = NULL;
186                 *vals = v;
187                 rc = LDAP_SUCCESS;
188         }
189
190 return_results:
191         if( target != e ) {
192                 /* free entry and reader lock */
193                 cache_return_entry_r( &li->li_cache, e );                 
194         }
195
196 #ifdef NEW_LOGGING
197         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
198                    "ldbm_back_attribute: rc=%d nvals=%d.\n",
199                    rc, jv - v ));
200 #else
201         Debug( LDAP_DEBUG_TRACE,
202                 "ldbm_back_attribute: rc=%d nvals=%d\n",
203                 rc, jv - v, 0 ); 
204 #endif
205
206         return(rc);
207 }
208