#include "mglueP.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <errno.h>
OM_uint32 KRB5_CALLCONV
gss_import_name(minor_status,
input_name_buffer,
input_name_type,
output_name)
OM_uint32 * minor_status;
gss_buffer_t input_name_buffer;
gss_OID input_name_type;
gss_name_t * output_name;
{
gss_union_name_t union_name;
OM_uint32 tmp, major_status = GSS_S_FAILURE;
gss_OID mech;
gss_initialize();
if (minor_status)
*minor_status = 0;
if(output_name == NULL)
return (GSS_S_COMPLETE);
*output_name = 0;
if (input_name_buffer == GSS_C_NO_BUFFER)
return (GSS_S_BAD_NAME);
union_name = (gss_union_name_t) malloc (sizeof(gss_union_name_desc));
if (!union_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_name->mech_type = 0;
union_name->mech_name = 0;
union_name->name_type = 0;
union_name->external_name = 0;
union_name->external_name =
(gss_buffer_t) malloc(sizeof(gss_buffer_desc));
if (!union_name->external_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_name->external_name->length = input_name_buffer->length;
union_name->external_name->value =
(void *) malloc(input_name_buffer->length+1);
if (!union_name->external_name->value) {
*minor_status = ENOMEM;
goto allocation_failure;
}
memcpy(union_name->external_name->value, input_name_buffer->value,
input_name_buffer->length);
((char *)union_name->external_name->value)
[input_name_buffer->length] = '\0';
major_status = generic_gss_copy_oid(minor_status, input_name_type,
&union_name->name_type);
if (major_status != GSS_S_COMPLETE)
goto allocation_failure;
mech = gss_find_mechanism_from_name_type(input_name_type);
if (mech) {
major_status = generic_gss_copy_oid(minor_status, mech,
&union_name->mech_type);
if (major_status != GSS_S_COMPLETE)
goto allocation_failure;
major_status = __gss_import_internal_name(minor_status, mech,
union_name,
&union_name->mech_name);
if (major_status)
goto allocation_failure;
}
*output_name = (gss_name_t) union_name;
return(GSS_S_COMPLETE);
allocation_failure:
if (union_name) {
if (union_name->external_name) {
if (union_name->external_name->value)
free(union_name->external_name->value);
free(union_name->external_name);
}
if (union_name->name_type)
generic_gss_release_oid(&tmp, &union_name->name_type);
if (union_name->mech_name)
__gss_release_internal_name(minor_status, union_name->mech_type,
&union_name->mech_name);
if (union_name->mech_type)
generic_gss_release_oid(&tmp, &union_name->mech_type);
free(union_name);
}
return (major_status);
}