1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/os/toffset.c - Manipulate time offset fields in os context */
4 * Copyright 1995, 2007 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
30 * This routine takes the "real time" as input, and sets the time
31 * offset field in the context structure so that the krb5 time
32 * routines will return the correct time as corrected by difference
33 * between the system time and the "real time" as passed to this
36 * If the real time microseconds are given as -1 the caller doesn't
37 * know the microseconds value so the usec offset is always zero.
39 krb5_error_code KRB5_CALLCONV
40 krb5_set_real_time(krb5_context context, krb5_timestamp seconds, krb5_int32 microseconds)
42 krb5_os_context os_ctx = &context->os_context;
45 krb5_error_code retval;
47 retval = krb5_crypto_us_timeofday(&sec, &usec);
51 os_ctx->time_offset = ts_delta(seconds, sec);
52 os_ctx->usec_offset = (microseconds > -1) ? microseconds - usec : 0;
54 os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_TIME) |
55 KRB5_OS_TOFFSET_VALID);
60 * This routine sets the krb5 time routines so that they will return
61 * the seconds and microseconds value as input to this function. This
62 * is useful for running the krb5 routines through test suites
65 krb5_set_debugging_time(krb5_context context, krb5_timestamp seconds, krb5_int32 microseconds)
67 krb5_os_context os_ctx = &context->os_context;
69 os_ctx->time_offset = seconds;
70 os_ctx->usec_offset = microseconds;
71 os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_VALID) |
72 KRB5_OS_TOFFSET_TIME);
77 * This routine turns off the time correction fields, so that the krb5
78 * routines return the "natural" time.
81 krb5_use_natural_time(krb5_context context)
83 krb5_os_context os_ctx = &context->os_context;
85 os_ctx->os_flags &= ~(KRB5_OS_TOFFSET_VALID|KRB5_OS_TOFFSET_TIME);
91 * This routine returns the current time offsets in use.
93 krb5_error_code KRB5_CALLCONV
94 krb5_get_time_offsets(krb5_context context, krb5_timestamp *seconds, krb5_int32 *microseconds)
96 krb5_os_context os_ctx = &context->os_context;
99 *seconds = os_ctx->time_offset;
101 *microseconds = os_ctx->usec_offset;
107 * This routine sets the time offsets directly.
110 krb5_set_time_offsets(krb5_context context, krb5_timestamp seconds, krb5_int32 microseconds)
112 krb5_os_context os_ctx = &context->os_context;
114 os_ctx->time_offset = seconds;
115 os_ctx->usec_offset = microseconds;
116 os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_TIME) |
117 KRB5_OS_TOFFSET_VALID);