1 /*
2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * lib/krb5/os/timeofday.c
8  *
9  * Copyright 1990 by the Massachusetts Institute of Technology.
10  * All Rights Reserved.
11  *
12  * Export of this software from the United States of America may
13  *   require a specific license from the United States Government.
14  *   It is the responsibility of any person or organization contemplating
15  *   export to obtain such a license before exporting.
16  *
17  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
18  * distribute this software and its documentation for any purpose and
19  * without fee is hereby granted, provided that the above copyright
20  * notice appear in all copies and that both that copyright notice and
21  * this permission notice appear in supporting documentation, and that
22  * the name of M.I.T. not be used in advertising or publicity pertaining
23  * to distribution of the software without specific, written prior
24  * permission.  Furthermore if you modify this software you must label
25  * your software as modified software and not distribute it in such a
26  * fashion that it might be confused with the original M.I.T. software.
27  * M.I.T. makes no representations about the suitability of
28  * this software for any purpose.  It is provided "as is" without express
29  * or implied warranty.
30  *
31  *
32  * libos: krb5_timeofday function for BSD 4.3
33  */
34 
35 
36 #include "k5-int.h"
37 
38 #ifdef	_KERNEL
39 #include <sys/time.h>
40 #else
41 #include <time.h>
42 #include <errno.h>
43 #endif
44 
45 krb5_error_code KRB5_CALLCONV
krb5_timeofday(krb5_context context,register krb5_timestamp * timeret)46 krb5_timeofday(krb5_context context, register krb5_timestamp *timeret)
47 {
48     krb5_os_context os_ctx = context->os_context;
49     /* Solaris Kerberos */
50     krb5_int32 tval;
51 
52     if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) {
53 	    *timeret = os_ctx->time_offset;
54 	    return 0;
55     }
56     {
57 	krb5_int32 usecs;
58 	krb5_error_code	kret;
59 
60 	if (kret = krb5_crypto_us_timeofday(&tval,
61 			 &usecs))
62 		return kret;
63     }
64     /* Solaris Kerberos */
65     if (tval == (krb5_int32) -1)
66 #ifdef _KERNEL
67 	return 1;
68 #else
69 	return (krb5_error_code) errno;
70 #endif
71     if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID)
72 	    tval += os_ctx->time_offset;
73     *timeret = tval;
74     return 0;
75 }
76