Path: blob/main/sys/kgssapi/gss_delete_sec_context.c
39476 views
/*-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/jail.h>31#include <sys/kernel.h>32#include <sys/kobj.h>33#include <sys/lock.h>34#include <sys/malloc.h>35#include <sys/mutex.h>3637#include <kgssapi/gssapi.h>38#include <kgssapi/gssapi_impl.h>3940#include "gssd.h"4142OM_uint3243gss_delete_sec_context(OM_uint32 *minor_status, gss_ctx_id_t *context_handle,44gss_buffer_t output_token)45{46struct delete_sec_context_res res;47struct delete_sec_context_args args;48enum clnt_stat stat;49gss_ctx_id_t ctx;50CLIENT *cl;5152*minor_status = 0;5354KGSS_CURVNET_SET_QUIET(KGSS_TD_TO_VNET(curthread));55if (!KGSS_VNET(kgss_gssd_handle)) {56KGSS_CURVNET_RESTORE();57return (GSS_S_FAILURE);58}59KGSS_CURVNET_RESTORE();6061if (*context_handle) {62ctx = *context_handle;6364/*65* If we are past the context establishment phase, let66* the in-kernel code do the delete, otherwise67* userland needs to deal with it.68*/69if (ctx->handle) {70args.ctx = ctx->handle;71cl = kgss_gssd_client();72if (cl == NULL)73return (GSS_S_FAILURE);7475bzero(&res, sizeof(res));76stat = gssd_delete_sec_context_1(&args, &res, cl);77CLNT_RELEASE(cl);78if (stat != RPC_SUCCESS) {79*minor_status = stat;80return (GSS_S_FAILURE);81}8283if (output_token)84kgss_copy_buffer(&res.output_token,85output_token);86xdr_free((xdrproc_t) xdr_delete_sec_context_res, &res);8788kgss_delete_context(ctx, NULL);89} else {90kgss_delete_context(ctx, output_token);91}92*context_handle = NULL;93} else {94if (output_token) {95output_token->length = 0;96output_token->value = NULL;97}98}99100return (GSS_S_COMPLETE);101}102103104