]> git.sur5r.net Git - openldap/blob - servers/slapd/compare.c
merged with autoconf branch
[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 extern Backend  *select_backend();
22
23 extern char     *default_referral;
24
25 void
26 do_compare(
27     Connection  *conn,
28     Operation   *op
29 )
30 {
31         char    *dn;
32         Ava     ava;
33         int     rc;
34         Backend *be;
35
36         Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
37
38         /*
39          * Parse the compare request.  It looks like this:
40          *
41          *      CompareRequest := [APPLICATION 14] SEQUENCE {
42          *              entry   DistinguishedName,
43          *              ava     SEQUENCE {
44          *                      type    AttributeType,
45          *                      value   AttributeValue
46          *              }
47          *      }
48          */
49
50         if ( ber_scanf( op->o_ber, "{a{ao}}", &dn, &ava.ava_type,
51             &ava.ava_value ) == LBER_ERROR ) {
52                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
53                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
54                 return;
55         }
56         value_normalize( ava.ava_value.bv_val, attr_syntax( ava.ava_type ) );
57         dn_normalize( dn );
58
59         Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
60             dn, ava.ava_type, ava.ava_value.bv_val );
61
62         Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d CMP dn=\"%s\" attr=\"%s\"\n",
63             conn->c_connid, op->o_opid, dn, ava.ava_type, 0 );
64
65         /*
66          * We could be serving multiple database backends.  Select the
67          * appropriate one, or send a referral to our "referral server"
68          * if we don't hold it.
69          */
70         if ( (be = select_backend( dn )) == NULL ) {
71                 free( dn );
72                 ava_free( &ava, 0 );
73
74                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
75                     default_referral );
76                 return;
77         }
78
79         if ( be->be_compare != NULL ) {
80                 (*be->be_compare)( be, conn, op, dn, &ava );
81         } else {
82                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
83                     "Function not implemented" );
84         }
85
86         free( dn );
87         ava_free( &ava, 0 );
88 }