]> git.sur5r.net Git - openldap/blob - servers/slapd/compare.c
Rework BER decoding with lieu of LDAPv3 controls (coming soon).
[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    *ndn;
28         Ava     ava;
29         Backend *be;
30
31         Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
32
33         /*
34          * Parse the compare request.  It looks like this:
35          *
36          *      CompareRequest := [APPLICATION 14] SEQUENCE {
37          *              entry   DistinguishedName,
38          *              ava     SEQUENCE {
39          *                      type    AttributeType,
40          *                      value   AttributeValue
41          *              }
42          *      }
43          */
44
45         if ( ber_scanf( op->o_ber, "{a{ao}}", &ndn, &ava.ava_type,
46             &ava.ava_value ) == LBER_ERROR ) {
47                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
48                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
49                 return;
50         }
51
52 #ifdef GET_CTRLS
53         if( get_ctrls( conn, op, 1 ) == -1 ) {
54                 free( ndn );
55                 ava_free( &ava, 0 );
56                 Debug( LDAP_DEBUG_ANY, "do_compare: get_ctrls failed\n", 0, 0, 0 );
57                 return;
58         } 
59 #endif
60
61         value_normalize( ava.ava_value.bv_val, attr_syntax( ava.ava_type ) );
62
63         Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
64             ndn, ava.ava_type, ava.ava_value.bv_val );
65
66         ndn = dn_normalize_case( ndn );
67
68         Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d CMP dn=\"%s\" attr=\"%s\"\n",
69             conn->c_connid, op->o_opid, ndn, ava.ava_type, 0 );
70
71         /*
72          * We could be serving multiple database backends.  Select the
73          * appropriate one, or send a referral to our "referral server"
74          * if we don't hold it.
75          */
76         if ( (be = select_backend( ndn )) == NULL ) {
77                 free( ndn );
78                 ava_free( &ava, 0 );
79
80                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
81                     default_referral );
82                 return;
83         }
84
85         /* alias suffix if approp */
86         ndn = suffixAlias( ndn, op, be );
87
88         if ( be->be_compare ) {
89                 (*be->be_compare)( be, conn, op, ndn, &ava );
90         } else {
91                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
92                     "Function not implemented" );
93         }
94
95         free( ndn );
96         ava_free( &ava, 0 );
97 }