From: John Gilmore Date: Wed, 29 Mar 1995 02:46:29 +0000 (+0000) Subject: * DNR.c: Add Apple MacTCP source file for domain name resolution. X-Git-Tag: krb5-1.0-beta5~422 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=599b7d751e1d4c689047aefe8bc3bf90c810b8a5;p=krb5.git * DNR.c: Add Apple MacTCP source file for domain name resolution. * macsock.c: Add fake socket support routines for MacTCP. * Makefile.in (OBJS, SRCS): Add DNR and macsock. * ccdefname.c: On Mac, default cred cache is "STDIO:krb5cc" for now. FIXME, this needs to find the Preferences folder and use that. FIXME, shouldn't be conditioned on HAVE_MACSOCK_H. * gmt_mktime.c: Use HAVE_SYS_TYPES_H. * krbfileio.c: Remove . * localaddr.c, sendto_kdc.c: Convert to more generic socket support. Use closesocket instead of close, SOCKET_ERRNO rather than errno, SOCKET rather than int, etc. * localaddr.c: Use getmyipaddr() from macsock.c, if on Mac. Add FIXME for multiple local addresses. * lock_file.c: Provide a dummy version for MacOS. * read_pwd.c (ECHO_PASSWORD): Add #ifdef's to avoid all the ioctls and other stuff that turn off echoing. This is useful for debugging on MacOS. FIXME: ECHO_PASSWORD needs to be added to configure.in. * ustime.c: Bring in Mac-specific time-and-timezone code. It probably isn't hooked up correctly, yet. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5299 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index dfac63ea8..51ba47587 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,25 @@ +Tue Mar 28 18:35:20 1995 John Gilmore (gnu at toad.com) + + * DNR.c: Add Apple MacTCP source file for domain name resolution. + * macsock.c: Add fake socket support routines for MacTCP. + * Makefile.in (OBJS, SRCS): Add DNR and macsock. + * ccdefname.c: On Mac, default cred cache is "STDIO:krb5cc" for now. + FIXME, this needs to find the Preferences folder and use that. + FIXME, shouldn't be conditioned on HAVE_MACSOCK_H. + * gmt_mktime.c: Use HAVE_SYS_TYPES_H. + * krbfileio.c: Remove . + * localaddr.c, sendto_kdc.c: Convert to more generic socket + support. Use closesocket instead of close, SOCKET_ERRNO rather + than errno, SOCKET rather than int, etc. + * localaddr.c: Use getmyipaddr() from macsock.c, if on Mac. + Add FIXME for multiple local addresses. + * lock_file.c: Provide a dummy version for MacOS. + * read_pwd.c (ECHO_PASSWORD): Add #ifdef's to avoid all the ioctls + and other stuff that turn off echoing. This is useful for debugging + on MacOS. FIXME: ECHO_PASSWORD needs to be added to configure.in. + * ustime.c: Bring in Mac-specific time-and-timezone code. It + probably isn't hooked up correctly, yet. + Mon Mar 27 14:16:39 1995 John Gilmore (gnu at toad.com) * full_ipadr.c, gen_rname.c, port2ip.c, read_msg.c, write_msg.c: diff --git a/src/lib/krb5/os/DNR.c b/src/lib/krb5/os/DNR.c new file mode 100644 index 000000000..ce530c2a3 --- /dev/null +++ b/src/lib/krb5/os/DNR.c @@ -0,0 +1,314 @@ +/* DNR.c - Domain Name Resolver library for MPW + + (c) Copyright 1988 by Apple Computer. All rights reserved + + Modifications by Jim Matthews, Dartmouth College, 5/91 + + FIXME jcm - copied from Authman 1.0.7 release, file not in ftp.seeding.apple.com + FIXME jcm - slight improvments over the version in the KClient 1.1b1 release + FIXME jcm - All rights reserved Apple Computer +*/ + +#include "k5-int.h" +#ifdef HAVE_MACSOCK_H /* Only build this on the Macintosh */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define OPENRESOLVER 1L +#define CLOSERESOLVER 2L +#define STRTOADDR 3L +#define ADDRTOSTR 4L +#define ENUMCACHE 5L +#define ADDRTONAME 6L +#define HINFO 7L +#define MXINFO 8L + +Handle codeHndl = nil; + +typedef OSErr (*OSErrProcPtr)(long,...); +OSErrProcPtr dnr = nil; + + +TrapType GetTrapType(theTrap) +unsigned long theTrap; +{ + if (BitAnd(theTrap, 0x0800) > 0) + return(ToolTrap); + else + return(OSTrap); + } + +Boolean TrapAvailable(trap) +unsigned long trap; +{ +TrapType trapType = ToolTrap; +unsigned long numToolBoxTraps; + + if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap)) + numToolBoxTraps = 0x200; + else + numToolBoxTraps = 0x400; + + trapType = GetTrapType(trap); + if (trapType == ToolTrap) { + trap = BitAnd(trap, 0x07FF); + if (trap >= numToolBoxTraps) + trap = _Unimplemented; + } + return(NGetTrapAddress(trap, trapType) != NGetTrapAddress(_Unimplemented, ToolTrap)); + +} + +void GetSystemFolder(short *vRefNumP, long *dirIDP) +{ + SysEnvRec info; + long wdProcID; + + SysEnvirons(1, &info); + if (GetWDInfo(info.sysVRefNum, vRefNumP, dirIDP, &wdProcID) != noErr) { + *vRefNumP = 0; + *dirIDP = 0; + } + } + +void GetCPanelFolder(short *vRefNumP, long *dirIDP) +{ + Boolean hasFolderMgr = false; + long feature; + +/* + if (TrapAvailable(_GestaltDispatch)) if (Gestalt(gestaltFindFolderAttr, &feature) == noErr) hasFolderMgr = true; + + FIXME jcm - what defines _Gestalt + if (TrapAvailable(_Gestalt)) +*/ + if (Gestalt(gestaltFindFolderAttr, &feature) == noErr) hasFolderMgr = true; + if (!hasFolderMgr) { + GetSystemFolder(vRefNumP, dirIDP); + return; + } + else { + if (FindFolder(kOnSystemDisk, kControlPanelFolderType, kDontCreateFolder, vRefNumP, dirIDP) != noErr) { + *vRefNumP = 0; + *dirIDP = 0; + } + } + } + +/* SearchFolderForDNRP is called to search a folder for files that might + contain the 'dnrp' resource */ +short SearchFolderForDNRP(long targetType, long targetCreator, short vRefNum, long dirID) +{ + HParamBlockRec fi; + Str255 filename; + short refnum; + + fi.fileParam.ioCompletion = nil; + fi.fileParam.ioNamePtr = filename; + fi.fileParam.ioVRefNum = vRefNum; + fi.fileParam.ioDirID = dirID; + fi.fileParam.ioFDirIndex = 1; + + while (PBHGetFInfo(&fi, false) == noErr) { + /* scan system folder for driver resource files of specific type & creator */ + if (fi.fileParam.ioFlFndrInfo.fdType == targetType && + fi.fileParam.ioFlFndrInfo.fdCreator == targetCreator) { + /* found the MacTCP driver file? */ + + refnum = HOpenResFile(vRefNum, dirID, filename, fsRdPerm); + + SetResLoad(false); + if (GetIndResource('dnrp', 1) == NULL) { + SetResLoad(true); + CloseResFile(refnum); + } + else { + SetResLoad(true); + return refnum; + } + SetResLoad(true); + } + /* check next file in system folder */ + fi.fileParam.ioFDirIndex++; + fi.fileParam.ioDirID = dirID; /* PBHGetFInfo() clobbers ioDirID */ + } + return(-1); + } + +/* OpenOurRF is called to open the MacTCP driver resources */ + +short OpenOurRF() +{ + short refnum; + short vRefNum; + long dirID; + + /* first search Control Panels for MacTCP 1.1 */ + GetCPanelFolder(&vRefNum, &dirID); + refnum = SearchFolderForDNRP('cdev', 'ztcp', vRefNum, dirID); + if (refnum != -1) return(refnum); + + /* next search System Folder for MacTCP 1.0.x */ + GetSystemFolder(&vRefNum, &dirID); + refnum = SearchFolderForDNRP('cdev', 'mtcp', vRefNum, dirID); + if (refnum != -1) return(refnum); + + /* finally, search Control Panels for MacTCP 1.0.x */ + GetCPanelFolder(&vRefNum, &dirID); + refnum = SearchFolderForDNRP('cdev', 'mtcp', vRefNum, dirID); + if (refnum != -1) return(refnum); + + return -1; + } + + +OSErr OpenResolver(fileName) +char *fileName; +{ + short refnum; + OSErr rc; + + if (dnr != nil) + /* resolver already loaded in */ + return(noErr); + + /* open the MacTCP driver to get DNR resources. Search for it based on + creator & type rather than simply file name */ + refnum = OpenOurRF(); + + /* ignore failures since the resource may have been installed in the + System file if running on a Mac 512Ke */ + + /* load in the DNR resource package */ + codeHndl = GetIndResource('dnrp', 1); + if (codeHndl == nil) { + /* can't open DNR */ + return(ResError()); + } + + DetachResource(codeHndl); + if (refnum != -1) { + CloseWD(refnum); + CloseResFile(refnum); + } + + /* lock the DNR resource since it cannot be reloated while opened */ + HLock(codeHndl); + dnr = (OSErrProcPtr) *codeHndl; + + /* call open resolver */ + rc = (*dnr)(OPENRESOLVER, fileName); + if (rc != noErr) { + /* problem with open resolver, flush it */ + HUnlock(codeHndl); + DisposHandle(codeHndl); + dnr = nil; + } + return(rc); + } + + +OSErr CloseResolver() +{ + if (dnr == nil) + /* resolver not loaded error */ + return(notOpenErr); + + /* call close resolver */ + (void) (*dnr)(CLOSERESOLVER); + + /* release the DNR resource package */ + HUnlock(codeHndl); + DisposHandle(codeHndl); + dnr = nil; + return(noErr); + } + +OSErr StrToAddr(hostName, rtnStruct, resultproc, userDataPtr) +char *hostName; +struct hostInfo *rtnStruct; +long resultproc; +char *userDataPtr; +{ + if (dnr == nil) + /* resolver not loaded error */ + return(notOpenErr); + + return((*dnr)(STRTOADDR, hostName, rtnStruct, resultproc, userDataPtr)); + } + +OSErr AddrToStr(addr, addrStr) +unsigned long addr; +char *addrStr; +{ + if (dnr == nil) + /* resolver not loaded error */ + return(notOpenErr); + + (*dnr)(ADDRTOSTR, addr, addrStr); + return(noErr); + } + +OSErr EnumCache(resultproc, userDataPtr) +long resultproc; +char *userDataPtr; +{ + if (dnr == nil) + /* resolver not loaded error */ + return(notOpenErr); + + return((*dnr)(ENUMCACHE, resultproc, userDataPtr)); + } + + +OSErr AddrToName(addr, rtnStruct, resultproc, userDataPtr) +unsigned long addr; +struct hostInfo *rtnStruct; +long resultproc; +char *userDataPtr; +{ + if (dnr == nil) + /* resolver not loaded error */ + return(notOpenErr); + + return((*dnr)(ADDRTONAME, addr, rtnStruct, resultproc, userDataPtr)); + } + + +extern OSErr HInfo(hostName, returnRecPtr, resultProc, userDataPtr) +char *hostName; +struct returnRec *returnRecPtr; +long resultProc; +char *userDataPtr; +{ + if (dnr == nil) + /* resolver not loaded error */ + return(notOpenErr); + + return((*dnr)(HINFO, hostName, returnRecPtr, resultProc, userDataPtr)); + + } + +extern OSErr MXInfo(hostName, returnRecPtr, resultProc, userDataPtr) +char *hostName; +struct returnRec *returnRecPtr; +long resultProc; +char *userDataPtr; +{ + if (dnr == nil) + /* resolver not loaded error */ + return(notOpenErr); + + return((*dnr)(MXINFO, hostName, returnRecPtr, resultProc, userDataPtr)); + + } + +#endif /* HAVE_MACSOCK_H */ diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index 2e739c8cc..9e53e7205 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -7,6 +7,7 @@ CFLAGS = $(CCOPTS) $(DEFS) OBJS= \ an_to_ln.$(OBJEXT) \ def_realm.$(OBJEXT) \ + DNR.$(OBJEXT) \ ccdefname.$(OBJEXT) \ free_krbhs.$(OBJEXT) \ free_hstrl.$(OBJEXT) \ @@ -23,6 +24,7 @@ OBJS= \ localaddr.$(OBJEXT) \ locate_kdc.$(OBJEXT) \ lock_file.$(OBJEXT) \ + macsock.$(OBJEXT) \ net_read.$(OBJEXT) \ net_write.$(OBJEXT) \ osconfig.$(OBJEXT) \ @@ -40,6 +42,7 @@ OBJS= \ SRCS= \ $(srcdir)/an_to_ln.c \ $(srcdir)/def_realm.c \ + $(srcdir)/DNR.c \ $(srcdir)/ccdefname.c \ $(srcdir)/free_krbhs.c \ $(srcdir)/free_hstrl.c \ @@ -56,6 +59,7 @@ SRCS= \ $(srcdir)/localaddr.c \ $(srcdir)/locate_kdc.c \ $(srcdir)/lock_file.c \ + $(srcdir)/macsock.c \ $(srcdir)/net_read.c \ $(srcdir)/net_write.c \ $(srcdir)/osconfig.c \ diff --git a/src/lib/krb5/os/gmt_mktime.c b/src/lib/krb5/os/gmt_mktime.c index fac8e65f3..7cfeba201 100644 --- a/src/lib/krb5/os/gmt_mktime.c +++ b/src/lib/krb5/os/gmt_mktime.c @@ -2,7 +2,9 @@ #include +#ifdef HAVE_SYS_TYPES_H #include +#endif #ifdef HAVE_SYS_TIME_H #include #ifdef TIME_WITH_SYS_TIME diff --git a/src/lib/krb5/os/krbfileio.c b/src/lib/krb5/os/krbfileio.c index 1a54ddd7f..43d12478b 100644 --- a/src/lib/krb5/os/krbfileio.c +++ b/src/lib/krb5/os/krbfileio.c @@ -39,7 +39,6 @@ static char *VersionID = "@(#)krbfileio.c 2 - 08/22/91"; #ifdef HAVE_SYS_FILE_H #include #endif -#include #ifdef NEED_SYS_FCNTL_H #include #endif diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c index 9287f3808..54ca6ea5e 100644 --- a/src/lib/krb5/os/localaddr.c +++ b/src/lib/krb5/os/localaddr.c @@ -30,7 +30,7 @@ #define NEED_SOCKETS #include "k5-int.h" -#ifndef _MSDOS +#if !defined(HAVE_MACSOCK_H) && !defined(_MSDOS) /* needed for solaris, harmless elsewhere... */ #define BSD_COMP @@ -109,7 +109,7 @@ krb5_os_localaddr(addr) code = ioctl (s, SIOCGIFCONF, (char *)&ifc); if (code < 0) { int retval = errno; - close(s); + closesocket (s); return retval; } n = ifc.ifc_len / sizeof (struct ifreq); @@ -220,7 +220,7 @@ krb5_os_localaddr(addr) return 0; } -#else /* DOS version */ +#else /* Windows/Mac version */ /* No ioctls in winsock so we just assume there is only one networking * card per machine, so gethostent is good enough. @@ -236,25 +236,28 @@ krb5_os_localaddr (krb5_address ***addr) { if (*addr == NULL) return ENOMEM; +#ifdef HAVE_MACSOCK_H + hostrec = getmyipaddr(); +#else /* HAVE_MACSOCK_H */ if (gethostname (host, sizeof(host))) { err = WSAGetLastError(); return err; } - hostrec = gethostbyname (host); if (hostrec == NULL) { err = WSAGetLastError(); return err; } +#endif /* HAVE_MACSOCK_H */ (*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]->addrtype = hostrec->h_addrtype; + (*addr)[0]->length = hostrec->h_length; (*addr)[0]->contents = (unsigned char *)malloc((*addr)[0]->length); if (!(*addr)[0]->contents) { free((*addr)[0]); @@ -262,9 +265,10 @@ krb5_os_localaddr (krb5_address ***addr) { return ENOMEM; } else { memcpy ((char *)(*addr)[0]->contents, - (char *)hostrec->h_addr, + (char *)&hostrec->h_addr, (*addr)[0]->length); } + /* FIXME, deal with the case where gethostent returns multiple addrs */ return(0); } diff --git a/src/lib/krb5/os/lock_file.c b/src/lib/krb5/os/lock_file.c index 95b086ce6..a449da250 100644 --- a/src/lib/krb5/os/lock_file.c +++ b/src/lib/krb5/os/lock_file.c @@ -24,12 +24,16 @@ * libos: krb5_lock_file routine */ -#ifndef _MSDOS +#include "k5-int.h" +#include + +#if !defined(_MSDOS) && !defined(HAVE_MACSOCK_H) + +/* Unix version... */ + #if HAVE_UNISTD_H #include #endif -#include "k5-int.h" -#include #ifdef POSIX_FILE_LOCKS #include @@ -44,8 +48,6 @@ #define UNLOCK_LOCK LOCK_UN #endif -#include - extern int errno; /*ARGSUSED*/ @@ -104,9 +106,7 @@ krb5_lock_file(context, filep, pathname, mode) #endif return 0; } -#else /* MSDOS */ - -#include "k5-int.h" +#else /* MSDOS or Macintosh */ krb5_error_code INTERFACE krb5_lock_file(context, filep, pathname, mode) diff --git a/src/lib/krb5/os/read_pwd.c b/src/lib/krb5/os/read_pwd.c index 1c07c9c40..0c05359d3 100644 --- a/src/lib/krb5/os/read_pwd.c +++ b/src/lib/krb5/os/read_pwd.c @@ -35,6 +35,12 @@ #include #endif +extern int errno; + +#ifdef ECHO_PASSWORD +#define cleanup(errcode) (void) signal(SIGINT, ointrfunc); return errcode; +#else + /* POSIX_* are auto-magically defined in at source configuration time. */ @@ -44,8 +50,6 @@ #include #endif /* POSIX_TERMIOS */ -extern int errno; - #ifdef POSIX_TERMIOS #define cleanup(errcode) (void) signal(SIGINT, ointrfunc); tcsetattr(fd, TCSANOW, &save_control); return errcode; #else @@ -56,6 +60,8 @@ extern int errno; #endif /* sun */ #endif /* POSIX_TERMIOS */ +#endif /* ECHO_PASSWORD */ + static jmp_buf pwd_jump; @@ -83,6 +89,7 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) register char *ptr; int scratchchar; krb5_sigtype (*ointrfunc)(); +#ifndef ECHO_PASSWORD #ifdef POSIX_TERMIOS struct termios echo_control, save_control; int fd; @@ -97,7 +104,7 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) errno=ENOTTY; /* say innapropriate ioctl for device */ return errno; } -#endif /* sun */ +#endif /* notdef */ if (tcgetattr(fd, &echo_control) == -1) return errno; @@ -122,7 +129,7 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) errno=ENOTTY; /* say innapropriate ioctl for device */ return errno; } -#endif /* sun */ +#endif /* notdef */ /* save terminal state */ if ( @@ -147,6 +154,8 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) return errno; #endif +#endif /* ECHO_PASSWORD */ + if (setjmp(pwd_jump)) { /* interrupted */ if (readin_string) { @@ -222,6 +231,7 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) /* reset intrfunc */ (void) signal(SIGINT, ointrfunc); +#ifndef ECHO_PASSWORD #ifdef POSIX_TERMIOS if (tcsetattr(fd, TCSANOW, &save_control) == -1) return errno; @@ -235,6 +245,7 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) == -1) return errno; #endif +#endif /* ECHO_PASSWORD */ *size_return = strlen(return_pwd); return 0; diff --git a/src/lib/krb5/os/sendto_kdc.c b/src/lib/krb5/os/sendto_kdc.c index 86a093dcf..0a534b356 100644 --- a/src/lib/krb5/os/sendto_kdc.c +++ b/src/lib/krb5/os/sendto_kdc.c @@ -29,7 +29,6 @@ #define NEED_LOWLEVEL_IO #include "k5-int.h" -#include #ifdef HAVE_SYS_TIME_H #include #else @@ -69,7 +68,7 @@ krb5_sendto_kdc (context, message, realm, reply) int naddr; int sent, nready; krb5_error_code retval; - int *socklist; + SOCKET *socklist; fd_set readable; struct timeval waitlen; int cc; @@ -83,14 +82,14 @@ krb5_sendto_kdc (context, message, realm, reply) if (naddr == 0) return KRB5_REALM_UNKNOWN; - socklist = (int *)malloc(naddr * sizeof(int)); + socklist = (SOCKET *)malloc(naddr * sizeof(SOCKET)); if (socklist == NULL) { krb5_xfree(addr); krb5_xfree(socklist); return ENOMEM; } for (i = 0; i < naddr; i++) - socklist[i] = -1; + socklist[i] = INVALID_SOCKET; if (!(reply->data = malloc(krb5_max_dgram_size))) { krb5_xfree(addr); @@ -110,7 +109,7 @@ krb5_sendto_kdc (context, message, realm, reply) /* send to the host, wait timeout seconds for a response, then move on. */ /* cache some sockets for each host */ - if (socklist[host] == -1) { + if (socklist[host] == INVALID_SOCKET) { /* XXX 4.2/4.3BSD has PF_xxx = AF_xxx, so the socket creation here will work properly... */ /* @@ -122,7 +121,7 @@ krb5_sendto_kdc (context, message, realm, reply) * within a given protocol family. */ socklist[host] = socket(addr[host].sa_family, SOCK_DGRAM, 0); - if (socklist[host] == -1) + if (socklist[host] == INVALID_SOCKET) continue; /* try other hosts */ /* have a socket to send/recv from */ /* On BSD systems, a connected UDP socket will get connection @@ -131,7 +130,7 @@ krb5_sendto_kdc (context, message, realm, reply) sendto, recvfrom. The connect here may return an error if the destination host is known to be unreachable. */ if (connect(socklist[host], - &addr[host], sizeof(addr[host])) == -1) + &addr[host], sizeof(addr[host])) == SOCKET_ERROR) continue; } if (send(socklist[host], @@ -142,19 +141,19 @@ krb5_sendto_kdc (context, message, realm, reply) waitlen.tv_sec = timeout; FD_ZERO(&readable); FD_SET(socklist[host], &readable); - if (nready = select(1 + socklist[host], + if (nready = select(SOCKET_NFDS(socklist[host]), &readable, 0, 0, &waitlen)) { - if (nready == -1) { - if (errno == EINTR) + if (nready == SOCKET_ERROR) { + if (SOCKET_ERRNO == SOCKET_EINTR) goto retry; - retval = errno; + retval = SOCKET_ERRNO; goto out; } if ((cc = recv(socklist[host], - reply->data, reply->length, 0)) == -1) + reply->data, reply->length, 0)) == SOCKET_ERROR) { /* man page says error could be: EBADF: won't happen @@ -169,7 +168,7 @@ krb5_sendto_kdc (context, message, realm, reply) server (i.e. don't set sent = 1). */ - if (errno == EINTR) + if (SOCKET_ERRNO == SOCKET_EINTR) sent = 1; continue; } @@ -199,8 +198,8 @@ krb5_sendto_kdc (context, message, realm, reply) retval = KRB5_KDC_UNREACH; out: for (i = 0; i < naddr; i++) - if (socklist[i] != -1) - (void) close(socklist[i]); + if (socklist[i] != INVALID_SOCKET) + (void) closesocket (socklist[i]); krb5_xfree(addr); krb5_xfree(socklist); if (retval) { diff --git a/src/lib/krb5/os/ustime.c b/src/lib/krb5/os/ustime.c index f0bc9c7b3..bc04a2eff 100644 --- a/src/lib/krb5/os/ustime.c +++ b/src/lib/krb5/os/ustime.c @@ -24,9 +24,159 @@ * krb5_mstimeofday for BSD 4.3 */ +#define NEED_SOCKETS #include "k5-int.h" +#ifdef HAVE_MACSOCK_H +/* We're a Macintosh -- do Mac time things. */ + +/* + * This code is derived from kerberos/src/lib/des/mac_time.c from + * the Cygnus Support release of Kerberos V4: + * + * mac_time.c + * (Originally time_stuff.c) + * Copyright 1989 by the Massachusetts Institute of Technology. + * Macintosh ooperating system interface for Kerberos. + */ + +#include "AddressXlation.h" /* for ip_addr, for #if 0'd net-time stuff */ + +#include /* Defines MachineLocation, used by getTimeZoneOffset */ +#include /* Defines BitTst(), called by getTimeZoneOffset() */ +#include /* Defines GetDateTime */ + +/* Mac Cincludes */ +#include +#include + + /******************************* + The Unix epoch is 1/1/70, the Mac epoch is 1/1/04. + + 70 - 4 = 66 year differential + + Thus the offset is: + + (66 yrs) * (365 days/yr) * (24 hours/day) * (60 mins/hour) * (60 secs/min) + plus + (17 leap days) * (24 hours/day) * (60 mins/hour) * (60 secs/min) + + Don't forget the offset from GMT. + *******************************/ + +/* returns the offset in hours between the mac local time and the GMT */ + +static +unsigned krb5_int32 +getTimeZoneOffset() +{ + MachineLocation macLocation; + long gmtDelta; + + macLocation.gmtFlags.gmtDelta=0L; + ReadLocation(&macLocation); + gmtDelta=macLocation.gmtFlags.gmtDelta & 0x00FFFFFF; + if (BitTst((void *)&gmtDelta,23L)) gmtDelta |= 0xFF000000; + gmtDelta /= 3600L; + return(gmtDelta); +} + +static krb5_int32 last_sec = 0, last_usec = 0; + +/* Returns the GMT in seconds (and fake microseconds) using the Unix epoch */ + +krb5_error_code INTERFACE +krb5_us_timeofday(context, seconds, microseconds) + krb5_context context; + krb5_int32 *seconds, *microseconds; +{ + krb5_int32 sec, usec; + time_t the_time; + + GetDateTime (&the_time); + sec = the_time - + ((66 * 365 * 24 * 60 * 60) + + (17 * 24 * 60 * 60) + + (getTimeZoneOffset() * 60 * 60)); + usec = 0; /* Mac is too slow to count faster than once a second */ + + if ((sec == last_sec) && (usec == last_usec)) { + if (++last_usec >= 1000000) { + last_usec = 0; + last_sec++; + } + sec = last_sec; + usec = last_usec; + } else + last_sec = sec; + last_usec = usec; + + *seconds = sec; + *microseconds = usec; + return 0; +} + +#if 0 + +int +gettimeofdaynet (struct timeval *tp, struct timezone *tz) +{ + tp->tv_sec = gettimeofdaynet_no_offset(); + return 0; +} + + +#define TIME_PORT 37 +#define TM_OFFSET 2208988800 + +/* + * + * get_net_offset () -- Use UDP time protocol to figure out the + * offset between what the Mac thinks the time is an what + * the network thinks. + * + */ +int +get_net_offset() +{ + time_t tv; + char buf[512],ts[256]; + long *nettime; + int attempts, cc, time_port; + long unixtime; + char realm[REALM_SZ]; + ip_addr fromaddr; + unsigned short fromport; + int result; + + nettime = (long *)buf; + time_port = TIME_PORT; + + cc = sizeof(buf); + result = hosts_send_recv(ts, 1, buf, &cc, "", time_port); + time (&tv); + + if (result!=KSUCCESS || cc<4) { + net_offset = 0; + if (!result) result = 100; + return result; + } + + unixtime = (long) ntohl(*nettime) - TM_OFFSET; + + tv -= 66 * 365 * 24 * 60 * 60 + + 17 * 60 * 60 * 24; /* Convert to unix time w/o offset */ + net_offset = unixtime - tv; + net_got_offset = 1; + + return 0; +} + +#endif /* 0 */ + +#else /* HAVE_MACSOCK_H */ #ifndef _MSDOS +/* We're a Unix machine -- do Unix time things. */ extern int errno; @@ -172,4 +322,5 @@ win_time_get_epoch() return epoch; } -#endif +#endif /* MSDOS */ +#endif /* HAVE_MACSOCK_H */