2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Dmitry Kovalev for inclusion
18 * by OpenLDAP Software.
26 #include <sys/types.h>
34 backsql_compare( Operation *op, SlapReply *rs )
36 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
37 backsql_entryID user_id;
39 Entry *e = NULL, user_entry;
40 Attribute *a = NULL, *a_op = NULL;
41 backsql_srch_info bsi;
43 AttributeName anlist[2];
45 user_entry.e_name.bv_val = NULL;
46 user_entry.e_name.bv_len = 0;
47 user_entry.e_nname.bv_val = NULL;
48 user_entry.e_nname.bv_len = 0;
49 user_entry.e_attrs = NULL;
51 Debug( LDAP_DEBUG_TRACE, "==>backsql_compare()\n", 0, 0, 0 );
53 rs->sr_err = backsql_get_db_conn( op, &dbh );
55 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
56 "could not get connection handle - exiting\n",
59 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
60 ? "SQL-backend error" : NULL;
64 rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
65 if ( rc != LDAP_SUCCESS ) {
66 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
67 "could not retrieve compare dn id - no such entry\n",
69 rs->sr_err = LDAP_NO_SUCH_OBJECT;
73 anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
74 anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
75 anlist[1].an_name.bv_val = NULL;
78 * Try to get attr as dynamic operational
80 if ( is_at_operational( op->oq_compare.rs_ava->aa_desc->ad_type ) ) {
81 AttributeName *an_old;
84 user_entry.e_attrs = NULL;
85 user_entry.e_name = op->o_req_dn;
86 user_entry.e_nname = op->o_req_ndn;
88 an_old = rs->sr_attrs;
91 rs->sr_attrs = anlist;
92 rs->sr_entry = &user_entry;
93 rs->sr_err = backsql_operational( op, rs, 0, &a_op );
94 rs->sr_attrs = an_old;
97 if ( rs->sr_err != LDAP_SUCCESS ) {
104 * attr was dynamic operational
106 if ( a_op != NULL ) {
107 user_entry.e_attrs = a_op;
111 backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
112 -1, -1, -1, NULL, dbh, op, anlist );
113 e = backsql_id2entry( &bsi, &user_entry, &user_id );
115 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
116 "error in backsql_id2entry() "
117 "- compare failed\n", 0, 0, 0 );
118 rs->sr_err = LDAP_OTHER;
123 if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
124 &op->oq_compare.rs_ava->aa_value,
125 ACL_COMPARE, NULL ) ) {
126 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
130 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
131 for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
133 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
135 rs->sr_err = LDAP_COMPARE_FALSE;
136 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
137 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
138 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
140 &op->oq_compare.rs_ava->aa_value,
141 op->o_tmpmemctx ) == 0 )
143 rs->sr_err = LDAP_COMPARE_TRUE;
149 send_ldap_result( op, rs );
152 if ( e->e_name.bv_val != NULL ) {
153 free( e->e_name.bv_val );
156 if ( e->e_nname.bv_val != NULL ) {
157 free( e->e_nname.bv_val );
160 if ( e->e_attrs != NULL ) {
161 attrs_free( e->e_attrs );
165 Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
166 switch ( rs->sr_err ) {
167 case LDAP_COMPARE_TRUE:
168 case LDAP_COMPARE_FALSE:
177 * sets the supported operational attributes (if required)
188 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
189 SQLHDBC dbh = SQL_NULL_HDBC;
193 Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry '%s'\n",
194 rs->sr_entry->e_nname.bv_val, 0, 0 );
197 if ( ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) )
198 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL ) {
200 rc = backsql_get_db_conn( op, &dbh );
201 if ( rc != LDAP_SUCCESS ) {
202 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
203 "could not get connection handle - exiting\n",
208 rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname );
211 case LDAP_COMPARE_TRUE:
212 case LDAP_COMPARE_FALSE:
213 *aa = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
221 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
222 "has_children failed( %d)\n", rc, 0, 0 );
228 Debug( LDAP_DEBUG_TRACE, "<==backsql_operational()\n", 0, 0, 0);
233 #endif /* SLAPD_SQL */