diff -ur /ssh-1.2.27/auth-passwd.c ssh-1.2.27/auth-passwd.c
--- /ssh-1.2.27/auth-passwd.c	Wed May 12 15:19:23 1999
+++ ssh-1.2.27/auth-passwd.c	Wed Aug 04 04:59:56 1999
@@ -127,6 +127,10 @@
  */
 
 #include "includes.h"
+#ifdef __CYGWIN__
+#include <windows.h>
+HANDLE hToken;
+#endif /* __CYGWIN__ */
 #ifdef HAVE_SCO_ETC_SHADOW
 # include <sys/security.h>
 # include <sys/audit.h>
@@ -529,6 +533,14 @@
       packet_send_debug("Server does not permit empty password login.");
       return 0;
   }
+#ifdef __CYGWIN__
+  if (LogonUser(server_user, NULL, password, LOGON32_LOGON_INTERACTIVE,
+				LOGON32_PROVIDER_DEFAULT, &hToken)
+      && SetHandleInformation (hToken, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))
+    return 1;
+  else
+    return 0;
+#endif
 
   /* Get the encrypted password for the user. */
   pw = getpwnam(server_user);
diff -ur /ssh-1.2.27/authfile.c ssh-1.2.27/authfile.c
--- /ssh-1.2.27/authfile.c	Wed May 12 15:19:24 1999
+++ ssh-1.2.27/authfile.c	Wed Aug 04 05:47:47 1999
@@ -134,7 +134,7 @@
   buffer_free(&buffer);
 
   /* Write to a file. */
-  uf = userfile_open(uid, filename, O_WRONLY|O_CREAT|O_TRUNC, 0600);
+  uf = userfile_open(uid, filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600);
   if (uf == NULL)
     return 0;
 
@@ -168,7 +168,7 @@
   char *cp;
 
   /* Read data from the file into the buffer. */
-  uf = userfile_open(uid, filename, O_RDONLY, 0);
+  uf = userfile_open(uid, filename, O_RDONLY|O_BINARY, 0);
   if (uf == NULL)
     return 0;
 
@@ -248,7 +248,7 @@
   CipherContext cipher;
 
   /* Read the file into the buffer. */
-  uf = userfile_open(uid, filename, O_RDONLY, 0);
+  uf = userfile_open(uid, filename, O_RDONLY|O_BINARY, 0);
   if (uf == NULL)
     return 0;
 
diff -ur /ssh-1.2.27/configure ssh-1.2.27/configure
--- /ssh-1.2.27/configure	Wed May 12 15:20:06 1999
+++ ssh-1.2.27/configure	Wed Aug 04 03:46:11 1999
@@ -5801,7 +5801,7 @@
 
   echo "$ac_t""getpseudotty" 1>&6
 else
-if test -c /dev/ptmx && test -c /dev/pts/0
+if test -c /dev/ptmx
 then
   cat >> confdefs.h <<\EOF
 #define HAVE_DEV_PTMX 1
diff -ur /ssh-1.2.27/configure.in ssh-1.2.27/configure.in
--- /ssh-1.2.27/configure.in	Wed May 12 15:20:02 1999
+++ ssh-1.2.27/configure.in	Wed May 12 15:18:50 1999
@@ -498,7 +498,7 @@
   AC_DEFINE(HAVE_GETPSEUDOTTY)
   AC_MSG_RESULT(getpseudotty)
 else
-if test -c /dev/ptmx && test -c /dev/pts/0
+if test -c /dev/ptmx
 then
   AC_DEFINE(HAVE_DEV_PTMX)
   AC_MSG_RESULT(streams ptys)
diff -ur /ssh-1.2.27/includes.h ssh-1.2.27/includes.h
--- /ssh-1.2.27/includes.h	Wed May 12 15:19:26 1999
+++ ssh-1.2.27/includes.h	Wed Aug 04 05:46:27 1999
@@ -385,5 +385,9 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif /* HAVE_SNPRINTF */
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
      
 #endif /* INCLUDES_H */
diff -ur /ssh-1.2.27/login.c ssh-1.2.27/login.c
--- /ssh-1.2.27/login.c	Wed May 12 15:19:26 1999
+++ ssh-1.2.27/login.c	Wed Aug 04 05:50:51 1999
@@ -145,7 +145,7 @@
 #endif
 #endif
 
-  fd = open(lastlogfile, O_RDONLY);
+  fd = open(lastlogfile, O_RDONLY|O_BINARY);
   if (fd < 0)
     return 0;
   if (read(fd, &ll, sizeof(ll)) != sizeof(ll))
