aboutsummaryrefslogtreecommitdiff
path: root/otime.h
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2006-04-13 20:02:27 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2006-04-13 20:02:27 +0000
commite5239fc26e88f70909c9c2b6b75906ad8898f974 (patch)
treeb6cdfb08aa66f46d1757afda4d50ce971123cc7f /otime.h
parentMerged PKCS#11 extensions to easy-rsa/2.0 (Alon Bar-Lev). (diff)
downloadopenvpn-e5239fc26e88f70909c9c2b6b75906ad8898f974.tar.xz
Re-added backtrack handling code.
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@1008 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to '')
-rw-r--r--otime.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/otime.h b/otime.h
index 2dca396..2e01bb2 100644
--- a/otime.h
+++ b/otime.h
@@ -58,6 +58,40 @@ extern time_t now; /* updated frequently to time(NULL) */
void time_test (void);
+#if TIME_BACKTRACK_PROTECTION && defined(HAVE_GETTIMEOFDAY)
+
+void update_now (const time_t system_time);
+
+extern time_t now_usec;
+void update_now_usec (struct timeval *tv);
+
+static inline int
+openvpn_gettimeofday (struct timeval *tv, void *tz)
+{
+ const int status = gettimeofday (tv, tz);
+ if (!status)
+ {
+ update_now_usec (tv);
+ tv->tv_sec = now;
+ tv->tv_usec = now_usec;
+ }
+ return status;
+}
+
+static inline void
+update_time (void)
+{
+#ifdef WIN32
+ /* on WIN32, gettimeofday is faster than time(NULL) */
+ struct timeval tv;
+ openvpn_gettimeofday (&tv, NULL);
+#else
+ update_now (time (NULL));
+#endif
+}
+
+#else /* !(TIME_BACKTRACK_PROTECTION && defined(HAVE_GETTIMEOFDAY)) */
+
static inline void
update_time (void)
{
@@ -85,6 +119,8 @@ openvpn_gettimeofday (struct timeval *tv, void *tz)
#endif
+#endif /* TIME_BACKTRACK_PROTECTION && defined(HAVE_GETTIMEOFDAY) */
+
static inline time_t
openvpn_time (time_t *t)
{