| OLD | NEW |
| 1 /* crypto/bio/bss_log.c */ | 1 /* crypto/bio/bss_log.c */ |
| 2 /* ==================================================================== | 2 /* ==================================================================== |
| 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 */ | 63 */ |
| 64 | 64 |
| 65 | 65 |
| 66 #include <stdio.h> | 66 #include <stdio.h> |
| 67 #include <errno.h> | 67 #include <errno.h> |
| 68 | 68 |
| 69 #include "cryptlib.h" | 69 #include "cryptlib.h" |
| 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> | |
| 74 #elif defined(OPENSSL_SYS_VMS) | 73 #elif defined(OPENSSL_SYS_VMS) |
| 75 # include <opcdef.h> | 74 # include <opcdef.h> |
| 76 # include <descrip.h> | 75 # include <descrip.h> |
| 77 # include <lib$routines.h> | 76 # include <lib$routines.h> |
| 78 # include <starlet.h> | 77 # include <starlet.h> |
| 78 /* Some compiler options may mask the declaration of "_malloc32". */ |
| 79 # if __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE |
| 80 # if __INITIAL_POINTER_SIZE == 64 |
| 81 # pragma pointer_size save |
| 82 # pragma pointer_size 32 |
| 83 void * _malloc32 (__size_t); |
| 84 # pragma pointer_size restore |
| 85 # endif /* __INITIAL_POINTER_SIZE == 64 */ |
| 86 # endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */ |
| 79 #elif defined(__ultrix) | 87 #elif defined(__ultrix) |
| 80 # include <sys/syslog.h> | 88 # include <sys/syslog.h> |
| 81 #elif defined(OPENSSL_SYS_NETWARE) | 89 #elif defined(OPENSSL_SYS_NETWARE) |
| 82 # define NO_SYSLOG | 90 # define NO_SYSLOG |
| 83 #elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !
defined(NO_SYSLOG) | 91 #elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !
defined(NO_SYSLOG) |
| 84 # include <syslog.h> | 92 # include <syslog.h> |
| 85 #endif | 93 #endif |
| 86 | 94 |
| 87 #include <openssl/buffer.h> | 95 #include <openssl/buffer.h> |
| 88 #include <openssl/err.h> | 96 #include <openssl/err.h> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 115 #endif | 123 #endif |
| 116 | 124 |
| 117 static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num); | 125 static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num); |
| 118 static int MS_CALLBACK slg_puts(BIO *h, const char *str); | 126 static int MS_CALLBACK slg_puts(BIO *h, const char *str); |
| 119 static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 127 static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
| 120 static int MS_CALLBACK slg_new(BIO *h); | 128 static int MS_CALLBACK slg_new(BIO *h); |
| 121 static int MS_CALLBACK slg_free(BIO *data); | 129 static int MS_CALLBACK slg_free(BIO *data); |
| 122 static void xopenlog(BIO* bp, char* name, int level); | 130 static void xopenlog(BIO* bp, char* name, int level); |
| 123 static void xsyslog(BIO* bp, int priority, const char* string); | 131 static void xsyslog(BIO* bp, int priority, const char* string); |
| 124 static void xcloselog(BIO* bp); | 132 static void xcloselog(BIO* bp); |
| 125 #ifdef OPENSSL_SYS_WIN32 | |
| 126 LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx; | |
| 127 HANDLE (WINAPI *register_event_source)() = NULL; | |
| 128 BOOL (WINAPI *deregister_event_source)() = NULL; | |
| 129 BOOL (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 | |
| 137 | 133 |
| 138 static BIO_METHOD methods_slg= | 134 static BIO_METHOD methods_slg= |
| 139 { | 135 { |
| 140 BIO_TYPE_MEM,"syslog", | 136 BIO_TYPE_MEM,"syslog", |
| 141 slg_write, | 137 slg_write, |
| 142 NULL, | 138 NULL, |
| 143 slg_puts, | 139 slg_puts, |
| 144 NULL, | 140 NULL, |
| 145 slg_ctrl, | 141 slg_ctrl, |
| 146 slg_new, | 142 slg_new, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 168 xcloselog(a); | 164 xcloselog(a); |
| 169 return(1); | 165 return(1); |
| 170 } | 166 } |
| 171 | 167 |
| 172 static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl) | 168 static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl) |
| 173 { | 169 { |
| 174 int ret= inl; | 170 int ret= inl; |
| 175 char* buf; | 171 char* buf; |
| 176 char* pp; | 172 char* pp; |
| 177 int priority, i; | 173 int priority, i; |
| 178 » static struct | 174 » static const struct |
| 179 { | 175 { |
| 180 int strl; | 176 int strl; |
| 181 char str[10]; | 177 char str[10]; |
| 182 int log_level; | 178 int log_level; |
| 183 } | 179 } |
| 184 mapping[] = | 180 mapping[] = |
| 185 { | 181 { |
| 186 { 6, "PANIC ", LOG_EMERG }, | 182 { 6, "PANIC ", LOG_EMERG }, |
| 187 { 6, "EMERG ", LOG_EMERG }, | 183 { 6, "EMERG ", LOG_EMERG }, |
| 188 { 4, "EMR ", LOG_EMERG }, | 184 { 4, "EMR ", LOG_EMERG }, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 238 |
| 243 n=strlen(str); | 239 n=strlen(str); |
| 244 ret=slg_write(bp,str,n); | 240 ret=slg_write(bp,str,n); |
| 245 return(ret); | 241 return(ret); |
| 246 } | 242 } |
| 247 | 243 |
| 248 #if defined(OPENSSL_SYS_WIN32) | 244 #if defined(OPENSSL_SYS_WIN32) |
| 249 | 245 |
| 250 static void xopenlog(BIO* bp, char* name, int level) | 246 static void xopenlog(BIO* bp, char* name, int level) |
| 251 { | 247 { |
| 252 » if ( !register_event_source ) | 248 » if (GetVersion() < 0x80000000) |
| 253 » » { | 249 » » bp->ptr = RegisterEventSourceA(NULL,name); |
| 254 » » HANDLE» advapi; | 250 » else |
| 255 » » if ( !(advapi = GetModuleHandle("advapi32")) ) | 251 » » bp->ptr = NULL; |
| 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); | |
| 273 } | 252 } |
| 274 | 253 |
| 275 static void xsyslog(BIO *bp, int priority, const char *string) | 254 static void xsyslog(BIO *bp, int priority, const char *string) |
| 276 { | 255 { |
| 277 LPCSTR lpszStrings[2]; | 256 LPCSTR lpszStrings[2]; |
| 278 WORD evtype= EVENTLOG_ERROR_TYPE; | 257 WORD evtype= EVENTLOG_ERROR_TYPE; |
| 279 » int pid = _getpid(); | 258 » char pidbuf[DECIMAL_SIZE(DWORD)+4]; |
| 280 » char pidbuf[DECIMAL_SIZE(pid)+4]; | 259 |
| 260 » if (bp->ptr == NULL) |
| 261 » » return; |
| 281 | 262 |
| 282 switch (priority) | 263 switch (priority) |
| 283 { | 264 { |
| 284 case LOG_EMERG: | 265 case LOG_EMERG: |
| 285 case LOG_ALERT: | 266 case LOG_ALERT: |
| 286 case LOG_CRIT: | 267 case LOG_CRIT: |
| 287 case LOG_ERR: | 268 case LOG_ERR: |
| 288 evtype = EVENTLOG_ERROR_TYPE; | 269 evtype = EVENTLOG_ERROR_TYPE; |
| 289 break; | 270 break; |
| 290 case LOG_WARNING: | 271 case LOG_WARNING: |
| 291 evtype = EVENTLOG_WARNING_TYPE; | 272 evtype = EVENTLOG_WARNING_TYPE; |
| 292 break; | 273 break; |
| 293 case LOG_NOTICE: | 274 case LOG_NOTICE: |
| 294 case LOG_INFO: | 275 case LOG_INFO: |
| 295 case LOG_DEBUG: | 276 case LOG_DEBUG: |
| 296 evtype = EVENTLOG_INFORMATION_TYPE; | 277 evtype = EVENTLOG_INFORMATION_TYPE; |
| 297 break; | 278 break; |
| 298 default: /* Should never happen, but set it | 279 default: /* Should never happen, but set it |
| 299 as error anyway. */ | 280 as error anyway. */ |
| 300 evtype = EVENTLOG_ERROR_TYPE; | 281 evtype = EVENTLOG_ERROR_TYPE; |
| 301 break; | 282 break; |
| 302 } | 283 } |
| 303 | 284 |
| 304 » sprintf(pidbuf, "[%d] ", pid); | 285 » sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); |
| 305 lpszStrings[0] = pidbuf; | 286 lpszStrings[0] = pidbuf; |
| 306 lpszStrings[1] = string; | 287 lpszStrings[1] = string; |
| 307 | 288 |
| 308 » if(report_event && bp->ptr) | 289 » ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, |
| 309 » » report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0, | |
| 310 lpszStrings, NULL); | 290 lpszStrings, NULL); |
| 311 } | 291 } |
| 312 | 292 |
| 313 static void xcloselog(BIO* bp) | 293 static void xcloselog(BIO* bp) |
| 314 { | 294 { |
| 315 » if(deregister_event_source && bp->ptr) | 295 » if(bp->ptr) |
| 316 » » deregister_event_source((HANDLE)(bp->ptr)); | 296 » » DeregisterEventSource((HANDLE)(bp->ptr)); |
| 317 bp->ptr= NULL; | 297 bp->ptr= NULL; |
| 318 } | 298 } |
| 319 | 299 |
| 320 #elif defined(OPENSSL_SYS_VMS) | 300 #elif defined(OPENSSL_SYS_VMS) |
| 321 | 301 |
| 322 static int VMS_OPC_target = LOG_DAEMON; | 302 static int VMS_OPC_target = LOG_DAEMON; |
| 323 | 303 |
| 324 static void xopenlog(BIO* bp, char* name, int level) | 304 static void xopenlog(BIO* bp, char* name, int level) |
| 325 { | 305 { |
| 326 VMS_OPC_target = level; | 306 VMS_OPC_target = level; |
| 327 } | 307 } |
| 328 | 308 |
| 329 static void xsyslog(BIO *bp, int priority, const char *string) | 309 static void xsyslog(BIO *bp, int priority, const char *string) |
| 330 { | 310 { |
| 331 struct dsc$descriptor_s opc_dsc; | 311 struct dsc$descriptor_s opc_dsc; |
| 312 |
| 313 /* Arrange 32-bit pointer to opcdef buffer and malloc(), if needed. */ |
| 314 #if __INITIAL_POINTER_SIZE == 64 |
| 315 # pragma pointer_size save |
| 316 # pragma pointer_size 32 |
| 317 # define OPCDEF_TYPE __char_ptr32 |
| 318 # define OPCDEF_MALLOC _malloc32 |
| 319 #else /* __INITIAL_POINTER_SIZE == 64 */ |
| 320 # define OPCDEF_TYPE char * |
| 321 # define OPCDEF_MALLOC OPENSSL_malloc |
| 322 #endif /* __INITIAL_POINTER_SIZE == 64 [else] */ |
| 323 |
| 332 struct opcdef *opcdef_p; | 324 struct opcdef *opcdef_p; |
| 325 |
| 326 #if __INITIAL_POINTER_SIZE == 64 |
| 327 # pragma pointer_size restore |
| 328 #endif /* __INITIAL_POINTER_SIZE == 64 */ |
| 329 |
| 333 char buf[10240]; | 330 char buf[10240]; |
| 334 unsigned int len; | 331 unsigned int len; |
| 335 struct dsc$descriptor_s buf_dsc; | 332 struct dsc$descriptor_s buf_dsc; |
| 336 $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); | 333 $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); |
| 337 char *priority_tag; | 334 char *priority_tag; |
| 338 | 335 |
| 339 switch (priority) | 336 switch (priority) |
| 340 { | 337 { |
| 341 case LOG_EMERG: priority_tag = "Emergency"; break; | 338 case LOG_EMERG: priority_tag = "Emergency"; break; |
| 342 case LOG_ALERT: priority_tag = "Alert"; break; | 339 case LOG_ALERT: priority_tag = "Alert"; break; |
| 343 case LOG_CRIT: priority_tag = "Critical"; break; | 340 case LOG_CRIT: priority_tag = "Critical"; break; |
| 344 case LOG_ERR: priority_tag = "Error"; break; | 341 case LOG_ERR: priority_tag = "Error"; break; |
| 345 case LOG_WARNING: priority_tag = "Warning"; break; | 342 case LOG_WARNING: priority_tag = "Warning"; break; |
| 346 case LOG_NOTICE: priority_tag = "Notice"; break; | 343 case LOG_NOTICE: priority_tag = "Notice"; break; |
| 347 case LOG_INFO: priority_tag = "Info"; break; | 344 case LOG_INFO: priority_tag = "Info"; break; |
| 348 case LOG_DEBUG: priority_tag = "DEBUG"; break; | 345 case LOG_DEBUG: priority_tag = "DEBUG"; break; |
| 349 } | 346 } |
| 350 | 347 |
| 351 buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | 348 buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
| 352 buf_dsc.dsc$b_class = DSC$K_CLASS_S; | 349 buf_dsc.dsc$b_class = DSC$K_CLASS_S; |
| 353 buf_dsc.dsc$a_pointer = buf; | 350 buf_dsc.dsc$a_pointer = buf; |
| 354 buf_dsc.dsc$w_length = sizeof(buf) - 1; | 351 buf_dsc.dsc$w_length = sizeof(buf) - 1; |
| 355 | 352 |
| 356 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); | 353 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); |
| 357 | 354 |
| 358 » /* we know there's an 8 byte header. That's documented */ | 355 » /* We know there's an 8-byte header. That's documented. */ |
| 359 » opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len); | 356 » opcdef_p = OPCDEF_MALLOC( 8+ len); |
| 360 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; | 357 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; |
| 361 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); | 358 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); |
| 362 opcdef_p->opc$l_ms_rqstid = 0; | 359 opcdef_p->opc$l_ms_rqstid = 0; |
| 363 memcpy(&opcdef_p->opc$l_ms_text, buf, len); | 360 memcpy(&opcdef_p->opc$l_ms_text, buf, len); |
| 364 | 361 |
| 365 opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | 362 opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
| 366 opc_dsc.dsc$b_class = DSC$K_CLASS_S; | 363 opc_dsc.dsc$b_class = DSC$K_CLASS_S; |
| 367 » opc_dsc.dsc$a_pointer = (char *)opcdef_p; | 364 » opc_dsc.dsc$a_pointer = (OPCDEF_TYPE) opcdef_p; |
| 368 opc_dsc.dsc$w_length = len + 8; | 365 opc_dsc.dsc$w_length = len + 8; |
| 369 | 366 |
| 370 sys$sndopr(opc_dsc, 0); | 367 sys$sndopr(opc_dsc, 0); |
| 371 | 368 |
| 372 OPENSSL_free(opcdef_p); | 369 OPENSSL_free(opcdef_p); |
| 373 } | 370 } |
| 374 | 371 |
| 375 static void xcloselog(BIO* bp) | 372 static void xcloselog(BIO* bp) |
| 376 { | 373 { |
| 377 } | 374 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 393 } | 390 } |
| 394 | 391 |
| 395 static void xcloselog(BIO* bp) | 392 static void xcloselog(BIO* bp) |
| 396 { | 393 { |
| 397 closelog(); | 394 closelog(); |
| 398 } | 395 } |
| 399 | 396 |
| 400 #endif /* Unix */ | 397 #endif /* Unix */ |
| 401 | 398 |
| 402 #endif /* NO_SYSLOG */ | 399 #endif /* NO_SYSLOG */ |
| OLD | NEW |