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

make file names more slapd-ish; add attribute inheritance to search...

make file names more slapd-ish; add attribute inheritance to search attributes; precompile uppercased search
parent 0b907a37
......@@ -13,10 +13,12 @@
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
SRCS = init.c config.c search.c bind.c other.c \
entry-id.c schema-map.c sql-wrap.c modify.c util.c
OBJS = init.lo config.lo search.lo bind.lo other.lo \
entry-id.lo schema-map.lo sql-wrap.lo modify.lo util.lo
SRCS = init.c config.c search.c bind.c compare.c operational.c \
entry-id.c schema-map.c sql-wrap.c modify.c util.c \
add.c delete.c modrdn.c
OBJS = init.lo config.lo search.lo bind.lo compare.lo operational.lo \
entry-id.lo schema-map.lo sql-wrap.lo modify.lo util.lo \
add.lo delete.lo modrdn.lo
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
......
This diff is collapsed.
......@@ -78,8 +78,14 @@
#include "sql-types.h"
/*
* Better use the standard length of 8192 (as of servers/slapd/dn.c) ?
* PostgreSQL 7.0 doesn't work without :(
*/
#define BACKSQL_REALLOC_STMT
/*
* Better use the standard length of 8192 (as of slap.h)?
*/
/* #define BACKSQL_MAX_DN_LEN SLAP_LDAPDN_MAXLEN */
#define BACKSQL_MAX_DN_LEN 255
/*
......@@ -87,6 +93,147 @@
*/
#undef BACKSQL_TRACE
/*
* Entry ID structure
*/
typedef struct backsql_entryID {
unsigned long id;
unsigned long keyval;
unsigned long oc_id;
struct berval dn;
struct backsql_entryID *next;
} backsql_entryID;
/*
* "structural" objectClass mapping structure
*/
typedef struct backsql_oc_map_rec {
/*
* Structure of corresponding LDAP objectClass definition
*/
ObjectClass *bom_oc;
#define BACKSQL_OC_NAME(ocmap) ((ocmap)->bom_oc->soc_cname.bv_val)
struct berval bom_keytbl;
struct berval bom_keycol;
/* expected to return keyval of newly created entry */
char *bom_create_proc;
/* in case create_proc does not return the keyval of the newly
* created row */
char *bom_create_keyval;
/* supposed to expect keyval as parameter and delete
* all the attributes as well */
char *bom_delete_proc;
/* flags whether delete_proc is a function (whether back-sql
* should bind first parameter as output for return code) */
int bom_expect_return;
unsigned long bom_id;
Avlnode *bom_attrs;
} backsql_oc_map_rec;
/*
* attributeType mapping structure
*/
typedef struct backsql_at_map_rec {
/* Description of corresponding LDAP attribute type */
AttributeDescription *bam_ad;
/* ObjectClass if bam_ad is objectClass */
ObjectClass *bam_oc;
struct berval bam_from_tbls;
struct berval bam_join_where;
struct berval bam_sel_expr;
/* TimesTen, or, if a uppercase function is defined,
* an uppercased version of bam_sel_expr */
struct berval bam_sel_expr_u;
/* supposed to expect 2 binded values: entry keyval
* and attr. value to add, like "add_name(?,?,?)" */
char *bam_add_proc;
/* supposed to expect 2 binded values: entry keyval
* and attr. value to delete */
char *bam_delete_proc;
/* for optimization purposes attribute load query
* is preconstructed from parts on schemamap load time */
char *bam_query;
/* following flags are bitmasks (first bit used for add_proc,
* second - for delete_proc) */
/* order of parameters for procedures above;
* 1 means "data then keyval", 0 means "keyval then data" */
int bam_param_order;
/* flags whether one or more of procedures is a function
* (whether back-sql should bind first parameter as output
* for return code) */
int bam_expect_return;
/* next mapping for attribute */
struct backsql_at_map_rec *bam_next;
} backsql_at_map_rec;
#define BACKSQL_AT_MAP_REC_INIT { NULL, NULL, BER_BVC(""), BER_BVC(""), BER_BVNULL, BER_BVNULL, NULL, NULL, NULL, 0, 0, NULL }
/* define to uppercase filters only if the matching rule requires it
* (currently broken) */
/* #define BACKSQL_UPPERCASE_FILTER */
#define BACKSQL_AT_CANUPPERCASE(at) ((at)->bam_sel_expr_u.bv_val)
/* defines to support bitmasks above */
#define BACKSQL_ADD 0x1
#define BACKSQL_DEL 0x2
#define BACKSQL_IS_ADD(x) ( BACKSQL_ADD & (x) )
#define BACKSQL_IS_DEL(x) ( BACKSQL_DEL & (x) )
#define BACKSQL_NCMP(v1,v2) ber_bvcmp((v1),(v2))
#define BACKSQL_CONCAT
/*
* berbuf structure: a berval with a buffer size associated
*/
typedef struct berbuf {
struct berval bb_val;
ber_len_t bb_len;
} BerBuffer;
#define BB_NULL { { 0, NULL }, 0 }
typedef struct backsql_srch_info {
Operation *bsi_op;
int bsi_flags;
#define BSQL_SF_ALL_OPER 0x0001
#define BSQL_SF_FILTER_HASSUBORDINATE 0x0002
struct berval *bsi_base_dn;
int bsi_scope;
Filter *bsi_filter;
int bsi_slimit,
bsi_tlimit;
time_t bsi_stoptime;
backsql_entryID *bsi_id_list,
*bsi_c_eid;
int bsi_n_candidates;
int bsi_abandon;
int bsi_status;
backsql_oc_map_rec *bsi_oc;
struct berbuf bsi_sel,
bsi_from,
bsi_join_where,
bsi_flt_where;
ObjectClass *bsi_filter_oc;
SQLHDBC bsi_dbh;
AttributeName *bsi_attrs;
Entry *bsi_e;
} backsql_srch_info;
/*
* Backend private data structure
*/
typedef struct {
char *dbhost;
int dbport;
......@@ -150,3 +297,5 @@ typedef struct {
#endif /* __BACKSQL_H__ */
......@@ -24,11 +24,9 @@
#include <stdio.h>
#include <sys/types.h>
#include "slap.h"
#include "back-sql.h"
#include "sql-wrap.h"
#include "util.h"
#include "entry-id.h"
#include "proto-sql.h"
int
backsql_bind( Operation *op, SlapReply *rs )
......
......@@ -24,11 +24,9 @@
#include <stdio.h>
#include <sys/types.h>
#include "slap.h"
#include "back-sql.h"
#include "sql-wrap.h"
#include "entry-id.h"
#include "util.h"
#include "proto-sql.h"
int
backsql_compare( Operation *op, SlapReply *rs )
......@@ -173,62 +171,5 @@ return_results:;
}
}
/*
* sets the supported operational attributes (if required)
*/
int
backsql_operational(
Operation *op,
SlapReply *rs,
int opattrs,
Attribute **a )
{
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
SQLHDBC dbh = SQL_NULL_HDBC;
Attribute **aa = a;
int rc = 0;
Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry '%s'\n",
rs->sr_entry->e_nname.bv_val, 0, 0 );
if ( ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) )
&& attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL ) {
rc = backsql_get_db_conn( op, &dbh );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
"could not get connection handle - exiting\n",
0, 0, 0 );
return 1;
}
rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname );
switch( rc ) {
case LDAP_COMPARE_TRUE:
case LDAP_COMPARE_FALSE:
*aa = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
if ( *aa != NULL ) {
aa = &(*aa)->a_next;
}
rc = 0;
break;
default:
Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
"has_children failed( %d)\n", rc, 0, 0 );
rc = 1;
break;
}
}
Debug( LDAP_DEBUG_TRACE, "<==backsql_operational()\n", 0, 0, 0);
return rc;
}
#endif /* SLAPD_SQL */
......@@ -25,10 +25,9 @@
#include <stdio.h>
#include "ac/string.h"
#include <sys/types.h>
#include "slap.h"
#include "back-sql.h"
#include "sql-wrap.h"
#include "util.h"
#include "proto-sql.h"
int
backsql_db_config(
......
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1999-2004 The OpenLDAP Foundation.
* Portions Copyright 1999 Dmitry Kovalev.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Dmitry Kovalev for inclusion
* by OpenLDAP Software.
*/
#include "portable.h"
#ifdef SLAPD_SQL
#include <stdio.h>
#include <sys/types.h>
#include "ac/string.h"
#include "slap.h"
#include "ldap_pvt.h"
#include "proto-sql.h"
int
backsql_delete( Operation *op, SlapReply *rs )
{
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
SQLHDBC dbh;
SQLHSTMT sth;
RETCODE rc;
backsql_oc_map_rec *oc = NULL;
backsql_entryID e_id;
Entry e;
/* first parameter no */
SQLUSMALLINT pno;
Debug( LDAP_DEBUG_TRACE, "==>backsql_delete(): deleting entry \"%s\"\n",
op->o_req_ndn.bv_val, 0, 0 );
dnParent( &op->o_req_dn, &e.e_name );
dnParent( &op->o_req_ndn, &e.e_nname );
e.e_attrs = NULL;
/* check parent for "children" acl */
if ( !access_allowed( op, &e, slap_schema.si_ad_children,
NULL, ACL_WRITE, NULL ) ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"no write access to parent\n",
0, 0, 0 );
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
goto done;
}
rs->sr_err = backsql_get_db_conn( op, &dbh );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"could not get connection handle - exiting\n",
0, 0, 0 );
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
? "SQL-backend error" : NULL;
goto done;
}
rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"could not lookup entry id\n", 0, 0, 0 );
goto done;
}
rs->sr_err = backsql_has_children( bi, dbh, &op->o_req_ndn );
switch ( rs->sr_err ) {
case LDAP_COMPARE_TRUE:
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"entry \"%s\" has children\n",
op->o_req_dn.bv_val, 0, 0 );
rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
rs->sr_text = "subtree delete not supported";
goto done;
case LDAP_COMPARE_FALSE:
break;
default:
goto done;
}
oc = backsql_id2oc( bi, e_id.oc_id );
if ( oc == NULL ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"cannot determine objectclass of entry -- aborting\n",
0, 0, 0 );
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "operation not permitted within namingContext";
goto done;
}
if ( oc->bom_delete_proc == NULL ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"delete procedure is not defined "
"for this objectclass - aborting\n", 0, 0, 0 );
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "operation not permitted within namingContext";
goto done;
}
SQLAllocStmt( dbh, &sth );
if ( BACKSQL_IS_DEL( oc->bom_expect_return ) ) {
pno = 1;
SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT, SQL_C_ULONG,
SQL_INTEGER, 0, 0, &rc, 0, 0 );
} else {
pno = 0;
}
SQLBindParameter( sth, pno + 1, SQL_PARAM_INPUT,
SQL_C_ULONG, SQL_INTEGER, 0, 0, &e_id.keyval, 0, 0 );
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): executing \"%s\"\n",
oc->bom_delete_proc, 0, 0 );
rc = SQLExecDirect( sth, oc->bom_delete_proc, SQL_NTS );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"delete_proc execution failed\n", 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error";
goto done;
}
#ifndef BACKSQL_REALLOC_STMT
SQLFreeStmt( sth, SQL_RESET_PARAMS );
#else /* BACKSQL_REALLOC_STMT */
SQLFreeStmt( sth, SQL_DROP );
SQLAllocStmt( dbh, &sth );
#endif /* BACKSQL_REALLOC_STMT */
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_delete(): "
"failed to delete record from ldap_entries\n",
0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error";
goto done;
}
SQLFreeStmt( sth, SQL_DROP );
/*
* Commit only if all operations succeed
*
* FIXME: backsql_add() does not fail if add operations
* are not available for some attributes, or if
* a multiple value add actually results in a replace,
* or if a single operation on an attribute fails
* for any reason
*/
SQLTransact( SQL_NULL_HENV, dbh,
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
rs->sr_err = LDAP_SUCCESS;
done:;
send_ldap_result( op, rs );
Debug( LDAP_DEBUG_TRACE, "<==backsql_delete()\n", 0, 0, 0 );
return ( ( rs->sr_err == LDAP_SUCCESS ) ? op->o_noop : 1 );
}
#endif /* SLAPD_SQL */
......@@ -25,14 +25,11 @@
#include <stdio.h>
#include <sys/types.h>
#include "ac/string.h"
#include "lber_pvt.h"
#include "ldap_pvt.h"
#include "slap.h"
#include "back-sql.h"
#include "sql-wrap.h"
#include "schema-map.h"
#include "entry-id.h"
#include "util.h"
#include "proto-sql.h"
backsql_entryID *
backsql_free_entryID( backsql_entryID *id, int freeit )
......@@ -367,7 +364,6 @@ Entry *
backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid )
{
int i;
backsql_at_map_rec *at;
int rc;
AttributeDescription *ad_oc = slap_schema.si_ad_objectClass;
......@@ -391,23 +387,29 @@ backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid )
Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
"custom attribute list\n", 0, 0, 0 );
for ( i = 0; bsi->bsi_attrs[ i ].an_name.bv_val; i++ ) {
AttributeName *attr = &bsi->bsi_attrs[ i ];
backsql_at_map_rec **vat;
AttributeName *attr = &bsi->bsi_attrs[ i ];
int j;
if ( attr->an_desc == ad_oc ) {
continue;
}
at = backsql_ad2at( bsi->bsi_oc, attr->an_desc );
if ( at != NULL ) {
backsql_get_attr_vals( at, bsi );
} else {
rc = backsql_supad2at( bsi->bsi_oc, attr->an_desc, &vat );
if ( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
"attribute '%s' is not defined "
"for objectlass '%s'\n",
attr->an_name.bv_val,
BACKSQL_OC_NAME( bsi->bsi_oc ), 0 );
"attribute '%s' is not defined "
"for objectlass '%s'\n",
attr->an_name.bv_val,
BACKSQL_OC_NAME( bsi->bsi_oc ), 0 );
continue;
}
for ( j = 0; vat[j]; j++ ) {
backsql_get_attr_vals( vat[j], bsi );
}
ch_free( vat );
}
} else {
......
......@@ -24,12 +24,10 @@
#include <stdio.h>
#include <sys/types.h>
#include "slap.h"
#include "ldap_pvt.h"
#include "back-sql.h"
#include "sql-wrap.h"
#include "schema-map.h"
#include "util.h"
#include "proto-sql.h"
#ifdef SLAPD_SQL_DYNAMIC
......
This diff is collapsed.
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1999-2004 The OpenLDAP Foundation.
* Portions Copyright 1999 Dmitry Kovalev.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Dmitry Kovalev for inclusion
* by OpenLDAP Software.
*/
#include "portable.h"
#ifdef SLAPD_SQL
#include <stdio.h>
#include <sys/types.h>
#include "ac/string.h"
#include "slap.h"
#include "ldap_pvt.h"
#include "proto-sql.h"
int
backsql_modrdn( Operation *op, SlapReply *rs )
{
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
SQLHDBC dbh;
SQLHSTMT sth;
RETCODE rc;
backsql_entryID e_id, pe_id, new_pid;
backsql_oc_map_rec *oc = NULL;
struct berval p_dn, p_ndn,
*new_pdn = NULL, *new_npdn = NULL,
new_dn, new_ndn;
LDAPRDN new_rdn = NULL;
LDAPRDN old_rdn = NULL;
Entry e;
Modifications *mod;
struct berval *newSuperior = op->oq_modrdn.rs_newSup;
Debug( LDAP_DEBUG_TRACE, "==>backsql_modrdn() renaming entry \"%s\", "
"newrdn=\"%s\", newSuperior=\"%s\"\n",