1a9148abdSDoug Rabson /*- 2a9148abdSDoug Rabson * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 3a9148abdSDoug Rabson * Authors: Doug Rabson <dfr@rabson.org> 4a9148abdSDoug Rabson * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org> 5a9148abdSDoug Rabson * 6a9148abdSDoug Rabson * Redistribution and use in source and binary forms, with or without 7a9148abdSDoug Rabson * modification, are permitted provided that the following conditions 8a9148abdSDoug Rabson * are met: 9a9148abdSDoug Rabson * 1. Redistributions of source code must retain the above copyright 10a9148abdSDoug Rabson * notice, this list of conditions and the following disclaimer. 11a9148abdSDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 12a9148abdSDoug Rabson * notice, this list of conditions and the following disclaimer in the 13a9148abdSDoug Rabson * documentation and/or other materials provided with the distribution. 14a9148abdSDoug Rabson * 15a9148abdSDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16a9148abdSDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17a9148abdSDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18a9148abdSDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19a9148abdSDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20a9148abdSDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21a9148abdSDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22a9148abdSDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23a9148abdSDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24a9148abdSDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25a9148abdSDoug Rabson * SUCH DAMAGE. 26a9148abdSDoug Rabson */ 27a9148abdSDoug Rabson 28a9148abdSDoug Rabson #include <sys/cdefs.h> 29a9148abdSDoug Rabson __FBSDID("$FreeBSD$"); 30a9148abdSDoug Rabson 31a9148abdSDoug Rabson #include <sys/param.h> 32a9148abdSDoug Rabson #include <sys/kernel.h> 33a9148abdSDoug Rabson #include <sys/kobj.h> 34*13870d5dSRick Macklem #include <sys/lock.h> 35a9148abdSDoug Rabson #include <sys/malloc.h> 36*13870d5dSRick Macklem #include <sys/mutex.h> 37a9148abdSDoug Rabson 38a9148abdSDoug Rabson #include <kgssapi/gssapi.h> 39a9148abdSDoug Rabson #include <kgssapi/gssapi_impl.h> 40a9148abdSDoug Rabson 41a9148abdSDoug Rabson #include "gssd.h" 42a9148abdSDoug Rabson 43a9148abdSDoug Rabson OM_uint32 44a9148abdSDoug Rabson gss_delete_sec_context(OM_uint32 *minor_status, gss_ctx_id_t *context_handle, 45a9148abdSDoug Rabson gss_buffer_t output_token) 46a9148abdSDoug Rabson { 47a9148abdSDoug Rabson struct delete_sec_context_res res; 48a9148abdSDoug Rabson struct delete_sec_context_args args; 49a9148abdSDoug Rabson enum clnt_stat stat; 50a9148abdSDoug Rabson gss_ctx_id_t ctx; 51*13870d5dSRick Macklem CLIENT *cl; 52*13870d5dSRick Macklem 53*13870d5dSRick Macklem *minor_status = 0; 54a9148abdSDoug Rabson 55a9148abdSDoug Rabson if (!kgss_gssd_handle) 56a9148abdSDoug Rabson return (GSS_S_FAILURE); 57a9148abdSDoug Rabson 58a9148abdSDoug Rabson if (*context_handle) { 59a9148abdSDoug Rabson ctx = *context_handle; 60a9148abdSDoug Rabson 61a9148abdSDoug Rabson /* 62a9148abdSDoug Rabson * If we are past the context establishment phase, let 63a9148abdSDoug Rabson * the in-kernel code do the delete, otherwise 64a9148abdSDoug Rabson * userland needs to deal with it. 65a9148abdSDoug Rabson */ 66a9148abdSDoug Rabson if (ctx->handle) { 67a9148abdSDoug Rabson args.ctx = ctx->handle; 68*13870d5dSRick Macklem cl = kgss_gssd_client(); 69*13870d5dSRick Macklem if (cl == NULL) 70*13870d5dSRick Macklem return (GSS_S_FAILURE); 71a9148abdSDoug Rabson 72a9148abdSDoug Rabson bzero(&res, sizeof(res)); 73*13870d5dSRick Macklem stat = gssd_delete_sec_context_1(&args, &res, cl); 74*13870d5dSRick Macklem CLNT_RELEASE(cl); 75a9148abdSDoug Rabson if (stat != RPC_SUCCESS) { 76a9148abdSDoug Rabson *minor_status = stat; 77a9148abdSDoug Rabson return (GSS_S_FAILURE); 78a9148abdSDoug Rabson } 79a9148abdSDoug Rabson 80a9148abdSDoug Rabson if (output_token) 81a9148abdSDoug Rabson kgss_copy_buffer(&res.output_token, 82a9148abdSDoug Rabson output_token); 83a9148abdSDoug Rabson xdr_free((xdrproc_t) xdr_delete_sec_context_res, &res); 84a9148abdSDoug Rabson 85a9148abdSDoug Rabson kgss_delete_context(ctx, NULL); 86a9148abdSDoug Rabson } else { 87a9148abdSDoug Rabson kgss_delete_context(ctx, output_token); 88a9148abdSDoug Rabson } 89a9148abdSDoug Rabson *context_handle = NULL; 90a9148abdSDoug Rabson } else { 91a9148abdSDoug Rabson if (output_token) { 92a9148abdSDoug Rabson output_token->length = 0; 93a9148abdSDoug Rabson output_token->value = NULL; 94a9148abdSDoug Rabson } 95a9148abdSDoug Rabson } 96a9148abdSDoug Rabson 97a9148abdSDoug Rabson return (GSS_S_COMPLETE); 98a9148abdSDoug Rabson } 99