2003-12-08 03:19:18 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
2000-03-17 03:34:46 +08:00
|
|
|
*
|
2003-12-08 03:19:18 +08:00
|
|
|
* Copyright 1999-2003 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.
|
2000-03-17 03:34:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
2000-03-19 14:18:27 +08:00
|
|
|
#ifdef SLAPD_SQL
|
|
|
|
|
2000-03-17 03:34:46 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2002-11-10 01:03:07 +08:00
|
|
|
#include "ac/string.h"
|
2000-03-17 03:34:46 +08:00
|
|
|
#include "slap.h"
|
2002-08-29 18:55:48 +08:00
|
|
|
#include "lber_pvt.h"
|
2002-08-17 00:45:24 +08:00
|
|
|
#include "ldap_pvt.h"
|
2000-03-17 03:34:46 +08:00
|
|
|
#include "back-sql.h"
|
|
|
|
#include "sql-wrap.h"
|
|
|
|
#include "schema-map.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* Uses the pointer to the ObjectClass structure
|
|
|
|
*/
|
|
|
|
static int
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_cmp_oc( const void *v_m1, const void *v_m2 )
|
2002-08-17 00:45:24 +08:00
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
const backsql_oc_map_rec *m1 = v_m1, *m2 = v_m2;
|
2003-04-19 01:16:48 +08:00
|
|
|
return SLAP_PTRCMP( m1->oc, m2->oc );
|
2002-08-17 00:45:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_cmp_oc_id( const void *v_m1, const void *v_m2 )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
const backsql_oc_map_rec *m1 = v_m1, *m2 = v_m2;
|
2002-08-17 00:45:24 +08:00
|
|
|
return ( m1->id < m2->id ? -1 : ( m1->id > m2->id ? 1 : 0 ) );
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* Uses the pointer to the AttributeDescription structure
|
|
|
|
*/
|
|
|
|
static int
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_cmp_attr( const void *v_m1, const void *v_m2 )
|
2002-08-17 00:45:24 +08:00
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
const backsql_at_map_rec *m1 = v_m1, *m2 = v_m2;
|
2003-04-19 01:16:48 +08:00
|
|
|
return SLAP_PTRCMP( m1->ad, m2->ad );
|
2002-08-17 00:45:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_make_attr_query(
|
|
|
|
backsql_oc_map_rec *oc_map,
|
|
|
|
backsql_at_map_rec *at_map )
|
2000-06-30 05:14:43 +08:00
|
|
|
{
|
2003-04-16 05:55:25 +08:00
|
|
|
struct berbuf bb = BB_NULL;
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2003-04-16 05:55:25 +08:00
|
|
|
backsql_strfcat( &bb, "lblblblbcbl",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "SELECT " ) - 1, "SELECT ",
|
|
|
|
&at_map->sel_expr,
|
|
|
|
(ber_len_t)sizeof( " AS " ) - 1, " AS ",
|
|
|
|
&at_map->ad->ad_cname,
|
|
|
|
(ber_len_t)sizeof( " FROM " ) - 1, " FROM ",
|
|
|
|
&at_map->from_tbls,
|
|
|
|
(ber_len_t)sizeof( " WHERE " ) - 1, " WHERE ",
|
|
|
|
&oc_map->keytbl,
|
|
|
|
'.',
|
|
|
|
&oc_map->keycol,
|
|
|
|
(ber_len_t)sizeof( "=?" ) - 1, "=?" );
|
|
|
|
|
|
|
|
if ( at_map->join_where.bv_val != NULL ) {
|
2003-04-16 05:55:25 +08:00
|
|
|
backsql_strfcat( &bb, "lb",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " AND ") - 1, " AND ",
|
|
|
|
&at_map->join_where );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2000-06-30 05:14:43 +08:00
|
|
|
|
2003-04-16 05:55:25 +08:00
|
|
|
at_map->query = bb.bb_val.bv_val;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
return 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2000-06-30 05:14:43 +08:00
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
static int
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
|
2000-06-30 05:14:43 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_at_map_rec *at_map;
|
2003-04-16 05:55:25 +08:00
|
|
|
char s[] = "+9223372036854775807L";
|
|
|
|
ber_len_t slen;
|
|
|
|
struct berbuf bb;
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
snprintf( s, sizeof( s ), "%ld", oc_map->id );
|
2002-08-23 16:54:08 +08:00
|
|
|
slen = strlen( s );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
at_map = (backsql_at_map_rec *)ch_calloc(1,
|
|
|
|
sizeof( backsql_at_map_rec ) );
|
2002-08-17 00:45:24 +08:00
|
|
|
at_map->ad = slap_schema.si_ad_objectClass;
|
2002-08-23 16:54:08 +08:00
|
|
|
ber_str2bv( "ldap_entry_objclasses.oc_name", 0, 1, &at_map->sel_expr );
|
|
|
|
ber_str2bv( "ldap_entry_objclasses,ldap_entries", 0, 1,
|
|
|
|
&at_map->from_tbls );
|
2003-04-16 05:55:25 +08:00
|
|
|
|
|
|
|
bb.bb_len = at_map->from_tbls.bv_len + 1;
|
|
|
|
bb.bb_val = at_map->from_tbls;
|
|
|
|
backsql_merge_from_clause( &bb, &oc_map->keytbl );
|
|
|
|
at_map->from_tbls = bb.bb_val;
|
|
|
|
|
|
|
|
bb.bb_val.bv_val = NULL;
|
|
|
|
bb.bb_val.bv_len = 0;
|
|
|
|
bb.bb_len = 0;
|
|
|
|
backsql_strfcat( &bb, "lbcbll",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "ldap_entries.id=ldap_entry_objclasses.entry_id and ldap_entries.keyval=" ) - 1,
|
|
|
|
"ldap_entries.id=ldap_entry_objclasses.entry_id and ldap_entries.keyval=",
|
|
|
|
&oc_map->keytbl,
|
|
|
|
'.',
|
|
|
|
&oc_map->keycol,
|
|
|
|
(ber_len_t)sizeof( " and ldap_entries.oc_map_id=" ) - 1,
|
|
|
|
" and ldap_entries.oc_map_id=",
|
|
|
|
slen, s );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2003-04-16 05:55:25 +08:00
|
|
|
at_map->join_where = bb.bb_val;
|
2002-08-14 01:12:27 +08:00
|
|
|
at_map->add_proc = NULL;
|
|
|
|
at_map->delete_proc = NULL;
|
|
|
|
at_map->param_order = 0;
|
|
|
|
at_map->expect_return = 0;
|
2003-04-16 05:55:25 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_make_attr_query( oc_map, at_map );
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_insert( &oc_map->attrs, at_map, backsql_cmp_attr, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
at_map = (backsql_at_map_rec *)ch_calloc( 1,
|
|
|
|
sizeof( backsql_at_map_rec ) );
|
2002-08-17 00:45:24 +08:00
|
|
|
at_map->ad = slap_schema.si_ad_ref;
|
2002-08-23 16:54:08 +08:00
|
|
|
ber_str2bv( "ldap_referrals.url", 0, 1, &at_map->sel_expr );
|
|
|
|
ber_str2bv( "ldap_referrals,ldap_entries", 0, 1, &at_map->from_tbls );
|
2003-04-16 05:55:25 +08:00
|
|
|
|
|
|
|
bb.bb_val.bv_val = NULL;
|
|
|
|
bb.bb_val.bv_len = 0;
|
|
|
|
bb.bb_len = at_map->from_tbls.bv_len + 1;
|
|
|
|
backsql_merge_from_clause( &bb, &oc_map->keytbl );
|
|
|
|
at_map->from_tbls = bb.bb_val;
|
|
|
|
|
|
|
|
bb.bb_val.bv_val = NULL;
|
|
|
|
bb.bb_val.bv_len = 0;
|
|
|
|
bb.bb_len = 0;
|
|
|
|
backsql_strfcat( &bb, "lbcbll",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "ldap_entries.id=ldap_referrals.entry_id and ldap_entries.keyval=" ) - 1,
|
|
|
|
"ldap_entries.id=ldap_referrals.entry_id and ldap_entries.keyval=",
|
|
|
|
&oc_map->keytbl,
|
|
|
|
'.',
|
|
|
|
&oc_map->keycol,
|
|
|
|
(ber_len_t)sizeof( " and ldap_entries.oc_map_id=" ) - 1,
|
|
|
|
" and ldap_entries.oc_map_id=",
|
|
|
|
slen, s );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2003-04-16 05:55:25 +08:00
|
|
|
at_map->join_where = bb.bb_val;
|
2002-08-14 01:12:27 +08:00
|
|
|
at_map->add_proc = NULL;
|
|
|
|
at_map->delete_proc = NULL;
|
|
|
|
at_map->param_order = 0;
|
|
|
|
at_map->expect_return = 0;
|
2003-04-16 05:55:25 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_make_attr_query( oc_map, at_map );
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_insert( &oc_map->attrs, at_map, backsql_cmp_attr, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
return 1;
|
2000-06-30 05:14:43 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
|
|
|
backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLHSTMT oc_sth, at_sth;
|
|
|
|
RETCODE rc;
|
|
|
|
BACKSQL_ROW_NTS oc_row, at_row;
|
|
|
|
unsigned long oc_id;
|
|
|
|
backsql_oc_map_rec *oc_map;
|
|
|
|
backsql_at_map_rec *at_map;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>load_schema_map()\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TimesTen : See if the ldap_entries.dn_ru field exists in the schema
|
|
|
|
*/
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( !BACKSQL_DONTCHECK_LDAPINFO_DN_RU( si ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
rc = backsql_Prepare( dbh, &oc_sth,
|
|
|
|
backsql_check_dn_ru_query, 0 );
|
|
|
|
if ( rc == SQL_SUCCESS ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
/* Yes, the field exists */
|
|
|
|
si->bsql_flags |= BSQLF_HAS_LDAPINFO_DN_RU;
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldapinfo.dn_ru field exists "
|
|
|
|
"in the schema\n", 0, 0, 0 );
|
|
|
|
} else {
|
2002-08-23 16:54:08 +08:00
|
|
|
/* No such field exists */
|
|
|
|
si->bsql_flags &= ~BSQLF_HAS_LDAPINFO_DN_RU;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SQLFreeStmt( oc_sth, SQL_DROP );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rc = backsql_Prepare( dbh, &oc_sth, si->oc_query, 0 );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"error preparing oc_query: '%s'\n",
|
|
|
|
si->oc_query, 0, 0 );
|
|
|
|
backsql_PrintErrors( si->db_env, dbh, oc_sth, rc );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_OTHER;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "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, "load_schema_map(): "
|
|
|
|
"error preparing at_query: '%s'\n",
|
|
|
|
si->at_query, 0, 0 );
|
|
|
|
backsql_PrintErrors( si->db_env, dbh, at_sth, rc );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_OTHER;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = backsql_BindParamID( at_sth, 1, &oc_id );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"error binding param for at_query: \n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( si->db_env, dbh, at_sth, rc );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_OTHER;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = SQLExecute( oc_sth );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"error executing oc_query: \n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( si->db_env, dbh, oc_sth, rc );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_OTHER;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
backsql_BindRowAsStrings( oc_sth, &oc_row );
|
|
|
|
rc = SQLFetch( oc_sth );
|
|
|
|
for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( oc_sth ) ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
int colnum;
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
oc_map = (backsql_oc_map_rec *)ch_calloc( 1,
|
|
|
|
sizeof( backsql_oc_map_rec ) );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
oc_map->id = strtol( oc_row.cols[ 0 ], NULL, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
oc_map->oc = oc_find( oc_row.cols[ 1 ] );
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( oc_map->oc == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"objectClass '%s' is not defined in schema\n",
|
2002-08-29 18:55:48 +08:00
|
|
|
oc_row.cols[ 1 ], 0, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_OTHER; /* undefined objectClass ? */
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
ber_str2bv( oc_row.cols[ 2 ], 0, 1, &oc_map->keytbl );
|
|
|
|
ber_str2bv( oc_row.cols[ 3 ], 0, 1, &oc_map->keycol );
|
2002-09-03 03:39:31 +08:00
|
|
|
oc_map->create_proc = ( oc_row.value_len[ 4 ] < 0 ) ? NULL
|
2002-08-14 01:12:27 +08:00
|
|
|
: ch_strdup( oc_row.cols[ 4 ] );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
colnum = 5;
|
|
|
|
if ( BACKSQL_CREATE_NEEDS_SELECT( si ) ) {
|
|
|
|
colnum = 6;
|
2002-09-03 03:39:31 +08:00
|
|
|
oc_map->create_keyval = ( oc_row.value_len[ 5 ] < 0 )
|
2002-08-23 16:54:08 +08:00
|
|
|
? NULL : ch_strdup( oc_row.cols[ 5 ] );
|
|
|
|
}
|
2002-09-03 03:39:31 +08:00
|
|
|
oc_map->delete_proc = ( oc_row.value_len[ colnum ] < 0 ) ? NULL
|
2002-08-23 16:54:08 +08:00
|
|
|
: ch_strdup( oc_row.cols[ colnum ] );
|
|
|
|
oc_map->expect_return = strtol( oc_row.cols[ colnum + 1 ],
|
|
|
|
NULL, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: first attempt to check for offending
|
|
|
|
* instructions in {create|delete}_proc
|
|
|
|
*/
|
|
|
|
|
|
|
|
oc_map->attrs = NULL;
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_insert( &si->oc_by_oc, oc_map, backsql_cmp_oc, NULL );
|
|
|
|
avl_insert( &si->oc_by_id, oc_map, backsql_cmp_oc_id, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
oc_id = oc_map->id;
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"objectClass '%s': keytbl='%s' keycol='%s'\n",
|
2002-08-29 18:55:48 +08:00
|
|
|
BACKSQL_OC_NAME( oc_map ),
|
2002-08-23 16:54:08 +08:00
|
|
|
oc_map->keytbl.bv_val, oc_map->keycol.bv_val );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( oc_map->create_proc ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "create_proc='%s'\n",
|
|
|
|
oc_map->create_proc, 0, 0 );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( oc_map->create_keyval ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "create_keyval='%s'\n",
|
|
|
|
oc_map->create_keyval, 0, 0 );
|
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( oc_map->delete_proc ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "delete_proc='%s'\n",
|
|
|
|
oc_map->delete_proc, 0, 0 );
|
|
|
|
}
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "expect_return: "
|
2002-08-23 16:54:08 +08:00
|
|
|
"add=%d, del=%d; attributes:\n",
|
2002-08-17 00:45:24 +08:00
|
|
|
BACKSQL_IS_ADD( oc_map->expect_return ),
|
|
|
|
BACKSQL_IS_DEL( oc_map->expect_return ), 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"autoadding 'objectClass' and 'ref' mappings\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_add_sysmaps( oc_map );
|
|
|
|
rc = SQLExecute( at_sth );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"error executing at_query: \n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( SQL_NULL_HENV, dbh, at_sth, rc );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_OTHER;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
backsql_BindRowAsStrings( at_sth, &at_row );
|
|
|
|
rc = SQLFetch( at_sth );
|
|
|
|
for ( ; BACKSQL_SUCCESS(rc); rc = SQLFetch( at_sth ) ) {
|
2002-08-17 00:45:24 +08:00
|
|
|
const char *text = NULL;
|
2002-08-23 16:54:08 +08:00
|
|
|
struct berval bv;
|
2003-04-16 05:55:25 +08:00
|
|
|
struct berbuf bb = BB_NULL;
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "********'%s'\n",
|
|
|
|
at_row.cols[ 0 ], 0, 0 );
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"name='%s',sel_expr='%s' from='%s'",
|
|
|
|
at_row.cols[ 0 ], at_row.cols[ 1 ],
|
|
|
|
at_row.cols[ 2 ] );
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"join_where='%s',add_proc='%s'",
|
|
|
|
at_row.cols[ 3 ], at_row.cols[ 4 ], 0 );
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "delete_proc='%s'\n",
|
|
|
|
at_row.cols[ 5 ], 0, 0 );
|
|
|
|
/* TimesTen */
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "sel_expr_u='%s'\n",
|
|
|
|
at_row.cols[ 8 ], 0, 0 );
|
|
|
|
at_map = (backsql_at_map_rec *)ch_calloc( 1,
|
|
|
|
sizeof( backsql_at_map_rec ) );
|
2002-08-23 16:54:08 +08:00
|
|
|
rc = slap_str2ad( at_row.cols[ 0 ],
|
|
|
|
&at_map->ad, &text );
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"attribute '%s' for objectClass '%s' "
|
|
|
|
"is not defined in schema: %s\n",
|
2002-10-23 22:10:21 +08:00
|
|
|
at_row.cols[ 0 ],
|
2002-08-29 18:55:48 +08:00
|
|
|
BACKSQL_OC_NAME( oc_map ), text );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_CONSTRAINT_VIOLATION;
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
ber_str2bv( at_row.cols[ 1 ], 0, 1, &at_map->sel_expr );
|
2002-09-03 03:39:31 +08:00
|
|
|
if ( at_row.value_len[ 8 ] < 0 ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
at_map->sel_expr_u.bv_val = NULL;
|
|
|
|
at_map->sel_expr_u.bv_len = 0;
|
|
|
|
} else {
|
|
|
|
ber_str2bv( at_row.cols[ 8 ], 0, 1,
|
|
|
|
&at_map->sel_expr_u );
|
|
|
|
}
|
2003-04-16 05:55:25 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
ber_str2bv( at_row.cols[ 2 ], 0, 0, &bv );
|
2003-04-16 05:55:25 +08:00
|
|
|
backsql_merge_from_clause( &bb, &bv );
|
|
|
|
at_map->from_tbls = bb.bb_val;
|
2002-09-03 03:39:31 +08:00
|
|
|
if ( at_row.value_len[ 3 ] < 0 ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
at_map->join_where.bv_val = NULL;
|
|
|
|
at_map->join_where.bv_len = 0;
|
|
|
|
} else {
|
|
|
|
ber_str2bv( at_row.cols[ 3 ], 0, 1,
|
|
|
|
&at_map->join_where );
|
|
|
|
}
|
2002-09-03 03:39:31 +08:00
|
|
|
at_map->add_proc = NULL;
|
|
|
|
if ( at_row.value_len[ 4 ] > 0 ) {
|
|
|
|
at_map->add_proc = ch_strdup( at_row.cols[4] );
|
|
|
|
}
|
|
|
|
at_map->delete_proc = NULL;
|
|
|
|
if ( at_row.value_len[ 5 ] > 0 ) {
|
|
|
|
at_map->delete_proc
|
|
|
|
= ch_strdup( at_row.cols[ 5 ] );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
at_map->param_order = strtol( at_row.cols[ 6 ],
|
|
|
|
NULL, 0 );
|
|
|
|
at_map->expect_return = strtol( at_row.cols[ 7 ],
|
|
|
|
NULL, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_make_attr_query( oc_map, at_map );
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
|
|
|
|
"preconstructed query '%s'\n",
|
|
|
|
at_map->query, 0, 0 );
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_insert( &oc_map->attrs, at_map, backsql_cmp_attr, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
backsql_FreeRow( &at_row );
|
|
|
|
SQLFreeStmt( at_sth, SQL_CLOSE );
|
|
|
|
}
|
|
|
|
backsql_FreeRow( &oc_row );
|
|
|
|
SQLFreeStmt( at_sth, SQL_DROP );
|
|
|
|
SQLFreeStmt( oc_sth, SQL_DROP );
|
2002-08-23 16:54:08 +08:00
|
|
|
si->bsql_flags |= BSQLF_SCHEMA_LOADED;
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==load_schema_map()\n", 0, 0, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
return LDAP_SUCCESS;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_oc_map_rec *
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_oc2oc( backsql_info *si, ObjectClass *oc )
|
|
|
|
{
|
|
|
|
backsql_oc_map_rec tmp, *res;
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_oc2oc(): "
|
|
|
|
"searching for objectclass with name='%s'\n",
|
|
|
|
objclass, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
tmp.oc = oc;
|
2002-12-15 06:25:52 +08:00
|
|
|
res = (backsql_oc_map_rec *)avl_find( si->oc_by_oc, &tmp, backsql_cmp_oc );
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( res != NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): "
|
2002-08-29 18:55:48 +08:00
|
|
|
"found name='%s', id=%d\n",
|
|
|
|
BACKSQL_OC_NAME( res ), res->id, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): "
|
|
|
|
"not found\n", 0, 0, 0 );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
backsql_oc_map_rec *
|
|
|
|
backsql_name2oc( backsql_info *si, struct berval *oc_name )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_oc_map_rec tmp, *res;
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>oc_with_name(): "
|
|
|
|
"searching for objectclass with name='%s'\n",
|
|
|
|
objclass, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
tmp.oc = oc_bvfind( oc_name );
|
|
|
|
if ( tmp.oc == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-12-15 06:25:52 +08:00
|
|
|
res = (backsql_oc_map_rec *)avl_find( si->oc_by_oc, &tmp, backsql_cmp_oc );
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( res != NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
|
2002-08-29 18:55:48 +08:00
|
|
|
"found name='%s', id=%d\n",
|
|
|
|
BACKSQL_OC_NAME( res ), res->id, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
|
|
|
|
"not found\n", 0, 0, 0 );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
return res;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_oc_map_rec *
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_id2oc( backsql_info *si, unsigned long id )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_oc_map_rec tmp, *res;
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>oc_with_id(): "
|
|
|
|
"searching for objectclass with id='%d'\n", id, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
tmp.id = id;
|
|
|
|
res = (backsql_oc_map_rec *)avl_find( si->oc_by_id, &tmp,
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_cmp_oc_id );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( res != NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
|
2002-08-29 18:55:48 +08:00
|
|
|
"found name='%s', id=%d\n",
|
|
|
|
BACKSQL_OC_NAME( res ), res->id, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
|
|
|
|
"not found\n", 0, 0, 0 );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
return res;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_at_map_rec *
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_ad2at( backsql_oc_map_rec* objclass, AttributeDescription *ad )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_at_map_rec tmp, *res;
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_ad2at(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"searching for attribute '%s' for objectclass '%s'\n",
|
2002-08-29 18:55:48 +08:00
|
|
|
attr, BACKSQL_OC_NAME( objclass ), 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
tmp.ad = ad;
|
2002-08-14 01:12:27 +08:00
|
|
|
res = (backsql_at_map_rec *)avl_find( objclass->attrs, &tmp,
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_cmp_attr );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( res != NULL ) {
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_ad2at(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"found name='%s', sel_expr='%s'\n",
|
2002-08-29 18:55:48 +08:00
|
|
|
res->ad->ad_cname.bv_val, res->sel_expr.bv_val, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_ad2at(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"not found\n", 0, 0, 0 );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
return res;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* Deprecated
|
|
|
|
*/
|
|
|
|
backsql_at_map_rec *
|
|
|
|
backsql_name2at( backsql_oc_map_rec* objclass, struct berval *attr )
|
|
|
|
{
|
|
|
|
backsql_at_map_rec tmp, *res;
|
|
|
|
const char *text = NULL;
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_name2at(): "
|
|
|
|
"searching for attribute '%s' for objectclass '%s'\n",
|
2002-08-29 18:55:48 +08:00
|
|
|
attr, BACKSQL_OC_NAME( objclass ), 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
if ( slap_bv2ad( attr, &tmp.ad, &text ) != LDAP_SUCCESS ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = (backsql_at_map_rec *)avl_find( objclass->attrs, &tmp,
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_cmp_attr );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( res != NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_name2at(): "
|
|
|
|
"found name='%s', sel_expr='%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
res->name, res->sel_expr.bv_val, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_name2at(): "
|
|
|
|
"not found\n", 0, 0, 0 );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_free_attr( void *v_at )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_at_map_rec *at = v_at;
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>free_attr(): '%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
ch_free( at->sel_expr.bv_val );
|
|
|
|
if ( at->from_tbls.bv_val != NULL ) {
|
|
|
|
ch_free( at->from_tbls.bv_val );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( at->join_where.bv_val != NULL ) {
|
|
|
|
ch_free( at->join_where.bv_val );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
if ( at->add_proc != NULL ) {
|
|
|
|
ch_free( at->add_proc );
|
|
|
|
}
|
|
|
|
if ( at->delete_proc != NULL ) {
|
|
|
|
ch_free( at->delete_proc );
|
|
|
|
}
|
|
|
|
if ( at->query ) {
|
|
|
|
ch_free( at->query );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TimesTen */
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( at->sel_expr_u.bv_val ) {
|
|
|
|
ch_free( at->sel_expr_u.bv_val );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
ch_free( at );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==free_attr()\n", 0, 0, 0 );
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
static void
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_free_oc( void *v_oc )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
backsql_oc_map_rec *oc = v_oc;
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>free_oc(): '%s'\n",
|
2002-08-29 18:55:48 +08:00
|
|
|
BACKSQL_OC_NAME( oc ), 0, 0 );
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_free( oc->attrs, backsql_free_attr );
|
2002-08-23 16:54:08 +08:00
|
|
|
ch_free( oc->keytbl.bv_val );
|
|
|
|
ch_free( oc->keycol.bv_val );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( oc->create_proc != NULL ) {
|
|
|
|
ch_free( oc->create_proc );
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( oc->create_keyval != NULL ) {
|
|
|
|
ch_free( oc->create_keyval );
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( oc->delete_proc != NULL ) {
|
|
|
|
ch_free( oc->delete_proc );
|
|
|
|
}
|
|
|
|
ch_free( oc );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==free_oc()\n", 0, 0, 0 );
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
|
|
|
backsql_destroy_schema_map( backsql_info *si )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>destroy_schema_map()\n", 0, 0, 0 );
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_free( si->oc_by_oc, 0 );
|
|
|
|
avl_free( si->oc_by_id, backsql_free_oc );
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==destroy_schema_map()\n", 0, 0, 0 );
|
|
|
|
return 0;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
2000-03-19 14:18:27 +08:00
|
|
|
|
2000-05-27 00:03:32 +08:00
|
|
|
#endif /* SLAPD_SQL */
|
2002-08-14 01:12:27 +08:00
|
|
|
|