129088Smarkm/*	$NetBSD$	*/
229088Smarkm
329088Smarkm/*-
429088Smarkm * Copyright (c) 2005 Doug Rabson
529088Smarkm * All rights reserved.
629088Smarkm *
729088Smarkm * Redistribution and use in source and binary forms, with or without
829088Smarkm * modification, are permitted provided that the following conditions
929088Smarkm * are met:
1029088Smarkm * 1. Redistributions of source code must retain the above copyright
1129088Smarkm *    notice, this list of conditions and the following disclaimer.
1229088Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1329088Smarkm *    notice, this list of conditions and the following disclaimer in the
1429088Smarkm *    documentation and/or other materials provided with the distribution.
1529088Smarkm *
1629088Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1729088Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1829088Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1929088Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2029088Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2129088Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2229088Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2329088Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2429088Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2529088Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2629088Smarkm * SUCH DAMAGE.
2729088Smarkm *
2829088Smarkm *	$FreeBSD: src/lib/libgssapi/gss_release_cred.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
2929088Smarkm */
3029088Smarkm
3129088Smarkm#include "mech_locl.h"
3229088Smarkm
3329088Smarkm/**
3429088Smarkm * Release a credentials
3529181Smarkm *
3629088Smarkm * Its ok to release the GSS_C_NO_CREDENTIAL/NULL credential, it will
3729088Smarkm * return a GSS_S_COMPLETE error code. On return cred_handle is set ot
3829088Smarkm * GSS_C_NO_CREDENTIAL.
3929088Smarkm *
4029088Smarkm * Example:
4129088Smarkm *
4229088Smarkm * @code
4329088Smarkm * gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
4429088Smarkm * major = gss_release_cred(&minor, &cred);
4529088Smarkm * @endcode
4629088Smarkm *
4729088Smarkm * @param minor_status minor status return code, mech specific
4829088Smarkm * @param cred_handle a pointer to the credential too release
4929088Smarkm *
5029088Smarkm * @return an gssapi error code
5129088Smarkm *
5229088Smarkm * @ingroup gssapi
5329088Smarkm */
5429088Smarkm
5529088SmarkmGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
5629088Smarkmgss_release_cred(OM_uint32 *minor_status, gss_cred_id_t *cred_handle)
5729088Smarkm{
5829088Smarkm	struct _gss_cred *cred = (struct _gss_cred *) *cred_handle;
5929088Smarkm	struct _gss_mechanism_cred *mc;
6029088Smarkm
6129181Smarkm	if (*cred_handle == GSS_C_NO_CREDENTIAL)
6229088Smarkm	    return (GSS_S_COMPLETE);
6329088Smarkm
6429088Smarkm	while (HEIM_SLIST_FIRST(&cred->gc_mc)) {
6529088Smarkm		mc = HEIM_SLIST_FIRST(&cred->gc_mc);
6629088Smarkm		HEIM_SLIST_REMOVE_HEAD(&cred->gc_mc, gmc_link);
6729088Smarkm		mc->gmc_mech->gm_release_cred(minor_status, &mc->gmc_cred);
6829088Smarkm		free(mc);
6929088Smarkm	}
7029088Smarkm	free(cred);
7129088Smarkm
7229088Smarkm	*minor_status = 0;
7329088Smarkm	*cred_handle = GSS_C_NO_CREDENTIAL;
7429088Smarkm	return (GSS_S_COMPLETE);
7529088Smarkm}
7629088Smarkm