xref: /freebsd/crypto/krb5/src/lib/gssapi/krb5/rel_cred.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
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(minor_status,cred_handle)27 krb5_gss_release_cred(minor_status, cred_handle)
28     OM_uint32 *minor_status;
29     gss_cred_id_t *cred_handle;
30 {
31     krb5_context context;
32     krb5_gss_cred_id_t cred;
33     krb5_error_code code1, code2;
34 
35     code1 = krb5_gss_init_context(&context);
36     if (code1) {
37         *minor_status = code1;
38         return GSS_S_FAILURE;
39     }
40 
41     if (*cred_handle == GSS_C_NO_CREDENTIAL) {
42         *minor_status = 0;
43         krb5_free_context(context);
44         return(GSS_S_COMPLETE);
45     }
46 
47     cred = (krb5_gss_cred_id_t)*cred_handle;
48 
49     k5_mutex_destroy(&cred->lock);
50     /* ignore error destroying mutex */
51 
52     if (cred->ccache) {
53         if (cred->destroy_ccache)
54             code1 = krb5_cc_destroy(context, cred->ccache);
55         else
56             code1 = krb5_cc_close(context, cred->ccache);
57     } else
58         code1 = 0;
59 
60     if (cred->client_keytab)
61         krb5_kt_close(context, cred->client_keytab);
62 
63 #ifndef LEAN_CLIENT
64     if (cred->keytab)
65         code2 = krb5_kt_close(context, cred->keytab);
66     else
67 #endif /* LEAN_CLIENT */
68         code2 = 0;
69 
70     if (cred->rcache)
71         k5_rc_close(context, cred->rcache);
72     if (cred->name)
73         kg_release_name(context, &cred->name);
74 
75     krb5_free_principal(context, cred->acceptor_mprinc);
76     krb5_free_principal(context, cred->impersonator);
77 
78     if (cred->req_enctypes)
79         free(cred->req_enctypes);
80 
81     if (cred->password != NULL)
82         zapfree(cred->password, strlen(cred->password));
83 
84     xfree(cred);
85 
86     *cred_handle = NULL;
87 
88     *minor_status = 0;
89     if (code1)
90         *minor_status = code1;
91     if (code2)
92         *minor_status = code2;
93 
94     if (*minor_status)
95         save_error_info(*minor_status, context);
96     krb5_free_context(context);
97     return(*minor_status?GSS_S_FAILURE:GSS_S_COMPLETE);
98 }
99