Bug 231093 - db2bak: crash bug
Summary: db2bak: crash bug
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: 389
Classification: Retired
Component: Database - General
Version: 1.0.4
Hardware: All
OS: Linux
high
high
Target Milestone: ---
Assignee: Noriko Hosoi
QA Contact: Viktor Ashirov
URL:
Whiteboard:
Depends On:
Blocks: 152373 240316 FDS1.1.0
TreeView+ depends on / blocked
 
Reported: 2007-03-06 02:25 UTC by Noriko Hosoi
Modified: 2015-12-07 16:37 UTC (History)
0 users

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


Attachments (Terms of Use)
cvs diff dblayer.c (12.18 KB, patch)
2007-03-06 02:45 UTC, Noriko Hosoi
no flags Details | Diff
cvs diffs (10.05 KB, patch)
2007-12-03 23:21 UTC, Noriko Hosoi
no flags Details | Diff
test cases and results (2.56 KB, text/plain)
2007-12-03 23:48 UTC, Noriko Hosoi
no flags Details
revised ldbm_config.c (6.48 KB, patch)
2007-12-04 00:49 UTC, Noriko Hosoi
no flags Details | Diff
cvs commit message (1.64 KB, text/plain)
2007-12-04 00:51 UTC, Noriko Hosoi
no flags Details

Description Noriko Hosoi 2007-03-06 02:25:09 UTC
Description of problem:
Occurred in the falied test cases.  Caused by the initial configuration error:
    errors:[...] - Db home directory is not set. Possibly nsslapd-directory
(optinally nsslapd-db-home-directory) is missing in the config file.

Still, the server should not crash.

[stacktrace]
#0  0xb6edd2c7 in dblayer_get_full_inst_dir (li=0x8127350, inst=0x8187f00,
    buf=0xbfffc480 "", buflen=4096)
    at ldap/servers/slapd/back-ldbm/dblayer.c:1209
#1  0xb6ee4d42 in dblayer_in_import (inst=0x8187f00)
    at ldap/servers/slapd/back-ldbm/dblayer.c:5623
#2  0xb6ed8bd0 in ldbm_back_ldbm2archive (pb=0xbfffd570)
    at ldap/servers/slapd/back-ldbm/archive.c:353
#3  0x0805d59e in slapd_exemode_db2archive () at ldap/servers/slapd/main.c:2457
#4  0x0805e5e7 in main (argc=6, argv=0xbfffdca4)
    at ldap/servers/slapd/main.c:947

Comment 1 Noriko Hosoi 2007-03-06 02:45:16 UTC
Created attachment 149315 [details]
cvs diff dblayer.c

File: ldap/servers/slapd/back-ldbm/dblayer.c

Problem description: 
The server instance home directory in the dblayer private structure
(li->li_dblayer_private) is empty.  Either of these fields is supposed to be
set:
  dblayer_home_directory = 0x0
  dblayer_dbhome_directory = 0x8125ba0 ""

Fix descrption: if the fields are not set, issues an error message and returns.

Comment 2 Rich Megginson 2007-03-06 15:56:03 UTC
In this code:
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec3

Do you need to initialize inst->inst_parent_dir_name, or is it already
initialized to NULL?

In this code:
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec5

Do you need to initialize priv->dblayer_home_directory to NULL?

In this code:
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec6

Do you need to initialize envdir to NULL?

In this code:
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec12

Do you need to initialize dirhandle to NULL?


Comment 3 Noriko Hosoi 2007-03-06 18:23:17 UTC
Thanks for the comments, Rich.

