xref: /freebsd/crypto/krb5/src/lib/gssapi/mechglue/g_rel_cred.c (revision f1c4c3daccbaf3820f0e2224de53df12fc952fcc)
1 /* #pragma ident	"@(#)g_rel_cred.c	1.14	04/02/23 SMI" */
2 
3 /*
4  * Copyright 1996 by Sun Microsystems, Inc.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appears in all copies and
9  * that both that copyright notice and this permission notice appear in
10  * supporting documentation, and that the name of Sun Microsystems not be used
11  * in advertising or publicity pertaining to distribution of the software
12  * without specific, written prior permission. Sun Microsystems makes no
13  * representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18  * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22  * PERFORMANCE OF THIS SOFTWARE.
23  */
24 
25 /* Glue routine for gss_release_cred */
26 
27 #include "mglueP.h"
28 #include <stdio.h>
29 #ifdef HAVE_STDLIB_H
30 #include <stdlib.h>
31 #endif
32 
33 OM_uint32 KRB5_CALLCONV
gss_release_cred(OM_uint32 * minor_status,gss_cred_id_t * cred_handle)34 gss_release_cred(OM_uint32 *minor_status, gss_cred_id_t *cred_handle)
35 {
36     OM_uint32		status, temp_status;
37     int			j;
38     gss_union_cred_t	union_cred;
39     gss_mechanism	mech;
40 
41     if (minor_status == NULL)
42 	return (GSS_S_CALL_INACCESSIBLE_WRITE);
43 
44     *minor_status = 0;
45 
46     if (cred_handle == NULL)
47 	return (GSS_S_NO_CRED | GSS_S_CALL_INACCESSIBLE_READ);
48 
49     /*
50      * Loop through the union_cred struct, selecting the approprate
51      * underlying mechanism routine and calling it. At the end,
52      * release all of the storage taken by the union_cred struct.
53      */
54 
55     union_cred = (gss_union_cred_t) *cred_handle;
56     if (union_cred == (gss_union_cred_t)GSS_C_NO_CREDENTIAL)
57 	return (GSS_S_COMPLETE);
58 
59     if (GSSINT_CHK_LOOP(union_cred))
60 	return (GSS_S_NO_CRED | GSS_S_CALL_INACCESSIBLE_READ);
61     *cred_handle = NULL;
62 
63     status = GSS_S_COMPLETE;
64 
65     for(j=0; j < union_cred->count; j++) {
66 
67 	mech = gssint_get_mechanism (&union_cred->mechs_array[j]);
68 
69 	if (union_cred->mechs_array[j].elements)
70 		free(union_cred->mechs_array[j].elements);
71 	if (mech) {
72 	    if (mech->gss_release_cred) {
73 		temp_status = mech->gss_release_cred
74 		    (
75 		     minor_status,
76 		     &union_cred->cred_array[j]);
77 
78 		if (temp_status != GSS_S_COMPLETE) {
79 		    map_error(minor_status, mech);
80 		    status = GSS_S_NO_CRED;
81 		}
82 
83 	    } else
84 		status = GSS_S_UNAVAILABLE;
85 	} else
86 	    status = GSS_S_DEFECTIVE_CREDENTIAL;
87     }
88 
89     free(union_cred->cred_array);
90     free(union_cred->mechs_array);
91     free(union_cred);
92 
93     return(status);
94 }
95