summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bss_log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/bss_log.c')
-rw-r--r--src/lib/libcrypto/bio/bss_log.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
index 7ead044b37..6360dbc820 100644
--- a/src/lib/libcrypto/bio/bss_log.c
+++ b/src/lib/libcrypto/bio/bss_log.c
@@ -70,6 +70,7 @@
70 70
71#if defined(OPENSSL_SYS_WINCE) 71#if defined(OPENSSL_SYS_WINCE)
72#elif defined(OPENSSL_SYS_WIN32) 72#elif defined(OPENSSL_SYS_WIN32)
73# include <process.h>
73#elif defined(OPENSSL_SYS_VMS) 74#elif defined(OPENSSL_SYS_VMS)
74# include <opcdef.h> 75# include <opcdef.h>
75# include <descrip.h> 76# include <descrip.h>
@@ -121,6 +122,18 @@ static int MS_CALLBACK slg_free(BIO *data);
121static void xopenlog(BIO* bp, char* name, int level); 122static void xopenlog(BIO* bp, char* name, int level);
122static void xsyslog(BIO* bp, int priority, const char* string); 123static void xsyslog(BIO* bp, int priority, const char* string);
123static void xcloselog(BIO* bp); 124static void xcloselog(BIO* bp);
125#ifdef OPENSSL_SYS_WIN32
126LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx;
127HANDLE (WINAPI *register_event_source)() = NULL;
128BOOL (WINAPI *deregister_event_source)() = NULL;
129BOOL (WINAPI *report_event)() = NULL;
130#define DL_PROC(m,f) (GetProcAddress( m, f ))
131#ifdef UNICODE
132#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
133#else
134#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
135#endif
136#endif
124 137
125static BIO_METHOD methods_slg= 138static BIO_METHOD methods_slg=
126 { 139 {
@@ -162,7 +175,7 @@ static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
162 char* buf; 175 char* buf;
163 char* pp; 176 char* pp;
164 int priority, i; 177 int priority, i;
165 static const struct 178 static struct
166 { 179 {
167 int strl; 180 int strl;
168 char str[10]; 181 char str[10];
@@ -236,20 +249,35 @@ static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
236 249
237static void xopenlog(BIO* bp, char* name, int level) 250static void xopenlog(BIO* bp, char* name, int level)
238{ 251{
239 if (GetVersion() < 0x80000000) 252 if ( !register_event_source )
240 bp->ptr = RegisterEventSourceA(NULL,name); 253 {
241 else 254 HANDLE advapi;
242 bp->ptr = NULL; 255 if ( !(advapi = GetModuleHandle("advapi32")) )
256 return;
257 register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
258 "RegisterEventSource" );
259 deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
260 "DeregisterEventSource");
261 report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
262 "ReportEvent" );
263 if ( !(register_event_source && deregister_event_source &&
264 report_event) )
265 {
266 register_event_source = NULL;
267 deregister_event_source = NULL;
268 report_event = NULL;
269 return;
270 }
271 }
272 bp->ptr= (char *)register_event_source(NULL, name);
243} 273}
244 274
245static void xsyslog(BIO *bp, int priority, const char *string) 275static void xsyslog(BIO *bp, int priority, const char *string)
246{ 276{
247 LPCSTR lpszStrings[2]; 277 LPCSTR lpszStrings[2];
248 WORD evtype= EVENTLOG_ERROR_TYPE; 278 WORD evtype= EVENTLOG_ERROR_TYPE;
249 char pidbuf[DECIMAL_SIZE(DWORD)+4]; 279 int pid = _getpid();
250 280 char pidbuf[DECIMAL_SIZE(pid)+4];
251 if (bp->ptr == NULL)
252 return;
253 281
254 switch (priority) 282 switch (priority)
255 { 283 {
@@ -273,18 +301,19 @@ static void xsyslog(BIO *bp, int priority, const char *string)
273 break; 301 break;
274 } 302 }
275 303
276 sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); 304 sprintf(pidbuf, "[%d] ", pid);
277 lpszStrings[0] = pidbuf; 305 lpszStrings[0] = pidbuf;
278 lpszStrings[1] = string; 306 lpszStrings[1] = string;
279 307
280 ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, 308 if(report_event && bp->ptr)
309 report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
281 lpszStrings, NULL); 310 lpszStrings, NULL);
282} 311}
283 312
284static void xcloselog(BIO* bp) 313static void xcloselog(BIO* bp)
285{ 314{
286 if(bp->ptr) 315 if(deregister_event_source && bp->ptr)
287 DeregisterEventSource((HANDLE)(bp->ptr)); 316 deregister_event_source((HANDLE)(bp->ptr));
288 bp->ptr= NULL; 317 bp->ptr= NULL;
289} 318}
290 319