(In reply to comment #2)
> In this code:
>
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec3
>
> Do you need to initialize inst->inst_parent_dir_name, or is it already
> initialized to NULL?

The structure ldbm_instance (inst) is allocated in ldbm_instance_create, where
the field is initialized to NULL.

> In this code:
>
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec5
>
> Do you need to initialize priv->dblayer_home_directory to NULL?

The structure "dblayer_private" is allocated in dblayer_init, where the field is
initialized to NULL.  And the attribute value of nsslapd-directory is set in
dblayer_start.

> In this code:
>
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec6
>
> Do you need to initialize envdir to NULL?

I think it is.
   2269 int dblayer_release_aux_id2entry(backend *be, DB *pDB, DB_ENV *pEnv)
   2270 {
   2271     ldbm_instance *inst;
   2272     char *envdir = NULL;
    [...]
   2284     inst_dirp = dblayer_get_full_inst_dir(inst->inst_li, inst,
   2285                                           inst_dir, MAXPATHLEN);
   2286     if (inst_dirp && *inst_dirp)
   2287     {
   2288         envdir = slapi_ch_smprintf("%s/dbenv", inst_dirp);
   2289     }

> In this code:
>
https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=149315&action=diff#dblayer.c_sec12
>
> Do you need to initialize dirhandle to NULL?

I think it is.
   4111 static int _dblayer_delete_instance_dir(ldbm_instance *inst, int startdb
       )
   4112 {
   4113     PRDir *dirhandle = NULL;
    [...]
   4146     inst_dirp = dblayer_get_full_inst_dir(li, inst, inst_dir, MAXPATHLEN
       );
   4147     if (inst_dirp && *inst_dirp) {
   4148         dirhandle = PR_OpenDir(inst_dirp);
   4149     }

Comment 4 Noriko Hosoi 2007-03-15 21:37:01 UTC
Checked in with 232050: Change format of DBVERSION and guardian files
Checking in dblayer.c;
/cvs/dirsec/ldapserver/ldap/servers/slapd/back-ldbm/dblayer.c,v  <--  dblayer.c
new revision: 1.18; previous revision: 1.17
done


Comment 5 Noriko Hosoi 2007-11-29 01:16:17 UTC
Steps to reproduce:
1. stop the server
2. edit dse.ldif to remove nsslapd-directory and nsslapd-db-home-directory.
3. run db2bak

Note: the server's owner should be non root (e.g., nobody)

If the command line fails with errors as follows instead of crashes, it's okay.
[...]
[...] - WARNING---no write permission to file /usr/sbin//vgexport
[...] - libdb: /usr/sbin/__db.001: Permission denied
[...] - Opening database environment (/usr/sbin/) failed. err=13: Permission denied
[...] - db2archive: Failed to init database


Comment 6 Chandrasekar Kannan 2007-11-29 22:16:43 UTC
Tried the above steps. when I run db2bak, I get these messages.

[root@colossus slapd-colossus]# ./db2bak
Back up directory: /var/lib/dirsrv/slapd-colossus/bak/colossus-2007_11_29_14_03_58
[29/Nov/2007:14:03:58 -0800] - WARNING---no write permission to file
/usr/sbin//amreport
[29/Nov/2007:14:03:58 -0800] - WARNING---no write permission to file
/usr/sbin//tcpslice
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file
/usr/sbin//semodule
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file
/usr/sbin//named-checkconf
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file
/usr/sbin//genhomedircon
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file /usr/sbin//ripd
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file
/usr/sbin//lockdev
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file
/usr/sbin//postqueue
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file
/usr/sbin//foomatic-ppdload
[29/Nov/2007:14:03:59 -0800] - WARNING---no write permission to file
/usr/sbin//setup-ds-admin.pl

...
...

[29/Nov/2007:14:04:00 -0800] - libdb: /usr/sbin/__db.001: Permission denied
[29/Nov/2007:14:04:00 -0800] - Opening database environment (/usr/sbin/) failed.
err=13: Permission denied
[29/Nov/2007:14:04:00 -0800] - db2archive: Failed to init database

######################################################################
db2bak is attempting to write to each file in /usr/sbin/. that seems
wrong to me. 

if the variable nsslapd-directory is not set in dse.ldif, db2bak 
should print out a message saying, this variable is not set (OR)
dont have permission to write to value defined in nsslapd-directory
and quit.

Comment 7 Noriko Hosoi 2007-12-03 23:21:18 UTC
Created attachment 276401 [details]
cvs diffs

Files:
 ldbm_config.h
 ldbm_instance_config.c
 ldbm_config.c
 dblayer.c
 start.c

Description:
Set the strong requirement: nsslapd-directory must have some value.
to guarantee it:
1) checking errors from ldbm_config_directory_set. If the check fails, don't
start the server.
2) if nsslapd-directory does not exist or the value is empty in dse.ldif,
issuing an error message and returning the error code.
3) since it was difficult to distinguish the nsslapd-directory empty value from
the initial default value, introduced CONFIG_FLAG_SKIP_DEFAULT_SETTING flag to
tell the backend config code to skip setting the default value.

Comment 8 Noriko Hosoi 2007-12-03 23:48:21 UTC
Created attachment 276431 [details]
test cases and results

Comment 9 Rich Megginson 2007-12-04 00:01:07 UTC
If there is a problem with the entry, does it print the DN of the entry?

Comment 10 Noriko Hosoi 2007-12-04 00:47:06 UTC
Good idea!  I've added the backend config entry to the error message:
[..] - ERROR: db directory is not set; check nsslapd-directory in the db config:
cn=config,cn=ldbm database,cn=plugins,cn=config


Comment 11 Noriko Hosoi 2007-12-04 00:49:23 UTC
Created attachment 276451 [details]
revised ldbm_config.c

This diff includes the suggestion from Rich and PL_strcmp fix.

Comment 12 Noriko Hosoi 2007-12-04 00:51:31 UTC
Created attachment 276461 [details]
cvs commit message

Thank you to Rich for the reviews and comments.

Checked in into CVS HEAD.


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