2000-03-17 03:08:22 +08:00
|
|
|
/*
|
2000-05-27 00:03:32 +08:00
|
|
|
* Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
|
2000-03-17 03:08:22 +08:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted only
|
|
|
|
* as authorized by the OpenLDAP Public License. A copy of this
|
|
|
|
* license is available at http://www.OpenLDAP.org/license.html or
|
|
|
|
* in file LICENSE in the top-level directory of the distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
2000-03-19 14:18:27 +08:00
|
|
|
#ifdef SLAPD_SQL
|
|
|
|
|
2000-03-17 03:08:22 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2002-11-10 01:03:07 +08:00
|
|
|
#include "ac/string.h"
|
2000-03-17 03:08:22 +08:00
|
|
|
#include "slap.h"
|
2002-08-17 00:45:24 +08:00
|
|
|
#include "ldap_pvt.h"
|
2000-03-17 03:08:22 +08:00
|
|
|
#include "back-sql.h"
|
|
|
|
#include "sql-wrap.h"
|
|
|
|
#include "schema-map.h"
|
|
|
|
#include "entry-id.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
2002-08-23 16:54:08 +08:00
|
|
|
* PostgreSQL 7.0 doesn't work without :(
|
2002-08-14 01:12:27 +08:00
|
|
|
*/
|
|
|
|
#define BACKSQL_REALLOC_STMT
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
/*
|
|
|
|
* Skip:
|
|
|
|
* - the first occurrence of objectClass, which is used
|
|
|
|
* to determine how to bulid the SQL entry (FIXME ?!?)
|
|
|
|
* - operational attributes
|
|
|
|
* empty attributes (FIXME ?!?)
|
|
|
|
*/
|
|
|
|
#define backsql_attr_skip(ad,vals) \
|
|
|
|
( \
|
|
|
|
( (ad) == slap_schema.si_ad_objectClass \
|
|
|
|
&& (vals)[ 1 ].bv_val == NULL ) \
|
|
|
|
|| is_at_operational( (ad)->ad_type ) \
|
|
|
|
|| ( (vals)[ 0 ].bv_val == NULL ) \
|
|
|
|
)
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
static int
|
|
|
|
backsql_modify_internal(
|
2002-09-03 03:39:31 +08:00
|
|
|
BackendDB *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
2002-08-17 00:45:24 +08:00
|
|
|
SQLHDBC dbh,
|
|
|
|
backsql_oc_map_rec *oc,
|
|
|
|
backsql_entryID *e_id,
|
2002-08-23 16:54:08 +08:00
|
|
|
Modifications *modlist,
|
|
|
|
const char **text )
|
2000-03-17 03:08:22 +08:00
|
|
|
{
|
2002-09-03 03:39:31 +08:00
|
|
|
backsql_info *bi = (backsql_info*)be->be_private;
|
2002-08-17 00:45:24 +08:00
|
|
|
RETCODE rc;
|
|
|
|
SQLHSTMT sth;
|
|
|
|
Modifications *ml;
|
2002-08-23 16:54:08 +08:00
|
|
|
int res = LDAP_SUCCESS;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"traversing modifications list\n", 0, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
*text = NULL;
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
|
|
|
SQLAllocStmt( dbh, &sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
AttributeDescription *ad;
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_at_map_rec *at = NULL;
|
|
|
|
struct berval *at_val;
|
|
|
|
Modification *c_mod;
|
|
|
|
int i;
|
|
|
|
/* first parameter no, parameter order */
|
|
|
|
SQLUSMALLINT pno, po;
|
|
|
|
/* procedure return code */
|
|
|
|
int prc;
|
|
|
|
|
|
|
|
#ifdef BACKSQL_REALLOC_STMT
|
|
|
|
SQLAllocStmt( dbh, &sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
c_mod = &ml->sml_mod;
|
2002-08-17 00:45:24 +08:00
|
|
|
ad = c_mod->sm_desc;
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify_internal(): "
|
|
|
|
"modifying attribute '%s'\n",
|
|
|
|
ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( backsql_attr_skip( ad, c_mod->sm_bvalues ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
at = backsql_ad2at( oc, ad );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( at == NULL ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"attribute provided is not registered "
|
2002-08-23 16:54:08 +08:00
|
|
|
"in objectClass '%s'\n",
|
2002-08-17 00:45:24 +08:00
|
|
|
ad->ad_cname.bv_val, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
*text = "operation not permitted "
|
|
|
|
"within namingContext";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
2000-05-27 00:03:32 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
switch( c_mod->sm_op ) {
|
|
|
|
case LDAP_MOD_REPLACE: {
|
|
|
|
SQLHSTMT asth;
|
|
|
|
BACKSQL_ROW_NTS row;
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"replacing values for attribute '%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
if ( at->add_proc == NULL ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"add procedure is not defined "
|
|
|
|
"for attribute '%s' "
|
|
|
|
"- unable to perform replacements\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
*text = "operation not permitted "
|
|
|
|
"within namingContext";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( at->delete_proc == NULL ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"delete procedure is not defined "
|
|
|
|
"for attribute '%s' "
|
|
|
|
"- adding only\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
*text = "operation not permitted "
|
|
|
|
"within namingContext";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
goto add_only;
|
|
|
|
}
|
|
|
|
|
2000-03-17 03:08:22 +08:00
|
|
|
del_all:
|
2002-08-14 01:12:27 +08:00
|
|
|
rc = backsql_Prepare( dbh, &asth, at->query, 0 );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"error preparing query\n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh,
|
|
|
|
asth, rc );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_OTHER;
|
|
|
|
*text = "SQL-backend error";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
rc = backsql_BindParamID( asth, 1, &e_id->keyval );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( rc != SQL_SUCCESS ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"error binding key value parameter\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh,
|
|
|
|
asth, rc );
|
|
|
|
SQLFreeStmt( asth, SQL_DROP );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_OTHER;
|
|
|
|
*text = "SQL-backend error";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = SQLExecute( asth );
|
|
|
|
if ( !BACKSQL_SUCCESS( rc ) ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"error executing attribute query\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh,
|
|
|
|
asth, rc );
|
|
|
|
SQLFreeStmt( asth, SQL_DROP );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_OTHER;
|
|
|
|
*text = "SQL-backend error";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
backsql_BindRowAsStrings( asth, &row );
|
|
|
|
rc = SQLFetch( asth );
|
|
|
|
for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( asth ) ) {
|
|
|
|
for ( i = 0; i < row.ncols; i++ ) {
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( BACKSQL_IS_DEL( at->expect_return ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
pno = 1;
|
|
|
|
SQLBindParameter(sth, 1,
|
|
|
|
SQL_PARAM_OUTPUT,
|
|
|
|
SQL_C_ULONG,
|
|
|
|
SQL_INTEGER,
|
|
|
|
0, 0, &prc, 0, 0 );
|
|
|
|
} else {
|
|
|
|
pno = 0;
|
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
po = ( BACKSQL_IS_DEL( at->param_order ) ) > 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLBindParameter( sth, pno + 1 + po,
|
|
|
|
SQL_PARAM_INPUT,
|
|
|
|
SQL_C_ULONG, SQL_INTEGER,
|
2002-08-17 00:45:24 +08:00
|
|
|
0, 0, &e_id->keyval, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for syntax needed here
|
|
|
|
* maybe need binary bind?
|
|
|
|
*/
|
|
|
|
SQLBindParameter(sth, pno + 2 - po,
|
|
|
|
SQL_PARAM_INPUT,
|
|
|
|
SQL_C_CHAR, SQL_CHAR,
|
|
|
|
0, 0, row.cols[ i ],
|
|
|
|
strlen( row.cols[ i ] ), 0 );
|
2000-05-27 00:03:32 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2002-08-23 16:54:08 +08:00
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"executing '%s'\n",
|
|
|
|
at->delete_proc, 0, 0 );
|
|
|
|
rc = SQLExecDirect( sth,
|
|
|
|
at->delete_proc, SQL_NTS );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2002-08-23 16:54:08 +08:00
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"delete_proc "
|
|
|
|
"execution failed\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env,
|
|
|
|
dbh, sth, rc );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_OTHER;
|
|
|
|
*text = "SQL-backend error";
|
|
|
|
goto done;
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifdef BACKSQL_REALLOC_STMT
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
SQLAllocStmt( dbh, &sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_FreeRow( &row );
|
|
|
|
SQLFreeStmt( asth, SQL_DROP );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PASSTHROUGH - to add new attributes -- do NOT add break
|
|
|
|
*/
|
|
|
|
case LDAP_MOD_ADD:
|
2002-08-17 00:45:24 +08:00
|
|
|
case SLAP_MOD_SOFTADD:
|
2002-08-14 01:12:27 +08:00
|
|
|
add_only:;
|
|
|
|
if ( at->add_proc == NULL ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"add procedure is not defined "
|
|
|
|
"for attribute '%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
*text = "operation not permitted "
|
|
|
|
"within namingContext";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"adding new values for attribute '%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
for ( i = 0, at_val = c_mod->sm_bvalues;
|
2002-08-14 01:12:27 +08:00
|
|
|
at_val->bv_val != NULL;
|
2002-08-17 00:45:24 +08:00
|
|
|
i++, at_val++ ) {
|
|
|
|
if ( BACKSQL_IS_ADD( at->expect_return ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
pno = 1;
|
|
|
|
SQLBindParameter( sth, 1,
|
|
|
|
SQL_PARAM_OUTPUT,
|
|
|
|
SQL_C_ULONG, SQL_INTEGER,
|
|
|
|
0, 0, &prc, 0, 0);
|
|
|
|
} else {
|
|
|
|
pno = 0;
|
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
po = ( BACKSQL_IS_ADD( at->param_order ) ) > 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLBindParameter( sth, pno + 1 + po,
|
|
|
|
SQL_PARAM_INPUT,
|
|
|
|
SQL_C_ULONG, SQL_INTEGER,
|
2002-08-17 00:45:24 +08:00
|
|
|
0, 0, &e_id->keyval, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for syntax needed here
|
|
|
|
* maybe need binary bind?
|
|
|
|
*/
|
|
|
|
SQLBindParameter( sth, pno + 2 - po,
|
|
|
|
SQL_PARAM_INPUT,
|
|
|
|
SQL_C_CHAR, SQL_CHAR,
|
|
|
|
0, 0, at_val->bv_val,
|
|
|
|
at_val->bv_len, 0 );
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"executing '%s'\n",
|
|
|
|
at->add_proc, 0, 0 );
|
|
|
|
rc = SQLExecDirect( sth, at->add_proc,
|
|
|
|
SQL_NTS );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2002-08-23 16:54:08 +08:00
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"add_proc execution failed\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env,
|
|
|
|
dbh, sth, rc );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_OTHER;
|
|
|
|
*text = "SQL-backend error";
|
|
|
|
goto done;
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifdef BACKSQL_REALLOC_STMT
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
SQLAllocStmt( dbh, &sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
case LDAP_MOD_DELETE:
|
|
|
|
if ( at->delete_proc == NULL ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"delete procedure is not defined "
|
|
|
|
"for attribute '%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
*text = "operation not permitted "
|
|
|
|
"within namingContext";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
if ( c_mod->sm_bvalues == NULL ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"no values given to delete "
|
|
|
|
"for attribute '%s' "
|
|
|
|
"-- deleting all values\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
goto del_all;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"deleting values for attribute '%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
at->ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
for ( i = 0, at_val = c_mod->sm_bvalues;
|
2002-08-14 01:12:27 +08:00
|
|
|
at_val->bv_val != NULL;
|
2002-08-17 00:45:24 +08:00
|
|
|
i++, at_val++ ) {
|
|
|
|
if ( BACKSQL_IS_DEL( at->expect_return ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
pno = 1;
|
|
|
|
SQLBindParameter( sth, 1,
|
|
|
|
SQL_PARAM_OUTPUT,
|
|
|
|
SQL_C_ULONG, SQL_INTEGER,
|
|
|
|
0, 0, &prc, 0, 0 );
|
|
|
|
} else {
|
|
|
|
pno = 0;
|
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
po = ( BACKSQL_IS_DEL( at->param_order ) ) > 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLBindParameter( sth, pno + 1 + po,
|
|
|
|
SQL_PARAM_INPUT,
|
|
|
|
SQL_C_ULONG, SQL_INTEGER,
|
2002-08-17 00:45:24 +08:00
|
|
|
0, 0, &e_id->keyval, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for syntax needed here
|
|
|
|
* maybe need binary bind?
|
|
|
|
*/
|
|
|
|
SQLBindParameter( sth, pno + 2 - po,
|
|
|
|
SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
|
|
|
|
0, 0, at_val->bv_val,
|
|
|
|
at_val->bv_len, 0 );
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"executing '%s'\n",
|
|
|
|
at->delete_proc, 0, 0 );
|
|
|
|
rc = SQLExecDirect( sth, at->delete_proc,
|
|
|
|
SQL_NTS );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2002-08-23 16:54:08 +08:00
|
|
|
"backsql_modify_internal(): "
|
2002-08-14 01:12:27 +08:00
|
|
|
"delete_proc execution "
|
|
|
|
"failed\n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env,
|
|
|
|
dbh, sth, rc );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
res = LDAP_OTHER;
|
|
|
|
*text = "SQL-backend error";
|
|
|
|
goto done;
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifdef BACKSQL_REALLOC_STMT
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
SQLAllocStmt( dbh, &sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLFreeStmt( sth, SQL_RESET_PARAMS );
|
2002-08-17 00:45:24 +08:00
|
|
|
#else /* BACKSQL_REALLOC_STMT */
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
done:;
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-08-17 00:45:24 +08:00
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: should fail in case one change fails?
|
|
|
|
*/
|
2002-08-23 16:54:08 +08:00
|
|
|
return res;
|
2002-08-17 00:45:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
backsql_modify(
|
|
|
|
BackendDB *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
struct berval *dn,
|
|
|
|
struct berval *ndn,
|
|
|
|
Modifications *modlist )
|
|
|
|
{
|
|
|
|
backsql_info *bi = (backsql_info*)be->be_private;
|
|
|
|
SQLHDBC dbh;
|
|
|
|
backsql_oc_map_rec *oc = NULL;
|
|
|
|
backsql_entryID e_id;
|
2002-08-23 16:54:08 +08:00
|
|
|
Entry e;
|
2002-08-17 00:45:24 +08:00
|
|
|
int res;
|
2002-08-23 16:54:08 +08:00
|
|
|
const char *text = NULL;
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: in case part of the operation cannot be performed
|
|
|
|
* (missing mapping, SQL write fails or so) the entire operation
|
|
|
|
* should be rolled-back
|
|
|
|
*/
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_modify(): changing entry '%s'\n",
|
|
|
|
ndn->bv_val, 0, 0 );
|
|
|
|
res = backsql_get_db_conn( be, conn, &dbh );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
/*
|
|
|
|
* FIXME: we don't want to send back
|
|
|
|
* excessively detailed messages
|
|
|
|
*/
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL,
|
|
|
|
res == LDAP_OTHER ? "SQL-backend error" : "",
|
2002-08-17 00:45:24 +08:00
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = backsql_dn2id( bi, &e_id, dbh, ndn );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
|
|
|
|
"could not lookup entry id\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res , NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
res == LDAP_OTHER ? "SQL-backend error" : "",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
|
|
|
|
"modifying entry '%s' (id=%ld)\n",
|
|
|
|
e_id.dn.bv_val, e_id.id, 0 );
|
|
|
|
|
|
|
|
oc = backsql_id2oc( bi, e_id.oc_id );
|
|
|
|
if ( oc == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
|
|
|
|
"cannot determine objectclass of entry -- aborting\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
/*
|
|
|
|
* FIXME: should never occur, since the entry was built!!!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: we don't want to send back
|
|
|
|
* excessively detailed messages
|
|
|
|
*/
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
"SQL-backend error", NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
e.e_attrs = NULL;
|
|
|
|
e.e_name = *dn;
|
|
|
|
e.e_nname = *ndn;
|
|
|
|
if ( !acl_check_modlist( be, conn, op, &e, modlist )) {
|
|
|
|
res = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
|
|
|
|
} else {
|
2002-09-03 03:39:31 +08:00
|
|
|
res = backsql_modify_internal( be, conn, op,
|
|
|
|
dbh, oc, &e_id, modlist, &text );
|
2002-08-23 16:54:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( res == LDAP_SUCCESS ) {
|
|
|
|
/*
|
|
|
|
* Commit only if all operations succeed
|
|
|
|
*/
|
2002-08-29 18:55:48 +08:00
|
|
|
SQLTransact( SQL_NULL_HENV, dbh,
|
|
|
|
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
|
2002-08-17 00:45:24 +08:00
|
|
|
}
|
2002-08-29 18:55:48 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL, text, NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
|
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
return op->o_noop;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
|
|
|
backsql_modrdn(
|
|
|
|
BackendDB *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
struct berval *dn,
|
|
|
|
struct berval *ndn,
|
|
|
|
struct berval *newrdn,
|
|
|
|
struct berval *nnewrdn,
|
|
|
|
int deleteoldrdn,
|
|
|
|
struct berval *newSuperior,
|
|
|
|
struct berval *nnewSuperior )
|
2000-03-17 03:08:22 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_info *bi = (backsql_info*)be->be_private;
|
|
|
|
SQLHDBC dbh;
|
|
|
|
SQLHSTMT sth;
|
|
|
|
RETCODE rc;
|
|
|
|
backsql_entryID e_id, pe_id, new_pid;
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_oc_map_rec *oc = NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
int res;
|
|
|
|
struct berval p_dn, p_ndn,
|
|
|
|
*new_pdn = NULL, *new_npdn = NULL,
|
|
|
|
new_dn, new_ndn;
|
2002-08-17 00:45:24 +08:00
|
|
|
const char *text = NULL;
|
|
|
|
LDAPRDN *new_rdn = NULL;
|
|
|
|
LDAPRDN *old_rdn = NULL;
|
2002-08-23 16:54:08 +08:00
|
|
|
Entry e;
|
2002-08-17 00:45:24 +08:00
|
|
|
Modifications *mod;
|
2000-06-30 05:14:43 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_modrdn() renaming entry '%s', "
|
|
|
|
"newrdn='%s', newSuperior='%s'\n",
|
2002-08-17 00:45:24 +08:00
|
|
|
dn->bv_val, newrdn->bv_val,
|
|
|
|
newSuperior ? newSuperior->bv_val : "(NULL)" );
|
|
|
|
res = backsql_get_db_conn( be, conn, &dbh );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
res == LDAP_OTHER ? "SQL-backend error" : "",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = backsql_dn2id( bi, &e_id, dbh, ndn );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"could not lookup entry id\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
res == LDAP_OTHER ? "SQL-backend error" : "",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* FIXME: check whether entry has children
|
|
|
|
*/
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): entry id is %ld\n",
|
|
|
|
e_id.id, 0, 0 );
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( backsql_has_children( bi, dbh, ndn ) == LDAP_COMPARE_TRUE ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"entry \"%s\" has children\n", dn->bv_val, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
|
|
|
|
NULL, "subtree delete not supported",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
dnParent( dn, &p_dn );
|
|
|
|
dnParent( ndn, &p_ndn );
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
/*
|
|
|
|
* namingContext "" is not supported
|
|
|
|
*/
|
|
|
|
if ( p_dn.bv_len == 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"parent is \"\" - aborting\n", 0, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
|
2002-09-03 03:39:31 +08:00
|
|
|
NULL, "not allowed within namingContext",
|
2002-08-23 16:54:08 +08:00
|
|
|
NULL, NULL );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for children access to parent
|
|
|
|
*/
|
|
|
|
e.e_attrs = NULL;
|
|
|
|
e.e_name = p_dn;
|
|
|
|
e.e_nname = p_ndn;
|
|
|
|
if ( !access_allowed( be, conn, op, &e, slap_schema.si_ad_children,
|
|
|
|
NULL, ACL_WRITE, NULL ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0, 0, 0 );
|
|
|
|
res = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( newSuperior ) {
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* namingContext "" is not supported
|
|
|
|
*/
|
|
|
|
if ( newSuperior->bv_len == 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"newSuperior is \"\" - aborting\n", 0, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
|
2002-09-03 03:39:31 +08:00
|
|
|
NULL,
|
|
|
|
"not allowed within namingContext",
|
2002-08-17 00:45:24 +08:00
|
|
|
NULL, NULL );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
new_pdn = newSuperior;
|
|
|
|
new_npdn = nnewSuperior;
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
e.e_name = *new_pdn;
|
|
|
|
e.e_nname = *new_npdn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for children access to new parent
|
|
|
|
*/
|
|
|
|
if ( !access_allowed( be, conn, op, &e,
|
|
|
|
slap_schema.si_ad_children,
|
|
|
|
NULL, ACL_WRITE, NULL ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "no access to new parent\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
res = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
|
|
|
new_pdn = &p_dn;
|
|
|
|
new_npdn = &p_ndn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newSuperior && dn_match( &p_ndn, new_npdn ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
2002-08-17 00:45:24 +08:00
|
|
|
"newSuperior is equal to old parent - ignored\n",
|
2002-08-14 01:12:27 +08:00
|
|
|
0, 0, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
newSuperior = NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( newSuperior && dn_match( ndn, new_npdn ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"newSuperior is equal to entry being moved "
|
|
|
|
"- aborting\n", 0, 0, 0 );
|
2003-03-02 04:17:52 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
2002-09-03 03:39:31 +08:00
|
|
|
NULL, "newSuperior is equal to old DN",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
build_new_dn( &new_dn, new_pdn, newrdn );
|
|
|
|
if ( dnNormalize2( NULL, &new_dn, &new_ndn ) != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"new dn is invalid ('%s') - aborting\n",
|
|
|
|
new_dn.bv_val, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX,
|
|
|
|
NULL, "new DN is invalid", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): new entry dn is '%s'\n",
|
|
|
|
new_dn.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
res = backsql_dn2id( bi, &pe_id, dbh, &p_ndn );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"could not lookup old parent entry id\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
res == LDAP_OTHER ? "SQL-backend error" : "",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"old parent entry id is %ld\n", pe_id.id, 0, 0 );
|
|
|
|
|
|
|
|
res = backsql_dn2id( bi, &new_pid, dbh, new_npdn );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"could not lookup new parent entry id\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
res == LDAP_OTHER ? "SQL-backend error" : "",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"new parent entry id is %ld\n", new_pid.id, 0, 0 );
|
|
|
|
|
2000-06-30 05:14:43 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
|
|
|
|
"executing delentry_query\n", 0, 0, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
SQLAllocStmt( dbh, &sth );
|
2002-08-14 01:12:27 +08:00
|
|
|
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 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
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.bv_val, 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 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
/*
|
|
|
|
* Get attribute type and attribute value of our new rdn,
|
|
|
|
* we will need to add that to our new entry
|
2002-08-14 01:12:27 +08:00
|
|
|
*/
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( ldap_bv2rdn( newrdn, &new_rdn, (char **)&text,
|
|
|
|
LDAP_DN_FORMAT_LDAP ) ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( OPERATION, ERR,
|
|
|
|
"backsql_modrdn: can't figure out "
|
|
|
|
"type(s)/values(s) of newrdn\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modrdn: can't figure out "
|
|
|
|
"type(s)/values(s) of newrdn\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
rc = LDAP_INVALID_DN_SYNTAX;
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( OPERATION, RESULTS,
|
|
|
|
"backsql_modrdn: new_rdn_type=\"%s\", "
|
|
|
|
"new_rdn_val=\"%s\"\n",
|
|
|
|
new_rdn[ 0 ][ 0 ]->la_attr.bv_val,
|
|
|
|
new_rdn[ 0 ][ 0 ]->la_value.bv_val, 0 );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modrdn: new_rdn_type=\"%s\", "
|
|
|
|
"new_rdn_val=\"%s\"\n",
|
|
|
|
new_rdn[ 0 ][ 0 ]->la_attr.bv_val,
|
|
|
|
new_rdn[ 0 ][ 0 ]->la_value.bv_val, 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( deleteoldrdn ) {
|
|
|
|
if ( ldap_bv2rdn( dn, &old_rdn, (char **)&text,
|
|
|
|
LDAP_DN_FORMAT_LDAP ) ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( OPERATION, ERR,
|
|
|
|
"backsql_modrdn: can't figure out "
|
|
|
|
"type(s)/values(s) of old_rdn\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_modrdn: can't figure out "
|
|
|
|
"the old_rdn type(s)/value(s)\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
rc = LDAP_OTHER;
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
e.e_name = new_dn;
|
|
|
|
e.e_nname = new_ndn;
|
|
|
|
res = slap_modrdn2mods( be, conn, op, &e, old_rdn, new_rdn,
|
2002-08-17 00:45:24 +08:00
|
|
|
deleteoldrdn, &mod );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( !acl_check_modlist( be, conn, op, &e, mod )) {
|
|
|
|
res = LDAP_INSUFFICIENT_ACCESS;
|
2002-08-17 00:45:24 +08:00
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
oc = backsql_id2oc( bi, e_id.oc_id );
|
2002-09-03 03:39:31 +08:00
|
|
|
res = backsql_modify_internal( be, conn, op,
|
|
|
|
dbh, oc, &e_id, mod, &text );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( res == LDAP_SUCCESS ) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commit only if all operations succeed
|
|
|
|
*/
|
2002-08-29 18:55:48 +08:00
|
|
|
SQLTransact( SQL_NULL_HENV, dbh,
|
|
|
|
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
|
2002-08-23 16:54:08 +08:00
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2000-06-30 05:14:43 +08:00
|
|
|
modrdn_return:
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
|
|
|
|
if ( new_dn.bv_val ) {
|
|
|
|
ch_free( new_dn.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( new_ndn.bv_val ) {
|
|
|
|
ch_free( new_ndn.bv_val );
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
/* LDAP v2 supporting correct attribute handling. */
|
|
|
|
if ( new_rdn != NULL ) {
|
|
|
|
ldap_rdnfree( new_rdn );
|
|
|
|
}
|
|
|
|
if ( old_rdn != NULL ) {
|
|
|
|
ldap_rdnfree( old_rdn );
|
|
|
|
}
|
|
|
|
if( mod != NULL ) {
|
|
|
|
Modifications *tmp;
|
|
|
|
for (; mod; mod=tmp ) {
|
|
|
|
tmp = mod->sml_next;
|
|
|
|
free( mod );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL, text, NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
return op->o_noop;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
|
|
|
backsql_add(
|
|
|
|
BackendDB *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
Entry *e )
|
2000-03-17 03:08:22 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_info *bi = (backsql_info*)be->be_private;
|
|
|
|
SQLHDBC dbh;
|
|
|
|
SQLHSTMT sth;
|
|
|
|
unsigned long new_keyval = 0;
|
|
|
|
long i;
|
|
|
|
RETCODE rc;
|
|
|
|
backsql_oc_map_rec *oc = NULL;
|
|
|
|
backsql_at_map_rec *at_rec = NULL;
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_entryID e_id, parent_id;
|
2002-08-23 16:54:08 +08:00
|
|
|
Entry p;
|
2002-08-14 01:12:27 +08:00
|
|
|
int res;
|
|
|
|
Attribute *at;
|
|
|
|
struct berval *at_val;
|
|
|
|
struct berval pdn;
|
2002-08-23 16:54:08 +08:00
|
|
|
/* first parameter #, parameter order */
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLUSMALLINT pno, po;
|
|
|
|
/* procedure return code */
|
|
|
|
int prc;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_add(): adding entry '%s'\n",
|
2002-08-23 16:54:08 +08:00
|
|
|
e->e_name.bv_val, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
/* check schema */
|
|
|
|
if ( global_schemacheck ) {
|
|
|
|
const char *text = NULL;
|
|
|
|
char textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };
|
|
|
|
int rc;
|
|
|
|
rc = entry_schema_check( be, e, NULL,
|
|
|
|
&text, textbuf, sizeof( textbuf ) );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"entry failed schema check -- aborting\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, rc, NULL,
|
|
|
|
"operation not permitted "
|
|
|
|
"within namingContext",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
/* search structural objectClass */
|
|
|
|
for ( at = e->e_attrs; at != NULL; at = at->a_next ) {
|
|
|
|
if ( at->a_desc == slap_schema.si_ad_structuralObjectClass ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
/* there must exist */
|
|
|
|
assert( at != NULL );
|
|
|
|
|
|
|
|
/* I guess we should play with sub/supertypes to find a suitable oc */
|
|
|
|
oc = backsql_name2oc( bi, &at->a_vals[0] );
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( oc == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"cannot determine objectclass of entry -- aborting\n",
|
|
|
|
0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
"operation not permitted within namingContext",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oc->create_proc == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"create procedure is not defined for this objectclass "
|
|
|
|
"- aborting\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
"operation not permitted within namingContext",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
} else if ( BACKSQL_CREATE_NEEDS_SELECT( bi )
|
|
|
|
&& oc->create_keyval == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
2002-09-03 03:39:31 +08:00
|
|
|
"create procedure needs select procedure, "
|
|
|
|
"but none is defined - aborting\n", 0, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
|
2002-08-23 16:54:08 +08:00
|
|
|
"operation not permitted within namingContext",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
prc = backsql_get_db_conn( be, conn, &dbh );
|
|
|
|
if ( prc != LDAP_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, prc, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
prc == LDAP_OTHER ? "SQL-backend error" : "",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* Check if entry exists
|
|
|
|
*/
|
|
|
|
res = backsql_dn2id( bi, &e_id, dbh, &e->e_name );
|
|
|
|
if ( res == LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"entry '%s' exists\n",
|
|
|
|
e->e_name.bv_val, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_ALREADY_EXISTS,
|
|
|
|
NULL, NULL, NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if parent exists
|
|
|
|
*/
|
|
|
|
dnParent( &e->e_name, &pdn );
|
|
|
|
res = backsql_dn2id( bi, &parent_id, dbh, &pdn );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NO SUCH OBJECT seems more appropriate
|
|
|
|
*/
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"could not lookup parent entry for new record '%s'\n",
|
|
|
|
pdn.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( res != LDAP_NO_SUCH_OBJECT ) {
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res,
|
|
|
|
NULL, NULL, NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for matched
|
|
|
|
*/
|
|
|
|
while ( 1 ) {
|
|
|
|
struct berval dn;
|
2002-09-03 03:39:31 +08:00
|
|
|
char *matched = NULL;
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
dn = pdn;
|
|
|
|
dnParent( &dn, &pdn );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Empty DN ("") defaults to LDAP_SUCCESS
|
|
|
|
*/
|
|
|
|
res = backsql_dn2id( bi, &parent_id, dbh, &pdn );
|
|
|
|
switch ( res ) {
|
|
|
|
case LDAP_NO_SUCH_OBJECT:
|
|
|
|
if ( pdn.bv_len > 0 ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fail over to next case */
|
|
|
|
|
|
|
|
case LDAP_SUCCESS:
|
|
|
|
matched = pdn.bv_val;
|
|
|
|
/* fail over to next case */
|
|
|
|
|
|
|
|
default:
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res,
|
|
|
|
matched, NULL, NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create_proc is executed; if expect_return is set, then
|
|
|
|
* an output parameter is bound, which should contain
|
|
|
|
* the id of the added row; otherwise the procedure
|
|
|
|
* is expected to return the id as the first column of a select
|
|
|
|
*/
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
p.e_attrs = NULL;
|
|
|
|
p.e_name = pdn;
|
|
|
|
dnParent( &e->e_nname, &p.e_nname );
|
|
|
|
if ( !access_allowed( be, conn, op, &p, slap_schema.si_ad_children,
|
|
|
|
NULL, ACL_WRITE, NULL ) ) {
|
|
|
|
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
|
|
|
|
NULL, NULL, NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
rc = SQLAllocStmt( dbh, &sth );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( rc != SQL_SUCCESS ) {
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( BACKSQL_IS_ADD( oc->expect_return ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT, SQL_C_ULONG,
|
|
|
|
SQL_INTEGER, 0, 0, &new_keyval, 0, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): executing '%s'\n",
|
|
|
|
oc->create_proc, 0, 0 );
|
|
|
|
rc = SQLExecDirect( sth, oc->create_proc, SQL_NTS );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"create_proc execution failed\n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc);
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2002-09-03 03:39:31 +08:00
|
|
|
if ( op->o_noop ) {
|
|
|
|
SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( !BACKSQL_IS_ADD( oc->expect_return ) ) {
|
|
|
|
SWORD ncols;
|
2002-09-03 03:39:31 +08:00
|
|
|
SQLINTEGER value_len;
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) ) {
|
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
|
|
|
SQLFreeStmt( sth, SQL_RESET_PARAMS );
|
|
|
|
#else /* BACKSQL_REALLOC_STMT */
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
rc = SQLAllocStmt( dbh, &sth );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error",
|
|
|
|
NULL, NULL );
|
2002-08-23 16:54:08 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
|
|
|
|
|
|
|
rc = SQLExecDirect( sth, oc->create_keyval, SQL_NTS );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error",
|
|
|
|
NULL, NULL );
|
2002-08-23 16:54:08 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
2002-08-17 00:45:24 +08:00
|
|
|
* the query to know the id of the inserted entry
|
|
|
|
* must be embedded in the create procedure
|
2002-08-14 01:12:27 +08:00
|
|
|
*/
|
2002-08-17 00:45:24 +08:00
|
|
|
rc = SQLNumResultCols( sth, &ncols );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"create_proc result evaluation failed\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc);
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if ( ncols != 1 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
2002-08-23 16:54:08 +08:00
|
|
|
"create_proc result is bogus (ncols=%d)\n",
|
|
|
|
ncols, 0, 0 );
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc);
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
SQLCHAR colname[ 64 ];
|
|
|
|
SQLSMALLINT name_len, col_type, col_scale, col_null;
|
|
|
|
UDWORD col_prec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: check whether col_type is compatible,
|
|
|
|
* if it can be null and so on ...
|
|
|
|
*/
|
|
|
|
rc = SQLDescribeCol( sth, (SQLUSMALLINT)1,
|
|
|
|
&colname[ 0 ],
|
|
|
|
(SQLUINTEGER)( sizeof( colname ) - 1 ),
|
|
|
|
&name_len, &col_type,
|
|
|
|
&col_prec, &col_scale, &col_null );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rc = SQLBindCol( sth, (SQLUSMALLINT)1, SQL_C_ULONG,
|
|
|
|
(SQLPOINTER)&new_keyval,
|
|
|
|
(SQLINTEGER)sizeof( new_keyval ),
|
2002-09-03 03:39:31 +08:00
|
|
|
&value_len );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
rc = SQLFetch( sth );
|
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
if ( value_len <= 0 ) {
|
2002-08-17 00:45:24 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
2002-09-03 03:39:31 +08:00
|
|
|
"create_proc result is empty?\n",
|
2002-08-17 00:45:24 +08:00
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc);
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
|
|
|
SQLFreeStmt( sth, SQL_RESET_PARAMS );
|
|
|
|
#else /* BACKSQL_REALLOC_STMT */
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"create_proc returned keyval=%ld\n", new_keyval, 0, 0 );
|
|
|
|
|
|
|
|
for ( at = e->e_attrs; at != NULL; at = at->a_next ) {
|
|
|
|
SQLUSMALLINT currpos;
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"adding attribute '%s'\n",
|
|
|
|
at->a_desc->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip:
|
|
|
|
* - the first occurrence of objectClass, which is used
|
|
|
|
* to determine how to bulid the SQL entry (FIXME ?!?)
|
|
|
|
* - operational attributes
|
|
|
|
* empty attributes (FIXME ?!?)
|
|
|
|
*/
|
|
|
|
if ( backsql_attr_skip( at->a_desc, at->a_vals ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
at_rec = backsql_ad2at( oc, at->a_desc );
|
2000-05-27 00:03:32 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( at_rec == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"attribute '%s' is not registered "
|
|
|
|
"in objectclass '%s'\n",
|
2002-08-17 00:45:24 +08:00
|
|
|
at->a_desc->ad_cname.bv_val,
|
2002-08-29 18:55:48 +08:00
|
|
|
BACKSQL_OC_NAME( oc ), 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
send_ldap_result( conn, op,
|
2002-09-03 03:39:31 +08:00
|
|
|
LDAP_UNWILLING_TO_PERFORM, NULL,
|
2002-08-23 16:54:08 +08:00
|
|
|
"operation not permitted "
|
|
|
|
"within namingContext",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( at_rec->add_proc == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"add procedure is not defined "
|
|
|
|
"for attribute '%s'\n",
|
|
|
|
at->a_desc->ad_cname.bv_val, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
|
|
|
send_ldap_result( conn, op,
|
2002-09-03 03:39:31 +08:00
|
|
|
LDAP_UNWILLING_TO_PERFORM, NULL,
|
2002-08-23 16:54:08 +08:00
|
|
|
"operation not permitted "
|
|
|
|
"within namingContext",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BACKSQL_REALLOC_STMT
|
|
|
|
rc = backsql_Prepare( dbh, &sth, at_rec->add_proc, 0 );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error",
|
2002-08-23 16:54:08 +08:00
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( BACKSQL_IS_ADD( at_rec->expect_return ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
pno = 1;
|
|
|
|
SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT,
|
|
|
|
SQL_C_ULONG, SQL_INTEGER,
|
|
|
|
0, 0, &prc, 0, 0 );
|
|
|
|
} else {
|
|
|
|
pno = 0;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
po = ( BACKSQL_IS_ADD( at_rec->param_order ) ) > 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
currpos = pno + 1 + po;
|
|
|
|
SQLBindParameter( sth, currpos,
|
|
|
|
SQL_PARAM_INPUT, SQL_C_ULONG,
|
|
|
|
SQL_INTEGER, 0, 0, &new_keyval, 0, 0 );
|
|
|
|
currpos = pno + 2 - po;
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
for ( i = 0, at_val = &at->a_vals[ i ];
|
|
|
|
at_val->bv_val != NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
i++, at_val = &at->a_vals[ i ] ) {
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
/*
|
|
|
|
* Do not deal with the objectClass that is used
|
|
|
|
* to build the entry
|
|
|
|
*/
|
|
|
|
if ( at->a_desc == slap_schema.si_ad_objectClass ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
if ( bvmatch( at_val, &oc->oc->soc_cname ) ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
|
|
|
* check for syntax needed here
|
|
|
|
* maybe need binary bind?
|
|
|
|
*/
|
|
|
|
|
|
|
|
backsql_BindParamStr( sth, currpos,
|
|
|
|
at_val->bv_val, at_val->bv_len + 1 );
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifdef SECURITY_PARANOID
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"executing '%s', id=%ld\n",
|
|
|
|
at_rec->add_proc, new_keyval, 0 );
|
|
|
|
#else
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"executing '%s' with val='%s', id=%ld\n",
|
|
|
|
at_rec->add_proc, at_val->bv_val, new_keyval );
|
2002-08-17 00:45:24 +08:00
|
|
|
#endif
|
2002-08-14 01:12:27 +08:00
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
|
|
|
rc = SQLExecDirect( sth, at_rec->add_proc, SQL_NTS );
|
|
|
|
#else /* BACKSQL_REALLOC_STMT */
|
|
|
|
rc = SQLExecute( sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"add_proc execution failed\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL,
|
2002-08-23 16:54:08 +08:00
|
|
|
"SQL-backend error",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
|
|
|
SQLFreeStmt( sth, SQL_RESET_PARAMS );
|
|
|
|
#else /* BACKSQL_REALLOC_STMT */
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BACKSQL_REALLOC_STMT
|
|
|
|
rc = backsql_Prepare( dbh, &sth, bi->insentry_query, 0 );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_BindParamStr( sth, 1, e->e_name.bv_val, BACKSQL_MAX_DN_LEN );
|
|
|
|
SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
|
|
|
|
0, 0, &oc->id, 0, 0 );
|
|
|
|
SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
|
|
|
|
0, 0, &parent_id.id, 0, 0 );
|
|
|
|
SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
|
|
|
|
0, 0, &new_keyval, 0, 0 );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): executing '%s' for dn '%s'\n",
|
|
|
|
bi->insentry_query, e->e_name.bv_val, 0 );
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " for oc_map_id=%ld, parent_id=%ld, "
|
|
|
|
"keyval=%ld\n", oc->id, parent_id.id, new_keyval );
|
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
|
|
|
rc = SQLExecDirect( sth, bi->insentry_query, SQL_NTS );
|
|
|
|
#else /* BACKSQL_REALLOC_STMT */
|
|
|
|
rc = SQLExecute( sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
|
|
|
|
"could not insert ldap_entries record\n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* execute delete_proc to delete data added !!!
|
|
|
|
*/
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Commit only if all operations succeed
|
|
|
|
*/
|
2002-08-29 18:55:48 +08:00
|
|
|
SQLTransact( SQL_NULL_HENV, dbh,
|
2002-09-03 03:39:31 +08:00
|
|
|
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: NOOP does not work for add -- it works for all
|
|
|
|
* the other operations, and I don't get the reason :(
|
|
|
|
*/
|
|
|
|
|
|
|
|
send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
return op->o_noop;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
|
|
|
backsql_delete(
|
|
|
|
BackendDB *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
struct berval *dn,
|
|
|
|
struct berval *ndn )
|
2000-03-17 03:08:22 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_info *bi = (backsql_info*)be->be_private;
|
|
|
|
SQLHDBC dbh;
|
|
|
|
SQLHSTMT sth;
|
|
|
|
RETCODE rc;
|
|
|
|
backsql_oc_map_rec *oc = NULL;
|
|
|
|
backsql_entryID e_id;
|
2002-08-23 16:54:08 +08:00
|
|
|
Entry e;
|
2002-08-14 01:12:27 +08:00
|
|
|
int res;
|
|
|
|
/* first parameter no */
|
|
|
|
SQLUSMALLINT pno;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_delete(): deleting entry '%s'\n",
|
|
|
|
ndn->bv_val, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
dnParent( dn, &e.e_name );
|
|
|
|
dnParent( ndn, &e.e_nname );
|
|
|
|
e.e_attrs = NULL;
|
|
|
|
|
|
|
|
/* check parent for "children" acl */
|
|
|
|
if ( !access_allowed( be, conn, 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 );
|
|
|
|
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
|
2002-09-03 03:39:31 +08:00
|
|
|
NULL, NULL, NULL, NULL );
|
2002-08-23 16:54:08 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
res = backsql_get_db_conn( be, conn, &dbh );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL,
|
2002-08-17 00:45:24 +08:00
|
|
|
res == LDAP_OTHER ? "SQL-backend error" : "",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = backsql_dn2id( bi, &e_id, dbh, ndn );
|
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
|
|
|
|
"could not lookup entry id\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, res, NULL, NULL, NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
res = backsql_has_children( bi, dbh, ndn );
|
|
|
|
switch ( res ) {
|
|
|
|
case LDAP_COMPARE_TRUE:
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
|
|
|
|
"entry \"%s\" has children\n", dn->bv_val, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
|
|
|
|
NULL, "subtree delete not supported",
|
|
|
|
NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case LDAP_COMPARE_FALSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
send_ldap_result( conn, op, res, NULL, NULL, NULL, NULL );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
oc = backsql_id2oc( bi, e_id.oc_id );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( oc == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
|
2002-09-03 03:39:31 +08:00
|
|
|
"cannot determine objectclass of entry -- aborting\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
|
2002-08-23 16:54:08 +08:00
|
|
|
"operation not permitted within namingContext",
|
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oc->delete_proc == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
|
|
|
|
"delete procedure is not defined "
|
|
|
|
"for this objectclass - aborting\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
|
2002-08-23 16:54:08 +08:00
|
|
|
"operation not permitted within namingContext",
|
2002-08-17 00:45:24 +08:00
|
|
|
NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQLAllocStmt( dbh, &sth );
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( BACKSQL_IS_DEL( oc->expect_return ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
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->delete_proc, 0, 0 );
|
|
|
|
rc = SQLExecDirect( sth, oc->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 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
#ifndef BACKSQL_REALLOC_STMT
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLFreeStmt( sth, SQL_RESET_PARAMS );
|
2002-08-17 00:45:24 +08:00
|
|
|
#else /* BACKSQL_REALLOC_STMT */
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
SQLAllocStmt( dbh, &sth );
|
|
|
|
#endif /* BACKSQL_REALLOC_STMT */
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
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 );
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OTHER,
|
|
|
|
NULL, "SQL-backend error", NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2002-08-29 18:55:48 +08:00
|
|
|
SQLTransact( SQL_NULL_HENV, dbh,
|
2002-09-03 03:39:31 +08:00
|
|
|
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_delete()\n", 0, 0, 0 );
|
2002-09-03 03:39:31 +08:00
|
|
|
return op->o_noop;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
2000-03-19 14:18:27 +08:00
|
|
|
|
2000-05-27 00:03:32 +08:00
|
|
|
#endif /* SLAPD_SQL */
|
2002-08-14 01:12:27 +08:00
|
|
|
|