summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bss_log.c
diff options
context:
space:
mode:
authorbeck <>2000-04-15 06:18:51 +0000
committerbeck <>2000-04-15 06:18:51 +0000
commitb608c7f2b175e121f2c22d53341a317153afdc8e (patch)
treee94b160b3fcd8180df79e4251d68d24d665f0195 /src/lib/libcrypto/bio/bss_log.c
parentc8d6701c396cebdcd0d45eac73b762e9498f6b01 (diff)
downloadopenbsd-b608c7f2b175e121f2c22d53341a317153afdc8e.tar.gz
openbsd-b608c7f2b175e121f2c22d53341a317153afdc8e.tar.bz2
openbsd-b608c7f2b175e121f2c22d53341a317153afdc8e.zip
OpenSSL 0.9.5a merge
Diffstat (limited to 'src/lib/libcrypto/bio/bss_log.c')
-rw-r--r--src/lib/libcrypto/bio/bss_log.c220
1 files changed, 158 insertions, 62 deletions
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
index 4308b19663..497eb1af72 100644
--- a/src/lib/libcrypto/bio/bss_log.c
+++ b/src/lib/libcrypto/bio/bss_log.c
@@ -57,8 +57,8 @@
57 Why BIO_s_log? 57 Why BIO_s_log?
58 58
59 BIO_s_log is useful for system daemons (or services under NT). 59 BIO_s_log is useful for system daemons (or services under NT).
60 It is one-way BIO, it sends all stuff to syslogd (or event log 60 It is one-way BIO, it sends all stuff to syslogd (on system that
61 under NT). 61 commonly use that), or event log (on NT), or OPCOM (on OpenVMS).
62 62
63*/ 63*/
64 64
@@ -66,29 +66,58 @@
66#include <stdio.h> 66#include <stdio.h>
67#include <errno.h> 67#include <errno.h>
68 68
69#ifndef WIN32 69#if defined(WIN32)
70#ifdef __ultrix 70# include <process.h>
71#include <sys/syslog.h> 71#elif defined(VMS) || defined(__VMS)
72#else 72# include <opcdef.h>
73#include <syslog.h> 73# include <descrip.h>
74#endif 74# include <lib$routines.h>
75#else 75# include <starlet.h>
76#include <process.h> 76#elif defined(__ultrix)
77# include <sys/syslog.h>
78#elif !defined(MSDOS) /* Unix */
79# include <syslog.h>
77#endif 80#endif
78 81
79#include "cryptlib.h" 82#include "cryptlib.h"
80#include <openssl/buffer.h> 83#include <openssl/buffer.h>
81#include <openssl/err.h> 84#include <openssl/err.h>
85
82#ifndef NO_SYSLOG 86#ifndef NO_SYSLOG
83 87
88#if defined(WIN32)
89#define LOG_EMERG 0
90#define LOG_ALERT 1
91#define LOG_CRIT 2
92#define LOG_ERR 3
93#define LOG_WARNING 4
94#define LOG_NOTICE 5
95#define LOG_INFO 6
96#define LOG_DEBUG 7
97
98#define LOG_DAEMON (3<<3)
99#elif defined(VMS)
100/* On VMS, we don't really care about these, but we need them to compile */
101#define LOG_EMERG 0
102#define LOG_ALERT 1
103#define LOG_CRIT 2
104#define LOG_ERR 3
105#define LOG_WARNING 4
106#define LOG_NOTICE 5
107#define LOG_INFO 6
108#define LOG_DEBUG 7
109
110#define LOG_DAEMON OPC$M_NM_NTWORK
111#endif
84 112
85static int MS_CALLBACK slg_write(BIO *h,char *buf,int num); 113static int MS_CALLBACK slg_write(BIO *h,char *buf,int num);
86static int MS_CALLBACK slg_puts(BIO *h,char *str); 114static int MS_CALLBACK slg_puts(BIO *h,char *str);
87static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2); 115static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2);
88static int MS_CALLBACK slg_new(BIO *h); 116static int MS_CALLBACK slg_new(BIO *h);
89static int MS_CALLBACK slg_free(BIO *data); 117static int MS_CALLBACK slg_free(BIO *data);
90static int xopenlog(BIO* bp, const char* name, int level); 118static void xopenlog(BIO* bp, const char* name, int level);
91static int xcloselog(BIO* bp); 119static void xsyslog(BIO* bp, int priority, const char* string);
120static void xcloselog(BIO* bp);
92 121
93static BIO_METHOD methods_slg= 122static BIO_METHOD methods_slg=
94 { 123 {
@@ -113,11 +142,7 @@ static int MS_CALLBACK slg_new(BIO *bi)
113 bi->init=1; 142 bi->init=1;
114 bi->num=0; 143 bi->num=0;
115 bi->ptr=NULL; 144 bi->ptr=NULL;
116#ifndef WIN32
117 xopenlog(bi, "application", LOG_DAEMON); 145 xopenlog(bi, "application", LOG_DAEMON);
118#else
119 xopenlog(bi, "application", 0);
120#endif
121 return(1); 146 return(1);
122 } 147 }
123 148
@@ -133,43 +158,14 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
133 int ret= inl; 158 int ret= inl;
134 char* buf= in; 159 char* buf= in;
135 char* pp; 160 char* pp;
136#if defined(WIN32)
137 LPCSTR lpszStrings[2];
138 WORD evtype= EVENTLOG_ERROR_TYPE;
139 int pid = _getpid();
140 char pidbuf[20];
141#else
142 int priority; 161 int priority;
143#endif
144 162
145 if((buf= (char *)Malloc(inl+ 1)) == NULL){ 163 if((buf= (char *)Malloc(inl+ 1)) == NULL){
146 return(0); 164 return(0);
147 } 165 }
148 strncpy(buf, in, inl); 166 strncpy(buf, in, inl);
149 buf[inl]= '\0'; 167 buf[inl]= '\0';
150#if defined(WIN32)
151 if(strncmp(buf, "ERR ", 4) == 0){
152 evtype= EVENTLOG_ERROR_TYPE;
153 pp= buf+ 4;
154 }else if(strncmp(buf, "WAR ", 4) == 0){
155 evtype= EVENTLOG_WARNING_TYPE;
156 pp= buf+ 4;
157 }else if(strncmp(buf, "INF ", 4) == 0){
158 evtype= EVENTLOG_INFORMATION_TYPE;
159 pp= buf+ 4;
160 }else{
161 evtype= EVENTLOG_ERROR_TYPE;
162 pp= buf;
163 }
164 168
165 sprintf(pidbuf, "[%d] ", pid);
166 lpszStrings[0] = pidbuf;
167 lpszStrings[1] = pp;
168
169 if(b->ptr)
170 ReportEvent(b->ptr, evtype, 0, 1024, NULL, 2, 0,
171 lpszStrings, NULL);
172#else
173 if(strncmp(buf, "ERR ", 4) == 0){ 169 if(strncmp(buf, "ERR ", 4) == 0){
174 priority= LOG_ERR; 170 priority= LOG_ERR;
175 pp= buf+ 4; 171 pp= buf+ 4;
@@ -184,8 +180,8 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
184 pp= buf; 180 pp= buf;
185 } 181 }
186 182
187 syslog(priority, "%s", pp); 183 xsyslog(b, priority, pp);
188#endif 184
189 Free(buf); 185 Free(buf);
190 return(ret); 186 return(ret);
191 } 187 }
@@ -213,28 +209,128 @@ static int MS_CALLBACK slg_puts(BIO *bp, char *str)
213 return(ret); 209 return(ret);
214 } 210 }
215 211
216static int xopenlog(BIO* bp, const char* name, int level)
217{
218#if defined(WIN32) 212#if defined(WIN32)
219 if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){ 213
220 return(0); 214static void xopenlog(BIO* bp, const char* name, int level)
221 } 215{
222#else 216 bp->ptr= (char *)RegisterEventSource(NULL, name);
223 openlog(name, LOG_PID|LOG_CONS, level);
224#endif
225 return(1);
226} 217}
227 218
228static int xcloselog(BIO* bp) 219static void xsyslog(BIO *bp, int priority, const char *string)
220{
221 LPCSTR lpszStrings[2];
222 WORD evtype= EVENTLOG_ERROR_TYPE;
223 int pid = _getpid();
224 char pidbuf[20];
225
226 switch (priority)
227 {
228 case LOG_ERR:
229 evtype = EVENTLOG_ERROR_TYPE;
230 break;
231 case LOG_WARNING:
232 evtype = EVENTLOG_WARNING_TYPE;
233 break;
234 case LOG_INFO:
235 evtype = EVENTLOG_INFORMATION_TYPE;
236 break;
237 default:
238 evtype = EVENTLOG_ERROR_TYPE;
239 break;
240 }
241
242 sprintf(pidbuf, "[%d] ", pid);
243 lpszStrings[0] = pidbuf;
244 lpszStrings[1] = string;
245
246 if(bp->ptr)
247 ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
248 lpszStrings, NULL);
249}
250
251static void xcloselog(BIO* bp)
229{ 252{
230#if defined(WIN32)
231 if(bp->ptr) 253 if(bp->ptr)
232 DeregisterEventSource((HANDLE)(bp->ptr)); 254 DeregisterEventSource((HANDLE)(bp->ptr));
233 bp->ptr= NULL; 255 bp->ptr= NULL;
234#else 256}
257
258#elif defined(VMS)
259
260static int VMS_OPC_target = LOG_DAEMON;
261
262static void xopenlog(BIO* bp, const char* name, int level)
263{
264 VMS_OPC_target = level;
265}
266
267static void xsyslog(BIO *bp, int priority, const char *string)
268{
269 struct dsc$descriptor_s opc_dsc;
270 struct opcdef *opcdef_p;
271 char buf[10240];
272 unsigned int len;
273 struct dsc$descriptor_s buf_dsc;
274 $DESCRIPTOR(fao_cmd, "!AZ: !AZ");
275 char *priority_tag;
276
277 switch (priority)
278 {
279 case LOG_EMERG: priority_tag = "Emergency"; break;
280 case LOG_ALERT: priority_tag = "Alert"; break;
281 case LOG_CRIT: priority_tag = "Critical"; break;
282 case LOG_ERR: priority_tag = "Error"; break;
283 case LOG_WARNING: priority_tag = "Warning"; break;
284 case LOG_NOTICE: priority_tag = "Notice"; break;
285 case LOG_INFO: priority_tag = "Info"; break;
286 case LOG_DEBUG: priority_tag = "DEBUG"; break;
287 }
288
289 buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
290 buf_dsc.dsc$b_class = DSC$K_CLASS_S;
291 buf_dsc.dsc$a_pointer = buf;
292 buf_dsc.dsc$w_length = sizeof(buf) - 1;
293
294 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
295
296 /* we know there's an 8 byte header. That's documented */
297 opcdef_p = (struct opcdef *) Malloc(8 + len);
298 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
299 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
300 opcdef_p->opc$l_ms_rqstid = 0;
301 memcpy(&opcdef_p->opc$l_ms_text, buf, len);
302
303 opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
304 opc_dsc.dsc$b_class = DSC$K_CLASS_S;
305 opc_dsc.dsc$a_pointer = (char *)opcdef_p;
306 opc_dsc.dsc$w_length = len + 8;
307
308 sys$sndopr(opc_dsc, 0);
309
310 Free(opcdef_p);
311}
312
313static void xcloselog(BIO* bp)
314{
315}
316
317#else /* Unix */
318
319static void xopenlog(BIO* bp, const char* name, int level)
320{
321 openlog(name, LOG_PID|LOG_CONS, level);
322}
323
324static void xsyslog(BIO *bp, int priority, const char *string)
325{
326 syslog(priority, "%s", string);
327}
328
329static void xcloselog(BIO* bp)
330{
235 closelog(); 331 closelog();
236#endif
237 return(1);
238} 332}
239 333
240#endif 334#endif /* Unix */
335
336#endif /* NO_SYSLOG */