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(const Config
*cfg
)
59 struct ssh_gss_liblist
*list
= snew(struct ssh_gss_liblist
);
61 list
->libraries
= snewn(4, struct ssh_gss_library
);
64 /* Heimdal's GSSAPI Library */
65 if ((gsslib
= dlopen("libgssapi.so.2", RTLD_LAZY
)) != NULL
)
66 gss_init(&list
->libraries
[list
->nlibraries
++], gsslib
,
67 0, "Using GSSAPI from libgssapi.so.2");
69 /* MIT Kerberos's GSSAPI Library */
70 if ((gsslib
= dlopen("libgssapi_krb5.so.2", RTLD_LAZY
)) != NULL
)
71 gss_init(&list
->libraries
[list
->nlibraries
++], gsslib
,
72 1, "Using GSSAPI from libgssapi_krb5.so.2");
74 /* Sun's GSSAPI Library */
75 if ((gsslib
= dlopen("libgss.so.1", RTLD_LAZY
)) != NULL
)
76 gss_init(&list
->libraries
[list
->nlibraries
++], gsslib
,
77 2, "Using GSSAPI from libgss.so.1");
79 /* User-specified GSSAPI library */
80 if (cfg
->ssh_gss_custom
.path
[0] &&
81 (gsslib
= dlopen(cfg
->ssh_gss_custom
.path
, RTLD_LAZY
)) != NULL
)
82 gss_init(&list
->libraries
[list
->nlibraries
++], gsslib
,
83 3, dupprintf("Using GSSAPI from user-specified"
84 " library '%s'", cfg
->ssh_gss_custom
.path
));
89 void ssh_gss_cleanup(struct ssh_gss_liblist
*list
)
94 * dlopen and dlclose are defined to employ reference counting
95 * in the case where the same library is repeatedly dlopened, so
96 * even in a multiple-sessions-per-process context it's safe to
97 * naively dlclose everything here without worrying about
98 * destroying it under the feet of another SSH instance still
101 for (i
= 0; i
< list
->nlibraries
; i
++) {
102 dlclose(list
->libraries
[i
].handle
);
103 if (list
->libraries
[i
].id
== 3) {
104 /* The 'custom' id involves a dynamically allocated message.
105 * Note that we must cast away the 'const' to free it. */
106 sfree((char *)list
->libraries
[i
].gsslogmsg
);
109 sfree(list
->libraries
);
113 #elif !defined NO_GSSAPI
115 const int ngsslibs
= 1;
116 const char *const gsslibnames
[1] = {
119 const struct keyvalwhere gsslibkeywords
[] = {
120 { "static", 0, -1, -1 },
124 * Link-time binding against GSSAPI. Here we just construct a single
125 * library structure containing pointers to the functions we linked
129 #include <gssapi/gssapi.h>
131 /* Dynamically load gssapi libs. */
132 struct ssh_gss_liblist
*ssh_gss_setup(const Config
*cfg
)
134 struct ssh_gss_liblist
*list
= snew(struct ssh_gss_liblist
);
136 list
->libraries
= snew(struct ssh_gss_library
);
137 list
->nlibraries
= 1;
139 list
->libraries
[0].gsslogmsg
= "Using statically linked GSSAPI";
141 #define BIND_GSS_FN(name) \
142 list->libraries[0].u.gssapi.name = (t_gss_##name) gss_##name
144 BIND_GSS_FN(delete_sec_context
);
145 BIND_GSS_FN(display_status
);
146 BIND_GSS_FN(get_mic
);
147 BIND_GSS_FN(import_name
);
148 BIND_GSS_FN(init_sec_context
);
149 BIND_GSS_FN(release_buffer
);
150 BIND_GSS_FN(release_cred
);
151 BIND_GSS_FN(release_name
);
155 ssh_gssapi_bind_fns(&list
->libraries
[0]);
160 void ssh_gss_cleanup(struct ssh_gss_liblist
*list
)
162 sfree(list
->libraries
);
166 #endif /* NO_LIBDL */
168 #endif /* NO_GSSAPI */