133965Sjdp/*
2130561Sobrien * Copyright (c) 2004, PADL Software Pty Ltd.
360484Sobrien * All rights reserved.
433965Sjdp *
533965Sjdp * Redistribution and use in source and binary forms, with or without
633965Sjdp * modification, are permitted provided that the following conditions
733965Sjdp * are met:
833965Sjdp *
933965Sjdp * 1. Redistributions of source code must retain the above copyright
1033965Sjdp *    notice, this list of conditions and the following disclaimer.
1133965Sjdp *
1233965Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1333965Sjdp *    notice, this list of conditions and the following disclaimer in the
1433965Sjdp *    documentation and/or other materials provided with the distribution.
1533965Sjdp *
1633965Sjdp * 3. Neither the name of PADL Software nor the names of its contributors
1733965Sjdp *    may be used to endorse or promote products derived from this software
1833965Sjdp *    without specific prior written permission.
1933965Sjdp *
2033965Sjdp * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
2133965Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2233965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2333965Sjdp * ARE DISCLAIMED.  IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
2433965Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2533965Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2633965Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2733965Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2833965Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2933965Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3033965Sjdp * SUCH DAMAGE.
3133965Sjdp */
3233965Sjdp/* $FreeBSD$ */
3333965Sjdp
3433965Sjdp#include <gssapi/gssapi.h>
3533965Sjdp
3633965Sjdp#include "mech_switch.h"
3777298Sobrien#include "cred.h"
3833965Sjdp#include "name.h"
3933965Sjdp
4033965Sjdp/* RCSID("$Id: gss_inquire_cred_by_oid.c 19960 2007-01-17 15:09:24Z lha $"); */
4133965Sjdp
4233965SjdpOM_uint32
4333965Sjdpgss_inquire_cred_by_oid (OM_uint32 *minor_status,
4433965Sjdp			 const gss_cred_id_t cred_handle,
4533965Sjdp			 const gss_OID desired_object,
4633965Sjdp			 gss_buffer_set_t *data_set)
4733965Sjdp{
4833965Sjdp	struct _gss_cred *cred = (struct _gss_cred *) cred_handle;
4933965Sjdp	OM_uint32		status = GSS_S_COMPLETE;
5033965Sjdp	struct _gss_mechanism_cred *mc;
5133965Sjdp	struct _gss_mech_switch *m;
5233965Sjdp	gss_buffer_set_t set = GSS_C_NO_BUFFER_SET;
5333965Sjdp
5433965Sjdp	*minor_status = 0;
5533965Sjdp	*data_set = GSS_C_NO_BUFFER_SET;
5633965Sjdp
5733965Sjdp	if (cred == NULL)
5833965Sjdp		return GSS_S_NO_CRED;
5933965Sjdp
6033965Sjdp	SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) {
6133965Sjdp		gss_buffer_set_t rset = GSS_C_NO_BUFFER_SET;
6233965Sjdp		size_t i;
6333965Sjdp
6433965Sjdp		m = mc->gmc_mech;
6533965Sjdp		if (m == NULL) {
6633965Sjdp	       		gss_release_buffer_set(minor_status, &set);
6733965Sjdp			*minor_status = 0;
6833965Sjdp			return GSS_S_BAD_MECH;
6933965Sjdp		}
7033965Sjdp
7133965Sjdp		if (m->gm_inquire_cred_by_oid == NULL)
7233965Sjdp			continue;
7333965Sjdp
7433965Sjdp		status = m->gm_inquire_cred_by_oid(minor_status,
7533965Sjdp		    mc->gmc_cred, desired_object, &rset);
7633965Sjdp		if (status != GSS_S_COMPLETE)
7733965Sjdp			continue;
7833965Sjdp
7933965Sjdp		for (i = 0; i < rset->count; i++) {
8033965Sjdp			status = gss_add_buffer_set_member(minor_status,
8133965Sjdp			     &rset->elements[i], &set);
8233965Sjdp			if (status != GSS_S_COMPLETE)
8333965Sjdp				break;
8433965Sjdp		}
8533965Sjdp		gss_release_buffer_set(minor_status, &rset);
8660484Sobrien	}
8760484Sobrien	if (set == GSS_C_NO_BUFFER_SET)
8877298Sobrien		status = GSS_S_FAILURE;
8933965Sjdp	*data_set = set;
9060484Sobrien	*minor_status = 0;
9133965Sjdp	return status;
9233965Sjdp}
9333965Sjdp
9433965Sjdp