xref: /titanic_41/usr/src/lib/libgss/g_unseal.c (revision bbb1277b6ec1b0daad4e3ed1a2b891d3e2ece2eb)
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 gss_unseal
28  */
29 
30 #include <mechglueP.h>
31 
32 OM_uint32
33 gss_unseal(minor_status,
34 		context_handle,
35 		input_message_buffer,
36 		output_message_buffer,
37 		conf_state,
38 		qop_state)
39 
40 OM_uint32 *		minor_status;
41 gss_ctx_id_t		context_handle;
42 gss_buffer_t		input_message_buffer;
43 gss_buffer_t		output_message_buffer;
44 int *			conf_state;
45 int *			qop_state;
46 
47 {
48 /* EXPORT DELETE START */
49 	OM_uint32		status;
50 	gss_union_ctx_id_t	ctx;
51 	gss_mechanism		mech;
52 
53 	if (minor_status != NULL)
54 		*minor_status = 0;
55 
56 	if (output_message_buffer != GSS_C_NO_BUFFER) {
57 		output_message_buffer->length = 0;
58 		output_message_buffer->value = NULL;
59 	}
60 
61 	if (minor_status == NULL)
62 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
63 
64 	if (context_handle == GSS_C_NO_CONTEXT)
65 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
66 
67 	if (input_message_buffer == GSS_C_NO_BUFFER ||
68 	    GSS_EMPTY_BUFFER(input_message_buffer))
69 		return (GSS_S_CALL_INACCESSIBLE_READ);
70 
71 	if (output_message_buffer == GSS_C_NO_BUFFER)
72 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
73 
74 	/*
75 	 * select the approprate underlying mechanism routine and
76 	 * call it.
77 	 */
78 
79 	ctx = (gss_union_ctx_id_t) context_handle;
80 	mech = __gss_get_mechanism(ctx->mech_type);
81 
82 	if (mech) {
83 		if (mech->gss_unseal)
84 			status = mech->gss_unseal(
85 						mech->context,
86 						minor_status,
87 						ctx->internal_ctx_id,
88 						input_message_buffer,
89 						output_message_buffer,
90 						conf_state,
91 						qop_state);
92 		else
93 			status = GSS_S_UNAVAILABLE;
94 
95 		return (status);
96 	}
97 
98 /* EXPORT DELETE END */
99 
100 	return (GSS_S_BAD_MECH);
101 }
102 
103 OM_uint32
104 gss_unwrap(minor_status,
105 		context_handle,
106 		input_message_buffer,
107 		output_message_buffer,
108 		conf_state,
109 		qop_state)
110 
111 OM_uint32 *		minor_status;
112 const gss_ctx_id_t	context_handle;
113 const gss_buffer_t	input_message_buffer;
114 gss_buffer_t		output_message_buffer;
115 int *			conf_state;
116 gss_qop_t *		qop_state;
117 
118 {
119 	return (gss_unseal(minor_status, (gss_ctx_id_t)context_handle,
120 			(gss_buffer_t)input_message_buffer,
121 			output_message_buffer, conf_state, (int *) qop_state));
122 }
123