]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attribute.c
8dd03e13c6f77bc3ba99ef0fc30041b7bf0ee11f
[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 {
34         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
35         Entry        *e;
36         int          i, j, rc;
37         Attribute   *attr;
38         struct berval **v;
39         char *s;
40         const char *entry_at_name = entry_at->ad_cname->bv_val;
41
42         Debug( LDAP_DEBUG_ARGS,
43                 "=> ldbm_back_attribute: gr dn: \"%s\"\n",
44                 e_ndn, 0, 0 ); 
45         Debug( LDAP_DEBUG_ARGS,
46                 "=> ldbm_back_attribute: at: \"%s\"\n", 
47                 entry_at_name, 0, 0 ); 
48
49         Debug( LDAP_DEBUG_ARGS,
50                 "=> ldbm_back_attribute: tr dn: \"%s\"\n",
51                 target ? target->e_ndn : "", 0, 0 ); 
52
53         if (target != NULL && strcmp(target->e_ndn, e_ndn) == 0) {
54                 /* we already have a LOCKED copy of the entry */
55                 e = target;
56                 Debug( LDAP_DEBUG_ARGS,
57                         "=> ldbm_back_attribute: target is entry: \"%s\"\n",
58                         e_ndn, 0, 0 );
59
60         } else {
61                 /* can we find entry with reader lock */
62                 if ((e = dn2entry_r(be, e_ndn, NULL )) == NULL) {
63                         Debug( LDAP_DEBUG_ACL,
64                                 "=> ldbm_back_attribute: cannot find entry: \"%s\"\n",
65                                         e_ndn, 0, 0 ); 
66                         return LDAP_NO_SUCH_OBJECT; 
67                 }
68                 
69                 Debug( LDAP_DEBUG_ACL,
70                         "=> ldbm_back_attribute: found entry: \"%s\"\n",
71                         e_ndn, 0, 0 ); 
72     }
73
74         /* find attribute values */
75         
76         if( is_entry_alias( e ) ) {
77                 Debug( LDAP_DEBUG_ACL,
78                         "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
79                 rc = LDAP_ALIAS_PROBLEM;
80                 goto return_results;
81         }
82
83         if( is_entry_referral( e ) ) {
84                 Debug( LDAP_DEBUG_ACL,
85                         "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
86                 rc = LDAP_REFERRAL;
87                 goto return_results;
88         }
89
90         if (conn != NULL && op != NULL
91                 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry,
92                         NULL, ACL_READ) == 0)
93         {
94                 rc = LDAP_INSUFFICIENT_ACCESS;
95                 goto return_results;
96         }
97
98         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
99                 Debug( LDAP_DEBUG_ACL,
100                         "<= ldbm_back_attribute: failed to find %s\n",
101                         entry_at_name, 0, 0 ); 
102                 rc = LDAP_NO_SUCH_ATTRIBUTE;
103                 goto return_results;
104         }
105
106         if (conn != NULL && op != NULL
107                 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_READ) == 0)
108         {
109                 rc = LDAP_INSUFFICIENT_ACCESS;
110                 goto return_results;
111         }
112
113         for ( i = 0; attr->a_vals[i] != NULL; i++ ) {
114                 /* count them */
115         }
116
117         v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
118
119         for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
120                 if( 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