xref: /illumos-gate/usr/src/lib/libgss/g_rel_cred.c (revision 6a634c9d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*5e01956fSGlenn Barry  * Common Development and Distribution License (the "License").
6*5e01956fSGlenn Barry  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*5e01956fSGlenn Barry  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  *  glue routine for gss_release_cred
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <mechglueP.h>
30*5e01956fSGlenn Barry #include "gssapiP_generic.h"
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate #ifdef HAVE_STDLIB_H
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate OM_uint32
gss_release_cred(minor_status,cred_handle)377c478bd9Sstevel@tonic-gate gss_release_cred(minor_status,
387c478bd9Sstevel@tonic-gate 			cred_handle)
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate OM_uint32 		*minor_status;
417c478bd9Sstevel@tonic-gate gss_cred_id_t 		*cred_handle;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate 	OM_uint32		status, temp_status;
457c478bd9Sstevel@tonic-gate 	int			j;
467c478bd9Sstevel@tonic-gate 	gss_union_cred_t	union_cred;
477c478bd9Sstevel@tonic-gate 	gss_mechanism		mech;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 	if (minor_status == NULL)
507c478bd9Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate 	*minor_status = 0;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	if (cred_handle == NULL)
557c478bd9Sstevel@tonic-gate 		return (GSS_S_NO_CRED | GSS_S_CALL_INACCESSIBLE_READ);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	/*
587c478bd9Sstevel@tonic-gate 	 * Loop through the union_cred struct, selecting the approprate
597c478bd9Sstevel@tonic-gate 	 * underlying mechanism routine and calling it. At the end,
607c478bd9Sstevel@tonic-gate 	 * release all of the storage taken by the union_cred struct.
617c478bd9Sstevel@tonic-gate 	 */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	union_cred = (gss_union_cred_t)*cred_handle;
647c478bd9Sstevel@tonic-gate 	if (union_cred == (gss_union_cred_t)GSS_C_NO_CREDENTIAL)
657c478bd9Sstevel@tonic-gate 		return (GSS_S_COMPLETE);
667c478bd9Sstevel@tonic-gate 
67*5e01956fSGlenn Barry 	if (GSSINT_CHK_LOOP(union_cred))
68*5e01956fSGlenn Barry 		return (GSS_S_NO_CRED | GSS_S_CALL_INACCESSIBLE_READ);
69*5e01956fSGlenn Barry 
70*5e01956fSGlenn Barry 	*cred_handle = NULL;
71*5e01956fSGlenn Barry 
727c478bd9Sstevel@tonic-gate 	status = GSS_S_COMPLETE;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	for (j = 0; j < union_cred->count; j++) {
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 		mech = __gss_get_mechanism(&union_cred->mechs_array[j]);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 		if (union_cred->mechs_array[j].elements)
797c478bd9Sstevel@tonic-gate 			free(union_cred->mechs_array[j].elements);
807c478bd9Sstevel@tonic-gate 		if (mech) {
817c478bd9Sstevel@tonic-gate 			if (mech->gss_release_cred) {
827c478bd9Sstevel@tonic-gate 				temp_status = mech->gss_release_cred
837c478bd9Sstevel@tonic-gate 						(mech->context, minor_status,
847c478bd9Sstevel@tonic-gate 						&union_cred->cred_array[j]);
857c478bd9Sstevel@tonic-gate 
86*5e01956fSGlenn Barry 				if (temp_status != GSS_S_COMPLETE) {
87*5e01956fSGlenn Barry 					map_error(minor_status, mech);
887c478bd9Sstevel@tonic-gate 					status = GSS_S_NO_CRED;
89*5e01956fSGlenn Barry 				}
907c478bd9Sstevel@tonic-gate 			} else
917c478bd9Sstevel@tonic-gate 				status = GSS_S_UNAVAILABLE;
927c478bd9Sstevel@tonic-gate 		} else
937c478bd9Sstevel@tonic-gate 			status = GSS_S_DEFECTIVE_CREDENTIAL;
947c478bd9Sstevel@tonic-gate 	}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	(void) gss_release_buffer(minor_status, &union_cred->auxinfo.name);
977c478bd9Sstevel@tonic-gate 	free(union_cred->cred_array);
987c478bd9Sstevel@tonic-gate 	free(union_cred->mechs_array);
997c478bd9Sstevel@tonic-gate 	free(union_cred);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	return (status);
1027c478bd9Sstevel@tonic-gate }
103