xref: /illumos-gate/usr/src/lib/libgss/g_delete_sec_context.c (revision 69a119caa6570c7077699161b7c28b6ee9f8b0f4)
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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 /*
26  *  glue routine for gss_delete_sec_context
27  */
28 
29 #include <mechglueP.h>
30 #include "gssapiP_generic.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 
77 	status = val_del_sec_ctx_args(minor_status,
78 				context_handle,
79 				output_token);
80 	if (status != GSS_S_COMPLETE)
81 		return (status);
82 
83 	/*
84 	 * select the approprate underlying mechanism routine and
85 	 * call it.
86 	 */
87 
88 	ctx = (gss_union_ctx_id_t) *context_handle;
89 	if (GSSINT_CHK_LOOP(ctx))
90 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
91 
92 	status = gssint_delete_internal_sec_context(minor_status,
93 						    ctx->mech_type,
94 						    &ctx->internal_ctx_id,
95 						    output_token);
96 	if (status)
97 		return status;
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