2 * Copyright (c) 2010 Your File System, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * - Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * - Neither the name of Your File System, Inc. nor the names of its contributors may be
11 * used to endorse or promote products derived from this software without
12 * specific prior written permission from Your File System, Inc.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
18 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <afsconfig.h>
28 #include <afs/param.h>
33 static char * (KRB5_CALLCONV *pkrb5_get_error_message)(krb5_context context, krb5_error_code code) = NULL;
34 static void (KRB5_CALLCONV *pkrb5_free_error_message)(krb5_context context, char *s) = NULL;
37 # define KRB5LIB "krb5_32.dll"
39 # define KRB5LIB "krb5_64.dll"
47 * On Windows, the error table will be initialized when the
48 * krb5 library is loaded into the process. Since not all
49 * versions of krb5 contain krb5_{get,free}_error_message()
50 * we load them conditionally by function pointer.
52 * On Unix, the MIT krb5 error table will be initialized
53 * by the library on first use.
55 * initialize_krb5_error_table is a macro substitution to
58 HINSTANCE h = LoadLibrary(KRB5LIB);
60 (FARPROC)pkrb5_get_error_message = GetProcAddress(h, "krb5_get_error_message");
61 (FARPROC)pkrb5_free_error_message = GetProcAddress(h, "krb5_free_error_message");
66 fetch_krb5_error_message(krb5_context context, krb5_error_code code)
68 static char errorText[1024];
70 if (pkrb5_get_error_message) {
71 char *msg = pkrb5_get_error_message(context, code);
73 strncpy(errorText, msg, sizeof(errorText));
74 errorText[sizeof(errorText)-1]='\0';
75 pkrb5_free_error_message(context, msg);