Bug 316281 - db2bak fails if the archive path exists and ends with '/'
Summary: db2bak fails if the archive path exists and ends with '/'
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: 389
Classification: Retired
Component: Command Line Utilities
Version: 1.1.0
Hardware: All
OS: Linux
high
high
Target Milestone: ---
Assignee: Noriko Hosoi
QA Contact: Viktor Ashirov
URL:
Whiteboard:
Depends On:
Blocks: 240316 FDS1.1.0
TreeView+ depends on / blocked
 
Reported: 2007-10-02 22:33 UTC by Noriko Hosoi
Modified: 2015-12-07 16:36 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-12-07 16:36:24 UTC
Embargoed:


Attachments (Terms of Use)
cvs diff ldapserver/ldap/servers/slapd/back-ldbm/archive.c (8.68 KB, patch)
2007-10-02 22:44 UTC, Noriko Hosoi
no flags Details | Diff
cvs commit message (1.07 KB, text/plain)
2007-10-03 19:15 UTC, Noriko Hosoi
no flags Details
CVS Diffs (827 bytes, patch)
2007-10-08 18:38 UTC, Nathan Kinder
no flags Details | Diff
cvs commit message (530 bytes, text/plain)
2007-11-30 17:24 UTC, Noriko Hosoi
no flags Details

Description Noriko Hosoi 2007-10-02 22:33:14 UTC
Description of problem:
db2bak /export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/
Back up directory:
/export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/
[02/Oct/2007:12:04:19 -0700] - db2archive:
/export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/ exists.
Renaming to
/export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/.bak
[02/Oct/2007:12:04:19 -0700] - db2archive: Failed to rename
"/export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/" to
"/export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/.bak".[02/Oct/2007:12:04:19
-0700] - Netscape Portable Runtime error -5987 (Invalid function argument.)

Comment 1 Noriko Hosoi 2007-10-02 22:44:10 UTC
Created attachment 214191 [details]
cvs diff ldapserver/ldap/servers/slapd/back-ldbm/archive.c

Fix description:
1. Use path normalize API rel2abspath to remove the trailing '/'.
2. db2bak renames the archive dir if the directory exists, checks the directory
is the db dir or not.  If it is, the command line rename back the existing db
to the original and exits with the error: db2archive: Cannot archive to the db
directory.    Then, the original dir is renamed back.  If the db2bak runs as a
task (db2bak.pl or console), the server is up and running.  Although the
backend is disabled, we don't want to rename the db path even for a short time.
 That being said, changed the order to: check if the archive dir is the same as
db dir or not.	It exits immediately.

Comment 2 Noriko Hosoi 2007-10-03 19:15:46 UTC
Created attachment 214951 [details]
cvs commit message

Reviewed by Nathan (Thank you!!)

Checked in into CVS HEAD.

Comment 3 Nathan Kinder 2007-10-08 17:26:06 UTC
This fix caused a regression.  If I try to perform a backup via Console, it
causes ns-slapd to SIGSEGV.  Here are some of the details:

Console Debug output:

LDAPTask.initTask(): adding entry LDAPEntry: cn=backup1191863537867,
cn=backup, cn=tasks, cn=config; LDAPAttributeSet: LDAPAttribute
{type='objectclass', values='top,extensibleObject'} LDAPAttribute {type='cn',
values='backup1191863537867'} LDAPAttribute {type='ttl', values='4'}
LDAPAttribute {type='nsArchiveDir',
values='/var/lib/dirsrv/slapd-crunch/bak/2007_10_08_10_11_45'} LDAPAttribute
{type='nsDatabaseType', values='ldbm database'}
LDAPTask.testTaskEntry

Stack:

(gdb) where
#0  0x00a7b777 in opendir () from /lib/tls/libc.so.6
#1  0x00dc472b in PR_OpenDir () from /usr/lib/dirsec/libnspr4.so
#2  0x009bb07f in ldbm_delete_dirs () from
/usr/lib/dirsrv/plugins/libback-ldbm.so
#3  0x0097e2b5 in ldbm_back_ldbm2archive () from
/usr/lib/dirsrv/plugins/libback-ldbm.so
#4  0x006a5a3d in slapi_task_log_status () from /usr/lib/dirsrv/libslapd.so.0
#5  0x00dc5dff in PR_Select () from /usr/lib/dirsec/libnspr4.so
#6  0x001573cc in start_thread () from /lib/tls/libpthread.so.0
#7  0x00abdc3e in clone () from /lib/tls/libc.so.6

Errors Log:

[08/Oct/2007:10:09:55 -0700] - slapd started.  Listening on All Interfaces
port 389 for LDAP requests
[08/Oct/2007:10:12:16 -0700] - Beginning backup of 'ldbm database'
[08/Oct/2007:10:12:16 -0700] - db2archive: mkdir((null)) failed; errno 14 (Bad
address)
[08/Oct/2007:10:12:16 -0700] - db2archive: Rename (null) back to (null)

Comment 4 Nathan Kinder 2007-10-08 18:38:16 UTC
Created attachment 220021 [details]
CVS Diffs

These diffs initialize the normalized backup directory name before checking if
the directory already exists.  The prior case was only performing this
initialization for the case where the backup directory already exists, which
would cause it to be NULL for the other case.  This would cause ns-slapd to
SIGSEGV later.

Comment 5 Noriko Hosoi 2007-10-08 18:41:09 UTC
Thanks a lot, Nathan, for finding out the problem and fixing it!  

Comment 6 Nathan Kinder 2007-10-08 18:45:29 UTC
Checked into ldapserver (HEAD).  Thanks to Noriko for her review!

Checking in archive.c;
/cvs/dirsec/ldapserver/ldap/servers/slapd/back-ldbm/archive.c,v  <--  archive.c
new revision: 1.14; previous revision: 1.13
done

Comment 8 Noriko Hosoi 2007-11-29 21:29:40 UTC
Argh...  If the specified back up path only ends with '/' (not including
redundant dirs with dots), the normalization was passed.  I made the condition
changed.

Index: util.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/util.c,v
retrieving revision 1.15
diff -t -w -U4 -r1.15 util.c
--- util.c      3 Oct 2007 00:55:35 -0000       1.15
+++ util.c      29 Nov 2007 21:26:35 -0000
@@ -528,10 +528,10 @@
             PL_strcatn( abspath, sizeof(abspath), relpath );
         }
     }
     retpath = slapi_ch_strdup(abspath);
-    /* if there's no '.', no need to call normalize_path */
-    if (NULL != strchr(abspath, '.') || NULL != strstr(abspath, _PSEP2))
+    /* if there's no '.' or separators, no need to call normalize_path */
+    if (NULL != strchr(abspath, '.') || NULL != strstr(abspath, _PSEP))
     {
         char **norm_path = normalize_path(abspath);
         char **np, *rp;
         int pathlen = strlen(abspath) + 1;


Comment 9 Noriko Hosoi 2007-11-30 17:24:03 UTC
Created attachment 274021 [details]
cvs commit message

Reviewed by Rich (Thank you!!)

Checked in into CVS HEAD.


Note You need to log in before you can comment on or make changes to this bug.