summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-03-09 03:14:40 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-03-09 03:14:40 +0000
commit2350800b95c7586362ecfea2732b205949806485 (patch)
treeff53fc6d05f17d7bd64ad05c6935274e63dbf4c3 /usr.bin
parent806de81a5d7719f2316d641709fe3eaae8e6c587 (diff)
create *.pub files with umask 0644, so that you can mv them to authorized_keys
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/ssh-keygen.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c
index f245faea2a9..065c752cd18 100644
--- a/usr.bin/ssh/ssh-keygen.c
+++ b/usr.bin/ssh/ssh-keygen.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-keygen.c,v 1.45 2001/02/22 08:03:51 deraadt Exp $");
+RCSID("$OpenBSD: ssh-keygen.c,v 1.46 2001/03/09 03:14:39 deraadt Exp $");
#include <openssl/evp.h>
#include <openssl/pem.h>
@@ -508,12 +508,11 @@ do_change_passphrase(struct passwd *pw)
void
do_change_comment(struct passwd *pw)
{
- char new_comment[1024], *comment;
- Key *private;
- Key *public;
- char *passphrase;
+ char new_comment[1024], *comment, *passphrase;
+ Key *private, *public;
struct stat st;
FILE *f;
+ int fd;
if (!have_identity)
ask_filename(pw, "Enter file in which the key is");
@@ -581,11 +580,16 @@ do_change_comment(struct passwd *pw)
key_free(private);
strlcat(identity_file, ".pub", sizeof(identity_file));
- f = fopen(identity_file, "w");
- if (!f) {
+ fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (fd == -1) {
printf("Could not save your public key in %s\n", identity_file);
exit(1);
}
+ f = fdopen(fd, "w");
+ if (f == NULL) {
+ printf("fdopen %s failed", identity_file);
+ exit(1);
+ }
if (!key_write(public, f))
fprintf(stderr, "write key failed");
key_free(public);
@@ -613,12 +617,11 @@ int
main(int ac, char **av)
{
char dotsshdir[16 * 1024], comment[1024], *passphrase1, *passphrase2;
+ Key *private, *public;
struct passwd *pw;
- int opt, type;
+ int opt, type, fd;
struct stat st;
FILE *f;
- Key *private;
- Key *public;
extern int optind;
extern char *optarg;
@@ -820,11 +823,16 @@ passphrase_again:
printf("Your identification has been saved in %s.\n", identity_file);
strlcat(identity_file, ".pub", sizeof(identity_file));
- f = fopen(identity_file, "w");
- if (!f) {
+ fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (fd == -1) {
printf("Could not save your public key in %s\n", identity_file);
exit(1);
}
+ f = fdopen(fd, "w");
+ if (f == NULL) {
+ printf("fdopen %s failed", identity_file);
+ exit(1);
+ }
if (!key_write(public, f))
fprintf(stderr, "write key failed");
fprintf(f, " %s\n", comment);