mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-30 03:29:35 -05:00
Check DB directory validity at config time
This commit is contained in:
parent
e9749fcd7b
commit
a8ba9e2131
1 changed files with 25 additions and 3 deletions
|
|
@ -19,6 +19,7 @@
|
|||
#include <stdio.h>
|
||||
#include <ac/ctype.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/errno.h>
|
||||
|
||||
#include "back-bdb.h"
|
||||
|
||||
|
|
@ -331,8 +332,11 @@ bdb_cf_cleanup( ConfigArgs *c )
|
|||
/* If this fails, we need to restart */
|
||||
if ( rc ) {
|
||||
slapd_shutdown = 2;
|
||||
snprintf( c->cr_msg, sizeof( c->cr_msg ),
|
||||
"failed to reopen database, rc=%d", rc );
|
||||
Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_cf_cleanup)
|
||||
": failed to reopen database, rc=%d", rc, 0, 0 );
|
||||
": %s\n", c->cr_msg, 0, 0 );
|
||||
rc = LDAP_OTHER;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
|
@ -614,7 +618,25 @@ bdb_cf_gen( ConfigArgs *c )
|
|||
|
||||
case BDB_DIRECTORY: {
|
||||
FILE *f;
|
||||
char *ptr;
|
||||
char *ptr, *testpath;
|
||||
int len;
|
||||
|
||||
len = strlen( c->value_string );
|
||||
testpath = ch_malloc( len + STRLENOF(LDAP_DIRSEP) + STRLENOF("DUMMY") + 1 );
|
||||
ptr = lutil_strcopy( testpath, c->value_string );
|
||||
*ptr++ = LDAP_DIRSEP[0];
|
||||
strcpy( ptr, "DUMMY" );
|
||||
f = fopen( testpath, "w" );
|
||||
if ( f ) {
|
||||
fclose( f );
|
||||
unlink( testpath );
|
||||
}
|
||||
ch_free( testpath );
|
||||
if ( !f ) {
|
||||
snprintf( c->cr_msg, sizeof( c->cr_msg ), "invalid path: %s", strerror( errno ));
|
||||
Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( bdb->bi_dbenv_home )
|
||||
ch_free( bdb->bi_dbenv_home );
|
||||
|
|
@ -623,7 +645,7 @@ bdb_cf_gen( ConfigArgs *c )
|
|||
/* See if a DB_CONFIG file already exists here */
|
||||
if ( bdb->bi_db_config_path )
|
||||
ch_free( bdb->bi_db_config_path );
|
||||
bdb->bi_db_config_path = ch_malloc( strlen( bdb->bi_dbenv_home ) +
|
||||
bdb->bi_db_config_path = ch_malloc( len +
|
||||
STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
|
||||
ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
|
||||
*ptr++ = LDAP_DIRSEP[0];
|
||||
|
|
|
|||
Loading…
Reference in a new issue