Skip to content

Commit

Permalink
Fix cert expiry warning for Windows, which lacks gmtime_r()
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Feb 5, 2014
1 parent 113965a commit 0f1e550
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions gnutls.c
Expand Up @@ -210,12 +210,27 @@ static int check_certificate_expiry(struct openconnect_info *vpninfo, gnutls_x50
reason = _("Client certificate expires soon at");

if (reason) {
struct tm tm;
char buf[80];
#ifdef _WIN32
/*
* Windows doesn't have gmtime_r but apparently its gmtime()
* *is* thread-safe because it uses a per-thread static buffer.
* cf. http://sourceforge.net/p/mingw/bugs/1625/
*
* We also explicitly say 'GMT' because %Z would give us the
* Microsoft stupidity "GMT Standard Time". Which is not only
* silly, but also ambiguous because Windows actually says that
* even when it means British Summer Time (GMT+1). And having
* used gmtime() we really *are* giving the time in GMT.
*/
struct tm *tm = gmtime(&expires);
strftime(buf, 80, "%a, %d %b %Y %H:%M:%S GMT", tm);
#else
struct tm tm;

gmtime_r(&expires, &tm);
strftime(buf, 80, "%a, %d %b %Y %T %Z", &tm);

#endif
vpn_progress(vpninfo, PRG_ERR, "%s: %s\n", reason, buf);
}
return 0;
Expand Down

0 comments on commit 0f1e550

Please sign in to comment.