1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright 1993 by OpenVision Technologies, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without fee,
7 * provided that the above copyright notice appears in all copies and
8 * that both that copyright notice and this permission notice appear in
9 * supporting documentation, and that the name of OpenVision not be used
10 * in advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. OpenVision makes no
12 * representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
22 */
23
24 #include "gssapiP_krb5.h"
25
26 OM_uint32 KRB5_CALLCONV
krb5_gss_release_cred(OM_uint32 * minor_status,gss_cred_id_t * cred_handle)27 krb5_gss_release_cred(OM_uint32 *minor_status, gss_cred_id_t *cred_handle)
28 {
29 krb5_context context;
30 krb5_gss_cred_id_t cred;
31 krb5_error_code code1, code2;
32
33 code1 = krb5_gss_init_context(&context);
34 if (code1) {
35 *minor_status = code1;
36 return GSS_S_FAILURE;
37 }
38
39 if (*cred_handle == GSS_C_NO_CREDENTIAL) {
40 *minor_status = 0;
41 krb5_free_context(context);
42 return(GSS_S_COMPLETE);
43 }
44
45 cred = (krb5_gss_cred_id_t)*cred_handle;
46
47 k5_mutex_destroy(&cred->lock);
48 /* ignore error destroying mutex */
49
50 if (cred->ccache) {
51 if (cred->destroy_ccache)
52 code1 = krb5_cc_destroy(context, cred->ccache);
53 else
54 code1 = krb5_cc_close(context, cred->ccache);
55 } else
56 code1 = 0;
57
58 if (cred->client_keytab)
59 krb5_kt_close(context, cred->client_keytab);
60
61 #ifndef LEAN_CLIENT
62 if (cred->keytab)
63 code2 = krb5_kt_close(context, cred->keytab);
64 else
65 #endif /* LEAN_CLIENT */
66 code2 = 0;
67
68 if (cred->rcache)
69 k5_rc_close(context, cred->rcache);
70 if (cred->name)
71 kg_release_name(context, &cred->name);
72
73 krb5_free_principal(context, cred->acceptor_mprinc);
74 krb5_free_principal(context, cred->impersonator);
75
76 if (cred->req_enctypes)
77 free(cred->req_enctypes);
78
79 if (cred->password != NULL)
80 zapfree(cred->password, strlen(cred->password));
81
82 xfree(cred);
83
84 *cred_handle = NULL;
85
86 *minor_status = 0;
87 if (code1)
88 *minor_status = code1;
89 if (code2)
90 *minor_status = code2;
91
92 if (*minor_status)
93 save_error_info(*minor_status, context);
94 krb5_free_context(context);
95 return(*minor_status?GSS_S_FAILURE:GSS_S_COMPLETE);
96 }
97