]> git.sur5r.net Git - openldap/blob - servers/ldapd/compare.c
Blindly added Autoconf support to ldapd.
[openldap] / servers / ldapd / compare.c
1 /*
2  * Copyright (c) 1990 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 <quipu/commonarg.h>
20 #include <quipu/attrvalue.h>
21 #include <quipu/ds_error.h>
22 #include <quipu/compare.h>
23 #include <quipu/dap2.h>
24 #include <quipu/dua.h>
25
26 #include "lber.h"
27 #include "ldap.h"
28 #include "common.h"
29
30 #ifdef HAVE_COMPAT20
31 extern int      ldap_compat;
32 #define COMPTAG (ldap_compat == 20 ? OLD_LDAP_RES_COMPARE : LDAP_RES_COMPARE)
33 #else
34 #define COMPTAG LDAP_RES_COMPARE
35 #endif
36
37 int
38 do_compare( 
39     Sockbuf     *clientsb,
40     struct msg  *m,
41     BerElement  *ber
42 )
43 {
44         char                    *dn, *attr, *value;
45         int                     rc;
46         struct ds_compare_arg   ca;
47         AttributeType           type;
48         static CommonArgs       common = default_common_args;
49         extern short            ldap_dn_syntax;
50
51         Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
52
53         /*
54          * Parse the compare request.  It looks like this:
55          *      CompareRequest := [APPLICATION 14] SEQUENCE {
56          *              entry   DistinguishedName,
57          *              ava     SEQUENCE {
58          *                      type    AttributeType,
59          *                      value   AttributeValue
60          *              }
61          *      }
62          */
63
64 #if ISODEPACKAGE == IC
65 #if ICRELEASE > 2
66         DAS_CompareArgument_INIT ( &ca );
67 #endif
68 #endif
69
70         if ( ber_scanf( ber, "{a{aa}}", &dn, &attr, &value ) == LBER_ERROR ) {
71                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
72                 send_ldap_msgresult( clientsb, COMPTAG, m,
73                     LDAP_PROTOCOL_ERROR, NULL, "" );
74                 return( 0 );
75         }
76
77         Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
78             dn, attr, value );
79
80         ca.cma_object = ldap_str2dn( dn );
81         free( dn );
82         if ( ca.cma_object == NULLDN ) {
83                 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
84                 send_ldap_msgresult( clientsb, COMPTAG, m,
85                     LDAP_INVALID_DN_SYNTAX, NULL, "" );
86                 return( 0 );
87         }
88
89         type = str2AttrT( attr );
90         if ( type == NULLAttrT ) {
91                 Debug( LDAP_DEBUG_ANY, "str2AttrT failed\n", 0, 0, 0 );
92                 send_ldap_msgresult( clientsb, COMPTAG, m,
93                     LDAP_UNDEFINED_TYPE, NULL, attr );
94                 free( attr );
95                 return( 0 );
96         }
97         free( attr );
98         ca.cma_purported.ava_type = type;
99
100         ca.cma_purported.ava_value = ldap_str2AttrV( value, type->oa_syntax );
101         free( value );
102         if ( ca.cma_purported.ava_value == NULLAttrV ) {
103                 Debug( LDAP_DEBUG_ANY, "str2AttrV failed\n", 0, 0, 0 );
104                 send_ldap_msgresult( clientsb, COMPTAG, m,
105                     LDAP_INVALID_SYNTAX, NULL, "" );
106                 return( 0 );
107         }
108
109         ca.cma_common = common; /* struct copy */
110
111         rc = initiate_dap_operation( OP_COMPARE, m, &ca );
112
113         dn_free( ca.cma_object );
114         AttrV_free( ca.cma_purported.ava_value );
115
116         if ( rc != 0 ) {
117                 send_ldap_msgresult( clientsb, COMPTAG, m, rc, NULL, "" );
118                 return( 0 );
119         }
120
121         return( 1 );
122 }
123
124 void
125 compare_result( 
126     Sockbuf                     *sb,
127     struct msg                  *m,
128     struct ds_compare_result    *cr
129 )
130 {
131         send_ldap_msgresult( sb, COMPTAG, m, cr->cmr_matched ?
132             LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE, NULL, "" );
133
134         return;
135 }