diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_log.c')
| -rw-r--r-- | src/lib/libcrypto/bio/bss_log.c | 130 |
1 files changed, 94 insertions, 36 deletions
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c index 497eb1af72..1edf16a76f 100644 --- a/src/lib/libcrypto/bio/bss_log.c +++ b/src/lib/libcrypto/bio/bss_log.c | |||
| @@ -110,14 +110,26 @@ | |||
| 110 | #define LOG_DAEMON OPC$M_NM_NTWORK | 110 | #define LOG_DAEMON OPC$M_NM_NTWORK |
| 111 | #endif | 111 | #endif |
| 112 | 112 | ||
| 113 | static int MS_CALLBACK slg_write(BIO *h,char *buf,int num); | 113 | static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num); |
| 114 | static int MS_CALLBACK slg_puts(BIO *h,char *str); | 114 | static int MS_CALLBACK slg_puts(BIO *h, const char *str); |
| 115 | static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2); | 115 | static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
| 116 | static int MS_CALLBACK slg_new(BIO *h); | 116 | static int MS_CALLBACK slg_new(BIO *h); |
| 117 | static int MS_CALLBACK slg_free(BIO *data); | 117 | static int MS_CALLBACK slg_free(BIO *data); |
| 118 | static void xopenlog(BIO* bp, const char* name, int level); | 118 | static void xopenlog(BIO* bp, char* name, int level); |
| 119 | static void xsyslog(BIO* bp, int priority, const char* string); | 119 | static void xsyslog(BIO* bp, int priority, const char* string); |
| 120 | static void xcloselog(BIO* bp); | 120 | static void xcloselog(BIO* bp); |
| 121 | #ifdef WIN32 | ||
| 122 | LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx; | ||
| 123 | HANDLE (WINAPI *register_event_source)() = NULL; | ||
| 124 | BOOL (WINAPI *deregister_event_source)() = NULL; | ||
| 125 | BOOL (WINAPI *report_event)() = NULL; | ||
| 126 | #define DL_PROC(m,f) (GetProcAddress( m, f )) | ||
| 127 | #ifdef UNICODE | ||
| 128 | #define DL_PROC_X(m,f) DL_PROC( m, f "W" ) | ||
| 129 | #else | ||
| 130 | #define DL_PROC_X(m,f) DL_PROC( m, f "A" ) | ||
| 131 | #endif | ||
| 132 | #endif | ||
| 121 | 133 | ||
| 122 | static BIO_METHOD methods_slg= | 134 | static BIO_METHOD methods_slg= |
| 123 | { | 135 | { |
| @@ -153,40 +165,60 @@ static int MS_CALLBACK slg_free(BIO *a) | |||
| 153 | return(1); | 165 | return(1); |
| 154 | } | 166 | } |
| 155 | 167 | ||
| 156 | static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) | 168 | static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl) |
| 157 | { | 169 | { |
| 158 | int ret= inl; | 170 | int ret= inl; |
| 159 | char* buf= in; | 171 | char* buf; |
| 160 | char* pp; | 172 | char* pp; |
| 161 | int priority; | 173 | int priority, i; |
| 162 | 174 | static struct | |
| 163 | if((buf= (char *)Malloc(inl+ 1)) == NULL){ | 175 | { |
| 176 | int strl; | ||
| 177 | char str[10]; | ||
| 178 | int log_level; | ||
| 179 | } | ||
| 180 | mapping[] = | ||
| 181 | { | ||
| 182 | { 6, "PANIC ", LOG_EMERG }, | ||
| 183 | { 6, "EMERG ", LOG_EMERG }, | ||
| 184 | { 4, "EMR ", LOG_EMERG }, | ||
| 185 | { 6, "ALERT ", LOG_ALERT }, | ||
| 186 | { 4, "ALR ", LOG_ALERT }, | ||
| 187 | { 5, "CRIT ", LOG_CRIT }, | ||
| 188 | { 4, "CRI ", LOG_CRIT }, | ||
| 189 | { 6, "ERROR ", LOG_ERR }, | ||
| 190 | { 4, "ERR ", LOG_ERR }, | ||
| 191 | { 8, "WARNING ", LOG_WARNING }, | ||
| 192 | { 5, "WARN ", LOG_WARNING }, | ||
| 193 | { 4, "WAR ", LOG_WARNING }, | ||
| 194 | { 7, "NOTICE ", LOG_NOTICE }, | ||
| 195 | { 5, "NOTE ", LOG_NOTICE }, | ||
| 196 | { 4, "NOT ", LOG_NOTICE }, | ||
| 197 | { 5, "INFO ", LOG_INFO }, | ||
| 198 | { 4, "INF ", LOG_INFO }, | ||
| 199 | { 6, "DEBUG ", LOG_DEBUG }, | ||
| 200 | { 4, "DBG ", LOG_DEBUG }, | ||
| 201 | { 0, "", LOG_ERR } /* The default */ | ||
| 202 | }; | ||
| 203 | |||
| 204 | if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){ | ||
| 164 | return(0); | 205 | return(0); |
| 165 | } | 206 | } |
| 166 | strncpy(buf, in, inl); | 207 | strncpy(buf, in, inl); |
| 167 | buf[inl]= '\0'; | 208 | buf[inl]= '\0'; |
| 168 | 209 | ||
| 169 | if(strncmp(buf, "ERR ", 4) == 0){ | 210 | i = 0; |
| 170 | priority= LOG_ERR; | 211 | while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++; |
| 171 | pp= buf+ 4; | 212 | priority = mapping[i].log_level; |
| 172 | }else if(strncmp(buf, "WAR ", 4) == 0){ | 213 | pp = buf + mapping[i].strl; |
| 173 | priority= LOG_WARNING; | ||
| 174 | pp= buf+ 4; | ||
| 175 | }else if(strncmp(buf, "INF ", 4) == 0){ | ||
| 176 | priority= LOG_INFO; | ||
| 177 | pp= buf+ 4; | ||
| 178 | }else{ | ||
| 179 | priority= LOG_ERR; | ||
| 180 | pp= buf; | ||
| 181 | } | ||
| 182 | 214 | ||
| 183 | xsyslog(b, priority, pp); | 215 | xsyslog(b, priority, pp); |
| 184 | 216 | ||
| 185 | Free(buf); | 217 | OPENSSL_free(buf); |
| 186 | return(ret); | 218 | return(ret); |
| 187 | } | 219 | } |
| 188 | 220 | ||
| 189 | static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr) | 221 | static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, void *ptr) |
| 190 | { | 222 | { |
| 191 | switch (cmd) | 223 | switch (cmd) |
| 192 | { | 224 | { |
| @@ -200,7 +232,7 @@ static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
| 200 | return(0); | 232 | return(0); |
| 201 | } | 233 | } |
| 202 | 234 | ||
| 203 | static int MS_CALLBACK slg_puts(BIO *bp, char *str) | 235 | static int MS_CALLBACK slg_puts(BIO *bp, const char *str) |
| 204 | { | 236 | { |
| 205 | int n,ret; | 237 | int n,ret; |
| 206 | 238 | ||
| @@ -211,9 +243,29 @@ static int MS_CALLBACK slg_puts(BIO *bp, char *str) | |||
| 211 | 243 | ||
| 212 | #if defined(WIN32) | 244 | #if defined(WIN32) |
| 213 | 245 | ||
| 214 | static void xopenlog(BIO* bp, const char* name, int level) | 246 | static void xopenlog(BIO* bp, char* name, int level) |
| 215 | { | 247 | { |
| 216 | bp->ptr= (char *)RegisterEventSource(NULL, name); | 248 | if ( !register_event_source ) |
| 249 | { | ||
| 250 | HANDLE advapi; | ||
| 251 | if ( !(advapi = GetModuleHandle("advapi32")) ) | ||
| 252 | return; | ||
| 253 | register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi, | ||
| 254 | "RegisterEventSource" ); | ||
| 255 | deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi, | ||
| 256 | "DeregisterEventSource"); | ||
| 257 | report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi, | ||
| 258 | "ReportEvent" ); | ||
| 259 | if ( !(register_event_source && deregister_event_source && | ||
| 260 | report_event) ) | ||
| 261 | { | ||
| 262 | register_event_source = NULL; | ||
| 263 | deregister_event_source = NULL; | ||
| 264 | report_event = NULL; | ||
| 265 | return; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | bp->ptr= (char *)register_event_source(NULL, name); | ||
| 217 | } | 269 | } |
| 218 | 270 | ||
| 219 | static void xsyslog(BIO *bp, int priority, const char *string) | 271 | static void xsyslog(BIO *bp, int priority, const char *string) |
| @@ -225,16 +277,22 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
| 225 | 277 | ||
| 226 | switch (priority) | 278 | switch (priority) |
| 227 | { | 279 | { |
| 280 | case LOG_EMERG: | ||
| 281 | case LOG_ALERT: | ||
| 282 | case LOG_CRIT: | ||
| 228 | case LOG_ERR: | 283 | case LOG_ERR: |
| 229 | evtype = EVENTLOG_ERROR_TYPE; | 284 | evtype = EVENTLOG_ERROR_TYPE; |
| 230 | break; | 285 | break; |
| 231 | case LOG_WARNING: | 286 | case LOG_WARNING: |
| 232 | evtype = EVENTLOG_WARNING_TYPE; | 287 | evtype = EVENTLOG_WARNING_TYPE; |
| 233 | break; | 288 | break; |
| 289 | case LOG_NOTICE: | ||
| 234 | case LOG_INFO: | 290 | case LOG_INFO: |
| 291 | case LOG_DEBUG: | ||
| 235 | evtype = EVENTLOG_INFORMATION_TYPE; | 292 | evtype = EVENTLOG_INFORMATION_TYPE; |
| 236 | break; | 293 | break; |
| 237 | default: | 294 | default: /* Should never happen, but set it |
| 295 | as error anyway. */ | ||
| 238 | evtype = EVENTLOG_ERROR_TYPE; | 296 | evtype = EVENTLOG_ERROR_TYPE; |
| 239 | break; | 297 | break; |
| 240 | } | 298 | } |
| @@ -243,15 +301,15 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
| 243 | lpszStrings[0] = pidbuf; | 301 | lpszStrings[0] = pidbuf; |
| 244 | lpszStrings[1] = string; | 302 | lpszStrings[1] = string; |
| 245 | 303 | ||
| 246 | if(bp->ptr) | 304 | if(report_event && bp->ptr) |
| 247 | ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0, | 305 | report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0, |
| 248 | lpszStrings, NULL); | 306 | lpszStrings, NULL); |
| 249 | } | 307 | } |
| 250 | 308 | ||
| 251 | static void xcloselog(BIO* bp) | 309 | static void xcloselog(BIO* bp) |
| 252 | { | 310 | { |
| 253 | if(bp->ptr) | 311 | if(deregister_event_source && bp->ptr) |
| 254 | DeregisterEventSource((HANDLE)(bp->ptr)); | 312 | deregister_event_source((HANDLE)(bp->ptr)); |
| 255 | bp->ptr= NULL; | 313 | bp->ptr= NULL; |
| 256 | } | 314 | } |
| 257 | 315 | ||
| @@ -259,7 +317,7 @@ static void xcloselog(BIO* bp) | |||
| 259 | 317 | ||
| 260 | static int VMS_OPC_target = LOG_DAEMON; | 318 | static int VMS_OPC_target = LOG_DAEMON; |
| 261 | 319 | ||
| 262 | static void xopenlog(BIO* bp, const char* name, int level) | 320 | static void xopenlog(BIO* bp, char* name, int level) |
| 263 | { | 321 | { |
| 264 | VMS_OPC_target = level; | 322 | VMS_OPC_target = level; |
| 265 | } | 323 | } |
| @@ -294,7 +352,7 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
| 294 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); | 352 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); |
| 295 | 353 | ||
| 296 | /* we know there's an 8 byte header. That's documented */ | 354 | /* we know there's an 8 byte header. That's documented */ |
| 297 | opcdef_p = (struct opcdef *) Malloc(8 + len); | 355 | opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len); |
| 298 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; | 356 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; |
| 299 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); | 357 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); |
| 300 | opcdef_p->opc$l_ms_rqstid = 0; | 358 | opcdef_p->opc$l_ms_rqstid = 0; |
| @@ -307,7 +365,7 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
| 307 | 365 | ||
| 308 | sys$sndopr(opc_dsc, 0); | 366 | sys$sndopr(opc_dsc, 0); |
| 309 | 367 | ||
| 310 | Free(opcdef_p); | 368 | OPENSSL_free(opcdef_p); |
| 311 | } | 369 | } |
| 312 | 370 | ||
| 313 | static void xcloselog(BIO* bp) | 371 | static void xcloselog(BIO* bp) |
| @@ -316,7 +374,7 @@ static void xcloselog(BIO* bp) | |||
| 316 | 374 | ||
| 317 | #else /* Unix */ | 375 | #else /* Unix */ |
| 318 | 376 | ||
| 319 | static void xopenlog(BIO* bp, const char* name, int level) | 377 | static void xopenlog(BIO* bp, char* name, int level) |
| 320 | { | 378 | { |
| 321 | openlog(name, LOG_PID|LOG_CONS, level); | 379 | openlog(name, LOG_PID|LOG_CONS, level); |
| 322 | } | 380 | } |
