]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Check broken ssl-parameters.dat files better and give a better error message when...
authorTimo Sirainen <tss@iki.fi>
Tue, 13 Jan 2009 18:13:19 +0000 (13:13 -0500)
committerTimo Sirainen <tss@iki.fi>
Tue, 13 Jan 2009 18:13:19 +0000 (13:13 -0500)
--HG--
branch : HEAD

src/login-common/Makefile.am
src/login-common/ssl-proxy-openssl.c

index 89d45a947b244c925a3d5827e4b82a9904441514..e2b64af373a2c40334356f1523c75593bdeb295e 100644 (file)
@@ -4,6 +4,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib \
        -I$(top_srcdir)/src/lib-auth \
        -DPKG_RUNDIR=\""$(rundir)"\" \
+       -DPKG_STATEDIR=\""$(statedir)"\" \
        -DSBINDIR=\""$(sbindir)"\"
 
 liblogin_common_a_SOURCES = \
index a5ac0ec37eee9aa42298656bc0246595f1a8682c..7fb9cffd5d92d6a6b4e512e6c0f6881b0b99075f 100644 (file)
@@ -78,6 +78,13 @@ static void ssl_step(struct ssl_proxy *proxy);
 static void ssl_proxy_destroy(struct ssl_proxy *proxy);
 static void ssl_proxy_unref(struct ssl_proxy *proxy);
 
+static void ssl_params_corrupted(const char *path)
+{
+       i_fatal("Corrupted SSL parameters file: %s/%s "
+               "(delete it and also the one in %s)",
+               getenv("LOGIN_DIR"), path, PKG_STATEDIR);
+}
+
 static void read_next(struct ssl_parameters *params, void *data, size_t size)
 {
        int ret;
@@ -85,7 +92,7 @@ static void read_next(struct ssl_parameters *params, void *data, size_t size)
        if ((ret = read_full(params->fd, data, size)) < 0)
                i_fatal("read(%s) failed: %m", params->fname);
        if (ret == 0)
-               i_fatal("read(%s) failed: Unexpected EOF", params->fname);
+               ssl_params_corrupted(params->fname);
 }
 
 static bool read_dh_parameters_next(struct ssl_parameters *params)
@@ -104,7 +111,7 @@ static bool read_dh_parameters_next(struct ssl_parameters *params)
        /* read data size. */
        read_next(params, &len, sizeof(len));
        if (len > 1024*100) /* should be enough? */
-               i_fatal("Corrupted SSL parameters file: %s", params->fname);
+               ssl_params_corrupted(params->fname);
 
        buf = i_malloc(len);
        read_next(params, buf, len);
@@ -117,6 +124,8 @@ static bool read_dh_parameters_next(struct ssl_parameters *params)
        case 1024:
                params->dh_1024 = d2i_DHparams(NULL, &cbuf, len);
                break;
+       default:
+               ssl_params_corrupted(params->fname);
        }
 
        i_free(buf);
@@ -138,6 +147,8 @@ static void ssl_free_parameters(struct ssl_parameters *params)
 static void ssl_read_parameters(struct ssl_parameters *params)
 {
        struct stat st;
+       ssize_t ret;
+       char c;
        bool warned = FALSE;
 
        /* we'll wait until parameter file exists */
@@ -167,6 +178,13 @@ static void ssl_read_parameters(struct ssl_parameters *params)
        ssl_free_parameters(params);
        while (read_dh_parameters_next(params)) ;
 
+       if ((ret = read_full(params->fd, &c, 1)) < 0)
+               i_fatal("read(%s) failed: %m", params->fname);
+       else if (ret != 0) {
+               /* more data than expected */
+               ssl_params_corrupted(params->fname);
+       }
+
        if (close(params->fd) < 0)
                i_error("close() failed: %m");
        params->fd = -1;