aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-07-30 10:45:58 +0200
committerAndreas Schneider <mail@cynapses.org>2009-07-30 10:45:58 +0200
commit766bae9d7626bb596fc3b60d2cd5fe5a7fc356db (patch)
treeec6aa6d9ea44d8eea5c47a8d1245c4fbe2930d96
parent94a57df0c9eceda18679b2823de74837fb5a73c1 (diff)
downloadlibssh-766bae9d7626bb596fc3b60d2cd5fe5a7fc356db.tar.gz
libssh-766bae9d7626bb596fc3b60d2cd5fe5a7fc356db.tar.xz
libssh-766bae9d7626bb596fc3b60d2cd5fe5a7fc356db.zip
Fix build with MSVC.
-rw-r--r--include/libssh/priv.h15
-rw-r--r--include/libssh/sftp.h18
-rw-r--r--libssh/auth.c20
-rw-r--r--libssh/channels.c3
-rw-r--r--libssh/connect.c2
-rw-r--r--libssh/crypt.c1
-rw-r--r--libssh/keyfiles.c1
-rw-r--r--libssh/misc.c16
-rw-r--r--libssh/options.c11
-rw-r--r--libssh/packet.c3
-rw-r--r--libssh/poll.c1
-rw-r--r--libssh/server.c3
-rw-r--r--libssh/sftpserver.c1
-rw-r--r--libssh/socket.c5
-rw-r--r--libssh/string.c1
-rw-r--r--libssh/wrapper.c165
16 files changed, 153 insertions, 113 deletions
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index ead6cfc3..ffdf8fd7 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -29,6 +29,13 @@
#ifndef _LIBSSH_PRIV_H
#define _LIBSSH_PRIV_H
+
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#else
+#include <unistd.h>
+#endif
+
#include "config.h"
#include "libssh/libssh.h"
@@ -172,13 +179,19 @@ void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
/* strings and buffers */
/* must be 32 bits number + immediatly our data */
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
struct ssh_string_struct {
uint32_t size;
unsigned char string[MAX_PACKET_LEN];
}
-#if !defined(__SUNPRO_C)
+#if !defined(__SUNPRO_C) && !defined(_MSC_VER)
__attribute__ ((packed))
#endif
+#ifdef _MSC_VER
+#pragma pack()
+#endif
;
/** Describes a buffer state at a moment
diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h
index a41681b8..702dd8e5 100644
--- a/include/libssh/sftp.h
+++ b/include/libssh/sftp.h
@@ -38,7 +38,11 @@
#ifndef SFTP_H
#define SFTP_H
-#include <libssh/libssh.h>
+
+#include <sys/types.h>
+
+#include "libssh.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -51,11 +55,19 @@ extern "C" {
#ifdef _WIN32
#ifndef uid_t
- typedef long uid_t;
+ typedef uint32_t uid_t;
#endif /* uid_t */
#ifndef gid_t
- typedef long gid_t;
+ typedef uint32_t gid_t;
#endif /* gid_t */
+#ifdef _MSC_VER
+#ifndef mode_t
+ typedef uint32_t mode_t;
+#endif /* mode_t */
+#ifndef ssize_t
+ typedef _W64 signed int ssize_t;
+#endif /* ssize_t */
+#endif /* _MSC_VER */
#endif /* _WIN32 */
typedef struct sftp_ext_struct *sftp_ext;
diff --git a/libssh/auth.c b/libssh/auth.c
index 22840a33..96b41102 100644
--- a/libssh/auth.c
+++ b/libssh/auth.c
@@ -750,6 +750,22 @@ error:
return rc;
}
+#ifdef _MSC_VER
+static const char privKey_1[] = "%s/.ssh/identity";
+static const char pubKey_1[] = "%s/.ssh/identity.pub";
+static const char privKey_2[] = "%s/.ssh/id_dsa";
+static const char pubKey_2[] = "%s/.ssh/id_dsa.pub";
+static const char privKey_3[] = "%s/.ssh/id_rsa";
+static const char pubKey_3[] = "%s/.ssh/id_rsa.pub";
+/** Used different var to allow const char[] declaration */
+static struct ssh_keys_struct keytab[] = {
+ { privKey_1, pubKey_1},
+ { privKey_2, pubKey_2},
+ { privKey_3, pubKey_3},
+ {0}
+};
+#else
+/* This requires GCC extensions */
static struct ssh_keys_struct keytab[] = {
{
.privatekey = "%s/.ssh/identity",
@@ -768,9 +784,7 @@ static struct ssh_keys_struct keytab[] = {
.publickey = NULL
}
};
-
-/* this function initialy was in the client */
-/* but the fools are the ones who never change mind */
+#endif
/**
* @brief Tries to automaticaly authenticate with public key and "none"
diff --git a/libssh/channels.c b/libssh/channels.c
index 8b190b4e..2dd9966d 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -24,7 +24,6 @@
#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
#include <stdio.h>
#include <errno.h>
@@ -929,7 +928,7 @@ int channel_write_common(ssh_channel channel, const void *data,
channel->remote_window -= effectivelen;
len -= effectivelen;
- data += effectivelen;
+ data = ((uint8_t*)data + effectivelen);
}
leave_function();
diff --git a/libssh/connect.c b/libssh/connect.c
index 760c3177..e08cd16c 100644
--- a/libssh/connect.c
+++ b/libssh/connect.c
@@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#ifdef _WIN32
/* getaddrinfo, freeaddrinfo, getnameinfo */
@@ -93,6 +92,7 @@ static void sock_set_nonblocking(socket_t sock) {
static void sock_set_blocking(socket_t sock) {
fcntl(sock, F_SETFL, 0);
}
+
#endif /* _WIN32 */
#ifdef HAVE_REGCOMP
diff --git a/libssh/crypt.c b/libssh/crypt.c
index bb77767b..f84a96f7 100644
--- a/libssh/crypt.c
+++ b/libssh/crypt.c
@@ -21,7 +21,6 @@
* MA 02111-1307, USA.
*/
-#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index a19fc65c..12b58c3f 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -25,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ctype.h>
diff --git a/libssh/misc.c b/libssh/misc.c
index 0df11464..03fd3c38 100644
--- a/libssh/misc.c
+++ b/libssh/misc.c
@@ -24,7 +24,6 @@
#include <limits.h>
#include <stdio.h>
-#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -33,8 +32,8 @@
#ifdef _WIN32
#define _WIN32_IE 0x0400 //SHGetSpecialFolderPath
+#include <winsock2.h> // Must be the first to include
#include <shlobj.h>
-#include <winsock2.h>
#else
#include <pwd.h>
#include <arpa/inet.h>
@@ -67,7 +66,6 @@
* @{ */
#ifdef _WIN32
-
char *ssh_get_user_home_dir(void) {
static char szPath[MAX_PATH] = {0};
@@ -77,7 +75,7 @@ char *ssh_get_user_home_dir(void) {
return NULL;
}
-
+
/* we have read access on file */
int ssh_file_readaccess_ok(const char *file) {
if (_access(file, 4) < 0) {
@@ -85,9 +83,8 @@ char *ssh_get_user_home_dir(void) {
}
return 1;
-}
+}
#else /* _WIN32 */
-
char *ssh_get_user_home_dir(void) {
static char szPath[PATH_MAX] = {0};
struct passwd *pwd = NULL;
@@ -102,8 +99,6 @@ char *ssh_get_user_home_dir(void) {
return szPath;
}
-#endif
-
/* we have read access on file */
int ssh_file_readaccess_ok(const char *file) {
if (access(file, R_OK) < 0) {
@@ -112,13 +107,14 @@ int ssh_file_readaccess_ok(const char *file) {
return 1;
}
+#endif
uint64_t ntohll(uint64_t a) {
#ifdef WORDS_BIGENDIAN
return a;
#else
- uint32_t low = a & 0xffffffff;
- uint32_t high = a >> 32 ;
+ uint32_t low = (uint32_t)(a & 0xffffffff);
+ uint32_t high = (uint32_t)(a >> 32);
low = ntohl(low);
high = ntohl(high);
diff --git a/libssh/options.c b/libssh/options.c
index bbc985b6..4e22b770 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -24,10 +24,11 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
#ifndef _WIN32
#include <pwd.h>
+#else
+#include <winsock2.h>
#endif
#include <sys/types.h>
#include "libssh/priv.h"
@@ -589,6 +590,7 @@ int ssh_options_default_username(SSH_OPTIONS *opt) {
return 0;
}
#else
+{
DWORD Size = 0;
GetUserName(NULL, &Size); //Get Size
user = malloc(Size);
@@ -601,6 +603,7 @@ int ssh_options_default_username(SSH_OPTIONS *opt) {
} else {
SAFE_FREE(user);
}
+}
#endif
return -1;
}
@@ -836,7 +839,10 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv) {
int ssh1 = 0;
#endif
int ssh2 = 1;
-
+#ifdef _MSC_VER
+ /* Not supported with a Microsoft compiler */
+ return -1;
+#else
int saveoptind = optind; /* need to save 'em */
int saveopterr = opterr;
@@ -985,6 +991,7 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv) {
}
return 0;
+#endif
}
/**
diff --git a/libssh/packet.c b/libssh/packet.c
index 3d1912c7..ed3a306c 100644
--- a/libssh/packet.c
+++ b/libssh/packet.c
@@ -23,7 +23,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <unistd.h>
#include <string.h>
#include <errno.h>
@@ -148,7 +147,7 @@ static int packet_read2(SSH_SESSION *session) {
* have been decrypted)
*/
if (packet_decrypt(session,
- buffer_get(session->in_buffer) + blocksize,
+ ((uint8_t*)buffer_get(session->in_buffer) + blocksize),
buffer_get_len(session->in_buffer) - blocksize) < 0) {
ssh_set_error(session, SSH_FATAL, "Decrypt error");
goto error;
diff --git a/libssh/poll.c b/libssh/poll.c
index 662e5ac9..55183cd9 100644
--- a/libssh/poll.c
+++ b/libssh/poll.c
@@ -81,6 +81,7 @@ int ssh_poll(pollfd_t *fds, nfds_t nfds, int timeout) {
#include <stdio.h>
#include <windows.h>
+#include <errno.h>
static int poll_rest (HANDLE *handles, int nhandles,
pollfd_t *fds, nfds_t nfds, int timeout) {
diff --git a/libssh/server.c b/libssh/server.c
index 8e7a26a0..3872849a 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -32,7 +32,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
#include "libssh/priv.h"
#include "libssh/libssh.h"
@@ -45,7 +44,7 @@
#define SOCKOPT_TYPE_ARG4 char
/* We need to provide hstrerror. Not we can't call the parameter h_errno because it's #defined */
-inline char *hstrerror(int h_errno_val) {
+static char *hstrerror(int h_errno_val) {
static char text[50] = {0};
snprintf(text, sizeof(text), "gethostbyname error %d\n", h_errno_val);
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 0423653f..4d234e4a 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -21,7 +21,6 @@
* MA 02111-1307, USA.
*/
-#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
diff --git a/libssh/socket.c b/libssh/socket.c
index 5d5f27f9..8b4c9059 100644
--- a/libssh/socket.c
+++ b/libssh/socket.c
@@ -21,7 +21,6 @@
* MA 02111-1307, USA.
*/
-#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
@@ -264,7 +263,7 @@ int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len) {
return SSH_ERROR;
}
- while((r = ssh_socket_unbuffered_read(s, buffer + total, toread))) {
+ while((r = ssh_socket_unbuffered_read(s, ((uint8_t*)buffer + total), toread))) {
if (r < 0) {
return SSH_ERROR;
}
@@ -303,7 +302,7 @@ int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len)
return SSH_ERROR;
}
len -= written;
- buffer += written;
+ buffer = ((uint8_t*)buffer + written);
}
leave_function();
diff --git a/libssh/string.c b/libssh/string.c
index 933d32c8..c9520842 100644
--- a/libssh/string.c
+++ b/libssh/string.c
@@ -22,7 +22,6 @@
*/
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
#ifndef _WIN32
diff --git a/libssh/wrapper.c b/libssh/wrapper.c
index f2011d88..a052c140 100644
--- a/libssh/wrapper.c
+++ b/libssh/wrapper.c
@@ -577,11 +577,11 @@ static int des3_set_key(struct crypto_struct *cipher, void *key) {
}
DES_set_odd_parity(key);
- DES_set_odd_parity(key + 8);
- DES_set_odd_parity(key + 16);
+ DES_set_odd_parity((void*)((uint8_t*)key + 8));
+ DES_set_odd_parity((void*)((uint8_t*)key + 16));
DES_set_key_unchecked(key, cipher->key);
- DES_set_key_unchecked(key + 8, cipher->key + sizeof(DES_key_schedule));
- DES_set_key_unchecked(key + 16, cipher->key + 2 * sizeof(DES_key_schedule));
+ DES_set_key_unchecked((void*)((uint8_t*)key + 8), (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)));
+ DES_set_key_unchecked((void*)((uint8_t*)key + 16), (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)));
}
return 0;
@@ -590,16 +590,16 @@ static int des3_set_key(struct crypto_struct *cipher, void *key) {
static void des3_encrypt(struct crypto_struct *cipher, void *in,
void *out, unsigned long len, void *IV) {
DES_ede3_cbc_encrypt(in, out, len, cipher->key,
- cipher->key + sizeof(DES_key_schedule),
- cipher->key + 2 * sizeof(DES_key_schedule),
+ (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
+ (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
IV, 1);
}
static void des3_decrypt(struct crypto_struct *cipher, void *in,
void *out, unsigned long len, void *IV) {
DES_ede3_cbc_encrypt(in, out, len, cipher->key,
- cipher->key + sizeof(DES_key_schedule),
- cipher->key + 2 * sizeof(DES_key_schedule),
+ (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
+ (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
IV, 0);
}
@@ -609,10 +609,10 @@ static void des3_1_encrypt(struct crypto_struct *cipher, void *in,
ssh_print_hexa("Encrypt IV before", IV, 24);
#endif
DES_ncbc_encrypt(in, out, len, cipher->key, IV, 1);
- DES_ncbc_encrypt(out, in, len, cipher->key + sizeof(DES_key_schedule),
- IV + 8, 0);
- DES_ncbc_encrypt(in, out, len, cipher->key + 2 * sizeof(DES_key_schedule),
- IV + 16, 1);
+ DES_ncbc_encrypt(out, in, len, (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
+ (void*)((uint8_t*)IV + 8), 0);
+ DES_ncbc_encrypt(in, out, len, (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
+ (void*)((uint8_t*)IV + 16), 1);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("Encrypt IV after", IV, 24);
#endif
@@ -624,11 +624,11 @@ static void des3_1_decrypt(struct crypto_struct *cipher, void *in,
ssh_print_hexa("Decrypt IV before", IV, 24);
#endif
- DES_ncbc_encrypt(in, out, len, cipher->key + 2 * sizeof(DES_key_schedule),
+ DES_ncbc_encrypt(in, out, len, (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
IV, 0);
- DES_ncbc_encrypt(out, in, len, cipher->key + sizeof(DES_key_schedule),
- IV + 8, 1);
- DES_ncbc_encrypt(in, out, len, cipher->key, IV + 16, 0);
+ DES_ncbc_encrypt(out, in, len, (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
+ (void*)((uint8_t*)IV + 8), 1);
+ DES_ncbc_encrypt(in, out, len, cipher->key, (void*)((uint8_t*)IV + 16), 0);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("Decrypt IV after", IV, 24);
@@ -637,90 +637,95 @@ static void des3_1_decrypt(struct crypto_struct *cipher, void *in,
#endif /* HAS_DES */
-/* the table of supported ciphers */
+/*
+ * The table of supported ciphers
+ *
+ * WARNING: If you modify crypto_struct, you must make sure the order is
+ * correct!
+ */
static struct crypto_struct ssh_ciphertab[] = {
#ifdef HAS_BLOWFISH
{
- .name = "blowfish-cbc",
- .blocksize = 8,
- .keylen = sizeof (BF_KEY),
- .key = NULL,
- .keysize = 128,
- .set_encrypt_key = blowfish_set_key,
- .set_decrypt_key = blowfish_set_key,
- .cbc_encrypt = blowfish_encrypt,
- .cbc_decrypt = blowfish_decrypt
+ "blowfish-cbc",
+ 8,
+ sizeof (BF_KEY),
+ NULL,
+ 128,
+ blowfish_set_key,
+ blowfish_set_key,
+ blowfish_encrypt,
+ blowfish_decrypt
},
#endif /* HAS_BLOWFISH */
#ifdef HAS_AES
{
- .name = "aes128-cbc",
- .blocksize = 16,
- .keylen = sizeof(AES_KEY),
- .key = NULL,
- .keysize = 128,
- .set_encrypt_key = aes_set_encrypt_key,
- .set_decrypt_key = aes_set_decrypt_key,
- .cbc_encrypt = aes_encrypt,
- .cbc_decrypt = aes_decrypt
+ "aes128-cbc",
+ 16,
+ sizeof(AES_KEY),
+ NULL,
+ 128,
+ aes_set_encrypt_key,
+ aes_set_decrypt_key,
+ aes_encrypt,
+ aes_decrypt
},
{
- .name = "aes192-cbc",
- .blocksize = 16,
- .keylen = sizeof(AES_KEY),
- .key = NULL,
- .keysize = 192,
- .set_encrypt_key = aes_set_encrypt_key,
- .set_decrypt_key = aes_set_decrypt_key,
- .cbc_encrypt = aes_encrypt,
- .cbc_decrypt = aes_decrypt
+ "aes192-cbc",
+ 16,
+ sizeof(AES_KEY),
+ NULL,
+ 192,
+ aes_set_encrypt_key,
+ aes_set_decrypt_key,
+ aes_encrypt,
+ aes_decrypt
},
{
- .name = "aes256-cbc",
- .blocksize = 16,
- .keylen = sizeof(AES_KEY),
- .key = NULL,
- .keysize = 256,
- .set_encrypt_key = aes_set_encrypt_key,
- .set_decrypt_key = aes_set_decrypt_key,
- .cbc_encrypt = aes_encrypt,
- .cbc_decrypt = aes_decrypt
+ "aes256-cbc",
+ 16,
+ sizeof(AES_KEY),
+ NULL,
+ 256,
+ aes_set_encrypt_key,
+ aes_set_decrypt_key,
+ aes_encrypt,
+ aes_decrypt
},
#endif /* HAS_AES */
#ifdef HAS_DES
{
- .name = "3des-cbc",
- .blocksize = 8,
- .keylen = sizeof(DES_key_schedule) * 3,
- .key = NULL,
- .keysize = 192,
- .set_encrypt_key = des3_set_key,
- .set_decrypt_key = des3_set_key,
- .cbc_encrypt = des3_encrypt,
- .cbc_decrypt = des3_decrypt
+ "3des-cbc",
+ 8,
+ sizeof(DES_key_schedule) * 3,
+ NULL,
+ 192,
+ des3_set_key,
+ des3_set_key,
+ des3_encrypt,
+ des3_decrypt
},
{
- .name = "3des-cbc-ssh1",
- .blocksize = 8,
- .keylen = sizeof(DES_key_schedule) * 3,
- .key = NULL,
- .keysize = 192,
- .set_encrypt_key = des3_set_key,
- .set_decrypt_key = des3_set_key,
- .cbc_encrypt = des3_1_encrypt,
- .cbc_decrypt = des3_1_decrypt
+ "3des-cbc-ssh1",
+ 8,
+ sizeof(DES_key_schedule) * 3,
+ NULL,
+ 192,
+ des3_set_key,
+ des3_set_key,
+ des3_1_encrypt,
+ des3_1_decrypt
},
#endif /* HAS_DES */
{
- .name = NULL,
- .blocksize = 0,
- .keylen = 0,
- .key = NULL,
- .keysize = 0,
- .set_encrypt_key = NULL,
- .set_decrypt_key = NULL,
- .cbc_encrypt = NULL,
- .cbc_decrypt = NULL
+ NULL,
+ 0,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ NULL
}
};
#endif /* OPENSSL_CRYPTO */