1998-08-09 08:43:13 +08:00
|
|
|
/* modify.c - ldbm backend modify routine */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-07 07:07:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
1999-05-21 11:53:37 +08:00
|
|
|
#include <ac/time.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
1998-09-21 04:22:46 +08:00
|
|
|
#include "proto-back-ldbm.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-19 12:00:58 +08:00
|
|
|
/* We need this function because of LDAP modrdn. If we do not
|
|
|
|
* add this there would be a bunch of code replication here
|
|
|
|
* and there and of course the likelihood of bugs increases.
|
|
|
|
* Juan C. Gomez (gomez@engr.sgi.com) 05/18/99
|
|
|
|
*/
|
|
|
|
|
1999-05-20 02:27:25 +08:00
|
|
|
int ldbm_modify_internal(
|
1998-08-09 08:43:13 +08:00
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
char *dn,
|
1999-05-19 12:00:58 +08:00
|
|
|
LDAPModList *modlist,
|
|
|
|
Entry *e
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
1999-05-22 08:31:36 +08:00
|
|
|
int err;
|
1999-05-19 12:00:58 +08:00
|
|
|
LDAPMod *mod;
|
1998-12-21 08:21:58 +08:00
|
|
|
LDAPModList *ml;
|
1999-06-15 02:16:05 +08:00
|
|
|
Attribute *a;
|
1999-07-29 12:41:49 +08:00
|
|
|
Attribute *save_attrs;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-10-22 01:53:56 +08:00
|
|
|
if ( !acl_check_modlist( be, conn, op, e, modlist )) {
|
|
|
|
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
|
1999-07-16 10:45:46 +08:00
|
|
|
NULL, NULL, NULL, NULL );
|
1999-05-19 12:00:58 +08:00
|
|
|
return -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-07-29 12:41:49 +08:00
|
|
|
save_attrs = e->e_attrs;
|
|
|
|
e->e_attrs = attrs_dup( e->e_attrs );
|
1999-05-19 12:00:58 +08:00
|
|
|
|
1999-07-29 12:41:49 +08:00
|
|
|
for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
|
1999-05-19 12:00:58 +08:00
|
|
|
mod = &ml->ml_mod;
|
1998-12-21 08:21:58 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
|
|
|
|
case LDAP_MOD_ADD:
|
1999-01-19 13:10:50 +08:00
|
|
|
err = add_values( e, mod, op->o_ndn );
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_DELETE:
|
1999-01-19 13:10:50 +08:00
|
|
|
err = delete_values( e, mod, op->o_ndn );
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_REPLACE:
|
1999-01-19 13:10:50 +08:00
|
|
|
err = replace_values( e, mod, op->o_ndn );
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
1999-05-26 19:45:17 +08:00
|
|
|
|
|
|
|
case LDAP_MOD_SOFTADD:
|
|
|
|
/* Avoid problems in index_add_mods()
|
|
|
|
* We need to add index if necessary.
|
|
|
|
*/
|
|
|
|
mod->mod_op = LDAP_MOD_ADD;
|
|
|
|
if ( (err = add_values( e, mod, op->o_ndn ))
|
|
|
|
== LDAP_TYPE_OR_VALUE_EXISTS ) {
|
|
|
|
|
|
|
|
err = LDAP_SUCCESS;
|
|
|
|
mod->mod_op = LDAP_MOD_SOFTADD;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( err != LDAP_SUCCESS ) {
|
1999-07-29 12:41:49 +08:00
|
|
|
attrs_free( e->e_attrs );
|
|
|
|
e->e_attrs = save_attrs;
|
1998-08-09 08:43:13 +08:00
|
|
|
/* unlock entry, delete from cache */
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, err,
|
|
|
|
NULL, NULL, NULL, NULL );
|
1999-05-19 12:00:58 +08:00
|
|
|
return -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-29 12:41:49 +08:00
|
|
|
/* check for abandon */
|
|
|
|
ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
|
|
|
|
if ( op->o_abandon ) {
|
|
|
|
attrs_free( e->e_attrs );
|
|
|
|
e->e_attrs = save_attrs;
|
|
|
|
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
/* check that the entry still obeys the schema */
|
|
|
|
if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
|
1999-07-29 12:41:49 +08:00
|
|
|
attrs_free( e->e_attrs );
|
|
|
|
e->e_attrs = save_attrs;
|
1998-09-21 04:22:46 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION,
|
|
|
|
NULL, NULL, NULL, NULL );
|
1999-05-19 12:00:58 +08:00
|
|
|
return -1;
|
1998-09-21 04:22:46 +08:00
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* check for abandon */
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( op->o_abandon ) {
|
1999-07-29 12:41:49 +08:00
|
|
|
attrs_free( e->e_attrs );
|
|
|
|
e->e_attrs = save_attrs;
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
1999-05-19 12:00:58 +08:00
|
|
|
return -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-31 11:37:40 +08:00
|
|
|
/* remove old indices */
|
1999-07-29 12:41:49 +08:00
|
|
|
if( save_attrs != NULL ) {
|
|
|
|
for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
|
1999-07-30 02:19:06 +08:00
|
|
|
mod = &ml->ml_mod;
|
1999-07-29 12:41:49 +08:00
|
|
|
if( ( mod->mod_op & ~LDAP_MOD_BVALUES )
|
|
|
|
== LDAP_MOD_REPLACE )
|
|
|
|
{
|
|
|
|
/* Need to remove all values from indexes */
|
|
|
|
a = attr_find( save_attrs, mod->mod_type );
|
|
|
|
|
|
|
|
if( a != NULL ) {
|
|
|
|
(void) index_change_values( be,
|
|
|
|
mod->mod_type,
|
|
|
|
a->a_vals,
|
|
|
|
e->e_id,
|
1999-08-18 03:00:59 +08:00
|
|
|
SLAP_INDEX_DELETE_OP);
|
1999-07-29 12:41:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
attrs_free( save_attrs );
|
|
|
|
}
|
|
|
|
|
1999-07-31 11:37:40 +08:00
|
|
|
/* modify indexes */
|
|
|
|
if ( index_add_mods( be, modlist, e->e_id ) != 0 ) {
|
|
|
|
/* our indices are likely hosed */
|
|
|
|
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
|
|
|
|
NULL, NULL, NULL, NULL );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* check for abandon */
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( op->o_abandon ) {
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
1999-05-19 12:00:58 +08:00
|
|
|
return -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-19 12:00:58 +08:00
|
|
|
return 0;
|
1999-07-29 12:41:49 +08:00
|
|
|
}
|
1999-05-19 12:00:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_back_modify(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
char *dn,
|
1999-09-19 07:40:03 +08:00
|
|
|
char *ndn,
|
1999-05-19 12:00:58 +08:00
|
|
|
LDAPModList *modlist
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
1999-07-16 10:45:46 +08:00
|
|
|
Entry *matched;
|
1999-05-19 12:00:58 +08:00
|
|
|
Entry *e;
|
1999-07-16 10:45:46 +08:00
|
|
|
int manageDSAit = get_manageDSAit( op );
|
1999-05-19 12:00:58 +08:00
|
|
|
|
|
|
|
Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
|
|
|
|
|
|
|
|
/* acquire and lock entry */
|
1999-09-19 07:40:03 +08:00
|
|
|
if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
char* matched_dn = NULL;
|
|
|
|
struct berval **refs = NULL;
|
|
|
|
|
1999-05-19 12:00:58 +08:00
|
|
|
if ( matched != NULL ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
matched_dn = ch_strdup( matched->e_dn );
|
|
|
|
refs = is_entry_referral( matched )
|
|
|
|
? get_entry_referrals( be, conn, op, matched )
|
|
|
|
: NULL;
|
|
|
|
cache_return_entry_r( &li->li_cache, matched );
|
|
|
|
} else {
|
|
|
|
refs = default_referral;
|
1999-05-19 12:00:58 +08:00
|
|
|
}
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
matched_dn, NULL, refs, NULL );
|
|
|
|
|
|
|
|
if ( matched != NULL ) {
|
|
|
|
ber_bvecfree( refs );
|
|
|
|
free( matched_dn );
|
|
|
|
}
|
|
|
|
|
1999-05-19 12:00:58 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
if ( !manageDSAit && is_entry_referral( e ) ) {
|
|
|
|
/* parent is a referral, don't allow add */
|
|
|
|
/* parent is an alias, don't allow add */
|
|
|
|
struct berval **refs = get_entry_referrals( be,
|
|
|
|
conn, op, e );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
|
|
|
|
0, 0 );
|
|
|
|
|
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
e->e_dn, NULL, refs, NULL );
|
|
|
|
|
|
|
|
ber_bvecfree( refs );
|
|
|
|
|
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
1999-05-19 12:00:58 +08:00
|
|
|
/* Modify the entry */
|
1999-09-19 07:40:03 +08:00
|
|
|
if ( ldbm_modify_internal( be, conn, op, ndn, modlist, e ) != 0 ) {
|
1999-05-19 12:00:58 +08:00
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* change the entry itself */
|
|
|
|
if ( id2entry_add( be, e ) != 0 ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
|
|
|
|
NULL, NULL, NULL, NULL );
|
1998-08-29 01:42:42 +08:00
|
|
|
goto error_return;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_SUCCESS,
|
|
|
|
NULL, NULL, NULL, NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
cache_return_entry_w( &li->li_cache, e );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( 0 );
|
1998-08-29 01:42:42 +08:00
|
|
|
|
|
|
|
error_return:;
|
1998-09-21 04:22:46 +08:00
|
|
|
cache_return_entry_w( &li->li_cache, e );
|
1998-08-29 01:42:42 +08:00
|
|
|
return( -1 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-03-04 05:58:51 +08:00
|
|
|
int
|
1998-08-09 08:43:13 +08:00
|
|
|
add_values(
|
|
|
|
Entry *e,
|
|
|
|
LDAPMod *mod,
|
|
|
|
char *dn
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Attribute *a;
|
|
|
|
|
|
|
|
/* check if the values we're adding already exist */
|
|
|
|
if ( (a = attr_find( e->e_attrs, mod->mod_type )) != NULL ) {
|
|
|
|
for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
|
|
|
|
if ( value_find( a->a_vals, mod->mod_bvalues[i],
|
|
|
|
a->a_syntax, 3 ) == 0 ) {
|
|
|
|
return( LDAP_TYPE_OR_VALUE_EXISTS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no - add them */
|
|
|
|
if( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
|
|
|
|
return( LDAP_CONSTRAINT_VIOLATION );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
}
|
|
|
|
|
1999-03-04 05:58:51 +08:00
|
|
|
int
|
1998-08-09 08:43:13 +08:00
|
|
|
delete_values(
|
|
|
|
Entry *e,
|
|
|
|
LDAPMod *mod,
|
|
|
|
char *dn
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int i, j, k, found;
|
|
|
|
Attribute *a;
|
|
|
|
|
|
|
|
/* delete the entire attribute */
|
|
|
|
if ( mod->mod_bvalues == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "removing entire attribute %s\n",
|
|
|
|
mod->mod_type, 0, 0 );
|
|
|
|
return( attr_delete( &e->e_attrs, mod->mod_type ) ?
|
|
|
|
LDAP_NO_SUCH_ATTRIBUTE : LDAP_SUCCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete specific values - find the attribute first */
|
|
|
|
if ( (a = attr_find( e->e_attrs, mod->mod_type )) == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "could not find attribute %s\n",
|
|
|
|
mod->mod_type, 0, 0 );
|
|
|
|
return( LDAP_NO_SUCH_ATTRIBUTE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find each value to delete */
|
|
|
|
for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
|
|
|
|
found = 0;
|
|
|
|
for ( j = 0; a->a_vals[j] != NULL; j++ ) {
|
|
|
|
if ( value_cmp( mod->mod_bvalues[i], a->a_vals[j],
|
|
|
|
a->a_syntax, 3 ) != 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
found = 1;
|
|
|
|
|
|
|
|
/* found a matching value - delete it */
|
|
|
|
ber_bvfree( a->a_vals[j] );
|
|
|
|
for ( k = j + 1; a->a_vals[k] != NULL; k++ ) {
|
|
|
|
a->a_vals[k - 1] = a->a_vals[k];
|
|
|
|
}
|
|
|
|
a->a_vals[k - 1] = NULL;
|
1999-07-18 08:33:30 +08:00
|
|
|
|
|
|
|
/* delete the entire attribute, if no values remain */
|
|
|
|
if ( a->a_vals[0] == NULL) {
|
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
|
|
|
"removing entire attribute %s\n",
|
|
|
|
mod->mod_type, 0, 0 );
|
|
|
|
if ( attr_delete( &e->e_attrs, mod->mod_type ) ) {
|
|
|
|
return LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* looked through them all w/o finding it */
|
|
|
|
if ( ! found ) {
|
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
|
|
|
"could not find value for attr %s\n",
|
|
|
|
mod->mod_type, 0, 0 );
|
|
|
|
return( LDAP_NO_SUCH_ATTRIBUTE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
}
|
|
|
|
|
1999-03-04 05:58:51 +08:00
|
|
|
int
|
1998-08-09 08:43:13 +08:00
|
|
|
replace_values(
|
|
|
|
Entry *e,
|
|
|
|
LDAPMod *mod,
|
|
|
|
char *dn
|
|
|
|
)
|
|
|
|
{
|
|
|
|
(void) attr_delete( &e->e_attrs, mod->mod_type );
|
|
|
|
|
1999-08-12 03:05:40 +08:00
|
|
|
if ( mod->mod_bvalues != NULL &&
|
|
|
|
attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 )
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
return( LDAP_CONSTRAINT_VIOLATION );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
}
|