diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/bio/bss_log.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/crypto/bio/bss_log.c b/crypto/bio/bss_log.c index be2ad38383..d5f905b62b 100644 --- a/crypto/bio/bss_log.c +++ b/crypto/bio/bss_log.c @@ -118,6 +118,18 @@ static int MS_CALLBACK slg_free(BIO *data); static void xopenlog(BIO* bp, const char* name, int level); static void xsyslog(BIO* bp, int priority, const char* string); static void xcloselog(BIO* bp); +#ifdef WIN32 +LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx; +HANDLE (WINAPI *register_event_source)() = NULL; +BOOL (WINAPI *deregister_event_source)() = NULL; +BOOL (WINAPI *report_event)() = NULL; +#define DL_PROC(m,f) (GetProcAddress( m, f )) +#ifdef UNICODE +#define DL_PROC_X(m,f) DL_PROC( m, f "W" ) +#else +#define DL_PROC_X(m,f) DL_PROC( m, f "A" ) +#endif +#endif static BIO_METHOD methods_slg= { @@ -213,7 +225,27 @@ static int MS_CALLBACK slg_puts(BIO *bp, const char *str) static void xopenlog(BIO* bp, const char* name, int level) { - bp->ptr= (char *)RegisterEventSource(NULL, name); + if ( !register_event_source ) + { + HANDLE advapi; + if ( !(advapi = GetModuleHandle("advapi32")) ) + return; + register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi, + "RegisterEventSource" ); + deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi, + "DeregisterEventSource"); + report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi, + "ReportEvent" ); + if ( !(register_event_source && deregister_event_source && + report_event) ) + { + register_event_source = NULL; + deregister_event_source = NULL; + report_event = NULL; + return; + } + } + bp->ptr= (char *)register_event_source(NULL, name); } static void xsyslog(BIO *bp, int priority, const char *string) @@ -243,15 +275,15 @@ static void xsyslog(BIO *bp, int priority, const char *string) lpszStrings[0] = pidbuf; lpszStrings[1] = string; - if(bp->ptr) - ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0, + if(report_event && bp->ptr) + report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0, lpszStrings, NULL); } static void xcloselog(BIO* bp) { - if(bp->ptr) - DeregisterEventSource((HANDLE)(bp->ptr)); + if(deregister_event_source && bp->ptr) + deregister_event_source((HANDLE)(bp->ptr)); bp->ptr= NULL; } |