xref: /titanic_41/usr/src/lib/libgss/g_delete_sec_context.c (revision 4c06356b0f0fffb4fc1b6eccc8e5d8e2254a84d6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *  glue routine for gss_delete_sec_context
28  */
29 
30 #include <mechglueP.h>
31 #include <stdio.h>
32 #ifdef HAVE_STDLIB_H
33 #include <stdlib.h>
34 #endif
35 
36 static OM_uint32
37 val_del_sec_ctx_args(
38 	OM_uint32 *minor_status,
39 	gss_ctx_id_t *context_handle,
40 	gss_buffer_t output_token)
41 {
42 
43 	/* Initialize outputs. */
44 
45 	if (minor_status != NULL)
46 		*minor_status = 0;
47 
48 	if (output_token != GSS_C_NO_BUFFER) {
49 		output_token->length = 0;
50 		output_token->value = NULL;
51 	}
52 
53 	/* Validate arguments. */
54 
55 	if (minor_status == NULL)
56 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
57 
58 	if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT)
59 		return (GSS_S_CALL_INACCESSIBLE_WRITE | GSS_S_NO_CONTEXT);
60 
61 	return (GSS_S_COMPLETE);
62 }
63 
64 OM_uint32
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 	gss_mechanism		mech;
77 
78 	status = val_del_sec_ctx_args(minor_status,
79 				context_handle,
80 				output_token);
81 	if (status != GSS_S_COMPLETE)
82 		return (status);
83 
84 	/*
85 	 * select the approprate underlying mechanism routine and
86 	 * call it.
87 	 */
88 
89 	ctx = (gss_union_ctx_id_t) *context_handle;
90 	mech = __gss_get_mechanism(ctx->mech_type);
91 
92 	if (mech) {
93 
94 		if (mech->gss_delete_sec_context)
95 			status = mech->gss_delete_sec_context(mech->context,
96 							minor_status,
97 							&ctx->internal_ctx_id,
98 							output_token);
99 		else
100 			status = GSS_S_UNAVAILABLE;
101 
102 		/* now free up the space for the union context structure */
103 		free(ctx->mech_type->elements);
104 		free(ctx->mech_type);
105 		free(*context_handle);
106 		*context_handle = NULL;
107 
108 		return (status);
109 	}
110 
111 	return (GSS_S_BAD_MECH);
112 }
113