xref: /freebsd/crypto/krb5/src/lib/gssapi/mechglue/g_rel_cred.c (revision 328110da2661a8841f12000b99fea27ceacdd5b2)
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
34 gss_release_cred(minor_status,
35                  cred_handle)
36 
37 OM_uint32 *		minor_status;
38 gss_cred_id_t *		cred_handle;
39 
40 {
41     OM_uint32		status, temp_status;
42     int			j;
43     gss_union_cred_t	union_cred;
44     gss_mechanism	mech;
45 
46     if (minor_status == NULL)
47 	return (GSS_S_CALL_INACCESSIBLE_WRITE);
48 
49     *minor_status = 0;
50 
51     if (cred_handle == NULL)
52 	return (GSS_S_NO_CRED | GSS_S_CALL_INACCESSIBLE_READ);
53 
54     /*
55      * Loop through the union_cred struct, selecting the approprate
56      * underlying mechanism routine and calling it. At the end,
57      * release all of the storage taken by the union_cred struct.
58      */
59 
60     union_cred = (gss_union_cred_t) *cred_handle;
61     if (union_cred == (gss_union_cred_t)GSS_C_NO_CREDENTIAL)
62 	return (GSS_S_COMPLETE);
63 
64     if (GSSINT_CHK_LOOP(union_cred))
65 	return (GSS_S_NO_CRED | GSS_S_CALL_INACCESSIBLE_READ);
66     *cred_handle = NULL;
67 
68     status = GSS_S_COMPLETE;
69 
70     for(j=0; j < union_cred->count; j++) {
71 
72 	mech = gssint_get_mechanism (&union_cred->mechs_array[j]);
73 
74 	if (union_cred->mechs_array[j].elements)
75 		free(union_cred->mechs_array[j].elements);
76 	if (mech) {
77 	    if (mech->gss_release_cred) {
78 		temp_status = mech->gss_release_cred
79 		    (
80 		     minor_status,
81 		     &union_cred->cred_array[j]);
82 
83 		if (temp_status != GSS_S_COMPLETE) {
84 		    map_error(minor_status, mech);
85 		    status = GSS_S_NO_CRED;
86 		}
87 
88 	    } else
89 		status = GSS_S_UNAVAILABLE;
90 	} else
91 	    status = GSS_S_DEFECTIVE_CREDENTIAL;
92     }
93 
94     free(union_cred->cred_array);
95     free(union_cred->mechs_array);
96     free(union_cred);
97 
98     return(status);
99 }
100