From eb5ae2b47322a30fe3e225ed0a50c1818fdf03d1 Mon Sep 17 00:00:00 2001 From: Keith Vetter Date: Thu, 2 Mar 1995 01:36:56 +0000 Subject: [PATCH] Ported 2 files needed by the crypto library to work on the PC git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5054 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 9 +++ src/lib/krb5/os/Makefile.in | 68 ++++++++++---------- src/lib/krb5/os/localaddr.c | 57 ++++++++++++++++- src/lib/krb5/os/ustime.c | 121 +++++++++++++++++++++++++++++++++++- 4 files changed, 221 insertions(+), 34 deletions(-) diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index d1e55452d..a11642544 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,12 @@ +Wed Mar 1 17:30:00 1995 Keith Vetter (keithv@fusion.com) + + * Makefile.in: made to work on the PC + * ustime.c: added section for time on the PC + * localaddr.c: added section for the PC--returns local IP address + N.B. not sure how we're going to handle different machine dependent + code changes. For now it's just added to the end of the file. Later, + we have to decide on a solution for all. + Tue Feb 28 01:07:37 1995 John Gilmore (gnu at toad.com) * *.c: Avoid includes. diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index badf4c093..aefffdd3d 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -1,40 +1,42 @@ CFLAGS = $(CCOPTS) $(DEFS) LDFLAGS = -g -all:: $(OBJS) +##DOSBUILDTOP = ..\..\.. +##DOSLIBNAME=..\libkrb5.lib +##DOS!include $(BUILDTOP)\config\windows.in OBJS= \ - an_to_ln.o \ - def_realm.o \ - ccdefname.o \ - free_krbhs.o \ - free_hstrl.o \ - full_ipadr.o \ - get_krbhst.o \ - gen_port.o \ - gen_rname.o \ - gmt_mktime.o \ - hst_realm.o \ - init_os_ctx.o \ - krbfileio.o \ - ktdefname.o \ - kuserok.o \ - localaddr.o \ - locate_kdc.o \ - lock_file.o \ - net_read.o \ - net_write.o \ - osconfig.o \ - port2ip.o \ - read_msg.o \ - read_pwd.o \ - realm_dom.o \ - sendto_kdc.o \ - sn2princ.o \ - timeofday.o \ - unlck_file.o \ - ustime.o \ - write_msg.o + an_to_ln.$(OBJEXT) \ + def_realm.$(OBJEXT) \ + ccdefname.$(OBJEXT) \ + free_krbhs.$(OBJEXT) \ + free_hstrl.$(OBJEXT) \ + full_ipadr.$(OBJEXT) \ + get_krbhst.$(OBJEXT) \ + gen_port.$(OBJEXT) \ + gen_rname.$(OBJEXT) \ + gmt_mktime.$(OBJEXT) \ + hst_realm.$(OBJEXT) \ + init_os_ctx.$(OBJEXT) \ + krbfileio.$(OBJEXT) \ + ktdefname.$(OBJEXT) \ + kuserok.$(OBJEXT) \ + localaddr.$(OBJEXT) \ + locate_kdc.$(OBJEXT) \ + lock_file.$(OBJEXT) \ + net_read.$(OBJEXT) \ + net_write.$(OBJEXT) \ + osconfig.$(OBJEXT) \ + port2ip.$(OBJEXT) \ + read_msg.$(OBJEXT) \ + read_pwd.$(OBJEXT) \ + realm_dom.$(OBJEXT) \ + sendto_kdc.$(OBJEXT) \ + sn2princ.$(OBJEXT) \ + timeofday.$(OBJEXT) \ + unlck_file.$(OBJEXT) \ + ustime.$(OBJEXT) \ + write_msg.$(OBJEXT) SRCS= \ $(srcdir)/an_to_ln.c \ @@ -68,3 +70,5 @@ SRCS= \ $(srcdir)/unlck_file.c \ $(srcdir)/ustime.c \ $(srcdir)/write_msg.c + +all:: $(OBJS) diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c index 1e35ca4ec..2e0a52a25 100644 --- a/src/lib/krb5/os/localaddr.c +++ b/src/lib/krb5/os/localaddr.c @@ -29,6 +29,8 @@ #include "k5-int.h" +#ifndef _MSDOS + /* needed for solaris, harmless elsewhere... */ #define BSD_COMP #include @@ -86,7 +88,8 @@ extern int errno; * This uses the SIOCGIFCONF, SIOCGIFFLAGS, and SIOCGIFADDR ioctl's. */ -krb5_error_code krb5_os_localaddr(addr) +krb5_error_code INTERFACE +krb5_os_localaddr(addr) krb5_address ***addr; { struct ifreq *ifr; @@ -217,3 +220,55 @@ krb5_error_code krb5_os_localaddr(addr) (*addr)[n_found] = 0; return 0; } + +#else /* DOS version */ + +/* No ioctls in winsock so we just assume there is only one networking + * card per machine, so gethostent is good enough. + */ +#include +#include + +krb5_error_code INTERFACE +krb5_os_localaddr (krb5_address ***addr) { + char host[64]; /* Name of local machine */ + struct hostent *hostrec; + int err; + + *addr = calloc (2, sizeof (krb5_address *)); + if (*addr == NULL) + return ENOMEM; + + if (gethostname (host, sizeof(host))) { + err = WSAGetLastError(); + return err; + } + + + hostrec = gethostbyname (host); + if (hostrec == NULL) { + err = WSAGetLastError(); + return err; + } + + (*addr)[0] = calloc (1, sizeof(krb5_address)); + if ((*addr)[0] == NULL) { + free (*addr); + return ENOMEM; + } + (*addr)[0]->addrtype = ADDRTYPE_INET; + (*addr)[0]->length = sizeof(struct in_addr); + (*addr)[0]->contents = (unsigned char *)malloc((*addr)[0]->length); + if (!(*addr)[0]->contents) { + free((*addr)[0]); + free(*addr); + return ENOMEM; + } else { + memcpy ((char *)(*addr)[0]->contents, + (char *)hostrec->h_addr, + (*addr)[0]->length); + } + + return(0); +} +#endif diff --git a/src/lib/krb5/os/ustime.c b/src/lib/krb5/os/ustime.c index 1d5014691..edc59b9a8 100644 --- a/src/lib/krb5/os/ustime.c +++ b/src/lib/krb5/os/ustime.c @@ -26,11 +26,13 @@ #include "k5-int.h" +#ifndef _MSDOS + extern int errno; static struct timeval last_tv = {0, 0}; -krb5_error_code +krb5_error_code INTERFACE krb5_us_timeofday(context, seconds, microseconds) krb5_context context; register krb5_int32 *seconds, *microseconds; @@ -54,3 +56,120 @@ krb5_us_timeofday(context, seconds, microseconds) *microseconds = tv.tv_usec; return 0; } + +#else /* DOS version */ +/* + * Originally written by John Gilmore, Cygnus Support, May '94. + * Public Domain. + */ + +#include +#include +#include + +/* + * Time handling. Translate Unix time calls into Kerberos internal + * procedure calls. + * + * 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 time_t win_gettime (); +static long win_time_get_epoch(); /* Adjust for MSC 7.00 bug */ + +krb5_error_code INTERFACE +krb5_us_timeofday(context, seconds, microseconds) +krb5_context context; +register krb5_int32 *seconds, *microseconds; +{ + krb5_int32 sec, usec; + static krb5_int32 last_sec = 0; + static krb5_int32 last_usec = 0; + + sec = win_gettime (); /* Get the current time */ + usec = 0; /* Can't do microseconds */ + + if (sec == last_sec) { /* Same as last time??? */ + usec = ++last_usec; /* Yep, so do microseconds */ + if (usec >= 1000000) { + ++sec; + usec = 0; + } + } + last_sec = sec; /* Remember for next time */ + last_usec = usec; + + *seconds = sec; /* Return the values */ + *microseconds = usec; + + return 0; +} +static time_t +win_gettime () { + 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 */ + void memset(); + + _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(); + return time + convert; + +} +/* + * 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; + +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