Path: blob/main/crypto/heimdal/appl/test/nt_gss_common.c
34870 views
/*1* Copyright (c) 1997, 1998, 1999 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*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* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "test_locl.h"34#include <gssapi.h>35#include "nt_gss_common.h"3637RCSID("$Id$");3839/*40* These are functions that are needed to interoperate with the41* `Sample SSPI Code' in Windows 2000 RC1 SDK.42*/4344/*45* Write the `gss_buffer_t' in `buf' onto the fd `sock', but remember that46* the length is written in little-endian-order.47*/4849void50nt_write_token (int sock, gss_buffer_t buf)51{52unsigned char net_len[4];53uint32_t len;54OM_uint32 min_stat;5556len = buf->length;5758net_len[0] = (len >> 0) & 0xFF;59net_len[1] = (len >> 8) & 0xFF;60net_len[2] = (len >> 16) & 0xFF;61net_len[3] = (len >> 24) & 0xFF;6263if (write (sock, net_len, 4) != 4)64err (1, "write");65if (write (sock, buf->value, len) != len)66err (1, "write");6768gss_release_buffer (&min_stat, buf);69}7071/*72*73*/7475void76nt_read_token (int sock, gss_buffer_t buf)77{78unsigned char net_len[4];79uint32_t len;8081if (read(sock, net_len, 4) != 4)82err (1, "read");83len = (net_len[0] << 0)84| (net_len[1] << 8)85| (net_len[2] << 16)86| (net_len[3] << 24);8788buf->length = len;89buf->value = malloc(len);90if (read (sock, buf->value, len) != len)91err (1, "read");92}9394void95gss_print_errors (int min_stat)96{97OM_uint32 new_stat;98OM_uint32 msg_ctx = 0;99gss_buffer_desc status_string;100OM_uint32 ret;101102do {103ret = gss_display_status (&new_stat,104min_stat,105GSS_C_MECH_CODE,106GSS_C_NO_OID,107&msg_ctx,108&status_string);109fprintf (stderr, "%.*s\n",110(int)status_string.length,111(char *)status_string.value);112gss_release_buffer (&new_stat, &status_string);113} while (!GSS_ERROR(ret) && msg_ctx != 0);114}115116void117gss_verr(int exitval, int status, const char *fmt, va_list ap)118{119vwarnx (fmt, ap);120gss_print_errors (status);121exit (exitval);122}123124void125gss_err(int exitval, int status, const char *fmt, ...)126{127va_list args;128129va_start(args, fmt);130gss_verr (exitval, status, fmt, args);131va_end(args);132}133134135