xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/os/ustime.c (revision 7934:6aeeafc994de)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * lib/krb5/os/ustime.c
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
50Sstevel@tonic-gate  * All Rights Reserved.
60Sstevel@tonic-gate  *
70Sstevel@tonic-gate  * Export of this software from the United States of America may
80Sstevel@tonic-gate  *   require a specific license from the United States Government.
90Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
100Sstevel@tonic-gate  *   export to obtain such a license before exporting.
110Sstevel@tonic-gate  *
120Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
130Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
140Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
150Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
160Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
170Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
180Sstevel@tonic-gate  * to distribution of the software without specific, written prior
190Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
200Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
210Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
220Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
230Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
240Sstevel@tonic-gate  * or implied warranty.
250Sstevel@tonic-gate  *
260Sstevel@tonic-gate  * krb5_crypto_us_timeofday() does all of the real work; however, we
270Sstevel@tonic-gate  * handle the time offset adjustment here, since this is context
280Sstevel@tonic-gate  * specific, and the crypto version of this call doesn't have access
290Sstevel@tonic-gate  * to the context variable.  Fortunately the only user of
300Sstevel@tonic-gate  * krb5_crypto_us_timeofday in the crypto library doesn't require that
310Sstevel@tonic-gate  * this time adjustment be done.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
34*7934SMark.Phalan@Sun.COM #include "k5-int.h"
350Sstevel@tonic-gate 
36781Sgtb krb5_error_code KRB5_CALLCONV
krb5_us_timeofday(krb5_context context,krb5_timestamp * seconds,krb5_int32 * microseconds)37*7934SMark.Phalan@Sun.COM krb5_us_timeofday(krb5_context context, krb5_timestamp *seconds, krb5_int32 *microseconds)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate     krb5_os_context os_ctx = context->os_context;
400Sstevel@tonic-gate     krb5_int32 sec, usec;
410Sstevel@tonic-gate     krb5_error_code retval;
420Sstevel@tonic-gate 
430Sstevel@tonic-gate     if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) {
440Sstevel@tonic-gate 	    *seconds = os_ctx->time_offset;
450Sstevel@tonic-gate 	    *microseconds = os_ctx->usec_offset;
460Sstevel@tonic-gate 	    return 0;
470Sstevel@tonic-gate     }
480Sstevel@tonic-gate     retval = krb5_crypto_us_timeofday(&sec, &usec);
490Sstevel@tonic-gate     if (retval)
500Sstevel@tonic-gate 	    return retval;
510Sstevel@tonic-gate     if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) {
520Sstevel@tonic-gate 	    usec += os_ctx->usec_offset;
530Sstevel@tonic-gate 	    if (usec > 1000000) {
540Sstevel@tonic-gate 		    usec -= 1000000;
550Sstevel@tonic-gate 		    sec++;
560Sstevel@tonic-gate 	    }
570Sstevel@tonic-gate 	    if (usec < 0) {
580Sstevel@tonic-gate 		usec += 1000000;
590Sstevel@tonic-gate 		sec--;
600Sstevel@tonic-gate 	    }
610Sstevel@tonic-gate 	    sec += os_ctx->time_offset;
620Sstevel@tonic-gate     }
630Sstevel@tonic-gate     *seconds = sec;
640Sstevel@tonic-gate     *microseconds = usec;
650Sstevel@tonic-gate     return 0;
660Sstevel@tonic-gate }
67