1226031Sstas/*-
2226031Sstas * Copyright (c) 2005 Doug Rabson
3226031Sstas * All rights reserved.
4226031Sstas *
5226031Sstas * Redistribution and use in source and binary forms, with or without
6226031Sstas * modification, are permitted provided that the following conditions
7226031Sstas * are met:
8226031Sstas * 1. Redistributions of source code must retain the above copyright
9226031Sstas *    notice, this list of conditions and the following disclaimer.
10226031Sstas * 2. Redistributions in binary form must reproduce the above copyright
11226031Sstas *    notice, this list of conditions and the following disclaimer in the
12226031Sstas *    documentation and/or other materials provided with the distribution.
13226031Sstas *
14226031Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17226031Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24226031Sstas * SUCH DAMAGE.
25226031Sstas *
26226031Sstas *	$FreeBSD: src/lib/libgssapi/gss_release_cred.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
27226031Sstas */
28226031Sstas
29226031Sstas#include "mech_locl.h"
30226031Sstas
31226031Sstas/**
32226031Sstas * Release a credentials
33226031Sstas *
34226031Sstas * Its ok to release the GSS_C_NO_CREDENTIAL/NULL credential, it will
35226031Sstas * return a GSS_S_COMPLETE error code. On return cred_handle is set ot
36226031Sstas * GSS_C_NO_CREDENTIAL.
37226031Sstas *
38226031Sstas * Example:
39226031Sstas *
40226031Sstas * @code
41226031Sstas * gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
42226031Sstas * major = gss_release_cred(&minor, &cred);
43226031Sstas * @endcode
44226031Sstas *
45226031Sstas * @param minor_status minor status return code, mech specific
46226031Sstas * @param cred_handle a pointer to the credential too release
47226031Sstas *
48226031Sstas * @return an gssapi error code
49226031Sstas *
50226031Sstas * @ingroup gssapi
51226031Sstas */
52226031Sstas
53226031SstasGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
54226031Sstasgss_release_cred(OM_uint32 *minor_status, gss_cred_id_t *cred_handle)
55226031Sstas{
56226031Sstas	struct _gss_cred *cred = (struct _gss_cred *) *cred_handle;
57226031Sstas	struct _gss_mechanism_cred *mc;
58226031Sstas
59226031Sstas	if (*cred_handle == GSS_C_NO_CREDENTIAL)
60226031Sstas	    return (GSS_S_COMPLETE);
61226031Sstas
62226031Sstas	while (HEIM_SLIST_FIRST(&cred->gc_mc)) {
63226031Sstas		mc = HEIM_SLIST_FIRST(&cred->gc_mc);
64226031Sstas		HEIM_SLIST_REMOVE_HEAD(&cred->gc_mc, gmc_link);
65226031Sstas		mc->gmc_mech->gm_release_cred(minor_status, &mc->gmc_cred);
66226031Sstas		free(mc);
67226031Sstas	}
68226031Sstas	free(cred);
69226031Sstas
70226031Sstas	*minor_status = 0;
71226031Sstas	*cred_handle = GSS_C_NO_CREDENTIAL;
72226031Sstas	return (GSS_S_COMPLETE);
73226031Sstas}
74