1153838Sdfr/*- 2153838Sdfr * Copyright (c) 2005 Doug Rabson 3153838Sdfr * All rights reserved. 4153838Sdfr * 5153838Sdfr * Redistribution and use in source and binary forms, with or without 6153838Sdfr * modification, are permitted provided that the following conditions 7153838Sdfr * are met: 8153838Sdfr * 1. Redistributions of source code must retain the above copyright 9153838Sdfr * notice, this list of conditions and the following disclaimer. 10153838Sdfr * 2. Redistributions in binary form must reproduce the above copyright 11153838Sdfr * notice, this list of conditions and the following disclaimer in the 12153838Sdfr * documentation and/or other materials provided with the distribution. 13153838Sdfr * 14153838Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15153838Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16153838Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17153838Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18153838Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19153838Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20153838Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21153838Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22153838Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23153838Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24153838Sdfr * SUCH DAMAGE. 25153838Sdfr * 26153838Sdfr * $FreeBSD$ 27153838Sdfr */ 28153838Sdfr 29153838Sdfr#include <gssapi/gssapi.h> 30153838Sdfr 31153838Sdfr#include "mech_switch.h" 32153838Sdfr#include "cred.h" 33153838Sdfr#include "name.h" 34153838Sdfr 35153838SdfrOM_uint32 36153838Sdfrgss_inquire_cred_by_mech(OM_uint32 *minor_status, 37153838Sdfr const gss_cred_id_t cred_handle, 38153838Sdfr const gss_OID mech_type, 39153838Sdfr gss_name_t *cred_name, 40153838Sdfr OM_uint32 *initiator_lifetime, 41153838Sdfr OM_uint32 *acceptor_lifetime, 42153838Sdfr gss_cred_usage_t *cred_usage) 43153838Sdfr{ 44153838Sdfr OM_uint32 major_status; 45153838Sdfr struct _gss_mech_switch *m; 46153838Sdfr struct _gss_mechanism_cred *mcp; 47153838Sdfr gss_cred_id_t mc; 48153838Sdfr gss_name_t mn; 49153838Sdfr struct _gss_name *name; 50153838Sdfr 51153838Sdfr *minor_status = 0; 52178828Sdfr if (cred_name) 53178828Sdfr *cred_name = GSS_C_NO_NAME; 54178828Sdfr if (initiator_lifetime) 55178828Sdfr *initiator_lifetime = 0; 56178828Sdfr if (acceptor_lifetime) 57178828Sdfr *acceptor_lifetime = 0; 58178828Sdfr if (cred_usage) 59178828Sdfr *cred_usage = 0; 60153838Sdfr 61153838Sdfr m = _gss_find_mech_switch(mech_type); 62153838Sdfr if (!m) 63153838Sdfr return (GSS_S_NO_CRED); 64153838Sdfr 65153838Sdfr if (cred_handle != GSS_C_NO_CREDENTIAL) { 66153838Sdfr struct _gss_cred *cred = (struct _gss_cred *) cred_handle; 67153838Sdfr SLIST_FOREACH(mcp, &cred->gc_mc, gmc_link) 68153838Sdfr if (mcp->gmc_mech == m) 69153838Sdfr break; 70153838Sdfr if (!mcp) 71153838Sdfr return (GSS_S_NO_CRED); 72153838Sdfr mc = mcp->gmc_cred; 73153838Sdfr } else { 74153838Sdfr mc = GSS_C_NO_CREDENTIAL; 75153838Sdfr } 76153838Sdfr 77153838Sdfr major_status = m->gm_inquire_cred_by_mech(minor_status, mc, mech_type, 78153838Sdfr &mn, initiator_lifetime, acceptor_lifetime, cred_usage); 79178828Sdfr if (major_status != GSS_S_COMPLETE) { 80178828Sdfr _gss_mg_error(m, major_status, *minor_status); 81153838Sdfr return (major_status); 82178828Sdfr } 83153838Sdfr 84178828Sdfr if (cred_name) { 85178828Sdfr name = _gss_make_name(m, mn); 86178828Sdfr if (!name) { 87178828Sdfr m->gm_release_name(minor_status, &mn); 88178828Sdfr return (GSS_S_NO_CRED); 89178828Sdfr } 90178828Sdfr *cred_name = (gss_name_t) name; 91178828Sdfr } else { 92153838Sdfr m->gm_release_name(minor_status, &mn); 93153838Sdfr } 94153838Sdfr 95153838Sdfr return (GSS_S_COMPLETE); 96153838Sdfr} 97