15e01956fSGlenn Barry /*
25e01956fSGlenn Barry  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
35e01956fSGlenn Barry  */
4ab9b2e15Sgtb /* Copyright 1993 by OpenVision Technologies, Inc.
5*55fea89dSDan Cross  *
67c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, distribute, and sell this software
77c478bd9Sstevel@tonic-gate  * and its documentation for any purpose is hereby granted without fee,
87c478bd9Sstevel@tonic-gate  * provided that the above copyright notice appears in all copies and
97c478bd9Sstevel@tonic-gate  * that both that copyright notice and this permission notice appear in
107c478bd9Sstevel@tonic-gate  * supporting documentation, and that the name of OpenVision not be used
117c478bd9Sstevel@tonic-gate  * in advertising or publicity pertaining to distribution of the software
127c478bd9Sstevel@tonic-gate  * without specific, written prior permission. OpenVision makes no
137c478bd9Sstevel@tonic-gate  * representations about the suitability of this software for any
147c478bd9Sstevel@tonic-gate  * purpose.  It is provided "as is" without express or implied warranty.
15*55fea89dSDan Cross  *
167c478bd9Sstevel@tonic-gate  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
177c478bd9Sstevel@tonic-gate  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
187c478bd9Sstevel@tonic-gate  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
197c478bd9Sstevel@tonic-gate  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
207c478bd9Sstevel@tonic-gate  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
217c478bd9Sstevel@tonic-gate  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
227c478bd9Sstevel@tonic-gate  * PERFORMANCE OF THIS SOFTWARE.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
25ab9b2e15Sgtb #include "gssapiP_krb5.h"
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
28ab9b2e15Sgtb  * $Id: context_time.c 16187 2004-03-19 09:33:57Z raeburn $
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate OM_uint32
krb5_gss_context_time(minor_status,context_handle,time_rec)32ab9b2e15Sgtb krb5_gss_context_time(minor_status, context_handle, time_rec)
337c478bd9Sstevel@tonic-gate      OM_uint32 *minor_status;
347c478bd9Sstevel@tonic-gate      gss_ctx_id_t context_handle;
357c478bd9Sstevel@tonic-gate      OM_uint32 *time_rec;
367c478bd9Sstevel@tonic-gate {
377c478bd9Sstevel@tonic-gate    krb5_error_code code;
387c478bd9Sstevel@tonic-gate    krb5_gss_ctx_id_rec *ctx;
397c478bd9Sstevel@tonic-gate    krb5_timestamp now;
407c478bd9Sstevel@tonic-gate    krb5_deltat lifetime;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate    /* validate the context handle */
437c478bd9Sstevel@tonic-gate    if (! kg_validate_ctx_id(context_handle)) {
447c478bd9Sstevel@tonic-gate       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
457c478bd9Sstevel@tonic-gate       return(GSS_S_NO_CONTEXT);
467c478bd9Sstevel@tonic-gate    }
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate    ctx = (krb5_gss_ctx_id_rec *) context_handle;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate    if (! ctx->established) {
517c478bd9Sstevel@tonic-gate       *minor_status = KG_CTX_INCOMPLETE;
527c478bd9Sstevel@tonic-gate       return(GSS_S_NO_CONTEXT);
537c478bd9Sstevel@tonic-gate    }
547c478bd9Sstevel@tonic-gate 
55ab9b2e15Sgtb    if ((code = krb5_timeofday(ctx->k5_context, &now))) {
567c478bd9Sstevel@tonic-gate       *minor_status = code;
575e01956fSGlenn Barry       save_error_info(*minor_status, ctx->k5_context);
587c478bd9Sstevel@tonic-gate       return(GSS_S_FAILURE);
597c478bd9Sstevel@tonic-gate    }
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate    if ((lifetime = ctx->endtime - now) <= 0) {
627c478bd9Sstevel@tonic-gate       *time_rec = 0;
637c478bd9Sstevel@tonic-gate       *minor_status = 0;
647c478bd9Sstevel@tonic-gate       return(GSS_S_CONTEXT_EXPIRED);
657c478bd9Sstevel@tonic-gate    } else {
667c478bd9Sstevel@tonic-gate       *time_rec = lifetime;
677c478bd9Sstevel@tonic-gate       *minor_status = 0;
687c478bd9Sstevel@tonic-gate       return(GSS_S_COMPLETE);
697c478bd9Sstevel@tonic-gate    }
707c478bd9Sstevel@tonic-gate }
71