1178825Sdfr/*
2233294Sstas * Copyright (c) 2006 - 2008 Kungliga Tekniska H��gskolan
3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden).
4233294Sstas * All rights reserved.
5178825Sdfr *
6233294Sstas * Redistribution and use in source and binary forms, with or without
7233294Sstas * modification, are permitted provided that the following conditions
8233294Sstas * are met:
9178825Sdfr *
10233294Sstas * 1. Redistributions of source code must retain the above copyright
11233294Sstas *    notice, this list of conditions and the following disclaimer.
12178825Sdfr *
13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
14233294Sstas *    notice, this list of conditions and the following disclaimer in the
15233294Sstas *    documentation and/or other materials provided with the distribution.
16178825Sdfr *
17178825Sdfr * 3. Neither the name of KTH nor the names of its contributors may be
18178825Sdfr *    used to endorse or promote products derived from this software without
19178825Sdfr *    specific prior written permission.
20178825Sdfr *
21178825Sdfr * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22178825Sdfr * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23178825Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24178825Sdfr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25178825Sdfr * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26178825Sdfr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27178825Sdfr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28178825Sdfr * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29178825Sdfr * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30178825Sdfr * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31178825Sdfr * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32178825Sdfr */
33178825Sdfr
34178825Sdfr#include "krb5/gsskrb5_locl.h"
35178825Sdfr#include <err.h>
36178825Sdfr#include "test_common.h"
37178825Sdfr
38178825Sdfrchar *
39178825Sdfrgssapi_err(OM_uint32 maj_stat, OM_uint32 min_stat, gss_OID mech)
40178825Sdfr{
41178825Sdfr	OM_uint32 disp_min_stat, disp_maj_stat;
42178825Sdfr	gss_buffer_desc maj_error_message;
43178825Sdfr	gss_buffer_desc min_error_message;
44178825Sdfr	OM_uint32 msg_ctx = 0;
45178825Sdfr
46178825Sdfr	char *ret = NULL;
47178825Sdfr
48178825Sdfr	maj_error_message.length = 0;
49178825Sdfr	maj_error_message.value = NULL;
50178825Sdfr	min_error_message.length = 0;
51178825Sdfr	min_error_message.value = NULL;
52233294Sstas
53233294Sstas	disp_maj_stat = gss_display_status(&disp_min_stat, maj_stat,
54178825Sdfr					   GSS_C_GSS_CODE,
55178825Sdfr					   mech, &msg_ctx, &maj_error_message);
56178825Sdfr	disp_maj_stat = gss_display_status(&disp_min_stat, min_stat,
57178825Sdfr					   GSS_C_MECH_CODE,
58178825Sdfr					   mech, &msg_ctx, &min_error_message);
59233294Sstas	if (asprintf(&ret, "gss-code: %lu %.*s -- mech-code: %lu %.*s",
60233294Sstas		     (unsigned long)maj_stat,
61233294Sstas		     (int)maj_error_message.length,
62233294Sstas		     (char *)maj_error_message.value,
63233294Sstas		     (unsigned long)min_stat,
64233294Sstas		     (int)min_error_message.length,
65233294Sstas		     (char *)min_error_message.value) < 0 || ret == NULL)
66233294Sstas	    errx(1, "malloc");
67178825Sdfr
68178825Sdfr	gss_release_buffer(&disp_min_stat, &maj_error_message);
69178825Sdfr	gss_release_buffer(&disp_min_stat, &min_error_message);
70178825Sdfr
71178825Sdfr	return ret;
72178825Sdfr}
73178825Sdfr
74