From d520cd607d452fe4809d86f37b299ee7665d0f12 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 19 Jan 2005 00:00:52 +0000 Subject: [PATCH] remove all referral specific code; now referrals can be used by defining appropriate data/metadata --- servers/slapd/back-sql/back-sql.h | 3 +- servers/slapd/back-sql/config.c | 15 ---- servers/slapd/back-sql/delete.c | 53 ------------- servers/slapd/back-sql/init.c | 12 --- servers/slapd/back-sql/proto-sql.h | 1 - .../rdbms_depend/mysql/backsql_create.sql | 7 -- .../rdbms_depend/mysql/testdb_create.sql | 3 +- .../rdbms_depend/mysql/testdb_data.sql | 2 +- .../rdbms_depend/mysql/testdb_metadata.sql | 9 +-- .../rdbms_depend/pgsql/backsql_create.sql | 7 -- .../rdbms_depend/pgsql/testdb_create.sql | 3 +- .../rdbms_depend/pgsql/testdb_data.sql | 2 +- .../rdbms_depend/pgsql/testdb_metadata.sql | 9 +-- servers/slapd/back-sql/schema-map.c | 78 +------------------ servers/slapd/back-sql/util.c | 2 - 15 files changed, 14 insertions(+), 192 deletions(-) diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index 6943160b09..8079471686 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -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; diff --git a/servers/slapd/back-sql/config.c b/servers/slapd/back-sql/config.c index 51d50e6a6a..9e82f0b358 100644 --- a/servers/slapd/back-sql/config.c +++ b/servers/slapd/back-sql/config.c @@ -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, diff --git a/servers/slapd/back-sql/delete.c b/servers/slapd/back-sql/delete.c index e094fb5842..35648c5f9e 100644 --- a/servers/slapd/back-sql/delete.c +++ b/servers/slapd/back-sql/delete.c @@ -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 ) { diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index 11aa1ffd38..f78b0c7627 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -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; diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index f0a8237f9f..8019284223 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -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[], diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql b/servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql index b39df23abd..771c1c88bf 100644 --- a/servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql +++ b/servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql @@ -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 ( diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_create.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_create.sql index b4f96261dd..3c6b71e8b0 100644 --- a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_create.sql +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_create.sql @@ -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 ); diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql index 2084a18795..c204ecd8ce 100644 --- a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql @@ -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/'); diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql index 2857ee6565..1606600fe9 100644 --- a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql @@ -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/'); - diff --git a/servers/slapd/back-sql/rdbms_depend/pgsql/backsql_create.sql b/servers/slapd/back-sql/rdbms_depend/pgsql/backsql_create.sql index 65aea733cb..a4baa70400 100644 --- a/servers/slapd/back-sql/rdbms_depend/pgsql/backsql_create.sql +++ b/servers/slapd/back-sql/rdbms_depend/pgsql/backsql_create.sql @@ -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 ( diff --git a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_create.sql b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_create.sql index 30a7378fe4..0142dd9b15 100644 --- a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_create.sql +++ b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_create.sql @@ -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 ); diff --git a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_data.sql b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_data.sql index 2084a18795..c204ecd8ce 100644 --- a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_data.sql +++ b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_data.sql @@ -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/'); diff --git a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql index 66d783f6cc..4afea62502 100644 --- a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql @@ -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'; diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index 618daf5d33..7d7be83a8f 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -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; } diff --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index 0b971b0241..641abc7eb1 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -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 "; -- 2.39.5