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