1130803Smarcel/*-
2130803Smarcel * Copyright (c) 2005 Doug Rabson
3130803Smarcel * All rights reserved.
4130803Smarcel *
5130803Smarcel * Redistribution and use in source and binary forms, with or without
6130803Smarcel * modification, are permitted provided that the following conditions
7130803Smarcel * are met:
8130803Smarcel * 1. Redistributions of source code must retain the above copyright
9130803Smarcel *    notice, this list of conditions and the following disclaimer.
10130803Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11130803Smarcel *    notice, this list of conditions and the following disclaimer in the
12130803Smarcel *    documentation and/or other materials provided with the distribution.
13130803Smarcel *
14130803Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15130803Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16130803Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17130803Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18130803Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19130803Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20130803Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21130803Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22130803Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23130803Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24130803Smarcel * SUCH DAMAGE.
25130803Smarcel *
26130803Smarcel *	$FreeBSD$
27130803Smarcel */
28130803Smarcel
29130803Smarcel#include <gssapi/gssapi.h>
30130803Smarcel#include <stdlib.h>
31130803Smarcel#include <errno.h>
32130803Smarcel
33130803Smarcel#include "mech_switch.h"
34130803Smarcel#include "name.h"
35130803Smarcel
36130803SmarcelOM_uint32
37130803Smarcelgss_release_name(OM_uint32 *minor_status,
38130803Smarcel    gss_name_t *input_name)
39130803Smarcel{
40130803Smarcel	struct _gss_name *name = (struct _gss_name *) *input_name;
41130803Smarcel
42130803Smarcel	*minor_status = 0;
43130803Smarcel	if (name) {
44130803Smarcel		if (name->gn_type.elements)
45130803Smarcel			free(name->gn_type.elements);
46130803Smarcel		while (SLIST_FIRST(&name->gn_mn)) {
47130803Smarcel			struct _gss_mechanism_name *mn;
48130803Smarcel			mn = SLIST_FIRST(&name->gn_mn);
49130803Smarcel			SLIST_REMOVE_HEAD(&name->gn_mn, gmn_link);
50130803Smarcel			mn->gmn_mech->gm_release_name(minor_status,
51130803Smarcel			    &mn->gmn_name);
52130803Smarcel			free(mn);
53130803Smarcel		}
54130803Smarcel		gss_release_buffer(minor_status, &name->gn_value);
55130803Smarcel		free(name);
56130803Smarcel		*input_name = GSS_C_NO_NAME;
57130803Smarcel	}
58130803Smarcel	return (GSS_S_COMPLETE);
59130803Smarcel}
60130803Smarcel