summaryrefslogtreecommitdiffstats
path: root/authfile.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-12-07 15:38:31 +1100
committerDamien Miller <djm@mindrot.org>1999-12-07 15:38:31 +1100
commit037a0dc0835bb5a442bdcbeecdd5baed723f0b45 (patch)
treed02954d57ac437fd036e3e9544f24559ca8f0f0f /authfile.c
parenteabf3417bc73ca9546a3ed489cd809ffdf303853 (diff)
- 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)
Diffstat (limited to 'authfile.c')
-rw-r--r--authfile.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/authfile.c b/authfile.c
index 97d0a878..b0e832a0 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 @@ save_private_key(const char *filename, const char *passphrase,
{
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 @@ save_private_key(const char *filename, const char *passphrase,
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 @@ int
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 @@ load_public_key(const char *filename, RSA * pub,
* 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 @@ int
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 @@ load_private_key(const char *filename, const char *passphrase,
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 @@ load_private_key(const char *filename, const char *passphrase,
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) {