xref: /freebsd/crypto/krb5/src/lib/gssapi/mechglue/g_delete_sec_context.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
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(minor_status,context_handle,output_token)65 gss_delete_sec_context (minor_status,
66                         context_handle,
67                         output_token)
68 
69 OM_uint32 *		minor_status;
70 gss_ctx_id_t *		context_handle;
71 gss_buffer_t		output_token;
72 
73 {
74     OM_uint32		status;
75     gss_union_ctx_id_t	ctx;
76 
77     status = val_del_sec_ctx_args(minor_status, context_handle, output_token);
78     if (status != GSS_S_COMPLETE)
79 	return (status);
80 
81     /*
82      * select the approprate underlying mechanism routine and
83      * call it.
84      */
85 
86     ctx = (gss_union_ctx_id_t) *context_handle;
87     if (GSSINT_CHK_LOOP(ctx))
88 	return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
89 
90     if (ctx->internal_ctx_id != GSS_C_NO_CONTEXT) {
91 	status = gssint_delete_internal_sec_context(minor_status,
92 						    ctx->mech_type,
93 						    &ctx->internal_ctx_id,
94 						    output_token);
95 	if (status)
96 	    return status;
97     }
98 
99     /* now free up the space for the union context structure */
100     free(ctx->mech_type->elements);
101     free(ctx->mech_type);
102     free(*context_handle);
103     *context_handle = GSS_C_NO_CONTEXT;
104 
105     return (GSS_S_COMPLETE);
106 }
107