d47accad |
1 | #include "putty.h" |
bf84a03a |
2 | #ifndef NO_GSSAPI |
b3d375b2 |
3 | #include "pgssapi.h" |
42af6a67 |
4 | #include "sshgss.h" |
b3d375b2 |
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) |
42af6a67 |
35 | { |
b3d375b2 |
36 | lib->id = id; |
37 | lib->gsslogmsg = msg; |
42af6a67 |
38 | |
b3d375b2 |
39 | #define BIND_GSS_FN(name) \ |
40 | lib->u.gssapi.name = (t_gss_##name) dlsym(dlhandle, "gss_" #name) |
42af6a67 |
41 | |
b3d375b2 |
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); |
42af6a67 |
50 | |
b3d375b2 |
51 | #undef BIND_GSS_FN |
42af6a67 |
52 | |
b3d375b2 |
53 | ssh_gssapi_bind_fns(lib); |
42af6a67 |
54 | } |
55 | |
b3d375b2 |
56 | /* Dynamically load gssapi libs. */ |
57 | void ssh_gss_init(void) |
42af6a67 |
58 | { |
b3d375b2 |
59 | void *gsslib; |
42af6a67 |
60 | |
b3d375b2 |
61 | if (initialised) return; |
62 | initialised = TRUE; |
42af6a67 |
63 | |
b3d375b2 |
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"); |
42af6a67 |
68 | |
b3d375b2 |
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"); |
42af6a67 |
73 | |
b3d375b2 |
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"); |
42af6a67 |
78 | } |
79 | |
b3d375b2 |
80 | #else /* NO_LIBDL */ |
42af6a67 |
81 | |
b3d375b2 |
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 | */ |
42af6a67 |
87 | |
b3d375b2 |
88 | #include <gssapi/gssapi.h> |
42af6a67 |
89 | |
b3d375b2 |
90 | /* Dynamically load gssapi libs. */ |
91 | void ssh_gss_init(void) |
42af6a67 |
92 | { |
b3d375b2 |
93 | if (initialised) return; |
94 | initialised = TRUE; |
42af6a67 |
95 | |
b3d375b2 |
96 | n_ssh_gss_libraries = 1; |
97 | ssh_gss_libraries[0].gsslogmsg = "Using statically linked GSSAPI"; |
42af6a67 |
98 | |
b3d375b2 |
99 | #define BIND_GSS_FN(name) \ |
100 | ssh_gss_libraries[0].u.gssapi.name = (t_gss_##name) gss_##name |
42af6a67 |
101 | |
b3d375b2 |
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); |
42af6a67 |
110 | |
b3d375b2 |
111 | #undef BIND_GSS_FN |
42af6a67 |
112 | |
b3d375b2 |
113 | ssh_gssapi_bind_fns(&ssh_gss_libraries[0]); |
42af6a67 |
114 | } |
115 | |
b3d375b2 |
116 | #endif /* NO_LIBDL */ |
117 | |
118 | #endif /* NO_GSSAPI */ |