|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
fd8b60 |
* Use is subject to license terms.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* #pragma ident "@(#)g_canon_name.c 1.15 04/02/23 SMI" */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* routine gss_canonicalize_name
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* This routine is used to produce a mechanism specific
|
|
Packit |
fd8b60 |
* representation of name that has been previously
|
|
Packit |
fd8b60 |
* imported with gss_import_name. The routine uses the mechanism
|
|
Packit |
fd8b60 |
* specific implementation of gss_import_name to implement this
|
|
Packit |
fd8b60 |
* function.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* We allow a NULL output_name, in which case we modify the
|
|
Packit |
fd8b60 |
* input_name to include the mechanism specific name.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include <mglueP.h>
|
|
Packit |
fd8b60 |
#ifdef HAVE_STDLIB_H
|
|
Packit |
fd8b60 |
#include <stdlib.h>
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#include <string.h>
|
|
Packit |
fd8b60 |
#include <errno.h>
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static OM_uint32
|
|
Packit |
fd8b60 |
val_canon_name_args(
|
|
Packit |
fd8b60 |
OM_uint32 *minor_status,
|
|
Packit |
fd8b60 |
const gss_name_t input_name,
|
|
Packit |
fd8b60 |
const gss_OID mech_type,
|
|
Packit |
fd8b60 |
gss_name_t *output_name)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Initialize outputs. */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (minor_status != NULL)
|
|
Packit |
fd8b60 |
*minor_status = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (output_name != NULL)
|
|
Packit |
fd8b60 |
*output_name = GSS_C_NO_NAME;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Validate arguments. */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (minor_status == NULL)
|
|
Packit |
fd8b60 |
return (GSS_S_CALL_INACCESSIBLE_WRITE);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (input_name == GSS_C_NO_NAME || mech_type == GSS_C_NULL_OID)
|
|
Packit |
fd8b60 |
return (GSS_S_CALL_INACCESSIBLE_READ);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return (GSS_S_COMPLETE);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
OM_uint32 KRB5_CALLCONV
|
|
Packit |
fd8b60 |
gss_canonicalize_name(minor_status,
|
|
Packit |
fd8b60 |
input_name,
|
|
Packit |
fd8b60 |
mech_type,
|
|
Packit |
fd8b60 |
output_name)
|
|
Packit |
fd8b60 |
OM_uint32 *minor_status;
|
|
Packit |
fd8b60 |
const gss_name_t input_name;
|
|
Packit |
fd8b60 |
const gss_OID mech_type;
|
|
Packit |
fd8b60 |
gss_name_t *output_name;
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
gss_union_name_t in_union, out_union = NULL, dest_union = NULL;
|
|
Packit |
fd8b60 |
OM_uint32 major_status = GSS_S_FAILURE, tmpmin;
|
|
Packit |
fd8b60 |
gss_OID selected_mech;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
major_status = val_canon_name_args(minor_status,
|
|
Packit |
fd8b60 |
input_name,
|
|
Packit |
fd8b60 |
mech_type,
|
|
Packit |
fd8b60 |
output_name);
|
|
Packit |
fd8b60 |
if (major_status != GSS_S_COMPLETE)
|
|
Packit |
fd8b60 |
return (major_status);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
major_status = gssint_select_mech_type(minor_status, mech_type,
|
|
Packit |
fd8b60 |
&selected_mech);
|
|
Packit |
fd8b60 |
if (major_status != GSS_S_COMPLETE)
|
|
Packit |
fd8b60 |
return (major_status);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Initial value needed below. */
|
|
Packit |
fd8b60 |
major_status = GSS_S_FAILURE;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
in_union = (gss_union_name_t)input_name;
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* If the caller wants to reuse the name, and the name has already
|
|
Packit |
fd8b60 |
* been converted, then there is nothing for us to do.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
if (!output_name && in_union->mech_type &&
|
|
Packit |
fd8b60 |
g_OID_equal(in_union->mech_type, selected_mech))
|
|
Packit |
fd8b60 |
return (GSS_S_COMPLETE);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ok, then we need to do something - start by creating data struct */
|
|
Packit |
fd8b60 |
if (output_name) {
|
|
Packit |
fd8b60 |
out_union =
|
|
Packit |
fd8b60 |
(gss_union_name_t)malloc(sizeof (gss_union_name_desc));
|
|
Packit |
fd8b60 |
if (!out_union)
|
|
Packit |
fd8b60 |
goto allocation_failure;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
out_union->mech_type = 0;
|
|
Packit |
fd8b60 |
out_union->mech_name = 0;
|
|
Packit |
fd8b60 |
out_union->name_type = 0;
|
|
Packit |
fd8b60 |
out_union->external_name = 0;
|
|
Packit |
fd8b60 |
out_union->loopback = out_union;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Allocate the buffer for the user specified representation */
|
|
Packit |
fd8b60 |
if (gssint_create_copy_buffer(in_union->external_name,
|
|
Packit |
fd8b60 |
&out_union->external_name, 1))
|
|
Packit |
fd8b60 |
goto allocation_failure;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (in_union->name_type != GSS_C_NULL_OID) {
|
|
Packit |
fd8b60 |
major_status = generic_gss_copy_oid(minor_status,
|
|
Packit |
fd8b60 |
in_union->name_type,
|
|
Packit |
fd8b60 |
&out_union->name_type);
|
|
Packit |
fd8b60 |
if (major_status) {
|
|
Packit |
fd8b60 |
map_errcode(minor_status);
|
|
Packit |
fd8b60 |
goto allocation_failure;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* might need to delete any old mechanism names if we are
|
|
Packit |
fd8b60 |
* reusing the buffer.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
if (!output_name) {
|
|
Packit |
fd8b60 |
if (in_union->mech_type) {
|
|
Packit |
fd8b60 |
(void) gssint_release_internal_name(minor_status,
|
|
Packit |
fd8b60 |
in_union->mech_type,
|
|
Packit |
fd8b60 |
&in_union->mech_name);
|
|
Packit |
fd8b60 |
(void) gss_release_oid(minor_status,
|
|
Packit |
fd8b60 |
&in_union->mech_type);
|
|
Packit |
fd8b60 |
in_union->mech_type = 0;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
dest_union = in_union;
|
|
Packit |
fd8b60 |
} else
|
|
Packit |
fd8b60 |
dest_union = out_union;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* now let's create the new mech name */
|
|
Packit |
fd8b60 |
if ((major_status = generic_gss_copy_oid(minor_status, selected_mech,
|
|
Packit |
fd8b60 |
&dest_union->mech_type))) {
|
|
Packit |
fd8b60 |
map_errcode(minor_status);
|
|
Packit |
fd8b60 |
goto allocation_failure;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if ((major_status =
|
|
Packit |
fd8b60 |
gssint_import_internal_name(minor_status, selected_mech,
|
|
Packit |
fd8b60 |
in_union,
|
|
Packit |
fd8b60 |
&dest_union->mech_name)))
|
|
Packit |
fd8b60 |
goto allocation_failure;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (output_name)
|
|
Packit |
fd8b60 |
*output_name = (gss_name_t)dest_union;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return (GSS_S_COMPLETE);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
allocation_failure:
|
|
Packit |
fd8b60 |
if (out_union) {
|
|
Packit |
fd8b60 |
/* Release the partly constructed out_union. */
|
|
Packit |
fd8b60 |
gss_name_t name = (gss_name_t)out_union;
|
|
Packit |
fd8b60 |
(void) gss_release_name(&tmpmin, &name);
|
|
Packit |
fd8b60 |
} else if (!output_name) {
|
|
Packit |
fd8b60 |
/* Release only the mech name fields in in_union. */
|
|
Packit |
fd8b60 |
if (in_union->mech_name) {
|
|
Packit |
fd8b60 |
(void) gssint_release_internal_name(&tmpmin,
|
|
Packit |
fd8b60 |
dest_union->mech_type,
|
|
Packit |
fd8b60 |
&dest_union->mech_name);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
if (in_union->mech_type)
|
|
Packit |
fd8b60 |
(void) gss_release_oid(&tmpmin, &dest_union->mech_type);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return (major_status);
|
|
Packit |
fd8b60 |
} /********** gss_canonicalize_name ********/
|