]> git.sur5r.net Git - openldap/blob - servers/ldapd/compare.c
schema definitions from Active Directory.
[openldap] / servers / ldapd / compare.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright (c) 1990 Regents of the University of Michigan.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that this notice is preserved and that due credit is given
8  * to the University of Michigan at Ann Arbor. The name of the University
9  * may not be used to endorse or promote products derived from this
10  * software without specific prior written permission. This software
11  * is provided ``as is'' without express or implied warranty.
12  */
13
14 #include "portable.h"
15
16 #include <stdio.h>
17
18 #include <ac/socket.h>
19
20 #include <quipu/commonarg.h>
21 #include <quipu/attrvalue.h>
22 #include <quipu/ds_error.h>
23 #include <quipu/compare.h>
24 #include <quipu/dap2.h>
25 #include <quipu/dua.h>
26
27 #include "lber.h"
28 #include "ldap.h"
29 #include "common.h"
30
31 #ifdef HAVE_COMPAT20
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
50         Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
51
52         /*
53          * Parse the compare request.  It looks like this:
54          *      CompareRequest := [APPLICATION 14] SEQUENCE {
55          *              entry   DistinguishedName,
56          *              ava     SEQUENCE {
57          *                      type    AttributeType,
58          *                      value   AttributeValue
59          *              }
60          *      }
61          */
62
63 #if ISODEPACKAGE == IC
64 #if ICRELEASE > 2
65         DAS_CompareArgument_INIT ( &ca );
66 #endif
67 #endif
68
69         if ( ber_scanf( ber, "{a{aa}}", &dn, &attr, &value ) == LBER_ERROR ) {
70                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
71                 send_ldap_msgresult( clientsb, COMPTAG, m,
72                     LDAP_PROTOCOL_ERROR, NULL, "" );
73                 return( 0 );
74         }
75
76         Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
77             dn, attr, value );
78
79         ca.cma_object = ldap_str2dn( dn );
80         free( dn );
81         if ( ca.cma_object == NULLDN ) {
82                 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
83                 send_ldap_msgresult( clientsb, COMPTAG, m,
84                     LDAP_INVALID_DN_SYNTAX, NULL, "" );
85                 return( 0 );
86         }
87
88         type = str2AttrT( attr );
89         if ( type == NULLAttrT ) {
90                 Debug( LDAP_DEBUG_ANY, "str2AttrT failed\n", 0, 0, 0 );
91                 send_ldap_msgresult( clientsb, COMPTAG, m,
92                     LDAP_UNDEFINED_TYPE, NULL, attr );
93                 free( attr );
94                 return( 0 );
95         }
96         free( attr );
97         ca.cma_purported.ava_type = type;
98
99         ca.cma_purported.ava_value = ldap_str2AttrV( value, type->oa_syntax );
100         free( value );
101         if ( ca.cma_purported.ava_value == NULLAttrV ) {
102                 Debug( LDAP_DEBUG_ANY, "str2AttrV failed\n", 0, 0, 0 );
103                 send_ldap_msgresult( clientsb, COMPTAG, m,
104                     LDAP_INVALID_SYNTAX, NULL, "" );
105                 return( 0 );
106         }
107
108         ca.cma_common = common; /* struct copy */
109
110         rc = initiate_dap_operation( OP_COMPARE, m, &ca );
111
112         dn_free( ca.cma_object );
113         AttrV_free( ca.cma_purported.ava_value );
114
115         if ( rc != 0 ) {
116                 send_ldap_msgresult( clientsb, COMPTAG, m, rc, NULL, "" );
117                 return( 0 );
118         }
119
120         return( 1 );
121 }
122
123 void
124 compare_result( 
125     Sockbuf                     *sb,
126     struct msg                  *m,
127     struct ds_compare_result    *cr
128 )
129 {
130         send_ldap_msgresult( sb, COMPTAG, m, cr->cmr_matched ?
131             LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE, NULL, "" );
132
133         return;
134 }