Commit d520cd60 authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

remove all referral specific code; now referrals can be used by defining appropriate data/metadata

parent a3fbea97
......@@ -480,8 +480,7 @@ typedef struct backsql_info {
char *sql_insentry_stmt,
*sql_delentry_stmt,
*sql_renentry_stmt,
*sql_delobjclasses_stmt,
*sql_delreferrals_stmt;
*sql_delobjclasses_stmt;
char *sql_id_query;
char *sql_has_children_query;
......
......@@ -321,21 +321,6 @@ backsql_db_config(
Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
"delobjclasses_stmt=%s\n", bi->sql_delobjclasses_stmt, 0, 0 );
} else if ( !strcasecmp( argv[ 0 ], "delreferrals_stmt" ) ||
!strcasecmp( argv[ 0 ], "delreferrals_query" ) )
{
if ( argc < 2 ) {
Debug( LDAP_DEBUG_TRACE,
"<==backsql_db_config (%s line %d): "
"missing SQL statement "
"in \"delreferrals_stmt\" directive\n",
fname, lineno, 0 );
return 1;
}
bi->sql_delreferrals_stmt = ch_strdup( argv[ 1 ] );
Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
"delreferrals_stmt=%s\n", bi->sql_delreferrals_stmt, 0, 0 );
} else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
if ( argc < 2 ) {
Debug( LDAP_DEBUG_TRACE,
......
......@@ -385,59 +385,6 @@ backsql_delete( Operation *op, SlapReply *rs )
}
SQLFreeStmt( sth, SQL_DROP );
/* delete referrals, if any... */
rc = backsql_Prepare( dbh, &sth, bi->sql_delreferrals_stmt, 0 );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_delete(): "
"error preparing ldap_referrals delete query\n",
0, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error";
e = NULL;
goto done;
}
rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_delete(): "
"error binding referrals entry ID parameter "
"for objectClass %s\n",
oc->bom_oc->soc_cname.bv_val, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
sth, rc );
SQLFreeStmt( sth, SQL_DROP );
rs->sr_text = "SQL-backend error";
rs->sr_err = LDAP_OTHER;
e = NULL;
goto done;
}
rc = SQLExecute( sth );
switch ( rc ) {
case SQL_NO_DATA:
/* apparently there were no referrals
* for this entry... */
case SQL_SUCCESS:
break;
default:
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"failed to delete record from ldap_referrals\n",
0, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error";
e = NULL;
goto done;
}
SQLFreeStmt( sth, SQL_DROP );
/* delete entry... */
rc = backsql_Prepare( dbh, &sth, bi->sql_delentry_stmt, 0 );
if ( rc != SQL_SUCCESS ) {
......
......@@ -145,7 +145,6 @@ backsql_db_destroy(
free( bi->sql_delentry_stmt );
free( bi->sql_renentry_stmt );
free( bi->sql_delobjclasses_stmt );
free( bi->sql_delreferrals_stmt );
if ( bi->sql_anlist ) {
int i;
......@@ -404,17 +403,6 @@ backsql_db_open(
bi->sql_delobjclasses_stmt = ch_strdup( backsql_def_delobjclasses_stmt );
}
if ( bi->sql_delreferrals_stmt == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
"referrals deletion SQL statement not specified "
"(use \"delreferrals_stmt\" directive in slapd.conf)\n",
0, 0, 0 );
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
"setting \"%s\" by default\n",
backsql_def_delreferrals_stmt, 0, 0 );
bi->sql_delreferrals_stmt = ch_strdup( backsql_def_delreferrals_stmt );
}
op->o_hdr = (Opheader *)&op[ 1 ];
op->o_connid = (unsigned long)(-1);
op->o_bd = bd;
......
......@@ -227,7 +227,6 @@ extern char
backsql_def_renentry_stmt[],
backsql_def_insentry_stmt[],
backsql_def_delobjclasses_stmt[],
backsql_def_delreferrals_stmt[],
backsql_def_subtree_cond[],
backsql_def_upper_subtree_cond[],
backsql_id_query[],
......
......@@ -49,13 +49,6 @@ alter table ldap_entries add
dn
);
drop table if exists ldap_referrals;
create table ldap_referrals
(
entry_id integer not null references ldap_entries(id),
url text not null
);
drop table if exists ldap_entry_objclasses;
create table ldap_entry_objclasses
(
......
......@@ -69,6 +69,7 @@ ALTER TABLE phones ADD
drop table if exists referrals;
CREATE TABLE referrals (
id int NOT NULL,
name varchar(255) NOT NULL
name varchar(255) NOT NULL,
url varchar(255) NOT NULL
);
......@@ -15,4 +15,4 @@ insert into authors_docs (pers_id,doc_id) values (1,1);
insert into authors_docs (pers_id,doc_id) values (1,2);
insert into authors_docs (pers_id,doc_id) values (2,1);
insert into referrals (id,name) values (1,'Referral');
insert into referrals (id,name,url) values (1,'Referral','ldap://localhost:9010/');
......@@ -77,6 +77,9 @@ values (12,3,'dc','lower(institutes.name)','institutes,ldap_entries AS dcObject,
insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
values (13,4,'ou','referrals.name','referrals',NULL,NULL,NULL,3,0);
insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
values (14,4,'ref','referrals.url','referrals',NULL,NULL,NULL,3,0);
-- entries mapping: each entry must appear in this table, with a unique DN rooted at the database naming context
-- id a unique number > 0 identifying the entry
-- dn the DN of the entry, in "pretty" form
......@@ -113,9 +116,3 @@ values (1,'dcObject');
insert into ldap_entry_objclasses (entry_id,oc_name)
values (7,'extensibleObject');
-- referrals mapping: entries that should be treated as referrals are stored here
-- entry_id the "ldap_entries.id" of the entry that should be treated as a referral
-- url the URI of the referral
insert into ldap_referrals (entry_id,url)
values (7,'ldap://localhost:9010/');
......@@ -41,13 +41,6 @@ create table ldap_entries
UNIQUE ( dn )
);
drop table ldap_referrals;
create table ldap_referrals
(
entry_id integer not null references ldap_entries(id),
url text not null
);
drop table ldap_entry_objclasses;
create table ldap_entry_objclasses
(
......
......@@ -41,6 +41,7 @@ drop table referrals;
drop sequence referrals_id_seq;
create table referrals (
id serial not null primary key,
name varchar(255) not null
name varchar(255) not null,
url varchar(255) not null
);
......@@ -15,4 +15,4 @@ insert into authors_docs (pers_id,doc_id) values (1,1);
insert into authors_docs (pers_id,doc_id) values (1,2);
insert into authors_docs (pers_id,doc_id) values (2,1);
insert into referrals (id,name) values (1,'Referral');
insert into referrals (id,name,url) values (1,'Referral','ldap://localhost:9010/');
......@@ -53,6 +53,8 @@ insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,
insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (13,4,'ou','referrals.name','referrals',NULL,'UPDATE referrals SET name=? WHERE id=?',NULL,3,0);
insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (14,4,'ref','referrals.url','referrals',NULL,'UPDATE referrals SET url=? WHERE id=?',NULL,3,0);
-- entries mapping: each entry must appear in this table, with a unique DN rooted at the database naming context
-- id a unique number > 0 identifying the entry
-- dn the DN of the entry, in "pretty" form
......@@ -80,11 +82,6 @@ insert into ldap_entry_objclasses (entry_id,oc_name) values (1,'dcObject');
insert into ldap_entry_objclasses (entry_id,oc_name) values (7,'extensibleObject');
-- referrals mapping: entries that should be treated as referrals are stored here
-- entry_id the "ldap_entries.id" of the entry that should be treated as a referral
-- url the URI of the referral
insert into ldap_referrals (entry_id,url) values (7,'ldap://localhost:9010/');
-- procedures
-- these procedures are specific for this RDBMS and are used in mapping objectClass and attributeType creation/modify/deletion
create function create_person () returns int
......@@ -138,7 +135,7 @@ as '
create function create_referral () returns int
as '
select setval (''referrals_id_seq'', (select case when max(id) is null then 1 else max(id) end from referrals));
insert into referrals (id,name,surname)
insert into referrals (id,name,url)
values ((select case when max(id) is null then 1 else nextval(''referrals_id_seq'') end from referrals),'''','''');
select max(id) from referrals
' language 'sql';
......
......@@ -190,8 +190,7 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
struct berbuf bb;
sbv.bv_val = s;
snprintf( s, sizeof( s ), "%ld", oc_map->bom_id );
sbv.bv_len = strlen( s );
sbv.bv_len = snprintf( s, sizeof( s ), "%ld", oc_map->bom_id );
/* extra objectClasses */
at_map = (backsql_at_map_rec *)ch_calloc(1,
......@@ -285,81 +284,6 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
&sbv );
at_map->bam_join_where = bb.bb_val;
/* referral attribute */
at_map = (backsql_at_map_rec *)ch_calloc( 1,
sizeof( backsql_at_map_rec ) );
at_map->bam_ad = slap_schema.si_ad_ref;
ber_str2bv( "ldap_referrals.url", 0, 1, &at_map->bam_sel_expr );
ber_str2bv( "ldap_referrals,ldap_entries", 0, 1, &at_map->bam_from_tbls );
bb.bb_len = at_map->bam_from_tbls.bv_len + 1;
bb.bb_val = at_map->bam_from_tbls;
backsql_merge_from_clause( &bb, &oc_map->bom_keytbl );
at_map->bam_from_tbls = bb.bb_val;
BER_BVZERO( &bb.bb_val );
bb.bb_len = 0;
backsql_strfcat( &bb, "lbcblb",
(ber_len_t)STRLENOF( "ldap_entries.id=ldap_referrals.entry_id AND ldap_entries.keyval=" ),
"ldap_entries.id=ldap_referrals.entry_id AND ldap_entries.keyval=",
&oc_map->bom_keytbl,
'.',
&oc_map->bom_keycol,
(ber_len_t)STRLENOF( " AND ldap_entries.oc_map_id=" ),
" AND ldap_entries.oc_map_id=",
&sbv );
at_map->bam_join_where = bb.bb_val;
at_map->bam_oc = NULL;
at_map->bam_add_proc = NULL;
{
char tmp[] =
"INSERT INTO ldap_referrals "
"(entry_id,url) VALUES "
"((SELECT id FROM ldap_entries "
"WHERE oc_map_id="
"18446744073709551615UL " /* 64 bit ULONG */
"AND keyval=?),?)";
snprintf( tmp, sizeof(tmp),
"INSERT INTO ldap_referrals "
"(entry_id,url) VALUES "
"((SELECT id FROM ldap_entries "
"WHERE oc_map_id=%lu "
"AND keyval=?),?)", oc_map->bom_id );
at_map->bam_add_proc = ch_strdup( tmp );
}
at_map->bam_delete_proc = NULL;
{
char tmp[] =
"DELETE FROM ldap_referrals "
"WHERE entry_id=(SELECT id FROM ldap_entries "
"WHERE oc_map_id="
"18446744073709551615UL " /* 64 bit ULONG */
"AND keyval=?) and url=?";
snprintf( tmp, sizeof(tmp),
"DELETE FROM ldap_referrals "
"WHERE entry_id=(SELECT id FROM ldap_entries "
"WHERE oc_map_id=%lu"
"AND keyval=?) and url=?",
oc_map->bom_id );
at_map->bam_delete_proc = ch_strdup( tmp );
}
at_map->bam_param_order = 0;
at_map->bam_expect_return = 0;
at_map->bam_next = NULL;
backsql_make_attr_query( oc_map, at_map );
if ( avl_insert( &oc_map->bom_attrs, at_map, backsql_cmp_attr, backsql_dup_attr ) == BACKSQL_DUPLICATE ) {
Debug( LDAP_DEBUG_TRACE, "backsql_add_sysmaps(): "
"duplicate attribute \"%s\" in objectClass \"%s\" map\n",
at_map->bam_ad->ad_cname.bv_val,
oc_map->bom_oc->soc_cname.bv_val, 0 );
}
return 1;
}
......
......@@ -55,8 +55,6 @@ char backsql_def_insentry_stmt[] =
"VALUES (?,?,?,?)";
char backsql_def_delobjclasses_stmt[] = "DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=?";
char backsql_def_delreferrals_stmt[] = "DELETE FROM ldap_referrals "
"WHERE entry_id=?";
char backsql_def_subtree_cond[] = "ldap_entries.dn LIKE CONCAT('%',?)";
char backsql_def_upper_subtree_cond[] = "(ldap_entries.dn) LIKE CONCAT('%',?)";
char backsql_id_query[] = "SELECT id,keyval,oc_map_id,dn FROM ldap_entries WHERE ";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment