2009-07-28 23:20:50 +00:00
|
|
|
#include "putty.h"
|
2008-12-02 18:18:32 +00:00
|
|
|
#ifndef NO_GSSAPI
|
2010-05-19 18:22:17 +00:00
|
|
|
#include "pgssapi.h"
|
2008-08-10 13:10:31 +00:00
|
|
|
#include "sshgss.h"
|
2010-05-19 18:22:17 +00:00
|
|
|
#include "sshgssc.h"
|
|
|
|
|
|
|
|
/* Unix code to set up the GSSAPI library list. */
|
|
|
|
|
|
|
|
struct ssh_gss_library ssh_gss_libraries[3];
|
|
|
|
int n_ssh_gss_libraries = 0;
|
|
|
|
static int initialised = FALSE;
|
|
|
|
|
|
|
|
const int ngsslibs = 3;
|
|
|
|
const char *const gsslibnames[3] = {
|
|
|
|
"libgssapi (Heimdal)",
|
|
|
|
"libgssapi_krb5 (MIT Kerberos)",
|
|
|
|
"libgss (Sun)",
|
|
|
|
};
|
|
|
|
const struct keyval gsslibkeywords[] = {
|
|
|
|
{ "libgssapi", 0 },
|
|
|
|
{ "libgssapi_krb5", 1 },
|
|
|
|
{ "libgss", 2 },
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef NO_LIBDL
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run-time binding against a choice of GSSAPI implementations. We
|
|
|
|
* try loading several libraries, and produce an entry in
|
|
|
|
* ssh_gss_libraries[] for each one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void gss_init(struct ssh_gss_library *lib, void *dlhandle,
|
|
|
|
int id, const char *msg)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
2010-05-19 18:22:17 +00:00
|
|
|
lib->id = id;
|
|
|
|
lib->gsslogmsg = msg;
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#define BIND_GSS_FN(name) \
|
|
|
|
lib->u.gssapi.name = (t_gss_##name) dlsym(dlhandle, "gss_" #name)
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
BIND_GSS_FN(delete_sec_context);
|
|
|
|
BIND_GSS_FN(display_status);
|
|
|
|
BIND_GSS_FN(get_mic);
|
|
|
|
BIND_GSS_FN(import_name);
|
|
|
|
BIND_GSS_FN(init_sec_context);
|
|
|
|
BIND_GSS_FN(release_buffer);
|
|
|
|
BIND_GSS_FN(release_cred);
|
|
|
|
BIND_GSS_FN(release_name);
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#undef BIND_GSS_FN
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
ssh_gssapi_bind_fns(lib);
|
2008-08-10 13:10:31 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
/* Dynamically load gssapi libs. */
|
|
|
|
void ssh_gss_init(void)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
2010-05-19 18:22:17 +00:00
|
|
|
void *gsslib;
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
if (initialised) return;
|
|
|
|
initialised = TRUE;
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
/* Heimdal's GSSAPI Library */
|
|
|
|
if ((gsslib = dlopen("libgssapi.so.2", RTLD_LAZY)) != NULL)
|
|
|
|
gss_init(&ssh_gss_libraries[n_ssh_gss_libraries++], gsslib,
|
|
|
|
0, "Using GSSAPI from libgssapi.so.2");
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
/* MIT Kerberos's GSSAPI Library */
|
|
|
|
if ((gsslib = dlopen("libgssapi_krb5.so.2", RTLD_LAZY)) != NULL)
|
|
|
|
gss_init(&ssh_gss_libraries[n_ssh_gss_libraries++], gsslib,
|
|
|
|
1, "Using GSSAPI from libgssapi_krb5.so.2");
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
/* Sun's GSSAPI Library */
|
|
|
|
if ((gsslib = dlopen("libgss.so.1", RTLD_LAZY)) != NULL)
|
|
|
|
gss_init(&ssh_gss_libraries[n_ssh_gss_libraries++], gsslib,
|
|
|
|
2, "Using GSSAPI from libgss.so.1");
|
2008-08-10 13:10:31 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#else /* NO_LIBDL */
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
/*
|
|
|
|
* Link-time binding against GSSAPI. Here we just construct a single
|
|
|
|
* library structure containing pointers to the functions we linked
|
|
|
|
* against.
|
|
|
|
*/
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#include <gssapi/gssapi.h>
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
/* Dynamically load gssapi libs. */
|
|
|
|
void ssh_gss_init(void)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
2010-05-19 18:22:17 +00:00
|
|
|
if (initialised) return;
|
|
|
|
initialised = TRUE;
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
n_ssh_gss_libraries = 1;
|
|
|
|
ssh_gss_libraries[0].gsslogmsg = "Using statically linked GSSAPI";
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#define BIND_GSS_FN(name) \
|
|
|
|
ssh_gss_libraries[0].u.gssapi.name = (t_gss_##name) gss_##name
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
BIND_GSS_FN(delete_sec_context);
|
|
|
|
BIND_GSS_FN(display_status);
|
|
|
|
BIND_GSS_FN(get_mic);
|
|
|
|
BIND_GSS_FN(import_name);
|
|
|
|
BIND_GSS_FN(init_sec_context);
|
|
|
|
BIND_GSS_FN(release_buffer);
|
|
|
|
BIND_GSS_FN(release_cred);
|
|
|
|
BIND_GSS_FN(release_name);
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#undef BIND_GSS_FN
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
ssh_gssapi_bind_fns(&ssh_gss_libraries[0]);
|
2008-08-10 13:10:31 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#endif /* NO_LIBDL */
|
|
|
|
|
|
|
|
#endif /* NO_GSSAPI */
|