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;
28 Entry *e = NULL, user_entry;
29 Attribute *a = NULL, *a_op = NULL;
30 backsql_srch_info bsi;
32 AttributeName anlist[2];
34 user_entry.e_name.bv_val = NULL;
35 user_entry.e_name.bv_len = 0;
36 user_entry.e_nname.bv_val = NULL;
37 user_entry.e_nname.bv_len = 0;
38 user_entry.e_attrs = NULL;
40 Debug( LDAP_DEBUG_TRACE, "==>backsql_compare()\n", 0, 0, 0 );
42 rs->sr_err = backsql_get_db_conn( op, &dbh );
44 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
45 "could not get connection handle - exiting\n",
48 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
49 ? "SQL-backend error" : NULL;
53 rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
54 if ( rc != LDAP_SUCCESS ) {
55 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
56 "could not retrieve compare dn id - no such entry\n",
58 rs->sr_err = LDAP_NO_SUCH_OBJECT;
62 anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
63 anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
64 anlist[1].an_name.bv_val = NULL;
67 * Try to get attr as dynamic operational
69 if ( is_at_operational( op->oq_compare.rs_ava->aa_desc->ad_type ) ) {
70 AttributeName *an_old;
73 user_entry.e_attrs = NULL;
74 user_entry.e_name = op->o_req_dn;
75 user_entry.e_nname = op->o_req_ndn;
77 an_old = rs->sr_attrs;
80 rs->sr_attrs = anlist;
81 rs->sr_entry = &user_entry;
82 rs->sr_err = backsql_operational( op, rs, 0, &a_op );
83 rs->sr_attrs = an_old;
86 if ( rs->sr_err != LDAP_SUCCESS ) {
93 * attr was dynamic operational
96 user_entry.e_attrs = a_op;
100 backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
101 -1, -1, -1, NULL, dbh, op, anlist );
102 e = backsql_id2entry( &bsi, &user_entry, &user_id );
104 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
105 "error in backsql_id2entry() "
106 "- compare failed\n", 0, 0, 0 );
107 rs->sr_err = LDAP_OTHER;
112 if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
113 &op->oq_compare.rs_ava->aa_value,
114 ACL_COMPARE, NULL ) ) {
115 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
119 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
120 for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
122 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
124 rs->sr_err = LDAP_COMPARE_FALSE;
125 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
126 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
127 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
129 &op->oq_compare.rs_ava->aa_value,
130 op->o_tmpmemctx ) == 0 )
132 rs->sr_err = LDAP_COMPARE_TRUE;
138 send_ldap_result( op, rs );
141 if ( e->e_name.bv_val != NULL ) {
142 free( e->e_name.bv_val );
145 if ( e->e_nname.bv_val != NULL ) {
146 free( e->e_nname.bv_val );
149 if ( e->e_attrs != NULL ) {
150 attrs_free( e->e_attrs );
154 Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
155 switch ( rs->sr_err ) {
156 case LDAP_COMPARE_TRUE:
157 case LDAP_COMPARE_FALSE:
166 * sets the supported operational attributes (if required)
177 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
178 SQLHDBC dbh = SQL_NULL_HDBC;
182 Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry '%s'\n",
183 rs->sr_entry->e_nname.bv_val, 0, 0 );
186 if ( ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) )
187 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL ) {
189 rc = backsql_get_db_conn( op, &dbh );
190 if ( rc != LDAP_SUCCESS ) {
191 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
192 "could not get connection handle - exiting\n",
197 rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname );
200 case LDAP_COMPARE_TRUE:
201 case LDAP_COMPARE_FALSE:
202 *aa = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
210 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
211 "has_children failed( %d)\n", rc, 0, 0 );
217 Debug( LDAP_DEBUG_TRACE, "<==backsql_operational()\n", 0, 0, 0);
222 #endif /* SLAPD_SQL */