17c478bd9Sstevel@tonic-gate /*
2159d09a2SMark Phalan  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate  * lib/krb5/os/timeofday.c
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * Copyright 1990 by the Massachusetts Institute of Technology.
107c478bd9Sstevel@tonic-gate  * All Rights Reserved.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
137c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
147c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
157c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
16*55fea89dSDan Cross  *
177c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
187c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
197c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
207c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
217c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
227c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
237c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
24159d09a2SMark Phalan  * permission.  Furthermore if you modify this software you must label
25159d09a2SMark Phalan  * your software as modified software and not distribute it in such a
26159d09a2SMark Phalan  * fashion that it might be confused with the original M.I.T. software.
27159d09a2SMark Phalan  * M.I.T. makes no representations about the suitability of
287c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
297c478bd9Sstevel@tonic-gate  * or implied warranty.
307c478bd9Sstevel@tonic-gate  *
31*55fea89dSDan Cross  *
32*55fea89dSDan Cross  * libos: krb5_timeofday function for BSD 4.3
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
36159d09a2SMark Phalan #include "k5-int.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
397c478bd9Sstevel@tonic-gate #include <sys/time.h>
407c478bd9Sstevel@tonic-gate #else
417c478bd9Sstevel@tonic-gate #include <time.h>
427c478bd9Sstevel@tonic-gate #include <errno.h>
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
45159d09a2SMark Phalan krb5_error_code KRB5_CALLCONV
krb5_timeofday(krb5_context context,register krb5_timestamp * timeret)46159d09a2SMark Phalan krb5_timeofday(krb5_context context, register krb5_timestamp *timeret)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate     krb5_os_context os_ctx = context->os_context;
49159d09a2SMark Phalan     /* Solaris Kerberos */
507c478bd9Sstevel@tonic-gate     krb5_int32 tval;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) {
537c478bd9Sstevel@tonic-gate 	    *timeret = os_ctx->time_offset;
547c478bd9Sstevel@tonic-gate 	    return 0;
557c478bd9Sstevel@tonic-gate     }
567c478bd9Sstevel@tonic-gate     {
577c478bd9Sstevel@tonic-gate 	krb5_int32 usecs;
587c478bd9Sstevel@tonic-gate 	krb5_error_code	kret;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	if (kret = krb5_crypto_us_timeofday(&tval,
617c478bd9Sstevel@tonic-gate 			 &usecs))
627c478bd9Sstevel@tonic-gate 		return kret;
637c478bd9Sstevel@tonic-gate     }
64159d09a2SMark Phalan     /* Solaris Kerberos */
65159d09a2SMark Phalan     if (tval == (krb5_int32) -1)
667c478bd9Sstevel@tonic-gate #ifdef _KERNEL
677c478bd9Sstevel@tonic-gate 	return 1;
687c478bd9Sstevel@tonic-gate #else
697c478bd9Sstevel@tonic-gate 	return (krb5_error_code) errno;
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate     if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID)
727c478bd9Sstevel@tonic-gate 	    tval += os_ctx->time_offset;
737c478bd9Sstevel@tonic-gate     *timeret = tval;
747c478bd9Sstevel@tonic-gate     return 0;
757c478bd9Sstevel@tonic-gate }
76