]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attribute.c
add new ber dump routine (behind NEW_LOGGING)
[openldap] / servers / slapd / back-ldbm / attribute.c
1 /* attribute.c - ldbm backend acl attribute 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 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         const char      *e_ndn,
30         AttributeDescription *entry_at,
31         struct berval ***vals )
32 {
33         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
34         Entry        *e;
35         int          i, j, rc;
36         Attribute   *attr;
37         struct berval **v;
38         const char *entry_at_name = entry_at->ad_cname->bv_val;
39
40         Debug( LDAP_DEBUG_ARGS,
41                 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
42                 e_ndn, 0, 0 ); 
43         Debug( LDAP_DEBUG_ARGS,
44                 "=> ldbm_back_attribute: at: \"%s\"\n", 
45                 entry_at_name, 0, 0 ); 
46
47         Debug( LDAP_DEBUG_ARGS,
48                 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
49                 target ? target->e_ndn : "", 0, 0 ); 
50
51         if (target != NULL && strcmp(target->e_ndn, e_ndn) == 0) {
52                 /* we already have a LOCKED copy of the entry */
53                 e = target;
54                 Debug( LDAP_DEBUG_ARGS,
55                         "=> ldbm_back_attribute: target is entry: \"%s\"\n",
56                         e_ndn, 0, 0 );
57
58         } else {
59                 /* can we find entry with reader lock */
60                 if ((e = dn2entry_r(be, e_ndn, NULL )) == NULL) {
61                         Debug( LDAP_DEBUG_ACL,
62                                 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
63                                         e_ndn, 0, 0 ); 
64                         return LDAP_NO_SUCH_OBJECT; 
65                 }
66                 
67                 Debug( LDAP_DEBUG_ACL,
68                         "=> ldbm_back_attribute: found entry: \"%s\"\n",
69                         e_ndn, 0, 0 ); 
70     }
71
72         /* find attribute values */
73         
74         if( is_entry_alias( e ) ) {
75                 Debug( LDAP_DEBUG_ACL,
76                         "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
77                 rc = LDAP_ALIAS_PROBLEM;
78                 goto return_results;
79         }
80
81         if( is_entry_referral( e ) ) {
82                 Debug( LDAP_DEBUG_ACL,
83                         "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
84                 rc = LDAP_REFERRAL;
85                 goto return_results;
86         }
87
88         if (conn != NULL && op != NULL
89                 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
90                         NULL, ACL_READ) == 0)
91         {
92                 rc = LDAP_INSUFFICIENT_ACCESS;
93                 goto return_results;
94         }
95
96         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
97                 Debug( LDAP_DEBUG_ACL,
98                         "<= ldbm_back_attribute: failed to find %s\n",
99                         entry_at_name, 0, 0 ); 
100                 rc = LDAP_NO_SUCH_ATTRIBUTE;
101                 goto return_results;
102         }
103
104         if (conn != NULL && op != NULL
105                 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
106         {
107                 rc = LDAP_INSUFFICIENT_ACCESS;
108                 goto return_results;
109         }
110
111         for ( i = 0; attr->a_vals[i] != NULL; i++ ) {
112                 /* count them */
113         }
114
115         v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
116
117         for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
118                 if( conn != NULL
119                         && op != NULL
120                         && access_allowed(be, conn, op, e, entry_at,
121                                 attr->a_vals[i], ACL_READ) == 0)
122                 {
123                         continue;
124                 }
125                 v[j] = ber_bvdup( attr->a_vals[i] );
126
127                 if( v[j] != NULL ) j++;
128         }
129
130         if( j == 0 ) {
131                 ch_free( v );
132                 *vals = NULL;
133                 rc = LDAP_INSUFFICIENT_ACCESS;
134         } else {
135                 v[j] = NULL;
136                 *vals = v;
137                 rc = LDAP_SUCCESS;
138         }
139
140 return_results:
141         if( target != e ) {
142                 /* free entry and reader lock */
143                 cache_return_entry_r( &li->li_cache, e );                 
144         }
145
146         Debug( LDAP_DEBUG_TRACE,
147                 "ldbm_back_attribute: rc=%d nvals=%d\n",
148                 rc, j, 0 ); 
149         return(rc);
150 }
151