From c9ed85e55b80d5c7d2a422437ae59672b8da6c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20R.=20Sede=C3=B1o?= Date: Sat, 6 Feb 2010 17:50:35 -0500 Subject: [PATCH 06/13] Fix the windows build Windows build works with GSSAPI as well as SSPI. We try MIT KfW's GSSAPI first, then fall back to MS SSPI. --- windows/wingss.c | 53 +++++++++++++++++++++++++++++++++++++++++---------- windows/wingss.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++ windows/winstuff.h | 10 ++++++++- 3 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 windows/wingss.h diff --git a/windows/wingss.c b/windows/wingss.c index a16db03..c5ae06c 100644 --- a/windows/wingss.c +++ b/windows/wingss.c @@ -5,7 +5,7 @@ #define SECURITY_WIN32 #include -#include "sshgss.h" +#include "wingss.h" #include "misc.h" DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS, @@ -47,11 +47,41 @@ typedef struct winSsh_gss_ctx { const Ssh_gss_buf gss_mech_krb5={9,"\x2A\x86\x48\x86\xF7\x12\x01\x02\x02"}; +void ssh_sspi_bind_fns(void) +{ + BIND_SSH_GSS_FN(indicate_mech, sspi); + BIND_SSH_GSS_FN(import_name, sspi); + BIND_SSH_GSS_FN(release_name, sspi); + BIND_SSH_GSS_FN(init_sec_context, sspi); + BIND_SSH_GSS_FN(free_tok, sspi); + BIND_SSH_GSS_FN(acquire_cred, sspi); + BIND_SSH_GSS_FN(release_cred, sspi); + BIND_SSH_GSS_FN(get_mic, sspi); + BIND_SSH_GSS_FN(free_mic, sspi); + BIND_SSH_GSS_FN(display_status, sspi); +} + int ssh_gss_init(void) { if (security_module) return 1; /* already initialised */ + /* MIT Kerbers GSSAPI implementation */ + /* TODO: For 64-bit builds, check for gssapi64.dll */ + security_module = LoadLibrary("gssapi32.dll"); + if (security_module) { + BIND_GSS_FN(security_module, gss_delete_sec_context); + BIND_GSS_FN(security_module, gss_display_status); + BIND_GSS_FN(security_module, gss_get_mic); + BIND_GSS_FN(security_module, gss_import_name); + BIND_GSS_FN(security_module, gss_init_sec_context); + BIND_GSS_FN(security_module, gss_release_buffer); + BIND_GSS_FN(security_module, gss_release_cred); + BIND_GSS_FN(security_module, gss_release_name); + ssh_gssapi_bind_fns(); + return 1; + } + /* Microsoft SSPI Implementation */ security_module = LoadLibrary("secur32.dll"); if (security_module) { GET_WINDOWS_FUNCTION(security_module, AcquireCredentialsHandleA); @@ -61,19 +91,20 @@ int ssh_gss_init(void) GET_WINDOWS_FUNCTION(security_module, DeleteSecurityContext); GET_WINDOWS_FUNCTION(security_module, QueryContextAttributesA); GET_WINDOWS_FUNCTION(security_module, MakeSignature); + ssh_sspi_bind_fns(); return 1; } return 0; } -Ssh_gss_stat ssh_gss_indicate_mech(Ssh_gss_buf *mech) +Ssh_gss_stat ssh_sspi_indicate_mech(Ssh_gss_buf *mech) { *mech = gss_mech_krb5; return SSH_GSS_OK; } -Ssh_gss_stat ssh_gss_import_name(char *host, Ssh_gss_name *srv_name) +Ssh_gss_stat ssh_sspi_import_name(char *host, Ssh_gss_name *srv_name) { char *pStr; @@ -88,7 +119,7 @@ Ssh_gss_stat ssh_gss_import_name(char *host, Ssh_gss_name *srv_name) return SSH_GSS_OK; } -Ssh_gss_stat ssh_gss_acquire_cred(Ssh_gss_ctx *ctx) +Ssh_gss_stat ssh_sspi_acquire_cred(Ssh_gss_ctx *ctx) { winSsh_gss_ctx *winctx = snew(winSsh_gss_ctx); memset(winctx, 0, sizeof(winSsh_gss_ctx)); @@ -117,7 +148,7 @@ Ssh_gss_stat ssh_gss_acquire_cred(Ssh_gss_ctx *ctx) } -Ssh_gss_stat ssh_gss_init_sec_context(Ssh_gss_ctx *ctx, +Ssh_gss_stat ssh_sspi_init_sec_context(Ssh_gss_ctx *ctx, Ssh_gss_name srv_name, int to_deleg, Ssh_gss_buf *recv_tok, @@ -159,7 +190,7 @@ Ssh_gss_stat ssh_gss_init_sec_context(Ssh_gss_ctx *ctx, return SSH_GSS_FAILURE; } -Ssh_gss_stat ssh_gss_free_tok(Ssh_gss_buf *send_tok) +Ssh_gss_stat ssh_sspi_free_tok(Ssh_gss_buf *send_tok) { /* check input */ if (send_tok == NULL) return SSH_GSS_FAILURE; @@ -171,7 +202,7 @@ Ssh_gss_stat ssh_gss_free_tok(Ssh_gss_buf *send_tok) return SSH_GSS_OK; } -Ssh_gss_stat ssh_gss_release_cred(Ssh_gss_ctx *ctx) +Ssh_gss_stat ssh_sspi_release_cred(Ssh_gss_ctx *ctx) { winSsh_gss_ctx *winctx= (winSsh_gss_ctx *) *ctx; @@ -190,7 +221,7 @@ Ssh_gss_stat ssh_gss_release_cred(Ssh_gss_ctx *ctx) } -Ssh_gss_stat ssh_gss_release_name(Ssh_gss_name *srv_name) +Ssh_gss_stat ssh_sspi_release_name(Ssh_gss_name *srv_name) { char *pStr= (char *) *srv_name; @@ -201,7 +232,7 @@ Ssh_gss_stat ssh_gss_release_name(Ssh_gss_name *srv_name) return SSH_GSS_OK; } -Ssh_gss_stat ssh_gss_display_status(Ssh_gss_ctx ctx, Ssh_gss_buf *buf) +Ssh_gss_stat ssh_sspi_display_status(Ssh_gss_ctx ctx, Ssh_gss_buf *buf) { winSsh_gss_ctx *winctx = (winSsh_gss_ctx *) ctx; char *msg; @@ -251,7 +282,7 @@ Ssh_gss_stat ssh_gss_display_status(Ssh_gss_ctx ctx, Ssh_gss_buf *buf) return SSH_GSS_OK; } -Ssh_gss_stat ssh_gss_get_mic(Ssh_gss_ctx ctx, Ssh_gss_buf *buf, +Ssh_gss_stat ssh_sspi_get_mic(Ssh_gss_ctx ctx, Ssh_gss_buf *buf, Ssh_gss_buf *hash) { winSsh_gss_ctx *winctx= (winSsh_gss_ctx *) ctx; @@ -296,7 +327,7 @@ Ssh_gss_stat ssh_gss_get_mic(Ssh_gss_ctx ctx, Ssh_gss_buf *buf, return winctx->maj_stat; } -Ssh_gss_stat ssh_gss_free_mic(Ssh_gss_buf *hash) +Ssh_gss_stat ssh_sspi_free_mic(Ssh_gss_buf *hash) { sfree(hash->value); return SSH_GSS_OK; diff --git a/windows/wingss.h b/windows/wingss.h new file mode 100644 index 0000000..e3648e7 --- /dev/null +++ b/windows/wingss.h @@ -0,0 +1,47 @@ +#ifndef PUTTY_WINGSS_H +#define PUTTY_WINGSS_H + +#ifndef NO_GSSAPI +#include "putty.h" + +#include "sshgss.h" +#include "sshgssc.h" + +void ssh_sspi_bind_fns(void); + +int ssh_gss_init(void); + +Ssh_gss_stat ssh_sspi_indicate_mech(Ssh_gss_buf *mech); + +Ssh_gss_stat ssh_sspi_import_name(char *host, Ssh_gss_name *srv_name); + +Ssh_gss_stat ssh_sspi_acquire_cred(Ssh_gss_ctx *ctx); + +Ssh_gss_stat ssh_sspi_init_sec_context(Ssh_gss_ctx *ctx, + Ssh_gss_name srv_name, + int to_deleg, + Ssh_gss_buf *recv_tok, + Ssh_gss_buf *send_tok); + +Ssh_gss_stat ssh_sspi_free_tok(Ssh_gss_buf *send_tok); + +Ssh_gss_stat ssh_sspi_release_cred(Ssh_gss_ctx *ctx); + +Ssh_gss_stat ssh_sspi_release_name(Ssh_gss_name *srv_name); + +Ssh_gss_stat ssh_sspi_display_status(Ssh_gss_ctx ctx, Ssh_gss_buf *buf); + +Ssh_gss_stat ssh_sspi_get_mic(Ssh_gss_ctx ctx, Ssh_gss_buf *buf, + Ssh_gss_buf *hash); + +Ssh_gss_stat ssh_sspi_free_mic(Ssh_gss_buf *hash); + +#else + +/* Dummy function so this source file defines something if NO_GSSAPI + is defined. */ + +int ssh_gss_init(void); +#endif + +#endif /* PUTTY_WINGSS_H */ diff --git a/windows/winstuff.h b/windows/winstuff.h index 29ab0b3..14b8496 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -124,17 +124,25 @@ typedef struct terminal_tag Terminal; typedef HDC Context; +typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */ +#define PUTTY_UINT32_DEFINED + #ifndef NO_GSSAPI /* * GSS-API stuff */ +#define GSS_CC CALLBACK +#define BIND_GSS_FN(handle, name) \ + name = handle ? (t_##name) GetProcAddress(handle, STR(name)) : NULL +/* typedef struct Ssh_gss_buf { - int length; + size_t length; char *value; } Ssh_gss_buf; #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL} typedef void *Ssh_gss_name; +*/ #endif /* -- 1.6.6