]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1302] OpenSSL under Windows needs applink support.
authorDave Hart <hart@ntp.org>
Sun, 11 Oct 2009 02:36:55 +0000 (02:36 +0000)
committerDave Hart <hart@ntp.org>
Sun, 11 Oct 2009 02:36:55 +0000 (02:36 +0000)
bk: 4ad144c7f6PPWpTVYE-HfJLBUnMy5w

ChangeLog
ports/winnt/ntpd/ntservice.c
util/ntp-keygen.c

index f86a5be54bb2b40e1c8ba9fd3ac529a378df0b51..73a399e162750cf6615de2a1cc0bac0291ab30ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 1302] OpenSSL under Windows needs applink support.
 (4.2.5p231-RC) 2009/10/10 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1335] Broadcast client degraded by wildcard default change.
 (4.2.5p230-RC) 2009/10/09 Released by Harlan Stenn <stenn@ntp.org>
index a4cf01f19ae59203889f03a4d5a25e8d3ff28c5f..11cf708c4526703c16635978a6b89c3dfc68574e 100644 (file)
 #include "ntp_iocompletionport.h"
 #include "isc/win32os.h"
 
+#ifdef OPENSSL
+# pragma warning(push)
+# pragma warning(disable: 4152)
+# include <openssl/applink.c>
+# pragma warning(pop)
+#endif
+
+#if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
+#define WRAP_DBG_MALLOC
+#endif
 
-/* Handle to SCM for updating service status */
+/*
+ * Globals
+ */
 static SERVICE_STATUS_HANDLE hServiceStatus = 0;
 static BOOL foreground = FALSE;
 static BOOL computer_shutting_down = FALSE;
@@ -45,10 +57,16 @@ extern volatile int debug;
 /*
  * Forward declarations
  */
-void           uninit_io_completion_port(void);
-int            ntpdmain(int argc, char *argv[]);
-void WINAPI    ServiceControl(DWORD dwCtrlCode);
-void           ntservice_exit(void);
+void uninit_io_completion_port();
+int ntpdmain(int argc, char *argv[]);
+void WINAPI ServiceControl(DWORD dwCtrlCode);
+void ntservice_exit(void);
+
+#ifdef WRAP_DBG_MALLOC
+void *wrap_dbg_malloc(size_t s, const char *f, int l);
+void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l);
+void wrap_dbg_free(void *p);
+#endif
 
 void WINAPI service_main( DWORD argc, LPTSTR *argv )
 {
@@ -76,6 +94,14 @@ int main( int argc, char *argv[] )
        int rc;
        int i = 1;
 
+
+#ifdef OPENSSL
+#ifdef WRAP_DBG_MALLOC
+       CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+#else
+       CRYPTO_malloc_init();
+#endif
+#endif
        /* Save the command line parameters */
        glb_argc = argc;
        glb_argv = argv;
@@ -88,15 +114,9 @@ int main( int argc, char *argv[] )
        /* Command line users should put -n in the options */
        while (argv[i]) {
                if (!_strnicmp(argv[i], "-d", 2) ||
-                       !strcmp(argv[i], "--debug_level") ||
-                       !strcmp(argv[i], "--set-debug_level") ||
                        !strcmp(argv[i], "-q") ||
-                       !strcmp(argv[i], "--quit") ||
-                       !strcmp(argv[i], "-?") ||
                        !strcmp(argv[i], "--help") ||
-                       !strcmp(argv[i], "-n") ||
-                       !strcmp(argv[i], "--nofork") ||
-                       !strcmp(argv[i], "--saveconfigquit")) {
+                       !strcmp(argv[i], "-n")) {
                        foreground = TRUE;
                        break;
                }
@@ -313,3 +333,25 @@ OnConsoleEvent(
        return TRUE;
 }
 
+
+#if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
+/*
+ * OpenSSL malloc overriding uses different parameters
+ * for DEBUG malloc/realloc/free (lacking block type).
+ * Simple wrappers convert.
+ */
+void *wrap_dbg_malloc(size_t s, const char *f, int l)
+{
+       return _malloc_dbg(s, _NORMAL_BLOCK, f, l);
+}
+
+void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l)
+{
+       return _realloc_dbg(p, s, _NORMAL_BLOCK, f, l);
+}
+
+void wrap_dbg_free(void *p)
+{
+       _free_dbg(p, _NORMAL_BLOCK);
+}
+#endif /* defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG) */
index c5f79714d9be19a83bc789b3526539bb0b612978..ce6381d266ad665dcb96c0c75c1dd2732f086bcc 100644 (file)
 extern int     ntp_getopt      (int, char **, const char *);
 #define getopt ntp_getopt
 #define optarg ntp_optarg
-#endif /* SYS_WINNT */
+#endif /* SYS_WINNT */
 
 #ifdef OPENSSL
 #include "openssl/bn.h"
@@ -111,6 +111,12 @@ extern     int     ntp_getopt      (int, char **, const char *);
 #include "openssl/pem.h"
 #include "openssl/x509v3.h"
 #include <openssl/objects.h>
+#ifdef SYS_WINNT
+# pragma warning(push)
+# pragma warning(disable: 4152)
+# include <openssl/applink.c>
+# pragma warning(pop)
+#endif /* SYS_WINNT */
 #endif /* OPENSSL */
 
 /*