Attribute *at,
*at_objectClass = NULL;
struct berval pdn;
- struct berval realdn = BER_BVNULL,
- realndn = BER_BVNULL,
- realpdn = BER_BVNULL;
+ struct berval realdn = BER_BVNULL;
#ifdef BACKSQL_SYNCPROV
/*
goto done;
}
- realndn = op->oq_add.rs_e->e_nname;
- if ( backsql_api_dn2odbc( op, rs, &realndn ) ) {
- Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
- "backsql_api_dn2odbc(\"%s\") failed\n",
- op->oq_add.rs_e->e_name.bv_val, realndn.bv_val, 0 );
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- goto done;
- }
-
- rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realndn );
+ rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realdn, 0 );
if ( rs->sr_err == LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"entry exists\n",
dnParent( &op->oq_add.rs_e->e_nname, &pdn );
}
- realpdn = pdn;
- if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
- Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
- "backsql_api_dn2odbc(\"%s\") failed\n",
- op->oq_add.rs_e->e_name.bv_val, pdn.bv_val, 0 );
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- goto done;
- }
-
- rs->sr_err = backsql_dn2id( op, rs, &parent_id, dbh, &realpdn );
+ rs->sr_err = backsql_dn2id( op, rs, &parent_id, dbh, &pdn, 1 );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"could not lookup parent entry for new record \"%s\"\n",
struct berval dn;
char *matched = NULL;
- if ( realpdn.bv_val != pdn.bv_val ) {
- ch_free( realpdn.bv_val );
- }
-
dn = pdn;
dnParent( &dn, &pdn );
/*
* Empty DN ("") defaults to LDAP_SUCCESS
*/
- realpdn = pdn;
- if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
- Debug( LDAP_DEBUG_TRACE,
- " backsql_add(\"%s\"): "
- "backsql_api_dn2odbc failed\n",
- op->oq_add.rs_e->e_name.bv_val, 0, 0 );
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- goto done;
- }
-
- rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realpdn );
+ rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &pdn, 1 );
switch ( rs->sr_err ) {
case LDAP_NO_SUCH_OBJECT:
if ( !BER_BVISEMPTY( &pdn ) ) {
{
ch_free( realdn.bv_val );
}
- if ( !BER_BVISNULL( &realndn )
- && realndn.bv_val != op->oq_add.rs_e->e_nname.bv_val )
- {
- ch_free( realndn.bv_val );
- }
- if ( !BER_BVISNULL( &realpdn ) && realpdn.bv_val != pdn.bv_val ) {
- ch_free( realpdn.bv_val );
- }
if ( !BER_BVISNULL( &parent_id.eid_ndn ) ) {
(void)backsql_free_entryID( &parent_id, 0 );
}
backsql_srch_info bsi;
AttributeName anlist[2];
int rc;
- struct berval ndn;
Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
return 1;
}
- ndn = op->o_req_ndn;
- if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
- "backsql_api_dn2odbc failed\n",
- 0, 0, 0 );
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- goto error_return;
- }
-
anlist[0].an_name = password->ad_cname;
anlist[0].an_desc = password;
anlist[1].an_name.bv_val = NULL;
- rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE,
- -1, -1, -1, NULL, dbh, op, rs, anlist, 1 );
+ rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
+ -1, -1, -1, NULL, dbh, op, rs, anlist,
+ ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
"could not retrieve bindDN ID - no such entry\n",
return 1;
}
- if ( ndn.bv_val != op->o_req_ndn.bv_val ) {
- ch_free( ndn.bv_val );
- }
-
Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
return 0;
}
backsql_srch_info bsi;
int rc;
AttributeName anlist[2];
- struct berval ndn;
user_entry.e_name.bv_val = NULL;
user_entry.e_name.bv_len = 0;
goto return_results;
}
- ndn = op->o_req_ndn;
- if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
- "backsql_api_dn2odbc failed\n",
- 0, 0, 0 );
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- goto return_results;
- }
-
memset( &anlist[0], 0, 2 * sizeof( AttributeName ) );
anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
user_entry.e_attrs = nrs.sr_operational_attrs;
} else {
- rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE,
- -1, -1, -1, NULL, dbh, op, rs, anlist, 1 );
+ rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
+ -1, -1, -1, NULL, dbh, op, rs, anlist,
+ ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
"could not retrieve compareDN ID - no such entry\n",
(void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
}
- if ( ndn.bv_val != op->o_req_ndn.bv_val ) {
- ch_free( ndn.bv_val );
- }
-
if ( e != NULL ) {
entry_clean( e );
}
goto done;
}
- /* FIXME: API... */
- rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn, 1 );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"could not lookup entry id\n", 0, 0, 0 );
SlapReply *rs,
backsql_entryID *id,
SQLHDBC dbh,
- struct berval *ndn )
+ struct berval *ndn,
+ int muck )
{
backsql_info *bi = op->o_bd->be_private;
- SQLHSTMT sth;
+ SQLHSTMT sth = SQL_NULL_HSTMT;
BACKSQL_ROW_NTS row;
RETCODE rc;
int res;
+ struct berval realndn = BER_BVNULL;
/* TimesTen */
char upperdn[ BACKSQL_MAX_DN_LEN + 1 ];
"backsql_dn2id(): error preparing SQL:\n%s",
bi->sql_id_query, 0, 0);
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
- SQLFreeStmt( sth, SQL_DROP );
- return LDAP_OTHER;
+ res = LDAP_OTHER;
+ goto done;
+ }
+
+ realndn = *ndn;
+ if ( muck ) {
+ if ( backsql_api_dn2odbc( op, rs, &realndn ) ) {
+ Debug( LDAP_DEBUG_TRACE, " backsql_dn2id(\"%s\"): "
+ "backsql_api_dn2odbc(\"%s\") failed\n",
+ ndn->bv_val, realndn.bv_val, 0 );
+ res = LDAP_OTHER;
+ goto done;
+ }
}
if ( BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ) {
* that can be searched using indexes
*/
- for ( i = 0, j = ndn->bv_len - 1; ndn->bv_val[ i ]; i++, j--) {
- upperdn[ i ] = ndn->bv_val[ j ];
+ for ( i = 0, j = realndn.bv_len - 1; realndn.bv_val[ i ]; i++, j--) {
+ upperdn[ i ] = realndn.bv_val[ j ];
}
upperdn[ i ] = '\0';
ldap_pvt_str2upper( upperdn );
} else {
if ( BACKSQL_USE_REVERSE_DN( bi ) ) {
- AC_MEMCPY( upperdn, ndn->bv_val, ndn->bv_len + 1 );
+ AC_MEMCPY( upperdn, realndn.bv_val, realndn.bv_len + 1 );
ldap_pvt_str2upper( upperdn );
Debug( LDAP_DEBUG_TRACE,
"==>backsql_dn2id(): upperdn=\"%s\"\n",
ber_str2bv( upperdn, 0, 0, &tbbDN );
} else {
- tbbDN = *ndn;
+ tbbDN = realndn;
}
}
"error binding dn=\"%s\" parameter:\n",
tbbDN.bv_val, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
- SQLFreeStmt( sth, SQL_DROP );
- return LDAP_OTHER;
+ res = LDAP_OTHER;
+ goto done;
}
rc = SQLExecute( sth );
"error executing query (\"%s\", \"%s\"):\n",
bi->sql_id_query, tbbDN.bv_val, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
- SQLFreeStmt( sth, SQL_DROP );
- return LDAP_OTHER;
+ res = LDAP_OTHER;
+ goto done;
}
backsql_BindRowAsStrings( sth, &row );
Debug( LDAP_DEBUG_TRACE,
"<==backsql_dn2id(\"%s\"): "
"dnPrettyNormal failed (%d: %s)\n",
- ndn->bv_val, res,
+ realndn.bv_val, res,
ldap_err2string( res ) );
/* cleanup... */
}
backsql_FreeRow( &row );
- SQLFreeStmt( sth, SQL_DROP );
+done:;
+ if ( sth != SQL_NULL_HSTMT ) {
+ SQLFreeStmt( sth, SQL_DROP );
+ }
+
+ if ( !BER_BVISNULL( &realndn ) && realndn.bv_val != ndn->bv_val ) {
+ ch_free( realndn.bv_val );
+ }
+
return res;
}
*/
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
? "SQL-backend error" : NULL;
- send_ldap_result( op, rs );
- return 1;
+ goto done;
}
- /* FIXME: API... */
- rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn, 1 );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
"could not lookup entry id\n", 0, 0, 0 );
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
? "SQL-backend error" : NULL;
- send_ldap_result( op, rs );
- return 1;
+ goto done;
}
#ifdef BACKSQL_ARBITRARY_KEY
*/
rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error";
- send_ldap_result( op, rs );
- return 1;
+ goto done;
}
e.e_attrs = NULL;
SQLTransact( SQL_NULL_HENV, dbh,
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
}
+
+done:;
send_ldap_result( op, rs );
Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
- return op->o_noop;
+ return rs->sr_err != LDAP_SUCCESS ? rs->sr_err : op->o_noop;
}
backsql_oc_map_rec *oc = NULL;
struct berval p_dn = BER_BVNULL, p_ndn = BER_BVNULL,
*new_pdn = NULL, *new_npdn = NULL,
- new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
+ new_dn = BER_BVNULL, new_ndn = BER_BVNULL,
+ realnew_dn = BER_BVNULL;
LDAPRDN new_rdn = NULL;
LDAPRDN old_rdn = NULL;
Entry e;
return 1;
}
- /* FIXME: API... */
- rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn, 1 );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup entry id (%d)\n",
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): new entry dn is \"%s\"\n",
new_dn.bv_val, 0, 0 );
- /* FIXME: API... */
- rs->sr_err = backsql_dn2id( op, rs, &pe_id, dbh, &p_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &pe_id, dbh, &p_ndn, 1 );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup old parent entry id\n", 0, 0, 0 );
(void)backsql_free_entryID( &pe_id, 0 );
- /* FIXME: API... */
- rs->sr_err = backsql_dn2id( op, rs, &new_pe_id, dbh, new_npdn );
+ rs->sr_err = backsql_dn2id( op, rs, &new_pe_id, dbh, new_npdn, 1 );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup new parent entry id\n", 0, 0, 0 );
goto done;
}
- rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &new_dn );
+ realnew_dn = new_dn;
+ if ( backsql_api_dn2odbc( op, rs, &realnew_dn ) ) {
+ Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(\"%s\"): "
+ "backsql_api_dn2odbc(\"%s\") failed\n",
+ op->o_req_dn.bv_val, realnew_dn.bv_val, 0 );
+ SQLFreeStmt( sth, SQL_DROP );
+
+ rs->sr_text = "SQL-backend error";
+ rs->sr_err = LDAP_OTHER;
+ goto done;
+ }
+
+ rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &realnew_dn );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_add_attr(): "
}
modrdn_return:;
+ if ( !BER_BVISNULL( &realnew_dn ) && realnew_dn.bv_val != new_dn.bv_val ) {
+ ch_free( realnew_dn.bv_val );
+ }
+
if ( !BER_BVISNULL( &new_dn ) ) {
slap_sl_free( new_dn.bv_val, op->o_tmpmemctx );
}
&& !got[ BACKSQL_OP_ENTRYUUID ]
&& attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID ) == NULL )
{
- struct berval ndn;
backsql_srch_info bsi;
- ndn = rs->sr_entry->e_nname;
- if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
- "backsql_api_dn2odbc failed\n",
- 0, 0, 0 );
- return 1;
- }
-
- rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE,
- -1, -1, -1, NULL, dbh, op, rs, NULL, 1 );
+ rc = backsql_init_search( &bsi, &rs->sr_entry->e_nname,
+ LDAP_SCOPE_BASE, -1, -1, -1, NULL,
+ dbh, op, rs, NULL,
+ ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
"could not retrieve entry ID - no such entry\n",
(void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
- if ( ndn.bv_val != rs->sr_entry->e_nname.bv_val ) {
- free( ndn.bv_val );
- }
-
if ( *ap == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
"could not retrieve entryUUID\n",
/* stores in *id the ID in table ldap_entries corresponding to DN, if any */
int backsql_dn2id( Operation *op, SlapReply *rs, backsql_entryID *id,
- SQLHDBC dbh, struct berval *dn );
+ SQLHDBC dbh, struct berval *dn, int muck );
/* stores in *nchildren the count of children for an entry */
int backsql_count_children( backsql_info *bi, SQLHDBC dbh,
* search.c
*/
+#define BACKSQL_ISF_GET_ID 0x1U
+#define BACKSQL_ISF_MUCK 0x2U
int backsql_init_search( backsql_srch_info *bsi,
struct berval *nbase, int scope, int slimit, int tlimit,
time_t stoptime, Filter *filter, SQLHDBC dbh,
Operation *op, SlapReply *rs, AttributeName *attrs,
- int get_base_id );
+ unsigned flags );
/*
* sql-wrap.h
Operation *op,
SlapReply *rs,
AttributeName *attrs,
- int get_base_id )
+ unsigned flags )
{
AttributeName *p;
int rc = LDAP_SUCCESS;
bsi->bsi_flt_where.bb_len = 0;
bsi->bsi_filter_oc = NULL;
- if ( get_base_id ) {
+ if ( flags & BACKSQL_ISF_GET_ID ) {
assert( op->o_bd->be_private );
- rc = backsql_dn2id( op, rs, &bsi->bsi_base_id, dbh, nbase );
+ rc = backsql_dn2id( op, rs, &bsi->bsi_base_id, dbh, nbase,
+ ( flags & BACKSQL_ISF_MUCK ) );
}
return ( bsi->bsi_status = rc );
time_t stoptime = 0;
backsql_srch_info bsi;
backsql_entryID *eid = NULL;
- struct berval nbase = BER_BVNULL;
+ struct berval nbase = BER_BVNULL,
+ realndn = BER_BVNULL;
manageDSAit = get_manageDSAit( op );
/* compute it anyway; root does not use it */
stoptime = op->o_time + op->ors_tlimit;
- nbase = op->o_req_ndn;
- if ( backsql_api_dn2odbc( op, rs, &nbase ) ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
- "backsql_api_dn2odbc failed\n",
- 0, 0, 0 );
+ realndn = op->o_req_ndn;
+ if ( backsql_api_dn2odbc( op, rs, &realndn ) ) {
+ Debug( LDAP_DEBUG_TRACE, " backsql_search(\"%s\"): "
+ "backsql_api_dn2odbc(\"%s\") failed\n",
+ op->o_req_ndn.bv_val, realndn.bv_val, 0 );
rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error";
send_ldap_result( op, rs );
}
/* init search */
- rs->sr_err = backsql_init_search( &bsi, &nbase,
+ rs->sr_err = backsql_init_search( &bsi, &realndn,
op->ors_scope,
op->ors_slimit, op->ors_tlimit,
stoptime, op->ors_filter,
- dbh, op, rs, op->ors_attrs, 1 );
+ dbh, op, rs, op->ors_attrs,
+ ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
if ( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
goto done;
&e->e_nname,
LDAP_SCOPE_BASE,
-1, -1, -1, NULL,
- dbh, op, rs, NULL, 0 );
+ dbh, op, rs, NULL,
+ BACKSQL_ISF_MUCK );
bsi2.bsi_e = &user_entry2;
rc = backsql_id2entry( &bsi2, eid );
if ( rc == LDAP_SUCCESS ) {
#endif /* BACKSQL_SYNCPROV */
done:;
+ if ( !BER_BVISNULL( &realndn ) && realndn.bv_val != op->o_req_ndn.bv_val ) {
+ ch_free( realndn.bv_val );
+ }
+
if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
(void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
}
ndn,
LDAP_SCOPE_BASE,
SLAP_NO_LIMIT, SLAP_NO_LIMIT, -1, NULL,
- dbh, op, &rs, at ? anlist : NULL, 1 );
+ dbh, op, &rs, at ? anlist : NULL,
+ ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
if ( rc != LDAP_SUCCESS ) {
return rc;
}