From: Dmitry Kovalev Date: Thu, 29 Jun 2000 21:14:43 +0000 (+0000) Subject: changes for 2.0-beta X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~2508 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e90ef57645da061ce0e276f92fd13db20134f6ff;p=openldap changes for 2.0-beta including: - fixes according to new API changes - closing db connection in connection_destroy callback, not unbind - support of new schema code, samples changed accordingly - support for multiple objectclasses (to distinguish from unique objectclass-to-tables mapping) - auto 'ref' attribute support - samples now include illustrations of using these 2 features to make named referrals as described in ldapext-namedref draft more to come: - documentation update - different improvements to be more close to native directory (after beta?) --- diff --git a/servers/slapd/back-sql/bind.c b/servers/slapd/back-sql/bind.c index 08b2ab2f61..20c566ed7f 100644 --- a/servers/slapd/back-sql/bind.c +++ b/servers/slapd/back-sql/bind.c @@ -30,7 +30,6 @@ int backsql_bind(BackendDB *be,Connection *conn,Operation *op, int backsql_unbind(BackendDB *be,Connection *conn,Operation *op) { Debug(LDAP_DEBUG_TRACE,"==>backsql_unbind()\n",0,0,0); - backsql_free_db_conn(be,conn); send_ldap_result(conn,op,LDAP_SUCCESS,NULL,NULL,NULL,0); Debug(LDAP_DEBUG_TRACE,"<==backsql_unbind()\n",0,0,0); return 0; diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 9bdbbaa52b..e75ded38ff 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -106,7 +106,7 @@ int backsql_get_attr_vals(backsql_at_map_rec *at,backsql_srch_info *bsi) if ((rc=SQLExecute(sth)) != SQL_SUCCESS && rc!= SQL_SUCCESS_WITH_INFO) { - Debug(LDAP_DEBUG_TRACE,"backsql_get_attr_values(): error executing query\n",0,0,0); + Debug(LDAP_DEBUG_TRACE,"backsql_get_attr_values(): error executing attribute query '%s'\n",at->query,0,0); backsql_PrintErrors(bsi->bi->db_env,bsi->dbh,sth,rc); SQLFreeStmt(sth,SQL_DROP); return 1; @@ -145,8 +145,13 @@ Entry* backsql_id2entry(backsql_srch_info *bsi,Entry* e,backsql_entryID* eid) bsi->e=e; bsi->c_eid=eid; e->e_attrs=NULL; - if (bsi->base_dn != NULL) - e->e_dn=ch_strdup(bsi->c_eid->dn); + e->e_private=NULL; + +// if (bsi->base_dn != NULL)??? + + e->e_id=eid->id; + e->e_dn=ch_strdup(bsi->c_eid->dn); + e->e_ndn=dn_normalize(ch_strdup(bsi->c_eid->dn)); if (bsi->attrs!=NULL) { diff --git a/servers/slapd/back-sql/external.h b/servers/slapd/back-sql/external.h index 3f9bd7cd4d..14bac04071 100644 --- a/servers/slapd/back-sql/external.h +++ b/servers/slapd/back-sql/external.h @@ -43,12 +43,12 @@ extern int backsql_search LDAP_P(( BackendDB *bd, extern int backsql_compare LDAP_P((BackendDB *bd, Connection *conn, Operation *op, const char *dn, const char *ndn, - Ava *ava )); + AttributeAssertion *ava )); extern int backsql_modify LDAP_P(( BackendDB *bd, Connection *conn, Operation *op, const char *dn, const char *ndn, - LDAPModList *ml )); + Modifications *ml )); extern int backsql_modrdn LDAP_P(( BackendDB *bd, Connection *conn, Operation *op, @@ -66,6 +66,9 @@ extern int backsql_delete LDAP_P(( BackendDB *bd, extern int backsql_abandon LDAP_P(( BackendDB *bd, Connection *conn, Operation *op, int msgid )); +extern int backsql_connection_destroy LDAP_P(( BackendDB *bd, + Connection *conn)); + LDAP_END_DECL #endif /* _SQL_EXTERNAL_H */ diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index 8c58f1b27c..dca5ee5fb0 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -70,7 +70,7 @@ int sql_back_initialize( bi->bi_chk_referrals = 0; bi->bi_connection_init = 0; - bi->bi_connection_destroy = 0; + bi->bi_connection_destroy = backsql_connection_destroy; Debug(LDAP_DEBUG_TRACE,"<==backsql_initialize()\n",0,0,0); return 0; @@ -212,4 +212,12 @@ int backsql_db_close(BackendDB *bd) return 0; } +int backsql_connection_destroy(BackendDB *be,Connection *conn) +{ + Debug(LDAP_DEBUG_TRACE,"==>backsql_connection_destroy()\n",0,0,0); + backsql_free_db_conn(be,conn); + Debug(LDAP_DEBUG_TRACE,"<==backsql_connection_destroy()\n",0,0,0); + return 0; +} + #endif /* SLAPD_SQL */ diff --git a/servers/slapd/back-sql/modify.c b/servers/slapd/back-sql/modify.c index bc1ce05873..ebaa7834a0 100644 --- a/servers/slapd/back-sql/modify.c +++ b/servers/slapd/back-sql/modify.c @@ -22,7 +22,7 @@ #include "util.h" int backsql_modify(BackendDB *be,Connection *conn,Operation *op, - const char *dn,const char *ndn,LDAPModList *modlist) + const char *dn,const char *ndn,Modifications *modlist) { backsql_info *bi=(backsql_info*)be->be_private; SQLHDBC dbh; @@ -30,7 +30,8 @@ int backsql_modify(BackendDB *be,Connection *conn,Operation *op, RETCODE rc; backsql_oc_map_rec *oc=NULL; backsql_entryID e_id,*res; - LDAPModList *c_mod; + Modification *c_mod; + Modifications *ml; backsql_at_map_rec *at=NULL; struct berval *at_val; int i; @@ -64,17 +65,18 @@ int backsql_modify(BackendDB *be,Connection *conn,Operation *op, SQLAllocStmt(dbh, &sth); Debug(LDAP_DEBUG_TRACE,"backsql_modify(): traversing modifications list\n",0,0,0); - for(c_mod=modlist;c_mod!=NULL;c_mod=c_mod->ml_next) + for(ml=modlist;ml!=NULL;ml=ml->sml_next) { - Debug(LDAP_DEBUG_TRACE,"backsql_modify(): attribute '%s'\n",c_mod->ml_type,0,0); - at=backsql_at_with_name(oc,c_mod->ml_type); + c_mod=&ml->sml_mod; + Debug(LDAP_DEBUG_TRACE,"backsql_modify(): attribute '%s'\n",c_mod->sm_desc->ad_cname->bv_val,0,0); + at=backsql_at_with_name(oc,c_mod->sm_desc->ad_cname->bv_val); if (at==NULL) { - Debug(LDAP_DEBUG_TRACE,"backsql_modify(): attribute provided is not registered in this objectclass ('%s')\n",c_mod->ml_type,0,0); + Debug(LDAP_DEBUG_TRACE,"backsql_modify(): attribute provided is not registered in this objectclass ('%s')\n",c_mod->sm_desc->ad_cname->bv_val,0,0); continue; } - switch(c_mod->ml_op) + switch(c_mod->sm_op) { case LDAP_MOD_REPLACE: { @@ -148,13 +150,13 @@ del_all: Debug(LDAP_DEBUG_TRACE,"backsql_modify(): add procedure is not defined for this attribute ('%s')\n",at->name,0,0); break; } - if (c_mod->ml_bvalues==NULL) + if (c_mod->sm_bvalues==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_modify(): no values given to add for attribute '%s'\n",at->name,0,0); break; } Debug(LDAP_DEBUG_TRACE,"backsql_modify(): adding new values for attribute '%s'\n",at->name,0,0); - for(i=0,at_val=c_mod->ml_bvalues[0];at_val!=NULL;i++,at_val=c_mod->ml_bvalues[i]) + for(i=0,at_val=c_mod->sm_bvalues[0];at_val!=NULL;i++,at_val=c_mod->sm_bvalues[i]) { if (at->expect_return & BACKSQL_ADD) { @@ -183,13 +185,13 @@ del_all: Debug(LDAP_DEBUG_TRACE,"backsql_modify(): delete procedure is not defined for this attribute ('%s')\n",at->name,0,0); break; } - if (c_mod->ml_bvalues==NULL) + if (c_mod->sm_bvalues==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_modify(): no values given to delete for attribute '%s' -- deleting all values\n",at->name,0,0); goto del_all; } Debug(LDAP_DEBUG_TRACE,"backsql_modify(): deleting values for attribute '%s'\n",at->name,0,0); - for(i=0,at_val=c_mod->ml_bvalues[0];at_val!=NULL;i++,at_val=c_mod->ml_bvalues[i]) + for(i=0,at_val=c_mod->sm_bvalues[0];at_val!=NULL;i++,at_val=c_mod->sm_bvalues[i]) { if (at->expect_return & BACKSQL_DEL) { @@ -225,7 +227,122 @@ del_all: int backsql_modrdn(BackendDB *be,Connection *conn,Operation *op, const char *dn,const char *ndn,const char *newrdn,int deleteoldrdn,const char *newSuperior) { - Debug(LDAP_DEBUG_TRACE,"==>backsql_modrdn()\n",0,0,0); + backsql_info *bi=(backsql_info*)be->be_private; + SQLHDBC dbh; + SQLHSTMT sth; + RETCODE rc; + backsql_oc_map_rec *oc=NULL; + backsql_entryID e_id,pe_id,new_pid,*res; + backsql_at_map_rec *at=NULL; + char *p_dn=NULL,*new_pdn=NULL, *new_dn; + + + Debug(LDAP_DEBUG_TRACE,"==>backsql_modrdn() renaming entry '%s', newrdn='%s', newSuperior='%s'\n",dn,newrdn,newSuperior); + dbh=backsql_get_db_conn(be,conn); + if (!dbh) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not get connection handle - exiting\n",0,0,0); + send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); + return 1; + } + res=backsql_dn2id(bi,&e_id,dbh,(char*)ndn); + if (res==NULL) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not lookup entry id\n",0,0,0); + send_ldap_result(conn,op,LDAP_NO_SUCH_OBJECT,"",NULL,NULL,NULL); + return 1; + } + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): entry id is %d\n",e_id.id,0,0); + + p_dn=dn_parent(be,ndn); + + if (newSuperior) + new_pdn=dn_validate(ch_strdup(newSuperior)); + else + new_pdn=p_dn; + + SQLAllocStmt(dbh, &sth); + + if (newSuperior && !strcasecmp(p_dn,new_pdn)) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): newSuperior is equal to old parent - aborting\n",0,0,0); + send_ldap_result(conn,op,LDAP_OTHER,"",NULL,NULL,NULL); + goto modrdn_return; + } + + if (newSuperior && !strcasecmp(ndn,new_pdn)) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): newSuperior is equal to entry being moved - aborting\n",0,0,0); + send_ldap_result(conn,op,LDAP_OTHER,"",NULL,NULL,NULL); + goto modrdn_return; + } + + build_new_dn( &new_dn, dn, new_pdn, newrdn ); + if (!dn_validate(new_dn)) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): new dn is invalid ('%s') - aborting\n",new_dn,0,0); + send_ldap_result(conn,op,LDAP_OTHER,"",NULL,NULL,NULL); + goto modrdn_return; + } + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): new entry dn is '%s'\n",new_dn,0,0); + + res=backsql_dn2id(bi,&pe_id,dbh,(char*)p_dn); + if (res==NULL) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not lookup old parent entry id\n",0,0,0); + send_ldap_result(conn,op,LDAP_NO_SUCH_OBJECT,"",NULL,NULL,NULL); + goto modrdn_return; + } + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): old parent entry id is %d\n",pe_id.id,0,0); + + res=backsql_dn2id(bi,&new_pid,dbh,(char*)new_pdn); + if (res==NULL) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not lookup new parent entry id\n",0,0,0); + send_ldap_result(conn,op,LDAP_NO_SUCH_OBJECT,"",NULL,NULL,NULL); + goto modrdn_return; + } + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): new parent entry id is %d\n",new_pid.id,0,0); + + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): executing delentry_query\n",0,0,0); + SQLBindParameter(sth,1,SQL_PARAM_INPUT,SQL_C_ULONG,SQL_INTEGER,0,0,&e_id.id,0,0); + rc=SQLExecDirect(sth,bi->delentry_query,SQL_NTS); + if (rc != SQL_SUCCESS) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): failed to delete record from ldap_entries\n",0,0,0); + backsql_PrintErrors(bi->db_env,dbh,sth,rc); + send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); + goto modrdn_return; + } + + SQLFreeStmt(sth,SQL_RESET_PARAMS); + + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): executing insentry_query\n",0,0,0); + backsql_BindParamStr(sth,1,new_dn,BACKSQL_MAX_DN_LEN); + SQLBindParameter(sth,2,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&e_id.oc_id,0,0); + SQLBindParameter(sth,3,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&new_pid.id,0,0); + SQLBindParameter(sth,4,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&e_id.keyval,0,0); + rc=SQLExecDirect(sth,bi->insentry_query,SQL_NTS); + if (rc != SQL_SUCCESS) + { + Debug(LDAP_DEBUG_TRACE,"backsql_modrdn(): could not insert ldap_entries record\n",0,0,0); + backsql_PrintErrors(bi->db_env,dbh,sth,rc); + send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); + goto modrdn_return; + } + + //should process deleteoldrdn here... + + send_ldap_result(conn,op,LDAP_SUCCESS,"",NULL,NULL,NULL); +modrdn_return: + SQLFreeStmt(sth,SQL_DROP); + if (p_dn) + ch_free(p_dn); + if (newSuperior && new_pdn) + ch_free(new_pdn); + if (new_dn) + ch_free(new_dn); + Debug(LDAP_DEBUG_TRACE,"<==backsql_modrdn()\n",0,0,0); return 0; } @@ -254,7 +371,7 @@ int backsql_add(BackendDB *be,Connection *conn,Operation *op,Entry *e) for(at=e->e_attrs;at!=NULL;at=at->a_next) { //Debug(LDAP_DEBUG_TRACE,"backsql_add(): scanning entry -- %s\n",at->a_type,0,0); - if (!strcasecmp(at->a_type,"objectclass")) + if (!strcasecmp(at->a_desc->ad_cname->bv_val,"objectclass")) { oc=backsql_oc_with_name(bi,at->a_vals[0]->bv_val); break; @@ -300,15 +417,16 @@ int backsql_add(BackendDB *be,Connection *conn,Operation *op,Entry *e) for(at=e->e_attrs;at!=NULL;at=at->a_next) { - at_rec=backsql_at_with_name(oc,at->a_type); + at_rec=backsql_at_with_name(oc,at->a_desc->ad_cname->bv_val); + if (at_rec==NULL) { - Debug(LDAP_DEBUG_TRACE,"backsql_add(): attribute provided is not registered in this objectclass ('%s')\n",at->a_type,0,0); + Debug(LDAP_DEBUG_TRACE,"backsql_add(): attribute provided is not registered in this objectclass ('%s')\n",at->a_desc->ad_cname->bv_val,0,0); continue; } if (at_rec->add_proc==NULL) { - Debug(LDAP_DEBUG_TRACE,"backsql_add(): add procedure is not defined for this attribute ('%s')\n",at->a_type,0,0); + Debug(LDAP_DEBUG_TRACE,"backsql_add(): add procedure is not defined for this attribute ('%s')\n",at->a_desc->ad_cname->bv_val,0,0); continue; } diff --git a/servers/slapd/back-sql/other.c b/servers/slapd/back-sql/other.c index b4a3fa0100..c89e4d0f23 100644 --- a/servers/slapd/back-sql/other.c +++ b/servers/slapd/back-sql/other.c @@ -22,8 +22,10 @@ int backsql_dummy() return 0; } -int backsql_compare(BackendDB *be,Connection *conn,Operation *op, - const char *dn,const char *ndn,Ava *ava) +int backsql_compare(BackendDB *bd, + Connection *conn, Operation *op, + const char *dn, const char *ndn, + AttributeAssertion *ava ) { Debug(LDAP_DEBUG_TRACE,"==>backsql_compare()\n",0,0,0); return 0; diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/backsql_create.sql b/servers/slapd/back-sql/rdbms_depend/mssql/backsql_create.sql new file mode 100644 index 0000000000..ebbffbd0b9 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mssql/backsql_create.sql @@ -0,0 +1,100 @@ +create table ldap_oc_mappings ( + id int identity (1, 1) not null , + name varchar (64) not null , + keytbl varchar (64) not null , + keycol varchar (64) not null , + create_proc varchar (255) NULL , + delete_proc varchar (255) NULL, + expect_return int not null +) +GO + +alter table ldap_oc_mappings add + constraint pk_ldap_oc_mappings primary key + ( + id + ) +GO + + +alter table ldap_oc_mappings add + constraint unq1_ldap_oc_mappings unique + ( + name + ) +GO + + +create table ldap_attr_mappings ( + id int identity (1, 1) not null , + oc_map_id int not null references ldap_oc_mappings(id), + name varchar (255) not null , + sel_expr varchar (255) not null , + from_tbls varchar (255) not null , + join_where varchar (255) NULL , + add_proc varchar (255) NULL , + modify_proc varchar (255) NULL , + delete_proc varchar (255) NULL , + param_order int not null, + expect_return int not null +) +GO + +alter table ldap_attr_mappings add + constraint pk_ldap_attr_mappings primary key + ( + id + ) +GO + + +create table ldap_entries ( + id int identity (1, 1) not null , + dn varchar (255) not null , + oc_map_id int not null references ldap_oc_mappings(id), + parent int not null , + keyval int not null +) +GO + + +alter table ldap_entries add + constraint pk_ldap_entries primary key + ( + id + ) +GO + +alter table ldap_entries add + constraint unq1_ldap_entries unique + ( + oc_map_id, + keyval + ) +GO + +alter table ldap_entries add + constraint unq2_ldap_entries unique + ( + dn + ) +GO + + +create table ldap_referrals + ( + entry_id int not null references ldap_entries(id), + url text not null +) +GO + +create index entry_idx on ldap_referrals(entry_id); + +create table ldap_entry_objclasses + ( + entry_id int not null references ldap_entries(id), + oc_name varchar(64) + ) +GO + +create index entry_idx on ldap_entry_objclasses(entry_id); \ No newline at end of file diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/backsql_drop.sql b/servers/slapd/back-sql/rdbms_depend/mssql/backsql_drop.sql new file mode 100644 index 0000000000..0e888b31c6 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mssql/backsql_drop.sql @@ -0,0 +1,14 @@ +drop table ldap_attr_mappings +GO + +drop table ldap_referrals +GO + +drop table ldap_entry_objclasses +GO + +drop table ldap_entries +GO + +drop table ldap_oc_mappings +GO diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/create.sql b/servers/slapd/back-sql/rdbms_depend/mssql/create.sql deleted file mode 100644 index 1ac2e1f17f..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mssql/create.sql +++ /dev/null @@ -1,79 +0,0 @@ -CREATE TABLE ldap_attrs ( - id int IDENTITY (1, 1) NOT NULL , - oc_id int NOT NULL , - name varchar (255) NOT NULL , - sel_expr varchar (255) NOT NULL , - from_tbls varchar (255) NOT NULL , - join_where varchar (255) NULL , - add_proc varchar (255) NULL , - modify_proc varchar (255) NULL , - delete_proc varchar (255) NULL , - param_order int NOT NULL, - expect_return int NOT NULL -) -GO - -CREATE TABLE ldap_entries ( - id int IDENTITY (1, 1) NOT NULL , - dn varchar (255) NOT NULL , - objclass int NOT NULL , - parent int NOT NULL , - keyval int NOT NULL -) -GO - -CREATE TABLE ldap_objclasses ( - id int IDENTITY (1, 1) NOT NULL , - name varchar (64) NOT NULL , - keytbl varchar (64) NOT NULL , - keycol varchar (64) NOT NULL , - create_proc varchar (255) NULL , - delete_proc varchar (255) NULL, - expect_return int NOT NULL -) -GO - - -ALTER TABLE ldap_attrs WITH NOCHECK ADD - CONSTRAINT PK_ldap_attrs PRIMARY KEY - ( - id - ) -GO - -ALTER TABLE ldap_entries WITH NOCHECK ADD - CONSTRAINT PK_ldap_entries PRIMARY KEY - ( - id - ) -GO - -ALTER TABLE ldap_entries WITH NOCHECK ADD - CONSTRAINT UNQ1_ldap_entries UNIQUE - ( - objclass, - keyval - ) -GO - -ALTER TABLE ldap_entries WITH NOCHECK ADD - CONSTRAINT UNQ2_ldap_entries UNIQUE - ( - dn - ) -GO - -ALTER TABLE ldap_objclasses WITH NOCHECK ADD - CONSTRAINT PK_ldap_objclasses PRIMARY KEY - ( - id - ) -GO - - -ALTER TABLE ldap_objclasses WITH NOCHECK ADD - CONSTRAINT UNQ_ldap_objclasses UNIQUE - ( - name - ) -GO diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/create_testdb.sql b/servers/slapd/back-sql/rdbms_depend/mssql/create_testdb.sql deleted file mode 100644 index 1040e580ec..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mssql/create_testdb.sql +++ /dev/null @@ -1,160 +0,0 @@ - -CREATE TABLE authors_docs ( - pers_id int NOT NULL , - doc_id int NOT NULL -) -GO - -CREATE TABLE documents ( - id int IDENTITY (1, 1) NOT NULL , - abstract varchar (255) NULL , - title varchar (255) NULL , - body binary (255) NULL -) -GO - -CREATE TABLE institutes ( - id int IDENTITY (1, 1) NOT NULL , - name varchar (255) NOT NULL -) -GO - - -CREATE TABLE persons ( - id int IDENTITY (1, 1) NOT NULL , - name varchar (255) NULL -) -GO - -CREATE TABLE phones ( - id int IDENTITY (1, 1) NOT NULL , - phone varchar (255) NOT NULL , - pers_id int NOT NULL -) -GO - -ALTER TABLE authors_docs WITH NOCHECK ADD - CONSTRAINT PK_authors_docs PRIMARY KEY - ( - pers_id, - doc_id - ) -GO - -ALTER TABLE documents WITH NOCHECK ADD - CONSTRAINT PK_documents PRIMARY KEY - ( - id - ) -GO - -ALTER TABLE institutes WITH NOCHECK ADD - CONSTRAINT PK_institutes PRIMARY KEY - ( - id - ) -GO - - -ALTER TABLE persons WITH NOCHECK ADD - CONSTRAINT PK_persons PRIMARY KEY - ( - id - ) -GO - -ALTER TABLE phones WITH NOCHECK ADD - CONSTRAINT PK_phones PRIMARY KEY - ( - id - ) -GO - -SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON -GO - -CREATE PROCEDURE add_phone @pers_id int, @phone varchar(255) AS -INSERT INTO ldap.phones (pers_id,phone) VALUES (@pers_id,@phone) -GO - -CREATE PROCEDURE create_person @@keyval int OUTPUT AS -INSERT INTO ldap.persons (name) VALUES (''); -set @@keyval=(SELECT MAX(id) FROM ldap.persons) -GO - -CREATE PROCEDURE delete_person @keyval int AS -DELETE FROM ldap.phones WHERE pers_id=@keyval; -DELETE FROM ldap.authors_docs WHERE pers_id=@keyval; -DELETE FROM ldap.persons WHERE id=@keyval; -GO - -CREATE PROCEDURE create_org @@keyval int OUTPUT AS -INSERT INTO ldap.institutes (name) VALUES (''); -set @@keyval=(SELECT MAX(id) FROM ldap.institutes) -GO - -CREATE PROCEDURE create_document @@keyval int OUTPUT AS -INSERT INTO ldap.documents (title) VALUES (''); -set @@keyval=(SELECT MAX(id) FROM ldap.documents) -GO - -CREATE PROCEDURE delete_org @keyval int AS -DELETE FROM ldap.institutes WHERE id=@keyval; -GO - -CREATE PROCEDURE delete_document @keyval int AS -DELETE FROM ldap.authors_docs WHERE doc_id=@keyval; -DELETE FROM ldap.documents WHERE id=@keyval; -GO - -CREATE PROCEDURE delete_phone @keyval int,@phone varchar(64) AS -DELETE FROM ldap.phones WHERE pers_id=@keyval AND phone=@phone; -GO - -CREATE PROCEDURE set_person_name @keyval int, @new_name varchar(255) AS -UPDATE ldap.persons SET name=@new_name WHERE id=@keyval; -GO - -CREATE PROCEDURE set_org_name @keyval int, @new_name varchar(255) AS -UPDATE ldap.institutes SET name=@new_name WHERE id=@keyval; -GO - -CREATE PROCEDURE set_doc_title @keyval int, @new_title varchar(255) AS -UPDATE ldap.documents SET title=@new_title WHERE id=@keyval; -GO - -CREATE PROCEDURE set_doc_abstract @keyval int, @new_abstract varchar(255) AS -UPDATE ldap.documents SET abstract=@new_abstract WHERE id=@keyval; -GO - -CREATE PROCEDURE make_author_link @keyval int, @author_dn varchar(255) AS -DECLARE @per_id int; -SET @per_id=(SELECT keyval FROM ldap.ldap_entries - WHERE objclass=1 AND dn=@author_dn); -IF NOT (@per_id IS NULL) - INSERT INTO ldap.authors_docs (doc_id,pers_id) VALUES (@keyval,@per_id); -GO - -CREATE PROCEDURE make_doc_link @keyval int, @doc_dn varchar(255) AS -DECLARE @doc_id int; -SET @doc_id=(SELECT keyval FROM ldap.ldap_entries - WHERE objclass=2 AND dn=@doc_dn); -IF NOT (@doc_id IS NULL) - INSERT INTO ldap.authors_docs (pers_id,doc_id) VALUES (@keyval,@doc_id); -GO - -CREATE PROCEDURE del_doc_link @keyval int, @doc_dn varchar(255) AS -DECLARE @doc_id int; -SET @doc_id=(SELECT keyval FROM ldap.ldap_entries - WHERE objclass=2 AND dn=@doc_dn); -IF NOT (@doc_id IS NULL) -DELETE FROM ldap.authors_docs WHERE pers_id=@keyval AND doc_id=@doc_id; -GO - -CREATE PROCEDURE del_author_link @keyval int, @author_dn varchar(255) AS -DECLARE @per_id int; -SET @per_id=(SELECT keyval FROM ldap.ldap_entries - WHERE objclass=1 AND dn=@author_dn); -IF NOT (@per_id IS NULL) - DELETE FROM ldap.authors_docs WHERE doc_id=@keyval AND pers_id=@per_id; -GO diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/drop.sql b/servers/slapd/back-sql/rdbms_depend/mssql/drop.sql deleted file mode 100644 index 2773ab811b..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mssql/drop.sql +++ /dev/null @@ -1,13 +0,0 @@ - -if exists (select * from sysobjects where id = object_id(N'ldap_attrs') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table ldap_attrs -GO - -if exists (select * from sysobjects where id = object_id(N'ldap_entries') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table ldap_entries -GO - -if exists (select * from sysobjects where id = object_id(N'ldap_objclasses') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table ldap_objclasses -GO - diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/drop_testdb.sql b/servers/slapd/back-sql/rdbms_depend/mssql/drop_testdb.sql deleted file mode 100644 index 4842ed8920..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mssql/drop_testdb.sql +++ /dev/null @@ -1,39 +0,0 @@ -drop procedure create_person -drop procedure set_person_name -drop procedure delete_phone -drop procedure add_phone -drop procedure make_doc_link -drop procedure del_doc_link -drop procedure delete_person - -drop procedure create_org -drop procedure set_org_name -drop procedure delete_org - -drop procedure create_document -drop procedure set_doc_title -drop procedure set_doc_abstract -drop procedure make_author_link -drop procedure del_author_link -drop procedure delete_document - -if exists (select * from sysobjects where id = object_id(N'authors_docs') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table authors_docs -GO - -if exists (select * from sysobjects where id = object_id(N'documents') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table documents -GO - -if exists (select * from sysobjects where id = object_id(N'institutes') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table institutes -GO - -if exists (select * from sysobjects where id = object_id(N'persons') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table persons -GO - -if exists (select * from sysobjects where id = object_id(N'phones') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -drop table phones -GO - diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/slapd.conf b/servers/slapd/back-sql/rdbms_depend/mssql/slapd.conf index 386fb93517..c3032f2367 100644 --- a/servers/slapd/back-sql/rdbms_depend/mssql/slapd.conf +++ b/servers/slapd/back-sql/rdbms_depend/mssql/slapd.conf @@ -3,8 +3,9 @@ # See slapd.conf(5) for details on configuration options. # This file should NOT be world readable. # -include ./slapd.at.conf -include ./slapd.oc.conf +include ./schema/core.schema +include ./schema/cosine.schema +include ./schema/inetorgperson.schema # Define global ACLs to disable default read access. @@ -16,19 +17,9 @@ pidfile ./slapd.pid argsfile ./slapd.args ####################################################################### -# ldbm database definitions +# sql database definitions ####################################################################### -#database ldbm -#suffix "dc=your-domain, dc=com" -#suffix "o=Your Organization Name, c=US" -#directory /usr/tmp -#rootdn "cn=root, dc=your-domain, dc=com" -#rootdn "cn=root, o=Your Organization Name, c=US" -#rootpw secret -# cleartext passwords, especially for the rootdn, should -# be avoid. See slapd.conf(5) for details. - database sql suffix "o=sql,c=RU" rootdn "cn=root,o=sql,c=RU" diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/test_data.sql b/servers/slapd/back-sql/rdbms_depend/mssql/test_data.sql deleted file mode 100644 index a166969d99..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mssql/test_data.sql +++ /dev/null @@ -1,45 +0,0 @@ -set IDENTITY_INSERT institutes ON -insert into institutes (id,name) values (1,'sql') -set IDENTITY_INSERT institutes OFF - -set IDENTITY_INSERT persons ON -insert into persons (id,name) values (1,'Mitya Kovalev') -insert into persons (id,name) values (2,'Torvlobnor Puzdoy') -insert into persons (id,name) values (3,'Akakiy Zinberstein') -set IDENTITY_INSERT persons OFF - -set IDENTITY_INSERT phones ON -insert into phones (id,phone,pers_id) values (1,'332-2334',1) -insert into phones (id,phone,pers_id) values (2,'222-3234',1) -insert into phones (id,phone,pers_id) values (3,'545-4563',2) -set IDENTITY_INSERT phones OFF - -set IDENTITY_INSERT documents ON -insert into documents (id,abstract,title) values (1,'abstract1','book1') -insert into documents (id,abstract,title) values (2,'abstract2','book2') -set IDENTITY_INSERT documents OFF - -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) - -SET IDENTITY_INSERT ldap_entries ON -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (1,'o=sql,c=RU',3,0,1) - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (2,'cn=Mitya Kovalev,o=sql,c=RU',1,1,1) - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (3,'cn=Torvlobnor Puzdoy,o=sql,c=RU',1,1,2) - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (4,'cn=Akakiy Zinberstein,o=sql,c=RU',1,1,3) - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (5,'documentTitle=book1,o=sql,c=RU',2,1,1) - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (6,'documentTitle=book2,o=sql,c=RU',2,1,2) - -SET IDENTITY_INSERT ldap_entries OFF diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/test_metadata.sql b/servers/slapd/back-sql/rdbms_depend/mssql/test_metadata.sql deleted file mode 100644 index d401ad28da..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mssql/test_metadata.sql +++ /dev/null @@ -1,56 +0,0 @@ - - -SET IDENTITY_INSERT ldap_objclasses ON -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (1,'person','persons','id','{call create_person(?)}','{call delete_person(?)}',0) - -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (2,'document','documents','id','{call create_document(?)}','{call delete_document(?)}',0) - -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (3,'organization','institutes','id','{call create_org(?)}','{call delete_org(?)}',0) -SET IDENTITY_INSERT ldap_objclasses OFF - - -SET IDENTITY_INSERT ldap_attrs ON -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (1,1,'cn','persons.name','persons',NULL,'{call set_person_name(?,?)}', - NULL,NULL,0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (2,1,'telephoneNumber','phones.phone','persons,phones', - 'phones.pers_id=persons.id','{call add_phone(?,?)}', - NULL,'{call delete_phone(?,?)}',0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (3,1,'sn','persons.name','persons',NULL,'{call set_person_name(?,?)}', - NULL,NULL,0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (4,2,'abstract','documents.abstract','documents',NULL,'{call set_doc_abstract(?,?)}', - NULL,NULL,0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (5,2,'documentTitle','documents.title','documents',NULL,'{call set_doc_title(?,?)}', - NULL,NULL,0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (6,2,'documentAuthor','persons.name','persons,documents,authors_docs', - 'persons.id=authors_docs.pers_id AND documents.id=authors_docs.doc_id', - NULL,NULL,NULL,0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (7,3,'o','institutes.name','institutes',NULL,'{call set_org_name(?,?)}', - NULL,NULL,0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', - 'ldap_entries.keyval=documents.id AND ldap_entries.objclass=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', - '{call make_doc_link(?,?)}',NULL,'{call del_doc_link(?,?)}',0,0) - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (9,2,'authorDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', - 'ldap_entries.keyval=persons.id AND ldap_entries.objclass=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', - '{call make_author_link(?,?)}',NULL,'{call del_author_link(?,?)}',0,0) - -SET IDENTITY_INSERT ldap_attrs OFF diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/testdb_create.sql b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_create.sql new file mode 100644 index 0000000000..42bfe4d624 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_create.sql @@ -0,0 +1,72 @@ + +CREATE TABLE authors_docs ( + pers_id int NOT NULL , + doc_id int NOT NULL +) +GO + +CREATE TABLE documents ( + id int IDENTITY (1, 1) NOT NULL , + abstract varchar (255) NULL , + title varchar (255) NULL , + body binary (255) NULL +) +GO + +CREATE TABLE institutes ( + id int IDENTITY (1, 1) NOT NULL , + name varchar (255) NOT NULL +) +GO + + +CREATE TABLE persons ( + id int IDENTITY (1, 1) NOT NULL , + name varchar (255) NULL +) +GO + +CREATE TABLE phones ( + id int IDENTITY (1, 1) NOT NULL , + phone varchar (255) NOT NULL , + pers_id int NOT NULL +) +GO + +ALTER TABLE authors_docs WITH NOCHECK ADD + CONSTRAINT PK_authors_docs PRIMARY KEY + ( + pers_id, + doc_id + ) +GO + +ALTER TABLE documents WITH NOCHECK ADD + CONSTRAINT PK_documents PRIMARY KEY + ( + id + ) +GO + +ALTER TABLE institutes WITH NOCHECK ADD + CONSTRAINT PK_institutes PRIMARY KEY + ( + id + ) +GO + + +ALTER TABLE persons WITH NOCHECK ADD + CONSTRAINT PK_persons PRIMARY KEY + ( + id + ) +GO + +ALTER TABLE phones WITH NOCHECK ADD + CONSTRAINT PK_phones PRIMARY KEY + ( + id + ) +GO + diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/testdb_data.sql b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_data.sql new file mode 100644 index 0000000000..1daa348ed8 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_data.sql @@ -0,0 +1,24 @@ +set IDENTITY_INSERT institutes ON +insert into institutes (id,name) values (1,'sql') +set IDENTITY_INSERT institutes OFF + +set IDENTITY_INSERT persons ON +insert into persons (id,name) values (1,'Mitya Kovalev') +insert into persons (id,name) values (2,'Torvlobnor Puzdoy') +insert into persons (id,name) values (3,'Akakiy Zinberstein') +set IDENTITY_INSERT persons OFF + +set IDENTITY_INSERT phones ON +insert into phones (id,phone,pers_id) values (1,'332-2334',1) +insert into phones (id,phone,pers_id) values (2,'222-3234',1) +insert into phones (id,phone,pers_id) values (3,'545-4563',2) +set IDENTITY_INSERT phones OFF + +set IDENTITY_INSERT documents ON +insert into documents (id,abstract,title) values (1,'abstract1','book1') +insert into documents (id,abstract,title) values (2,'abstract2','book2') +set IDENTITY_INSERT documents OFF + +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) diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/testdb_drop.sql b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_drop.sql new file mode 100644 index 0000000000..4842ed8920 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_drop.sql @@ -0,0 +1,39 @@ +drop procedure create_person +drop procedure set_person_name +drop procedure delete_phone +drop procedure add_phone +drop procedure make_doc_link +drop procedure del_doc_link +drop procedure delete_person + +drop procedure create_org +drop procedure set_org_name +drop procedure delete_org + +drop procedure create_document +drop procedure set_doc_title +drop procedure set_doc_abstract +drop procedure make_author_link +drop procedure del_author_link +drop procedure delete_document + +if exists (select * from sysobjects where id = object_id(N'authors_docs') and OBJECTPROPERTY(id, N'IsUserTable') = 1) +drop table authors_docs +GO + +if exists (select * from sysobjects where id = object_id(N'documents') and OBJECTPROPERTY(id, N'IsUserTable') = 1) +drop table documents +GO + +if exists (select * from sysobjects where id = object_id(N'institutes') and OBJECTPROPERTY(id, N'IsUserTable') = 1) +drop table institutes +GO + +if exists (select * from sysobjects where id = object_id(N'persons') and OBJECTPROPERTY(id, N'IsUserTable') = 1) +drop table persons +GO + +if exists (select * from sysobjects where id = object_id(N'phones') and OBJECTPROPERTY(id, N'IsUserTable') = 1) +drop table phones +GO + diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql b/servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql new file mode 100644 index 0000000000..4e5bb51e0f --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql @@ -0,0 +1,64 @@ +drop table if exists ldap_oc_mappings; +create table ldap_oc_mappings + ( + id integer unsigned not null primary key auto_increment, + name varchar(64) not null, + keytbl varchar(64) not null, + keycol varchar(64) not null, + create_proc varchar(255), + delete_proc varchar(255), + expect_return tinyint not null +); + +drop table if exists ldap_attr_mappings; +create table ldap_attr_mappings + ( + id integer unsigned not null primary key auto_increment, + oc_map_id integer unsigned not null references ldap_oc_mappings(id), + name varchar(255) not null, + sel_expr varchar(255) not null, + from_tbls varchar(255) not null, + join_where varchar(255), + add_proc varchar(255), + delete_proc varchar(255), + param_order tinyint not null, + expect_return tinyint not null +); + +drop table if exists ldap_entries; +create table ldap_entries + ( + id integer unsigned not null primary key auto_increment, + dn varchar(255) not null, + oc_map_id integer unsigned not null references ldap_oc_mappings(id), + parent int NOT NULL , + keyval int NOT NULL +); + +alter table ldap_entries add + constraint unq1_ldap_entries unique + ( + oc_map_id, + keyval + ); + +alter table ldap_entries add + constraint unq2_ldap_entries unique + ( + 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 + ( + entry_id integer not null references ldap_entries(id), + oc_name varchar(64) + ); + diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/backsql_drop.sql b/servers/slapd/back-sql/rdbms_depend/mysql/backsql_drop.sql new file mode 100644 index 0000000000..b497eb9d54 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mysql/backsql_drop.sql @@ -0,0 +1,9 @@ +DROP TABLE IF EXISTS ldap_referrals; + +DROP TABLE IF EXISTS ldap_entry_objclasses; + +DROP TABLE IF EXISTS ldap_attr_mappings; + +DROP TABLE IF EXISTS ldap_entries; + +DROP TABLE IF EXISTS ldap_oc_mappings; diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/create.sql b/servers/slapd/back-sql/rdbms_depend/mysql/create.sql deleted file mode 100644 index 964b310e97..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mysql/create.sql +++ /dev/null @@ -1,53 +0,0 @@ -CREATE TABLE ldap_attrs ( - id int NOT NULL PRIMARY KEY AUTO_INCREMENT, - oc_id int NOT NULL, - name varchar(255) NOT NULL, - sel_expr varchar(255) NOT NULL, - from_tbls varchar(255) NOT NULL, - join_where varchar(255), - add_proc varchar(255), - modify_proc varchar(255), - delete_proc varchar(255), - param_order tinyint NOT NULL, - expect_return tinyint NOT NULL -); - - -CREATE TABLE ldap_entries ( - id int NOT NULL PRIMARY KEY AUTO_INCREMENT, - dn varchar(255) NOT NULL , - objclass int NOT NULL , - parent int NOT NULL , - keyval int NOT NULL -); - - -CREATE TABLE ldap_objclasses ( - id int NOT NULL PRIMARY KEY AUTO_INCREMENT, - name varchar(64) NOT NULL , - keytbl varchar(64) NOT NULL , - keycol varchar(64) NOT NULL , - create_proc varchar(255), - delete_proc varchar(255), - expect_return tinyint NOT NULL -); - -ALTER TABLE ldap_entries ADD - CONSTRAINT UNQ1_ldap_entries UNIQUE - ( - objclass, - keyval - ); - -ALTER TABLE ldap_entries ADD - CONSTRAINT UNQ2_ldap_entries UNIQUE - ( - dn - ); - - -ALTER TABLE ldap_objclasses ADD - CONSTRAINT UNQ_ldap_objclasses UNIQUE - ( - name - ); diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/create_testdb.sql b/servers/slapd/back-sql/rdbms_depend/mysql/create_testdb.sql deleted file mode 100644 index c122ffae78..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mysql/create_testdb.sql +++ /dev/null @@ -1,61 +0,0 @@ -CREATE TABLE persons ( - id int NOT NULL, - name varchar(255) NOT NULL -); - -CREATE TABLE institutes ( - id int NOT NULL, - name varchar(255) -); - -CREATE TABLE documents ( - id int NOT NULL, - title varchar(255) NOT NULL, - abstract varchar(255) -); - -CREATE TABLE authors_docs ( - pers_id int NOT NULL, - doc_id int NOT NULL -); - -CREATE TABLE phones ( - id int NOT NULL , - phone varchar(255) NOT NULL , - pers_id int NOT NULL -); - - - -ALTER TABLE authors_docs ADD - CONSTRAINT PK_authors_docs PRIMARY KEY - ( - pers_id, - doc_id - ); - -ALTER TABLE documents ADD - CONSTRAINT PK_documents PRIMARY KEY - ( - id - ); - -ALTER TABLE institutes ADD - CONSTRAINT PK_institutes PRIMARY KEY - ( - id - ); - - -ALTER TABLE persons ADD - CONSTRAINT PK_persons PRIMARY KEY - ( - id - ); - -ALTER TABLE phones ADD - CONSTRAINT PK_phones PRIMARY KEY - ( - id - ); - diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/drop.sql b/servers/slapd/back-sql/rdbms_depend/mysql/drop.sql deleted file mode 100644 index 95bd287eae..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mysql/drop.sql +++ /dev/null @@ -1,5 +0,0 @@ -DROP TABLE IF EXISTS ldap_attrs; - -DROP TABLE IF EXISTS ldap_entries; - -DROP TABLE IF EXISTS ldap_objclasses; diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/drop_testdb.sql b/servers/slapd/back-sql/rdbms_depend/mysql/drop_testdb.sql deleted file mode 100644 index 7c5e9e759e..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mysql/drop_testdb.sql +++ /dev/null @@ -1,5 +0,0 @@ -DROP TABLE IF EXISTS persons; -DROP TABLE IF EXISTS institutes; -DROP TABLE IF EXISTS documents; -DROP TABLE IF EXISTS authors_docs; -DROP TABLE IF EXISTS phones; diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/slapd.conf b/servers/slapd/back-sql/rdbms_depend/mysql/slapd.conf index ba5a823216..3157628b5f 100644 --- a/servers/slapd/back-sql/rdbms_depend/mysql/slapd.conf +++ b/servers/slapd/back-sql/rdbms_depend/mysql/slapd.conf @@ -3,8 +3,9 @@ # See slapd.conf(5) for details on configuration options. # This file should NOT be world readable. # -include /usr/local/etc/openldap/slapd.at.conf -include /usr/local/etc/openldap/slapd.oc.conf +include /usr/local/etc/openldap/schema/core.schema +include /usr/local/etc/openldap/schema/cosine.schema +include /usr/local/etc/openldap/schema/inetorgperson.schema # Define global ACLs to disable default read access. @@ -16,7 +17,7 @@ pidfile /usr/local/var/slapd.pid argsfile /usr/local/var/slapd.args ####################################################################### -# ldbm database definitions +# sql database definitions ####################################################################### database sql @@ -27,4 +28,4 @@ dbname ldap_mysql dbuser root dbpasswd subtree_cond "ldap_entries.dn LIKE CONCAT('%',?)" -insentry_query "INSERT INTO ldap_entries (dn,objclass,parent,keyval) VALUES (?,?,?,?)" +insentry_query "INSERT INTO ldap_entries (dn,oc_map_id,parent,keyval) VALUES (?,?,?,?)" diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/test_data.sql b/servers/slapd/back-sql/rdbms_depend/mysql/test_data.sql deleted file mode 100644 index e436c5079d..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mysql/test_data.sql +++ /dev/null @@ -1,34 +0,0 @@ -insert into institutes (id,name) values (1,'sql'); - -insert into persons (id,name) values (1,'Mitya Kovalev'); -insert into persons (id,name) values (2,'Torvlobnor Puzdoy'); -insert into persons (id,name) values (3,'Akakiy Zinberstein'); - -insert into phones (id,phone,pers_id) values (1,'332-2334',1); -insert into phones (id,phone,pers_id) values (2,'222-3234',1); -insert into phones (id,phone,pers_id) values (3,'545-4563',2); - -insert into documents (id,abstract,title) values (1,'abstract1','book1'); -insert into documents (id,abstract,title) values (2,'abstract2','book2'); - -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 ldap_entries (id,dn,objclass,parent,keyval) -values (1,'o=sql,c=RU',3,0,1); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (2,'cn=Mitya Kovalev,o=sql,c=RU',1,1,1); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (3,'cn=Torvlobnor Puzdoy,o=sql,c=RU',1,1,2); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (4,'cn=Akakiy Zinberstein,o=sql,c=RU',1,1,3); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (5,'documentTitle=book1,o=sql,c=RU',2,1,1); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (6,'documentTitle=book2,o=sql,c=RU',2,1,2); diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/test_metadata.sql b/servers/slapd/back-sql/rdbms_depend/mysql/test_metadata.sql deleted file mode 100644 index ccf23dc84e..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/mysql/test_metadata.sql +++ /dev/null @@ -1,43 +0,0 @@ -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (1,'person','persons','id',"insert into persons (name) values ('');\n select last_insert_id();",NULL,0); - -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (2,'document','documents','id',NULL,NULL,0); - -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (3,'organization','institutes','id',NULL,NULL,0); - - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (1,1,'cn','persons.name','persons',NULL,NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (2,1,'telephoneNumber','phones.phone','persons,phones', - 'phones.pers_id=persons.id',NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (3,1,'sn','persons.name','persons',NULL,NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (4,2,'abstract','documents.abstract','documents',NULL,NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (5,2,'documentTitle','documents.title','documents',NULL,NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (6,2,'documentAuthor','persons.name','persons,documents,authors_docs', - 'persons.id=authors_docs.pers_id AND documents.id=authors_docs.doc_id', - NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (7,3,'o','institutes.name','institutes',NULL,NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', - 'ldap_entries.keyval=documents.id AND ldap_entries.objclass=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', - NULL,NULL,NULL,3,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (9,2,'authorDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', - 'ldap_entries.keyval=persons.id AND ldap_entries.objclass=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', - NULL,NULL,NULL,3,0); diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_create.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_create.sql new file mode 100644 index 0000000000..9fb97416f9 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_create.sql @@ -0,0 +1,66 @@ +drop table if exists persons; +CREATE TABLE persons ( + id int NOT NULL, + name varchar(255) NOT NULL +); + +drop table if exists institutes; +CREATE TABLE institutes ( + id int NOT NULL, + name varchar(255) +); + +drop table if exists documents; +CREATE TABLE documents ( + id int NOT NULL, + title varchar(255) NOT NULL, + abstract varchar(255) +); + +drop table if exists authors_docs; +CREATE TABLE authors_docs ( + pers_id int NOT NULL, + doc_id int NOT NULL +); + +drop table if exists phones; +CREATE TABLE phones ( + id int NOT NULL , + phone varchar(255) NOT NULL , + pers_id int NOT NULL +); + + + +ALTER TABLE authors_docs ADD + CONSTRAINT PK_authors_docs PRIMARY KEY + ( + pers_id, + doc_id + ); + +ALTER TABLE documents ADD + CONSTRAINT PK_documents PRIMARY KEY + ( + id + ); + +ALTER TABLE institutes ADD + CONSTRAINT PK_institutes PRIMARY KEY + ( + id + ); + + +ALTER TABLE persons ADD + CONSTRAINT PK_persons PRIMARY KEY + ( + id + ); + +ALTER TABLE phones ADD + CONSTRAINT PK_phones PRIMARY KEY + ( + id + ); + diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql new file mode 100644 index 0000000000..f141f414eb --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql @@ -0,0 +1,16 @@ +insert into institutes (id,name) values (1,'sql'); + +insert into persons (id,name) values (1,'Mitya Kovalev'); +insert into persons (id,name) values (2,'Torvlobnor Puzdoy'); +insert into persons (id,name) values (3,'Akakiy Zinberstein'); + +insert into phones (id,phone,pers_id) values (1,'332-2334',1); +insert into phones (id,phone,pers_id) values (2,'222-3234',1); +insert into phones (id,phone,pers_id) values (3,'545-4563',2); + +insert into documents (id,abstract,title) values (1,'abstract1','book1'); +insert into documents (id,abstract,title) values (2,'abstract2','book2'); + +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); diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_drop.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_drop.sql new file mode 100644 index 0000000000..7c5e9e759e --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_drop.sql @@ -0,0 +1,5 @@ +DROP TABLE IF EXISTS persons; +DROP TABLE IF EXISTS institutes; +DROP TABLE IF EXISTS documents; +DROP TABLE IF EXISTS authors_docs; +DROP TABLE IF EXISTS phones; diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/backsql_create.sql b/servers/slapd/back-sql/rdbms_depend/oracle/backsql_create.sql new file mode 100644 index 0000000000..e88284bba8 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/oracle/backsql_create.sql @@ -0,0 +1,86 @@ +create table ldap_oc_mappings ( + id number not null , + name varchar2(64) not null , + keytbl varchar2(64) not null , + keycol varchar2(64) not null , + create_proc varchar2(255), + delete_proc varchar2(255), + expect_return number not null +); + +alter table ldap_oc_mappings add + constraint PK_ldap_oc_mappings primary key + ( + id + ); + +alter table ldap_oc_mappings add + constraint unq_ldap_oc_mappings unique + ( + name + ); + +create table ldap_attr_mappings ( + id number not null, + oc_map_id number not null references ldap_oc_mappings(id), + name varchar2(255) not null, + sel_expr varchar2(255) not null, + from_tbls varchar2(255) not null, + join_where varchar2(255), + add_proc varchar2(255), + delete_proc varchar2(255), + param_order number not null, + expect_return number not null +); + +alter table ldap_attr_mappings add + constraint pk_ldap_attr_mappings primary key + ( + id + ); + + +create table ldap_entries ( + id number not null , + dn varchar2(255) not null , + oc_map_id number not null references ldap_oc_mappings(id), + parent number not null , + keyval number not null +); + +alter table ldap_entries add + constraint PK_ldap_entries primary key + ( + id + ); + +alter table ldap_entries add + constraint unq1_ldap_entries unique + ( + oc_map_id, + keyval + ); + +alter table ldap_entries add + constraint unq2_ldap_entries unique + ( + dn + ); + +create sequence ldap_objclass_ids start with 1 increment by 1; + +create sequence ldap_attr_ids start with 1 increment by 1; + +create sequence ldap_entry_ids start with 1 increment by 1; + +create table ldap_referrals + ( + entry_id number not null references ldap_entries(id), + url varchar(1023) not null +); + +create table ldap_entry_objclasses + ( + entry_id number not null references ldap_entries(id), + oc_name varchar(64) + ); diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/backsql_drop.sql b/servers/slapd/back-sql/rdbms_depend/oracle/backsql_drop.sql new file mode 100644 index 0000000000..19bb8b66cc --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/oracle/backsql_drop.sql @@ -0,0 +1,8 @@ +drop table ldap_attr_mappings; +drop table ldap_entry_objclasses; +drop table ldap_referrals; +drop sequence ldap_entry_ids; +drop sequence ldap_attr_ids; +drop sequence ldap_objclass_ids; +drop table ldap_entries; +drop table ldap_oc_mappings; diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/create.sql b/servers/slapd/back-sql/rdbms_depend/oracle/create.sql deleted file mode 100644 index 0d968e1a76..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/oracle/create.sql +++ /dev/null @@ -1,79 +0,0 @@ -CREATE TABLE ldap_attrs ( - id NUMBER NOT NULL, - oc_id NUMBER NOT NULL, - name varchar2(255) NOT NULL, - sel_expr varchar2(255) NOT NULL, - from_tbls varchar2(255) NOT NULL, - join_where varchar2(255), - add_proc varchar2(255), - modify_proc varchar2(255), - delete_proc varchar2(255), - param_order NUMBER NOT NULL, - expect_return NUMBER NOT NULL -); - - -CREATE TABLE ldap_entries ( - id NUMBER NOT NULL , - dn varchar2(255) NOT NULL , - objclass NUMBER NOT NULL , - parent NUMBER NOT NULL , - keyval NUMBER NOT NULL -); - - -CREATE TABLE ldap_objclasses ( - id NUMBER NOT NULL , - name varchar2(64) NOT NULL , - keytbl varchar2(64) NOT NULL , - keycol varchar2(64) NOT NULL , - create_proc varchar2(255), - delete_proc varchar2(255), - expect_return NUMBER NOT NULL -); - - -ALTER TABLE ldap_attrs ADD - CONSTRAINT PK_ldap_attrs PRIMARY KEY - ( - id - ); - -ALTER TABLE ldap_entries ADD - CONSTRAINT PK_ldap_entries PRIMARY KEY - ( - id - ); - -ALTER TABLE ldap_objclasses ADD - CONSTRAINT PK_ldap_objclasses PRIMARY KEY - ( - id - ); - -ALTER TABLE ldap_entries ADD - CONSTRAINT UNQ1_ldap_entries UNIQUE - ( - objclass, - keyval - ); - -ALTER TABLE ldap_entries ADD - CONSTRAINT UNQ2_ldap_entries UNIQUE - ( - dn - ); - - -ALTER TABLE ldap_objclasses ADD - CONSTRAINT UNQ_ldap_objclasses UNIQUE - ( - name - ); - - -CREATE SEQUENCE ldap_objclass_ids START WITH 1 INCREMENT BY 1; - -CREATE SEQUENCE ldap_attr_ids START WITH 1 INCREMENT BY 1; - -CREATE SEQUENCE ldap_entry_ids START WITH 1 INCREMENT BY 1; diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/create_testdb.sql b/servers/slapd/back-sql/rdbms_depend/oracle/create_testdb.sql deleted file mode 100644 index 36ac2373b6..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/oracle/create_testdb.sql +++ /dev/null @@ -1,198 +0,0 @@ -CREATE TABLE persons ( - id NUMBER NOT NULL, - name varchar2(255) NOT NULL -); - -CREATE TABLE institutes ( - id NUMBER NOT NULL, - name varchar2(255) -); - -CREATE TABLE documents ( - id NUMBER NOT NULL, - title varchar2(255) NOT NULL, - abstract varchar2(255) -); - -CREATE TABLE authors_docs ( - pers_id NUMBER NOT NULL, - doc_id NUMBER NOT NULL -); - -CREATE TABLE phones ( - id NUMBER NOT NULL , - phone varchar2(255) NOT NULL , - pers_id NUMBER NOT NULL -); - - -ALTER TABLE authors_docs ADD - CONSTRAINT PK_authors_docs PRIMARY KEY - ( - pers_id, - doc_id - ); - -ALTER TABLE documents ADD - CONSTRAINT PK_documents PRIMARY KEY - ( - id - ); - -ALTER TABLE institutes ADD - CONSTRAINT PK_institutes PRIMARY KEY - ( - id - ); - -ALTER TABLE persons ADD - CONSTRAINT PK_persons PRIMARY KEY - ( - id - ); - -ALTER TABLE phones ADD - CONSTRAINT PK_phones PRIMARY KEY - ( - id - ); - -CREATE SEQUENCE person_ids START WITH 1 INCREMENT BY 1; - -CREATE SEQUENCE document_ids START WITH 1 INCREMENT BY 1; - -CREATE SEQUENCE institute_ids START WITH 1 INCREMENT BY 1; - -CREATE SEQUENCE phone_ids START WITH 1 INCREMENT BY 1; - -CREATE OR REPLACE PROCEDURE create_person(keyval OUT NUMBER) AS -BEGIN -INSERT INTO persons (id,name) VALUES (person_ids.nextval,' '); -SELECT person_ids.currval INTO keyval FROM DUAL; -END; -/ - -CREATE OR REPLACE PROCEDURE delete_person(keyval IN NUMBER) AS -BEGIN -DELETE FROM phones WHERE pers_id=keyval; -DELETE FROM authors_docs WHERE pers_id=keyval; -DELETE FROM persons WHERE id=keyval; -END; -/ - -CREATE OR REPLACE PROCEDURE create_org(keyval OUT NUMBER) AS -BEGIN -INSERT INTO institutes (id,name) VALUES (institute_ids.nextval,' '); -SELECT institute_ids.currval INTO keyval FROM DUAL; -END; -/ - -CREATE OR REPLACE PROCEDURE delete_org(keyval IN NUMBER) AS -BEGIN -DELETE FROM institutes WHERE id=keyval; -END; -/ - -CREATE OR REPLACE PROCEDURE create_document(keyval OUT NUMBER) AS -BEGIN -INSERT INTO documents (id,title) VALUES (document_ids.nextval,' '); -SELECT document_ids.currval INTO keyval FROM DUAL; -END; -/ - -CREATE OR REPLACE PROCEDURE delete_document (keyval IN NUMBER) AS -BEGIN -DELETE FROM authors_docs WHERE doc_id=keyval; -DELETE FROM documents WHERE id=keyval; -END; -/ - -CREATE OR REPLACE PROCEDURE add_phone(pers_id IN NUMBER, phone IN varchar2) AS -BEGIN -INSERT INTO phones (id,pers_id,phone) VALUES (phone_ids.nextval,pers_id,phone); -END; -/ - -CREATE OR REPLACE PROCEDURE delete_phone(keyval IN NUMBER, phone IN varchar2) AS -BEGIN -DELETE FROM phones WHERE pers_id=keyval AND phone=phone; -END; -/ - -CREATE OR REPLACE PROCEDURE set_person_name(keyval IN NUMBER, new_name IN varchar2) AS -BEGIN -UPDATE persons SET name=new_name WHERE id=keyval; -END; -/ - -CREATE OR REPLACE PROCEDURE set_org_name(keyval IN NUMBER, new_name IN varchar2) AS -BEGIN -UPDATE institutes SET name=new_name WHERE id=keyval; -END; -/ - -CREATE OR REPLACE PROCEDURE set_doc_title (keyval IN NUMBER, new_title IN varchar2) AS -BEGIN -UPDATE documents SET title=new_title WHERE id=keyval; -END; -/ - -CREATE OR REPLACE PROCEDURE set_doc_abstract (keyval IN NUMBER, new_abstract IN varchar2) AS -BEGIN -UPDATE documents SET abstract=new_abstract WHERE id=keyval; -END; -/ - -CREATE OR REPLACE FUNCTION make_author_link (keyval IN NUMBER, author_dn IN varchar2) RETURN NUMBER AS -per_id NUMBER; -BEGIN -SELECT keyval INTO per_id FROM ldap_entries - WHERE objclass=1 AND dn=author_dn; -IF NOT (per_id IS NULL) THEN - INSERT INTO authors_docs (doc_id,pers_id) VALUES (keyval,per_id); - RETURN 1; -END IF; -RETURN 0; -END; -/ - -CREATE OR REPLACE FUNCTION make_doc_link (keyval IN NUMBER, doc_dn IN varchar2) RETURN NUMBER AS -docid NUMBER; -BEGIN -SELECT keyval INTO docid FROM ldap_entries - WHERE objclass=2 AND dn=doc_dn; -IF NOT (docid IS NULL) THEN - INSERT INTO authors_docs (pers_id,doc_id) VALUES (keyval,docid); - RETURN 1; -END IF; -RETURN 0; -END; -/ - -CREATE OR REPLACE FUNCTION del_doc_link (keyval IN NUMBER, doc_dn IN varchar2) RETURN NUMBER AS -docid NUMBER; -BEGIN -SELECT keyval INTO docid FROM ldap_entries - WHERE objclass=2 AND dn=doc_dn; -IF NOT (docid IS NULL) THEN - DELETE FROM authors_docs WHERE pers_id=keyval AND doc_id=docid; - RETURN 1; -END IF; -RETURN 0; -END; -/ - -CREATE OR REPLACE FUNCTION del_author_link (keyval IN NUMBER, author_dn IN varchar2) RETURN NUMBER AS -per_id NUMBER; -BEGIN -SELECT keyval INTO per_id FROM ldap_entries - WHERE objclass=1 AND dn=author_dn; - -IF NOT (per_id IS NULL) THEN - DELETE FROM authors_docs WHERE doc_id=keyval AND pers_id=per_id; - RETURN 1; -END IF; - RETURN 0; -END; -/ - diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/drop.sql b/servers/slapd/back-sql/rdbms_depend/oracle/drop.sql deleted file mode 100644 index d008937563..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/oracle/drop.sql +++ /dev/null @@ -1,7 +0,0 @@ -DROP TABLE ldap_attrs; -DROP TABLE ldap_entries; -DROP TABLE ldap_objclasses; -DROP SEQUENCE ldap_entry_ids; -DROP SEQUENCE ldap_attr_ids; -DROP SEQUENCE ldap_objclass_ids; - diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/drop_testdb.sql b/servers/slapd/back-sql/rdbms_depend/oracle/drop_testdb.sql deleted file mode 100644 index 0cf44637be..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/oracle/drop_testdb.sql +++ /dev/null @@ -1,25 +0,0 @@ -DROP TABLE persons; -DROP TABLE institutes; -DROP TABLE documents; -DROP TABLE authors_docs; -DROP TABLE phones; -DROP SEQUENCE person_ids; -DROP SEQUENCE institute_ids; -DROP SEQUENCE document_ids; -DROP SEQUENCE phone_ids; -DROP PROCEDURE create_person; -DROP PROCEDURE delete_person; -DROP PROCEDURE add_phone; -DROP PROCEDURE delete_phone; -DROP PROCEDURE set_person_name; -DROP PROCEDURE set_org_name; -DROP PROCEDURE set_doc_title; -DROP PROCEDURE set_doc_abstract; -DROP PROCEDURE create_document; -DROP PROCEDURE create_org; -DROP PROCEDURE delete_document; -DROP PROCEDURE delete_org; -DROP PROCEDURE make_doc_link; -DROP PROCEDURE del_doc_link; -DROP PROCEDURE make_author_link; -DROP PROCEDURE del_author_link; diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/slapd.conf b/servers/slapd/back-sql/rdbms_depend/oracle/slapd.conf index bb7ba453be..e94368237a 100644 --- a/servers/slapd/back-sql/rdbms_depend/oracle/slapd.conf +++ b/servers/slapd/back-sql/rdbms_depend/oracle/slapd.conf @@ -3,8 +3,9 @@ # See slapd.conf(5) for details on configuration options. # This file should NOT be world readable. # -include ./slapd.at.conf -include ./slapd.oc.conf +include /usr/local/etc/openldap/schema/core.schema +include /usr/local/etc/openldap/schema/cosine.schema +include /usr/local/etc/openldap/schema/inetorgperson.schema # Define global ACLs to disable default read access. @@ -12,31 +13,20 @@ include ./slapd.oc.conf # service AND an understanding of referrals. #referral ldap://root.openldap.org -pidfile ./slapd.pid -argsfile ./slapd.args +pidfile /usr/local/var/slapd.pid +argsfile /usr/local/var/slapd.args ####################################################################### -# ldbm database definitions +# sql database definitions ####################################################################### -#database ldbm -#suffix "dc=your-domain, dc=com" -#suffix "o=Your Organization Name, c=US" -#directory /usr/tmp -#rootdn "cn=root, dc=your-domain, dc=com" -#rootdn "cn=root, o=Your Organization Name, c=US" -#rootpw secret -# cleartext passwords, especially for the rootdn, should -# be avoid. See slapd.conf(5) for details. - database sql suffix "o=sql,c=RU" rootdn "cn=root,o=sql,c=RU" rootpw secret -#dbname ldap_ora8_ms dbname ldap_ora8 dbuser ldap dbpasswd ldap subtree_cond "UPPER(ldap_entries.dn) LIKE CONCAT('%',UPPER(?))" -insentry_query "INSERT INTO ldap_entries (id,dn,objclass,parent,keyval) VALUES (ldap_entry_ids.nextval,?,?,?,?)" +insentry_query "INSERT INTO ldap_entries (id,dn,oc_map_id,parent,keyval) VALUES (ldap_entry_ids.nextval,?,?,?,?)" upper_func UPPER diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/test_data.sql b/servers/slapd/back-sql/rdbms_depend/oracle/test_data.sql deleted file mode 100644 index 33d6b9f4a2..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/oracle/test_data.sql +++ /dev/null @@ -1,45 +0,0 @@ -insert into institutes (id,name) values (institute_ids.nextval,'sql'); - -insert into persons (id,name) values (person_ids.nextval,'Mitya Kovalev'); - -insert into persons (id,name) values (person_ids.nextval,'Torvlobnor Puzdoy'); - -insert into persons (id,name) values (person_ids.nextval,'Akakiy Zinberstein'); - - -insert into phones (id,phone,pers_id) values (phone_ids.nextval,'332-2334',1); - -insert into phones (id,phone,pers_id) values (phone_ids.nextval,'222-3234',1); - -insert into phones (id,phone,pers_id) values (phone_ids.nextval,'545-4563',2); - - -insert into documents (id,abstract,title) values (document_ids.nextval,'abstract1','book1'); - -insert into documents (id,abstract,title) values (document_ids.nextval,'abstract2','book2'); - - -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 ldap_entries (id,dn,objclass,parent,keyval) -values (ldap_entry_ids.nextval,'o=sql,c=RU',3,0,1); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (ldap_entry_ids.nextval,'cn=Mitya Kovalev,o=sql,c=RU',1,1,1); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (ldap_entry_ids.nextval,'cn=Torvlobnor Puzdoy,o=sql,c=RU',1,1,2); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (ldap_entry_ids.nextval,'cn=Akakiy Zinberstein,o=sql,c=RU',1,1,3); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (ldap_entry_ids.nextval,'documentTitle=book1,o=sql,c=RU',2,1,1); - -insert into ldap_entries (id,dn,objclass,parent,keyval) -values (ldap_entry_ids.nextval,'documentTitle=book2,o=sql,c=RU',2,1,2); diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/test_metadata.sql b/servers/slapd/back-sql/rdbms_depend/oracle/test_metadata.sql deleted file mode 100644 index 0d44ee0a6f..0000000000 --- a/servers/slapd/back-sql/rdbms_depend/oracle/test_metadata.sql +++ /dev/null @@ -1,49 +0,0 @@ -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (1,'person','persons','id','{call create_person(?)}','{call delete_person(?)}',0); - -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (2,'document','documents','id','{call create_document(?)}','{call delete_document(?)}',0); - -insert into ldap_objclasses (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) -values (3,'organization','institutes','id','{call create_org(?)}','{call delete_org(?)}',0); - - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (1,1,'cn','persons.name','persons',NULL,'{call set_person_name(?,?)}', - NULL,NULL,0,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (2,1,'telephoneNumber','phones.phone','persons,phones', - 'phones.pers_id=persons.id','{call add_phone(?,?)}', - NULL,'{call delete_phone(?,?)}',0,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (3,1,'sn','persons.name','persons',NULL,'{call set_person_name(?,?)}', - NULL,NULL,0,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (4,2,'abstract','documents.abstract','documents',NULL,'{call set_doc_abstract(?,?)}', - NULL,NULL,0,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (5,2,'documentTitle','documents.title','documents',NULL,'{call set_doc_title(?,?)}', - NULL,NULL,0,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (6,2,'documentAuthor','persons.name','persons,documents,authors_docs', - 'persons.id=authors_docs.pers_id AND documents.id=authors_docs.doc_id', - NULL,NULL,NULL,0,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (7,3,'o','institutes.name','institutes',NULL,'{call set_org_name(?,?)}', - NULL,NULL,0,0); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', - 'ldap_entries.keyval=documents.id AND ldap_entries.objclass=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', - '{?=call make_doc_link(?,?)}',NULL,'{?=call del_doc_link(?,?)}',0,3); - -insert into ldap_attrs (id,oc_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) -values (9,2,'authorDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', - 'ldap_entries.keyval=persons.id AND ldap_entries.objclass=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', - '{?=call make_author_link(?,?)}',NULL,'{?=call del_author_link(?,?)}',0,3); diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/testdb_create.sql b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_create.sql new file mode 100644 index 0000000000..36859d1b76 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_create.sql @@ -0,0 +1,66 @@ +CREATE TABLE persons ( + id NUMBER NOT NULL, + name varchar2(255) NOT NULL +); + +CREATE TABLE institutes ( + id NUMBER NOT NULL, + name varchar2(255) +); + +CREATE TABLE documents ( + id NUMBER NOT NULL, + title varchar2(255) NOT NULL, + abstract varchar2(255) +); + +CREATE TABLE authors_docs ( + pers_id NUMBER NOT NULL, + doc_id NUMBER NOT NULL +); + +CREATE TABLE phones ( + id NUMBER NOT NULL , + phone varchar2(255) NOT NULL , + pers_id NUMBER NOT NULL +); + + +ALTER TABLE authors_docs ADD + CONSTRAINT PK_authors_docs PRIMARY KEY + ( + pers_id, + doc_id + ); + +ALTER TABLE documents ADD + CONSTRAINT PK_documents PRIMARY KEY + ( + id + ); + +ALTER TABLE institutes ADD + CONSTRAINT PK_institutes PRIMARY KEY + ( + id + ); + +ALTER TABLE persons ADD + CONSTRAINT PK_persons PRIMARY KEY + ( + id + ); + +ALTER TABLE phones ADD + CONSTRAINT PK_phones PRIMARY KEY + ( + id + ); + +CREATE SEQUENCE person_ids START WITH 1 INCREMENT BY 1; + +CREATE SEQUENCE document_ids START WITH 1 INCREMENT BY 1; + +CREATE SEQUENCE institute_ids START WITH 1 INCREMENT BY 1; + +CREATE SEQUENCE phone_ids START WITH 1 INCREMENT BY 1; diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/testdb_data.sql b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_data.sql new file mode 100644 index 0000000000..439bacca3b --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_data.sql @@ -0,0 +1,27 @@ +insert into institutes (id,name) values (institute_ids.nextval,'sql'); + +insert into persons (id,name) values (person_ids.nextval,'Mitya Kovalev'); + +insert into persons (id,name) values (person_ids.nextval,'Torvlobnor Puzdoy'); + +insert into persons (id,name) values (person_ids.nextval,'Akakiy Zinberstein'); + + +insert into phones (id,phone,pers_id) values (phone_ids.nextval,'332-2334',1); + +insert into phones (id,phone,pers_id) values (phone_ids.nextval,'222-3234',1); + +insert into phones (id,phone,pers_id) values (phone_ids.nextval,'545-4563',2); + + +insert into documents (id,abstract,title) values (document_ids.nextval,'abstract1','book1'); + +insert into documents (id,abstract,title) values (document_ids.nextval,'abstract2','book2'); + + +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); + diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/testdb_drop.sql b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_drop.sql new file mode 100644 index 0000000000..0cf44637be --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_drop.sql @@ -0,0 +1,25 @@ +DROP TABLE persons; +DROP TABLE institutes; +DROP TABLE documents; +DROP TABLE authors_docs; +DROP TABLE phones; +DROP SEQUENCE person_ids; +DROP SEQUENCE institute_ids; +DROP SEQUENCE document_ids; +DROP SEQUENCE phone_ids; +DROP PROCEDURE create_person; +DROP PROCEDURE delete_person; +DROP PROCEDURE add_phone; +DROP PROCEDURE delete_phone; +DROP PROCEDURE set_person_name; +DROP PROCEDURE set_org_name; +DROP PROCEDURE set_doc_title; +DROP PROCEDURE set_doc_abstract; +DROP PROCEDURE create_document; +DROP PROCEDURE create_org; +DROP PROCEDURE delete_document; +DROP PROCEDURE delete_org; +DROP PROCEDURE make_doc_link; +DROP PROCEDURE del_doc_link; +DROP PROCEDURE make_author_link; +DROP PROCEDURE del_author_link; diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index ed5f0692c7..3e59874a3b 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -41,6 +41,67 @@ int backsql_cmp_attr(backsql_at_map_rec *m1,backsql_at_map_rec *m2) return strcasecmp(m1->name,m2->name); } +char* backsql_make_attr_query(backsql_oc_map_rec *oc_map,backsql_at_map_rec *at_map) +{ + char *tmps; + int tmpslen; + + tmps=NULL;tmpslen=0; + tmps=backsql_strcat(tmps,&tmpslen,"SELECT ",at_map->sel_expr," AS ",at_map->name, + " FROM ",at_map->from_tbls, + " WHERE ",oc_map->keytbl,".",oc_map->keycol,"=?",NULL); + if (at_map->join_where!=NULL && at_map->join_where[0]!='\0') + tmps=backsql_strcat(tmps,&tmpslen," AND ",at_map->join_where,NULL); + at_map->query=ch_strdup(tmps); + ch_free(tmps); + return at_map->query; +} + + +int backsql_add_sysmaps(backsql_oc_map_rec *oc_map) +{ + backsql_at_map_rec *at_map; + long len; + char s[30]; + + sprintf(s,"%d",oc_map->id); + at_map=(backsql_at_map_rec*)ch_calloc(1,sizeof(backsql_at_map_rec)); + at_map->name=ch_strdup("objectClass"); + at_map->sel_expr=ch_strdup("ldap_entry_objclasses.oc_name"); + at_map->from_tbls=ch_strdup("ldap_entry_objclasses,ldap_entries"); + len=strlen(at_map->from_tbls); + backsql_merge_from_clause(&at_map->from_tbls,&len,oc_map->keytbl); + at_map->join_where=NULL; len=0; + at_map->join_where=backsql_strcat(at_map->join_where,&len, + "ldap_entries.id=ldap_entry_objclasses.entry_id and ldap_entries.keyval=", + oc_map->keytbl,".",oc_map->keycol," and ldap_entries.oc_map_id=",s,NULL); + at_map->add_proc=NULL; + at_map->delete_proc=NULL; + at_map->param_order=0; + at_map->expect_return=0; + backsql_make_attr_query(oc_map,at_map); + avl_insert(&oc_map->attrs,at_map,(AVL_CMP)backsql_cmp_attr,backsql_dummy); + + at_map=(backsql_at_map_rec*)ch_calloc(1,sizeof(backsql_at_map_rec)); + at_map->name=ch_strdup("ref"); + at_map->sel_expr=ch_strdup("ldap_referrals.url"); + at_map->from_tbls=ch_strdup("ldap_referrals,ldap_entries"); + len=strlen(at_map->from_tbls); + backsql_merge_from_clause(&at_map->from_tbls,&len,oc_map->keytbl); + at_map->join_where=NULL; len=0; + at_map->join_where=backsql_strcat(at_map->join_where,&len, + "ldap_entries.id=ldap_referrals.entry_id and ldap_entries.keyval=", + oc_map->keytbl,".",oc_map->keycol," and ldap_entries.oc_map_id=",s,NULL); + at_map->add_proc=NULL; + at_map->delete_proc=NULL; + at_map->param_order=0; + at_map->expect_return=0; + backsql_make_attr_query(oc_map,at_map); + avl_insert(&oc_map->attrs,at_map,(AVL_CMP)backsql_cmp_attr,backsql_dummy); + + return 1; +} + int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh) { SQLHSTMT oc_sth,at_sth; @@ -99,6 +160,8 @@ int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh) oc_map->name,oc_map->keytbl,oc_map->keycol); Debug(LDAP_DEBUG_TRACE,"create_proc='%s' delete_proc='%s' expect_return=%d; attributes:\n", oc_map->create_proc,oc_map->delete_proc,oc_map->expect_return); + Debug(LDAP_DEBUG_TRACE,"load_schema_map(): autoadding 'objectClass' and 'ref' mappings\n",0,0,0); + backsql_add_sysmaps(oc_map); if ((rc=SQLExecute(at_sth)) != SQL_SUCCESS) { Debug(LDAP_DEBUG_TRACE,"load_schema_map(): error executing at_query: \n",0,0,0); @@ -111,9 +174,9 @@ int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh) 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' modify_proc='%s' ",at_row.cols[3], - at_row.cols[4],at_row.cols[5]); - Debug(LDAP_DEBUG_TRACE,"delete_proc='%s'\n",at_row.cols[6],0,0); + 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); at_map=(backsql_at_map_rec*)ch_calloc(1,sizeof(backsql_at_map_rec)); at_map->name=ch_strdup(at_row.cols[0]); at_map->sel_expr=ch_strdup(at_row.cols[1]); @@ -123,18 +186,10 @@ int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh) ch_free(tmps); at_map->join_where=ch_strdup((at_row.is_null[3]<0)?"":at_row.cols[3]); at_map->add_proc=(at_row.is_null[4]<0)?NULL:ch_strdup(at_row.cols[4]); - at_map->modify_proc=(at_row.is_null[5]<0)?NULL:ch_strdup(at_row.cols[5]); - at_map->delete_proc=(at_row.is_null[6]<0)?NULL:ch_strdup(at_row.cols[6]); - at_map->param_order=atoi(at_row.cols[7]); - at_map->expect_return=atoi(at_row.cols[8]); - tmps=NULL;tmpslen=0; - tmps=backsql_strcat(tmps,&tmpslen,"SELECT ",at_map->sel_expr," AS ",at_map->name, - " FROM ",at_map->from_tbls, - " WHERE ",oc_map->keytbl,".",oc_map->keycol,"=?",NULL); - if (at_map->join_where!=NULL && at_map->join_where[0]!='\0') - tmps=backsql_strcat(tmps,&tmpslen," AND ",at_map->join_where,NULL); - at_map->query=ch_strdup(tmps); - ch_free(tmps); + at_map->delete_proc=(at_row.is_null[5]<0)?NULL:ch_strdup(at_row.cols[5]); + at_map->param_order=atoi(at_row.cols[6]); + at_map->expect_return=atoi(at_row.cols[7]); + backsql_make_attr_query(oc_map,at_map); Debug(LDAP_DEBUG_TRACE,"load_schema_map(): preconstructed query '%s'\n",at_map->query,0,0); avl_insert(&oc_map->attrs,at_map,(AVL_CMP)backsql_cmp_attr,backsql_dummy); } @@ -204,8 +259,6 @@ int backsql_free_attr(backsql_at_map_rec *at) ch_free(at->join_where); if (at->add_proc!=NULL) ch_free(at->add_proc); - if (at->modify_proc!=NULL) - ch_free(at->modify_proc); if (at->delete_proc!=NULL) ch_free(at->delete_proc); if (at->query) diff --git a/servers/slapd/back-sql/schema-map.h b/servers/slapd/back-sql/schema-map.h index 3d9830930c..6e48c36fbb 100644 --- a/servers/slapd/back-sql/schema-map.h +++ b/servers/slapd/back-sql/schema-map.h @@ -29,8 +29,7 @@ typedef struct char *from_tbls; char *join_where; char *sel_expr; - char *add_proc; //supposed to expect 2 binded values: entry keyval and attr. value to add, like "add_name(?,?)" - char *modify_proc; //supposed to expect two binded values: entry keyval and old and new values of attr + char *add_proc; //supposed to expect 2 binded values: entry keyval and attr. value to add, like "add_name(?,?,?)" char *delete_proc; //supposed to expect 2 binded values: entry keyval and attr. value to delete char *query; //for optimization purposes attribute load query is preconstructed from parts on schemamap load time //following flags are bitmasks (first bit used for add_proc, second - for modify, third - for delete_proc) diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 6bc9fefd90..e8b2d5800e 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -80,6 +80,8 @@ int backsql_process_filter_list(backsql_srch_info *bsi,Filter *f,int op) char *sub_clause=NULL; int len=0,res; + if (!f) + return 0; bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"(",NULL); while(1) { @@ -108,8 +110,10 @@ int backsql_process_filter_list(backsql_srch_info *bsi,Filter *f,int op) int backsql_process_sub_filter(backsql_srch_info *bsi,Filter *f) { int i; - - backsql_at_map_rec *at=backsql_at_with_name(bsi->oc,f->f_sub_type); + backsql_at_map_rec *at=backsql_at_with_name(bsi->oc,f->f_sub_desc->ad_cname->bv_val); + + if (!f) + return 0; bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"(",NULL); @@ -154,6 +158,11 @@ int backsql_process_filter(backsql_srch_info *bsi,Filter *f) int done=0,len=0; Debug(LDAP_DEBUG_TRACE,"==>backsql_process_filter()\n",0,0,0); + if (f==NULL) + { + return 0; + } + switch(f->f_choice) { case LDAP_FILTER_OR: @@ -171,10 +180,10 @@ int backsql_process_filter(backsql_srch_info *bsi,Filter *f) done=1; break; case LDAP_FILTER_PRESENT: - at_name=f->f_type; + at_name=f->f_desc->ad_cname->bv_val; break; default: - at_name=f->f_avtype; + at_name=f->f_av_desc->ad_cname->bv_val; break; } @@ -214,20 +223,22 @@ int backsql_process_filter(backsql_srch_info *bsi,Filter *f) //upper_func stuff is made for Oracle, where UPPER is //safely applicable to NUMBER etc. if (bsi->bi->upper_func) - bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"(", + bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"(", bsi->bi->upper_func,"(",at->sel_expr,")='", - f->f_avvalue.bv_val,"')",NULL); + f->f_av_value->bv_val,"')",NULL); else bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"(",at->sel_expr,"='", - f->f_avvalue.bv_val,"')",NULL); + f->f_av_value->bv_val,"')",NULL); + break; case LDAP_FILTER_GE: bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"(",at->sel_expr,">=", - f->f_avvalue.bv_val,")",NULL); + f->f_av_value->bv_val,")",NULL); + break; case LDAP_FILTER_LE: bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"(",at->sel_expr,"<=", - f->f_avvalue.bv_val,")",NULL); + f->f_av_value->bv_val,")",NULL); break; case LDAP_FILTER_PRESENT: bsi->flt_where=backsql_strcat(bsi->flt_where,&bsi->fwhere_len,"NOT (",at->sel_expr, @@ -265,7 +276,7 @@ char* backsql_srch_query(backsql_srch_info *bsi) bsi->from=backsql_strcat(bsi->from,&bsi->from_len," FROM ldap_entries,",bsi->oc->keytbl,NULL); bsi->join_where=backsql_strcat(bsi->join_where,&bsi->jwhere_len," WHERE ", bsi->oc->keytbl,".",bsi->oc->keycol,"=ldap_entries.keyval AND ", - "ldap_entries.objclass=? AND ",NULL); + "ldap_entries.oc_map_id=? AND ",NULL); switch(bsi->scope) { @@ -415,7 +426,7 @@ int backsql_search(BackendDB *be,Connection *conn,Operation *op, SQLHDBC dbh; int sres; int nentries; - Entry entry,*res; + Entry *entry,*res; int manageDSAit = get_manageDSAit( op ); struct berval **v2refs = NULL; time_t stoptime; @@ -490,7 +501,8 @@ int backsql_search(BackendDB *be,Connection *conn,Operation *op, Debug(LDAP_DEBUG_TRACE,"backsql_search(): loading data for entry id=%d, oc_id=%d, keyval=%d\n", eid->id,eid->oc_id,eid->keyval); - res=backsql_id2entry(&srch_info,&entry,eid); + entry=(Entry *)ch_calloc(sizeof(Entry),1); + res=backsql_id2entry(&srch_info,entry,eid); if (res==NULL) { Debug(LDAP_DEBUG_TRACE,"backsql_search(): error in backsql_id2entry() - skipping entry\n",0,0,0); @@ -498,24 +510,25 @@ int backsql_search(BackendDB *be,Connection *conn,Operation *op, } if ( !manageDSAit && scope != LDAP_SCOPE_BASE && - is_entry_referral( &entry ) ) + is_entry_referral( entry ) ) { - struct berval **refs = get_entry_referrals(be,conn,op,&entry); + struct berval **refs = get_entry_referrals(be,conn,op,entry); - send_search_reference( be, conn, op, &entry, refs, scope, NULL, &v2refs ); + send_search_reference( be, conn, op, entry, refs, scope, NULL, &v2refs ); ber_bvecfree( refs ); continue; } - // if (test_filter(be,conn,op,&entry,filter)==0) + if (test_filter(be,conn,op,entry,filter)==LDAP_COMPARE_TRUE) { - if ((sres=send_search_entry(be,conn,op,&entry,attrs,attrsonly,NULL))==-1) + if ((sres=send_search_entry(be,conn,op,entry,attrs,attrsonly,NULL))==-1) { Debug(LDAP_DEBUG_TRACE,"backsql_search(): connection lost\n",0,0,0); break; } nentries+=!sres; } + entry_free(entry); } for(eid=srch_info.id_list;eid!=NULL;eid=backsql_free_entryID(eid)); diff --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index 5965182b3a..5d89c71f5c 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -17,16 +17,16 @@ #include #include "slap.h" #include "back-sql.h" +#include "schema-map.h" #include "util.h" -char backsql_def_oc_query[]="SELECT id,name,keytbl,keycol,create_proc,delete_proc,expect_return FROM ldap_objclasses"; -char backsql_def_at_query[]="SELECT name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return FROM ldap_attrs WHERE oc_id=?"; +char backsql_def_oc_query[]="SELECT id,name,keytbl,keycol,create_proc,delete_proc,expect_return FROM ldap_oc_mappings"; +char backsql_def_at_query[]="SELECT name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return FROM ldap_attr_mappings WHERE oc_map_id=?"; char backsql_def_delentry_query[]="DELETE FROM ldap_entries WHERE id=?"; -char backsql_def_insentry_query[]="INSERT INTO ldap_entries (dn,objclass,parent,keyval) VALUES (?,?,?,?)"; +char backsql_def_insentry_query[]="INSERT INTO ldap_entries (dn,oc_map_id,parent,keyval) VALUES (?,?,?,?)"; char backsql_def_subtree_cond[]="ldap_entries.dn LIKE CONCAT('%',?)"; -char backsql_id_query[]="SELECT id,keyval,objclass FROM ldap_entries WHERE "; - +char backsql_id_query[]="SELECT id,keyval,oc_map_id FROM ldap_entries WHERE "; char* backsql_strcat(char* dest,int *buflen, ...) { @@ -69,43 +69,35 @@ char* backsql_strcat(char* dest,int *buflen, ...) int backsql_entry_addattr(Entry *e,char *at_name,char *at_val,unsigned int at_val_len) { Attribute *c_at=e->e_attrs; - struct berval **cval; - int nvals; + struct berval* add_val[2]; + struct berval cval; + AttributeDescription *ad; + int rc; + const char *text; Debug(LDAP_DEBUG_TRACE,"backsql_entry_addattr(): at_name='%s', at_val='%s'\n",at_name,at_val,0); - while (c_at!=NULL && strcasecmp(c_at->a_type,at_name)) - c_at=c_at->a_next; - if (c_at == NULL) + cval.bv_val=at_val; + cval.bv_len=at_val_len; + add_val[0]=&cval; + add_val[1]=NULL; + + ad=NULL; + rc = slap_str2ad( at_name, &ad, &text ); + if( rc != LDAP_SUCCESS ) { - //Debug(LDAP_DEBUG_TRACE,"backsql_addattr(): creating new attribute\n",0,0,0); - c_at=(Attribute *)ch_calloc(sizeof(Attribute),1); - c_at->a_type=ch_strdup(at_name); - c_at->a_syntax=SYNTAX_CIS; - c_at->a_vals=(struct berval**)ch_calloc(sizeof(struct berval *),1); - c_at->a_vals[0]=NULL; - c_at->a_next=e->e_attrs; - e->e_attrs=c_at; + Debug(LDAP_DEBUG_TRACE,"backsql_entry_addattr(): failed to find AttributeDescription for '%s'\n",at_name,0,0); + return 0; } - //Debug(LDAP_DEBUG_TRACE,"backsql_addattr(): checking attribute values\n",0,0,0); - //should use different comparison methods for different attributes - //for now, uses memcmp - for (cval=c_at->a_vals,nvals=0;*cval != NULL && - memcmp((*cval)->bv_val,at_val,BACKSQL_MIN((*cval)->bv_len,at_val_len));cval++,nvals++); - - if (*cval==NULL) + + rc = attr_merge(e,ad,add_val); + ad_free( ad, 1 ); + + if( rc != 0 ) { - //Debug(LDAP_DEBUG_TRACE,"backsql_addattr(): nvals=%d; adding new value\n",nvals,0,0); - c_at->a_vals=(struct berval **)realloc(c_at->a_vals,sizeof(struct berval *)*(nvals+2)); - c_at->a_vals[nvals]=(struct berval*)ch_calloc(sizeof(struct berval),1); - c_at->a_vals[nvals]->bv_val=(char*)ch_calloc(sizeof(char),at_val_len); - strncpy(c_at->a_vals[nvals]->bv_val,at_val,at_val_len); - c_at->a_vals[nvals]->bv_len=at_val_len; - c_at->a_vals[nvals+1]=NULL; + Debug(LDAP_DEBUG_TRACE,"backsql_entry_addattr(): failed to merge value '%s' for attribute '%s'\n",at_val,at_name,0); + return 0; } - else - { - //Debug(LDAP_DEBUG_TRACE,"backsql_addattr(): value already exists\n",0,0,0); - } + Debug(LDAP_DEBUG_TRACE,"<==backsql_query_addattr()\n",0,0,0); return 1; }