158314Sache/*-
221308Sache * Copyright (c) 2005 Doug Rabson
321308Sache * All rights reserved.
4165675Sache *
521308Sache * Redistribution and use in source and binary forms, with or without
621308Sache * modification, are permitted provided that the following conditions
721308Sache * are met:
821308Sache * 1. Redistributions of source code must retain the above copyright
921308Sache *    notice, this list of conditions and the following disclaimer.
1021308Sache * 2. Redistributions in binary form must reproduce the above copyright
1158314Sache *    notice, this list of conditions and the following disclaimer in the
1221308Sache *    documentation and/or other materials provided with the distribution.
1321308Sache *
1421308Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1521308Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1621308Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1721308Sache * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1821308Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1921308Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2021308Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2121308Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2258314Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2321308Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2421308Sache * SUCH DAMAGE.
2521308Sache *
2621308Sache *	$FreeBSD: src/lib/libgssapi/gss_display_name.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
2721308Sache */
2821308Sache
2921308Sache#include "mech_locl.h"
3021308Sache
3121308SacheGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
3221308Sachegss_display_name(OM_uint32 *minor_status,
3321308Sache    const gss_name_t input_name,
3421308Sache    gss_buffer_t output_name_buffer,
3526497Sache    gss_OID *output_name_type)
3626497Sache{
3721308Sache	OM_uint32 major_status;
3821308Sache	struct _gss_name *name = (struct _gss_name *) input_name;
3921308Sache	struct _gss_mechanism_name *mn;
4021308Sache
4121308Sache	_mg_buffer_zero(output_name_buffer);
4221308Sache	if (output_name_type)
4326497Sache	    *output_name_type = GSS_C_NO_OID;
4421308Sache
4521308Sache	if (name == NULL) {
4621308Sache		*minor_status = 0;
47119614Sache		return (GSS_S_BAD_NAME);
4821308Sache	}
4921308Sache
5021308Sache	/*
5121308Sache	 * If we know it, copy the buffer used to import the name in
5221308Sache	 * the first place. Otherwise, ask all the MNs in turn if
5321308Sache	 * they can display the thing.
5421308Sache	 */
5521308Sache	if (name->gn_value.value) {
5658314Sache		output_name_buffer->value = malloc(name->gn_value.length);
5758314Sache		if (!output_name_buffer->value) {
5858314Sache			*minor_status = ENOMEM;
5921308Sache			return (GSS_S_FAILURE);
6021308Sache		}
6121308Sache		output_name_buffer->length = name->gn_value.length;
6221308Sache		memcpy(output_name_buffer->value, name->gn_value.value,
63119614Sache		    output_name_buffer->length);
64119614Sache		if (output_name_type)
65119614Sache			*output_name_type = &name->gn_type;
66119614Sache
67119614Sache		*minor_status = 0;
6821308Sache		return (GSS_S_COMPLETE);
69119614Sache	} else {
70136759Speter		HEIM_SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {
71119614Sache			major_status = mn->gmn_mech->gm_display_name(
72119614Sache				minor_status, mn->gmn_name,
73119614Sache				output_name_buffer,
74119614Sache				output_name_type);
75119614Sache			if (major_status == GSS_S_COMPLETE)
7621308Sache				return (GSS_S_COMPLETE);
7758314Sache		}
7821308Sache	}
7921308Sache
80165675Sache	*minor_status = 0;
81165675Sache	return (GSS_S_FAILURE);
8221308Sache}
8321308Sache