]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attribute.c
b17092d130f75f88d321610370327f4f9a4daa4b
[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 0 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         const char ***vals
32 )
33 {
34         struct ldbminfo *li = (struct ldbminfo *) be->be_private;    
35         Entry        *e;
36         int          i, j, rc = 1;
37         Attribute   *attr;
38         struct berval **abv;
39         char *s, **v;
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( 1 );
67                 }
68                 
69                 Debug( LDAP_DEBUG_ACL,
70                         "=> ldbm_back_attribute: found entry: \"%s\"\n",
71                         e_ndn, 0, 0 ); 
72     }
73
74         rc = 1;
75
76         /* find attribute values
77          */
78         
79         if( is_entry_alias( e ) ) {
80                 Debug( LDAP_DEBUG_ACL,
81                         "<= ldbm_back_attribute: entry is an alias\n", 0, 0, 0 );
82                 goto return_results;
83         }
84
85         if( is_entry_referral( e ) ) {
86                 Debug( LDAP_DEBUG_ACL,
87                         "<= ldbm_back_attribute: entry is an referral\n", 0, 0, 0 );
88                 goto return_results;
89         }
90
91         if (conn != NULL && op != NULL
92                 && access_allowed(be, conn, op, e, slap_schema.si_ad_entry, NULL, ACL_SEARCH) == 0)
93         {
94                 goto return_results;
95         }
96
97         if ((attr = attr_find(e->e_attrs, entry_at)) == NULL) {
98                 Debug( LDAP_DEBUG_ACL,
99                         "<= ldbm_back_attribute: failed to find %s\n",
100                         entry_at_name, 0, 0 ); 
101                 goto return_results;
102         }
103
104         if (conn != NULL && op != NULL
105                 && access_allowed(be, conn, op, e, entry_at, NULL, ACL_SEARCH) == 0)
106         {
107                 goto return_results;
108         }
109
110         for ( i = 0; attr->a_vals[i] != NULL; i++ ) { }
111         v = (char **) ch_calloc( (i + 1), sizeof(char *) );
112         if (v != NULL) {
113                 for ( j = 0, abv = attr->a_vals; --i >= 0; abv++ ) {
114                         if ( (*abv)->bv_len > 0 ) {
115                                 s = ch_malloc( (*abv)->bv_len + 1 );
116                                 if( s == NULL )
117                                         break;
118                                 memcpy(s, (*abv)->bv_val, (*abv)->bv_len);
119                                 s[(*abv)->bv_len] = 0;
120                                 v[j++] = s;
121                         }
122                 }
123                 v[j] = NULL;
124                 *vals = v;
125         }
126
127         rc = 0;
128
129 return_results:
130         if( target != e ) {
131                 /* free entry and reader lock */
132                 cache_return_entry_r( &li->li_cache, e );                 
133         }
134
135         Debug( LDAP_DEBUG_TRACE, "ldbm_back_attribute: rc=%d\n", rc, 0, 0 ); 
136         return(rc);
137 }
138