]> git.sur5r.net Git - openldap/blob - servers/slapd/compare.c
Didn't return after returning unknown critical control.
[openldap] / servers / slapd / compare.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright (c) 1995 Regents of the University of Michigan.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * provided that this notice is preserved and that due credit is given
12  * to the University of Michigan at Ann Arbor. The name of the University
13  * may not be used to endorse or promote products derived from this
14  * software without specific prior written permission. This software
15  * is provided ``as is'' without express or implied warranty.
16  */
17
18 #include "portable.h"
19
20 #include <stdio.h>
21
22 #include <ac/socket.h>
23
24 #include "ldap_pvt.h"
25 #include "slap.h"
26
27 int
28 do_compare(
29     Connection  *conn,
30     Operation   *op
31 )
32 {
33         char    *dn = NULL, *ndn=NULL;
34         Ava     ava;
35         Backend *be;
36         int rc = LDAP_SUCCESS;
37
38         Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
39
40         if( op->o_bind_in_progress ) {
41                 Debug( LDAP_DEBUG_ANY, "do_compare: SASL bind in progress.\n",
42                         0, 0, 0 );
43                 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
44                         NULL, "SASL bind in progress", NULL, NULL );
45                 return LDAP_SASL_BIND_IN_PROGRESS;
46         }
47
48         /*
49          * Parse the compare request.  It looks like this:
50          *
51          *      CompareRequest := [APPLICATION 14] SEQUENCE {
52          *              entry   DistinguishedName,
53          *              ava     SEQUENCE {
54          *                      type    AttributeType,
55          *                      value   AttributeValue
56          *              }
57          *      }
58          */
59
60         if ( ber_scanf( op->o_ber, "{a" /*}*/, &dn ) == LBER_ERROR ) {
61                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
62                 send_ldap_disconnect( conn, op,
63                         LDAP_PROTOCOL_ERROR, "decoding error" );
64                 return -1;
65         }
66
67         ndn = ch_strdup( dn );
68
69         if( dn_normalize( ndn ) == NULL ) {
70                 Debug( LDAP_DEBUG_ANY, "do_compare: invalid dn (%s)\n", dn, 0, 0 );
71                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
72                     "invalid DN", NULL, NULL );
73                 goto cleanup;
74         }
75
76         if ( get_ava( op->o_ber, &ava ) != LDAP_SUCCESS ) {
77                 Debug( LDAP_DEBUG_ANY, "do_compare: get ava failed\n", 0, 0, 0 );
78                 send_ldap_disconnect( conn, op,
79                         LDAP_PROTOCOL_ERROR, "decoding error" );
80                 return -1;
81         }
82
83         if ( ber_scanf( op->o_ber, /*{*/ "}" ) == LBER_ERROR ) {
84                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
85                 send_ldap_disconnect( conn, op,
86                         LDAP_PROTOCOL_ERROR, "decoding error" );
87                 return -1;
88         }
89
90         if( ( rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
91                 Debug( LDAP_DEBUG_ANY, "do_compare: get_ctrls failed\n", 0, 0, 0 );
92                 goto cleanup;
93         } 
94
95         Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
96             dn, ava.ava_type, ava.ava_value.bv_val );
97
98         Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
99             op->o_connid, op->o_opid, dn, ava.ava_type, 0 );
100
101         /*
102          * We could be serving multiple database backends.  Select the
103          * appropriate one, or send a referral to our "referral server"
104          * if we don't hold it.
105          */
106         if ( (be = select_backend( ndn )) == NULL ) {
107                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
108                         NULL, NULL, default_referral, NULL );
109                 rc = 1;
110                 goto cleanup;
111         }
112
113         /* make sure this backend recongizes critical controls */
114         rc = backend_check_controls( be, conn, op ) ;
115
116         if( rc != LDAP_SUCCESS ) {
117                 send_ldap_result( conn, op, rc,
118                         NULL, NULL, NULL, NULL );
119                 goto cleanup;
120         }
121
122         /* deref suffix alias if appropriate */
123         ndn = suffix_alias( be, ndn );
124
125         if ( be->be_compare ) {
126                 (*be->be_compare)( be, conn, op, dn, ndn, &ava );
127         } else {
128                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
129                         NULL, "Function not implemented", NULL, NULL );
130         }
131
132 cleanup:
133         free( dn );
134         free( ndn );
135         ava_free( &ava, 0 );
136
137         return rc;
138 }