2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * glue routine for gss_init_sec_context
2N/A */
2N/A#include <mglueP.h>
2N/A#include "gssapiP_generic.h"
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A
2N/Astatic OM_uint32
2N/Aval_init_sec_ctx_args(
2N/A OM_uint32 *minor_status,
2N/A gss_ctx_id_t *context_handle,
2N/A gss_name_t target_name,
2N/A gss_OID *actual_mech_type,
2N/A gss_buffer_t output_token)
2N/A{
2N/A
2N/A /* Initialize outputs. */
2N/A
2N/A if (minor_status != NULL)
2N/A *minor_status = 0;
2N/A
2N/A if (actual_mech_type != NULL)
2N/A *actual_mech_type = GSS_C_NO_OID;
2N/A
2N/A if (output_token != GSS_C_NO_BUFFER) {
2N/A output_token->length = 0;
2N/A output_token->value = NULL;
2N/A }
2N/A
2N/A /* Validate arguments. */
2N/A
2N/A if (minor_status == NULL)
2N/A return (GSS_S_CALL_INACCESSIBLE_WRITE);
2N/A
2N/A if (context_handle == NULL)
2N/A return (GSS_S_CALL_INACCESSIBLE_WRITE | GSS_S_NO_CONTEXT);
2N/A
2N/A if (target_name == NULL)
2N/A return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
2N/A
2N/A if (output_token == NULL)
2N/A return (GSS_S_CALL_INACCESSIBLE_WRITE);
2N/A
2N/A return (GSS_S_COMPLETE);
2N/A}
2N/A
2N/AOM_uint32
2N/Agss_init_sec_context(minor_status,
2N/A claimant_cred_handle,
2N/A context_handle,
2N/A target_name,
2N/A req_mech_type,
2N/A req_flags,
2N/A time_req,
2N/A input_chan_bindings,
2N/A input_token,
2N/A actual_mech_type,
2N/A output_token,
2N/A ret_flags,
2N/A time_rec)
2N/A
2N/AOM_uint32 * minor_status;
2N/Aconst gss_cred_id_t claimant_cred_handle;
2N/Agss_ctx_id_t *context_handle;
2N/Aconst gss_name_t target_name;
2N/Aconst gss_OID req_mech_type;
2N/AOM_uint32 req_flags;
2N/AOM_uint32 time_req;
2N/Aconst gss_channel_bindings_t input_chan_bindings;
2N/Aconst gss_buffer_t input_token;
2N/Agss_OID * actual_mech_type;
2N/Agss_buffer_t output_token;
2N/AOM_uint32 * ret_flags;
2N/AOM_uint32 * time_rec;
2N/A
2N/A{
2N/A OM_uint32 status, temp_minor_status;
2N/A gss_union_name_t union_name;
2N/A gss_union_cred_t union_cred;
2N/A gss_name_t internal_name;
2N/A gss_union_ctx_id_t union_ctx_id;
2N/A gss_OID mech_type = GSS_C_NULL_OID;
2N/A gss_mechanism mech;
2N/A gss_cred_id_t input_cred_handle;
2N/A
2N/A status = val_init_sec_ctx_args(minor_status,
2N/A context_handle,
2N/A target_name,
2N/A actual_mech_type,
2N/A output_token);
2N/A if (status != GSS_S_COMPLETE)
2N/A return (status);
2N/A
2N/A if (req_mech_type)
2N/A mech_type = (gss_OID)req_mech_type;
2N/A
2N/A union_name = (gss_union_name_t)target_name;
2N/A
2N/A /*
2N/A * obtain the gss mechanism information for the requested
2N/A * mechanism. If mech_type is NULL, set it to the resultant
2N/A * mechanism
2N/A */
2N/A mech = __gss_get_mechanism(mech_type);
2N/A if (mech == NULL)
2N/A return (GSS_S_BAD_MECH);
2N/A
2N/A if (mech->gss_init_sec_context == NULL)
2N/A return (GSS_S_UNAVAILABLE);
2N/A
2N/A if (mech_type == GSS_C_NULL_OID)
2N/A mech_type = &mech->mech_type;
2N/A
2N/A /*
2N/A * If target_name is mechanism_specific, then it must match the
2N/A * mech_type that we're about to use. Otherwise, do an import on
2N/A * the external_name form of the target name.
2N/A */
2N/A if (union_name->mech_type &&
2N/A g_OID_equal(union_name->mech_type, mech_type)) {
2N/A internal_name = union_name->mech_name;
2N/A } else {
2N/A if ((status = __gss_import_internal_name(minor_status,
2N/A mech_type, union_name,
2N/A &internal_name)) != GSS_S_COMPLETE)
2N/A return (status);
2N/A }
2N/A
2N/A /*
2N/A * if context_handle is GSS_C_NO_CONTEXT, allocate a union context
2N/A * descriptor to hold the mech type information as well as the
2N/A * underlying mechanism context handle. Otherwise, cast the
2N/A * value of *context_handle to the union context variable.
2N/A */
2N/A if (*context_handle == GSS_C_NO_CONTEXT) {
2N/A status = GSS_S_FAILURE;
2N/A union_ctx_id = (gss_union_ctx_id_t)
2N/A malloc(sizeof (gss_union_ctx_id_desc));
2N/A if (union_ctx_id == NULL)
2N/A goto end;
2N/A
2N/A if (generic_gss_copy_oid(&temp_minor_status, mech_type,
2N/A &union_ctx_id->mech_type) != GSS_S_COMPLETE) {
2N/A free(union_ctx_id);
2N/A goto end;
2N/A }
2N/A
2N/A /* copy the supplied context handle */
2N/A union_ctx_id->internal_ctx_id = *context_handle;
2N/A } else
2N/A union_ctx_id = (gss_union_ctx_id_t)*context_handle;
2N/A
2N/A /*
2N/A * get the appropriate cred handle from the union cred struct.
2N/A * defaults to GSS_C_NO_CREDENTIAL if there is no cred, which will
2N/A * use the default credential.
2N/A */
2N/A union_cred = (gss_union_cred_t)claimant_cred_handle;
2N/A input_cred_handle = __gss_get_mechanism_cred(union_cred, mech_type);
2N/A
2N/A /*
2N/A * now call the approprate underlying mechanism routine
2N/A */
2N/A
2N/A status = mech->gss_init_sec_context(
2N/A minor_status,
2N/A input_cred_handle,
2N/A &union_ctx_id->internal_ctx_id,
2N/A internal_name,
2N/A mech_type,
2N/A req_flags,
2N/A time_req,
2N/A input_chan_bindings,
2N/A input_token,
2N/A actual_mech_type,
2N/A output_token,
2N/A ret_flags,
2N/A time_rec);
2N/A
2N/A if (status != GSS_S_COMPLETE && status != GSS_S_CONTINUE_NEEDED) {
2N/A /*
2N/A * the spec says (the preferred) method is to delete all
2N/A * context info on the first call to init, and on all
2N/A * subsequent calls make the caller responsible for
2N/A * calling gss_delete_sec_context
2N/A */
2N/A map_error(minor_status, mech);
2N/A if (*context_handle == GSS_C_NO_CONTEXT) {
2N/A free(union_ctx_id->mech_type->elements);
2N/A free(union_ctx_id->mech_type);
2N/A free(union_ctx_id);
2N/A }
2N/A } else if (*context_handle == GSS_C_NO_CONTEXT) {
2N/A union_ctx_id->loopback = union_ctx_id;
2N/A *context_handle = (gss_ctx_id_t)union_ctx_id;
2N/A }
2N/A
2N/Aend:
2N/A if (union_name->mech_name == NULL ||
2N/A union_name->mech_name != internal_name) {
2N/A (void) __gss_release_internal_name(&temp_minor_status,
2N/A mech_type, &internal_name);
2N/A }
2N/A
2N/A return (status);
2N/A}