/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008 Isilon Inc http://www.isilon.com/4* Authors: Doug Rabson <[email protected]>5* Developed with Red Inc: Alfred Perlstein <[email protected]>6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#include <sys/param.h>30#include <sys/kernel.h>31#include <sys/kobj.h>32#include <sys/lock.h>33#include <sys/malloc.h>34#include <sys/mutex.h>35#include <sys/proc.h>3637#include <kgssapi/gssapi.h>38#include <kgssapi/gssapi_impl.h>3940#include "gssd.h"4142OM_uint3243gss_acquire_cred(OM_uint32 *minor_status,44const gss_name_t desired_name,45OM_uint32 time_req,46const gss_OID_set desired_mechs,47gss_cred_usage_t cred_usage,48gss_cred_id_t *output_cred_handle,49gss_OID_set *actual_mechs,50OM_uint32 *time_rec)51{52OM_uint32 major_status;53struct acquire_cred_res res;54struct acquire_cred_args args;55enum clnt_stat stat;56gss_cred_id_t cred;57int i;58CLIENT *cl;5960*minor_status = 0;61cl = kgss_gssd_client();62if (cl == NULL)63return (GSS_S_FAILURE);6465args.uid = curthread->td_ucred->cr_uid;66if (desired_name)67args.desired_name = desired_name->handle;68else69args.desired_name = 0;70args.time_req = time_req;71args.desired_mechs = desired_mechs;72args.cred_usage = cred_usage;7374bzero(&res, sizeof(res));75stat = gssd_acquire_cred_1(&args, &res, cl);76CLNT_RELEASE(cl);77if (stat != RPC_SUCCESS) {78*minor_status = stat;79return (GSS_S_FAILURE);80}8182if (res.major_status != GSS_S_COMPLETE) {83*minor_status = res.minor_status;84return (res.major_status);85}8687cred = malloc(sizeof(struct _gss_cred_id_t), M_GSSAPI, M_WAITOK);88cred->handle = res.output_cred;89*output_cred_handle = cred;90if (actual_mechs) {91major_status = gss_create_empty_oid_set(minor_status,92actual_mechs);93if (major_status)94return (major_status);95for (i = 0; i < res.actual_mechs->count; i++) {96major_status = gss_add_oid_set_member(minor_status,97&res.actual_mechs->elements[i], actual_mechs);98if (major_status)99return (major_status);100}101}102if (time_rec)103*time_rec = res.time_rec;104105xdr_free((xdrproc_t) xdr_acquire_cred_res, &res);106107return (GSS_S_COMPLETE);108}109110111