LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/gssapi/mech - gss_export_sec_context.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 0 78 0.0 %
Date: 2024-04-21 15:09:00 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*-
       2             :  * Copyright (c) 2005 Doug Rabson
       3             :  * All rights reserved.
       4             :  *
       5             :  * Redistribution and use in source and binary forms, with or without
       6             :  * modification, are permitted provided that the following conditions
       7             :  * are met:
       8             :  * 1. Redistributions of source code must retain the above copyright
       9             :  *    notice, this list of conditions and the following disclaimer.
      10             :  * 2. Redistributions in binary form must reproduce the above copyright
      11             :  *    notice, this list of conditions and the following disclaimer in the
      12             :  *    documentation and/or other materials provided with the distribution.
      13             :  *
      14             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
      15             :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      16             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      17             :  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
      18             :  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      19             :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      20             :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      21             :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      22             :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      23             :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      24             :  * SUCH DAMAGE.
      25             :  *
      26             :  *      $FreeBSD: src/lib/libgssapi/gss_export_sec_context.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
      27             :  */
      28             : 
      29             : #include "mech_locl.h"
      30             : 
      31             : GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
      32           0 : gss_export_sec_context(OM_uint32 *minor_status,
      33             :     gss_ctx_id_t *context_handle,
      34             :     gss_buffer_t interprocess_token)
      35             : {
      36           0 :         OM_uint32 major_status = GSS_S_FAILURE, tmp_minor;
      37           0 :         krb5_storage *sp;
      38           0 :         krb5_data data;
      39           0 :         krb5_error_code kret;
      40           0 :         struct _gss_context *ctx;
      41           0 :         gssapi_mech_interface m;
      42           0 :         gss_buffer_desc buf = GSS_C_EMPTY_BUFFER;
      43           0 :         unsigned char verflags;
      44             : 
      45           0 :         *minor_status = 0;
      46             : 
      47           0 :         if (!interprocess_token)
      48           0 :             return GSS_S_CALL_INACCESSIBLE_READ;
      49             : 
      50           0 :         _mg_buffer_zero(interprocess_token);
      51             : 
      52           0 :         if (context_handle == NULL)
      53           0 :             return GSS_S_NO_CONTEXT;
      54             : 
      55           0 :         ctx = (struct _gss_context *) *context_handle;
      56           0 :         if (ctx == NULL)
      57           0 :             return GSS_S_NO_CONTEXT;
      58             : 
      59           0 :         sp = krb5_storage_emem();
      60           0 :         if (sp == NULL) {
      61           0 :             *minor_status = ENOMEM;
      62           0 :             goto failure;
      63             :         }
      64           0 :         krb5_storage_set_byteorder(sp, KRB5_STORAGE_BYTEORDER_PACKED);
      65             : 
      66           0 :         verflags = 0x00;                /* Version 0 */
      67             : 
      68           0 :         if (ctx->gc_target_len)
      69           0 :             verflags |= EXPORT_CONTEXT_FLAG_ACCUMULATING;
      70             : 
      71           0 :         if (ctx->gc_ctx)
      72           0 :             verflags |= EXPORT_CONTEXT_FLAG_MECH_CTX;
      73             : 
      74           0 :         kret = krb5_store_uint8(sp, verflags);
      75           0 :         if (kret) {
      76           0 :             *minor_status = kret;
      77           0 :             goto failure;
      78             :         }
      79             : 
      80           0 :         if (ctx->gc_target_len) {
      81           0 :             _gss_mg_log(10, "gss-esc: exporting partial token %zu/%zu",
      82             :                 ctx->gc_input.length, ctx->gc_target_len);
      83           0 :             kret = krb5_store_uint8(sp, ctx->gc_initial);
      84           0 :             if (kret) {
      85           0 :                 *minor_status = kret;
      86           0 :                 goto failure;
      87             :             }
      88           0 :             kret = krb5_store_uint32(sp, ctx->gc_target_len);
      89           0 :             if (kret) {
      90           0 :                 *minor_status = kret;
      91           0 :                 goto failure;
      92             :             }
      93           0 :             major_status = _gss_mg_store_buffer(minor_status, sp,
      94           0 :                                                 &ctx->gc_input);
      95           0 :             if (major_status != GSS_S_COMPLETE)
      96           0 :                 goto failure;
      97           0 :         } else if (ctx->gc_ctx == GSS_C_NO_CONTEXT) {
      98           0 :             gss_delete_sec_context(&tmp_minor, context_handle,
      99             :                                    GSS_C_NO_BUFFER);
     100           0 :             return GSS_S_NO_CONTEXT;
     101             :         }
     102             : 
     103           0 :         if (ctx->gc_ctx) {
     104           0 :             m = ctx->gc_mech;
     105             : 
     106           0 :             major_status = m->gm_export_sec_context(minor_status,
     107             :                                                     &ctx->gc_ctx, &buf);
     108             : 
     109           0 :             if (major_status != GSS_S_COMPLETE) {
     110           0 :                 _gss_mg_error(m, *minor_status);
     111           0 :                 goto failure;
     112             :             }
     113             : 
     114           0 :             major_status = _gss_mg_store_oid(minor_status, sp,
     115           0 :                                              &m->gm_mech_oid);
     116           0 :             if (major_status != GSS_S_COMPLETE)
     117           0 :                 goto failure;
     118             : 
     119           0 :             major_status = _gss_mg_store_buffer(minor_status, sp, &buf);
     120           0 :             if (major_status != GSS_S_COMPLETE)
     121           0 :                 goto failure;
     122             :         }
     123             : 
     124           0 :         kret = krb5_storage_to_data(sp, &data);
     125           0 :         if (kret) {
     126           0 :             *minor_status = kret;
     127           0 :             goto failure;
     128             :         }
     129             : 
     130           0 :         interprocess_token->length = data.length;
     131           0 :         interprocess_token->value  = data.data;
     132             : 
     133           0 :         major_status = GSS_S_COMPLETE;
     134             : 
     135           0 :         _gss_mg_log(1, "gss-esc: token length %zu", data.length);
     136             : 
     137           0 : failure:
     138           0 :         if (major_status == GSS_S_COMPLETE && *minor_status == 0)
     139           0 :             gss_delete_sec_context(&tmp_minor, context_handle,
     140             :                                    GSS_C_NO_BUFFER);
     141           0 :         else if (*minor_status)
     142           0 :             major_status = GSS_S_FAILURE;
     143             : 
     144           0 :         _gss_secure_release_buffer(minor_status, &buf);
     145           0 :         krb5_storage_free(sp);
     146           0 :         return major_status;
     147             : }

Generated by: LCOV version 1.14