gss_delete_sec_context.c 3.0 KB

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