]> git.sur5r.net Git - openldap/blob - servers/slapd/compare.c
Import cache_delete_entry_internal/dntree&idtree delete fix from -devel.
[openldap] / servers / slapd / compare.c
1 /*
2  * Copyright (c) 1995 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/socket.h>
18
19 #include "slap.h"
20
21 void
22 do_compare(
23     Connection  *conn,
24     Operation   *op
25 )
26 {
27         char    *dn;
28         Ava     ava;
29         int     rc;
30         Backend *be;
31
32         Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
33
34         /*
35          * Parse the compare request.  It looks like this:
36          *
37          *      CompareRequest := [APPLICATION 14] SEQUENCE {
38          *              entry   DistinguishedName,
39          *              ava     SEQUENCE {
40          *                      type    AttributeType,
41          *                      value   AttributeValue
42          *              }
43          *      }
44          */
45
46         if ( ber_scanf( op->o_ber, "{a{ao}}", &dn, &ava.ava_type,
47             &ava.ava_value ) == LBER_ERROR ) {
48                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
49                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
50                 return;
51         }
52         value_normalize( ava.ava_value.bv_val, attr_syntax( ava.ava_type ) );
53         dn_normalize( dn );
54
55         Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
56             dn, ava.ava_type, ava.ava_value.bv_val );
57
58         Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d CMP dn=\"%s\" attr=\"%s\"\n",
59             conn->c_connid, op->o_opid, dn, ava.ava_type, 0 );
60
61         /*
62          * We could be serving multiple database backends.  Select the
63          * appropriate one, or send a referral to our "referral server"
64          * if we don't hold it.
65          */
66         if ( (be = select_backend( dn )) == NULL ) {
67                 free( dn );
68                 ava_free( &ava, 0 );
69
70                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
71                     default_referral );
72                 return;
73         }
74
75         if ( be->be_compare != NULL ) {
76                 (*be->be_compare)( be, conn, op, dn, &ava );
77         } else {
78                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
79                     "Function not implemented" );
80         }
81
82         free( dn );
83         ava_free( &ava, 0 );
84 }