1 /* #pragma ident "@(#)g_delete_sec_context.c 1.11 97/11/09 SMI" */
2
3 /*
4 * Copyright 1996 by Sun Microsystems, Inc.
5 *
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appears in all copies and
9 * that both that copyright notice and this permission notice appear in
10 * supporting documentation, and that the name of Sun Microsystems not be used
11 * in advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. Sun Microsystems makes no
13 * representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
15 *
16 * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
23 */
24
25 /*
26 * glue routine for gss_delete_sec_context
27 */
28
29 #include "mglueP.h"
30 #include <stdio.h>
31 #ifdef HAVE_STDLIB_H
32 #include <stdlib.h>
33 #endif
34
35 static OM_uint32
val_del_sec_ctx_args(OM_uint32 * minor_status,gss_ctx_id_t * context_handle,gss_buffer_t output_token)36 val_del_sec_ctx_args(
37 OM_uint32 *minor_status,
38 gss_ctx_id_t *context_handle,
39 gss_buffer_t output_token)
40 {
41
42 /* Initialize outputs. */
43
44 if (minor_status != NULL)
45 *minor_status = 0;
46
47 if (output_token != GSS_C_NO_BUFFER) {
48 output_token->length = 0;
49 output_token->value = NULL;
50 }
51
52 /* Validate arguments. */
53
54 if (minor_status == NULL)
55 return (GSS_S_CALL_INACCESSIBLE_WRITE);
56
57 if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT)
58 return (GSS_S_CALL_INACCESSIBLE_WRITE | GSS_S_NO_CONTEXT);
59
60 return (GSS_S_COMPLETE);
61 }
62
63
64 OM_uint32 KRB5_CALLCONV
gss_delete_sec_context(OM_uint32 * minor_status,gss_ctx_id_t * context_handle,gss_buffer_t output_token)65 gss_delete_sec_context(OM_uint32 *minor_status, gss_ctx_id_t *context_handle,
66 gss_buffer_t output_token)
67 {
68 OM_uint32 status;
69 gss_union_ctx_id_t ctx;
70
71 status = val_del_sec_ctx_args(minor_status, context_handle, output_token);
72 if (status != GSS_S_COMPLETE)
73 return (status);
74
75 /*
76 * select the approprate underlying mechanism routine and
77 * call it.
78 */
79
80 ctx = (gss_union_ctx_id_t) *context_handle;
81 if (GSSINT_CHK_LOOP(ctx))
82 return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
83
84 if (ctx->internal_ctx_id != GSS_C_NO_CONTEXT) {
85 status = gssint_delete_internal_sec_context(minor_status,
86 ctx->mech_type,
87 &ctx->internal_ctx_id,
88 output_token);
89 if (status)
90 return status;
91 }
92
93 /* now free up the space for the union context structure */
94 free(ctx->mech_type->elements);
95 free(ctx->mech_type);
96 free(*context_handle);
97 *context_handle = GSS_C_NO_CONTEXT;
98
99 return (GSS_S_COMPLETE);
100 }
101