1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

Log file tinkering: copy Event Log entries into the SSH packet log,

so that when people send us a packet log they never forget to send
the Event Log alongside it :-)

[originally from svn r1960]
This commit is contained in:
Simon Tatham 2002-09-15 13:21:32 +00:00
parent 9164a7b176
commit 994aee285f
3 changed files with 31 additions and 10 deletions

View File

@ -32,12 +32,25 @@ void logtraffic(unsigned char c, int logmode)
} }
} }
/*
* Log an Event Log entry (used in SSH packet logging mode).
*/
void log_eventlog(char *event)
{
if (cfg.logtype != LGTYP_PACKETS)
return;
if (!lgfp)
logfopen();
if (lgfp)
fprintf(lgfp, "Event Log: %s\n", event);
}
/* /*
* Log an SSH packet. * Log an SSH packet.
*/ */
void log_packet(int direction, int type, char *texttype, void *data, int len) void log_packet(int direction, int type, char *texttype, void *data, int len)
{ {
int i, j, c; int i, j;
char dumpdata[80], smalldata[5]; char dumpdata[80], smalldata[5];
if (cfg.logtype != LGTYP_PACKETS) if (cfg.logtype != LGTYP_PACKETS)
@ -72,6 +85,10 @@ void logfopen(void)
struct tm tm; struct tm tm;
char writemod[4]; char writemod[4];
/* Prevent repeat calls */
if (lgfp)
return;
if (!cfg.logtype) if (!cfg.logtype)
return; return;
sprintf(writemod, "wb"); /* default to rewrite */ sprintf(writemod, "wb"); /* default to rewrite */
@ -98,20 +115,21 @@ void logfopen(void)
lgfp = fopen(currlogfilename, writemod); lgfp = fopen(currlogfilename, writemod);
if (lgfp) { /* enter into event log */ if (lgfp) { /* enter into event log */
sprintf(buf, "%s session log (%s mode) to file : ",
(writemod[0] == 'a') ? "Appending" : "Writing new",
(cfg.logtype == LGTYP_ASCII ? "ASCII" :
cfg.logtype == LGTYP_DEBUG ? "raw" : "<ukwn>"));
/* Make sure we do not exceed the output buffer size */
strncat(buf, currlogfilename, 128);
buf[strlen(buf)] = '\0';
logevent(buf);
/* --- write header line into log file */ /* --- write header line into log file */
fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", lgfp); fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", lgfp);
strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm); strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm);
fputs(buf, lgfp); fputs(buf, lgfp);
fputs(" =~=~=~=~=~=~=~=~=~=~=~=\r\n", lgfp); fputs(" =~=~=~=~=~=~=~=~=~=~=~=\r\n", lgfp);
sprintf(buf, "%s session log (%s mode) to file: ",
(writemod[0] == 'a') ? "Appending" : "Writing new",
(cfg.logtype == LGTYP_ASCII ? "ASCII" :
cfg.logtype == LGTYP_DEBUG ? "raw" :
cfg.logtype == LGTYP_PACKETS ? "SSH packets" : "<ukwn>"));
/* Make sure we do not exceed the output buffer size */
strncat(buf, currlogfilename, 128);
buf[strlen(buf)] = '\0';
logevent(buf);
} }
} }

View File

@ -518,6 +518,7 @@ void term_reconfig(void);
*/ */
void logtraffic(unsigned char c, int logmode); void logtraffic(unsigned char c, int logmode);
enum { PKT_INCOMING, PKT_OUTGOING }; enum { PKT_INCOMING, PKT_OUTGOING };
void log_eventlog(char *string);
void log_packet(int direction, int type, char *texttype, void *data, int len); void log_packet(int direction, int type, char *texttype, void *data, int len);
/* /*

View File

@ -3705,6 +3705,8 @@ void logevent(char *string)
char timebuf[40]; char timebuf[40];
time_t t; time_t t;
log_eventlog(string);
if (nevents >= negsize) { if (nevents >= negsize) {
negsize += 64; negsize += 64;
events = srealloc(events, negsize * sizeof(*events)); events = srealloc(events, negsize * sizeof(*events));