diff options
Diffstat (limited to 'crypto/openssl/crypto/bio/bss_log.c')
-rw-r--r-- | crypto/openssl/crypto/bio/bss_log.c | 214 |
1 files changed, 159 insertions, 55 deletions
diff --git a/crypto/openssl/crypto/bio/bss_log.c b/crypto/openssl/crypto/bio/bss_log.c index db82e75..497eb1a 100644 --- a/crypto/openssl/crypto/bio/bss_log.c +++ b/crypto/openssl/crypto/bio/bss_log.c @@ -57,8 +57,8 @@ Why BIO_s_log? BIO_s_log is useful for system daemons (or services under NT). - It is one-way BIO, it sends all stuff to syslogd (or event log - under NT). + It is one-way BIO, it sends all stuff to syslogd (on system that + commonly use that), or event log (on NT), or OPCOM (on OpenVMS). */ @@ -66,27 +66,58 @@ #include <stdio.h> #include <errno.h> -#ifndef WIN32 -#ifdef __ultrix -#include <sys/syslog.h> -#else -#include <syslog.h> -#endif +#if defined(WIN32) +# include <process.h> +#elif defined(VMS) || defined(__VMS) +# include <opcdef.h> +# include <descrip.h> +# include <lib$routines.h> +# include <starlet.h> +#elif defined(__ultrix) +# include <sys/syslog.h> +#elif !defined(MSDOS) /* Unix */ +# include <syslog.h> #endif #include "cryptlib.h" #include <openssl/buffer.h> #include <openssl/err.h> + #ifndef NO_SYSLOG +#if defined(WIN32) +#define LOG_EMERG 0 +#define LOG_ALERT 1 +#define LOG_CRIT 2 +#define LOG_ERR 3 +#define LOG_WARNING 4 +#define LOG_NOTICE 5 +#define LOG_INFO 6 +#define LOG_DEBUG 7 + +#define LOG_DAEMON (3<<3) +#elif defined(VMS) +/* On VMS, we don't really care about these, but we need them to compile */ +#define LOG_EMERG 0 +#define LOG_ALERT 1 +#define LOG_CRIT 2 +#define LOG_ERR 3 +#define LOG_WARNING 4 +#define LOG_NOTICE 5 +#define LOG_INFO 6 +#define LOG_DEBUG 7 + +#define LOG_DAEMON OPC$M_NM_NTWORK +#endif static int MS_CALLBACK slg_write(BIO *h,char *buf,int num); static int MS_CALLBACK slg_puts(BIO *h,char *str); static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int MS_CALLBACK slg_new(BIO *h); static int MS_CALLBACK slg_free(BIO *data); -static int xopenlog(BIO* bp, const char* name, int level); -static int xcloselog(BIO* bp); +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); static BIO_METHOD methods_slg= { @@ -98,6 +129,7 @@ static BIO_METHOD methods_slg= slg_ctrl, slg_new, slg_free, + NULL, }; BIO_METHOD *BIO_s_log(void) @@ -110,11 +142,7 @@ static int MS_CALLBACK slg_new(BIO *bi) bi->init=1; bi->num=0; bi->ptr=NULL; -#ifndef WIN32 xopenlog(bi, "application", LOG_DAEMON); -#else - xopenlog(bi, "application", 0); -#endif return(1); } @@ -130,38 +158,14 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) int ret= inl; char* buf= in; char* pp; -#if defined(WIN32) - LPTSTR lpszStrings[1]; - WORD evtype= EVENTLOG_ERROR_TYPE; -#else int priority; -#endif if((buf= (char *)Malloc(inl+ 1)) == NULL){ return(0); } strncpy(buf, in, inl); buf[inl]= '\0'; -#if defined(WIN32) - if(strncmp(buf, "ERR ", 4) == 0){ - evtype= EVENTLOG_ERROR_TYPE; - pp= buf+ 4; - }else if(strncmp(buf, "WAR ", 4) == 0){ - evtype= EVENTLOG_WARNING_TYPE; - pp= buf+ 4; - }else if(strncmp(buf, "INF ", 4) == 0){ - evtype= EVENTLOG_INFORMATION_TYPE; - pp= buf+ 4; - }else{ - evtype= EVENTLOG_ERROR_TYPE; - pp= buf; - } - lpszStrings[0]= pp; - if(b->ptr) - ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0, - lpszStrings, NULL); -#else if(strncmp(buf, "ERR ", 4) == 0){ priority= LOG_ERR; pp= buf+ 4; @@ -176,8 +180,8 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) pp= buf; } - syslog(priority, "%s", pp); -#endif + xsyslog(b, priority, pp); + Free(buf); return(ret); } @@ -205,28 +209,128 @@ static int MS_CALLBACK slg_puts(BIO *bp, char *str) return(ret); } -static int xopenlog(BIO* bp, const char* name, int level) -{ #if defined(WIN32) - if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){ - return(0); - } -#else - openlog(name, LOG_PID|LOG_CONS, level); -#endif - return(1); + +static void xopenlog(BIO* bp, const char* name, int level) +{ + bp->ptr= (char *)RegisterEventSource(NULL, name); } -static int xcloselog(BIO* bp) +static void xsyslog(BIO *bp, int priority, const char *string) +{ + LPCSTR lpszStrings[2]; + WORD evtype= EVENTLOG_ERROR_TYPE; + int pid = _getpid(); + char pidbuf[20]; + + switch (priority) + { + case LOG_ERR: + evtype = EVENTLOG_ERROR_TYPE; + break; + case LOG_WARNING: + evtype = EVENTLOG_WARNING_TYPE; + break; + case LOG_INFO: + evtype = EVENTLOG_INFORMATION_TYPE; + break; + default: + evtype = EVENTLOG_ERROR_TYPE; + break; + } + + sprintf(pidbuf, "[%d] ", pid); + lpszStrings[0] = pidbuf; + lpszStrings[1] = string; + + if(bp->ptr) + ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0, + lpszStrings, NULL); +} + +static void xcloselog(BIO* bp) { -#if defined(WIN32) if(bp->ptr) DeregisterEventSource((HANDLE)(bp->ptr)); bp->ptr= NULL; -#else +} + +#elif defined(VMS) + +static int VMS_OPC_target = LOG_DAEMON; + +static void xopenlog(BIO* bp, const char* name, int level) +{ + VMS_OPC_target = level; +} + +static void xsyslog(BIO *bp, int priority, const char *string) +{ + struct dsc$descriptor_s opc_dsc; + struct opcdef *opcdef_p; + char buf[10240]; + unsigned int len; + struct dsc$descriptor_s buf_dsc; + $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); + char *priority_tag; + + switch (priority) + { + case LOG_EMERG: priority_tag = "Emergency"; break; + case LOG_ALERT: priority_tag = "Alert"; break; + case LOG_CRIT: priority_tag = "Critical"; break; + case LOG_ERR: priority_tag = "Error"; break; + case LOG_WARNING: priority_tag = "Warning"; break; + case LOG_NOTICE: priority_tag = "Notice"; break; + case LOG_INFO: priority_tag = "Info"; break; + case LOG_DEBUG: priority_tag = "DEBUG"; break; + } + + buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; + buf_dsc.dsc$b_class = DSC$K_CLASS_S; + buf_dsc.dsc$a_pointer = buf; + buf_dsc.dsc$w_length = sizeof(buf) - 1; + + lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); + + /* we know there's an 8 byte header. That's documented */ + opcdef_p = (struct opcdef *) Malloc(8 + len); + opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; + memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); + opcdef_p->opc$l_ms_rqstid = 0; + memcpy(&opcdef_p->opc$l_ms_text, buf, len); + + opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T; + opc_dsc.dsc$b_class = DSC$K_CLASS_S; + opc_dsc.dsc$a_pointer = (char *)opcdef_p; + opc_dsc.dsc$w_length = len + 8; + + sys$sndopr(opc_dsc, 0); + + Free(opcdef_p); +} + +static void xcloselog(BIO* bp) +{ +} + +#else /* Unix */ + +static void xopenlog(BIO* bp, const char* name, int level) +{ + openlog(name, LOG_PID|LOG_CONS, level); +} + +static void xsyslog(BIO *bp, int priority, const char *string) +{ + syslog(priority, "%s", string); +} + +static void xcloselog(BIO* bp) +{ closelog(); -#endif - return(1); } -#endif +#endif /* Unix */ + +#endif /* NO_SYSLOG */ |