implement krb5_set_real_time, used by SAMBA, requested by Luke Howard <lukeh@PADL.COM>
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12389 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -16,6 +16,7 @@ TESTS = \
|
|||||||
store-test \
|
store-test \
|
||||||
parse-name-test \
|
parse-name-test \
|
||||||
test_cc \
|
test_cc \
|
||||||
|
test_time \
|
||||||
name-45-test
|
name-45-test
|
||||||
|
|
||||||
check_PROGRAMS = $(TESTS)
|
check_PROGRAMS = $(TESTS)
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
.\" Copyright (c) 2001 Kungliga Tekniska H<>gskolan
|
.\" $Id$
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 2001, 2003 Kungliga Tekniska H<>gskolan
|
||||||
.\" (Royal Institute of Technology, Stockholm, Sweden).
|
.\" (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
@@ -31,27 +33,87 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $Id$
|
.\" $Id$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 1, 2001
|
.Dd June 17, 2003
|
||||||
.Dt KRB5_TIMEOFDAY 3
|
.Dt KRB5_TIMEOFDAY 3
|
||||||
|
.Os HEIMDAL
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm krb5_timeofday ,
|
.Nm krb5_timeofday
|
||||||
|
.Nm krb5_set_real_time
|
||||||
.Nm krb5_us_timeofday
|
.Nm krb5_us_timeofday
|
||||||
.Nd whatever these functions do
|
.Nm krb5_format_time
|
||||||
|
.Nm krb5_string_to_deltat
|
||||||
|
.Nd Kerberos 5 time handling functions
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
Kerberos 5 Library (libkrb5, -lkrb5)
|
Kerberos 5 Library (libkrb5, -lkrb5)
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In krb5.h
|
.In krb5.h
|
||||||
.Ft "krb5_error_code"
|
.Pp
|
||||||
.Fn krb5_timeofday "krb5_context context" "krb5_timestamp *timeret"
|
.Li krb5_timestamp ;
|
||||||
.Ft "krb5_error_code"
|
.Pp
|
||||||
.Fn krb5_us_timeofday "krb5_context context" "int32_t *sec" "int32_t *usec"
|
.Li krb5_deltat ;
|
||||||
|
.Ft krb5_error_code
|
||||||
|
.Fo krb5_set_real_time
|
||||||
|
.Fa "krb5_context context"
|
||||||
|
.Fa "krb5_timestamp sec"
|
||||||
|
.Fa "int32_t usec"
|
||||||
|
.Fc
|
||||||
|
.Ft krb5_error_code
|
||||||
|
.Fo krb5_timeofday
|
||||||
|
.Fa "krb5_context context"
|
||||||
|
.Fa "krb5_timestamp *timeret"
|
||||||
|
.Fc
|
||||||
|
.Ft krb5_error_code
|
||||||
|
.Fo krb5_us_timeofday
|
||||||
|
.Fa "krb5_context context"
|
||||||
|
.Fa "krb5_timestamp *sec"
|
||||||
|
.Fa "int32_t *usec"
|
||||||
|
.Fc
|
||||||
|
.Ft krb5_error_code
|
||||||
|
.Fo krb5_format_time
|
||||||
|
.Fa "krb5_context context"
|
||||||
|
.Fa "time_t t"
|
||||||
|
.Fa "char *s"
|
||||||
|
.Fa "size_t len"
|
||||||
|
.Fa "krb5_boolean include_time"
|
||||||
|
.Fc
|
||||||
|
.Ft krb5_error_code
|
||||||
|
.Fo krb5_string_to_deltat
|
||||||
|
.Fa "const char *string"
|
||||||
|
.Fa "krb5_deltat *deltat"
|
||||||
|
.Fc
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
|
.Nm krb5_set_real_time
|
||||||
|
set the
|
||||||
|
.Fa sec
|
||||||
|
and
|
||||||
|
.Fa usec
|
||||||
|
to the match the time as the KDC time.
|
||||||
|
This update the time screw parameter
|
||||||
|
in
|
||||||
|
.Fa context .
|
||||||
|
.Pp
|
||||||
.Fn krb5_timeofday
|
.Fn krb5_timeofday
|
||||||
returns the current time, but adjusted with the time difference
|
returns the current time, but adjusted with the time difference
|
||||||
between the local host and the KDC.
|
between the local host and the KDC.
|
||||||
.Fn krb5_us_timeofday
|
.Fn krb5_us_timeofday
|
||||||
also returns microseconds.
|
also returns microseconds.
|
||||||
.Pp
|
.Pp
|
||||||
.\".Sh EXAMPLE
|
.Nm krb5_format_time
|
||||||
|
formats the time
|
||||||
|
.Fa t
|
||||||
|
into the string
|
||||||
|
.Fa s
|
||||||
|
of length
|
||||||
|
.Fa len .
|
||||||
|
If
|
||||||
|
.Fa include_time
|
||||||
|
is set, the time is set include_time.
|
||||||
|
.Pp
|
||||||
|
.Nm krb5_string_to_deltat
|
||||||
|
Parses delta time
|
||||||
|
.Fa string
|
||||||
|
into
|
||||||
|
.Fa deltat .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr gettimeofday 2
|
.Xr gettimeofday 2 ,
|
||||||
|
.Xr krb5 3
|
||||||
|
84
lib/krb5/test_time.c
Normal file
84
lib/krb5/test_time.c
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2003 Kungliga Tekniska H<>gskolan
|
||||||
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. Neither the name of KTH nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||||
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "krb5_locl.h"
|
||||||
|
|
||||||
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_set_time(krb5_context context)
|
||||||
|
{
|
||||||
|
krb5_error_code ret;
|
||||||
|
krb5_timestamp sec;
|
||||||
|
int32_t usec;
|
||||||
|
struct timeval tv;
|
||||||
|
int diff = 10;
|
||||||
|
int diff2;
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
|
ret = krb5_set_real_time(context, tv.tv_sec + diff, tv.tv_usec);
|
||||||
|
if (ret)
|
||||||
|
krb5_err(context, 1, ret, "krb5_us_timeofday");
|
||||||
|
|
||||||
|
ret = krb5_us_timeofday(context, &sec, &usec);
|
||||||
|
if (ret)
|
||||||
|
krb5_err(context, 1, ret, "krb5_us_timeofday");
|
||||||
|
|
||||||
|
diff2 = abs(sec - tv.tv_sec);
|
||||||
|
|
||||||
|
if (diff2 < 9 || diff > 11)
|
||||||
|
krb5_errx(context, 1, "set time error: diff: %d",
|
||||||
|
abs(sec - tv.tv_sec));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
krb5_context context;
|
||||||
|
krb5_error_code ret;
|
||||||
|
|
||||||
|
ret = krb5_init_context(&context);
|
||||||
|
if (ret)
|
||||||
|
errx(1, "krb5_init_context %d", ret);
|
||||||
|
|
||||||
|
check_set_time(context);
|
||||||
|
check_set_time(context);
|
||||||
|
check_set_time(context);
|
||||||
|
check_set_time(context);
|
||||||
|
check_set_time(context);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -35,6 +35,24 @@
|
|||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the time the kerberos library will use to `sec',`usec' to
|
||||||
|
*/
|
||||||
|
|
||||||
|
krb5_error_code
|
||||||
|
krb5_set_real_time (krb5_context context,
|
||||||
|
krb5_timestamp sec,
|
||||||
|
int32_t usec)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
|
context->kdc_sec_offset = sec - tv.tv_sec;
|
||||||
|
context->kdc_usec_offset = usec - tv.tv_sec;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return ``corrected'' time in `timeret'.
|
* return ``corrected'' time in `timeret'.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user