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