2 * Copyright (c) 1990 Regents of the University of Michigan.
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.
14 #include <quipu/commonarg.h>
15 #include <quipu/attrvalue.h>
16 #include <quipu/ds_error.h>
17 #include <quipu/compare.h>
18 #include <quipu/dap2.h>
19 #include <quipu/dua.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
27 extern int ldap_compat;
28 #define COMPTAG (ldap_compat == 20 ? OLD_LDAP_RES_COMPARE : LDAP_RES_COMPARE)
30 #define COMPTAG LDAP_RES_COMPARE
40 char *dn, *attr, *value;
42 struct ds_compare_arg ca;
44 static CommonArgs common = default_common_args;
45 extern short ldap_dn_syntax;
47 Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
50 * Parse the compare request. It looks like this:
51 * CompareRequest := [APPLICATION 14] SEQUENCE {
52 * entry DistinguishedName,
55 * value AttributeValue
60 #if ISODEPACKAGE == IC
62 DAS_CompareArgument_INIT ( &ca );
66 if ( ber_scanf( ber, "{a{aa}}", &dn, &attr, &value ) == LBER_ERROR ) {
67 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
68 send_ldap_msgresult( clientsb, COMPTAG, m,
69 LDAP_PROTOCOL_ERROR, NULL, "" );
73 Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
76 ca.cma_object = ldap_str2dn( dn );
78 if ( ca.cma_object == NULLDN ) {
79 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
80 send_ldap_msgresult( clientsb, COMPTAG, m,
81 LDAP_INVALID_DN_SYNTAX, NULL, "" );
85 type = str2AttrT( attr );
86 if ( type == NULLAttrT ) {
87 Debug( LDAP_DEBUG_ANY, "str2AttrT failed\n", 0, 0, 0 );
88 send_ldap_msgresult( clientsb, COMPTAG, m,
89 LDAP_UNDEFINED_TYPE, NULL, attr );
94 ca.cma_purported.ava_type = type;
96 ca.cma_purported.ava_value = ldap_str2AttrV( value, type->oa_syntax );
98 if ( ca.cma_purported.ava_value == NULLAttrV ) {
99 Debug( LDAP_DEBUG_ANY, "str2AttrV failed\n", 0, 0, 0 );
100 send_ldap_msgresult( clientsb, COMPTAG, m,
101 LDAP_INVALID_SYNTAX, NULL, "" );
105 ca.cma_common = common; /* struct copy */
107 rc = initiate_dap_operation( OP_COMPARE, m, &ca );
109 dn_free( ca.cma_object );
110 AttrV_free( ca.cma_purported.ava_value );
113 send_ldap_msgresult( clientsb, COMPTAG, m, rc, NULL, "" );
124 struct ds_compare_result *cr
127 send_ldap_msgresult( sb, COMPTAG, m, cr->cmr_matched ?
128 LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE, NULL, "" );