2 * Error handling for Kerberos.
4 * Provides versions of die and warn that take a Kerberos context and a
5 * Kerberos error code and append the Kerberos error message to the provided
8 * The canonical version of this file is maintained in the rra-c-util package,
9 * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
11 * Written by Russ Allbery <eagle@eyrie.org>
12 * Copyright 2006-2010, 2013
13 * The Board of Trustees of the Leland Stanford Junior University
15 * Permission is hereby granted, free of charge, to any person obtaining a
16 * copy of this software and associated documentation files (the "Software"),
17 * to deal in the Software without restriction, including without limitation
18 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 * and/or sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following conditions:
22 * The above copyright notice and this permission notice shall be included in
23 * all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31 * DEALINGS IN THE SOFTWARE.
33 * SPDX-License-Identifier: MIT
37 #include <portable/krb5.h>
38 #include <portable/system.h>
40 #include <util/messages-krb5.h>
41 #include <util/messages.h>
42 #include <util/xmalloc.h>
46 * Report a Kerberos error and exit.
49 die_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
51 const char *k5_msg = NULL;
56 k5_msg = krb5_get_error_message(ctx, code);
57 va_start(args, format);
58 xvasprintf(&message, format, args);
63 die("%s: %s", message, k5_msg);
68 * Report a Kerberos error.
71 warn_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
73 const char *k5_msg = NULL;
78 k5_msg = krb5_get_error_message(ctx, code);
79 va_start(args, format);
80 xvasprintf(&message, format, args);
85 warn("%s: %s", message, k5_msg);
88 krb5_free_error_message(ctx, k5_msg);