From 15ddec639305cfb75fdbc738814a5307ca815b4f Mon Sep 17 00:00:00 2001 From: Keith Vetter Date: Wed, 22 Mar 1995 22:28:10 +0000 Subject: [PATCH] New file, unix_time, didn't work on the PC git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5197 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/des425/ChangeLog | 7 +++ src/lib/des425/des.h | 2 +- src/lib/des425/read_passwd.c | 2 +- src/lib/des425/unix_time.c | 96 ++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 2 deletions(-) diff --git a/src/lib/des425/ChangeLog b/src/lib/des425/ChangeLog index 955051c1b..3782fc850 100644 --- a/src/lib/des425/ChangeLog +++ b/src/lib/des425/ChangeLog @@ -1,3 +1,10 @@ +Wed Mar 22 11:21:38 1995 Keith Vetter (keithv@fusion.com) + + * read_passwd.c: changed return value to krb5_error_code + * des.h: same as above + * unix_time.c: didn't work on the PC. Copied PC time code from + krb5\os\ustime.c. + Mon Mar 20 21:14:40 1995 Theodore Y. Ts'o * Makefile.in, unix_time.c(unix_time_gmt_unixsec): Added function diff --git a/src/lib/des425/des.h b/src/lib/des425/des.h index 9bd6885ea..df5f0f31d 100644 --- a/src/lib/des425/des.h +++ b/src/lib/des425/des.h @@ -80,7 +80,7 @@ void INTERFACE des_generate_random_block(); int INTERFACE des_pcbc_encrypt(); unsigned long INTERFACE des_quad_cksum(); int INTERFACE des_random_key(); -int INTERFACE des_read_password(); +krb5_error_code INTERFACE des_read_password(); int INTERFACE des_string_to_key(); int INTERFACE des_is_weak_key(); diff --git a/src/lib/des425/read_passwd.c b/src/lib/des425/read_passwd.c index b010b5127..61207c69a 100644 --- a/src/lib/des425/read_passwd.c +++ b/src/lib/des425/read_passwd.c @@ -32,7 +32,7 @@ static krb5_context krb4_global_context = 0; /*** Routines ****************************************************** */ -int INTERFACE +krb5_error_code INTERFACE des_read_password/*_v4_compat_crock*/(k,prompt,verify) mit_des_cblock *k; char *prompt; diff --git a/src/lib/des425/unix_time.c b/src/lib/des425/unix_time.c index c69be6186..786d13575 100644 --- a/src/lib/des425/unix_time.c +++ b/src/lib/des425/unix_time.c @@ -9,7 +9,10 @@ * Required for use by the Cygnus krb.a. */ + #include "k5-int.h" + +#ifndef _MSDOS #include krb5_ui_4 INTERFACE @@ -23,3 +26,96 @@ unix_time_gmt_unixsec (usecptr) *usecptr = now.tv_usec; return now.tv_sec; } + +#else /* _MSDOS */ + +/* + * Originally written by John Gilmore, Cygnus Support, May '94. + * Public Domain. + */ + +#include +#include +#include +#include + +/* + * Due to the fact that DOS time can be unreliable we have reverted + * to using the AT hardware clock and converting it to Unix time. + */ +static long win_time_get_epoch(void); + +krb5_ui_4 INTERFACE +unix_time_gmt_unixsec (usecptr) + krb5_ui_4 *usecptr; +{ + struct tm tm; + union _REGS inregs; /* For calling BIOS */ + union _REGS outregs; + struct _timeb now; + time_t time; + long convert; /* MSC 7.00 bug work around */ + krb5_ui_4 retval; /* What we return */ + + _ftime(&now); /* Daylight savings time */ + + /* Get time from AT hardware clock INT 0x1A, AH=2 */ + memset(&inregs, 0, sizeof(inregs)); + inregs.h.ah = 2; + _int86(0x1a, &inregs, &outregs); + + /* 0x13 = decimal 13, hence the decoding below */ + tm.tm_sec = 10 * ((outregs.h.dh & 0xF0) >> 4) + (outregs.h.dh & 0x0F); + tm.tm_min = 10 * ((outregs.h.cl & 0xF0) >> 4) + (outregs.h.cl & 0x0F); + tm.tm_hour = 10 * ((outregs.h.ch & 0xF0) >> 4) + (outregs.h.ch & 0x0F); + + /* Get date from AT hardware clock INT 0x1A, AH=4 */ + memset(&inregs, 0, sizeof(inregs)); + inregs.h.ah = 4; + _int86(0x1a, &inregs, &outregs); + + tm.tm_mday = 10 * ((outregs.h.dl & 0xF0) >> 4) + (outregs.h.dl & 0x0F); + tm.tm_mon = 10 * ((outregs.h.dh & 0xF0) >> 4) + (outregs.h.dh & 0x0F) - 1; + tm.tm_year = 10 * ((outregs.h.cl & 0xF0) >> 4) + (outregs.h.cl & 0x0F); + tm.tm_year += 100 * ((10 * (outregs.h.ch & 0xF0) >> 4) + + (outregs.h.ch & 0x0F) - 19); + + tm.tm_wday = 0; + tm.tm_yday = 0; + tm.tm_isdst = now.dstflag; + + time = mktime(&tm); + + convert = win_time_get_epoch(); + retval = time + convert; + + if (usecptr) + *usecptr = retval; + + return retval; +} +/* + * This routine figures out the current time epoch and returns the + * conversion factor. It exists because + * Microloss screwed the pooch on the time() and _ftime() calls in + * its release 7.0 libraries. They changed the epoch to Dec 31, 1899! + * Idiots... We try to cope. + */ + +static struct tm jan_1_70 = {0, 0, 0, 1, 0, 70}; +static long epoch = 0; +static int epoch_set = 0; + +static long +win_time_get_epoch() +{ + + if (!epoch_set) { + epoch = 0 - mktime (&jan_1_70); /* Seconds til 1970 localtime */ + epoch += _timezone; /* Seconds til 1970 GMT */ + epoch_set = 1; + } + return epoch; +} + +#endif -- 2.26.2