|
| 1 | +diff --git a/src/connect.c b/src/connect.c |
| 2 | +index 124b9f56..936611ff 100644 |
| 3 | +--- a/src/connect.c |
| 4 | ++++ b/src/connect.c |
| 5 | +@@ -33,6 +33,7 @@ |
| 6 | + #include "libssh/misc.h" |
| 7 | + |
| 8 | + #ifdef _WIN32 |
| 9 | ++#if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
| 10 | + /* |
| 11 | + * Only use Windows API functions available on Windows 2000 SP4 or later. |
| 12 | + * The available constants are in <sdkddkver.h>. |
| 13 | +@@ -49,6 +50,7 @@ |
| 14 | + #undef NTDDI_VERSION |
| 15 | + #define NTDDI_VERSION 0x05010000 /* NTDDI_WINXP */ |
| 16 | + #endif |
| 17 | ++#endif |
| 18 | + |
| 19 | + #if _MSC_VER >= 1400 |
| 20 | + #include <io.h> |
| 21 | +diff --git a/src/getpass.c b/src/getpass.c |
| 22 | +index 99627665..7c9941f3 100644 |
| 23 | +--- a/src/getpass.c |
| 24 | ++++ b/src/getpass.c |
| 25 | +@@ -122,6 +122,9 @@ int ssh_getpass(const char *prompt, |
| 26 | + size_t len, |
| 27 | + int echo, |
| 28 | + int verify) { |
| 29 | ++#if defined(WINAPI_FAMILY) || (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
| 30 | ++ return -1; |
| 31 | ++#else |
| 32 | + HANDLE h; |
| 33 | + DWORD mode = 0; |
| 34 | + int ok; |
| 35 | +@@ -158,6 +161,7 @@ int ssh_getpass(const char *prompt, |
| 36 | + buf[len - 1] = '\0'; |
| 37 | + |
| 38 | + return 0; |
| 39 | ++#endif |
| 40 | + } |
| 41 | + |
| 42 | + #else |
| 43 | +diff --git a/src/init.c b/src/init.c |
| 44 | +index a8dfe030..b74cf6dd 100644 |
| 45 | +--- a/src/init.c |
| 46 | ++++ b/src/init.c |
| 47 | +@@ -32,17 +32,40 @@ |
| 48 | + #include <winsock2.h> |
| 49 | + #endif |
| 50 | + |
| 51 | ++#if defined(_WIN32) && defined(_MSC_VER) && defined(LIBSSH_STATIC) |
| 52 | ++# define CONSTRUCTOR_ATTRIBUTE_(_func,p) static void _func(void); \ |
| 53 | ++ static int _func ## _wrapper(void) { _func(); return 0; } \ |
| 54 | ++ __pragma(section(".CRT$XCU",read)) \ |
| 55 | ++ __declspec(allocate(".CRT$XCU")) int (* _func##_)(void) = _func ## _wrapper; \ |
| 56 | ++ __pragma(comment(linker,"/include:" p #_func "_")) |
| 57 | ++#ifdef _WIN64 |
| 58 | ++#define CONSTRUCTOR_ATTRIBUTE(f) CONSTRUCTOR_ATTRIBUTE_(f,"") |
| 59 | ++#else |
| 60 | ++#define CONSTRUCTOR_ATTRIBUTE(f) CONSTRUCTOR_ATTRIBUTE_(f,"_") |
| 61 | ++#endif |
| 62 | ++# define DESTRUCTOR_ATTRIBUTE_(_func,p) static void _func(void); \ |
| 63 | ++ static int _func ## _constructor(void) { atexit (_func); return 0; } \ |
| 64 | ++ __pragma(section(".CRT$XCU",read)) \ |
| 65 | ++ __declspec(allocate(".CRT$XCU")) int (* _func##_)(void) = _func ## _constructor; \ |
| 66 | ++ __pragma(comment(linker,"/include:" p #_func "_")) |
| 67 | ++#ifdef _WIN64 |
| 68 | ++#define DESTRUCTOR_ATTRIBUTE(f) DESTRUCTOR_ATTRIBUTE_(f,"") |
| 69 | ++#else |
| 70 | ++#define DESTRUCTOR_ATTRIBUTE(f) DESTRUCTOR_ATTRIBUTE_(f,"_") |
| 71 | ++#endif |
| 72 | ++#else |
| 73 | + #ifdef HAVE_CONSTRUCTOR_ATTRIBUTE |
| 74 | +-#define CONSTRUCTOR_ATTRIBUTE __attribute__((constructor)) |
| 75 | ++##define CONSTRUCTOR_ATTRIBUTE(_func) void _func(void) __attribute__((constructor)) |
| 76 | + #else |
| 77 | +-#define CONSTRUCTOR_ATTRIBUTE |
| 78 | ++#define CONSTRUCTOR_ATTRIBUTE(_func) |
| 79 | + #endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */ |
| 80 | + |
| 81 | + #ifdef HAVE_DESTRUCTOR_ATTRIBUTE |
| 82 | +-#define DESTRUCTOR_ATTRIBUTE __attribute__((destructor)) |
| 83 | ++#define DESTRUCTOR_ATTRIBUTE(_func) void _func(void) __attribute__((destructor)) |
| 84 | + #else |
| 85 | +-#define DESTRUCTOR_ATTRIBUTE |
| 86 | ++#define DESTRUCTOR_ATTRIBUTE(_func) |
| 87 | + #endif /* HAVE_DESTRUCTOR_ATTRIBUTE */ |
| 88 | ++#endif |
| 89 | + |
| 90 | + /* Declare static mutex */ |
| 91 | + static SSH_MUTEX ssh_init_mutex = SSH_MUTEX_STATIC_INIT; |
| 92 | +@@ -53,8 +76,8 @@ static int _ssh_initialized = 0; |
| 93 | + /* Cache the returned value */ |
| 94 | + static int _ssh_init_ret = 0; |
| 95 | + |
| 96 | +-void libssh_constructor(void) CONSTRUCTOR_ATTRIBUTE; |
| 97 | +-void libssh_destructor(void) DESTRUCTOR_ATTRIBUTE; |
| 98 | ++CONSTRUCTOR_ATTRIBUTE(libssh_constructor); |
| 99 | ++DESTRUCTOR_ATTRIBUTE(libssh_destructor); |
| 100 | + |
| 101 | + static int _ssh_init(unsigned constructor) { |
| 102 | + |
| 103 | +diff --git a/src/misc.c b/src/misc.c |
| 104 | +index 0c6b570c..c365e62b 100644 |
| 105 | +--- a/src/misc.c |
| 106 | ++++ b/src/misc.c |
| 107 | +@@ -50,9 +50,10 @@ |
| 108 | + |
| 109 | + |
| 110 | + #ifdef _WIN32 |
| 111 | +- |
| 112 | +-#ifndef _WIN32_IE |
| 113 | +-# define _WIN32_IE 0x0501 // SHGetSpecialFolderPath |
| 114 | ++#if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
| 115 | ++# ifndef _WIN32_IE |
| 116 | ++# define _WIN32_IE 0x0501 // SHGetSpecialFolderPath |
| 117 | ++# endif |
| 118 | + #endif |
| 119 | + |
| 120 | + #include <winsock2.h> // Must be the first to include |
| 121 | +@@ -105,6 +106,9 @@ |
| 122 | + |
| 123 | + #ifdef _WIN32 |
| 124 | + char *ssh_get_user_home_dir(void) { |
| 125 | ++#if defined(WINAPI_FAMILY) || (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
| 126 | ++ return NULL; |
| 127 | ++#else |
| 128 | + char tmp[MAX_PATH] = {0}; |
| 129 | + char *szPath = NULL; |
| 130 | + |
| 131 | +@@ -119,6 +123,7 @@ char *ssh_get_user_home_dir(void) { |
| 132 | + } |
| 133 | + |
| 134 | + return NULL; |
| 135 | ++#endif |
| 136 | + } |
| 137 | + |
| 138 | + /* we have read access on file */ |
| 139 | +@@ -147,22 +152,26 @@ int gettimeofday(struct timeval *__p, void *__t) { |
| 140 | + } |
| 141 | + |
| 142 | + char *ssh_get_local_username(void) { |
| 143 | ++#if defined(WINAPI_FAMILY) || (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
| 144 | ++ return NULL; |
| 145 | ++#else |
| 146 | + DWORD size = 0; |
| 147 | + char *user; |
| 148 | + |
| 149 | + /* get the size */ |
| 150 | +- GetUserName(NULL, &size); |
| 151 | ++ GetUserNameA(NULL, &size); |
| 152 | + |
| 153 | + user = (char *) malloc(size); |
| 154 | + if (user == NULL) { |
| 155 | + return NULL; |
| 156 | + } |
| 157 | + |
| 158 | +- if (GetUserName(user, &size)) { |
| 159 | ++ if (GetUserNameA(user, &size)) { |
| 160 | + return user; |
| 161 | + } |
| 162 | + |
| 163 | + return NULL; |
| 164 | ++#endif |
| 165 | + } |
| 166 | + |
| 167 | + int ssh_is_ipaddr_v4(const char *str) { |
| 168 | +diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c |
| 169 | +index 705830c0..8ecbbdde 100644 |
| 170 | +--- a/src/pki_gcrypt.c |
| 171 | ++++ b/src/pki_gcrypt.c |
| 172 | +@@ -2140,7 +2140,11 @@ ssh_signature pki_do_sign_hash(const ssh_key privkey, |
| 173 | + size_t hlen, |
| 174 | + enum ssh_digest_e hash_type) |
| 175 | + { |
| 176 | ++#if defined(_MSC_VER) |
| 177 | ++ unsigned char* ghash = (char*)_alloca(sizeof(char) * (hlen + 1)); |
| 178 | ++#else |
| 179 | + unsigned char ghash[hlen + 1]; |
| 180 | ++#endif |
| 181 | + const char *hash_c = NULL; |
| 182 | + ssh_signature sig; |
| 183 | + gcry_sexp_t sexp; |
0 commit comments