diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_log.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_log.c | 186 |
1 files changed, 103 insertions, 83 deletions
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c index 1cc413a916..9225af4df2 100644 --- a/src/lib/libcrypto/bio/bss_log.c +++ b/src/lib/libcrypto/bio/bss_log.c | |||
@@ -80,7 +80,7 @@ | |||
80 | # if __INITIAL_POINTER_SIZE == 64 | 80 | # if __INITIAL_POINTER_SIZE == 64 |
81 | # pragma pointer_size save | 81 | # pragma pointer_size save |
82 | # pragma pointer_size 32 | 82 | # pragma pointer_size 32 |
83 | void * _malloc32 (__size_t); | 83 | void * _malloc32 (__size_t); |
84 | # pragma pointer_size restore | 84 | # pragma pointer_size restore |
85 | # endif /* __INITIAL_POINTER_SIZE == 64 */ | 85 | # endif /* __INITIAL_POINTER_SIZE == 64 */ |
86 | # endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */ | 86 | # endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */ |
@@ -131,9 +131,8 @@ static void xopenlog(BIO* bp, char* name, int level); | |||
131 | static void xsyslog(BIO* bp, int priority, const char* string); | 131 | static void xsyslog(BIO* bp, int priority, const char* string); |
132 | static void xcloselog(BIO* bp); | 132 | static void xcloselog(BIO* bp); |
133 | 133 | ||
134 | static BIO_METHOD methods_slg= | 134 | static BIO_METHOD methods_slg = { |
135 | { | 135 | BIO_TYPE_MEM, "syslog", |
136 | BIO_TYPE_MEM,"syslog", | ||
137 | slg_write, | 136 | slg_write, |
138 | NULL, | 137 | NULL, |
139 | slg_puts, | 138 | slg_puts, |
@@ -142,43 +141,46 @@ static BIO_METHOD methods_slg= | |||
142 | slg_new, | 141 | slg_new, |
143 | slg_free, | 142 | slg_free, |
144 | NULL, | 143 | NULL, |
145 | }; | 144 | }; |
146 | 145 | ||
147 | BIO_METHOD *BIO_s_log(void) | 146 | BIO_METHOD |
148 | { | 147 | *BIO_s_log(void) |
149 | return(&methods_slg); | 148 | { |
150 | } | 149 | return (&methods_slg); |
150 | } | ||
151 | 151 | ||
152 | static int slg_new(BIO *bi) | 152 | static int |
153 | { | 153 | slg_new(BIO *bi) |
154 | bi->init=1; | 154 | { |
155 | bi->num=0; | 155 | bi->init = 1; |
156 | bi->ptr=NULL; | 156 | bi->num = 0; |
157 | bi->ptr = NULL; | ||
157 | xopenlog(bi, "application", LOG_DAEMON); | 158 | xopenlog(bi, "application", LOG_DAEMON); |
158 | return(1); | 159 | return (1); |
159 | } | 160 | } |
160 | 161 | ||
161 | static int slg_free(BIO *a) | 162 | static int |
162 | { | 163 | slg_free(BIO *a) |
163 | if (a == NULL) return(0); | 164 | { |
165 | if (a == NULL) | ||
166 | return (0); | ||
164 | xcloselog(a); | 167 | xcloselog(a); |
165 | return(1); | 168 | return (1); |
166 | } | 169 | } |
167 | 170 | ||
168 | static int slg_write(BIO *b, const char *in, int inl) | 171 | static int |
169 | { | 172 | slg_write(BIO *b, const char *in, int inl) |
170 | int ret= inl; | 173 | { |
174 | int ret = inl; | ||
171 | char* buf; | 175 | char* buf; |
172 | char* pp; | 176 | char* pp; |
173 | int priority, i; | 177 | int priority, i; |
174 | static const struct | 178 | static const struct { |
175 | { | ||
176 | int strl; | 179 | int strl; |
177 | char str[10]; | 180 | char str[10]; |
178 | int log_level; | 181 | int log_level; |
179 | } | 182 | } |
180 | mapping[] = | 183 | mapping[] = { |
181 | { | ||
182 | { 6, "PANIC ", LOG_EMERG }, | 184 | { 6, "PANIC ", LOG_EMERG }, |
183 | { 6, "EMERG ", LOG_EMERG }, | 185 | { 6, "EMERG ", LOG_EMERG }, |
184 | { 4, "EMR ", LOG_EMERG }, | 186 | { 4, "EMR ", LOG_EMERG }, |
@@ -199,69 +201,72 @@ static int slg_write(BIO *b, const char *in, int inl) | |||
199 | { 6, "DEBUG ", LOG_DEBUG }, | 201 | { 6, "DEBUG ", LOG_DEBUG }, |
200 | { 4, "DBG ", LOG_DEBUG }, | 202 | { 4, "DBG ", LOG_DEBUG }, |
201 | { 0, "", LOG_ERR } /* The default */ | 203 | { 0, "", LOG_ERR } /* The default */ |
202 | }; | 204 | }; |
203 | 205 | ||
204 | if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){ | 206 | if ((buf = (char *)OPENSSL_malloc(inl + 1)) == NULL) { |
205 | return(0); | 207 | return (0); |
206 | } | 208 | } |
207 | strncpy(buf, in, inl); | 209 | strncpy(buf, in, inl); |
208 | buf[inl]= '\0'; | 210 | buf[inl] = '\0'; |
209 | 211 | ||
210 | i = 0; | 212 | i = 0; |
211 | while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++; | 213 | while (strncmp(buf, mapping[i].str, mapping[i].strl) != 0) |
214 | i++; | ||
212 | priority = mapping[i].log_level; | 215 | priority = mapping[i].log_level; |
213 | pp = buf + mapping[i].strl; | 216 | pp = buf + mapping[i].strl; |
214 | 217 | ||
215 | xsyslog(b, priority, pp); | 218 | xsyslog(b, priority, pp); |
216 | 219 | ||
217 | OPENSSL_free(buf); | 220 | OPENSSL_free(buf); |
218 | return(ret); | 221 | return (ret); |
219 | } | 222 | } |
220 | 223 | ||
221 | static long slg_ctrl(BIO *b, int cmd, long num, void *ptr) | 224 | static long |
222 | { | 225 | slg_ctrl(BIO *b, int cmd, long num, void *ptr) |
223 | switch (cmd) | 226 | { |
224 | { | 227 | switch (cmd) { |
225 | case BIO_CTRL_SET: | 228 | case BIO_CTRL_SET: |
226 | xcloselog(b); | 229 | xcloselog(b); |
227 | xopenlog(b, ptr, num); | 230 | xopenlog(b, ptr, num); |
228 | break; | 231 | break; |
229 | default: | 232 | default: |
230 | break; | 233 | break; |
231 | } | ||
232 | return(0); | ||
233 | } | 234 | } |
235 | return (0); | ||
236 | } | ||
234 | 237 | ||
235 | static int slg_puts(BIO *bp, const char *str) | 238 | static int |
236 | { | 239 | slg_puts(BIO *bp, const char *str) |
237 | int n,ret; | 240 | { |
241 | int n, ret; | ||
238 | 242 | ||
239 | n=strlen(str); | 243 | n = strlen(str); |
240 | ret=slg_write(bp,str,n); | 244 | ret = slg_write(bp, str, n); |
241 | return(ret); | 245 | return (ret); |
242 | } | 246 | } |
243 | 247 | ||
244 | #if defined(OPENSSL_SYS_WIN32) | 248 | #if defined(OPENSSL_SYS_WIN32) |
245 | 249 | ||
246 | static void xopenlog(BIO* bp, char* name, int level) | 250 | static void |
251 | xopenlog(BIO* bp, char* name, int level) | ||
247 | { | 252 | { |
248 | if (check_winnt()) | 253 | if (check_winnt()) |
249 | bp->ptr = RegisterEventSourceA(NULL,name); | 254 | bp->ptr = RegisterEventSourceA(NULL, name); |
250 | else | 255 | else |
251 | bp->ptr = NULL; | 256 | bp->ptr = NULL; |
252 | } | 257 | } |
253 | 258 | ||
254 | static void xsyslog(BIO *bp, int priority, const char *string) | 259 | static void |
260 | xsyslog(BIO *bp, int priority, const char *string) | ||
255 | { | 261 | { |
256 | LPCSTR lpszStrings[2]; | 262 | LPCSTR lpszStrings[2]; |
257 | WORD evtype= EVENTLOG_ERROR_TYPE; | 263 | WORD evtype = EVENTLOG_ERROR_TYPE; |
258 | char pidbuf[DECIMAL_SIZE(DWORD)+4]; | 264 | char pidbuf[DECIMAL_SIZE(DWORD) + 4]; |
259 | 265 | ||
260 | if (bp->ptr == NULL) | 266 | if (bp->ptr == NULL) |
261 | return; | 267 | return; |
262 | 268 | ||
263 | switch (priority) | 269 | switch (priority) { |
264 | { | ||
265 | case LOG_EMERG: | 270 | case LOG_EMERG: |
266 | case LOG_ALERT: | 271 | case LOG_ALERT: |
267 | case LOG_CRIT: | 272 | case LOG_CRIT: |
@@ -280,33 +285,37 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
280 | as error anyway. */ | 285 | as error anyway. */ |
281 | evtype = EVENTLOG_ERROR_TYPE; | 286 | evtype = EVENTLOG_ERROR_TYPE; |
282 | break; | 287 | break; |
283 | } | 288 | } |
284 | 289 | ||
285 | sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); | 290 | sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); |
286 | lpszStrings[0] = pidbuf; | 291 | lpszStrings[0] = pidbuf; |
287 | lpszStrings[1] = string; | 292 | lpszStrings[1] = string; |
288 | 293 | ||
289 | ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, | 294 | ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, |
290 | lpszStrings, NULL); | 295 | lpszStrings, NULL); |
291 | } | 296 | } |
292 | 297 | ||
293 | static void xcloselog(BIO* bp) | 298 | static void |
299 | xcloselog(BIO* bp) | ||
294 | { | 300 | { |
295 | if(bp->ptr) | 301 | if (bp->ptr) |
296 | DeregisterEventSource((HANDLE)(bp->ptr)); | 302 | DeregisterEventSource((HANDLE)(bp->ptr)); |
297 | bp->ptr= NULL; | 303 | bp->ptr = NULL; |
298 | } | 304 | } |
299 | 305 | ||
300 | #elif defined(OPENSSL_SYS_VMS) | 306 | #elif defined(OPENSSL_SYS_VMS) |
301 | 307 | ||
302 | static int VMS_OPC_target = LOG_DAEMON; | 308 | static int VMS_OPC_target = LOG_DAEMON; |
303 | 309 | ||
304 | static void xopenlog(BIO* bp, char* name, int level) | 310 | static void |
311 | xopenlog(BIO* bp, char* name, int level) | ||
305 | { | 312 | { |
306 | VMS_OPC_target = level; | 313 | VMS_OPC_target = level; |
314 | |||
307 | } | 315 | } |
308 | 316 | ||
309 | static void xsyslog(BIO *bp, int priority, const char *string) | 317 | static void |
318 | xsyslog(BIO *bp, int priority, const char *string) | ||
310 | { | 319 | { |
311 | struct dsc$descriptor_s opc_dsc; | 320 | struct dsc$descriptor_s opc_dsc; |
312 | 321 | ||
@@ -329,21 +338,28 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
329 | 338 | ||
330 | char buf[10240]; | 339 | char buf[10240]; |
331 | unsigned int len; | 340 | unsigned int len; |
332 | struct dsc$descriptor_s buf_dsc; | 341 | struct dsc$descriptor_s buf_dsc; |
333 | $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); | 342 | $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); |
334 | char *priority_tag; | 343 | char *priority_tag; |
335 | 344 | ||
336 | switch (priority) | 345 | switch (priority) { |
337 | { | 346 | case LOG_EMERG: |
338 | case LOG_EMERG: priority_tag = "Emergency"; break; | 347 | priority_tag = "Emergency"; break; |
339 | case LOG_ALERT: priority_tag = "Alert"; break; | 348 | case LOG_ALERT: |
340 | case LOG_CRIT: priority_tag = "Critical"; break; | 349 | priority_tag = "Alert"; break; |
341 | case LOG_ERR: priority_tag = "Error"; break; | 350 | case LOG_CRIT: |
342 | case LOG_WARNING: priority_tag = "Warning"; break; | 351 | priority_tag = "Critical"; break; |
343 | case LOG_NOTICE: priority_tag = "Notice"; break; | 352 | case LOG_ERR: |
344 | case LOG_INFO: priority_tag = "Info"; break; | 353 | priority_tag = "Error"; break; |
345 | case LOG_DEBUG: priority_tag = "DEBUG"; break; | 354 | case LOG_WARNING: |
346 | } | 355 | priority_tag = "Warning"; break; |
356 | case LOG_NOTICE: | ||
357 | priority_tag = "Notice"; break; | ||
358 | case LOG_INFO: | ||
359 | priority_tag = "Info"; break; | ||
360 | case LOG_DEBUG: | ||
361 | priority_tag = "DEBUG"; break; | ||
362 | } | ||
347 | 363 | ||
348 | buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | 364 | buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
349 | buf_dsc.dsc$b_class = DSC$K_CLASS_S; | 365 | buf_dsc.dsc$b_class = DSC$K_CLASS_S; |
@@ -353,7 +369,7 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
353 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); | 369 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); |
354 | 370 | ||
355 | /* We know there's an 8-byte header. That's documented. */ | 371 | /* We know there's an 8-byte header. That's documented. */ |
356 | opcdef_p = OPCDEF_MALLOC( 8+ len); | 372 | opcdef_p = OPCDEF_MALLOC( 8 + len); |
357 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; | 373 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; |
358 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); | 374 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); |
359 | opcdef_p->opc$l_ms_rqstid = 0; | 375 | opcdef_p->opc$l_ms_rqstid = 0; |
@@ -369,13 +385,15 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
369 | OPENSSL_free(opcdef_p); | 385 | OPENSSL_free(opcdef_p); |
370 | } | 386 | } |
371 | 387 | ||
372 | static void xcloselog(BIO* bp) | 388 | static void |
389 | xcloselog(BIO* bp) | ||
373 | { | 390 | { |
374 | } | 391 | } |
375 | 392 | ||
376 | #else /* Unix/Watt32 */ | 393 | #else /* Unix/Watt32 */ |
377 | 394 | ||
378 | static void xopenlog(BIO* bp, char* name, int level) | 395 | static void |
396 | xopenlog(BIO* bp, char* name, int level) | ||
379 | { | 397 | { |
380 | #ifdef WATT32 /* djgpp/DOS */ | 398 | #ifdef WATT32 /* djgpp/DOS */ |
381 | openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level); | 399 | openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level); |
@@ -384,12 +402,14 @@ static void xopenlog(BIO* bp, char* name, int level) | |||
384 | #endif | 402 | #endif |
385 | } | 403 | } |
386 | 404 | ||
387 | static void xsyslog(BIO *bp, int priority, const char *string) | 405 | static void |
406 | xsyslog(BIO *bp, int priority, const char *string) | ||
388 | { | 407 | { |
389 | syslog(priority, "%s", string); | 408 | syslog(priority, "%s", string); |
390 | } | 409 | } |
391 | 410 | ||
392 | static void xcloselog(BIO* bp) | 411 | static void |
412 | xcloselog(BIO* bp) | ||
393 | { | 413 | { |
394 | closelog(); | 414 | closelog(); |
395 | } | 415 | } |