]> git.sur5r.net Git - openldap/commitdiff
db config validity check
authorQuanah Gibson-Mount <quanah@openldap.org>
Thu, 18 Oct 2007 03:03:41 +0000 (03:03 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 18 Oct 2007 03:03:41 +0000 (03:03 +0000)
error message propagation fix

servers/slapd/back-bdb/config.c
servers/slapd/bconfig.c

index 3844629cb4bf734c70b38a190a55726586a55a87..32291d7d054e773848e191cc913088d1a1fc9886 100644 (file)
@@ -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,26 @@ 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 ), "%s: invalid path: %s",
+                               c->log, strerror( errno ));
+                       Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
+                       return -1;
+               }
 
                if ( bdb->bi_dbenv_home )
                        ch_free( bdb->bi_dbenv_home );
@@ -623,7 +646,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];
index 0cf122727fbe5758de85612820d2b0f85ce65f5c..451045bf93d69cf2a69991792f021a28d96e1c92 100644 (file)
@@ -77,6 +77,7 @@ typedef struct {
 static CfBackInfo cfBackInfo;
 
 static char    *passwd_salt;
+static FILE *logfile;
 static char    *logfileName;
 #ifdef SLAP_AUTH_REWRITE
 static BerVarray authz_rewrites;
@@ -1124,6 +1125,10 @@ config_generic(ConfigArgs *c) {
                case CFG_LOGFILE:
                        ch_free( logfileName );
                        logfileName = NULL;
+                       if ( logfile ) {
+                               fclose( logfile );
+                               logfile = NULL;
+                       }
                        break;
 
                case CFG_SERVERID: {
@@ -1683,7 +1688,6 @@ sortval_reject:
                        }
                        break;
                case CFG_LOGFILE: {
-                               FILE *logfile;
                                if ( logfileName ) ch_free( logfileName );
                                logfileName = c->value_string;
                                logfile = fopen(logfileName, "w");
@@ -4826,6 +4830,7 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
 out:
        /* Undo for a failed operation */
        if ( rc != LDAP_SUCCESS ) {
+               ConfigReply msg = ca->reply;
                for ( s = save_attrs; s; s = s->a_next ) {
                        if ( s->a_flags & SLAP_ATTR_IXDEL ) {
                                s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
@@ -4862,6 +4867,7 @@ out:
                                }
                        }
                }
+               ca->reply = msg;
        }
 
        if ( ca->cleanup )
@@ -4928,8 +4934,7 @@ config_back_modify( Operation *op, SlapReply *rs )
 
        slap_mods_opattrs( op, &op->orm_modlist, 1 );
 
-       if ( !slapd_shutdown )
-               ldap_pvt_thread_pool_pause( &connection_pool );
+       ldap_pvt_thread_pool_pause( &connection_pool );
 
        /* Strategy:
         * 1) perform the Modify on the cached Entry.
@@ -4961,8 +4966,7 @@ config_back_modify( Operation *op, SlapReply *rs )
                op->o_ndn = ndn;
        }
 
-       if ( !slapd_shutdown )
-               ldap_pvt_thread_pool_resume( &connection_pool );
+       ldap_pvt_thread_pool_resume( &connection_pool );
 out:
        send_ldap_result( op, rs );
        slap_graduate_commit_csn( op );