version 1.179, 2010/02/26 20:29:54 |
version 1.180, 2010/03/02 23:20:57 |
|
|
{ |
{ |
struct tm tm; |
struct tm tm; |
time_t tt; |
time_t tt; |
|
char buf[32], *fmt; |
|
|
if (strlen(s) != 8 && strlen(s) != 14) |
/* |
|
* POSIX strptime says "The application shall ensure that there |
|
* is white-space or other non-alphanumeric characters between |
|
* any two conversion specifications" so arrange things this way. |
|
*/ |
|
switch (strlen(s)) { |
|
case 8: |
|
fmt = "%Y/%m/%d"; |
|
snprintf(buf, sizeof(buf), "%.4s/%.2s/%.2s", s, s + 4, s + 6); |
|
break; |
|
case 14: |
|
fmt = "%Y/%m/%d %H:%M:%S"; |
|
snprintf(buf, sizeof(buf), "%.4s/%.2s/%.2s %.2s:%.2s:%.2s", |
|
s, s + 4, s + 6, s + 8, s + 10, s + 12); |
|
break; |
|
default: |
fatal("Invalid certificate time format %s", s); |
fatal("Invalid certificate time format %s", s); |
|
} |
|
|
bzero(&tm, sizeof(tm)); |
bzero(&tm, sizeof(tm)); |
if (strptime(s, |
if (strptime(buf, fmt, &tm) == NULL) |
strlen(s) == 8 ? "%Y%m%d" : "%Y%m%d%H%M%S", &tm) == NULL) |
|
fatal("Invalid certificate time %s", s); |
fatal("Invalid certificate time %s", s); |
if ((tt = mktime(&tm)) < 0) |
if ((tt = mktime(&tm)) < 0) |
fatal("Certificate time %s cannot be represented", s); |
fatal("Certificate time %s cannot be represented", s); |