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>
34 # include <krb5\krb5.h>
37 static int krb5_initialized = 0;
43 * On Windows, the error table will be initialized when the
44 * krb5 library is loaded into the process for MIT KFW but
45 * for Heimdal the error table is initialized when the
46 * krb5_init_context() call is issued. We always build
47 * against the Kerberos Compat SDK now so we do not have
48 * load by function pointer. Use DelayLoadHeimd
50 * On Unix, the MIT krb5 error table will be initialized
51 * by the library on first use.
53 * initialize_krb5_error_table is a macro substitution to
56 if (!DelayLoadHeimdal()) {
57 fprintf(stderr, "Kerberos for Windows or Heimdal is not available.\n");
64 fetch_krb5_error_message(afs_uint32 code)
66 static char errorText[1024];
70 if (krb5_initialized && krb5_init_context(&context) == 0) {
71 msg = krb5_get_error_message(context, code);
73 strncpy(errorText, msg, sizeof(errorText));
74 errorText[sizeof(errorText)-1]='\0';
75 krb5_free_error_message(context, msg);
78 krb5_free_context(context);