From: Theodore Tso Date: Fri, 1 Sep 1995 05:39:48 +0000 (+0000) Subject: * toffset.c: Added new file which implements the abstract interfaces X-Git-Tag: krb5-1.0-beta6~1209 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=565dd658322a355c127c2f8c4decde771e81acfd;p=krb5.git * toffset.c: Added new file which implements the abstract interfaces for manipulating the time offset fields in the os context. ustime.c (krb5_us_timeofday): Add support for using the time offset fields in the os context. timeofday.c (krb5_timeofday): Add support for using the time offset fields in the os context. init_os_ctx.c (krb5_os_init_context): Initialize the time offset and flags fields in the os context. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6647 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 8c36e44c5..41e501380 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,5 +1,20 @@ +Fri Sep 1 00:47:27 1995 Theodore Y. Ts'o + + * toffset.c: Added new file which implements the abstract + interfaces for manipulating the time offset fields in the + os context. + + * ustime.c (krb5_us_timeofday): Add support for using the time + offset fields in the os context. + + * timeofday.c (krb5_timeofday): Add support for using the time + offset fields in the os context. + + * init_os_ctx.c (krb5_os_init_context): Initialize the time offset + and flags fields in the os context. Thu Aug 31 17:24:48 EDT 1995 Paul Park (pjpark@mit.edu) + * t_an_to_ln.c - Translate until error and return status. * Makefile.in - Test aname_to_lname under check-unix. diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index 27ed3ccf4..72228c303 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -42,6 +42,7 @@ OBJS= \ sendto_kdc.$(OBJEXT) \ sn2princ.$(OBJEXT) \ timeofday.$(OBJEXT) \ + toffset.$(OBJEXT) \ unlck_file.$(OBJEXT) \ ustime.$(OBJEXT) \ write_msg.$(OBJEXT) @@ -79,6 +80,7 @@ SRCS= \ $(srcdir)/sendto_kdc.c \ $(srcdir)/sn2princ.c \ $(srcdir)/timeofday.c \ + $(srcdir)/toffset.c \ $(srcdir)/unlck_file.c \ $(srcdir)/ustime.c \ $(srcdir)/write_msg.c diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index 49921a900..08fe13ee0 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -46,6 +46,10 @@ krb5_os_init_context(ctx) ctx->os_context = (void *) os_ctx; + os_ctx->time_offset = 0; + os_ctx->usec_offset = 0; + os_ctx->os_flags = 0; + #ifdef _WINDOWS { char defname[160]; /* Default value */ diff --git a/src/lib/krb5/os/timeofday.c b/src/lib/krb5/os/timeofday.c index 3aaf81485..0499ff26f 100644 --- a/src/lib/krb5/os/timeofday.c +++ b/src/lib/krb5/os/timeofday.c @@ -44,11 +44,18 @@ krb5_timeofday(context, timeret) krb5_context context; register krb5_int32 *timeret; { + krb5_os_context os_ctx = context->os_context; timetype tval; + if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) { + *timeret = os_ctx->time_offset; + return 0; + } tval = time(0); if (tval == (timetype) -1) return (krb5_error_code) errno; + if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) + tval += os_ctx->time_offset; *timeret = tval; return 0; } diff --git a/src/lib/krb5/os/toffset.c b/src/lib/krb5/os/toffset.c new file mode 100644 index 000000000..2debd9f98 --- /dev/null +++ b/src/lib/krb5/os/toffset.c @@ -0,0 +1,121 @@ +/* + * lib/krb5/os/toffset.c + * + * Copyright 1995 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * These routines manipulates the time offset fields in the os context. + */ + +#include "k5-int.h" + +/* + * This routine takes the "real time" as input, and sets the time + * offset field in the context structure so that the krb5 time + * routines will return the correct time as corrected by difference + * between the system time and the "real time" as passed to this + * routine + */ +krb5_error_code +krb5_set_real_time(context, seconds, microseconds) + krb5_context context; + krb5_int32 seconds, microseconds; +{ + krb5_os_context os_ctx = context->os_context; + krb5_int32 sec, usec; + krb5_error_code retval; + + retval = krb5_crypto_us_timeofday(&sec, &usec); + if (retval) + return retval; + os_ctx->time_offset = seconds - sec; + os_ctx->usec_offset = microseconds - usec; + os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_TIME) | + KRB5_OS_TOFFSET_VALID); + return 0; +} + +/* + * This routine sets the krb5 time routines so that they will return + * the seconds and microseconds value as input to this function. This + * is useful for running the krb5 routines through test suites + */ +krb5_error_code +krb5_set_debugging_time(context, seconds, microseconds) + krb5_context context; + krb5_int32 seconds, microseconds; +{ + krb5_os_context os_ctx = context->os_context; + + os_ctx->time_offset = seconds; + os_ctx->usec_offset = microseconds; + os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_VALID) | + KRB5_OS_TOFFSET_TIME); + return 0; +} + +/* + * This routine turns off the time correction fields, so that the krb5 + * routines return the "natural" time. + */ +krb5_error_code +krb5_use_natural_time(context) + krb5_context context; +{ + krb5_os_context os_ctx = context->os_context; + + os_ctx->os_flags &= ~(KRB5_OS_TOFFSET_VALID|KRB5_OS_TOFFSET_TIME); + + return 0; +} + +/* + * This routine returns the current time offsets in use. + */ +krb5_error_code +krb5_get_time_offsets(context, seconds, microseconds) + krb5_context context; + krb5_int32 *seconds, *microseconds; +{ + krb5_os_context os_ctx = context->os_context; + + if (seconds) + *seconds = os_ctx->time_offset; + if (microseconds) + *microseconds = os_ctx->usec_offset; + return 0; +} + + +/* + * This routine sets the time offsets directly. + */ +krb5_error_code +krb5_set_time_offsets(context, seconds, microseconds) + krb5_context context; + krb5_int32 seconds, microseconds; +{ + krb5_os_context os_ctx = context->os_context; + + os_ctx->time_offset = seconds; + os_ctx->usec_offset = microseconds; + os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_TIME) | + KRB5_OS_TOFFSET_VALID); + return 0; +} diff --git a/src/lib/krb5/os/ustime.c b/src/lib/krb5/os/ustime.c index 853a83f23..9fd9dd726 100644 --- a/src/lib/krb5/os/ustime.c +++ b/src/lib/krb5/os/ustime.c @@ -20,8 +20,12 @@ * this software for any purpose. It is provided "as is" without express * or implied warranty. * - * Just a stub that calls krb5_crypto_us_timeofday(). - * + * krb5_crypto_us_timeofday() does all of the real work; however, we + * handle the time offset adjustment here, since this is context + * specific, and the crypto version of this call doesn't have access + * to the context variable. Fortunately the only user of + * krb5_crypto_us_timeofday in the crypto library doesn't require that + * this time adjustment be done. */ #include "k5-int.h" @@ -31,5 +35,27 @@ krb5_us_timeofday(context, seconds, microseconds) krb5_context context; krb5_int32 *seconds, *microseconds; { - return krb5_crypto_us_timeofday(seconds, microseconds); + krb5_os_context os_ctx = context->os_context; + krb5_int32 sec, usec; + krb5_error_code retval; + + if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) { + *seconds = os_ctx->time_offset; + *microseconds = os_ctx->usec_offset; + return 0; + } + retval = krb5_crypto_us_timeofday(&sec, &usec); + if (retval) + return retval; + if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) { + usec += os_ctx->usec_offset; + if (usec > 1000000) { + usec -= 1000000; + sec++; + } + sec += os_ctx->time_offset; + } + *seconds = sec; + *microseconds = usec; + return 0; }