1240075Sdes/*-
269587Sgreen * SPDX-License-Identifier: BSD-2-Clause
369587Sgreen *
469587Sgreen * Copyright (c) 2005 Doug Rabson
569587Sgreen * All rights reserved.
669587Sgreen *
769587Sgreen * Redistribution and use in source and binary forms, with or without
869587Sgreen * modification, are permitted provided that the following conditions
969587Sgreen * are met:
1069587Sgreen * 1. Redistributions of source code must retain the above copyright
1169587Sgreen *    notice, this list of conditions and the following disclaimer.
1269587Sgreen * 2. Redistributions in binary form must reproduce the above copyright
1369587Sgreen *    notice, this list of conditions and the following disclaimer in the
1469587Sgreen *    documentation and/or other materials provided with the distribution.
1569587Sgreen *
1669587Sgreen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1769587Sgreen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1869587Sgreen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1969587Sgreen * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2069587Sgreen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2169587Sgreen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2269587Sgreen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2369587Sgreen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2469587Sgreen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2569587Sgreen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2669587Sgreen * SUCH DAMAGE.
2769587Sgreen */
28162852Sdes
2969587Sgreen#include <gssapi/gssapi.h>
3069587Sgreen
3169587Sgreen#include "mech_switch.h"
3269587Sgreen#include "name.h"
33162852Sdes#include "utils.h"
34162852Sdes
35162852SdesOM_uint32
36162852Sdesgss_export_name(OM_uint32 *minor_status,
37162852Sdes    const gss_name_t input_name,
3869587Sgreen    gss_buffer_t exported_name)
3976259Sgreen{
4076259Sgreen	struct _gss_name *name = (struct _gss_name *) input_name;
4176259Sgreen	struct _gss_mechanism_name *mn;
4269587Sgreen
4392555Sdes	_gss_buffer_zero(exported_name);
4469587Sgreen
4569587Sgreen	/*
4669587Sgreen	 * If this name already has any attached MNs, export the first
4769587Sgreen	 * one, otherwise export based on the first mechanism in our
48162852Sdes	 * list.
49181111Sdes	 */
5069587Sgreen	mn = SLIST_FIRST(&name->gn_mn);
5169587Sgreen	if (!mn) {
52162852Sdes		*minor_status = 0;
53162852Sdes		return (GSS_S_NAME_NOT_MN);
5469587Sgreen	}
5569587Sgreen
5669587Sgreen	return mn->gmn_mech->gm_export_name(minor_status,
57106121Sdes	    mn->gmn_name, exported_name);
5869587Sgreen}
5969587Sgreen