Home | History | Annotate | Download | only in libgss
      1     0  stevel /*
      2     0  stevel  * CDDL HEADER START
      3     0  stevel  *
      4     0  stevel  * The contents of this file are subject to the terms of the
      5  5053     gtb  * Common Development and Distribution License (the "License").
      6  5053     gtb  * You may not use this file except in compliance with the License.
      7     0  stevel  *
      8     0  stevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9     0  stevel  * or http://www.opensolaris.org/os/licensing.
     10     0  stevel  * See the License for the specific language governing permissions
     11     0  stevel  * and limitations under the License.
     12     0  stevel  *
     13     0  stevel  * When distributing Covered Code, include this CDDL HEADER in each
     14     0  stevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15     0  stevel  * If applicable, add the following below this CDDL HEADER, with the
     16     0  stevel  * fields enclosed by brackets "[]" replaced with your own identifying
     17     0  stevel  * information: Portions Copyright [yyyy] [name of copyright owner]
     18     0  stevel  *
     19     0  stevel  * CDDL HEADER END
     20     0  stevel  */
     21     0  stevel /*
     22  9698   Peter  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23     0  stevel  * Use is subject to license terms.
     24     0  stevel  */
     25     0  stevel 
     26     0  stevel /*
     27     0  stevel  * routine gss_canonicalize_name
     28     0  stevel  *
     29     0  stevel  * This routine is used to produce a mechanism specific
     30     0  stevel  * representation of name that has been previously
     31     0  stevel  * imported with gss_import_name.  The routine uses the mechanism
     32     0  stevel  * specific implementation of gss_import_name to implement this
     33     0  stevel  * function.
     34     0  stevel  *
     35     0  stevel  * We allow a NULL output_name, in which case we modify the
     36     0  stevel  * input_name to include the mechanism specific name.
     37     0  stevel  */
     38     0  stevel 
     39     0  stevel #include <mechglueP.h>
     40     0  stevel #ifdef HAVE_STDLIB_H
     41     0  stevel #include <stdlib.h>
     42     0  stevel #endif
     43     0  stevel #include <string.h>
     44     0  stevel #include <errno.h>
     45     0  stevel 
     46  9698   Peter static OM_uint32 val_canon_name_args(
     47  9698   Peter 	OM_uint32 *minor_status,
     48  9698   Peter 	const gss_name_t input_name,
     49  9698   Peter 	const gss_OID mech_type,
     50  9698   Peter 	gss_name_t *output_name)
     51  9698   Peter {
     52  9698   Peter 
     53  9698   Peter 	/* Initialize outputs. */
     54  9698   Peter 
     55  9698   Peter 	if (minor_status != NULL)
     56  9698   Peter 		*minor_status = 0;
     57  9698   Peter 
     58  9698   Peter 	if (output_name != NULL)
     59  9698   Peter 		*output_name = GSS_C_NO_NAME;
     60  9698   Peter 
     61  9698   Peter 	/* Validate arguments. */
     62  9698   Peter 
     63  9698   Peter 	if (minor_status == NULL)
     64  9698   Peter 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
     65  9698   Peter 
     66  9698   Peter 	if (input_name == GSS_C_NO_NAME || mech_type == GSS_C_NULL_OID)
     67  9698   Peter 		return (GSS_S_CALL_INACCESSIBLE_READ);
     68  9698   Peter 
     69  9698   Peter 	return (GSS_S_COMPLETE);
     70  9698   Peter }
     71  9698   Peter 
     72     0  stevel OM_uint32
     73     0  stevel gss_canonicalize_name(minor_status,
     74     0  stevel 				input_name,
     75     0  stevel 				mech_type,
     76     0  stevel 				output_name)
     77     0  stevel OM_uint32 *minor_status;
     78     0  stevel const gss_name_t input_name;
     79     0  stevel const gss_OID mech_type;
     80     0  stevel gss_name_t *output_name;
     81     0  stevel {
     82     0  stevel 	gss_union_name_t in_union, out_union = NULL, dest_union = NULL;
     83     0  stevel 	OM_uint32 major_status = GSS_S_FAILURE;
     84     0  stevel 
     85  9698   Peter 	major_status = val_canon_name_args(minor_status,
     86  9698   Peter 					input_name,
     87  9698   Peter 					mech_type,
     88  9698   Peter 					output_name);
     89  9698   Peter 	if (major_status != GSS_S_COMPLETE)
     90  9698   Peter 		return (major_status);
     91     0  stevel 
     92  9698   Peter 	/* Initial value needed below. */
     93  9698   Peter 	major_status = GSS_S_FAILURE;
     94     0  stevel 
     95     0  stevel 	in_union = (gss_union_name_t)input_name;
     96     0  stevel 	/*
     97     0  stevel 	 * If the caller wants to reuse the name, and the name has already
     98     0  stevel 	 * been converted, then there is nothing for us to do.
     99     0  stevel 	 */
    100     0  stevel 	if (!output_name && in_union->mech_type &&
    101     0  stevel 		g_OID_equal(in_union->mech_type, mech_type))
    102     0  stevel 		return (GSS_S_COMPLETE);
    103     0  stevel 
    104     0  stevel 	/* ok, then we need to do something - start by creating data struct */
    105     0  stevel 	if (output_name) {
    106     0  stevel 		out_union =
    107     0  stevel 			(gss_union_name_t)malloc(sizeof (gss_union_name_desc));
    108     0  stevel 		if (!out_union)
    109     0  stevel 			goto allocation_failure;
    110     0  stevel 
    111     0  stevel 		out_union->mech_type = 0;
    112     0  stevel 		out_union->mech_name = 0;
    113     0  stevel 		out_union->name_type = 0;
    114     0  stevel 		out_union->external_name = 0;
    115     0  stevel 
    116     0  stevel 		/* Allocate the buffer for the user specified representation */
    117  5053     gtb 		if (gssint_create_copy_buffer(in_union->external_name,
    118     0  stevel 				&out_union->external_name, 1))
    119     0  stevel 			goto allocation_failure;
    120     0  stevel 
    121     0  stevel 		if (in_union->name_type != GSS_C_NULL_OID) {
    122     0  stevel 			if ((major_status = generic_gss_copy_oid(minor_status,
    123     0  stevel 				in_union->name_type, &out_union->name_type)))
    124     0  stevel 			goto allocation_failure;
    125     0  stevel 		}
    126     0  stevel 
    127     0  stevel 	}
    128     0  stevel 
    129     0  stevel 	/*
    130     0  stevel 	 * might need to delete any old mechanism names if we are
    131     0  stevel 	 * reusing the buffer.
    132     0  stevel 	 */
    133     0  stevel 	if (!output_name) {
    134     0  stevel 		if (in_union->mech_type) {
    135     0  stevel 			(void) __gss_release_internal_name(minor_status,
    136     0  stevel 							in_union->mech_type,
    137     0  stevel 							&in_union->mech_name);
    138     0  stevel 			(void) gss_release_oid(minor_status,
    139     0  stevel 					    &in_union->mech_type);
    140     0  stevel 			in_union->mech_type = 0;
    141     0  stevel 		}
    142     0  stevel 		dest_union = in_union;
    143     0  stevel 	} else
    144     0  stevel 		dest_union = out_union;
    145     0  stevel 
    146     0  stevel 	/* now let's create the new mech name */
    147     0  stevel 	if (major_status = generic_gss_copy_oid(minor_status, mech_type,
    148     0  stevel 						&dest_union->mech_type))
    149     0  stevel 		goto allocation_failure;
    150     0  stevel 
    151     0  stevel 	if (major_status =
    152     0  stevel 		__gss_import_internal_name(minor_status, mech_type,
    153     0  stevel 						dest_union,
    154     0  stevel 						&dest_union->mech_name))
    155     0  stevel 		goto allocation_failure;
    156     0  stevel 
    157     0  stevel 	if (output_name)
    158     0  stevel 		*output_name = (gss_name_t)dest_union;
    159     0  stevel 
    160     0  stevel 	return (GSS_S_COMPLETE);
    161     0  stevel 
    162     0  stevel allocation_failure:
    163     0  stevel 	/* do not delete the src name external name format */
    164     0  stevel 	if (output_name) {
    165     0  stevel 		if (out_union->external_name) {
    166     0  stevel 			if (out_union->external_name->value)
    167     0  stevel 				free(out_union->external_name->value);
    168     0  stevel 			free(out_union->external_name);
    169     0  stevel 		}
    170     0  stevel 		if (out_union->name_type)
    171     0  stevel 			(void) gss_release_oid(minor_status,
    172     0  stevel 					    &out_union->name_type);
    173     0  stevel 
    174     0  stevel 		dest_union = out_union;
    175     0  stevel 	} else
    176     0  stevel 		dest_union = in_union;
    177     0  stevel 
    178     0  stevel 	/*
    179     0  stevel 	 * delete the partially created mech specific name
    180     0  stevel 	 * applies for both src and dest which ever is being used for output
    181     0  stevel 	 */
    182     0  stevel 
    183     0  stevel 	if (dest_union->mech_name) {
    184     0  stevel 		(void) __gss_release_internal_name(minor_status,
    185     0  stevel 						dest_union->mech_type,
    186     0  stevel 						&dest_union->mech_name);
    187     0  stevel 	}
    188     0  stevel 
    189     0  stevel 	if (dest_union->mech_type)
    190     0  stevel 		(void) gss_release_oid(minor_status, &dest_union->mech_type);
    191     0  stevel 
    192     0  stevel 
    193     0  stevel 	if (output_name)
    194     0  stevel 		free(out_union);
    195     0  stevel 
    196     0  stevel 	return (major_status);
    197     0  stevel } /**********  gss_canonicalize_name ********/
    198