@@ -191,7 +191,7 @@
 #endif
 #endif
 
-  fd = open(lastlog, O_RDONLY);
+  fd = open(lastlog, O_RDONLY|O_BINARY);
   if (fd < 0)
     return 0;
   lseek(fd, (off_t)((long)uid * sizeof(ll)), 0);
@@ -333,7 +333,7 @@
   login(&u);
 #else /* HAVE_LIBUTIL_LOGIN */
   /* Append an entry to wtmp. */
-  fd = open(wtmp, O_WRONLY|O_APPEND);
+  fd = open(wtmp, O_WRONLY|O_APPEND|O_BINARY);
   if (fd >= 0)
     {
       if (write(fd, &u, sizeof(u)) != sizeof(u))
@@ -343,7 +343,7 @@
 
   /* Replace the proper entry in utmp, as identified by ut_line.  Append a
      new entry if the line could not be found. */
-  fd = open(utmp, O_RDWR);
+  fd = open(utmp, O_RDWR|O_BINARY);
   if (fd >= 0)
     {
 #ifdef HAVE_TTYSLOT
@@ -494,7 +494,7 @@
 #ifdef LASTLOG_IS_DIR
       snprintf(lastlogfile, sizeof(lastlogfile),
                "%.100s/%.100s", lastlog, user);
-      fd = open(lastlogfile, O_WRONLY | O_CREAT, 0644);
+      fd = open(lastlogfile, O_WRONLY | O_CREAT | O_BINARY, 0644);
       if (fd >= 0)
         {
           if (write(fd, &ll, sizeof(ll)) != sizeof(ll))
@@ -507,7 +507,7 @@
           log_msg("Could not open %.100s: %.100s", lastlogfile, strerror(errno));
         }
 #else /* LASTLOG_IS_DIR */
-      fd = open(lastlog, O_RDWR);
+      fd = open(lastlog, O_RDWR|O_BINARY);
       if (fd >= 0)
         {
           lseek(fd, (off_t)((long)uid * sizeof(ll)), 0);
diff -ur /ssh-1.2.27/pty.c ssh-1.2.27/pty.c
--- /ssh-1.2.27/pty.c	Wed May 12 15:19:27 1999
+++ ssh-1.2.27/pty.c	Wed Aug 04 04:35:57 1999
@@ -103,7 +103,9 @@
 #ifdef HAVE_SYS_STREAM_H
 #include <sys/stream.h>
 #endif /* HAVE_SYS_STREAM_H */
+#ifndef __CYGWIN__
 #include <stropts.h>
+#endif
 #ifdef HAVE_SYS_CONF_H
 #include <sys/conf.h>
 #endif /* HAVE_SYS_CONF_H */
@@ -235,6 +237,7 @@
   if (isastream(*ttyfd))
 #endif /* HAVE_ISASTREAM */
       { 
+#ifndef __CYGWIN__
         /* Push the appropriate streams modules, as described in Solaris pts(7). */
         if (ioctl(*ttyfd, I_PUSH, "ptem") < 0)
           error("ioctl I_PUSH ptem: %.100s", strerror(errno));
@@ -247,6 +250,7 @@
 #else
         ioctl(*ttyfd, I_PUSH, "ttcompat");
 #endif
+#endif /* __CYGWIN__ */
       }
   
   return 1;
diff -ur /ssh-1.2.27/randoms.c ssh-1.2.27/randoms.c
--- /ssh-1.2.27/randoms.c	Wed May 12 15:19:27 1999
+++ ssh-1.2.27/randoms.c	Wed Aug 04 05:52:11 1999
@@ -89,7 +89,7 @@
 
   /* Get noise from the file. */
   random_add_noise(state, filename, strlen(filename)); /* Use the path. */
-  uf = userfile_open(uid, filename, O_RDONLY, 0);
+  uf = userfile_open(uid, filename, O_RDONLY|O_BINARY, 0);
   if (uf != NULL)
     {
       state->state[0] += (int)uf;
@@ -402,7 +402,7 @@
 
   /* Create and write the file.  Failure to create the file is silently
      ignored. */
-  uf = userfile_open(uid, filename, O_WRONLY|O_CREAT|O_TRUNC, 0600);
+  uf = userfile_open(uid, filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600);
   if (uf != NULL)
     {
       /* Creation successful.  Write data to the file. */
diff -ur /ssh-1.2.27/scp.c ssh-1.2.27/scp.c
--- /ssh-1.2.27/scp.c	Wed May 12 15:19:28 1999
+++ ssh-1.2.27/scp.c	Wed Aug 04 05:55:28 1999
@@ -750,7 +750,7 @@
 
         for (indx = 0; indx < argc; ++indx) {
                 name = argv[indx];
-                if ((fd = open(name, O_RDONLY, 0)) < 0)
+                if ((fd = open(name, O_RDONLY|O_BINARY, 0)) < 0)
                         goto syserr;
                 if (fstat(fd, &stb) < 0) {
 syserr:                 run_err("%s: %s", name, strerror(errno));
@@ -1111,9 +1111,9 @@
 #ifdef HAVE_FTRUNCATE
                 /* Don't use O_TRUNC so the file doesn't get corrupted if
                    copying on itself. */
-                ofd = open(np, O_WRONLY|O_CREAT, mode);
+                ofd = open(np, O_WRONLY|O_CREAT|O_BINARY, mode);
 #else /* HAVE_FTRUNCATE */
-                ofd = open(np, O_WRONLY|O_CREAT|O_TRUNC, mode);
+                ofd = open(np, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, mode);
 #endif /* HAVE_FTRUNCATE */
                 if (ofd < 0) {
 bad:                    run_err("%s: %s", np, strerror(errno));
diff -ur /ssh-1.2.27/servconf.c ssh-1.2.27/servconf.c
--- /ssh-1.2.27/servconf.c	Wed May 12 15:19:28 1999
+++ ssh-1.2.27/servconf.c	Wed Aug 04 04:37:14 1999
@@ -147,7 +147,9 @@
 	options->port = ntohs(sp->s_port);
       else
 	options->port = SSH_DEFAULT_PORT;
+#ifndef __CYGWIN__
       endservent();
+#endif
     }
   if (options->host_key_file == NULL)
     options->host_key_file = HOST_KEY_FILE;
diff -ur /ssh-1.2.27/sshconnect.c ssh-1.2.27/sshconnect.c
--- /ssh-1.2.27/sshconnect.c	Wed May 12 15:19:29 1999
+++ ssh-1.2.27/sshconnect.c	Wed Aug 04 05:57:24 1999
@@ -1486,7 +1486,7 @@
   /* Read also some random data from the systemwide random seed file to
      avoid the user being able to guess his own session key when running
      as root. */
-  f = open(SSH_DAEMON_SEED_FILE, O_RDONLY);
+  f = open(SSH_DAEMON_SEED_FILE, O_RDONLY|O_BINARY);
   if (f >= 0)
     {
       len = read(f, seedbuf, sizeof(seedbuf)); /* Try to read 128 bits. */
diff -ur /ssh-1.2.27/sshd.c ssh-1.2.27/sshd.c
--- /ssh-1.2.27/sshd.c	Wed May 12 15:19:29 1999
+++ ssh-1.2.27/sshd.c	Wed Aug 04 06:24:24 1999
@@ -453,6 +453,10 @@
 #include "servconf.h"
 #include "userfile.h"
 #include "emulate.h"
+#ifdef __CYGWIN__
+#include <windows.h>
+extern HANDLE hToken;
+#endif /* __CYGWIN__ */
 #ifdef HAVE_USERSEC_H
 #include <usersec.h>
 #endif /* HAVE_USERSEC_H */
@@ -1460,12 +1464,14 @@
 
   /* Declare supported authentication types. */
   auth_mask = 0;
+#ifndef __CYGWIN__
   if (options.rhosts_authentication)
     auth_mask |= 1 << SSH_AUTH_RHOSTS;
   if (options.rhosts_rsa_authentication)
     auth_mask |= 1 << SSH_AUTH_RHOSTS_RSA;
   if (options.rsa_authentication)
     auth_mask |= 1 << SSH_AUTH_RSA;
+#endif /* __CYGWIN__ */
 #ifdef HAVE_TIS
   if (options.tis_authentication)
     auth_mask |= 1 << SSH_AUTH_TIS;
@@ -2234,10 +2240,12 @@
   userfile_init(pw->pw_name, pw->pw_uid, pw->pw_gid,
                 sshd_userfile_cleanup, NULL);
 
+#ifndef __CYGWIN__
   /* If we are not running as root, the user must have the same uid as the
      server. */
   if (getuid() != UID_ROOT && pw->pw_uid != getuid())
     packet_disconnect("Cannot change user when server not running as root.");
+#endif /* __CYGWIN__ */
 
   debug("Attempting authentication for %.100s.", user);
 
@@ -2354,7 +2362,11 @@
 #endif /* KERBEROS */
           
         case SSH_CMSG_AUTH_RHOSTS:
+#ifndef __CYGWIN__
           if (!options.rhosts_authentication)
+#else
+	  if (1)
+#endif
             {
               packet_get_all();
               log_msg("Rhosts authentication disabled.");
@@ -2393,7 +2405,11 @@
           break;
 
         case SSH_CMSG_AUTH_RHOSTS_RSA:
+#ifndef __CYGWIN__
           if (!options.rhosts_rsa_authentication)
+#else
+	  if (1)
+#endif
             {
               packet_get_all();
               log_msg("Rhosts with RSA authentication disabled.");
@@ -2456,7 +2472,11 @@
           break;
           
         case SSH_CMSG_AUTH_RSA:
+#ifndef __CYGWIN__
           if (!options.rsa_authentication)
+#else
+	  if (1)
+#endif
             {
               packet_get_all();
               log_msg("RSA authentication disabled.");
@@ -3544,6 +3564,7 @@
 void child_set_env(char ***envp, unsigned int *envsizep, const char *name,
                    const char *value)
 {
+#ifndef __CYGWIN__
   unsigned int i, namelen;
   char **env;
 
@@ -3577,6 +3598,9 @@
   /* Allocate space and format the variable in the appropriate slot. */
   env[i] = xmalloc(strlen(name) + strlen(value) + 2);
   snprintf(env[i], strlen(name) + strlen(value) + 2, "%s=%s", name, value);
+#else
+  setenv(name, value, 1);
+#endif /*__CYGWIN__ */
 }
 
 /* Reads environment variables from the given file and adds/overrides them
@@ -3677,6 +3701,7 @@
   /* Set PATH from SUPATH if we are logging in as root, and PATH
      otherwise.  If neither of these exists, we use the default ssh
      path. */
+#ifndef __CYGWIN__
   if (user_uid == UID_ROOT)
     def = child_get_env(defenv, "SUPATH");
   else
@@ -3692,6 +3717,7 @@
     }
   else
     child_set_env(env, envsize, "PATH", DEFAULT_PATH ":" SSH_BINDIR);
+#endif /* __CYGWIN__ */
 
   /* Set TZ if TIMEZONE is defined and we haven't inherited a value
      for TZ. */
@@ -4165,8 +4191,10 @@
             fatal("setuid %d: %.100s", (int)user_uid, strerror(errno));
         }
       
+#ifndef __CYGWIN__
       if (getuid() != user_uid || geteuid() != user_uid)
         fatal("Failed to set uids to %d.", (int)user_uid);
+#endif /* __CYGWIN__ */
 #endif /* HAVE_SIA */
 #endif /* (_BSDI_VERSION > 199510) */
 #endif /* HAVE_LOGIN_CAP_H */
@@ -4203,7 +4231,9 @@
       child_set_env(&env, &envsize, "LOGNAME", user_name);
 
 #ifndef HAVE_LOGIN_CAP_H
+#ifndef __CYGWIN__
       child_set_env(&env, &envsize, "PATH", DEFAULT_PATH ":" SSH_BINDIR);
+#endif /* __CYGWIN__ */
       
 #ifdef MAIL_SPOOL_DIRECTORY
       snprintf(buf, sizeof(buf),
@@ -4331,9 +4361,13 @@
     }
       
   
+#ifndef __CYGWIN__
   /* Must take new environment into use so that .ssh/rc, /etc/sshrc and
      xauth are run in the proper environment. */
   environ = env;
+#else
+  env = environ;
+#endif /* __CYGWIN__ */
 
 #ifdef HAVE_SIA
 #ifdef USELOGIN
@@ -4557,7 +4591,11 @@
 #if defined (__FreeBSD__) && defined(HAVE_LOGIN_CAP_H)
           execve(real_shell, argv, env);
 #else
+#ifndef __CYGWIN__
           execve(shell, argv, env);
+#else
+          sexecve(hToken, shell, argv, env);
+#endif /* __CYGWIN__ */
 #endif /* HAVE_LOGIN_CAP_H */
           /* Executing the shell failed. */
           perror(shell);
@@ -4582,7 +4620,11 @@
 #if defined (__FreeBSD__) && defined(HAVE_LOGIN_CAP_H)
   execve(real_shell, argv, env);
 #else
+#ifndef __CYGWIN__
   execve(shell, argv, env);
+#else
+  sexecve(hToken, shell, argv, env);
+#endif /* __CYGWIN__ */
 #endif /* HAVE_LOGIN_CAP_H */
   perror(shell);
   exit(1);
