]> git.sur5r.net Git - openldap/blob - servers/slapd/back-wt/compare.c
Happy New Year
[openldap] / servers / slapd / back-wt / compare.c
1 /* OpenLDAP WiredTiger backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2002-2018 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was developed by HAMANO Tsukasa <hamano@osstech.co.jp>
18  * based on back-bdb for inclusion in OpenLDAP Software.
19  * WiredTiger is a product of MongoDB Inc.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "back-wt.h"
28 #include "config.h"
29
30 int
31 wt_compare( Operation *op, SlapReply *rs )
32 {
33     struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
34         Entry *e = NULL;
35         int manageDSAit = get_manageDSAit( op );
36         int rc;
37         wt_ctx *wc = NULL;
38
39         Debug( LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(wt_compare) ": %s\n",
40                    op->o_req_dn.bv_val, 0, 0 );
41
42         wc = wt_ctx_get(op, wi);
43         if( !wc ){
44                 Debug( LDAP_DEBUG_ANY,
45                            LDAP_XSTRING(wt_compare)
46                            ": wt_ctx_get failed\n",
47                            0, 0, 0 );
48                 rs->sr_err = LDAP_OTHER;
49                 rs->sr_text = "internal error";
50         send_ldap_result( op, rs );
51         return rs->sr_err;
52         }
53
54         rs->sr_err = wt_dn2entry(op->o_bd, wc, &op->o_req_ndn, &e);
55         switch( rs->sr_err ) {
56         case 0:
57         case WT_NOTFOUND:
58                 break;
59         default:
60                 rs->sr_err = LDAP_OTHER;
61                 rs->sr_text = "internal error";
62                 goto return_results;
63         }
64
65         if ( rs->sr_err == WT_NOTFOUND ) {
66                 if ( e != NULL ) {
67                         /* return referral only if "disclose" is granted on the object */
68                         if ( ! access_allowed( op, e, slap_schema.si_ad_entry,
69                                                                    NULL, ACL_DISCLOSE, NULL ) )
70                         {
71                                 rs->sr_err = LDAP_NO_SUCH_OBJECT;
72                         } else {
73                                 rs->sr_matched = ch_strdup( e->e_dn );
74                                 if ( is_entry_referral( e )) {
75                                         BerVarray ref = get_entry_referrals( op, e );
76                                         rs->sr_ref = referral_rewrite( ref,
77                                                                                                    &e->e_name,
78                                                                                                    &op->o_req_dn,
79                                                                                                    LDAP_SCOPE_DEFAULT );
80                                         ber_bvarray_free( ref );
81                                 } else {
82                                         rs->sr_ref = NULL;
83                                 }
84                                 rs->sr_err = LDAP_REFERRAL;
85                         }
86                         wt_entry_return( e );
87                         e = NULL;
88                 } else {
89                         rs->sr_ref = referral_rewrite( default_referral,
90                                                                                    NULL,
91                                                                                    &op->o_req_dn,
92                                                                                    LDAP_SCOPE_DEFAULT );
93                         rs->sr_err = rs->sr_ref ? LDAP_REFERRAL : LDAP_NO_SUCH_OBJECT;
94                 }
95
96                 rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
97                 send_ldap_result( op, rs );
98                 goto done;
99         }
100
101         if (!manageDSAit && is_entry_referral( e ) ) {
102                 /* return referral only if "disclose" is granted on the object */
103                 if ( !access_allowed( op, e, slap_schema.si_ad_entry,
104                                                           NULL, ACL_DISCLOSE, NULL ) )
105                 {
106                         rs->sr_err = LDAP_NO_SUCH_OBJECT;
107                 } else {
108                         /* entry is a referral, don't allow compare */
109                         rs->sr_ref = get_entry_referrals( op, e );
110                         rs->sr_err = LDAP_REFERRAL;
111                         rs->sr_matched = e->e_name.bv_val;
112                 }
113
114                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0, 0, 0 );
115
116                 send_ldap_result( op, rs );
117
118                 ber_bvarray_free( rs->sr_ref );
119                 rs->sr_ref = NULL;
120                 rs->sr_matched = NULL;
121                 goto done;
122         }
123
124         rs->sr_err = slap_compare_entry( op, e, op->orc_ava );
125
126 return_results:
127         send_ldap_result( op, rs );
128
129         switch ( rs->sr_err ) {
130         case LDAP_COMPARE_FALSE:
131         case LDAP_COMPARE_TRUE:
132                 rs->sr_err = LDAP_SUCCESS;
133                 break;
134         }
135
136 done:
137         if ( e != NULL ) {
138                 wt_entry_return( e );
139         }
140     return rs->sr_err;
141 }
142
143 /*
144  * Local variables:
145  * indent-tabs-mode: t
146  * tab-width: 4
147  * c-basic-offset: 4
148  * End:
149  */