From 5a60b811fe26816cbd47c0a6fd3bb0fdef64a387 Mon Sep 17 00:00:00 2001 From: manojampalam Date: Wed, 23 Mar 2016 21:54:35 -0700 Subject: [PATCH] Added implementation for dlopen, dlclose, dlsym and dlerror --- contrib/win32/openssh/win32iocompat.vcxproj | 1 + .../openssh/win32iocompat.vcxproj.filters | 3 ++ contrib/win32/win32compat/inc/dlfcn.h | 11 ++++++ contrib/win32/win32compat/misc.c | 13 +++++++ ssh-pkcs11.c | 39 +------------------ ssh_api.c | 2 +- 6 files changed, 31 insertions(+), 38 deletions(-) create mode 100644 contrib/win32/win32compat/inc/dlfcn.h diff --git a/contrib/win32/openssh/win32iocompat.vcxproj b/contrib/win32/openssh/win32iocompat.vcxproj index 10b874b..179cd50 100644 --- a/contrib/win32/openssh/win32iocompat.vcxproj +++ b/contrib/win32/openssh/win32iocompat.vcxproj @@ -163,6 +163,7 @@ + diff --git a/contrib/win32/openssh/win32iocompat.vcxproj.filters b/contrib/win32/openssh/win32iocompat.vcxproj.filters index 092b33b..ab0c612 100644 --- a/contrib/win32/openssh/win32iocompat.vcxproj.filters +++ b/contrib/win32/openssh/win32iocompat.vcxproj.filters @@ -50,6 +50,9 @@ inc + + inc + diff --git a/contrib/win32/win32compat/inc/dlfcn.h b/contrib/win32/win32compat/inc/dlfcn.h new file mode 100644 index 0000000..e7201d7 --- /dev/null +++ b/contrib/win32/win32compat/inc/dlfcn.h @@ -0,0 +1,11 @@ +#pragma once +#include +#define RTLD_NOW 0 + +#define dlerror() GetLastError() + +HMODULE *dlopen(const char *filename, int flags); + +int dlclose(HMODULE *handle); + +FARPROC *dlsym(HMODULE *handle, const char *symbol); \ No newline at end of file diff --git a/contrib/win32/win32compat/misc.c b/contrib/win32/win32compat/misc.c index 49bcbf5..9e9cbfd 100644 --- a/contrib/win32/win32compat/misc.c +++ b/contrib/win32/win32compat/misc.c @@ -60,4 +60,17 @@ int statvfs(const char *path, struct statvfs *buf) { int fstatvfs(int fd, struct statvfs *buf) { errno = ENOSYS; return -1; +} + +#include "inc\dlfcn.h" +HMODULE *dlopen(const char *filename, int flags) { + return LoadLibraryA(filename); +} + +int dlclose(HMODULE *handle) { + FreeLibrary(handle); +} + +FARPROC *dlsym(HMODULE *handle, const char *symbol) { + return GetProcAddress(handle, symbol); } \ No newline at end of file diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c index 94cf4d4..83255c3 100644 --- a/ssh-pkcs11.c +++ b/ssh-pkcs11.c @@ -28,11 +28,7 @@ #include -#ifdef WIN32_FIXME -#include -#else #include -#endif /*WIN32_FIXME*/ #include "openbsd-compat/sys-queue.h" @@ -114,11 +110,7 @@ pkcs11_provider_finalize(struct pkcs11_provider *p) p->valid = 0; p->function_list = NULL; - #ifdef WIN32_FIXME - FreeLibrary(p -> handle); - #else dlclose(p->handle); - #endif /*WIN32_FIXME*/ } /* @@ -589,28 +581,6 @@ pkcs11_add_provider(char *provider_id, char *pin, struct sshkey ***keyp) goto fail; } /* open shared pkcs11-libarary */ -#ifdef WIN32_FIXME - - handle = LoadLibrary(provider_id); - - if (handle == NULL) - { - error("Cannot load OpenSC library. Error code is: %u.\n" - "Please ensure that path to these libraries is properly " - "set in your PATH variable.\n", GetLastError()); - goto fail; - } - - getfunctionlist = (CK_RV(*)(CK_FUNCTION_LIST **))GetProcAddress(handle, "C_GetFunctionList"); - - if (getfunctionlist == NULL) - { - error("Cannot load OpenSC library. Error code is: %u.\n", GetLastError()); - - goto fail; - } - -#else if ((handle = dlopen(provider_id, RTLD_NOW)) == NULL) { error("dlopen %s failed: %s", provider_id, dlerror()); goto fail; @@ -619,8 +589,7 @@ pkcs11_add_provider(char *provider_id, char *pin, struct sshkey ***keyp) error("dlsym(C_GetFunctionList) failed: %s", dlerror()); goto fail; } -#endif /*WIN32_FIXME*/ - + p = xcalloc(1, sizeof(*p)); p->name = xstrdup(provider_id); p->handle = handle; @@ -705,13 +674,9 @@ fail: free(p->slotinfo); free(p); } - #ifdef WIN32_FIXME - if (handle) - FreeLibrary(handle); - #else + if (handle) dlclose(handle); - #endif/*WIN32_FIXME*/ return (-1); } diff --git a/ssh_api.c b/ssh_api.c index 1ed75f9..c781cdb 100644 --- a/ssh_api.c +++ b/ssh_api.c @@ -382,7 +382,7 @@ _ssh_send_banner(struct ssh *ssh, char **bannerp) char buf[256]; int r; - #ifndef WIN32_FIXME + #ifndef WIN32_FIXME//R snprintf(buf, sizeof buf, "SSH-2.0-%.100s\r\n", SSH_VERSION); #else snprintf(buf, sizeof buf, "SSH-2.0-%.100sp1 Microsoft_Win32_port %s\r\n", SSH_VERSION, __DATE__ );