xref: /titanic_41/usr/src/lib/libgss/g_rel_cred.c (revision 6185db853e024a486ff8837e6784dd290d866112)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  *  glue routine for gss_release_cred
31  */
32 
33 #include <mechglueP.h>
34 #include <stdio.h>
35 #ifdef HAVE_STDLIB_H
36 #include <stdlib.h>
37 #endif
38 
39 OM_uint32
40 gss_release_cred(minor_status,
41 			cred_handle)
42 
43 OM_uint32 		*minor_status;
44 gss_cred_id_t 		*cred_handle;
45 
46 {
47 	OM_uint32		status, temp_status;
48 	int			j;
49 	gss_union_cred_t	union_cred;
50 	gss_mechanism		mech;
51 
52 	if (minor_status == NULL)
53 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
54 
55 	*minor_status = 0;
56 
57 	if (cred_handle == NULL)
58 		return (GSS_S_NO_CRED | GSS_S_CALL_INACCESSIBLE_READ);
59 
60 	/*
61 	 * Loop through the union_cred struct, selecting the approprate
62 	 * underlying mechanism routine and calling it. At the end,
63 	 * release all of the storage taken by the union_cred struct.
64 	 */
65 
66 	union_cred = (gss_union_cred_t)*cred_handle;
67 	*cred_handle = NULL;
68 
69 	if (union_cred == (gss_union_cred_t)GSS_C_NO_CREDENTIAL)
70 		return (GSS_S_COMPLETE);
71 
72 	status = GSS_S_COMPLETE;
73 
74 	for (j = 0; j < union_cred->count; j++) {
75 
76 		mech = __gss_get_mechanism(&union_cred->mechs_array[j]);
77 
78 		if (union_cred->mechs_array[j].elements)
79 			free(union_cred->mechs_array[j].elements);
80 		if (mech) {
81 			if (mech->gss_release_cred) {
82 				temp_status = mech->gss_release_cred
83 						(mech->context, minor_status,
84 						&union_cred->cred_array[j]);
85 
86 				if (temp_status != GSS_S_COMPLETE)
87 					status = GSS_S_NO_CRED;
88 			} else
89 				status = GSS_S_UNAVAILABLE;
90 		} else
91 			status = GSS_S_DEFECTIVE_CREDENTIAL;
92 	}
93 
94 	(void) gss_release_buffer(minor_status, &union_cred->auxinfo.name);
95 	free(union_cred->cred_array);
96 	free(union_cred->mechs_array);
97 	free(union_cred);
98 
99 	return (status);
100 }
101