7 /* Unix code to set up the GSSAPI library list. */
9 #if !defined NO_LIBDL && !defined NO_GSSAPI
11 const int ngsslibs = 4;
12 const char *const gsslibnames[4] = {
13 "libgssapi (Heimdal)",
14 "libgssapi_krb5 (MIT Kerberos)",
16 "User-specified GSSAPI library",
18 const struct keyvalwhere gsslibkeywords[] = {
19 { "libgssapi", 0, -1, -1 },
20 { "libgssapi_krb5", 1, -1, -1 },
21 { "libgss", 2, -1, -1 },
22 { "custom", 3, -1, -1 },
26 * Run-time binding against a choice of GSSAPI implementations. We
27 * try loading several libraries, and produce an entry in
28 * ssh_gss_libraries[] for each one.
31 static void gss_init(struct ssh_gss_library *lib, void *dlhandle,
32 int id, const char *msg)
36 lib->handle = dlhandle;
38 #define BIND_GSS_FN(name) \
39 lib->u.gssapi.name = (t_gss_##name) dlsym(dlhandle, "gss_" #name)
41 BIND_GSS_FN(delete_sec_context);
42 BIND_GSS_FN(display_status);
44 BIND_GSS_FN(import_name);
45 BIND_GSS_FN(init_sec_context);
46 BIND_GSS_FN(release_buffer);
47 BIND_GSS_FN(release_cred);
48 BIND_GSS_FN(release_name);
52 ssh_gssapi_bind_fns(lib);
55 /* Dynamically load gssapi libs. */
56 struct ssh_gss_liblist *ssh_gss_setup(Conf *conf)
60 struct ssh_gss_liblist *list = snew(struct ssh_gss_liblist);
62 list->libraries = snewn(4, struct ssh_gss_library);
65 /* Heimdal's GSSAPI Library */
66 if ((gsslib = dlopen("libgssapi.so.2", RTLD_LAZY)) != NULL)
67 gss_init(&list->libraries[list->nlibraries++], gsslib,
68 0, "Using GSSAPI from libgssapi.so.2");
70 /* MIT Kerberos's GSSAPI Library */
71 if ((gsslib = dlopen("libgssapi_krb5.so.2", RTLD_LAZY)) != NULL)
72 gss_init(&list->libraries[list->nlibraries++], gsslib,
73 1, "Using GSSAPI from libgssapi_krb5.so.2");
75 /* Sun's GSSAPI Library */
76 if ((gsslib = dlopen("libgss.so.1", RTLD_LAZY)) != NULL)
77 gss_init(&list->libraries[list->nlibraries++], gsslib,
78 2, "Using GSSAPI from libgss.so.1");
80 /* User-specified GSSAPI library */
81 gsspath = conf_get_filename(conf, CONF_ssh_gss_custom)->path;
82 if (*gsspath && (gsslib = dlopen(gsspath, RTLD_LAZY)) != NULL)
83 gss_init(&list->libraries[list->nlibraries++], gsslib,
84 3, dupprintf("Using GSSAPI from user-specified"
85 " library '%s'", gsspath));
90 void ssh_gss_cleanup(struct ssh_gss_liblist *list)
95 * dlopen and dlclose are defined to employ reference counting
96 * in the case where the same library is repeatedly dlopened, so
97 * even in a multiple-sessions-per-process context it's safe to
98 * naively dlclose everything here without worrying about
99 * destroying it under the feet of another SSH instance still
102 for (i = 0; i < list->nlibraries; i++) {
103 dlclose(list->libraries[i].handle);
104 if (list->libraries[i].id == 3) {
105 /* The 'custom' id involves a dynamically allocated message.
106 * Note that we must cast away the 'const' to free it. */
107 sfree((char *)list->libraries[i].gsslogmsg);
110 sfree(list->libraries);
114 #elif !defined NO_GSSAPI
116 const int ngsslibs = 1;
117 const char *const gsslibnames[1] = {
120 const struct keyvalwhere gsslibkeywords[] = {
121 { "static", 0, -1, -1 },
125 * Link-time binding against GSSAPI. Here we just construct a single
126 * library structure containing pointers to the functions we linked
130 #include <gssapi/gssapi.h>
132 /* Dynamically load gssapi libs. */
133 struct ssh_gss_liblist *ssh_gss_setup(Conf *conf)
135 struct ssh_gss_liblist *list = snew(struct ssh_gss_liblist);
137 list->libraries = snew(struct ssh_gss_library);
138 list->nlibraries = 1;
140 list->libraries[0].gsslogmsg = "Using statically linked GSSAPI";
142 #define BIND_GSS_FN(name) \
143 list->libraries[0].u.gssapi.name = (t_gss_##name) gss_##name
145 BIND_GSS_FN(delete_sec_context);
146 BIND_GSS_FN(display_status);
147 BIND_GSS_FN(get_mic);
148 BIND_GSS_FN(import_name);
149 BIND_GSS_FN(init_sec_context);
150 BIND_GSS_FN(release_buffer);
151 BIND_GSS_FN(release_cred);
152 BIND_GSS_FN(release_name);
156 ssh_gssapi_bind_fns(&list->libraries[0]);
161 void ssh_gss_cleanup(struct ssh_gss_liblist *list)
163 sfree(list->libraries);
167 #endif /* NO_LIBDL */
169 #endif /* NO_GSSAPI */