summaryrefslogtreecommitdiffstats
path: root/src/lib/gssapi/krb5/inquire_context.c
blob: aefea92dee7b4ed75a651424459056e3d3a1acfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright 1993 by OpenVision Technologies, Inc.
 * 
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appears in all copies and
 * that both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of OpenVision not be used
 * in advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission. OpenVision makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 * 
 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#include "gssapiP_krb5.h"

OM_uint32
krb5_gss_inquire_context(minor_status, context_handle, initiator_name, 
			 acceptor_name, lifetime_rec, mech_type, ret_flags,
			 locally_initiated)
     OM_uint32 *minor_status;
     gss_ctx_id_t context_handle;
     gss_name_t *initiator_name;
     gss_name_t *acceptor_name;
     OM_uint32 *lifetime_rec;
     gss_OID *mech_type;
     int *ret_flags;
     int *locally_initiated;
{
   krb5_error_code code;
   krb5_gss_ctx_id_rec *ctx;
   krb5_principal init, accept;
   krb5_timestamp now;
   krb5_deltat lifetime;

   if (initiator_name)
      *initiator_name = GSS_C_NO_NAME;
   if (acceptor_name)
      *acceptor_name = GSS_C_NO_NAME;

   /* validate the context handle */
   if (! kg_validate_ctx_id(context_handle)) {
      *minor_status = G_VALIDATE_FAILED;
      return(GSS_S_NO_CONTEXT);
   }

   ctx = (krb5_gss_ctx_id_rec *) context_handle;

   if (! ctx->established) {
      *minor_status = KG_CTX_INCOMPLETE;
      return(GSS_S_NO_CONTEXT);
   }

   init = NULL;
   accept = NULL;

   if (code = krb5_timeofday(&now)) {
      *minor_status = code;
      return(GSS_S_FAILURE);
   }

   if ((lifetime = ctx->endtime - now) < 0)
      lifetime = 0;

   if (initiator_name) {
      if (code = krb5_copy_principal(ctx->initiate?ctx->here:ctx->there,
				     &init)) {
	 *minor_status = code;
	 return(GSS_S_FAILURE);
      }
      if (! kg_save_name((gss_name_t) init)) {
	 krb5_free_principal(init);
	 *minor_status = G_VALIDATE_FAILED;
	 return(GSS_S_FAILURE);
      }
   }

   if (acceptor_name) {
      if (code = krb5_copy_principal(ctx->initiate?ctx->there:ctx->here,
				     &accept)) {
	 if (init) krb5_free_principal(init);
	 *minor_status = code;
	 return(GSS_S_FAILURE);
      }
      if (! kg_save_name((gss_name_t) accept)) {
	 krb5_free_principal(accept);
	 if (init) {
	    kg_delete_name((gss_name_t) accept);
	    krb5_free_principal(init);
	 }
	 *minor_status = G_VALIDATE_FAILED;
	 return(GSS_S_FAILURE);
      }
   }

   if (initiator_name)
      *initiator_name = (gss_name_t) init;

   if (acceptor_name)
      *acceptor_name = (gss_name_t) accept;

   if (lifetime_rec)
      *lifetime_rec = lifetime;

   if (mech_type)
      *mech_type = (gss_OID) gss_mech_krb5;

   if (ret_flags)
      *ret_flags = GSS_C_CONF_FLAG | GSS_C_INTEG_FLAG | ctx->mutual;

   if (locally_initiated)
      *locally_initiated = ctx->initiate;

   *minor_status = 0;
   return((lifetime == 0)?GSS_S_CONTEXT_EXPIRED:GSS_S_COMPLETE);
}