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