xref: /netbsd-src/external/bsd/openldap/dist/servers/slapd/back-monitor/compare.c (revision d909946ca08dceb44d7d0f22ec9488679695d976)
1 /*	$NetBSD: compare.c,v 1.1.1.4 2014/05/28 09:58:50 tron 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-2014 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 "portable.h"
25 
26 #include <stdio.h>
27 
28 #include <slap.h>
29 #include "back-monitor.h"
30 
31 int
32 monitor_back_compare( Operation *op, SlapReply *rs )
33 {
34 	monitor_info_t	*mi = ( monitor_info_t * ) op->o_bd->be_private;
35 	Entry           *e, *matched = NULL;
36 	int		rc;
37 
38 	/* get entry with reader lock */
39 	monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
40 	if ( e == NULL ) {
41 		rs->sr_err = LDAP_NO_SUCH_OBJECT;
42 		if ( matched ) {
43 			if ( !access_allowed_mask( op, matched,
44 					slap_schema.si_ad_entry,
45 					NULL, ACL_DISCLOSE, NULL, NULL ) )
46 			{
47 				/* do nothing */ ;
48 			} else {
49 				rs->sr_matched = matched->e_dn;
50 			}
51 		}
52 		send_ldap_result( op, rs );
53 		if ( matched ) {
54 			monitor_cache_release( mi, matched );
55 			rs->sr_matched = NULL;
56 		}
57 
58 		return rs->sr_err;
59 	}
60 
61 	monitor_entry_update( op, rs, e );
62 	rs->sr_err = slap_compare_entry( op, e, op->orc_ava );
63 	rc = rs->sr_err;
64 	switch ( rc ) {
65 	case LDAP_COMPARE_FALSE:
66 	case LDAP_COMPARE_TRUE:
67 		rc = LDAP_SUCCESS;
68 		break;
69 	}
70 
71 	send_ldap_result( op, rs );
72 	rs->sr_err = rc;
73 
74 	monitor_cache_release( mi, e );
75 
76 	return rs->sr_err;
77 }
78 
79