xref: /freebsd/crypto/krb5/src/lib/gssapi/mechglue/g_wrap_iov.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* #pragma ident	"@(#)g_seal.c	1.19	98/04/21 SMI" */
2*7f2fe78bSCy Schubert 
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert  * Copyright 1996 by Sun Microsystems, Inc.
5*7f2fe78bSCy Schubert  *
6*7f2fe78bSCy Schubert  * Permission to use, copy, modify, distribute, and sell this software
7*7f2fe78bSCy Schubert  * and its documentation for any purpose is hereby granted without fee,
8*7f2fe78bSCy Schubert  * provided that the above copyright notice appears in all copies and
9*7f2fe78bSCy Schubert  * that both that copyright notice and this permission notice appear in
10*7f2fe78bSCy Schubert  * supporting documentation, and that the name of Sun Microsystems not be used
11*7f2fe78bSCy Schubert  * in advertising or publicity pertaining to distribution of the software
12*7f2fe78bSCy Schubert  * without specific, written prior permission. Sun Microsystems makes no
13*7f2fe78bSCy Schubert  * representations about the suitability of this software for any
14*7f2fe78bSCy Schubert  * purpose.  It is provided "as is" without express or implied warranty.
15*7f2fe78bSCy Schubert  *
16*7f2fe78bSCy Schubert  * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17*7f2fe78bSCy Schubert  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18*7f2fe78bSCy Schubert  * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19*7f2fe78bSCy Schubert  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20*7f2fe78bSCy Schubert  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21*7f2fe78bSCy Schubert  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22*7f2fe78bSCy Schubert  * PERFORMANCE OF THIS SOFTWARE.
23*7f2fe78bSCy Schubert  */
24*7f2fe78bSCy Schubert 
25*7f2fe78bSCy Schubert /*
26*7f2fe78bSCy Schubert  *  glue routine for gss_wrap_iov
27*7f2fe78bSCy Schubert  */
28*7f2fe78bSCy Schubert 
29*7f2fe78bSCy Schubert #include "mglueP.h"
30*7f2fe78bSCy Schubert 
31*7f2fe78bSCy Schubert static OM_uint32
val_wrap_iov_args(OM_uint32 * minor_status,gss_ctx_id_t context_handle,int conf_req_flag,gss_qop_t qop_req,int * conf_state,gss_iov_buffer_desc * iov,int iov_count)32*7f2fe78bSCy Schubert val_wrap_iov_args(
33*7f2fe78bSCy Schubert     OM_uint32 *minor_status,
34*7f2fe78bSCy Schubert     gss_ctx_id_t context_handle,
35*7f2fe78bSCy Schubert     int conf_req_flag,
36*7f2fe78bSCy Schubert     gss_qop_t qop_req,
37*7f2fe78bSCy Schubert     int *conf_state,
38*7f2fe78bSCy Schubert     gss_iov_buffer_desc *iov,
39*7f2fe78bSCy Schubert     int iov_count)
40*7f2fe78bSCy Schubert {
41*7f2fe78bSCy Schubert 
42*7f2fe78bSCy Schubert     /* Initialize outputs. */
43*7f2fe78bSCy Schubert 
44*7f2fe78bSCy Schubert     if (minor_status != NULL)
45*7f2fe78bSCy Schubert 	*minor_status = 0;
46*7f2fe78bSCy Schubert 
47*7f2fe78bSCy Schubert     /* Validate arguments. */
48*7f2fe78bSCy Schubert 
49*7f2fe78bSCy Schubert     if (minor_status == NULL)
50*7f2fe78bSCy Schubert 	return (GSS_S_CALL_INACCESSIBLE_WRITE);
51*7f2fe78bSCy Schubert 
52*7f2fe78bSCy Schubert     if (context_handle == GSS_C_NO_CONTEXT)
53*7f2fe78bSCy Schubert 	return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
54*7f2fe78bSCy Schubert 
55*7f2fe78bSCy Schubert     if (iov == GSS_C_NO_IOV_BUFFER)
56*7f2fe78bSCy Schubert 	return (GSS_S_CALL_INACCESSIBLE_READ);
57*7f2fe78bSCy Schubert 
58*7f2fe78bSCy Schubert     return (GSS_S_COMPLETE);
59*7f2fe78bSCy Schubert }
60*7f2fe78bSCy Schubert 
61*7f2fe78bSCy Schubert 
62*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_wrap_iov(minor_status,context_handle,conf_req_flag,qop_req,conf_state,iov,iov_count)63*7f2fe78bSCy Schubert gss_wrap_iov (minor_status,
64*7f2fe78bSCy Schubert               context_handle,
65*7f2fe78bSCy Schubert               conf_req_flag,
66*7f2fe78bSCy Schubert               qop_req,
67*7f2fe78bSCy Schubert               conf_state,
68*7f2fe78bSCy Schubert               iov,
69*7f2fe78bSCy Schubert               iov_count)
70*7f2fe78bSCy Schubert OM_uint32 *		minor_status;
71*7f2fe78bSCy Schubert gss_ctx_id_t		context_handle;
72*7f2fe78bSCy Schubert int			conf_req_flag;
73*7f2fe78bSCy Schubert gss_qop_t		qop_req;
74*7f2fe78bSCy Schubert int *			conf_state;
75*7f2fe78bSCy Schubert gss_iov_buffer_desc  *	iov;
76*7f2fe78bSCy Schubert int			iov_count;
77*7f2fe78bSCy Schubert {
78*7f2fe78bSCy Schubert  /* EXPORT DELETE START */
79*7f2fe78bSCy Schubert 
80*7f2fe78bSCy Schubert     OM_uint32		status;
81*7f2fe78bSCy Schubert     gss_union_ctx_id_t	ctx;
82*7f2fe78bSCy Schubert     gss_mechanism	mech;
83*7f2fe78bSCy Schubert 
84*7f2fe78bSCy Schubert     status = val_wrap_iov_args(minor_status, context_handle,
85*7f2fe78bSCy Schubert 			       conf_req_flag, qop_req,
86*7f2fe78bSCy Schubert 			       conf_state, iov, iov_count);
87*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE)
88*7f2fe78bSCy Schubert 	return (status);
89*7f2fe78bSCy Schubert 
90*7f2fe78bSCy Schubert     /*
91*7f2fe78bSCy Schubert      * select the approprate underlying mechanism routine and
92*7f2fe78bSCy Schubert      * call it.
93*7f2fe78bSCy Schubert      */
94*7f2fe78bSCy Schubert 
95*7f2fe78bSCy Schubert     ctx = (gss_union_ctx_id_t) context_handle;
96*7f2fe78bSCy Schubert     if (ctx->internal_ctx_id == GSS_C_NO_CONTEXT)
97*7f2fe78bSCy Schubert 	return (GSS_S_NO_CONTEXT);
98*7f2fe78bSCy Schubert     mech = gssint_get_mechanism (ctx->mech_type);
99*7f2fe78bSCy Schubert 
100*7f2fe78bSCy Schubert     if (mech) {
101*7f2fe78bSCy Schubert 	if (mech->gss_wrap_iov) {
102*7f2fe78bSCy Schubert 	    status = mech->gss_wrap_iov(
103*7f2fe78bSCy Schubert 					minor_status,
104*7f2fe78bSCy Schubert 					ctx->internal_ctx_id,
105*7f2fe78bSCy Schubert 					conf_req_flag,
106*7f2fe78bSCy Schubert 					qop_req,
107*7f2fe78bSCy Schubert 					conf_state,
108*7f2fe78bSCy Schubert 					iov,
109*7f2fe78bSCy Schubert 					iov_count);
110*7f2fe78bSCy Schubert 	    if (status != GSS_S_COMPLETE)
111*7f2fe78bSCy Schubert 		map_error(minor_status, mech);
112*7f2fe78bSCy Schubert 	} else
113*7f2fe78bSCy Schubert 	    status = GSS_S_UNAVAILABLE;
114*7f2fe78bSCy Schubert 
115*7f2fe78bSCy Schubert 	return(status);
116*7f2fe78bSCy Schubert     }
117*7f2fe78bSCy Schubert  /* EXPORT DELETE END */
118*7f2fe78bSCy Schubert 
119*7f2fe78bSCy Schubert     return (GSS_S_BAD_MECH);
120*7f2fe78bSCy Schubert }
121*7f2fe78bSCy Schubert 
122*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_wrap_iov_length(minor_status,context_handle,conf_req_flag,qop_req,conf_state,iov,iov_count)123*7f2fe78bSCy Schubert gss_wrap_iov_length (minor_status,
124*7f2fe78bSCy Schubert                      context_handle,
125*7f2fe78bSCy Schubert                      conf_req_flag,
126*7f2fe78bSCy Schubert                      qop_req,
127*7f2fe78bSCy Schubert                      conf_state,
128*7f2fe78bSCy Schubert                      iov,
129*7f2fe78bSCy Schubert                      iov_count)
130*7f2fe78bSCy Schubert OM_uint32 *		minor_status;
131*7f2fe78bSCy Schubert gss_ctx_id_t		context_handle;
132*7f2fe78bSCy Schubert int			conf_req_flag;
133*7f2fe78bSCy Schubert gss_qop_t		qop_req;
134*7f2fe78bSCy Schubert int *			conf_state;
135*7f2fe78bSCy Schubert gss_iov_buffer_desc  *	iov;
136*7f2fe78bSCy Schubert int			iov_count;
137*7f2fe78bSCy Schubert {
138*7f2fe78bSCy Schubert  /* EXPORT DELETE START */
139*7f2fe78bSCy Schubert 
140*7f2fe78bSCy Schubert     OM_uint32		status;
141*7f2fe78bSCy Schubert     gss_union_ctx_id_t	ctx;
142*7f2fe78bSCy Schubert     gss_mechanism	mech;
143*7f2fe78bSCy Schubert 
144*7f2fe78bSCy Schubert     status = val_wrap_iov_args(minor_status, context_handle,
145*7f2fe78bSCy Schubert 			       conf_req_flag, qop_req,
146*7f2fe78bSCy Schubert 			       conf_state, iov, iov_count);
147*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE)
148*7f2fe78bSCy Schubert 	return (status);
149*7f2fe78bSCy Schubert 
150*7f2fe78bSCy Schubert     /*
151*7f2fe78bSCy Schubert      * select the approprate underlying mechanism routine and
152*7f2fe78bSCy Schubert      * call it.
153*7f2fe78bSCy Schubert      */
154*7f2fe78bSCy Schubert 
155*7f2fe78bSCy Schubert     ctx = (gss_union_ctx_id_t) context_handle;
156*7f2fe78bSCy Schubert     if (ctx->internal_ctx_id == GSS_C_NO_CONTEXT)
157*7f2fe78bSCy Schubert 	return (GSS_S_NO_CONTEXT);
158*7f2fe78bSCy Schubert     mech = gssint_get_mechanism (ctx->mech_type);
159*7f2fe78bSCy Schubert 
160*7f2fe78bSCy Schubert     if (mech) {
161*7f2fe78bSCy Schubert 	if (mech->gss_wrap_iov_length) {
162*7f2fe78bSCy Schubert 	    status = mech->gss_wrap_iov_length(
163*7f2fe78bSCy Schubert 					      minor_status,
164*7f2fe78bSCy Schubert 					      ctx->internal_ctx_id,
165*7f2fe78bSCy Schubert 					      conf_req_flag,
166*7f2fe78bSCy Schubert 					      qop_req,
167*7f2fe78bSCy Schubert 					      conf_state,
168*7f2fe78bSCy Schubert 					      iov,
169*7f2fe78bSCy Schubert 					      iov_count);
170*7f2fe78bSCy Schubert 	    if (status != GSS_S_COMPLETE)
171*7f2fe78bSCy Schubert 		map_error(minor_status, mech);
172*7f2fe78bSCy Schubert 	} else
173*7f2fe78bSCy Schubert 	    status = GSS_S_UNAVAILABLE;
174*7f2fe78bSCy Schubert 
175*7f2fe78bSCy Schubert 	return(status);
176*7f2fe78bSCy Schubert     }
177*7f2fe78bSCy Schubert  /* EXPORT DELETE END */
178*7f2fe78bSCy Schubert 
179*7f2fe78bSCy Schubert     return (GSS_S_BAD_MECH);
180*7f2fe78bSCy Schubert }
181*7f2fe78bSCy Schubert 
182*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_get_mic_iov(OM_uint32 * minor_status,gss_ctx_id_t context_handle,gss_qop_t qop_req,gss_iov_buffer_desc * iov,int iov_count)183*7f2fe78bSCy Schubert gss_get_mic_iov(OM_uint32 *minor_status, gss_ctx_id_t context_handle,
184*7f2fe78bSCy Schubert 		gss_qop_t qop_req, gss_iov_buffer_desc *iov, int iov_count)
185*7f2fe78bSCy Schubert {
186*7f2fe78bSCy Schubert     OM_uint32 status;
187*7f2fe78bSCy Schubert     gss_union_ctx_id_t ctx;
188*7f2fe78bSCy Schubert     gss_mechanism mech;
189*7f2fe78bSCy Schubert 
190*7f2fe78bSCy Schubert     status = val_wrap_iov_args(minor_status, context_handle, 0, qop_req, NULL,
191*7f2fe78bSCy Schubert 			       iov, iov_count);
192*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE)
193*7f2fe78bSCy Schubert 	return status;
194*7f2fe78bSCy Schubert 
195*7f2fe78bSCy Schubert     /* Select the approprate underlying mechanism routine and call it. */
196*7f2fe78bSCy Schubert     ctx = (gss_union_ctx_id_t)context_handle;
197*7f2fe78bSCy Schubert     if (ctx->internal_ctx_id == GSS_C_NO_CONTEXT)
198*7f2fe78bSCy Schubert 	return GSS_S_NO_CONTEXT;
199*7f2fe78bSCy Schubert     mech = gssint_get_mechanism(ctx->mech_type);
200*7f2fe78bSCy Schubert     if (mech == NULL)
201*7f2fe78bSCy Schubert 	return GSS_S_BAD_MECH;
202*7f2fe78bSCy Schubert     if (mech->gss_get_mic_iov == NULL)
203*7f2fe78bSCy Schubert 	return GSS_S_UNAVAILABLE;
204*7f2fe78bSCy Schubert     status = mech->gss_get_mic_iov(minor_status, ctx->internal_ctx_id, qop_req,
205*7f2fe78bSCy Schubert 				   iov, iov_count);
206*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE)
207*7f2fe78bSCy Schubert 	map_error(minor_status, mech);
208*7f2fe78bSCy Schubert     return status;
209*7f2fe78bSCy Schubert }
210*7f2fe78bSCy Schubert 
211*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_get_mic_iov_length(OM_uint32 * minor_status,gss_ctx_id_t context_handle,gss_qop_t qop_req,gss_iov_buffer_desc * iov,int iov_count)212*7f2fe78bSCy Schubert gss_get_mic_iov_length(OM_uint32 *minor_status, gss_ctx_id_t context_handle,
213*7f2fe78bSCy Schubert 		       gss_qop_t qop_req, gss_iov_buffer_desc *iov,
214*7f2fe78bSCy Schubert 		       int iov_count)
215*7f2fe78bSCy Schubert {
216*7f2fe78bSCy Schubert     OM_uint32 status;
217*7f2fe78bSCy Schubert     gss_union_ctx_id_t ctx;
218*7f2fe78bSCy Schubert     gss_mechanism mech;
219*7f2fe78bSCy Schubert 
220*7f2fe78bSCy Schubert     status = val_wrap_iov_args(minor_status, context_handle, 0, qop_req, NULL,
221*7f2fe78bSCy Schubert 			       iov, iov_count);
222*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE)
223*7f2fe78bSCy Schubert 	return status;
224*7f2fe78bSCy Schubert 
225*7f2fe78bSCy Schubert     /* Select the approprate underlying mechanism routine and call it. */
226*7f2fe78bSCy Schubert     ctx = (gss_union_ctx_id_t)context_handle;
227*7f2fe78bSCy Schubert     if (ctx->internal_ctx_id == GSS_C_NO_CONTEXT)
228*7f2fe78bSCy Schubert 	return GSS_S_NO_CONTEXT;
229*7f2fe78bSCy Schubert     mech = gssint_get_mechanism(ctx->mech_type);
230*7f2fe78bSCy Schubert     if (mech == NULL)
231*7f2fe78bSCy Schubert 	return GSS_S_BAD_MECH;
232*7f2fe78bSCy Schubert     if (mech->gss_get_mic_iov_length == NULL)
233*7f2fe78bSCy Schubert 	return GSS_S_UNAVAILABLE;
234*7f2fe78bSCy Schubert     status = mech->gss_get_mic_iov_length(minor_status, ctx->internal_ctx_id,
235*7f2fe78bSCy Schubert 					  qop_req, iov, iov_count);
236*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE)
237*7f2fe78bSCy Schubert 	map_error(minor_status, mech);
238*7f2fe78bSCy Schubert     return status;
239*7f2fe78bSCy Schubert }
240*7f2fe78bSCy Schubert 
241*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_release_iov_buffer(minor_status,iov,iov_count)242*7f2fe78bSCy Schubert gss_release_iov_buffer (minor_status,
243*7f2fe78bSCy Schubert 			iov,
244*7f2fe78bSCy Schubert 			iov_count)
245*7f2fe78bSCy Schubert OM_uint32 *		minor_status;
246*7f2fe78bSCy Schubert gss_iov_buffer_desc *	iov;
247*7f2fe78bSCy Schubert int			iov_count;
248*7f2fe78bSCy Schubert {
249*7f2fe78bSCy Schubert     OM_uint32		status = GSS_S_COMPLETE;
250*7f2fe78bSCy Schubert     int			i;
251*7f2fe78bSCy Schubert 
252*7f2fe78bSCy Schubert     if (minor_status)
253*7f2fe78bSCy Schubert 	*minor_status = 0;
254*7f2fe78bSCy Schubert 
255*7f2fe78bSCy Schubert     if (iov == GSS_C_NO_IOV_BUFFER)
256*7f2fe78bSCy Schubert 	return GSS_S_COMPLETE;
257*7f2fe78bSCy Schubert 
258*7f2fe78bSCy Schubert     for (i = 0; i < iov_count; i++) {
259*7f2fe78bSCy Schubert 	if (iov[i].type & GSS_IOV_BUFFER_FLAG_ALLOCATED) {
260*7f2fe78bSCy Schubert 	    status = gss_release_buffer(minor_status, &iov[i].buffer);
261*7f2fe78bSCy Schubert 	    if (status != GSS_S_COMPLETE)
262*7f2fe78bSCy Schubert 		break;
263*7f2fe78bSCy Schubert 
264*7f2fe78bSCy Schubert 	    iov[i].type &= ~(GSS_IOV_BUFFER_FLAG_ALLOCATED);
265*7f2fe78bSCy Schubert 	}
266*7f2fe78bSCy Schubert     }
267*7f2fe78bSCy Schubert 
268*7f2fe78bSCy Schubert     return status;
269*7f2fe78bSCy Schubert }
270