mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-23 15:09:24 -05:00
New function ltime() returns a struct tm of the current local time.
Fixes crashes when time() returns (time_t)-1 on Windows by using the Win32 GetLocalTime() function. (The Unix implementation still just uses time() and localtime().) [originally from svn r5086]
This commit is contained in:
parent
3669401216
commit
06434ffc71
11
Recipe
11
Recipe
@ -206,8 +206,8 @@ SFTP = sftp int64 logging
|
|||||||
# Miscellaneous objects appearing in all the network utilities (not
|
# Miscellaneous objects appearing in all the network utilities (not
|
||||||
# Pageant or PuTTYgen).
|
# Pageant or PuTTYgen).
|
||||||
MISC = timing misc version settings tree234 proxy
|
MISC = timing misc version settings tree234 proxy
|
||||||
WINMISC = MISC winstore winnet cmdline windefs winmisc pproxy
|
WINMISC = MISC winstore winnet cmdline windefs winmisc pproxy wintime
|
||||||
UXMISC = MISC uxstore uxsel uxnet cmdline uxmisc uxproxy
|
UXMISC = MISC uxstore uxsel uxnet cmdline uxmisc uxproxy time
|
||||||
MACMISC = MISC macstore macnet mtcpnet otnet macmisc macabout pproxy
|
MACMISC = MISC macstore macnet mtcpnet otnet macmisc macabout pproxy
|
||||||
|
|
||||||
# Character set library, for use in pterm.
|
# Character set library, for use in pterm.
|
||||||
@ -245,10 +245,10 @@ pageant : [G] winpgnt sshrsa sshpubk sshdes sshbn sshmd5 version tree234
|
|||||||
puttygen : [G] winpgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
|
puttygen : [G] winpgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
|
||||||
+ sshrand winnoise sshsha winstore misc winctrls sshrsa sshdss winmisc
|
+ sshrand winnoise sshsha winstore misc winctrls sshrsa sshdss winmisc
|
||||||
+ sshpubk sshaes sshsh512 import winutils puttygen.res tree234
|
+ sshpubk sshaes sshsh512 import winutils puttygen.res tree234
|
||||||
+ notiming LIBS
|
+ notiming LIBS wintime
|
||||||
|
|
||||||
pterm : [X] UXTERM uxmisc misc ldisc settings uxpty uxsel BE_NONE uxstore
|
pterm : [X] UXTERM uxmisc misc ldisc settings uxpty uxsel BE_NONE uxstore
|
||||||
+ uxsignal CHARSET cmdline uxpterm version
|
+ uxsignal CHARSET cmdline uxpterm version time
|
||||||
putty : [X] UXTERM uxmisc misc ldisc settings uxpty uxsel BE_ALL uxstore
|
putty : [X] UXTERM uxmisc misc ldisc settings uxpty uxsel BE_ALL uxstore
|
||||||
+ uxsignal CHARSET uxputty NONSSH UXSSH UXMISC ux_x11
|
+ uxsignal CHARSET uxputty NONSSH UXSSH UXMISC ux_x11
|
||||||
puttytel : [X] UXTERM uxmisc misc ldisc settings uxpty uxsel BE_NOSSH
|
puttytel : [X] UXTERM uxmisc misc ldisc settings uxpty uxsel BE_NOSSH
|
||||||
@ -258,7 +258,8 @@ plink : [U] uxplink uxcons NONSSH UXSSH BE_ALL logging UXMISC uxsignal ux_x11
|
|||||||
|
|
||||||
puttygen : [U] cmdgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
|
puttygen : [U] cmdgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
|
||||||
+ sshrand uxnoise sshsha misc sshrsa sshdss uxcons uxstore uxmisc
|
+ sshrand uxnoise sshsha misc sshrsa sshdss uxcons uxstore uxmisc
|
||||||
+ sshpubk sshaes sshsh512 import puttygen.res tree234 uxgen notiming
|
+ sshpubk sshaes sshsh512 import puttygen.res time tree234 uxgen
|
||||||
|
+ notiming
|
||||||
|
|
||||||
pscp : [U] pscp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC
|
pscp : [U] pscp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC
|
||||||
psftp : [U] psftp uxsftp uxcons UXSSH BE_SSH SFTP UXMISC
|
psftp : [U] psftp uxsftp uxcons UXSSH BE_SSH SFTP UXMISC
|
||||||
|
10
cmdgen.c
10
cmdgen.c
@ -602,19 +602,17 @@ int main(int argc, char **argv)
|
|||||||
if (keytype != NOKEYGEN) {
|
if (keytype != NOKEYGEN) {
|
||||||
char *entropy;
|
char *entropy;
|
||||||
char default_comment[80];
|
char default_comment[80];
|
||||||
time_t t;
|
struct tm tm;
|
||||||
struct tm *tm;
|
|
||||||
struct progress prog;
|
struct progress prog;
|
||||||
|
|
||||||
prog.phase = -1;
|
prog.phase = -1;
|
||||||
prog.current = -1;
|
prog.current = -1;
|
||||||
|
|
||||||
time(&t);
|
tm = ltime();
|
||||||
tm = localtime(&t);
|
|
||||||
if (keytype == DSA)
|
if (keytype == DSA)
|
||||||
strftime(default_comment, 30, "dsa-key-%Y%m%d", tm);
|
strftime(default_comment, 30, "dsa-key-%Y%m%d", &tm);
|
||||||
else
|
else
|
||||||
strftime(default_comment, 30, "rsa-key-%Y%m%d", tm);
|
strftime(default_comment, 30, "rsa-key-%Y%m%d", &tm);
|
||||||
|
|
||||||
random_ref();
|
random_ref();
|
||||||
entropy = get_random_data(bits / 8);
|
entropy = get_random_data(bits / 8);
|
||||||
|
@ -169,7 +169,6 @@ void logfopen(void *handle)
|
|||||||
{
|
{
|
||||||
struct LogContext *ctx = (struct LogContext *)handle;
|
struct LogContext *ctx = (struct LogContext *)handle;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
time_t t;
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
char writemod[4];
|
char writemod[4];
|
||||||
|
|
||||||
@ -181,8 +180,7 @@ void logfopen(void *handle)
|
|||||||
return;
|
return;
|
||||||
sprintf(writemod, "wb"); /* default to rewrite */
|
sprintf(writemod, "wb"); /* default to rewrite */
|
||||||
|
|
||||||
time(&t);
|
tm = ltime();
|
||||||
tm = *localtime(&t);
|
|
||||||
|
|
||||||
/* substitute special codes in file name */
|
/* substitute special codes in file name */
|
||||||
xlatlognam(&ctx->currlogfilename, ctx->cfg.logfilename,ctx->cfg.host, &tm);
|
xlatlognam(&ctx->currlogfilename, ctx->cfg.logfilename,ctx->cfg.host, &tm);
|
||||||
|
3
misc.h
3
misc.h
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <stdio.h> /* for FILE * */
|
#include <stdio.h> /* for FILE * */
|
||||||
#include <stdarg.h> /* for va_list */
|
#include <stdarg.h> /* for va_list */
|
||||||
|
#include <time.h> /* for struct_tm */
|
||||||
|
|
||||||
#ifndef FALSE
|
#ifndef FALSE
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
@ -41,6 +42,8 @@ void bufchain_prefix(bufchain *ch, void **data, int *len);
|
|||||||
void bufchain_consume(bufchain *ch, int len);
|
void bufchain_consume(bufchain *ch, int len);
|
||||||
void bufchain_fetch(bufchain *ch, void *data, int len);
|
void bufchain_fetch(bufchain *ch, void *data, int len);
|
||||||
|
|
||||||
|
struct tm ltime(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Debugging functions.
|
* Debugging functions.
|
||||||
*
|
*
|
||||||
|
10
time.c
Normal file
10
time.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <time.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
struct tm ltime(void)
|
||||||
|
{
|
||||||
|
time_t t;
|
||||||
|
time(&t);
|
||||||
|
assert (t != ((time_t)-1));
|
||||||
|
return *localtime(&t);
|
||||||
|
}
|
@ -2728,16 +2728,15 @@ void logevent_dlg(void *estuff, const char *string)
|
|||||||
struct eventlog_stuff *es = (struct eventlog_stuff *)estuff;
|
struct eventlog_stuff *es = (struct eventlog_stuff *)estuff;
|
||||||
|
|
||||||
char timebuf[40];
|
char timebuf[40];
|
||||||
time_t t;
|
struct tm tm;
|
||||||
|
|
||||||
if (es->nevents >= es->negsize) {
|
if (es->nevents >= es->negsize) {
|
||||||
es->negsize += 64;
|
es->negsize += 64;
|
||||||
es->events = sresize(es->events, es->negsize, char *);
|
es->events = sresize(es->events, es->negsize, char *);
|
||||||
}
|
}
|
||||||
|
|
||||||
time(&t);
|
tm=ltime();
|
||||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", &tm);
|
||||||
localtime(&t));
|
|
||||||
|
|
||||||
es->events[es->nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
|
es->events[es->nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
|
||||||
strcpy(es->events[es->nevents], timebuf);
|
strcpy(es->events[es->nevents], timebuf);
|
||||||
|
@ -661,7 +661,7 @@ int do_reconfig(HWND hwnd, int protcfginfo)
|
|||||||
void logevent(void *frontend, const char *string)
|
void logevent(void *frontend, const char *string)
|
||||||
{
|
{
|
||||||
char timebuf[40];
|
char timebuf[40];
|
||||||
time_t t;
|
struct tm tm;
|
||||||
|
|
||||||
log_eventlog(logctx, string);
|
log_eventlog(logctx, string);
|
||||||
|
|
||||||
@ -670,9 +670,8 @@ void logevent(void *frontend, const char *string)
|
|||||||
events = sresize(events, negsize, char *);
|
events = sresize(events, negsize, char *);
|
||||||
}
|
}
|
||||||
|
|
||||||
time(&t);
|
tm=ltime();
|
||||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", &tm);
|
||||||
localtime(&t));
|
|
||||||
|
|
||||||
events[nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
|
events[nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
|
||||||
strcpy(events[nevents], timebuf);
|
strcpy(events[nevents], timebuf);
|
||||||
|
@ -1279,14 +1279,12 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
|||||||
*/
|
*/
|
||||||
*state->commentptr = snewn(30, char);
|
*state->commentptr = snewn(30, char);
|
||||||
{
|
{
|
||||||
time_t t;
|
struct tm tm;
|
||||||
struct tm *tm;
|
tm = ltime();
|
||||||
time(&t);
|
|
||||||
tm = localtime(&t);
|
|
||||||
if (state->is_dsa)
|
if (state->is_dsa)
|
||||||
strftime(*state->commentptr, 30, "dsa-key-%Y%m%d", tm);
|
strftime(*state->commentptr, 30, "dsa-key-%Y%m%d", &tm);
|
||||||
else
|
else
|
||||||
strftime(*state->commentptr, 30, "rsa-key-%Y%m%d", tm);
|
strftime(*state->commentptr, 30, "rsa-key-%Y%m%d", &tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
20
windows/wintime.c
Normal file
20
windows/wintime.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "putty.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
struct tm ltime(void)
|
||||||
|
{
|
||||||
|
SYSTEMTIME st;
|
||||||
|
struct tm tm;
|
||||||
|
|
||||||
|
GetLocalTime(&st);
|
||||||
|
tm.tm_sec=st.wSecond;
|
||||||
|
tm.tm_min=st.wMinute;
|
||||||
|
tm.tm_hour=st.wHour;
|
||||||
|
tm.tm_mday=st.wDay;
|
||||||
|
tm.tm_mon=st.wMonth-1;
|
||||||
|
tm.tm_year=(st.wYear>=1900?st.wYear-1900:0);
|
||||||
|
tm.tm_wday=st.wDayOfWeek;
|
||||||
|
tm.tm_yday=-1; /* GetLocalTime doesn't tell us */
|
||||||
|
tm.tm_isdst=0; /* GetLocalTime doesn't tell us */
|
||||||
|
return tm;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user