Startup check for mismatched OpenSSL library versions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 6 Feb 2013 01:19:50 +0000 (20:19 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 6 Feb 2013 01:23:40 +0000 (20:23 -0500)
Print OpenSSL version in debug output

Conflicts:
src/main/version.c

src/include/radiusd.h
src/main/radiusd.c
src/main/version.c

index 43e455f..0c77a01 100644 (file)
@@ -524,6 +524,8 @@ int         pairlist_read(const char *file, PAIR_LIST **list, int complain);
 void           pairlist_free(PAIR_LIST **);
 
 /* version.c */
+int            ssl_check_version(void);
+const char     *ssl_version(void);
 void           version(void);
 
 /* log.c */
index 4651052..556cef2 100644 (file)
@@ -253,6 +253,14 @@ int main(int argc, char *argv[])
                }
        }
 
+       /*
+        *      Mismatch between build time OpenSSL and linked SSL,
+        *      better to die here than segfault later.
+        */
+       if (ssl_check_version() < 0) {
+               exit(1);
+       }
+
        if (flag && (flag != 0x03)) {
                fprintf(stderr, "radiusd: The options -i and -p cannot be used individually.\n");
                exit(1);
@@ -260,6 +268,7 @@ int main(int argc, char *argv[])
 
        if (debug_flag)
                version();
+               
 
        /*  Read the configuration files, BEFORE doing anything else.  */
        if (read_mainconfig(0) < 0) {
@@ -327,6 +336,10 @@ int main(int argc, char *argv[])
        } else {
                setlinebuf(stdout); /* unbuffered output */
        }
+       
+       /*
+        *      Now we have logging check that the OpenSSL 
+        */
 
        /*
         *      Initialize the event pool, including threads.
index ebb0fb3..a3a6ad7 100644 (file)
@@ -27,6 +27,57 @@ RCSID("$Id$")
 
 #include <freeradius-devel/radiusd.h>
 
+
+#ifdef HAVE_OPENSSL_CRYPTO_H
+#include <openssl/crypto.h>
+#include <openssl/opensslv.h>
+
+static long ssl_built = OPENSSL_VERSION_NUMBER;
+
+/** Check build and linked versions of OpenSSL match
+ *
+ * Startup check for whether the linked version of OpenSSL matches the
+ * version the server was built against.
+ *
+ * @return 0 if ok, else -1
+ */
+int ssl_check_version(void)
+{
+       long ssl_linked;
+       
+       ssl_linked = SSLeay();
+       
+       if (ssl_linked != ssl_built) {
+               radlog(L_ERR, "libssl version mismatch."
+                      "  Built with: %lx\n  Linked: %lx",
+                      (unsigned long) ssl_built,
+                      (unsigned long) ssl_linked);
+       
+               return -1;
+       };
+       
+       return 0;
+}
+
+/** Print the current linked version of Openssl
+ *
+ * Print the currently linked version of the OpenSSL library.
+ */
+const char *ssl_version(void)
+{
+       return SSLeay_version(SSLEAY_VERSION); 
+}
+#else
+int ssl_version_check(void) {
+       return 0;
+}
+
+const char *ssl_version()
+{
+       return "not linked"
+}
+#endif
+
 /*
  *     Display the revision number for this program
  */
@@ -34,8 +85,12 @@ void version(void)
 {
 
        radlog(L_INFO, "%s: %s", progname, radiusd_version);
-       DEBUG3("Compilation flags: ");
-
+       DEBUG3("Server was built with: ");
+               
+#ifdef WITH_ACCOUNTING
+       DEBUG3("  accounting");
+#endif
+       DEBUG3("  authentication"); /* always enabled */
        /* here are all the conditional feature flags */
 #if defined(WITH_DHCP)
        DEBUG3(" WITH_DHCP");
@@ -73,7 +128,10 @@ void version(void)
 #if defined(WITHOUT_COA)
        DEBUG3(" WITHOUT_COA");
 #endif
-       radlog(L_INFO, "Copyright (C) 1999-2012 The FreeRADIUS server project and contributors.");
+       DEBUG3("Server core libs:");
+       DEBUG3("  ssl: %s", ssl_version());
+
+       radlog(L_INFO, "Copyright (C) 1999-2013 The FreeRADIUS server project and contributors.");
        radlog(L_INFO, "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A");
        radlog(L_INFO, "PARTICULAR PURPOSE.");
        radlog(L_INFO, "You may redistribute copies of FreeRADIUS under the terms of the");