xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/mech/context_time.c (revision 13132:9615cdbf7b70)
1*13132SGlenn.Barry@oracle.com /*
2*13132SGlenn.Barry@oracle.com  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3*13132SGlenn.Barry@oracle.com  */
45053Sgtb /* Copyright 1993 by OpenVision Technologies, Inc.
55053Sgtb  *
60Sstevel@tonic-gate  * Permission to use, copy, modify, distribute, and sell this software
70Sstevel@tonic-gate  * and its documentation for any purpose is hereby granted without fee,
80Sstevel@tonic-gate  * provided that the above copyright notice appears in all copies and
90Sstevel@tonic-gate  * that both that copyright notice and this permission notice appear in
100Sstevel@tonic-gate  * supporting documentation, and that the name of OpenVision not be used
110Sstevel@tonic-gate  * in advertising or publicity pertaining to distribution of the software
120Sstevel@tonic-gate  * without specific, written prior permission. OpenVision makes no
130Sstevel@tonic-gate  * representations about the suitability of this software for any
140Sstevel@tonic-gate  * purpose.  It is provided "as is" without express or implied warranty.
155053Sgtb  *
160Sstevel@tonic-gate  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
170Sstevel@tonic-gate  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
180Sstevel@tonic-gate  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
190Sstevel@tonic-gate  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
200Sstevel@tonic-gate  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
210Sstevel@tonic-gate  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
220Sstevel@tonic-gate  * PERFORMANCE OF THIS SOFTWARE.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
255053Sgtb #include "gssapiP_krb5.h"
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*
285053Sgtb  * $Id: context_time.c 16187 2004-03-19 09:33:57Z raeburn $
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate OM_uint32
krb5_gss_context_time(minor_status,context_handle,time_rec)325053Sgtb krb5_gss_context_time(minor_status, context_handle, time_rec)
330Sstevel@tonic-gate      OM_uint32 *minor_status;
340Sstevel@tonic-gate      gss_ctx_id_t context_handle;
350Sstevel@tonic-gate      OM_uint32 *time_rec;
360Sstevel@tonic-gate {
370Sstevel@tonic-gate    krb5_error_code code;
380Sstevel@tonic-gate    krb5_gss_ctx_id_rec *ctx;
390Sstevel@tonic-gate    krb5_timestamp now;
400Sstevel@tonic-gate    krb5_deltat lifetime;
410Sstevel@tonic-gate 
420Sstevel@tonic-gate    /* validate the context handle */
430Sstevel@tonic-gate    if (! kg_validate_ctx_id(context_handle)) {
440Sstevel@tonic-gate       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
450Sstevel@tonic-gate       return(GSS_S_NO_CONTEXT);
460Sstevel@tonic-gate    }
470Sstevel@tonic-gate 
480Sstevel@tonic-gate    ctx = (krb5_gss_ctx_id_rec *) context_handle;
490Sstevel@tonic-gate 
500Sstevel@tonic-gate    if (! ctx->established) {
510Sstevel@tonic-gate       *minor_status = KG_CTX_INCOMPLETE;
520Sstevel@tonic-gate       return(GSS_S_NO_CONTEXT);
530Sstevel@tonic-gate    }
540Sstevel@tonic-gate 
555053Sgtb    if ((code = krb5_timeofday(ctx->k5_context, &now))) {
560Sstevel@tonic-gate       *minor_status = code;
57*13132SGlenn.Barry@oracle.com       save_error_info(*minor_status, ctx->k5_context);
580Sstevel@tonic-gate       return(GSS_S_FAILURE);
590Sstevel@tonic-gate    }
600Sstevel@tonic-gate 
610Sstevel@tonic-gate    if ((lifetime = ctx->endtime - now) <= 0) {
620Sstevel@tonic-gate       *time_rec = 0;
630Sstevel@tonic-gate       *minor_status = 0;
640Sstevel@tonic-gate       return(GSS_S_CONTEXT_EXPIRED);
650Sstevel@tonic-gate    } else {
660Sstevel@tonic-gate       *time_rec = lifetime;
670Sstevel@tonic-gate       *minor_status = 0;
680Sstevel@tonic-gate       return(GSS_S_COMPLETE);
690Sstevel@tonic-gate    }
700Sstevel@tonic-gate }
71