xref: /titanic_50/usr/src/lib/gss_mechs/mech_krb5/mech/context_time.c (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
1 /*
2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 /* Copyright 1993 by OpenVision Technologies, Inc.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appears in all copies and
9  * that both that copyright notice and this permission notice appear in
10  * supporting documentation, and that the name of OpenVision not be used
11  * in advertising or publicity pertaining to distribution of the software
12  * without specific, written prior permission. OpenVision makes no
13  * representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22  * PERFORMANCE OF THIS SOFTWARE.
23  */
24 
25 #include "gssapiP_krb5.h"
26 
27 /*
28  * $Id: context_time.c 16187 2004-03-19 09:33:57Z raeburn $
29  */
30 
31 OM_uint32
krb5_gss_context_time(minor_status,context_handle,time_rec)32 krb5_gss_context_time(minor_status, context_handle, time_rec)
33      OM_uint32 *minor_status;
34      gss_ctx_id_t context_handle;
35      OM_uint32 *time_rec;
36 {
37    krb5_error_code code;
38    krb5_gss_ctx_id_rec *ctx;
39    krb5_timestamp now;
40    krb5_deltat lifetime;
41 
42    /* validate the context handle */
43    if (! kg_validate_ctx_id(context_handle)) {
44       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
45       return(GSS_S_NO_CONTEXT);
46    }
47 
48    ctx = (krb5_gss_ctx_id_rec *) context_handle;
49 
50    if (! ctx->established) {
51       *minor_status = KG_CTX_INCOMPLETE;
52       return(GSS_S_NO_CONTEXT);
53    }
54 
55    if ((code = krb5_timeofday(ctx->k5_context, &now))) {
56       *minor_status = code;
57       save_error_info(*minor_status, ctx->k5_context);
58       return(GSS_S_FAILURE);
59    }
60 
61    if ((lifetime = ctx->endtime - now) <= 0) {
62       *time_rec = 0;
63       *minor_status = 0;
64       return(GSS_S_CONTEXT_EXPIRED);
65    } else {
66       *time_rec = lifetime;
67       *minor_status = 0;
68       return(GSS_S_COMPLETE);
69    }
70 }
71