xref: /titanic_50/usr/src/lib/libgss/g_delete_sec_context.c (revision bcde4861cca9caf5cab2b710a3241b038fec477c)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1996,1997, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  *  glue routine for gss_delete_sec_context
31  */
32 
33 #include <mechglueP.h>
34 #include <stdio.h>
35 #ifdef HAVE_STDLIB_H
36 #include <stdlib.h>
37 #endif
38 
39 OM_uint32
40 gss_delete_sec_context(minor_status,
41 				context_handle,
42 				output_token)
43 
44 OM_uint32 *			minor_status;
45 gss_ctx_id_t *			context_handle;
46 gss_buffer_t			output_token;
47 
48 {
49 	OM_uint32		status;
50 	gss_union_ctx_id_t	ctx;
51 	gss_mechanism		mech;
52 
53 	if (minor_status == NULL)
54 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
55 
56 	/* if the context_handle is Null, return NO_CONTEXT error */
57 	if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT)
58 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
59 
60 	/*
61 	 * select the approprate underlying mechanism routine and
62 	 * call it.
63 	 */
64 
65 	ctx = (gss_union_ctx_id_t) *context_handle;
66 	mech = __gss_get_mechanism(ctx->mech_type);
67 
68 	if (mech) {
69 
70 		if (mech->gss_delete_sec_context)
71 			status = mech->gss_delete_sec_context(mech->context,
72 							minor_status,
73 							&ctx->internal_ctx_id,
74 							output_token);
75 		else
76 			status = GSS_S_UNAVAILABLE;
77 
78 		/* now free up the space for the union context structure */
79 		free(ctx->mech_type->elements);
80 		free(ctx->mech_type);
81 		free(*context_handle);
82 		*context_handle = NULL;
83 
84 		return (status);
85 	}
86 
87 	return (GSS_S_BAD_MECH);
88 }
89