xref: /freebsd/crypto/krb5/src/lib/gssapi/krb5/delete_sec_context.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * Copyright 1993 by OpenVision Technologies, Inc.
4*7f2fe78bSCy Schubert  *
5*7f2fe78bSCy Schubert  * Permission to use, copy, modify, distribute, and sell this software
6*7f2fe78bSCy Schubert  * and its documentation for any purpose is hereby granted without fee,
7*7f2fe78bSCy Schubert  * provided that the above copyright notice appears in all copies and
8*7f2fe78bSCy Schubert  * that both that copyright notice and this permission notice appear in
9*7f2fe78bSCy Schubert  * supporting documentation, and that the name of OpenVision not be used
10*7f2fe78bSCy Schubert  * in advertising or publicity pertaining to distribution of the software
11*7f2fe78bSCy Schubert  * without specific, written prior permission. OpenVision makes no
12*7f2fe78bSCy Schubert  * representations about the suitability of this software for any
13*7f2fe78bSCy Schubert  * purpose.  It is provided "as is" without express or implied warranty.
14*7f2fe78bSCy Schubert  *
15*7f2fe78bSCy Schubert  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16*7f2fe78bSCy Schubert  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17*7f2fe78bSCy Schubert  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18*7f2fe78bSCy Schubert  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19*7f2fe78bSCy Schubert  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20*7f2fe78bSCy Schubert  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21*7f2fe78bSCy Schubert  * PERFORMANCE OF THIS SOFTWARE.
22*7f2fe78bSCy Schubert  */
23*7f2fe78bSCy Schubert 
24*7f2fe78bSCy Schubert #include "gssapiP_krb5.h"
25*7f2fe78bSCy Schubert 
26*7f2fe78bSCy Schubert /*
27*7f2fe78bSCy Schubert  * $Id$
28*7f2fe78bSCy Schubert  */
29*7f2fe78bSCy Schubert 
30*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
krb5_gss_delete_sec_context(minor_status,context_handle,output_token)31*7f2fe78bSCy Schubert krb5_gss_delete_sec_context(minor_status, context_handle, output_token)
32*7f2fe78bSCy Schubert     OM_uint32 *minor_status;
33*7f2fe78bSCy Schubert     gss_ctx_id_t *context_handle;
34*7f2fe78bSCy Schubert     gss_buffer_t output_token;
35*7f2fe78bSCy Schubert {
36*7f2fe78bSCy Schubert     krb5_context context;
37*7f2fe78bSCy Schubert     krb5_gss_ctx_id_rec *ctx;
38*7f2fe78bSCy Schubert 
39*7f2fe78bSCy Schubert     if (output_token) {
40*7f2fe78bSCy Schubert         output_token->length = 0;
41*7f2fe78bSCy Schubert         output_token->value = NULL;
42*7f2fe78bSCy Schubert     }
43*7f2fe78bSCy Schubert 
44*7f2fe78bSCy Schubert     /*SUPPRESS 29*/
45*7f2fe78bSCy Schubert     if (*context_handle == GSS_C_NO_CONTEXT) {
46*7f2fe78bSCy Schubert         *minor_status = 0;
47*7f2fe78bSCy Schubert         return(GSS_S_COMPLETE);
48*7f2fe78bSCy Schubert     }
49*7f2fe78bSCy Schubert 
50*7f2fe78bSCy Schubert     ctx = (krb5_gss_ctx_id_t) *context_handle;
51*7f2fe78bSCy Schubert     context = ctx->k5_context;
52*7f2fe78bSCy Schubert 
53*7f2fe78bSCy Schubert     /* free all the context state */
54*7f2fe78bSCy Schubert 
55*7f2fe78bSCy Schubert     if (ctx->seqstate)
56*7f2fe78bSCy Schubert         g_seqstate_free(ctx->seqstate);
57*7f2fe78bSCy Schubert 
58*7f2fe78bSCy Schubert     if (ctx->enc)
59*7f2fe78bSCy Schubert         krb5_k_free_key(context, ctx->enc);
60*7f2fe78bSCy Schubert 
61*7f2fe78bSCy Schubert     if (ctx->seq)
62*7f2fe78bSCy Schubert         krb5_k_free_key(context, ctx->seq);
63*7f2fe78bSCy Schubert 
64*7f2fe78bSCy Schubert     if (ctx->here)
65*7f2fe78bSCy Schubert         kg_release_name(context, &ctx->here);
66*7f2fe78bSCy Schubert     if (ctx->there)
67*7f2fe78bSCy Schubert         kg_release_name(context, &ctx->there);
68*7f2fe78bSCy Schubert     if (ctx->subkey)
69*7f2fe78bSCy Schubert         krb5_k_free_key(context, ctx->subkey);
70*7f2fe78bSCy Schubert     if (ctx->acceptor_subkey)
71*7f2fe78bSCy Schubert         krb5_k_free_key(context, ctx->acceptor_subkey);
72*7f2fe78bSCy Schubert 
73*7f2fe78bSCy Schubert     if (ctx->auth_context) {
74*7f2fe78bSCy Schubert         if (ctx->cred_rcache)
75*7f2fe78bSCy Schubert             (void)krb5_auth_con_setrcache(context, ctx->auth_context, NULL);
76*7f2fe78bSCy Schubert 
77*7f2fe78bSCy Schubert         krb5_auth_con_free(context, ctx->auth_context);
78*7f2fe78bSCy Schubert     }
79*7f2fe78bSCy Schubert 
80*7f2fe78bSCy Schubert     if (ctx->mech_used)
81*7f2fe78bSCy Schubert         krb5_gss_release_oid(minor_status, &ctx->mech_used);
82*7f2fe78bSCy Schubert 
83*7f2fe78bSCy Schubert     if (ctx->authdata)
84*7f2fe78bSCy Schubert         krb5_free_authdata(context, ctx->authdata);
85*7f2fe78bSCy Schubert 
86*7f2fe78bSCy Schubert     if (ctx->k5_context)
87*7f2fe78bSCy Schubert         krb5_free_context(ctx->k5_context);
88*7f2fe78bSCy Schubert 
89*7f2fe78bSCy Schubert     /* Zero out context */
90*7f2fe78bSCy Schubert     zap(ctx, sizeof(*ctx));
91*7f2fe78bSCy Schubert     xfree(ctx);
92*7f2fe78bSCy Schubert 
93*7f2fe78bSCy Schubert     /* zero the handle itself */
94*7f2fe78bSCy Schubert 
95*7f2fe78bSCy Schubert     *context_handle = GSS_C_NO_CONTEXT;
96*7f2fe78bSCy Schubert 
97*7f2fe78bSCy Schubert     *minor_status = 0;
98*7f2fe78bSCy Schubert     return(GSS_S_COMPLETE);
99*7f2fe78bSCy Schubert }
100