From: Ben Laurie Date: Mon, 22 Feb 1999 21:21:08 +0000 (+0000) Subject: Add syslogging BIO. X-Git-Tag: OpenSSL_0_9_2b~125 X-Git-Url: https://git.openssl.org/?p=openssl.git;a=commitdiff_plain;h=0849d13811a61d9ce711ac1f3a706ddd19fec1f3;ds=sidebyside Add syslogging BIO. --- diff --git a/CHANGES b/CHANGES index 000f671598..c2ef7bffec 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,9 @@ Changes between 0.9.1c and 0.9.2 + *) Add cool BIO that does syslog (or event log on NT). + [Arne Ansper , integrated by Ben Laurie] + *) Add support for new TLS ciphersuites, TLS_RSA_EXPORT56_WITH_RC4_56_MD5, TLS_RSA_EXPORT56_WITH_RC2_CBC_56_MD5 and TLS_RSA_EXPORT56_WITH_DES_CBC_SHA, as specified in "56-bit Export Cipher diff --git a/crypto/bio/Makefile.ssl b/crypto/bio/Makefile.ssl index 5e8f44a255..2849c2841a 100644 --- a/crypto/bio/Makefile.ssl +++ b/crypto/bio/Makefile.ssl @@ -26,12 +26,12 @@ LIBSRC= bio_lib.c bio_cb.c $(ERRC).c \ bss_mem.c bss_null.c bss_fd.c \ bss_file.c bss_sock.c bss_conn.c \ bf_null.c bf_buff.c b_print.c b_dump.c \ - b_sock.c bss_acpt.c bf_nbio.c + b_sock.c bss_acpt.c bf_nbio.c bss_log.c LIBOBJ= bio_lib.o bio_cb.o $(ERRC).o \ bss_mem.o bss_null.o bss_fd.o \ bss_file.o bss_sock.o bss_conn.o \ bf_null.o bf_buff.o b_print.o b_dump.o \ - b_sock.o bss_acpt.o bf_nbio.o + b_sock.o bss_acpt.o bf_nbio.o bss_log.o SRC= $(LIBSRC) diff --git a/crypto/bio/bio.h b/crypto/bio/bio.h index 8ddfedee51..82aaf31719 100644 --- a/crypto/bio/bio.h +++ b/crypto/bio/bio.h @@ -508,6 +508,7 @@ BIO_METHOD *BIO_s_socket(void); BIO_METHOD *BIO_s_connect(void); BIO_METHOD *BIO_s_accept(void); BIO_METHOD *BIO_s_fd(void); +BIO_METHOD *BIO_s_log(void); BIO_METHOD *BIO_s_null(void); BIO_METHOD *BIO_f_null(void); BIO_METHOD *BIO_f_buffer(void); @@ -574,6 +575,7 @@ BIO_METHOD *BIO_s_socket(); BIO_METHOD *BIO_s_connect(); BIO_METHOD *BIO_s_accept(); BIO_METHOD *BIO_s_fd(); +BIO_METHOD *BIO_s_log(); BIO_METHOD *BIO_s_null(); BIO_METHOD *BIO_f_null(); BIO_METHOD *BIO_f_buffer(); diff --git a/crypto/bio/bss_log.c b/crypto/bio/bss_log.c new file mode 100644 index 0000000000..cb2779855b --- /dev/null +++ b/crypto/bio/bss_log.c @@ -0,0 +1,244 @@ +/* crypto/bio/bss_log.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + 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). + +*/ + +#include +#include + +#ifndef WIN32 +#include +#endif + +#include "cryptlib.h" +#include "buffer.h" +#include "err.h" + +#ifndef NOPROTO +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); +#else +static int MS_CALLBACK slg_write(); +static int MS_CALLBACK slg_puts(); +static long MS_CALLBACK slg_ctrl(); +static int MS_CALLBACK slg_new(); +static int MS_CALLBACK slg_free(); +#endif + +static int xopenlog(BIO* bp, char* name, int level); +static int xcloselog(BIO* bp); + +static BIO_METHOD methods_slg= + { + BIO_TYPE_MEM,"syslog", + slg_write, + NULL, + slg_puts, + NULL, + slg_ctrl, + slg_new, + slg_free, + }; + +BIO_METHOD *BIO_s_log() + { + return(&methods_slg); + } + +static int MS_CALLBACK slg_new(bi) +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); + } + +static int MS_CALLBACK slg_free(a) +BIO *a; + { + if (a == NULL) return(0); + xcloselog(a); + return(1); + } + +static int MS_CALLBACK slg_write(b,in,inl) +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; + }else if(strncmp(buf, "WAR ", 4) == 0){ + priority= LOG_WARNING; + pp= buf+ 4; + }else if(strncmp(buf, "INF ", 4) == 0){ + priority= LOG_INFO; + pp= buf+ 4; + }else{ + priority= LOG_ERR; + pp= buf; + } + + syslog(priority, "%s", pp); +#endif + Free(buf); + return(ret); + } + +static long MS_CALLBACK slg_ctrl(b,cmd,num,ptr) +BIO *b; +int cmd; +long num; +char *ptr; + { + switch (cmd) + { + case BIO_CTRL_SET: + xcloselog(b); + xopenlog(b, ptr, num); + break; + default: + break; + } + return(0); + } + +static int MS_CALLBACK slg_puts(bp,str) +BIO *bp; +char *str; + { + int n,ret; + + n=strlen(str); + ret=slg_write(bp,str,n); + return(ret); + } + +static int xopenlog(BIO* bp, 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 int xcloselog(BIO* bp) +{ +#if defined(WIN32) + if(bp->ptr) + DeregisterEventSource((HANDLE)(bp->ptr)); + bp->ptr= NULL; +#else + closelog(); +#endif + return(1); +} +