1*13132SGlenn.Barry@oracle.com /*
2*13132SGlenn.Barry@oracle.com * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3*13132SGlenn.Barry@oracle.com */
40Sstevel@tonic-gate /*
50Sstevel@tonic-gate * Copyright 1993 by OpenVision Technologies, Inc.
65053Sgtb *
70Sstevel@tonic-gate * Permission to use, copy, modify, distribute, and sell this software
80Sstevel@tonic-gate * and its documentation for any purpose is hereby granted without fee,
90Sstevel@tonic-gate * provided that the above copyright notice appears in all copies and
100Sstevel@tonic-gate * that both that copyright notice and this permission notice appear in
110Sstevel@tonic-gate * supporting documentation, and that the name of OpenVision not be used
120Sstevel@tonic-gate * in advertising or publicity pertaining to distribution of the software
130Sstevel@tonic-gate * without specific, written prior permission. OpenVision makes no
140Sstevel@tonic-gate * representations about the suitability of this software for any
150Sstevel@tonic-gate * purpose. It is provided "as is" without express or implied warranty.
165053Sgtb *
170Sstevel@tonic-gate * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
180Sstevel@tonic-gate * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
190Sstevel@tonic-gate * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
200Sstevel@tonic-gate * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
210Sstevel@tonic-gate * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
220Sstevel@tonic-gate * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
230Sstevel@tonic-gate * PERFORMANCE OF THIS SOFTWARE.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
265053Sgtb #include "gssapiP_krb5.h"
270Sstevel@tonic-gate
285053Sgtb OM_uint32
krb5_gss_release_cred(minor_status,cred_handle)295053Sgtb krb5_gss_release_cred(minor_status, cred_handle)
300Sstevel@tonic-gate OM_uint32 *minor_status;
310Sstevel@tonic-gate gss_cred_id_t *cred_handle;
320Sstevel@tonic-gate {
335053Sgtb krb5_context context;
340Sstevel@tonic-gate krb5_gss_cred_id_t cred;
350Sstevel@tonic-gate krb5_error_code code1, code2, code3;
360Sstevel@tonic-gate
375053Sgtb code1 = krb5_gss_init_context(&context);
385053Sgtb if (code1) {
395053Sgtb *minor_status = code1;
405053Sgtb return GSS_S_FAILURE;
415053Sgtb }
420Sstevel@tonic-gate
435053Sgtb if (*cred_handle == GSS_C_NO_CREDENTIAL) {
445053Sgtb *minor_status = 0;
455053Sgtb krb5_free_context(context);
465053Sgtb return(GSS_S_COMPLETE);
470Sstevel@tonic-gate }
480Sstevel@tonic-gate
490Sstevel@tonic-gate if (! kg_delete_cred_id(*cred_handle)) {
500Sstevel@tonic-gate *minor_status = (OM_uint32) G_VALIDATE_FAILED;
515053Sgtb krb5_free_context(context);
520Sstevel@tonic-gate return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_NO_CRED);
530Sstevel@tonic-gate }
540Sstevel@tonic-gate
550Sstevel@tonic-gate cred = (krb5_gss_cred_id_t)*cred_handle;
560Sstevel@tonic-gate
575053Sgtb k5_mutex_destroy(&cred->lock);
585053Sgtb /* ignore error destroying mutex */
595053Sgtb
605053Sgtb
610Sstevel@tonic-gate if (cred->ccache) {
620Sstevel@tonic-gate /*
635053Sgtb * Solaris Kerberos
640Sstevel@tonic-gate * If the ccache is a MEMORY ccache then this credential handle
650Sstevel@tonic-gate * should be the only way to get to it, at least until the advent
660Sstevel@tonic-gate * of a GSS_Duplicate_cred() (which is needed and may well be
670Sstevel@tonic-gate * added some day). Until then MEMORY ccaches must be destroyed,
680Sstevel@tonic-gate * not closed, else their contents (tickets, session keys) will
690Sstevel@tonic-gate * leak.
700Sstevel@tonic-gate */
710Sstevel@tonic-gate if (strcmp("MEMORY", krb5_cc_get_type(context, cred->ccache)) == 0)
720Sstevel@tonic-gate code1 = krb5_cc_destroy(context, cred->ccache);
730Sstevel@tonic-gate else
740Sstevel@tonic-gate code1 = krb5_cc_close(context, cred->ccache);
750Sstevel@tonic-gate } else
760Sstevel@tonic-gate code1 = 0;
770Sstevel@tonic-gate
780Sstevel@tonic-gate if (cred->keytab)
790Sstevel@tonic-gate code2 = krb5_kt_close(context, cred->keytab);
800Sstevel@tonic-gate else
810Sstevel@tonic-gate code2 = 0;
820Sstevel@tonic-gate
830Sstevel@tonic-gate if (cred->rcache)
840Sstevel@tonic-gate code3 = krb5_rc_close(context, cred->rcache);
850Sstevel@tonic-gate else
860Sstevel@tonic-gate code3 = 0;
870Sstevel@tonic-gate if (cred->princ)
880Sstevel@tonic-gate krb5_free_principal(context, cred->princ);
895053Sgtb
905053Sgtb if (cred->req_enctypes)
915053Sgtb free(cred->req_enctypes);
925053Sgtb
930Sstevel@tonic-gate xfree(cred);
940Sstevel@tonic-gate
950Sstevel@tonic-gate *cred_handle = NULL;
960Sstevel@tonic-gate
970Sstevel@tonic-gate *minor_status = 0;
980Sstevel@tonic-gate if (code1)
990Sstevel@tonic-gate *minor_status = code1;
1000Sstevel@tonic-gate if (code2)
1010Sstevel@tonic-gate *minor_status = code2;
1020Sstevel@tonic-gate if (code3)
1030Sstevel@tonic-gate *minor_status = code3;
1040Sstevel@tonic-gate
105*13132SGlenn.Barry@oracle.com if (*minor_status)
106*13132SGlenn.Barry@oracle.com save_error_info(*minor_status, context);
107*13132SGlenn.Barry@oracle.com krb5_free_context(context);
1080Sstevel@tonic-gate return(*minor_status?GSS_S_FAILURE:GSS_S_COMPLETE);
1090Sstevel@tonic-gate }
110