1/*	$NetBSD: compare.c,v 1.3 2021/08/14 16:15:00 christos Exp $	*/
2
3/* compare.c - monitor backend compare routine */
4/* $OpenLDAP$ */
5/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2001-2021 The OpenLDAP Foundation.
8 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted only as authorized by the OpenLDAP
13 * Public License.
14 *
15 * A copy of this license is available in file LICENSE in the
16 * top-level directory of the distribution or, alternatively, at
17 * <http://www.OpenLDAP.org/license.html>.
18 */
19/* ACKNOWLEDGEMENTS:
20 * This work was initially developed by Pierangelo Masarati for inclusion
21 * in OpenLDAP Software.
22 */
23
24#include <sys/cdefs.h>
25__RCSID("$NetBSD: compare.c,v 1.3 2021/08/14 16:15:00 christos Exp $");
26
27#include "portable.h"
28
29#include <stdio.h>
30
31#include <slap.h>
32#include "back-monitor.h"
33
34int
35monitor_back_compare( Operation *op, SlapReply *rs )
36{
37	monitor_info_t	*mi = ( monitor_info_t * ) op->o_bd->be_private;
38	Entry           *e, *matched = NULL;
39	int		rc;
40
41	/* get entry with reader lock */
42	monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
43	if ( e == NULL ) {
44		rs->sr_err = LDAP_NO_SUCH_OBJECT;
45		if ( matched ) {
46			if ( !access_allowed_mask( op, matched,
47					slap_schema.si_ad_entry,
48					NULL, ACL_DISCLOSE, NULL, NULL ) )
49			{
50				/* do nothing */ ;
51			} else {
52				rs->sr_matched = matched->e_dn;
53			}
54		}
55		send_ldap_result( op, rs );
56		if ( matched ) {
57			monitor_cache_release( mi, matched );
58			rs->sr_matched = NULL;
59		}
60
61		return rs->sr_err;
62	}
63
64	monitor_entry_update( op, rs, e );
65	rs->sr_err = slap_compare_entry( op, e, op->orc_ava );
66	rc = rs->sr_err;
67	switch ( rc ) {
68	case LDAP_COMPARE_FALSE:
69	case LDAP_COMPARE_TRUE:
70		rc = LDAP_SUCCESS;
71		break;
72	}
73
74	send_ldap_result( op, rs );
75	rs->sr_err = rc;
76
77	monitor_cache_release( mi, e );
78
79	return rs->sr_err;
80}
81
82