| 1 | #include "putty.h" |
| 2 | #ifndef NO_GSSAPI |
| 3 | #include "pgssapi.h" |
| 4 | #include "sshgss.h" |
| 5 | #include "sshgssc.h" |
| 6 | |
| 7 | /* Unix code to set up the GSSAPI library list. */ |
| 8 | |
| 9 | struct ssh_gss_library ssh_gss_libraries[3]; |
| 10 | int n_ssh_gss_libraries = 0; |
| 11 | static int initialised = FALSE; |
| 12 | |
| 13 | const int ngsslibs = 3; |
| 14 | const char *const gsslibnames[3] = { |
| 15 | "libgssapi (Heimdal)", |
| 16 | "libgssapi_krb5 (MIT Kerberos)", |
| 17 | "libgss (Sun)", |
| 18 | }; |
| 19 | const struct keyval gsslibkeywords[] = { |
| 20 | { "libgssapi", 0 }, |
| 21 | { "libgssapi_krb5", 1 }, |
| 22 | { "libgss", 2 }, |
| 23 | }; |
| 24 | |
| 25 | #ifndef NO_LIBDL |
| 26 | |
| 27 | /* |
| 28 | * Run-time binding against a choice of GSSAPI implementations. We |
| 29 | * try loading several libraries, and produce an entry in |
| 30 | * ssh_gss_libraries[] for each one. |
| 31 | */ |
| 32 | |
| 33 | static void gss_init(struct ssh_gss_library *lib, void *dlhandle, |
| 34 | int id, const char *msg) |
| 35 | { |
| 36 | lib->id = id; |
| 37 | lib->gsslogmsg = msg; |
| 38 | |
| 39 | #define BIND_GSS_FN(name) \ |
| 40 | lib->u.gssapi.name = (t_gss_##name) dlsym(dlhandle, "gss_" #name) |
| 41 | |
| 42 | BIND_GSS_FN(delete_sec_context); |
| 43 | BIND_GSS_FN(display_status); |
| 44 | BIND_GSS_FN(get_mic); |
| 45 | BIND_GSS_FN(import_name); |
| 46 | BIND_GSS_FN(init_sec_context); |
| 47 | BIND_GSS_FN(release_buffer); |
| 48 | BIND_GSS_FN(release_cred); |
| 49 | BIND_GSS_FN(release_name); |
| 50 | |
| 51 | #undef BIND_GSS_FN |
| 52 | |
| 53 | ssh_gssapi_bind_fns(lib); |
| 54 | } |
| 55 | |
| 56 | /* Dynamically load gssapi libs. */ |
| 57 | void ssh_gss_init(void) |
| 58 | { |
| 59 | void *gsslib; |
| 60 | |
| 61 | if (initialised) return; |
| 62 | initialised = TRUE; |
| 63 | |
| 64 | /* Heimdal's GSSAPI Library */ |
| 65 | if ((gsslib = dlopen("libgssapi.so.2", RTLD_LAZY)) != NULL) |
| 66 | gss_init(&ssh_gss_libraries[n_ssh_gss_libraries++], gsslib, |
| 67 | 0, "Using GSSAPI from libgssapi.so.2"); |
| 68 | |
| 69 | /* MIT Kerberos's GSSAPI Library */ |
| 70 | if ((gsslib = dlopen("libgssapi_krb5.so.2", RTLD_LAZY)) != NULL) |
| 71 | gss_init(&ssh_gss_libraries[n_ssh_gss_libraries++], gsslib, |
| 72 | 1, "Using GSSAPI from libgssapi_krb5.so.2"); |
| 73 | |
| 74 | /* Sun's GSSAPI Library */ |
| 75 | if ((gsslib = dlopen("libgss.so.1", RTLD_LAZY)) != NULL) |
| 76 | gss_init(&ssh_gss_libraries[n_ssh_gss_libraries++], gsslib, |
| 77 | 2, "Using GSSAPI from libgss.so.1"); |
| 78 | } |
| 79 | |
| 80 | #else /* NO_LIBDL */ |
| 81 | |
| 82 | /* |
| 83 | * Link-time binding against GSSAPI. Here we just construct a single |
| 84 | * library structure containing pointers to the functions we linked |
| 85 | * against. |
| 86 | */ |
| 87 | |
| 88 | #include <gssapi/gssapi.h> |
| 89 | |
| 90 | /* Dynamically load gssapi libs. */ |
| 91 | void ssh_gss_init(void) |
| 92 | { |
| 93 | if (initialised) return; |
| 94 | initialised = TRUE; |
| 95 | |
| 96 | n_ssh_gss_libraries = 1; |
| 97 | ssh_gss_libraries[0].gsslogmsg = "Using statically linked GSSAPI"; |
| 98 | |
| 99 | #define BIND_GSS_FN(name) \ |
| 100 | ssh_gss_libraries[0].u.gssapi.name = (t_gss_##name) gss_##name |
| 101 | |
| 102 | BIND_GSS_FN(delete_sec_context); |
| 103 | BIND_GSS_FN(display_status); |
| 104 | BIND_GSS_FN(get_mic); |
| 105 | BIND_GSS_FN(import_name); |
| 106 | BIND_GSS_FN(init_sec_context); |
| 107 | BIND_GSS_FN(release_buffer); |
| 108 | BIND_GSS_FN(release_cred); |
| 109 | BIND_GSS_FN(release_name); |
| 110 | |
| 111 | #undef BIND_GSS_FN |
| 112 | |
| 113 | ssh_gssapi_bind_fns(&ssh_gss_libraries[0]); |
| 114 | } |
| 115 | |
| 116 | #endif /* NO_LIBDL */ |
| 117 | |
| 118 | #endif /* NO_GSSAPI */ |