SRCS = init.c config.c search.c bind.c compare.c operational.c \
entry-id.c schema-map.c sql-wrap.c modify.c util.c \
- add.c delete.c modrdn.c
+ add.c delete.c modrdn.c api.c
OBJS = init.lo config.lo search.lo bind.lo compare.lo operational.lo \
entry-id.lo schema-map.lo sql-wrap.lo modify.lo util.lo \
- add.lo delete.lo modrdn.lo
+ add.lo delete.lo modrdn.lo api.lo
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
RETCODE rc;
backsql_oc_map_rec *oc = NULL;
backsql_at_map_rec *at_rec = NULL;
- backsql_entryID e_id, parent_id;
+ backsql_entryID parent_id = BACKSQL_ENTRYID_INIT;
Entry p;
Attribute *at;
struct berval *at_val;
SQLUSMALLINT pno, po;
/* procedure return code */
int prc;
+ struct berval realdn, realpdn;
Debug( LDAP_DEBUG_TRACE, "==>backsql_add(): adding entry \"%s\"\n",
op->oq_add.rs_e->e_name.bv_val, 0, 0 );
/*
* Check if entry exists
*/
- rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->oq_add.rs_e->e_name );
+ realdn = op->oq_add.rs_e->e_name;
+ if ( backsql_api_dn2odbc( op, rs, &realdn ) ) {
+ 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 done;
+ }
+
+ rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realdn );
if ( rs->sr_err == LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): "
"entry \"%s\" exists\n",
* Check if parent exists
*/
dnParent( &op->oq_add.rs_e->e_name, &pdn );
- rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &pdn );
+ realpdn = pdn;
+ if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
+ 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 done;
+ }
+
+ rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &realpdn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): "
"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
*/
- rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &pdn );
+ realpdn = pdn;
+ if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
+ Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
+ "backsql_api_dn2odbc failed\n",
+ 0, 0, 0 );
+ rs->sr_err = LDAP_OTHER;
+ rs->sr_text = "SQL-backend error";
+ goto done;
+ }
+
+ rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realpdn );
switch ( rs->sr_err ) {
case LDAP_NO_SUCH_OBJECT:
if ( pdn.bv_len > 0 ) {
done:;
send_ldap_result( op, rs );
+ if ( realdn.bv_val != op->oq_add.rs_e->e_name.bv_val ) {
+ ch_free( realdn.bv_val );
+ }
+ if ( realpdn.bv_val != pdn.bv_val ) {
+ ch_free( realpdn.bv_val );
+ }
+ if ( parent_id.eid_dn.bv_val != NULL ) {
+ backsql_free_entryID( &parent_id, 0 );
+ }
+
Debug( LDAP_DEBUG_TRACE, "<==backsql_add(): %d%s%s\n",
rs->sr_err,
rs->sr_text ? ": " : "",
--- /dev/null
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1999-2004 The OpenLDAP Foundation.
+ * Portions Copyright 1999 Dmitry Kovalev.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by Dmitry Kovalev for inclusion
+ * by OpenLDAP Software.
+ */
+
+#include "portable.h"
+
+#ifdef SLAPD_SQL
+
+#include <stdio.h>
+#include <sys/types.h>
+#include "ac/string.h"
+
+#include "slap.h"
+#include "lber_pvt.h"
+#include "ldap_pvt.h"
+#include "proto-sql.h"
+
+static backsql_api *backsqlapi;
+
+int
+backsql_api_config( backsql_info *si, const char *name )
+{
+ backsql_api *ba;
+
+ assert( si );
+ assert( name );
+
+ for ( ba = backsqlapi; ba; ba = ba->ba_next ) {
+ if ( strcasecmp( name, ba->ba_name ) == 0 ) {
+ backsql_api *ba2;
+
+ ba2 = ch_malloc( sizeof( backsql_api ) );
+ *ba2 = *ba;
+ ba2->ba_next = si->si_api;
+ si->si_api = ba2;
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+int
+backsql_api_register( backsql_api *ba )
+{
+ backsql_api *ba2;
+
+ assert( ba );
+
+ if ( ba->ba_name == NULL ) {
+ fprintf( stderr, "API module has no name\n" );
+ exit(EXIT_FAILURE);
+ }
+
+ for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
+ if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
+ fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ ba->ba_next = backsqlapi;
+ backsqlapi = ba;
+
+ return 0;
+}
+
+int
+backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn )
+{
+ backsql_info *si = (backsql_info *)op->o_bd->be_private;
+ backsql_api *ba;
+ int rc;
+ struct berval bv;
+
+ ba = si->si_api;
+
+ if ( ba == NULL ) {
+ return 0;
+ }
+
+ ber_dupbv( &bv, dn );
+
+ for ( ; ba; ba = ba->ba_next ) {
+ if ( ba->ba_dn2odbc ) {
+ rc = ( *ba->ba_dn2odbc )( op, rs, &bv );
+
+ if ( rc ) {
+ return rc;
+ }
+ }
+ }
+
+ *dn = bv;
+
+ return 0;
+}
+
+int
+backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn )
+{
+ backsql_info *si = (backsql_info *)op->o_bd->be_private;
+ backsql_api *ba;
+ int rc;
+ struct berval bv;
+
+ ba = si->si_api;
+
+ if ( ba == NULL ) {
+ return 0;
+ }
+
+ ber_dupbv( &bv, dn );
+
+ for ( ; ba; ba = ba->ba_next ) {
+ if ( ba->ba_dn2odbc ) {
+ rc = ( *ba->ba_odbc2dn )( op, rs, &bv );
+
+ if ( rc ) {
+ return rc;
+ }
+ }
+ }
+
+ *dn = bv;
+
+ return 0;
+}
+
+#endif /* SLAPD_SQL */
+
/*
* define to enable varchars as unique keys in user tables
*/
-#undef BACKSQL_ARBITRARY_KEY
+#define BACKSQL_ARBITRARY_KEY
+
+/*
+ * API
+ */
+typedef struct backsql_api {
+ char *ba_name;
+ int (*ba_dn2odbc)( Operation *op, SlapReply *rs, struct berval *dn );
+ int (*ba_odbc2dn)( Operation *op, SlapReply *rs, struct berval *dn );
+ struct backsql_api *ba_next;
+} backsql_api;
/*
* Entry ID structure
struct backsql_entryID *eid_next;
} backsql_entryID;
+#ifdef BACKSQL_ARBITRARY_KEY
+#define BACKSQL_ENTRYID_INIT { BER_BVNULL, BER_BVNULL, 0, BER_BVNULL, NULL }
+#else /* ! BACKSQL_ARBITRARY_KEY */
+#define BACKSQL_ENTRYID_INIT { 0, 0, 0, BER_BVNULL, NULL }
+#endif /* BACKSQL_ARBITRARY_KEY */
+
/*
* "structural" objectClass mapping structure
*/
typedef struct backsql_srch_info {
Operation *bsi_op;
+ SlapReply *bsi_rs;
int bsi_flags;
#define BSQL_SF_ALL_OPER 0x0001
struct berval *bsi_base_dn;
int bsi_scope;
+#define BACKSQL_SCOPE_BASE_LIKE ( LDAP_SCOPE_BASE | 0x1000 )
Filter *bsi_filter;
int bsi_slimit,
bsi_tlimit;
ldap_pvt_thread_mutex_t dbconn_mutex;
ldap_pvt_thread_mutex_t schema_mutex;
SQLHENV db_env;
+
+ backsql_api *si_api;
} backsql_info;
#define BACKSQL_SUCCESS( rc ) \
backsql_bind( Operation *op, SlapReply *rs )
{
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
- backsql_entryID user_id;
+ backsql_entryID user_id = BACKSQL_ENTRYID_INIT;
SQLHDBC dbh;
AttributeDescription *password = slap_schema.si_ad_userPassword;
Entry *e, user_entry;
backsql_srch_info bsi;
AttributeName anlist[2];
int rc;
+ struct berval dn;
Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
return 1;
}
- rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
+ dn = op->o_req_dn;
+ if ( backsql_api_dn2odbc( op, rs, &dn ) ) {
+ 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;
+ }
+
+ rc = backsql_dn2id( bi, &user_id, dbh, &dn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
"could not retrieve bind dn id - no such entry\n",
anlist[0].an_name = password->ad_cname;
anlist[0].an_desc = password;
anlist[1].an_name.bv_val = NULL;
- backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
- -1, -1, -1, NULL, dbh, op, anlist );
+
+ backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE,
+ -1, -1, -1, NULL, dbh, op, rs, anlist );
e = backsql_id2entry( &bsi, &user_entry, &user_id );
if ( e == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
"error in backsql_id2entry() - auth failed\n",
0, 0, 0 );
rs->sr_err = LDAP_OTHER;
- send_ldap_result( op, rs );
- return 1;
+ goto error_return;
}
if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
- send_ldap_result( op, rs );
- return 1;
+ goto error_return;
}
if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
- send_ldap_result( op, rs );
- return 1;
+ goto error_return;
}
if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
rs->sr_err = LDAP_INVALID_CREDENTIALS;
+ goto error_return;
+ }
+
+error_return:;
+ if ( rs->sr_err ) {
send_ldap_result( op, rs );
return 1;
}
+
+ if ( dn.bv_val != op->o_req_dn.bv_val ) {
+ ch_free( dn.bv_val );
+ }
Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
return 0;
backsql_compare( Operation *op, SlapReply *rs )
{
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
- backsql_entryID user_id;
+ backsql_entryID user_id = BACKSQL_ENTRYID_INIT;
SQLHDBC dbh;
Entry *e = NULL, user_entry;
Attribute *a = NULL, *a_op = NULL;
backsql_srch_info bsi;
int rc;
AttributeName anlist[2];
+ struct berval dn;
user_entry.e_name.bv_val = NULL;
user_entry.e_name.bv_len = 0;
goto return_results;
}
- rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
+ dn = op->o_req_dn;
+ if ( backsql_api_dn2odbc( op, rs, &dn ) ) {
+ 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;
+ }
+
+ rc = backsql_dn2id( bi, &user_id, dbh, &dn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
"could not retrieve compare dn id - no such entry\n",
e = &user_entry;
} else {
- backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
- -1, -1, -1, NULL, dbh, op, anlist );
+ backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE,
+ -1, -1, -1, NULL, dbh, op, rs, anlist );
e = backsql_id2entry( &bsi, &user_entry, &user_id );
if ( e == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
return_results:;
send_ldap_result( op, rs );
+ if ( dn.bv_val != op->o_req_dn.bv_val ) {
+ ch_free( dn.bv_val );
+ }
+
if ( e != NULL ) {
if ( e->e_name.bv_val != NULL ) {
free( e->e_name.bv_val );
"fail_if_no_mapping=%s\n",
BACKSQL_FAIL_IF_NO_MAPPING( si ) ? "yes" : "no", 0, 0 );
+ } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) {
+ if ( backsql_api_config( si, argv[ 1 ] ) ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "<==backsql_db_config (%s line %d): "
+ "unable to load sqllayer \"%s\"\n",
+ fname, lineno, argv[ 1 ] );
+ return 1;
+ }
+
} else {
return SLAP_CONF_UNKNOWN;
}
SQLHSTMT sth;
RETCODE rc;
backsql_oc_map_rec *oc = NULL;
- backsql_entryID e_id;
+ backsql_entryID e_id = BACKSQL_ENTRYID_INIT;
Entry e;
/* first parameter no */
SQLUSMALLINT pno;
/* TimesTen */
char upperdn[ BACKSQL_MAX_DN_LEN + 1 ];
- char *toBind;
+ struct berval toBind;
int i, j;
- Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): dn='%s'\n",
- dn->bv_val, 0, 0 );
+ /*
+ * NOTE: id can be NULL; in this case, the function
+ * simply checks whether the DN can be successfully
+ * turned into an ID, returning LDAP_SUCCESS for
+ * positive cases, or the most appropriate error
+ */
- assert( id );
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): dn=\"%s\"%s\n",
+ dn->bv_val, id == NULL ? " (no ID)" : "", 0 );
if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) {
Debug( LDAP_DEBUG_TRACE,
}
/* begin TimesTen */
- Debug(LDAP_DEBUG_TRACE, "id_query '%s'\n", bi->id_query, 0, 0);
+ Debug(LDAP_DEBUG_TRACE, "id_query \"%s\"\n", bi->id_query, 0, 0);
assert( bi->id_query );
rc = backsql_Prepare( dbh, &sth, bi->id_query, 0 );
if ( rc != SQL_SUCCESS ) {
upperdn[ i ] = '\0';
ldap_pvt_str2upper( upperdn );
- Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): upperdn='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): upperdn=\"%s\"\n",
upperdn, 0, 0 );
- toBind = upperdn;
+ ber_str2bv( upperdn, 0, 0, &toBind );
+
} else {
if ( BACKSQL_USE_REVERSE_DN( bi ) ) {
AC_MEMCPY( upperdn, dn->bv_val, dn->bv_len + 1 );
ldap_pvt_str2upper( upperdn );
Debug( LDAP_DEBUG_TRACE,
- "==>backsql_dn2id(): upperdn='%s'\n",
+ "==>backsql_dn2id(): upperdn=\"%s\"\n",
upperdn, 0, 0 );
- toBind = upperdn;
+ ber_str2bv( upperdn, 0, 0, &toBind );
} else {
- toBind = dn->bv_val;
+ toBind = *dn;
}
}
- rc = backsql_BindParamStr( sth, 1, toBind, BACKSQL_MAX_DN_LEN );
+ rc = backsql_BindParamStr( sth, 1, toBind.bv_val, BACKSQL_MAX_DN_LEN );
if ( rc != SQL_SUCCESS) {
/* end TimesTen */
Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): "
"error binding dn=\"%s\" parameter:\n",
- toBind, 0, 0 );
+ toBind.bv_val, 0, 0 );
backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
return LDAP_OTHER;
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): "
"error executing query (\"%s\", \"%s\"):\n",
- bi->id_query, toBind, 0 );
+ bi->id_query, toBind.bv_val, 0 );
backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
return LDAP_OTHER;
backsql_BindRowAsStrings( sth, &row );
rc = SQLFetch( sth );
if ( BACKSQL_SUCCESS( rc ) ) {
+ res = LDAP_SUCCESS;
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): id=%s keyval=%s oc_id=%s\n",
+ row.cols[ 0 ], row.cols[ 1 ], row.cols[ 2 ] );
+
+ if ( id != NULL ) {
#ifdef BACKSQL_ARBITRARY_KEY
- ber_str2bv( row.cols[ 0 ], 0, 1, &id->eid_id );
- ber_str2bv( row.cols[ 1 ], 0, 1, &id->eid_keyval );
+ ber_str2bv( row.cols[ 0 ], 0, 1, &id->eid_id );
+ ber_str2bv( row.cols[ 1 ], 0, 1, &id->eid_keyval );
#else /* ! BACKSQL_ARBITRARY_KEY */
- id->eid_id = strtol( row.cols[ 0 ], NULL, 0 );
- id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 );
+ id->eid_id = strtol( row.cols[ 0 ], NULL, 0 );
+ id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 );
#endif /* ! BACKSQL_ARBITRARY_KEY */
- id->eid_oc_id = strtol( row.cols[ 2 ], NULL, 0 );
- ber_dupbv( &id->eid_dn, dn );
- id->eid_next = NULL;
+ id->eid_oc_id = strtol( row.cols[ 2 ], NULL, 0 );
- res = LDAP_SUCCESS;
+ ber_dupbv( &id->eid_dn, dn );
+ id->eid_next = NULL;
+ }
} else {
res = LDAP_NO_SUCH_OBJECT;
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): no match\n",
+ 0, 0, 0 );
}
backsql_FreeRow( &row );
SQLFreeStmt( sth, SQL_DROP );
- if ( res == LDAP_SUCCESS ) {
-#ifdef BACKSQL_ARBITRARY_KEY
- Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): id=%s\n",
- id->eid_id.bv_val, 0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
- Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): id=%ld\n",
- id->eid_id, 0, 0 );
-#endif /* !BACKSQL_ARBITRARY_KEY */
- } else {
- Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): no match\n",
- 0, 0, 0 );
- }
return res;
}
RETCODE rc;
int res = LDAP_SUCCESS;
- Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn=\"%s\"\n",
dn->bv_val, 0, 0 );
if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) {
}
/* begin TimesTen */
- Debug(LDAP_DEBUG_TRACE, "children id query '%s'\n",
+ Debug(LDAP_DEBUG_TRACE, "children id query \"%s\"\n",
bi->has_children_query, 0, 0);
assert( bi->has_children_query );
rc = backsql_Prepare( dbh, &sth, bi->has_children_query, 0 );
#ifdef BACKSQL_ARBITRARY_KEY
Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): "
- "oc='%s' attr='%s' keyval=%s\n",
+ "oc=\"%s\" attr=\"%s\" keyval=%s\n",
BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val,
bsi->bsi_c_eid->eid_keyval.bv_val );
#else /* ! BACKSQL_ARBITRARY_KEY */
Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): "
- "oc='%s' attr='%s' keyval=%ld\n",
+ "oc=\"%s\" attr=\"%s\" keyval=%ld\n",
BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val,
bsi->bsi_c_eid->eid_keyval );
#endif /* ! BACKSQL_ARBITRARY_KEY */
rc = SQLExecute( sth );
if ( ! BACKSQL_SUCCESS( rc ) ) {
Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
- "error executing attribute query '%s'\n",
+ "error executing attribute query \"%s\"\n",
at->bam_query, 0, 0 );
backsql_PrintErrors( bi->db_env, bsi->bsi_dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
(int)row.col_prec[ i ], 0, 0 );
} else {
Debug( LDAP_DEBUG_TRACE, "NULL value "
- "in this row for attribute '%s'\n",
+ "in this row for attribute \"%s\"\n",
row.col_names[ i ].bv_val, 0, 0 );
#endif /* BACKSQL_TRACE */
}
rc = backsql_supad2at( bsi->bsi_oc, attr->an_desc, &vat );
if ( rc != 0 || vat == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
- "attribute '%s' is not defined "
- "for objectlass '%s'\n",
+ "attribute \"%s\" is not defined "
+ "for objectlass \"%s\"\n",
attr->an_name.bv_val,
BACKSQL_OC_NAME( bsi->bsi_oc ), 0 );
continue;
return 0;
}
-#endif /* SLAPD_SQL == SLAPD_MOD_DYNAMIC*/
+#endif /* SLAPD_SQL == SLAPD_MOD_DYNAMIC */
int
sql_back_initialize(
bi->bi_connection_init = 0;
bi->bi_connection_destroy = backsql_connection_destroy;
-
+
Debug( LDAP_DEBUG_TRACE,"<==backsql_initialize()\n", 0, 0, 0 );
return 0;
}
if ( backsql_split_pattern( backsql_def_concat_func,
&si->concat_func, 2 ) ) {
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "unable to parse pattern '%s'",
+ "unable to parse pattern \"%s\"",
backsql_def_concat_func, 0, 0 );
return 1;
}
si->subtree_cond = bb.bb_val;
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "setting '%s' as default\n",
+ "setting \"%s\" as default\n",
si->subtree_cond.bv_val, 0, 0 );
}
si->children_cond = bb.bb_val;
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "setting '%s' as default\n",
+ "setting \"%s\" as default\n",
si->children_cond.bv_val, 0, 0 );
}
"(use \"oc_query\" directive in slapd.conf)\n",
0, 0, 0 );
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "setting '%s' by default\n", si->oc_query, 0, 0 );
+ "setting \"%s\" by default\n", si->oc_query, 0, 0 );
}
if ( si->at_query == NULL ) {
"(use \"at_query\" directive in slapd.conf)\n",
0, 0, 0 );
Debug(LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "setting '%s' by default\n",
+ "setting \"%s\" by default\n",
backsql_def_at_query, 0, 0 );
si->at_query = ch_strdup( backsql_def_at_query );
}
"(use \"insentry_query\" directive in slapd.conf)\n",
0, 0, 0 );
Debug(LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "setting '%s' by default\n",
+ "setting \"%s\" by default\n",
backsql_def_insentry_query, 0, 0 );
si->insentry_query = ch_strdup( backsql_def_insentry_query );
}
"(use \"delentry_query\" directive in slapd.conf)\n",
0, 0, 0 );
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "setting '%s' by default\n",
+ "setting \"%s\" by default\n",
backsql_def_delentry_query, 0, 0 );
si->delentry_query = ch_strdup( backsql_def_delentry_query );
}
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
SQLHDBC dbh;
backsql_oc_map_rec *oc = NULL;
- backsql_entryID e_id;
+ backsql_entryID e_id = BACKSQL_ENTRYID_INIT;
Entry e;
/*
SQLHDBC dbh;
SQLHSTMT sth;
RETCODE rc;
- backsql_entryID e_id, pe_id, new_pid;
+ backsql_entryID e_id = BACKSQL_ENTRYID_INIT,
+ pe_id = BACKSQL_ENTRYID_INIT,
+ new_pid = BACKSQL_ENTRYID_INIT;
backsql_oc_map_rec *oc = NULL;
struct berval p_dn, p_ndn,
*new_pdn = NULL, *new_npdn = NULL,
"old parent entry id is %ld\n", pe_id.eid_id, 0, 0 );
#endif /* ! BACKSQL_ARBITRARY_KEY */
+ backsql_free_entryID( &pe_id, 0 );
+
rs->sr_err = backsql_dn2id( bi, &new_pid, dbh, new_npdn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
if ( old_rdn != NULL ) {
ldap_rdnfree( old_rdn );
}
- if( mod != NULL ) {
+ if ( mod != NULL ) {
Modifications *tmp;
for (; mod; mod=tmp ) {
tmp = mod->sml_next;
}
}
+ if ( new_pid.eid_dn.bv_val ) {
+ backsql_free_entryID( &pe_id, 0 );
+ }
+
send_ldap_result( op, rs );
Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 );
Attribute **aa = a;
int rc = 0;
- Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry '%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry \"%s\"\n",
rs->sr_entry->e_nname.bv_val, 0, 0 );
backsql_entryID *e_id,
Modifications *modlist );
+/*
+ * api.c
+ */
+int backsql_api_config( backsql_info *si, const char *name );
+int backsql_api_register( backsql_api *ba );
+int backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn );
+int backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn );
+
/*
* entry-id.c
*/
void 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, AttributeName *attrs );
+ Operation *op, SlapReply *rs, AttributeName *attrs );
/*
* sql-wrap.h
rc = backsql_Prepare( dbh, &oc_sth, si->oc_query, 0 );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
- "error preparing oc_query: '%s'\n",
+ "error preparing oc_query: \"%s\"\n",
si->oc_query, 0, 0 );
backsql_PrintErrors( si->db_env, dbh, oc_sth, rc );
return LDAP_OTHER;
}
- Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): at_query '%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): at_query \"%s\"\n",
si->at_query, 0, 0 );
rc = backsql_Prepare( dbh, &at_sth, si->at_query, 0 );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
- "error preparing at_query: '%s'\n",
+ "error preparing at_query: \"%s\"\n",
si->at_query, 0, 0 );
backsql_PrintErrors( si->db_env, dbh, at_sth, rc );
return LDAP_OTHER;
oc_map->bom_oc = oc_find( oc_row.cols[ 1 ] );
if ( oc_map->bom_oc == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
- "objectClass '%s' is not defined in schema\n",
+ "objectClass \"%s\" is not defined in schema\n",
oc_row.cols[ 1 ], 0, 0 );
return LDAP_OTHER; /* undefined objectClass ? */
}
}
oc_id = oc_map->bom_id;
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
- "objectClass '%s': keytbl='%s' keycol='%s'\n",
+ "objectClass \"%s\": keytbl=\"%s\" keycol=\"%s\"\n",
BACKSQL_OC_NAME( oc_map ),
oc_map->bom_keytbl.bv_val, oc_map->bom_keycol.bv_val );
if ( oc_map->bom_create_proc ) {
- Debug( LDAP_DEBUG_TRACE, "create_proc='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "create_proc=\"%s\"\n",
oc_map->bom_create_proc, 0, 0 );
}
if ( oc_map->bom_create_keyval ) {
- Debug( LDAP_DEBUG_TRACE, "create_keyval='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "create_keyval=\"%s\"\n",
oc_map->bom_create_keyval, 0, 0 );
}
if ( oc_map->bom_delete_proc ) {
- Debug( LDAP_DEBUG_TRACE, "delete_proc='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "delete_proc=\"%s\"\n",
oc_map->bom_delete_proc, 0, 0 );
}
Debug( LDAP_DEBUG_TRACE, "expect_return: "
Debug( LDAP_DEBUG_TRACE,
"attributeType:\n"
- "\tname='%s'\n"
- "\tsel_expr='%s'\n"
- "\tfrom='%s'\n",
+ "\tname=\"%s\"\n"
+ "\tsel_expr=\"%s\"\n"
+ "\tfrom=\"%s\"\n",
at_row.cols[ 0 ], at_row.cols[ 1 ],
at_row.cols[ 2 ] );
Debug( LDAP_DEBUG_TRACE,
- "\tjoin_where='%s'\n"
- "\tadd_proc='%s'\n"
- "\tdelete_proc='%s'\n",
+ "\tjoin_where=\"%s\"\n"
+ "\tadd_proc=\"%s\"\n"
+ "\tdelete_proc=\"%s\"\n",
at_row.cols[ 3 ], at_row.cols[ 4 ],
at_row.cols[ 5 ]);
/* TimesTen */
- Debug( LDAP_DEBUG_TRACE, "\tsel_expr_u='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "\tsel_expr_u=\"%s\"\n",
at_row.cols[ 8 ], 0, 0 );
at_map = (backsql_at_map_rec *)ch_calloc( 1,
sizeof( backsql_at_map_rec ) );
&at_map->bam_ad, &text );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
- "attribute '%s' for objectClass '%s' "
+ "attribute \"%s\" for objectClass \"%s\" "
"is not defined in schema: %s\n",
at_row.cols[ 0 ],
BACKSQL_OC_NAME( oc_map ), text );
NULL, 0 );
backsql_make_attr_query( oc_map, at_map );
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
- "preconstructed query '%s'\n",
+ "preconstructed query \"%s\"\n",
at_map->bam_query, 0, 0 );
at_map->bam_next = NULL;
if ( avl_insert( &oc_map->bom_attrs, at_map, backsql_cmp_attr, backsql_dup_attr ) == BACKSQL_DUPLICATE ) {
#ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "==>backsql_oc2oc(): "
- "searching for objectclass with name='%s'\n",
+ "searching for objectclass with name=\"%s\"\n",
objclass, 0, 0 );
#endif /* BACKSQL_TRACE */
#ifdef BACKSQL_TRACE
if ( res != NULL ) {
Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): "
- "found name='%s', id=%d\n",
+ "found name=\"%s\", id=%d\n",
BACKSQL_OC_NAME( res ), res->id, 0 );
} else {
Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): "
#ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "==>oc_with_name(): "
- "searching for objectclass with name='%s'\n",
+ "searching for objectclass with name=\"%s\"\n",
objclass, 0, 0 );
#endif /* BACKSQL_TRACE */
#ifdef BACKSQL_TRACE
if ( res != NULL ) {
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
- "found name='%s', id=%d\n",
+ "found name=\"%s\", id=%d\n",
BACKSQL_OC_NAME( res ), res->bom_id, 0 );
} else {
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
#ifdef BACKSQL_TRACE
if ( res != NULL ) {
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
- "found name='%s', id=%d\n",
+ "found name=\"%s\", id=%d\n",
BACKSQL_OC_NAME( res ), res->bom_id, 0 );
} else {
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
#ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "==>backsql_ad2at(): "
- "searching for attribute '%s' for objectclass '%s'\n",
+ "searching for attribute \"%s\" for objectclass \"%s\"\n",
attr, BACKSQL_OC_NAME( objclass ), 0 );
#endif /* BACKSQL_TRACE */
#ifdef BACKSQL_TRACE
if ( res != NULL ) {
Debug( LDAP_DEBUG_TRACE, "<==backsql_ad2at(): "
- "found name='%s', sel_expr='%s'\n",
+ "found name=\"%s\", sel_expr=\"%s\"\n",
res->bam_ad->ad_cname.bv_val,
res->bam_sel_expr.bv_val, 0 );
} else {
{
backsql_at_map_rec *at = v_at;
- Debug( LDAP_DEBUG_TRACE, "==>free_attr(): '%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "==>free_attr(): \"%s\"\n",
at->bam_ad->ad_cname.bv_val, 0, 0 );
ch_free( at->bam_sel_expr.bv_val );
if ( at->bam_from_tbls.bv_val != NULL ) {
{
backsql_oc_map_rec *oc = v_oc;
- Debug( LDAP_DEBUG_TRACE, "==>free_oc(): '%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "==>free_oc(): \"%s\"\n",
BACKSQL_OC_NAME( oc ), 0, 0 );
avl_free( oc->bom_attrs, backsql_free_attr );
ch_free( oc->bom_keytbl.bv_val );
an = &bsi->bsi_attrs[ n_attrs ];
Debug( LDAP_DEBUG_TRACE, "==>backsql_attrlist_add(): "
- "attribute '%s' is in list\n",
+ "attribute \"%s\" is in list\n",
an->an_name.bv_val, 0, 0 );
/*
* We can live with strcmp because the attribute
}
Debug( LDAP_DEBUG_TRACE, "==>backsql_attrlist_add(): "
- "adding '%s' to list\n", ad->ad_cname.bv_val, 0, 0 );
+ "adding \"%s\" to list\n", ad->ad_cname.bv_val, 0, 0 );
an = (AttributeName *)ch_realloc( bsi->bsi_attrs,
sizeof( AttributeName ) * ( n_attrs + 2 ) );
Filter *filter,
SQLHDBC dbh,
Operation *op,
+ SlapReply *rs,
AttributeName *attrs )
{
AttributeName *p;
-
+
bsi->bsi_base_dn = base;
bsi->bsi_scope = scope;
bsi->bsi_slimit = slimit;
bsi->bsi_filter = filter;
bsi->bsi_dbh = dbh;
bsi->bsi_op = op;
+ bsi->bsi_rs = rs;
bsi->bsi_flags = 0;
/*
/*
* to check for matching telephone numbers
- * with intermized chars, e.g. val='1234'
+ * with intermixed chars, e.g. val='1234'
* use
*
* val LIKE '%1%2%3%4%'
backsql_strfcat( &bsi->bsi_flt_where, "c", '(' /* ) */ );
/* TimesTen */
- Debug( LDAP_DEBUG_TRACE, "expr: '%s%s%s'\n", at->bam_sel_expr.bv_val,
+ Debug( LDAP_DEBUG_TRACE, "backsql_process_sub_filter(%s):\n",
+ at->bam_ad->ad_cname.bv_val, 0, 0 );
+ Debug(LDAP_DEBUG_TRACE, " expr: '%s%s%s'\n", at->bam_sel_expr.bv_val,
at->bam_sel_expr_u.bv_val ? "' '" : "",
at->bam_sel_expr_u.bv_val ? at->bam_sel_expr_u.bv_val : "" );
if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
if ( f->f_sub_initial.bv_val != NULL ) {
ber_len_t start;
+#ifdef BACKSQL_TRACE
+ Debug( LDAP_DEBUG_TRACE,
+ "==>backsql_process_sub_filter(%s): "
+ "sub_initial=\"%s\"\n", at->bam_ad->ad_cname.bv_val,
+ f->f_sub_initial.bv_val, 0 );
+#endif /* BACKSQL_TRACE */
+
start = bsi->bsi_flt_where.bb_val.bv_len;
backsql_strfcat( &bsi->bsi_flt_where, "b",
&f->f_sub_initial );
#ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE,
"==>backsql_process_sub_filter(%s): "
- "sub_any='%s'\n", at->bam_ad->ad_cname.bv_val,
- f->f_sub_any[ i ].bv_val, 0 );
+ "sub_any[%d]=\"%s\"\n", at->bam_ad->ad_cname.bv_val,
+ i, f->f_sub_any[ i ].bv_val );
#endif /* BACKSQL_TRACE */
start = bsi->bsi_flt_where.bb_val.bv_len;
ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
}
}
+ }
- if ( f->f_sub_final.bv_val != NULL ) {
- ber_len_t start;
+ if ( f->f_sub_final.bv_val != NULL ) {
+ ber_len_t start;
- start = bsi->bsi_flt_where.bb_val.bv_len;
- backsql_strfcat( &bsi->bsi_flt_where, "b",
- &f->f_sub_final );
- if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
- ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
- }
+#ifdef BACKSQL_TRACE
+ Debug( LDAP_DEBUG_TRACE,
+ "==>backsql_process_sub_filter(%s): "
+ "sub_final=\"%s\"\n", at->bam_ad->ad_cname.bv_val,
+ f->f_sub_final.bv_val, 0 );
+#endif /* BACKSQL_TRACE */
+
+ start = bsi->bsi_flt_where.bb_val.bv_len;
+ backsql_strfcat( &bsi->bsi_flt_where, "b",
+ &f->f_sub_final );
+ if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
+ ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
}
}
}
break;
+ case BACKSQL_SCOPE_BASE_LIKE:
+ if ( BACKSQL_CANUPPERCASE( bi ) ) {
+ backsql_strfcat( &bsi->bsi_join_where, "bl",
+ &bi->upper_func,
+ (ber_len_t)sizeof( "(ldap_entries.dn) LIKE ?" ) - 1,
+ "(ldap_entries.dn) LIKE ?" );
+ } else {
+ backsql_strfcat( &bsi->bsi_join_where, "l",
+ (ber_len_t)sizeof( "ldap_entries.dn LIKE ?" ) - 1,
+ "ldap_entries.dn LIKE ?" );
+ }
+ break;
+
case LDAP_SCOPE_ONELEVEL:
backsql_strfcat( &bsi->bsi_join_where, "l",
(ber_len_t)sizeof( "ldap_entries.parent=?" ) - 1,
struct berval query;
SQLHSTMT sth;
RETCODE rc;
- backsql_entryID base_id, *c_id;
+ backsql_entryID base_id = BACKSQL_ENTRYID_INIT;
int res;
BACKSQL_ROW_NTS row;
int i;
int j;
-
int n_candidates = bsi->bsi_n_candidates;
+ /*
+ * + 1 because we need room for '%'; this makes a subtree
+ * search for a DN BACKSQL_MAX_DN_LEN long legal
+ * if it returns that DN only
+ */
+ char temp_base_dn[ BACKSQL_MAX_DN_LEN + 1 + 1 ];
+
bsi->bsi_status = LDAP_SUCCESS;
- Debug( LDAP_DEBUG_TRACE, "==>backsql_oc_get_candidates(): oc='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_oc_get_candidates(): oc=\"%s\"\n",
BACKSQL_OC_NAME( oc ), 0, 0 );
if ( bsi->bsi_n_candidates == -1 ) {
res = backsql_srch_query( bsi, &query );
if ( res ) {
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
- "error while constructing query for objectclass '%s'\n",
+ "error while constructing query for objectclass \"%s\"\n",
oc->bom_oc->soc_cname.bv_val, 0, 0 );
/*
* FIXME: need to separate errors from legally
if ( query.bv_val == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
- "could not construct query for objectclass '%s'\n",
+ "could not construct query for objectclass \"%s\"\n",
oc->bom_oc->soc_cname.bv_val, 0, 0 );
bsi->bsi_status = LDAP_SUCCESS;
return BACKSQL_CONTINUE;
switch ( bsi->bsi_scope ) {
case LDAP_SCOPE_BASE:
- Debug( LDAP_DEBUG_TRACE, "(base)dn: '%s'\n",
- bsi->bsi_base_dn->bv_val, 0, 0 );
+ case BACKSQL_SCOPE_BASE_LIKE:
+ /*
+ * We do not accept DNs longer than BACKSQL_MAX_DN_LEN;
+ * however this should be handled earlier
+ */
+ if ( bsi->bsi_base_dn->bv_len > BACKSQL_MAX_DN_LEN ) {
+ bsi->bsi_status = LDAP_OTHER;
+ return BACKSQL_CONTINUE;
+ }
+
+ AC_MEMCPY( temp_base_dn, bsi->bsi_base_dn->bv_val,
+ bsi->bsi_base_dn->bv_len + 1 );
+
+ /* uppercase DN only if the stored DN can be uppercased
+ * for comparison */
+ if ( BACKSQL_CANUPPERCASE( bi ) ) {
+ ldap_pvt_str2upper( temp_base_dn );
+ }
- rc = backsql_BindParamStr( sth, 2, bsi->bsi_base_dn->bv_val,
+ Debug( LDAP_DEBUG_TRACE, "(base)dn: \"%s\"\n",
+ temp_base_dn, 0, 0 );
+
+ rc = backsql_BindParamStr( sth, 2, temp_base_dn,
BACKSQL_MAX_DN_LEN );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
break;
case LDAP_SCOPE_SUBTREE: {
-
- /*
- * + 1 because we need room for '%'; this makes a subtree
- * search for a DN BACKSQL_MAX_DN_LEN long legal
- * if it returns that DN only
- */
- char temp_base_dn[ BACKSQL_MAX_DN_LEN + 1 + 1 ];
-
/*
* We do not accept DNs longer than BACKSQL_MAX_DN_LEN;
* however this should be handled earlier
*/
- assert( bsi->bsi_base_dn->bv_len <= BACKSQL_MAX_DN_LEN );
-
+ if ( bsi->bsi_base_dn->bv_len > BACKSQL_MAX_DN_LEN ) {
+ bsi->bsi_status = LDAP_OTHER;
+ return BACKSQL_CONTINUE;
+ }
+
/*
* Sets the parameters for the SQL built earlier
* NOTE that all the databases could actually use
AC_MEMCPY( &temp_base_dn[ 1 ], bsi->bsi_base_dn->bv_val,
bsi->bsi_base_dn->bv_len + 1 );
}
+
/* uppercase DN only if the stored DN can be uppercased
* for comparison */
if ( BACKSQL_CANUPPERCASE( bi ) ) {
ldap_pvt_str2upper( temp_base_dn );
}
- Debug( LDAP_DEBUG_TRACE, "(sub)dn: '%s'\n", temp_base_dn,
+ Debug( LDAP_DEBUG_TRACE, "(sub)dn: \"%s\"\n", temp_base_dn,
0, 0 );
rc = backsql_BindParamStr( sth, 2, temp_base_dn,
}
#ifdef BACKSQL_ARBITRARY_KEY
- Debug( LDAP_DEBUG_TRACE, "(one)id: '%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "(one)id: \"%s\"\n",
base_id.eid_id.bv_val, 0, 0 );
rc = backsql_BindParamStr( sth, 2, base_id.eid_id.bv_val,
backsql_BindRowAsStrings( sth, &row );
rc = SQLFetch( sth );
for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) {
+ struct berval dn;
+ backsql_entryID *c_id = NULL;
+
+ ber_str2bv( row.cols[ 3 ], 0, 0, &dn );
+
+ if ( backsql_api_odbc2dn( bsi->bsi_op, bsi->bsi_rs, &dn ) ) {
+ continue;
+ }
+
c_id = (backsql_entryID *)ch_calloc( 1,
sizeof( backsql_entryID ) );
#ifdef BACKSQL_ARBITRARY_KEY
c_id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 );
#endif /* ! BACKSQL_ARBITRARY_KEY */
c_id->eid_oc_id = bsi->bsi_oc->bom_id;
- ber_str2bv( row.cols[ 3 ], 0, 1, &c_id->eid_dn );
+
+ if ( dn.bv_val == row.cols[ 3 ] ) {
+ ber_dupbv( &c_id->eid_dn, &dn );
+ } else {
+ c_id->eid_dn = dn;
+ }
+
c_id->eid_next = bsi->bsi_id_list;
bsi->bsi_id_list = c_id;
bsi->bsi_n_candidates--;
#ifdef BACKSQL_ARBITRARY_KEY
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
- "added entry id=%s, keyval=%s dn='%s'\n",
+ "added entry id=%s, keyval=%s dn=\"%s\"\n",
c_id->eid_id.bv_val, c_id->eid_keyval.bv_val,
row.cols[ 3 ] );
#else /* ! BACKSQL_ARBITRARY_KEY */
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
- "added entry id=%ld, keyval=%ld dn='%s'\n",
+ "added entry id=%ld, keyval=%ld dn=\"%s\"\n",
c_id->eid_id, c_id->eid_keyval, row.cols[ 3 ] );
#endif /* ! BACKSQL_ARBITRARY_KEY */
time_t stoptime = 0;
backsql_srch_info srch_info;
backsql_entryID *eid = NULL;
+ struct berval base;
manageDSAit = get_manageDSAit( op );
Debug( LDAP_DEBUG_TRACE, "==>backsql_search(): "
- "base='%s', filter='%s', scope=%d,",
+ "base=\"%s\", filter=\"%s\", scope=%d,",
op->o_req_ndn.bv_val,
op->ors_filterstr.bv_val,
op->ors_scope );
/* compute it anyway; root does not use it */
stoptime = op->o_time + op->ors_tlimit;
- backsql_init_search( &srch_info, &op->o_req_dn,
+ base = op->o_req_dn;
+ if ( backsql_api_dn2odbc( op, rs, &base ) ) {
+ 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";
+ send_ldap_result( op, rs );
+ return 1;
+ }
+
+ backsql_init_search( &srch_info, &base,
op->ors_scope,
op->ors_slimit, op->ors_tlimit,
stoptime, op->ors_filter,
- dbh, op, op->ors_attrs );
+ dbh, op, rs, op->ors_attrs );
/*
* for each objectclass we try to construct query which gets IDs
if ( !manageDSAit &&
op->ors_scope != LDAP_SCOPE_BASE &&
+ op->ors_scope != BACKSQL_SCOPE_BASE_LIKE &&
is_entry_referral( entry ) ) {
BerVarray refs;
struct berval matched_dn;
done:;
ch_free( srch_info.bsi_attrs );
+ if ( base.bv_val != op->o_req_ndn.bv_val ) {
+ ch_free( base.bv_val );
+ }
Debug( LDAP_DEBUG_TRACE, "<==backsql_search()\n", 0, 0, 0 );
return 0;
SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len );
#ifdef BACKSQL_TRACE
- Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name='%s'\n",
+ Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n",
drv_name, 0, 0 );
#endif /* BACKSQL_TRACE */
SQL_NTS, si->dbpasswd, SQL_NTS );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: "
- "SQLConnect() to database '%s' as user '%s' "
+ "SQLConnect() to database \"%s\" as user \"%s\" "
"%s:\n", si->dbname, si->dbuser,
rc == SQL_SUCCESS_WITH_INFO ?
"succeeded with info" : "failed" );
va_end( strs );
#ifdef BACKSQL_TRACE
- Debug( LDAP_DEBUG_TRACE, "<==backsql_strcat() (dest='%s')\n",
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_strcat() (dest=\"%s\")\n",
dest, 0, 0 );
#endif /* BACKSQL_TRACE */
va_end( strs );
#ifdef BACKSQL_TRACE
- Debug( LDAP_DEBUG_TRACE, "<==backsql_strfcat() (dest='%s')\n",
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_strfcat() (dest=\"%s\")\n",
dest, 0, 0 );
#endif /* BACKSQL_TRACE */
#ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(): "
- "at_name='%s', at_val='%s'\n",
+ "at_name=\"%s\", at_val=\"%s\"\n",
at_name->bv_val, at_val->bv_val, 0 );
#endif /* BACKSQL_TRACE */
rc = slap_bv2ad( at_name, &ad, &text );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(): "
- "failed to find AttributeDescription for '%s'\n",
+ "failed to find AttributeDescription for \"%s\"\n",
at_name->bv_val, 0, 0 );
return 0;
}
if ( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(): "
- "failed to merge value '%s' for attribute '%s'\n",
+ "failed to merge value \"%s\" for attribute \"%s\"\n",
at_val->bv_val, at_name->bv_val, 0 );
return 0;
}
#ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "==>backsql_merge_from_clause(): "
- "dest_from='%s',src_from='%s'\n",
+ "dest_from=\"%s\",src_from=\"%s\"\n",
dest_from ? dest_from->bb_val.bv_val : "<NULL>", src_from, 0 );
#endif /* BACKSQL_TRACE */
#ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "backsql_merge_from_clause(): "
- "p='%s' s='%s'\n", p, s, 0 );
+ "p=\"%s\" s=\"%s\"\n", p, s, 0 );
#endif /* BACKSQL_TRACE */
if ( res.bb_val.bv_val == NULL ) {