10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
59698SPeter.Shoults@Sun.COM * Common Development and Distribution License (the "License").
69698SPeter.Shoults@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*13132SGlenn.Barry@oracle.com * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate * glue routine for gss_init_sec_context
270Sstevel@tonic-gate */
280Sstevel@tonic-gate #include <mechglueP.h>
29*13132SGlenn.Barry@oracle.com #include "gssapiP_generic.h"
300Sstevel@tonic-gate #include <stdio.h>
310Sstevel@tonic-gate #include <stdlib.h>
320Sstevel@tonic-gate #include <string.h>
330Sstevel@tonic-gate
349698SPeter.Shoults@Sun.COM static OM_uint32
val_init_sec_ctx_args(OM_uint32 * minor_status,gss_ctx_id_t * context_handle,gss_name_t target_name,gss_OID * actual_mech_type,gss_buffer_t output_token)359698SPeter.Shoults@Sun.COM val_init_sec_ctx_args(
369698SPeter.Shoults@Sun.COM OM_uint32 *minor_status,
379698SPeter.Shoults@Sun.COM gss_ctx_id_t *context_handle,
389698SPeter.Shoults@Sun.COM gss_name_t target_name,
399698SPeter.Shoults@Sun.COM gss_OID *actual_mech_type,
409698SPeter.Shoults@Sun.COM gss_buffer_t output_token)
419698SPeter.Shoults@Sun.COM {
429698SPeter.Shoults@Sun.COM
439698SPeter.Shoults@Sun.COM /* Initialize outputs. */
449698SPeter.Shoults@Sun.COM
459698SPeter.Shoults@Sun.COM if (minor_status != NULL)
469698SPeter.Shoults@Sun.COM *minor_status = 0;
479698SPeter.Shoults@Sun.COM
489698SPeter.Shoults@Sun.COM if (actual_mech_type != NULL)
499698SPeter.Shoults@Sun.COM *actual_mech_type = GSS_C_NO_OID;
509698SPeter.Shoults@Sun.COM
519698SPeter.Shoults@Sun.COM if (output_token != GSS_C_NO_BUFFER) {
529698SPeter.Shoults@Sun.COM output_token->length = 0;
539698SPeter.Shoults@Sun.COM output_token->value = NULL;
549698SPeter.Shoults@Sun.COM }
559698SPeter.Shoults@Sun.COM
569698SPeter.Shoults@Sun.COM /* Validate arguments. */
579698SPeter.Shoults@Sun.COM
589698SPeter.Shoults@Sun.COM if (minor_status == NULL)
599698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_WRITE);
609698SPeter.Shoults@Sun.COM
619698SPeter.Shoults@Sun.COM if (context_handle == NULL)
629698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_WRITE | GSS_S_NO_CONTEXT);
639698SPeter.Shoults@Sun.COM
649698SPeter.Shoults@Sun.COM if (target_name == NULL)
659698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
669698SPeter.Shoults@Sun.COM
679698SPeter.Shoults@Sun.COM if (output_token == NULL)
689698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_WRITE);
699698SPeter.Shoults@Sun.COM
709698SPeter.Shoults@Sun.COM return (GSS_S_COMPLETE);
719698SPeter.Shoults@Sun.COM }
729698SPeter.Shoults@Sun.COM
730Sstevel@tonic-gate OM_uint32
gss_init_sec_context(minor_status,claimant_cred_handle,context_handle,target_name,req_mech_type,req_flags,time_req,input_chan_bindings,input_token,actual_mech_type,output_token,ret_flags,time_rec)740Sstevel@tonic-gate gss_init_sec_context(minor_status,
750Sstevel@tonic-gate claimant_cred_handle,
760Sstevel@tonic-gate context_handle,
770Sstevel@tonic-gate target_name,
780Sstevel@tonic-gate req_mech_type,
790Sstevel@tonic-gate req_flags,
800Sstevel@tonic-gate time_req,
810Sstevel@tonic-gate input_chan_bindings,
820Sstevel@tonic-gate input_token,
830Sstevel@tonic-gate actual_mech_type,
840Sstevel@tonic-gate output_token,
850Sstevel@tonic-gate ret_flags,
860Sstevel@tonic-gate time_rec)
870Sstevel@tonic-gate
880Sstevel@tonic-gate OM_uint32 * minor_status;
890Sstevel@tonic-gate const gss_cred_id_t claimant_cred_handle;
900Sstevel@tonic-gate gss_ctx_id_t *context_handle;
910Sstevel@tonic-gate const gss_name_t target_name;
920Sstevel@tonic-gate const gss_OID req_mech_type;
930Sstevel@tonic-gate OM_uint32 req_flags;
940Sstevel@tonic-gate OM_uint32 time_req;
950Sstevel@tonic-gate const gss_channel_bindings_t input_chan_bindings;
960Sstevel@tonic-gate const gss_buffer_t input_token;
970Sstevel@tonic-gate gss_OID * actual_mech_type;
980Sstevel@tonic-gate gss_buffer_t output_token;
990Sstevel@tonic-gate OM_uint32 * ret_flags;
1000Sstevel@tonic-gate OM_uint32 * time_rec;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate OM_uint32 status, temp_minor_status;
1040Sstevel@tonic-gate gss_union_name_t union_name;
1050Sstevel@tonic-gate gss_union_cred_t union_cred;
1060Sstevel@tonic-gate gss_name_t internal_name;
1070Sstevel@tonic-gate gss_union_ctx_id_t union_ctx_id;
1080Sstevel@tonic-gate gss_OID mech_type = GSS_C_NULL_OID;
1090Sstevel@tonic-gate gss_mechanism mech;
1100Sstevel@tonic-gate gss_cred_id_t input_cred_handle;
1110Sstevel@tonic-gate
1129698SPeter.Shoults@Sun.COM status = val_init_sec_ctx_args(minor_status,
1139698SPeter.Shoults@Sun.COM context_handle,
1149698SPeter.Shoults@Sun.COM target_name,
1159698SPeter.Shoults@Sun.COM actual_mech_type,
1169698SPeter.Shoults@Sun.COM output_token);
1179698SPeter.Shoults@Sun.COM if (status != GSS_S_COMPLETE)
1189698SPeter.Shoults@Sun.COM return (status);
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate if (req_mech_type)
1210Sstevel@tonic-gate mech_type = (gss_OID)req_mech_type;
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate union_name = (gss_union_name_t)target_name;
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate /*
1260Sstevel@tonic-gate * obtain the gss mechanism information for the requested
1270Sstevel@tonic-gate * mechanism. If mech_type is NULL, set it to the resultant
1280Sstevel@tonic-gate * mechanism
1290Sstevel@tonic-gate */
1300Sstevel@tonic-gate mech = __gss_get_mechanism(mech_type);
1310Sstevel@tonic-gate if (mech == NULL)
1320Sstevel@tonic-gate return (GSS_S_BAD_MECH);
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate if (mech->gss_init_sec_context == NULL)
1350Sstevel@tonic-gate return (GSS_S_UNAVAILABLE);
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate if (mech_type == GSS_C_NULL_OID)
1380Sstevel@tonic-gate mech_type = &mech->mech_type;
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate /*
1410Sstevel@tonic-gate * If target_name is mechanism_specific, then it must match the
1420Sstevel@tonic-gate * mech_type that we're about to use. Otherwise, do an import on
1430Sstevel@tonic-gate * the external_name form of the target name.
1440Sstevel@tonic-gate */
1450Sstevel@tonic-gate if (union_name->mech_type &&
1460Sstevel@tonic-gate g_OID_equal(union_name->mech_type, mech_type)) {
1470Sstevel@tonic-gate internal_name = union_name->mech_name;
1480Sstevel@tonic-gate } else {
1490Sstevel@tonic-gate if ((status = __gss_import_internal_name(minor_status,
1500Sstevel@tonic-gate mech_type, union_name,
1510Sstevel@tonic-gate &internal_name)) != GSS_S_COMPLETE)
1520Sstevel@tonic-gate return (status);
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate /*
1560Sstevel@tonic-gate * if context_handle is GSS_C_NO_CONTEXT, allocate a union context
1570Sstevel@tonic-gate * descriptor to hold the mech type information as well as the
1580Sstevel@tonic-gate * underlying mechanism context handle. Otherwise, cast the
1590Sstevel@tonic-gate * value of *context_handle to the union context variable.
1600Sstevel@tonic-gate */
1610Sstevel@tonic-gate if (*context_handle == GSS_C_NO_CONTEXT) {
1620Sstevel@tonic-gate status = GSS_S_FAILURE;
1630Sstevel@tonic-gate union_ctx_id = (gss_union_ctx_id_t)
1640Sstevel@tonic-gate malloc(sizeof (gss_union_ctx_id_desc));
1650Sstevel@tonic-gate if (union_ctx_id == NULL)
1660Sstevel@tonic-gate goto end;
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate if (generic_gss_copy_oid(&temp_minor_status, mech_type,
1690Sstevel@tonic-gate &union_ctx_id->mech_type) != GSS_S_COMPLETE) {
1700Sstevel@tonic-gate free(union_ctx_id);
1710Sstevel@tonic-gate goto end;
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate /* copy the supplied context handle */
1750Sstevel@tonic-gate union_ctx_id->internal_ctx_id = *context_handle;
1760Sstevel@tonic-gate } else
1770Sstevel@tonic-gate union_ctx_id = (gss_union_ctx_id_t)*context_handle;
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate /*
1800Sstevel@tonic-gate * get the appropriate cred handle from the union cred struct.
1810Sstevel@tonic-gate * defaults to GSS_C_NO_CREDENTIAL if there is no cred, which will
1820Sstevel@tonic-gate * use the default credential.
1830Sstevel@tonic-gate */
1840Sstevel@tonic-gate union_cred = (gss_union_cred_t)claimant_cred_handle;
1850Sstevel@tonic-gate input_cred_handle = __gss_get_mechanism_cred(union_cred, mech_type);
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate /*
1880Sstevel@tonic-gate * now call the approprate underlying mechanism routine
1890Sstevel@tonic-gate */
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate status = mech->gss_init_sec_context(
1920Sstevel@tonic-gate mech->context,
1930Sstevel@tonic-gate minor_status,
1940Sstevel@tonic-gate input_cred_handle,
1950Sstevel@tonic-gate &union_ctx_id->internal_ctx_id,
1960Sstevel@tonic-gate internal_name,
1970Sstevel@tonic-gate mech_type,
1980Sstevel@tonic-gate req_flags,
1990Sstevel@tonic-gate time_req,
2000Sstevel@tonic-gate input_chan_bindings,
2010Sstevel@tonic-gate input_token,
2020Sstevel@tonic-gate actual_mech_type,
2030Sstevel@tonic-gate output_token,
2040Sstevel@tonic-gate ret_flags,
2050Sstevel@tonic-gate time_rec);
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate if (status != GSS_S_COMPLETE && status != GSS_S_CONTINUE_NEEDED) {
2080Sstevel@tonic-gate /*
2090Sstevel@tonic-gate * the spec says (the preferred) method is to delete all
2100Sstevel@tonic-gate * context info on the first call to init, and on all
2110Sstevel@tonic-gate * subsequent calls make the caller responsible for
2120Sstevel@tonic-gate * calling gss_delete_sec_context
2130Sstevel@tonic-gate */
214*13132SGlenn.Barry@oracle.com map_error(minor_status, mech);
2150Sstevel@tonic-gate if (*context_handle == GSS_C_NO_CONTEXT) {
2160Sstevel@tonic-gate free(union_ctx_id->mech_type->elements);
2170Sstevel@tonic-gate free(union_ctx_id->mech_type);
2180Sstevel@tonic-gate free(union_ctx_id);
2190Sstevel@tonic-gate }
2200Sstevel@tonic-gate } else if (*context_handle == GSS_C_NO_CONTEXT)
2210Sstevel@tonic-gate *context_handle = (gss_ctx_id_t)union_ctx_id;
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate end:
2240Sstevel@tonic-gate if (union_name->mech_name == NULL ||
2250Sstevel@tonic-gate union_name->mech_name != internal_name) {
2260Sstevel@tonic-gate (void) __gss_release_internal_name(&temp_minor_status,
2270Sstevel@tonic-gate mech_type, &internal_name);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate return (status);
2310Sstevel@tonic-gate }
232