]> git.sur5r.net Git - openldap/commitdiff
fix most of the issues of ITS#4627
authorPierangelo Masarati <ando@openldap.org>
Tue, 14 Aug 2007 15:54:56 +0000 (15:54 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 14 Aug 2007 15:54:56 +0000 (15:54 +0000)
servers/slapd/back-ldif/ldif.c

index b6f943f92aaa7a876d8377932756ee2a91dc1486..72fd1be53a0781f67f17dccc54303d3071f33cd8 100644 (file)
@@ -86,7 +86,6 @@ dn2path(struct berval * dn, struct berval * suffixdn, struct berval * base_path,
        struct berval *res)
 {
        char *ptr, *sep, *end;
-       struct berval bv;
 
        assert( dn != NULL );
        assert( !BER_BVISNULL( dn ) );
@@ -108,19 +107,22 @@ dn2path(struct berval * dn, struct berval * suffixdn, struct berval * base_path,
        }
        strcpy(ptr, LDIF);
 #if IX_FSL != IX_DNL
-       bv = *res;
-       while ( ptr = ber_bvchr( &bv, IX_DNL ) ) {
-               *ptr++ = IX_FSL;
-               assert( ( ptr - bv.bv_val ) <= bv.bv_len );
-               bv.bv_len -= ( ptr - bv.bv_val );
-               bv.bv_val = ptr;
-               ptr = ber_bvchr( &bv, IX_DNR );
-               if ( !ptr )
-                       break;
-               *ptr++ = IX_FSR;
-               assert( ( ptr - bv.bv_val ) <= bv.bv_len );
-               bv.bv_len -= ( ptr - bv.bv_val );
-               bv.bv_val = ptr;
+       {
+               struct berval bv;
+               bv = *res;
+               while ( ptr = ber_bvchr( &bv, IX_DNL ) ) {
+                       *ptr++ = IX_FSL;
+                       assert( ( ptr - bv.bv_val ) <= bv.bv_len );
+                       bv.bv_len -= ( ptr - bv.bv_val );
+                       bv.bv_val = ptr;
+                       ptr = ber_bvchr( &bv, IX_DNR );
+                       if ( !ptr )
+                               break;
+                       *ptr++ = IX_FSR;
+                       assert( ( ptr - bv.bv_val ) <= bv.bv_len );
+                       bv.bv_len -= ( ptr - bv.bv_val );
+                       bv.bv_val = ptr;
+               }
        }
 #endif
 }
@@ -174,23 +176,24 @@ static int spew_file(int fd, char * spew, int len) {
        return writeres;
 }
 
-static int spew_entry(Entry * e, struct berval * path) {
+static int
+spew_entry( Entry * e, struct berval * path, int dolock, int *save_errnop )
+{
        int rs;
        int openres;
        int spew_res;
        int entry_length;
        char * entry_as_string;
+       char tmpfname[] = "tmpXXXXXX";
 
-       openres = open(path->bv_val, O_WRONLY|O_CREAT|O_TRUNC, S_IREAD | S_IWRITE);
-       if(openres == -1) {
-               if(errno == ENOENT)
-                       rs = LDAP_NO_SUCH_OBJECT;
-               else
-                       rs = LDAP_UNWILLING_TO_PERFORM;
+       openres = mkstemp( tmpfname );
+       if ( save_errnop ) *save_errnop = errno;
+       if ( openres == -1 ) {
+               rs = LDAP_UNWILLING_TO_PERFORM;
                Debug( LDAP_DEBUG_ANY, "could not open \"%s\": %s\n",
-                       path->bv_val, STRERROR( errno ), 0 );
-       }
-       else {
+                       path->bv_val, STRERROR( *save_errnop ), 0 );
+
+       else {
                struct berval rdn;
                int tmp;
 
@@ -203,6 +206,10 @@ static int spew_entry(Entry * e, struct berval * path) {
                        rdn.bv_len = tmp;
                }
 
+               if ( dolock ) {
+                       ldap_pvt_thread_mutex_lock(&entry2str_mutex);
+               }
+
                entry_as_string = entry2str(e, &entry_length);
 
                /* Restore full DN */
@@ -211,19 +218,45 @@ static int spew_entry(Entry * e, struct berval * path) {
                        e->e_name.bv_len = rdn.bv_len;
                }
 
-               if(entry_as_string == NULL) {
+               if ( entry_as_string == NULL ) {
                        rs = LDAP_UNWILLING_TO_PERFORM;
                        close(openres);
-               }
-               else {
-                       spew_res = spew_file(openres, entry_as_string, entry_length);
-                       close(openres);
-                       if(spew_res == -1)
-                               rs = LDAP_UNWILLING_TO_PERFORM;
-                       else
-                               rs = LDAP_SUCCESS;
+                       unlink( tmpfname );
+
+                       if ( dolock ) {
+                               ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
+                       }
+
+               } else {
+                       spew_res = spew_file( openres,
+                               entry_as_string, entry_length );
+
+                       if ( dolock ) {
+                               ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
+                       }
+
+                       close( openres );
+                       rs = LDAP_UNWILLING_TO_PERFORM;
+                       if ( spew_res != -1 ) {
+                               int res = rename( tmpfname, path->bv_val );
+                               if ( save_errnop ) *save_errnop = errno;
+                               if ( res == 0 ) {
+                                       rs = LDAP_SUCCESS;
+       
+                               } else {
+                                       switch ( *save_errnop ) {
+                                       case ENOENT:
+                                               rs = LDAP_NO_SUCH_OBJECT;
+                                               break;
+
+                                       default:
+                                               break;
+                                       }
+                               }
+                       }
                }
        }
+
        return rs;
 }
 
@@ -428,7 +461,7 @@ static int r_enum_tree(enumCookie *ck, struct berval *path,
                                if ( ptr ) {
                                        itmp.bv_len = ptr - itmp.bv_val;
                                        ber_dupbv( &bvl->num, &itmp );
-                                       bvl->inum = strtol( itmp.bv_val, NULL, 0 );
+                                       bvl->inum = strtoul( itmp.bv_val, NULL, 0 );
                                        itmp.bv_val[0] = '\0';
                                        bvl->off = itmp.bv_val - bvl->bv.bv_val;
                                }
@@ -481,14 +514,14 @@ enum_tree(
        enumCookie *ck
 )
 {
-       struct ldif_info *ni = (struct ldif_info *) ck->op->o_bd->be_private;
+       struct ldif_info *li = (struct ldif_info *) ck->op->o_bd->be_private;
        struct berval path;
        struct berval pdn, pndn;
        int rc;
 
        dnParent( &ck->op->o_req_dn, &pdn );
        dnParent( &ck->op->o_req_ndn, &pndn );
-       dn2path( &ck->op->o_req_ndn, &ck->op->o_bd->be_nsuffix[0], &ni->li_base_path, &path);
+       dn2path( &ck->op->o_req_ndn, &ck->op->o_bd->be_nsuffix[0], &li->li_base_path, &path);
        rc = r_enum_tree(ck, &path, &pdn, &pndn);
        ch_free( path.bv_val );
        return rc;
@@ -592,7 +625,7 @@ static int apply_modify_to_entry(Entry * entry,
 int
 ldif_back_referrals( Operation *op, SlapReply *rs )
 {
-       struct ldif_info        *ni = NULL;
+       struct ldif_info        *li = NULL;
        Entry                   *entry;
        int                     rc = LDAP_SUCCESS;
 
@@ -608,9 +641,9 @@ ldif_back_referrals( Operation *op, SlapReply *rs )
                return rc;
        }
 
-       ni = (struct ldif_info *)op->o_bd->be_private;
-       ldap_pvt_thread_rdwr_rlock( &ni->li_rdwr );
-       entry = (Entry *)get_entry( op, &ni->li_base_path );
+       li = (struct ldif_info *)op->o_bd->be_private;
+       ldap_pvt_thread_rdwr_rlock( &li->li_rdwr );
+       entry = get_entry( op, &li->li_base_path );
 
        /* no object is found for them */
        if ( entry == NULL ) {
@@ -629,10 +662,10 @@ ldif_back_referrals( Operation *op, SlapReply *rs )
                        op->o_req_dn = pndn;
                        op->o_req_ndn = pndn;
 
-                       entry = (Entry *)get_entry( op, &ni->li_base_path );
+                       entry = get_entry( op, &li->li_base_path );
                }
 
-               ldap_pvt_thread_rdwr_runlock( &ni->li_rdwr );
+               ldap_pvt_thread_rdwr_runlock( &li->li_rdwr );
 
                op->o_req_dn = odn;
                op->o_req_ndn = ondn;
@@ -682,7 +715,7 @@ ldif_back_referrals( Operation *op, SlapReply *rs )
                return rc;
        }
 
-       ldap_pvt_thread_rdwr_runlock( &ni->li_rdwr );
+       ldap_pvt_thread_rdwr_runlock( &li->li_rdwr );
 
        if ( is_entry_referral( entry ) ) {
                /* entry is a referral */
@@ -718,15 +751,15 @@ ldif_back_referrals( Operation *op, SlapReply *rs )
 static int
 ldif_back_bind( Operation *op, SlapReply *rs )
 {
-       struct ldif_info *ni = NULL;
+       struct ldif_info *li = NULL;
        Attribute * a = NULL;
        AttributeDescription *password = slap_schema.si_ad_userPassword;
        int return_val = 0;
        Entry * entry = NULL;
 
-       ni = (struct ldif_info *) op->o_bd->be_private;
-       ldap_pvt_thread_rdwr_rlock(&ni->li_rdwr);
-       entry = (Entry *) get_entry(op, &ni->li_base_path);
+       li = (struct ldif_info *) op->o_bd->be_private;
+       ldap_pvt_thread_rdwr_rlock(&li->li_rdwr);
+       entry = get_entry(op, &li->li_base_path);
 
        /* no object is found for them */
        if(entry == NULL) {
@@ -758,7 +791,7 @@ ldif_back_bind( Operation *op, SlapReply *rs )
        goto return_result;
 
  return_result:
-       ldap_pvt_thread_rdwr_runlock(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_runlock(&li->li_rdwr);
        if(return_val != 0)
                send_ldap_result( op, rs );
        if(entry != NULL)
@@ -768,21 +801,21 @@ ldif_back_bind( Operation *op, SlapReply *rs )
 
 static int ldif_back_search(Operation *op, SlapReply *rs)
 {
-       struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
+       struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
        enumCookie ck = { NULL, NULL, NULL, 0, 0 };
 
        ck.op = op;
        ck.rs = rs;
-       ldap_pvt_thread_rdwr_rlock(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_rlock(&li->li_rdwr);
        rs->sr_err = enum_tree( &ck );
-       ldap_pvt_thread_rdwr_runlock(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_runlock(&li->li_rdwr);
        send_ldap_result(op, rs);
 
        return rs->sr_err;
 }
 
 static int ldif_back_add(Operation *op, SlapReply *rs) {
-       struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
+       struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
        Entry * e = op->ora_e;
        struct berval dn = e->e_nname;
        struct berval leaf_path = BER_BVNULL;
@@ -800,9 +833,9 @@ static int ldif_back_add(Operation *op, SlapReply *rs) {
                &rs->sr_text, textbuf, sizeof( textbuf ), 1 );
        if ( rs->sr_err != LDAP_SUCCESS ) goto send_res;
 
-       ldap_pvt_thread_rdwr_wlock(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_wlock(&li->li_rdwr);
 
-       dn2path(&dn, &op->o_bd->be_nsuffix[0], &ni->li_base_path, &leaf_path);
+       dn2path(&dn, &op->o_bd->be_nsuffix[0], &li->li_base_path, &leaf_path);
 
        if(leaf_path.bv_val != NULL) {
                struct berval base = BER_BVNULL;
@@ -833,9 +866,7 @@ static int ldif_back_add(Operation *op, SlapReply *rs) {
                if(rs->sr_err == LDAP_SUCCESS) {
                        statres = stat(leaf_path.bv_val, &stats);
                        if(statres == -1 && errno == ENOENT) {
-                               ldap_pvt_thread_mutex_lock(&entry2str_mutex);
-                               rs->sr_err = (int) spew_entry(e, &leaf_path);
-                               ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
+                               rs->sr_err = spew_entry(e, &leaf_path, 1, NULL);
                        }
                        else if ( statres == -1 ) {
                                rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
@@ -849,7 +880,7 @@ static int ldif_back_add(Operation *op, SlapReply *rs) {
                SLAP_FREE(leaf_path.bv_val);
        }
 
-       ldap_pvt_thread_rdwr_wunlock(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_wunlock(&li->li_rdwr);
 
 send_res:
        Debug( LDAP_DEBUG_TRACE, 
@@ -857,11 +888,11 @@ send_res:
                                rs->sr_text : "", 0);
        send_ldap_result(op, rs);
        slap_graduate_commit_csn( op );
-       return 0;
+       return rs->sr_err;
 }
 
 static int ldif_back_modify(Operation *op, SlapReply *rs) {
-       struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
+       struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
        Modifications * modlst = op->orm_modlist;
        struct berval path = BER_BVNULL;
        Entry * entry = NULL;
@@ -869,19 +900,16 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
 
        slap_mods_opattrs( op, &op->orm_modlist, 1 );
 
-       ldap_pvt_thread_rdwr_wlock(&ni->li_rdwr);
-       dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path,
+       ldap_pvt_thread_rdwr_wlock(&li->li_rdwr);
+       dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &li->li_base_path,
                &path);
-       entry = (Entry *) get_entry(op, &ni->li_base_path);
+       entry = get_entry(op, &li->li_base_path);
 
        if(entry != NULL) {
                rs->sr_err = apply_modify_to_entry(entry, modlst, op, rs);
                if(rs->sr_err == LDAP_SUCCESS) {
                        int save_errno;
-                       ldap_pvt_thread_mutex_lock(&entry2str_mutex);
-                       spew_res = spew_entry(entry, &path);
-                       save_errno = errno;
-                       ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
+                       spew_res = spew_entry(entry, &path, 1, &save_errno);
                        if(spew_res == -1) {
                                Debug( LDAP_DEBUG_ANY,
                                        "%s ldif_back_modify: could not output entry \"%s\": %s\n",
@@ -899,14 +927,14 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
        if(path.bv_val != NULL)
                SLAP_FREE(path.bv_val);
        rs->sr_text = NULL;
-       ldap_pvt_thread_rdwr_wunlock(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_wunlock(&li->li_rdwr);
        send_ldap_result(op, rs);
        slap_graduate_commit_csn( op );
-       return 0;
+       return rs->sr_err;
 }
 
 static int ldif_back_delete(Operation *op, SlapReply *rs) {
-       struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
+       struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
        struct berval path = BER_BVNULL;
        int res = 0;
 
@@ -919,32 +947,48 @@ static int ldif_back_delete(Operation *op, SlapReply *rs) {
                slap_get_csn( op, &csn, 1 );
        }
 
-       ldap_pvt_thread_rdwr_wlock(&ni->li_rdwr);
-       dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path, &path);
+       ldap_pvt_thread_rdwr_wlock(&li->li_rdwr);
+       dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &li->li_base_path, &path);
 
        path.bv_val[path.bv_len - STRLENOF(LDIF)] = '\0';
        res = rmdir(path.bv_val);
        path.bv_val[path.bv_len - STRLENOF(LDIF)] = '.';
-       if ( res && errno != ENOENT ) {
-               rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
-       } else {
-               res = unlink(path.bv_val);
-       }
+       rs->sr_err = LDAP_SUCCESS;
+       if ( res ) {
+               switch ( errno ) {
+               case ENOTEMPTY:
+                       rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
+                       break;
 
-       if(res == -1) {
-               if(errno == ENOENT)
+               case ENOENT:
                        rs->sr_err = LDAP_NO_SUCH_OBJECT;
-               else
+                       break;
+
+               default:
                        rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+                       break;
+               }
+
+       } else {
+               res = unlink(path.bv_val);
+               if ( res == -1 ) {
+                       switch ( errno ) {
+                       case ENOENT:
+                               rs->sr_err = LDAP_NO_SUCH_OBJECT;
+                               break;
+
+                       default:
+                               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+                               break;
+                       }
+               }
        }
-       else
-               rs->sr_err = LDAP_SUCCESS;
 
        SLAP_FREE(path.bv_val);
-       ldap_pvt_thread_rdwr_wunlock(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_wunlock(&li->li_rdwr);
        send_ldap_result(op, rs);
        slap_graduate_commit_csn( op );
-       return 0;
+       return rs->sr_err;
 }
 
 
@@ -967,7 +1011,7 @@ static int move_entry(Entry * entry, struct berval * ndn,
                exists_res = open(newpath.bv_val, O_RDONLY);
                if(exists_res == -1 && errno == ENOENT) {
                        ldap_pvt_thread_mutex_lock( &entry2str_mutex );
-                       res = spew_entry(entry, &newpath);
+                       res = spew_entry(entry, &newpath, 0, NULL);
                        if(res != -1) {
                                /* if this fails we should log something bad */
                                res = unlink(path.bv_val);
@@ -1007,7 +1051,7 @@ static int move_entry(Entry * entry, struct berval * ndn,
 static int
 ldif_back_modrdn(Operation *op, SlapReply *rs)
 {
-       struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
+       struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
        struct berval new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
        struct berval p_dn;
        Entry * entry = NULL;
@@ -1015,8 +1059,8 @@ ldif_back_modrdn(Operation *op, SlapReply *rs)
 
        slap_mods_opattrs( op, &op->orr_modlist, 1 );
 
-       ldap_pvt_thread_rdwr_wlock( &ni->li_rdwr );
-       entry = (Entry *) get_entry( op, &ni->li_base_path );
+       ldap_pvt_thread_rdwr_wlock( &li->li_rdwr );
+       entry = get_entry( op, &li->li_base_path );
 
        /* build the mods to the entry */
        if ( entry != NULL ) {
@@ -1030,7 +1074,7 @@ ldif_back_modrdn(Operation *op, SlapReply *rs)
                        p_dn = *op->oq_modrdn.rs_newSup;
                        op->o_req_dn = *op->oq_modrdn.rs_newSup;
                        op->o_req_ndn = *op->oq_modrdn.rs_nnewSup;
-                       np = (Entry *)get_entry( op, &ni->li_base_path );
+                       np = get_entry( op, &li->li_base_path );
                        op->o_req_dn = op_dn;
                        op->o_req_ndn = op_ndn;
                        if ( np == NULL ) {
@@ -1053,7 +1097,7 @@ ldif_back_modrdn(Operation *op, SlapReply *rs)
                        rs->sr_err = move_entry( entry, &op->o_req_ndn,
                                                &new_ndn,
                                                &op->o_bd->be_nsuffix[0],
-                                               &ni->li_base_path );
+                                               &li->li_base_path );
                } else {
                        rs->sr_err = res;
                }
@@ -1067,10 +1111,10 @@ no_such_object:;
                entry_free( entry );
        }
        rs->sr_text = "";
-       ldap_pvt_thread_rdwr_wunlock( &ni->li_rdwr );
+       ldap_pvt_thread_rdwr_wunlock( &li->li_rdwr );
        send_ldap_result( op, rs );
        slap_graduate_commit_csn( op );
-       return 0;
+       return rs->sr_err;
 }
 
 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
@@ -1083,19 +1127,19 @@ int ldif_back_entry_get(
        int rw,
        Entry **ent )
 {
-       struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
+       struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
        struct berval op_dn = op->o_req_dn, op_ndn = op->o_req_ndn;
 
        assert( ndn != NULL );
        assert( !BER_BVISNULL( ndn ) );
 
-       ldap_pvt_thread_rdwr_rlock( &ni->li_rdwr );
+       ldap_pvt_thread_rdwr_rlock( &li->li_rdwr );
        op->o_req_dn = *ndn;
        op->o_req_ndn = *ndn;
-       *ent = (Entry *) get_entry( op, &ni->li_base_path );
+       *ent = get_entry( op, &li->li_base_path );
        op->o_req_dn = op_dn;
        op->o_req_ndn = op_ndn;
-       ldap_pvt_thread_rdwr_runlock( &ni->li_rdwr );
+       ldap_pvt_thread_rdwr_runlock( &li->li_rdwr );
 
        if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
                entry_free( *ent );
@@ -1106,71 +1150,71 @@ int ldif_back_entry_get(
 }
 
 static int ldif_tool_entry_open(BackendDB *be, int mode) {
-       struct ldif_info *ni = (struct ldif_info *) be->be_private;
-       ni->li_tool_current = 0;
+       struct ldif_info *li = (struct ldif_info *) be->be_private;
+       li->li_tool_current = 0;
        return 0;
 }                                      
 
 static int ldif_tool_entry_close(BackendDB * be) {
-       struct ldif_info *ni = (struct ldif_info *) be->be_private;
+       struct ldif_info *li = (struct ldif_info *) be->be_private;
 
-       SLAP_FREE(ni->li_tool_cookie.entries);
+       SLAP_FREE(li->li_tool_cookie.entries);
        return 0;
 }
 
 static ID
 ldif_tool_entry_first(BackendDB *be)
 {
-       struct ldif_info *ni = (struct ldif_info *) be->be_private;
+       struct ldif_info *li = (struct ldif_info *) be->be_private;
        ID id = 1; /* first entry in the array of entries shifted by one */
 
-       ni->li_tool_current = 1;
-       if(ni->li_tool_cookie.entries == NULL) {
+       li->li_tool_current = 1;
+       if(li->li_tool_cookie.entries == NULL) {
                Operation op = {0};
 
                op.o_bd = be;
                op.o_req_dn = *be->be_suffix;
                op.o_req_ndn = *be->be_nsuffix;
                op.ors_scope = LDAP_SCOPE_SUBTREE;
-               ni->li_tool_cookie.op = &op;
-               (void)enum_tree( &ni->li_tool_cookie );
-               ni->li_tool_cookie.op = NULL;
+               li->li_tool_cookie.op = &op;
+               (void)enum_tree( &li->li_tool_cookie );
+               li->li_tool_cookie.op = NULL;
        }
        return id;
 }
 
 static ID ldif_tool_entry_next(BackendDB *be)
 {
-       struct ldif_info *ni = (struct ldif_info *) be->be_private;
-       ni->li_tool_current += 1;
-       if(ni->li_tool_current > ni->li_tool_cookie.eind)
+       struct ldif_info *li = (struct ldif_info *) be->be_private;
+       li->li_tool_current += 1;
+       if(li->li_tool_current > li->li_tool_cookie.eind)
                return NOID;
        else
-               return ni->li_tool_current;
+               return li->li_tool_current;
 }
 
 static Entry * ldif_tool_entry_get(BackendDB * be, ID id) {
-       struct ldif_info *ni = (struct ldif_info *) be->be_private;
+       struct ldif_info *li = (struct ldif_info *) be->be_private;
        Entry * e;
 
-       if(id > ni->li_tool_cookie.eind || id < 1)
+       if(id > li->li_tool_cookie.eind || id < 1)
                return NULL;
        else {
-               e = ni->li_tool_cookie.entries[id - 1];
-               ni->li_tool_cookie.entries[id - 1] = NULL;
+               e = li->li_tool_cookie.entries[id - 1];
+               li->li_tool_cookie.entries[id - 1] = NULL;
                return e;
        }
 }
 
 static ID ldif_tool_entry_put(BackendDB * be, Entry * e, struct berval *text) {
-       struct ldif_info *ni = (struct ldif_info *) be->be_private;
+       struct ldif_info *li = (struct ldif_info *) be->be_private;
        struct berval dn = e->e_nname;
        struct berval leaf_path = BER_BVNULL;
        struct stat stats;
        int statres;
        int res = LDAP_SUCCESS;
 
-       dn2path(&dn, &be->be_nsuffix[0], &ni->li_base_path, &leaf_path);
+       dn2path(&dn, &be->be_nsuffix[0], &li->li_base_path, &leaf_path);
 
        if(leaf_path.bv_val != NULL) {
                struct berval base = BER_BVNULL;
@@ -1197,7 +1241,7 @@ static ID ldif_tool_entry_put(BackendDB * be, Entry * e, struct berval *text) {
                if(res == LDAP_SUCCESS) {
                        statres = stat(leaf_path.bv_val, &stats);
                        if(statres == -1 && errno == ENOENT) {
-                               res = (int) spew_entry(e, &leaf_path);
+                               res = spew_entry(e, &leaf_path, 0, NULL);
                        }
                        else /* it already exists */
                                res = LDAP_ALREADY_EXISTS;
@@ -1216,22 +1260,22 @@ static ID ldif_tool_entry_put(BackendDB * be, Entry * e, struct berval *text) {
 static int
 ldif_back_db_init( BackendDB *be, ConfigReply *cr )
 {
-       struct ldif_info *ni;
+       struct ldif_info *li;
 
-       ni = ch_calloc( 1, sizeof(struct ldif_info) );
-       be->be_private = ni;
+       li = ch_calloc( 1, sizeof(struct ldif_info) );
+       be->be_private = li;
        be->be_cf_ocs = ldifocs;
-       ldap_pvt_thread_rdwr_init(&ni->li_rdwr);
+       ldap_pvt_thread_rdwr_init(&li->li_rdwr);
        return 0;
 }
 
 static int
 ldif_back_db_destroy( Backend *be, ConfigReply *cr )
 {
-       struct ldif_info *ni = be->be_private;
+       struct ldif_info *li = be->be_private;
 
-       ch_free(ni->li_base_path.bv_val);
-       ldap_pvt_thread_rdwr_destroy(&ni->li_rdwr);
+       ch_free(li->li_base_path.bv_val);
+       ldap_pvt_thread_rdwr_destroy(&li->li_rdwr);
        free( be->be_private );
        return 0;
 }
@@ -1239,8 +1283,8 @@ ldif_back_db_destroy( Backend *be, ConfigReply *cr )
 static int
 ldif_back_db_open( Backend *be, ConfigReply *cr)
 {
-       struct ldif_info *ni = (struct ldif_info *) be->be_private;
-       if( BER_BVISEMPTY(&ni->li_base_path)) {/* missing base path */
+       struct ldif_info *li = (struct ldif_info *) be->be_private;
+       if( BER_BVISEMPTY(&li->li_base_path)) {/* missing base path */
                Debug( LDAP_DEBUG_ANY, "missing base path for back-ldif\n", 0, 0, 0);
                return 1;
        }