summaryrefslogtreecommitdiffstats
path: root/source/lib/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib/time.c')
-rw-r--r--source/lib/time.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/source/lib/time.c b/source/lib/time.c
index 84004a099be..9f94791b581 100644
--- a/source/lib/time.c
+++ b/source/lib/time.c
@@ -791,3 +791,25 @@ SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt)
SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec;
return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec);
}
+
+
+/****************************************************************************
+ convert ASN.1 GeneralizedTime string to unix-time
+ returns 0 on failure; Currently ignores timezone.
+****************************************************************************/
+time_t generalized_to_unix_time(const char *str)
+{
+ struct tm tm;
+
+ ZERO_STRUCT(tm);
+
+ if (sscanf(str, "%4d%2d%2d%2d%2d%2d",
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+ return 0;
+ }
+ tm.tm_year -= 1900;
+ tm.tm_mon -= 1;
+
+ return timegm(&tm);
+}