1 | /* |
---|
2 | * Shared GSS-API error handling code. |
---|
3 | * |
---|
4 | * Helper functions to interpret GSS-API errors that can be shared between the |
---|
5 | * client and the server. |
---|
6 | * |
---|
7 | * Written by Russ Allbery <rra@stanford.edu> |
---|
8 | * Copyright 2007 Board of Trustees, Leland Stanford Jr. University |
---|
9 | * |
---|
10 | * See LICENSE for licensing terms. |
---|
11 | */ |
---|
12 | |
---|
13 | #include <config.h> |
---|
14 | #include <portable/system.h> |
---|
15 | #include <portable/gssapi.h> |
---|
16 | |
---|
17 | #include <util/util.h> |
---|
18 | |
---|
19 | |
---|
20 | /* |
---|
21 | * Turn a GSS-API error code pair into a human-readable string, prefixed with |
---|
22 | * "GSS-API error" and the provided string. Uses gss_display_status to get |
---|
23 | * the internal error message. Returns a newly allocated string that the |
---|
24 | * caller must free. |
---|
25 | */ |
---|
26 | char * |
---|
27 | gssapi_error_string(const char *prefix, OM_uint32 major, OM_uint32 minor) |
---|
28 | { |
---|
29 | char *string, *old; |
---|
30 | gss_buffer_desc msg; |
---|
31 | OM_uint32 msg_ctx, status; |
---|
32 | |
---|
33 | string = NULL; |
---|
34 | msg_ctx = 0; |
---|
35 | do { |
---|
36 | gss_display_status(&status, major, GSS_C_GSS_CODE, |
---|
37 | (const gss_OID) GSS_KRB5_MECHANISM, |
---|
38 | &msg_ctx, &msg); |
---|
39 | if (string != NULL) { |
---|
40 | old = string; |
---|
41 | string = concat(string, ", ", msg.value, (char *) 0); |
---|
42 | free(old); |
---|
43 | } else { |
---|
44 | string = concat("GSS-API error ", prefix, ": ", msg.value, |
---|
45 | (char *) 0); |
---|
46 | } |
---|
47 | } while (msg_ctx != 0); |
---|
48 | if (minor != 0) { |
---|
49 | msg_ctx = 0; |
---|
50 | do { |
---|
51 | gss_display_status(&status, minor, GSS_C_MECH_CODE, |
---|
52 | (const gss_OID) GSS_KRB5_MECHANISM, &msg_ctx, |
---|
53 | &msg); |
---|
54 | old = string; |
---|
55 | string = concat(string, ", ", msg.value, (char *) 0); |
---|
56 | free(old); |
---|
57 | } while (msg_ctx != 0); |
---|
58 | } |
---|
59 | return string; |
---|
60 | } |
---|