From 98582314d1f9e044d44b7b01f8fdd220a5e72e65 Mon Sep 17 00:00:00 2001 From: Miro Jurisic Date: Wed, 9 Jun 1999 14:52:29 +0000 Subject: [PATCH] Merged changed from Mac_V2_0_derivatives branch git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11499 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 28 +++++++ src/lib/krb5/os/c_ustime.c | 133 ++++++++++++++++++++++++++++++---- src/lib/krb5/os/init_os_ctx.c | 11 ++- src/lib/krb5/os/net_write.c | 2 + src/util/profile/ChangeLog | 6 ++ src/util/profile/prof_file.c | 2 +- 6 files changed, 161 insertions(+), 21 deletions(-) diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index d230bc635..1771da98f 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,31 @@ +1999-06-09 Miro Jurisic + + * c_ustime.c (AbsoluteToSecsNanosecs): Fixed the UInt64 division + * c_ustime.c (krb5_crypto_us_timeofday): now returning the correct value + +1999-06-09 Miro Jurisic + + * c_ustime.c (AbsoluteToSecsNanosecs): Fixed the UInt64 comparison + +1999-06-09 Miro Jurisic + + * net_read.c, net_write.c: now setting errno on Mac too + +1999-06-09 Miro Jurisic + + * c_ustime.c (krb5_crypto_us_timeofday, HaveAccurateTime, + AbsoluteToSecsNanosecs): Added support for microseconds or + better timers on the Mac when available + + * c_ustime.c (krb5_crypto_us_timeofday): fixed usecs counting bug + (From Chas Williams) + + * init_os_ctx.c (GetMacProfilePathname): removed hardcoded config file name + (From Chas Williams) + + * init_os_ctx.c (os_init_paths): added NRL config file name + (From Chas Williams) + Tue Jun 8 15:26:21 1999 Alexandra Ellwood * changepw.c: Changed errno to SOCKET_ERRNO/SOCKET_SET_ERRNO diff --git a/src/lib/krb5/os/c_ustime.c b/src/lib/krb5/os/c_ustime.c index e790acc95..85197f1d2 100644 --- a/src/lib/krb5/os/c_ustime.c +++ b/src/lib/krb5/os/c_ustime.c @@ -23,7 +23,7 @@ * * krb5_mstimeofday for BSD 4.3 */ - + #define NEED_SOCKETS #include "k5-int.h" @@ -41,11 +41,12 @@ * 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 */ +#include /* Nanosecond timing */ +#include /* Check for presence of UpTime */ +#include /* 64-bit integer math */ /* Mac Cincludes */ #include @@ -53,6 +54,16 @@ static krb5_int32 last_sec = 0, last_usec = 0; +/* Check for availability of microseconds or better timer */ +Boolean HaveAccurateTime (); + +/* Convert nanoseconds to date and time */ +void AbsoluteToSecsNanosecs ( + AbsoluteTime eventTime, /* Value to convert */ + UInt32 *eventSeconds, /* Result goes here */ + UInt32 *residualNanoseconds /* Fractional second */ + ); + /* * The Unix epoch is 1/1/70, the Mac epoch is 1/1/04. * @@ -98,29 +109,119 @@ krb5_crypto_us_timeofday(seconds, microseconds) 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++; + + if (HaveAccurateTime ()) { /* Does hardware support accurate time? */ + + AbsoluteTime absoluteTime; + UInt32 nanoseconds; + + absoluteTime = UpTime (); + AbsoluteToSecsNanosecs (absoluteTime, seconds, &nanoseconds); + + usec = nanoseconds / 1000; + + } else { + usec = 0; + + if (sec == last_sec) { /* Same as last time? */ + usec = ++last_usec; /* Yep, so do microseconds */ + if (++last_usec >= 1000000) { + ++sec; + usec = 0; + } } - sec = last_sec; - usec = last_usec; - } - else { - last_sec = sec; + last_sec = sec; /* Remember for next time */ last_usec = usec; } *seconds = sec; - *microseconds = usec; + *microseconds = usec; /* Return the values */ return 0; } +/* Check if we have microsecond or better timer */ +Boolean HaveAccurateTime () +{ + static Boolean alreadyChecked = false; + static haveAccurateTime = false; + + if (!alreadyChecked) { + alreadyChecked = true; + haveAccurateTime = false; + if ((Ptr) UpTime != (Ptr) kUnresolvedCFragSymbolAddress) { + UInt32 minAbsoluteTimeDelta; + UInt32 theAbsoluteTimeToNanosecondNumerator; + UInt32 theAbsoluteTimeToNanosecondDenominator; + UInt32 theProcessorToAbsoluteTimeNumerator; + UInt32 theProcessorToAbsoluteTimeDenominator; + + GetTimeBaseInfo ( + &minAbsoluteTimeDelta, + &theAbsoluteTimeToNanosecondNumerator, + &theAbsoluteTimeToNanosecondDenominator, + &theProcessorToAbsoluteTimeNumerator, + &theProcessorToAbsoluteTimeDenominator); + + /* minAbsoluteTimeDelta is the period in which Uptime is updated, in absolute time */ + /* We convert it to nanoseconds and compare it with .5 microsecond */ + + if (minAbsoluteTimeDelta * theAbsoluteTimeToNanosecondNumerator < + 500 * theAbsoluteTimeToNanosecondDenominator) { + haveAccurateTime = true; + } + } + } + + return haveAccurateTime; +} + +/* Convert nanoseconds to date and time */ + +void AbsoluteToSecsNanosecs ( + AbsoluteTime eventTime, /* Value to convert */ + UInt32 *eventSeconds, /* Result goes here */ + UInt32 *residualNanoseconds /* Fractional second */ + ) +{ + UInt64 eventNanoseconds; + UInt64 eventSeconds64; + static const UInt64 kTenE9 = U64SetU (1000000000); + static UInt64 gNanosecondsAtStart = U64SetU (0); + + /* + * If this is the first call, compute the offset between + * GetDateTime and UpTime. + */ + if (U64Compare (gNanosecondsAtStart, U64SetU (0)) == 0) { + UInt32 secondsAtStart; + AbsoluteTime absoluteTimeAtStart; + UInt64 upTimeAtStart; + UInt64 nanosecondsAtStart; + + GetDateTime (&secondsAtStart); + upTimeAtStart = UnsignedWideToUInt64 (AbsoluteToNanoseconds (UpTime())); + nanosecondsAtStart = U64SetU (secondsAtStart); + nanosecondsAtStart = U64Multiply (nanosecondsAtStart, kTenE9); + gNanosecondsAtStart = U64Subtract (nanosecondsAtStart, upTimeAtStart); + } + /* + * Convert the event time (UpTime value) to nanoseconds and add + * the local time epoch. + */ + eventNanoseconds = UnsignedWideToUInt64 (AbsoluteToNanoseconds (eventTime)); + eventNanoseconds = U64Add (gNanosecondsAtStart, eventNanoseconds); + /* + * eventSeconds = eventNanoseconds /= 10e9; + * residualNanoseconds = eventNanoseconds % 10e9; + * Finally, compute the local time (seconds) and fraction. + */ + eventSeconds64 = U64Div (eventNanoseconds, kTenE9); + eventNanoseconds = U64Subtract (eventNanoseconds, U64Multiply (eventSeconds64, kTenE9)); + *eventSeconds = (UInt64ToUnsignedWide (eventSeconds64)).lo; + *residualNanoseconds = (UInt64ToUnsignedWide (eventNanoseconds)).lo; +} #elif defined(_WIN32) /* Microsoft Windows NT and 95 (32bit) */ diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index ab325cb26..7c031543e 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -80,7 +80,7 @@ OSErr err; } char* -GetMacProfilePathName(void) +GetMacProfilePathName(Str255 filename) { short vRefnum; long parID; @@ -89,7 +89,7 @@ FSSpec krbSpec; char pathbuf[255]; theErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRefnum, &parID); - FSMakeFSSpec(vRefnum, parID, "\pkrb5.ini", &krbSpec); + FSMakeFSSpec(vRefnum, parID, filename, &krbSpec); GetPathname(&krbSpec, &pathbuf); return strdup(pathbuf); } @@ -106,7 +106,9 @@ os_init_paths(ctx, secure) krb5_error_code retval = 0; char *name = 0; -#if defined(macintosh) || defined(_MSDOS) || defined(_WIN32) +#if defined(macintosh) + const char *filenames[3]; +#elif defined(_MSDOS) || defined(_WIN32) const char *filenames[2]; #endif @@ -132,7 +134,8 @@ os_init_paths(ctx, secure) #else /* _MSDOS || _WIN32 */ #ifdef macintosh - filenames[0] = GetMacProfilePathName(); + filenames[0] = GetMacProfilePathName("\pkrb Configuration"); + filenames[0] = GetMacProfilePathName("\pkrb5.ini"); filenames[1] = 0; retval = profile_init(filenames, &ctx->profile); #else diff --git a/src/lib/krb5/os/net_write.c b/src/lib/krb5/os/net_write.c index e959d68c9..1da730e1e 100644 --- a/src/lib/krb5/os/net_write.c +++ b/src/lib/krb5/os/net_write.c @@ -49,8 +49,10 @@ krb5_net_write(context, fd, buf, len) if (cc < 0) { if (SOCKET_ERRNO == SOCKET_EINTR) continue; + /* XXX this interface sucks! */ errno = SOCKET_ERRNO; + return(cc); } else { diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index e9917c633..02dd1c8ce 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,9 @@ +1999-06-09 Miro Jurisic + + * prof_file.c (profile_update_file): if fopen fails and errno is 0, set + errno to ENOENT so that we can try multiple names for settings file + (From Chas Williams) + Wed May 19 11:46:02 1999 Danilo Almeida * Makefile.in: Add windows build rules for putting header files in diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index 0f1ac658f..8606bf79e 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -130,7 +130,7 @@ errcode_t profile_update_file(prf) if (f == NULL) { retval = errno; if (retval == 0) - retval = PROF_FAIL_OPEN; + retval = ENOENT; return retval; } prf->upd_serial++; -- 2.26.2