Bug 316281 - db2bak fails if the archive path exists and ends with '/'
db2bak fails if the archive path exists and ends with '/'
Product: 389
Classification: Community
Component: Command Line Utilities (Show other bugs)
All Linux
high Severity high
: ---
: ---
Assigned To: Noriko Hosoi
Viktor Ashirov
Depends On:
Blocks: 240316 FDS1.1.0
  Show dependency treegraph
Reported: 2007-10-02 18:33 EDT by Noriko Hosoi
Modified: 2015-12-07 11:36 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2015-12-07 11:36:24 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

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

  None (edit)
Description Noriko Hosoi 2007-10-02 18:33:14 EDT
Description of problem:
db2bak /export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/
Back up directory:
[02/Oct/2007:12:04:19 -0700] - db2archive:
/export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/ exists.
Renaming to
[02/Oct/2007:12:04:19 -0700] - db2archive: Failed to rename
"/export/servers/ds72////var/lib/dirsrv/../dirsrv/slapd-laputa0/././/db/" to
-0700] - Netscape Portable Runtime error -5987 (Invalid function argument.)
Comment 1 Noriko Hosoi 2007-10-02 18:44:10 EDT
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 15:15:46 EDT
Created attachment 214951 [details]
cvs commit message

Reviewed by Nathan (Thank you!!)

Checked in into CVS HEAD.
Comment 3 Nathan Kinder 2007-10-08 13:26:06 EDT
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'}


(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
#3  0x0097e2b5 in ldbm_back_ldbm2archive () from
#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
[08/Oct/2007:10:12:16 -0700] - db2archive: Rename (null) back to (null)
Comment 4 Nathan Kinder 2007-10-08 14:38:16 EDT
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 14:41:09 EDT
Thanks a lot, Nathan, for finding out the problem and fixing it!  
Comment 6 Nathan Kinder 2007-10-08 14:45:29 EDT
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
Comment 8 Noriko Hosoi 2007-11-29 16:29:40 EST
Argh...  If the specified back up path only ends with '/' (not including
redundant dirs with dots), the normalization was passed.  I made the condition

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 12:24:03 EST
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.