Debian Codegraph @

servers/slapd/back-wt/compare.c

raw
1 /* OpenLDAP WiredTiger backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 2002-2024 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 <[email protected]>
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 "slap-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, "==> wt_compare: %s\n",
40 op->o_req_dn.bv_val );
41
42 wc = wt_ctx_get(op, wi);
43 if( !wc ){
44 Debug( LDAP_DEBUG_ANY, "wt_compare: wt_ctx_get failed\n" );
45 rs->sr_err = LDAP_OTHER;
46 rs->sr_text = "internal error";
47 send_ldap_result( op, rs );
48 return rs->sr_err;
49 }
50
51 rc = wt_dn2entry(op->o_bd, wc, &op->o_req_ndn, &e);
52 switch( rc ) {
53 case 0:
54 case WT_NOTFOUND:
55 break;
56 default:
57 rs->sr_err = LDAP_OTHER;
58 rs->sr_text = "internal error";
59 goto return_results;
60 }
61
62 if ( rc == WT_NOTFOUND ||
63 (!manageDSAit && e && is_entry_glue( e ) )) {
64
65 if ( !e ) {
66 rc = wt_dn2aentry(op->o_bd, wc, &op->o_req_ndn, &e);
67 switch( rc ) {
68 case 0:
69 break;
70 case WT_NOTFOUND:
71 rs->sr_err = LDAP_NO_SUCH_OBJECT;
72 goto return_results;
73 default:
74 Debug( LDAP_DEBUG_ANY, "wt_compare: wt_dn2aentry failed (%d)\n",
75 rc );
76 rs->sr_err = LDAP_OTHER;
77 rs->sr_text = "internal error";
78 goto return_results;
79 }
80 }
81
82 /* return referral only if "disclose" is granted on the object */
83 if ( ! access_allowed( op, e, slap_schema.si_ad_entry,
84 NULL, ACL_DISCLOSE, NULL ) )
85 {
86 rs->sr_err = LDAP_NO_SUCH_OBJECT;
87 } else {
88 rs->sr_matched = ch_strdup( e->e_dn );
89 if ( is_entry_referral( e )) {
90 BerVarray ref = get_entry_referrals( op, e );
91 rs->sr_ref = referral_rewrite( ref,
92 &e->e_name,
93 &op->o_req_dn,
94 LDAP_SCOPE_DEFAULT );
95 ber_bvarray_free( ref );
96 } else {
97 rs->sr_ref = NULL;
98 }
99 rs->sr_err = LDAP_REFERRAL;
100 }
101 rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
102 send_ldap_result( op, rs );
103 goto done;
104 }
105
106 if (!manageDSAit && is_entry_referral( e ) ) {
107 /* return referral only if "disclose" is granted on the object */
108 if ( !access_allowed( op, e, slap_schema.si_ad_entry,
109 NULL, ACL_DISCLOSE, NULL ) )
110 {
111 rs->sr_err = LDAP_NO_SUCH_OBJECT;
112 } else {
113 /* entry is a referral, don't allow compare */
114 rs->sr_ref = get_entry_referrals( op, e );
115 rs->sr_err = LDAP_REFERRAL;
116 rs->sr_matched = e->e_name.bv_val;
117 }
118
119 Debug( LDAP_DEBUG_TRACE, "entry is referral\n" );
120
121 send_ldap_result( op, rs );
122
123 ber_bvarray_free( rs->sr_ref );
124 rs->sr_ref = NULL;
125 rs->sr_matched = NULL;
126 goto done;
127 }
128
129 rs->sr_err = slap_compare_entry( op, e, op->orc_ava );
130
131 return_results:
132 send_ldap_result( op, rs );
133
134 switch ( rs->sr_err ) {
135 case LDAP_COMPARE_FALSE:
136 case LDAP_COMPARE_TRUE:
137 rs->sr_err = LDAP_SUCCESS;
138 break;
139 }
140
141 done:
142 if ( e != NULL ) {
143 wt_entry_return( e );
144 }
145 return rs->sr_err;
146 }
147
148 /*
149 * Local variables:
150 * indent-tabs-mode: t
151 * tab-width: 4
152 * c-basic-offset: 4
153 * End:
154 */