- Merged more OpenBSD changes:
   - [atomicio.c authfd.c scp.c serverloop.c ssh.h sshconnect.c sshd.c]
     move atomicio into it's own file.  wrap all socket write()s which
     were doing write(sock, buf, len) != len, with atomicio() calls.
   - [auth-skey.c]
     fd leak
   - [authfile.c]
     properly name fd variable
   - [channels.c]
     display great hatred towards strcpy
   - [pty.c pty.h sshd.c]
     use openpty() if it exists (it does on BSD4_4)
   - [tildexpand.c]
     check for ~ expansion past MAXPATHLEN
 - Modified helper.c to use new atomicio function.
 - Reformat Makefile a little
 - Moved RC4 routines from rc4.[ch] into helper.c
 - Added autoconf code to detect /dev/ptmx (Solaris) and /dev/ptc (AIX)
diff --git a/authfile.c b/authfile.c
index 97d0a87..b0e832a 100644
--- a/authfile.c
+++ b/authfile.c
@@ -15,7 +15,7 @@
  */
 
 #include "includes.h"
-RCSID("$Id: authfile.c,v 1.5 1999/11/25 00:54:58 damien Exp $");
+RCSID("$Id: authfile.c,v 1.6 1999/12/07 04:38:32 damien Exp $");
 
 #ifdef HAVE_OPENSSL
 #include <openssl/bn.h>
@@ -46,7 +46,7 @@
 {
 	Buffer buffer, encrypted;
 	char buf[100], *cp;
-	int f, i;
+	int fd, i;
 	CipherContext cipher;
 	int cipher_type;
 	u_int32_t rand;
@@ -117,19 +117,19 @@
 	memset(buf, 0, sizeof(buf));
 	buffer_free(&buffer);
 
-	f = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
-	if (f < 0)
+	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+	if (fd < 0)
 		return 0;
-	if (write(f, buffer_ptr(&encrypted), buffer_len(&encrypted)) !=
+	if (write(fd, buffer_ptr(&encrypted), buffer_len(&encrypted)) !=
 	    buffer_len(&encrypted)) {
 		debug("Write to key file %.200s failed: %.100s", filename,
 		      strerror(errno));
 		buffer_free(&encrypted);
-		close(f);
+		close(fd);
 		remove(filename);
 		return 0;
 	}
-	close(f);
+	close(fd);
 	buffer_free(&encrypted);
 	return 1;
 }
@@ -144,28 +144,28 @@
 load_public_key(const char *filename, RSA * pub,
 		char **comment_return)
 {
-	int f, i;
+	int fd, i;
 	off_t len;
 	Buffer buffer;
 	char *cp;
 
-	f = open(filename, O_RDONLY);
-	if (f < 0)
+	fd = open(filename, O_RDONLY);
+	if (fd < 0)
 		return 0;
-	len = lseek(f, (off_t) 0, SEEK_END);
-	lseek(f, (off_t) 0, SEEK_SET);
+	len = lseek(fd, (off_t) 0, SEEK_END);
+	lseek(fd, (off_t) 0, SEEK_SET);
 
 	buffer_init(&buffer);
 	buffer_append_space(&buffer, &cp, len);
 
-	if (read(f, cp, (size_t) len) != (size_t) len) {
+	if (read(fd, cp, (size_t) len) != (size_t) len) {
 		debug("Read from key file %.200s failed: %.100s", filename,
 		      strerror(errno));
 		buffer_free(&buffer);
-		close(f);
+		close(fd);
 		return 0;
 	}
-	close(f);
+	close(fd);
 
 	/* Check that it is at least big enought to contain the ID string. */
 	if (len < strlen(AUTHFILE_ID_STRING) + 1) {
@@ -178,7 +178,7 @@
 	 * from the buffer.
 	 */
 	for (i = 0; i < (unsigned int) strlen(AUTHFILE_ID_STRING) + 1; i++)
-		if (buffer_get_char(&buffer) != (unsigned char) AUTHFILE_ID_STRING[i]) {
+		if (buffer_get_char(&buffer) != (u_char) AUTHFILE_ID_STRING[i]) {
 			debug("Bad key file %.200s.", filename);
 			buffer_free(&buffer);
 			return 0;
@@ -213,7 +213,7 @@
 load_private_key(const char *filename, const char *passphrase,
 		 RSA * prv, char **comment_return)
 {
-	int f, i, check1, check2, cipher_type;
+	int fd, i, check1, check2, cipher_type;
 	off_t len;
 	Buffer buffer, decrypted;
 	char *cp;
@@ -222,14 +222,15 @@
 	BIGNUM *aux;
 	struct stat st;
 
-	f = open(filename, O_RDONLY);
-	if (f < 0)
+	fd = open(filename, O_RDONLY);
+	if (fd < 0)
 		return 0;
 
 	/* check owner and modes */
-	if (fstat(f, &st) < 0 ||
+	if (fstat(fd, &st) < 0 ||
 	    (st.st_uid != 0 && st.st_uid != getuid()) ||
 	    (st.st_mode & 077) != 0) {
+		close(fd);
 		error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
 		error("@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @");
 		error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
@@ -238,20 +239,20 @@
 		error("It is recommended that your private key files are NOT accessible by others.");
 		return 0;
 	}
-	len = lseek(f, (off_t) 0, SEEK_END);
-	lseek(f, (off_t) 0, SEEK_SET);
+	len = lseek(fd, (off_t) 0, SEEK_END);
+	lseek(fd, (off_t) 0, SEEK_SET);
 
 	buffer_init(&buffer);
 	buffer_append_space(&buffer, &cp, len);
 
-	if (read(f, cp, (size_t) len) != (size_t) len) {
+	if (read(fd, cp, (size_t) len) != (size_t) len) {
 		debug("Read from key file %.200s failed: %.100s", filename,
 		      strerror(errno));
 		buffer_free(&buffer);
-		close(f);
+		close(fd);
 		return 0;
 	}
-	close(f);
+	close(fd);
 
 	/* Check that it is at least big enought to contain the ID string. */
 	if (len < strlen(AUTHFILE_ID_STRING) + 1) {