From 8300eee0179798abe4a55cad6170044d1a80cf99 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 22 Feb 2018 03:12:32 +0000 Subject: [PATCH] back-mdb Multival fixes Fix multival logic on Replace Fix return codes from modify_internal, id2entry_put --- servers/slapd/back-mdb/id2entry.c | 27 ++++++++++++++++----------- servers/slapd/back-mdb/modify.c | 21 +++++++++++++++------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/servers/slapd/back-mdb/id2entry.c b/servers/slapd/back-mdb/id2entry.c index 6244dd77ca..4356363ea7 100644 --- a/servers/slapd/back-mdb/id2entry.c +++ b/servers/slapd/back-mdb/id2entry.c @@ -307,18 +307,23 @@ again: MDB_cursor *mvc; Attribute *a; rc = mdb_cursor_open( txn, mdb->mi_dbis[MDB_ID2VAL], &mvc ); - if( rc ) - return rc; - for ( a = ec.multi; a; a=a->a_next ) { - if (!(a->a_flags & SLAP_ATTR_BIG_MULTI)) - continue; - rc = mdb_mval_put( op, mvc, e->e_id, a ); - if( rc != LDAP_SUCCESS ) - break; + if( !rc ) { + for ( a = ec.multi; a; a=a->a_next ) { + if (!(a->a_flags & SLAP_ATTR_BIG_MULTI)) + continue; + rc = mdb_mval_put( op, mvc, e->e_id, a ); + if( rc ) + break; + } + mdb_cursor_close( mvc ); + } + if ( rc ) { + Debug( LDAP_DEBUG_ANY, + "mdb_id2entry_put: mdb_mval_put failed: %s(%d) \"%s\"\n", + mdb_strerror(rc), rc, + e->e_nname.bv_val ); + return LDAP_OTHER; } - mdb_cursor_close( mvc ); - if ( rc ) - return rc; } } if (rc) { diff --git a/servers/slapd/back-mdb/modify.c b/servers/slapd/back-mdb/modify.c index 7bfdb5cd58..e0ca295904 100644 --- a/servers/slapd/back-mdb/modify.c +++ b/servers/slapd/back-mdb/modify.c @@ -183,8 +183,11 @@ do_add: if ( anew->a_flags & SLAP_ATTR_BIG_MULTI ) { if (!mvc) { err = mdb_cursor_open( tid, mdb->mi_dbis[MDB_ID2VAL], &mvc ); - if (err) + if (err) { +mval_fail: strncpy( textbuf, mdb_strerror( err ), textlen ); + err = LDAP_OTHER; break; + } } /* if prev was set, just add new values */ if (a_flags & SLAP_ATTR_BIG_MULTI ) { @@ -199,6 +202,8 @@ do_add: if (anew->a_nvals == anew->a_vals) anew->a_nvals = NULL; } + if ( err ) + goto mval_fail; } } break; @@ -237,7 +242,7 @@ do_del: if (!mvc) { err = mdb_cursor_open( tid, mdb->mi_dbis[MDB_ID2VAL], &mvc ); if (err) - break; + goto mval_fail; } if ( mod->sm_numvals ) { anew = attr_find( e->e_attrs, mod->sm_desc ); @@ -259,6 +264,8 @@ do_del: anew->a_numvals = 0; } err = mdb_mval_del( op, mvc, e->e_id, anew ); + if ( err ) + goto mval_fail; } } break; @@ -279,7 +286,7 @@ do_del: if (!mvc) { err = mdb_cursor_open( tid, mdb->mi_dbis[MDB_ID2VAL], &mvc ); if (err) - break; + goto mval_fail; } /* delete all values */ anew = &a_dummy; @@ -287,17 +294,19 @@ do_del: anew->a_numvals = 0; err = mdb_mval_del( op, mvc, e->e_id, anew ); if (err) - break; + goto mval_fail; } anew = attr_find( e->e_attrs, mod->sm_desc ); - if (mod->sm_numvals >= mdb->mi_multi_lo) { + if (mod->sm_numvals > mdb->mi_multi_hi) { anew->a_flags |= SLAP_ATTR_BIG_MULTI; if (!mvc) { err = mdb_cursor_open( tid, mdb->mi_dbis[MDB_ID2VAL], &mvc ); if (err) - break; + goto mval_fail; } err = mdb_mval_put(op, mvc, e->e_id, anew); + if (err) + goto mval_fail; } else if (anew) { /* revert back to normal attr */ anew->a_flags &= ~SLAP_ATTR_BIG_MULTI;