From: Dave Hart Date: Sun, 11 Oct 2009 02:36:55 +0000 (+0000) Subject: [Bug 1302] OpenSSL under Windows needs applink support. X-Git-Tag: NTP_4_2_5P232_RC~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e02f3244ba98d47e0b8076b67262fb66fe33b9b;p=thirdparty%2Fntp.git [Bug 1302] OpenSSL under Windows needs applink support. bk: 4ad144c7f6PPWpTVYE-HfJLBUnMy5w --- diff --git a/ChangeLog b/ChangeLog index f86a5be54..73a399e16 100644 --- 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 * [Bug 1335] Broadcast client degraded by wildcard default change. (4.2.5p230-RC) 2009/10/09 Released by Harlan Stenn diff --git a/ports/winnt/ntpd/ntservice.c b/ports/winnt/ntpd/ntservice.c index a4cf01f19..11cf708c4 100644 --- a/ports/winnt/ntpd/ntservice.c +++ b/ports/winnt/ntpd/ntservice.c @@ -31,8 +31,20 @@ #include "ntp_iocompletionport.h" #include "isc/win32os.h" +#ifdef OPENSSL +# pragma warning(push) +# pragma warning(disable: 4152) +# include +# 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) */ diff --git a/util/ntp-keygen.c b/util/ntp-keygen.c index c5f79714d..ce6381d26 100644 --- a/util/ntp-keygen.c +++ b/util/ntp-keygen.c @@ -101,7 +101,7 @@ 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 +#ifdef SYS_WINNT +# pragma warning(push) +# pragma warning(disable: 4152) +# include +# pragma warning(pop) +#endif /* SYS_WINNT */ #endif /* OPENSSL */ /*