test_common.c revision 303975
121495Sjmacd/* 221495Sjmacd * Copyright (c) 2006 - 2008 Kungliga Tekniska H��gskolan 321495Sjmacd * (Royal Institute of Technology, Stockholm, Sweden). 421495Sjmacd * All rights reserved. 521495Sjmacd * 621495Sjmacd * Redistribution and use in source and binary forms, with or without 721495Sjmacd * modification, are permitted provided that the following conditions 821495Sjmacd * are met: 921495Sjmacd * 1021495Sjmacd * 1. Redistributions of source code must retain the above copyright 1121495Sjmacd * notice, this list of conditions and the following disclaimer. 1221495Sjmacd * 1321495Sjmacd * 2. Redistributions in binary form must reproduce the above copyright 1421495Sjmacd * notice, this list of conditions and the following disclaimer in the 1521495Sjmacd * documentation and/or other materials provided with the distribution. 1621495Sjmacd * 1721495Sjmacd * 3. Neither the name of KTH nor the names of its contributors may be 1821495Sjmacd * used to endorse or promote products derived from this software without 1921495Sjmacd * specific prior written permission. 2021495Sjmacd * 2121495Sjmacd * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY 2221495Sjmacd * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2321495Sjmacd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2442660Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE 2542660Smarkm * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2621495Sjmacd * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2742660Smarkm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2821495Sjmacd * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2921495Sjmacd * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3021495Sjmacd * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3121495Sjmacd * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3221495Sjmacd */ 3321495Sjmacd 3421495Sjmacd#include "krb5/gsskrb5_locl.h" 3521495Sjmacd#include <err.h> 3621495Sjmacd#include "test_common.h" 3721495Sjmacd 3821495Sjmacdchar * 3921495Sjmacdgssapi_err(OM_uint32 maj_stat, OM_uint32 min_stat, gss_OID mech) 4021495Sjmacd{ 4121495Sjmacd OM_uint32 disp_min_stat, disp_maj_stat; 4221495Sjmacd gss_buffer_desc maj_error_message; 4321495Sjmacd gss_buffer_desc min_error_message; 4421495Sjmacd OM_uint32 msg_ctx = 0; 4521495Sjmacd 4621495Sjmacd char *ret = NULL; 4721495Sjmacd 4821495Sjmacd maj_error_message.length = 0; 4921495Sjmacd maj_error_message.value = NULL; 5042660Smarkm min_error_message.length = 0; 51 min_error_message.value = NULL; 52 53 disp_maj_stat = gss_display_status(&disp_min_stat, maj_stat, 54 GSS_C_GSS_CODE, 55 mech, &msg_ctx, &maj_error_message); 56 disp_maj_stat = gss_display_status(&disp_min_stat, min_stat, 57 GSS_C_MECH_CODE, 58 mech, &msg_ctx, &min_error_message); 59 if (asprintf(&ret, "gss-code: %lu %.*s -- mech-code: %lu %.*s", 60 (unsigned long)maj_stat, 61 (int)maj_error_message.length, 62 (char *)maj_error_message.value, 63 (unsigned long)min_stat, 64 (int)min_error_message.length, 65 (char *)min_error_message.value) < 0 || ret == NULL) 66 errx(1, "malloc"); 67 68 gss_release_buffer(&disp_min_stat, &maj_error_message); 69 gss_release_buffer(&disp_min_stat, &min_error_message); 70 71 return ret; 72} 73 74