Home | History | Annotate | Download | only in gssapi
      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, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 /*
     30  *  glue routine gss_import_name
     31  *
     32  */
     33 
     34 #include "mechglueP.h"
     35 #include <sys/errno.h>
     36 OM_uint32
     37 gss_import_name(
     38 	OM_uint32 *minor_status,
     39 	const gss_buffer_t input_name_buffer,
     40 	const gss_OID input_name_type,
     41 	gss_name_t *output_name)
     42 
     43 {
     44 	gss_union_name_t	union_name;
     45 	OM_uint32		major_status = GSS_S_FAILURE;
     46 
     47 	if (minor_status)
     48 		*minor_status = 0;
     49 
     50 	/* if output_name is NULL, simply return */
     51 
     52 	if (output_name == NULL)
     53 		return (GSS_S_COMPLETE);
     54 
     55 	*output_name = 0;
     56 
     57 	if (input_name_buffer == GSS_C_NO_BUFFER || input_name_type == NULL)
     58 		return (GSS_S_BAD_NAME);
     59 
     60 	/*
     61 	 * First create the union name struct that will hold the external
     62 	 * name and the name type.
     63 	 */
     64 
     65 	union_name = (gss_union_name_t) MALLOC(sizeof (gss_union_name_desc));
     66 
     67 	if (!union_name) {
     68 		*minor_status = ENOMEM;
     69 		goto allocation_failure;
     70 	}
     71 	union_name->mech_type = 0;
     72 	union_name->mech_name = 0;
     73 	union_name->name_type = 0;
     74 	union_name->external_name = 0;
     75 
     76 	/*
     77 	 * All we do here is record the external name and name_type.
     78 	 * When the name is actually used, the underlying gss_import_name()
     79 	 * is called for the appropriate mechanism.
     80 	 * Since the name type may be a constant or comming from the
     81 	 * rpc resoults, we must make a copy.
     82 	 */
     83 	union_name->external_name =
     84 	(gss_buffer_t) MALLOC(sizeof (gss_buffer_desc));
     85 
     86 	if (!union_name->external_name) {
     87 		*minor_status = ENOMEM;
     88 		goto allocation_failure;
     89 	}
     90 
     91 	union_name->external_name->length = input_name_buffer->length;
     92 	union_name->external_name->value =
     93 	(void *) MALLOC(input_name_buffer->length);
     94 
     95 	if (!union_name->external_name->value) {
     96 		*minor_status = ENOMEM;
     97 		goto allocation_failure;
     98 	}
     99 
    100 	(void) memcpy(union_name->external_name->value,
    101 	    input_name_buffer->value, input_name_buffer->length);
    102 
    103 	/*
    104 	 * making a copy of the name_type structure and elements
    105 	 * we now delete it when calling gss_release_name
    106 	 */
    107 	union_name->name_type = (gss_OID) MALLOC(sizeof (gss_OID_desc));
    108 
    109 	if (!union_name->name_type) {
    110 		*minor_status = ENOMEM;
    111 		goto allocation_failure;
    112 	}
    113 
    114 	union_name->name_type->elements = (void *)
    115 		MALLOC(input_name_type->length);
    116 
    117 	if (!union_name->name_type->elements) {
    118 		*minor_status = ENOMEM;
    119 		goto allocation_failure;
    120 	}
    121 
    122 	(void) memcpy(union_name->name_type->elements,
    123 		input_name_type->elements, input_name_type->length);
    124 	union_name->name_type->length = input_name_type->length;
    125 
    126 	*output_name = (gss_name_t) union_name;
    127 
    128 	return (GSS_S_COMPLETE);
    129 
    130 allocation_failure:
    131 	if (union_name) {
    132 
    133 		if (union_name->external_name) {
    134 			if (union_name->external_name->value)
    135 				FREE(union_name->external_name->value,
    136 					union_name->external_name->length);
    137 			FREE(union_name->external_name,
    138 				sizeof (gss_buffer_desc));
    139 		}
    140 
    141 		if (union_name->name_type) {
    142 			FREE(union_name->name_type, sizeof (gss_OID_desc));
    143 		}
    144 		FREE(union_name, sizeof (gss_union_name_desc));
    145 	}
    146 	return (major_status);
    147 }
    148