From 689073e46aea00dbacb21c7801e8cb62a237c852 Mon Sep 17 00:00:00 2001 From: manojampalam Date: Tue, 22 Mar 2016 23:18:46 -0700 Subject: [PATCH] fix for 2012 read issue and refactored changes in libssh --- authfile.c | 8 ++--- bufaux.c | 58 ------------------------------ buffer.h | 8 ----- channels.c | 38 ++------------------ contrib/win32/win32compat/fileio.c | 10 ++++-- dns.c | 5 +-- hostfile.c | 4 +-- 7 files changed, 17 insertions(+), 114 deletions(-) diff --git a/authfile.c b/authfile.c index 0c5c9da..601fab4 100644 --- a/authfile.c +++ b/authfile.c @@ -121,7 +121,7 @@ sshkey_load_file(int fd, struct sshbuf *blob) goto out; } } -#ifndef WIN32_FIXME +#ifndef WIN32_FIXME//R if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 && st.st_size != (off_t)sshbuf_len(blob)) { r = SSH_ERR_FILE_CHANGED; @@ -183,7 +183,7 @@ sshkey_perm_ok(int fd, const char *filename) if (check_ntsec(filename)) #endif -#ifndef WIN32_FIXME +#ifndef WIN32_FIXME//R if ((st.st_uid == getuid()) && (st.st_mode & 077) != 0) { error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); error("@ WARNING: UNPROTECTED PRIVATE KEY FILE! @"); @@ -209,11 +209,7 @@ sshkey_load_private_type(int type, const char *filename, const char *passphrase, if (commentp != NULL) *commentp = NULL; -#ifdef WIN32_FIXME - if ((fd = open(filename, O_RDONLY | O_BINARY)) < 0) { -#else if ((fd = open(filename, O_RDONLY)) < 0) { -#endif if (perm_ok != NULL) *perm_ok = 0; diff --git a/bufaux.c b/bufaux.c index 67ce288..b0bf352 100644 --- a/bufaux.c +++ b/bufaux.c @@ -257,62 +257,4 @@ buffer_put_bignum2_from_string(Buffer *buffer, const u_char *s, u_int l) fatal("%s: %s", __func__, ssh_err(ret)); } -#ifdef WIN32_FIXME - -/* - * Pop string UTF8 string from buffer and convert it to Local8. - * This function guaranty, that data (received in UTF8 from network) - * are correctly translated to local8 CP used by current thread. - * - * WARNING: Returned string MUST be free by caller. - * - * b - Buffer struct to read data (IN). - * len - length of returned Locla8 string (OUT). - * - * RETURNS: Pointer to new allocated Local8 string or NULL if error. - */ - -void *buffer_get_string_local8_from_utf8(Buffer *b, u_int *len) -{ - char *local8 = NULL; - - char *utf8 = buffer_get_string(b, len); - - if (utf8) - { - local8 = CovertUtf8ToLocal8(utf8, -1, len); - - free(utf8); - } - - return local8; -} - -/* - * Convert string from Local8 to UTF8 and push it into buffer. - * This function guaranty, that data stored in local8 CP used by current - * thread are convert to UTF8 before sent to network. - * - * b - Buffer struct to read data (IN). - * str - Local8 string to push (IN). - * len - size of str size in bytes (IN). - * - */ - -void buffer_put_string_local8_to_utf8(Buffer *b, const void *str, u_int len) -{ - u_int utf8Len = 0; - - char *utf8 = ConvertLocal8ToUtf8(str, len, &utf8Len); - - if (utf8) - { - buffer_put_string(b, utf8, utf8Len); - - free(utf8); - } -} - - -#endif /* WIN32_FIXME */ diff --git a/buffer.h b/buffer.h index d604d79..df1aebc 100644 --- a/buffer.h +++ b/buffer.h @@ -73,14 +73,6 @@ void buffer_put_string(Buffer *, const void *, u_int); char *buffer_get_cstring(Buffer *, u_int *); void buffer_put_cstring(Buffer *, const char *); -#ifdef WIN32_FIXME - - void *buffer_get_string_local8_from_utf8(Buffer *, u_int *); - - void buffer_put_string_local8_to_utf8(Buffer *, const void *, u_int); - -#endif /* WIN32_FIXME */ - #define buffer_skip_string(b) (void)buffer_get_string_ptr(b, NULL); int buffer_put_bignum_ret(Buffer *, const BIGNUM *); diff --git a/channels.c b/channels.c index 6a8985f..de6102b 100644 --- a/channels.c +++ b/channels.c @@ -84,11 +84,6 @@ #include "authfd.h" #include "pathnames.h" -//#ifdef WIN32_FIXME -//#define isatty(a) WSHELPisatty(a) -//#define SFD_TYPE_CONSOLE 4 -//#endif - /* -- channel core */ @@ -1679,14 +1674,6 @@ channel_handle_rfd(Channel *c, fd_set *readset, fd_set *writeset) if (c->rfd != -1 && (force || FD_ISSET(c->rfd, readset))) { errno = 0; len = read(c->rfd, buf, sizeof(buf)); - #ifdef WIN32_FIXME - if (len == 0) { - - //if ( get_sfd_type(c->rfd) == SFD_TYPE_CONSOLE) - if(isatty(c->rfd)) - return 1; // in Win32 console read, there may be no data, but is ok - } - #endif if (len < 0 && (errno == EINTR || ((errno == EAGAIN || errno == EWOULDBLOCK) && !force))) return 1; @@ -1795,7 +1782,7 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset) } return -1; } -#ifndef WIN32_FIXME +#ifndef WIN32_FIXME//R #ifndef BROKEN_TCGETATTR_ICANON if (compat20 && c->isatty && dlen >= 1 && buf[0] != '\r') { if (tcgetattr(c->wfd, &tio) == 0 && @@ -2222,8 +2209,6 @@ channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp, * Winsock can't support this sort of fdset reallocation */ -#if(1)//ndef WIN32_FIXME - nfdset = howmany(n+1, NFDBITS); /* Explicitly test here, because xrealloc isn't always called */ if (nfdset && SIZE_MAX / nfdset < sizeof(fd_mask)) @@ -2236,25 +2221,11 @@ channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp, *writesetp = xreallocarray(*writesetp, nfdset, sizeof(fd_mask)); *nallocp = sz; } -#endif /* WIN32_FIXME */ *maxfdp = n; -#if(0)//def WIN32_FIXME - - if (*readsetp == NULL) - { - *readsetp = malloc(sizeof(fd_set)); - *writesetp = malloc(sizeof(fd_set)); - } - - FD_ZERO(*readsetp); - FD_ZERO(*writesetp); - -#else /* WIN32_FIXME */ memset(*readsetp, 0, sz); memset(*writesetp, 0, sz); -#endif /* else WIN32_FIXME */ if (!rekeying) channel_handler(channel_pre, *readsetp, *writesetp, @@ -2408,9 +2379,6 @@ channel_input_data(int type, u_int32_t seq, void *ctxt) const u_char *data; u_int data_len, win_len; Channel *c; - #ifdef WIN32_FIXME - static charinline = 0; // counts characters in a line for sshd in tty mode - #endif /* Get the channel number and verify it. */ id = packet_get_int(); @@ -2509,7 +2477,7 @@ channel_input_extended_data(int type, u_int32_t seq, void *ctxt) } debug2("channel %d: rcvd ext data %d", c->self, data_len); c->local_window -= data_len; - #ifndef WIN32_FIXME + #ifndef WIN32_FIXME//N buffer_append(&c->extended, data, data_len); #else if ( c->client_tty ) @@ -3911,7 +3879,7 @@ channel_connect_to_path(const char *path, char *ctype, char *rname) return connect_to(path, PORT_STREAMLOCAL, ctype, rname); } -#ifndef WIN32_FIXME +#ifndef WIN32_FIXME//N void channel_send_window_changes(void) { diff --git a/contrib/win32/win32compat/fileio.c b/contrib/win32/win32compat/fileio.c index e14edbd..8f4183c 100644 --- a/contrib/win32/win32compat/fileio.c +++ b/contrib/win32/win32compat/fileio.c @@ -60,7 +60,7 @@ errno_from_Win32Error(int win32_error) case ERROR_FILE_NOT_FOUND: return ENOENT; default: - return EOTHER; + return win32_error; } } @@ -355,7 +355,7 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) { else { if (-1 == fileio_ReadFileEx(pio)) { if ((FILETYPE(pio) == FILE_TYPE_PIPE) - && (errno == ERROR_NEGATIVE_SEEK)) { + && (errno == ERROR_BROKEN_PIPE)) { /* write end of the pipe closed */ debug("read - no more data, io:%p", pio); errno = 0; @@ -462,6 +462,10 @@ fileio_write(struct w32_io* pio, const void *buf, unsigned int max) { errno = errno_from_Win32Error(pio->write_details.error); debug("write - ERROR:%d on prior unblocking write, io:%p", errno, pio); pio->write_details.error = 0; + if ((FILETYPE(pio) == FILE_TYPE_PIPE) && (errno == ERROR_BROKEN_PIPE)) { + debug("write - ERROR:read end of the pipe closed, io:%p", pio); + errno = EPIPE; + } return -1; } @@ -498,7 +502,7 @@ fileio_write(struct w32_io* pio, const void *buf, unsigned int max) { else { errno = errno_from_Win32LastError(); /* read end of the pipe closed ? */ - if ((FILETYPE(pio) == FILE_TYPE_PIPE) && (errno == ERROR_NEGATIVE_SEEK)) { + if ((FILETYPE(pio) == FILE_TYPE_PIPE) && (errno == ERROR_BROKEN_PIPE)) { debug("write - ERROR:read end of the pipe closed, io:%p", pio); errno = EPIPE; } diff --git a/dns.c b/dns.c index 27475cf..de96dc6 100644 --- a/dns.c +++ b/dns.c @@ -204,7 +204,7 @@ int verify_host_key_dns(const char *hostname, struct sockaddr *address, struct sshkey *hostkey, int *flags) { -#ifndef WIN32_FIXME +#ifndef WIN32_FIXME//R u_int counter; int result; struct rrsetinfo *fingerprints = NULL; @@ -308,7 +308,8 @@ verify_host_key_dns(const char *hostname, struct sockaddr *address, return 0; #else - return 0; + error("dns host key verification is not supported in Windows"); + return -1; #endif /* else !WIN32_FIXME */ } diff --git a/hostfile.c b/hostfile.c index f5f2515..0ff17d6 100644 --- a/hostfile.c +++ b/hostfile.c @@ -532,7 +532,7 @@ int hostfile_replace_entries(const char *filename, const char *host, const char *ip, struct sshkey **keys, size_t nkeys, int store_hash, int quiet, int hash_alg) { - #ifndef WIN32_FIXME + #ifndef WIN32_FIXME//R int r, fd, oerrno = 0; int loglevel = quiet ? SYSLOG_LEVEL_DEBUG1 : SYSLOG_LEVEL_VERBOSE; struct host_delete_ctx ctx; @@ -648,7 +648,7 @@ hostfile_replace_entries(const char *filename, const char *host, const char *ip, errno = oerrno; return r; #else - //PRAGMA:TODO + error("replacing host file entries is not supported in Windows"); return 0; #endif }