2 * Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
4 * Redistribution and use in source and binary forms are permitted only
5 * as authorized by the OpenLDAP Public License. A copy of this
6 * license is available at http://www.OpenLDAP.org/license.html or
7 * in file LICENSE in the top-level directory of the distribution.
15 #include <sys/types.h>
23 backsql_compare( Operation *op, SlapReply *rs )
25 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
26 backsql_entryID user_id;
30 backsql_srch_info bsi;
32 AttributeName anlist[2];
34 Debug( LDAP_DEBUG_TRACE, "==>backsql_compare()\n", 0, 0, 0 );
36 rs->sr_err = backsql_get_db_conn( op, &dbh );
38 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
39 "could not get connection handle - exiting\n",
42 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
43 ? "SQL-backend error" : NULL;
47 rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
48 if ( rc != LDAP_SUCCESS ) {
49 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
50 "could not retrieve bind dn id - no such entry\n",
52 rs->sr_err = LDAP_INVALID_CREDENTIALS;
56 anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
57 anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
58 anlist[1].an_name.bv_val = NULL;
59 backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
60 -1, -1, -1, NULL, dbh, op, anlist);
61 e = backsql_id2entry( &bsi, &user_entry, &user_id );
63 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
64 "error in backsql_id2entry() - auth failed\n",
66 rs->sr_err = LDAP_OTHER;
70 if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
71 &op->oq_compare.rs_ava->aa_value,
72 ACL_COMPARE, NULL ) ) {
73 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
78 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
79 for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
81 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
83 rs->sr_err = LDAP_COMPARE_FALSE;
84 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
85 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
86 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
88 &op->oq_compare.rs_ava->aa_value,
89 op->o_tmpmemctx ) == 0 )
91 rs->sr_err = LDAP_COMPARE_TRUE;
97 send_ldap_result( op, rs );
99 Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
100 switch ( rs->sr_err ) {
101 case LDAP_COMPARE_TRUE:
102 case LDAP_COMPARE_FALSE:
111 * sets the supported operational attributes (if required)
122 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
123 SQLHDBC dbh = SQL_NULL_HDBC;
127 Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry '%s'\n",
128 rs->sr_entry->e_nname.bv_val, 0, 0 );
131 if ( ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) )
132 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL ) {
134 rc = backsql_get_db_conn( op, &dbh );
135 if ( rc != LDAP_SUCCESS ) {
136 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
137 "could not get connection handle - exiting\n",
142 rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname );
145 case LDAP_COMPARE_TRUE:
146 case LDAP_COMPARE_FALSE:
147 *aa = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
155 Debug(LDAP_DEBUG_TRACE,
156 "backsql_operational(): "
157 "has_children failed( %d)\n",
167 #endif /* SLAPD_SQL */