e7ccdfa332b5304e73842ba3d5735b2aa0a55e23
[krb5.git] / src / lib / gssapi / krb5 / delete_sec_context.c
1 /*
2  * Copyright 1993 by OpenVision Technologies, Inc.
3  * 
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appears in all copies and
7  * that both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of OpenVision not be used
9  * in advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission. OpenVision makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  * 
14  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include "gssapiP_krb5.h"
24
25 OM_uint32 INTERFACE
26 krb5_gss_delete_sec_context(context, minor_status, context_handle, output_token)
27      krb5_context context;
28      OM_uint32 *minor_status;
29      gss_ctx_id_t *context_handle;
30      gss_buffer_t output_token;
31 {
32    krb5_gss_ctx_id_rec *ctx;
33
34    if (output_token) {
35       output_token->length = 0;
36       output_token->value = NULL;
37    }
38
39    /*SUPPRESS 29*/
40    if (*context_handle == GSS_C_NO_CONTEXT) {
41       *minor_status = 0;
42       return(GSS_S_COMPLETE);
43    }
44
45    /*SUPPRESS 29*/
46    /* validate the context handle */
47    if (! kg_validate_ctx_id(*context_handle)) {
48       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
49       return(GSS_S_NO_CONTEXT);
50    }
51
52    /* construct a delete context token if necessary */
53
54    if (output_token) {
55       OM_uint32 major;
56       gss_buffer_desc empty;
57       empty.length = 0; empty.value = NULL;
58
59       if (major = kg_seal(minor_status, *context_handle, 0, GSS_C_QOP_DEFAULT,
60                           &empty, NULL, output_token, KG_TOK_DEL_CTX))
61          return(major);
62    }
63
64    /* invalidate the context handle */
65
66    (void)kg_delete_ctx_id(*context_handle);
67
68    /* free all the context state */
69
70    ctx = (gss_ctx_id_t) *context_handle;
71
72    if (ctx->enc.processed)
73       krb5_finish_key(context, &ctx->enc.eblock);
74    krb5_free_keyblock(context, ctx->enc.key);
75
76    if (ctx->seq.processed)
77       krb5_finish_key(context, &ctx->seq.eblock);
78
79    krb5_free_principal(context, ctx->here);
80    krb5_free_principal(context, ctx->there);
81    krb5_free_keyblock(context, ctx->subkey);
82
83    xfree(ctx);
84
85    /* zero the handle itself */
86
87    *context_handle = GSS_C_NO_CONTEXT;
88
89    *minor_status = 0;
90    return(GSS_S_COMPLETE);
91 }