summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/krb5/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/heimdal/lib/krb5/time.c')
-rw-r--r--crypto/heimdal/lib/krb5/time.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/crypto/heimdal/lib/krb5/time.c b/crypto/heimdal/lib/krb5/time.c
index 9346546..4cd992d 100644
--- a/crypto/heimdal/lib/krb5/time.c
+++ b/crypto/heimdal/lib/krb5/time.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997-2004 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -33,13 +33,38 @@
#include "krb5_locl.h"
-RCSID("$Id: time.c,v 1.5 2001/05/02 10:06:11 joda Exp $");
+RCSID("$Id: time.c 14308 2004-10-13 17:57:11Z lha $");
+
+/*
+ * Set the absolute time that the caller knows the kdc has so the
+ * kerberos library can calculate the relative diffrence beteen the
+ * KDC time and local system time.
+ */
+
+krb5_error_code KRB5_LIB_FUNCTION
+krb5_set_real_time (krb5_context context,
+ krb5_timestamp sec,
+ int32_t usec)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+
+ context->kdc_sec_offset = sec - tv.tv_sec;
+ context->kdc_usec_offset = usec - tv.tv_usec;
+
+ if (context->kdc_usec_offset < 0) {
+ context->kdc_sec_offset--;
+ context->kdc_usec_offset += 1000000;
+ }
+ return 0;
+}
/*
* return ``corrected'' time in `timeret'.
*/
-krb5_error_code
+krb5_error_code KRB5_LIB_FUNCTION
krb5_timeofday (krb5_context context,
krb5_timestamp *timeret)
{
@@ -51,9 +76,9 @@ krb5_timeofday (krb5_context context,
* like gettimeofday but with time correction to the KDC
*/
-krb5_error_code
+krb5_error_code KRB5_LIB_FUNCTION
krb5_us_timeofday (krb5_context context,
- int32_t *sec,
+ krb5_timestamp *sec,
int32_t *usec)
{
struct timeval tv;
@@ -65,7 +90,7 @@ krb5_us_timeofday (krb5_context context,
return 0;
}
-krb5_error_code
+krb5_error_code KRB5_LIB_FUNCTION
krb5_format_time(krb5_context context, time_t t,
char *s, size_t len, krb5_boolean include_time)
{
@@ -74,14 +99,16 @@ krb5_format_time(krb5_context context, time_t t,
tm = gmtime (&t);
else
tm = localtime(&t);
- strftime(s, len, include_time ? context->time_fmt : context->date_fmt, tm);
+ if(tm == NULL ||
+ strftime(s, len, include_time ? context->time_fmt : context->date_fmt, tm) == 0)
+ snprintf(s, len, "%ld", (long)t);
return 0;
}
-krb5_error_code
+krb5_error_code KRB5_LIB_FUNCTION
krb5_string_to_deltat(const char *string, krb5_deltat *deltat)
{
if((*deltat = parse_time(string, "s")) == -1)
- return EINVAL;
+ return KRB5_DELTAT_BADFORMAT;
return 0;
}
OpenPOWER on IntegriCloud