summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2020-06-26 05:02:03 +0000
committerDamien Miller <djm@mindrot.org>2020-06-26 15:24:27 +1000
commit74344c3ca42c3f53b00b025daf09ae7f6aa38076 (patch)
tree4952081cdbd6c6f3e6e891cd09a7688f003ea639 /ssh-keygen.c
parentc9e24daac6324fcbdba171392c325bf9ccc3c768 (diff)
upstream: Defer creation of ~/.ssh by ssh(1) until we attempt to
write to it so we don't leave an empty .ssh directory when it's not needed. Use the same function to replace the code in ssh-keygen that does the same thing. bz#3156, ok djm@ OpenBSD-Commit-ID: 59c073b569be1a60f4de36f491a4339bc4ae870f
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index bdc29e00a..7c6f11f40 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.412 2020/05/29 03:11:54 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.413 2020/06/26 05:02:03 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -3082,11 +3082,10 @@ usage(void)
3082int 3082int
3083main(int argc, char **argv) 3083main(int argc, char **argv)
3084{ 3084{
3085 char dotsshdir[PATH_MAX], comment[1024], *passphrase; 3085 char comment[1024], *passphrase;
3086 char *rr_hostname = NULL, *ep, *fp, *ra; 3086 char *rr_hostname = NULL, *ep, *fp, *ra;
3087 struct sshkey *private, *public; 3087 struct sshkey *private, *public;
3088 struct passwd *pw; 3088 struct passwd *pw;
3089 struct stat st;
3090 int r, opt, type; 3089 int r, opt, type;
3091 int change_passphrase = 0, change_comment = 0, show_cert = 0; 3090 int change_passphrase = 0, change_comment = 0, show_cert = 0;
3092 int find_host = 0, delete_host = 0, hash_hosts = 0; 3091 int find_host = 0, delete_host = 0, hash_hosts = 0;
@@ -3609,20 +3608,8 @@ main(int argc, char **argv)
3609 ask_filename(pw, "Enter file in which to save the key"); 3608 ask_filename(pw, "Enter file in which to save the key");
3610 3609
3611 /* Create ~/.ssh directory if it doesn't already exist. */ 3610 /* Create ~/.ssh directory if it doesn't already exist. */
3612 snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", 3611 hostfile_create_user_ssh_dir(identity_file, !quiet);
3613 pw->pw_dir, _PATH_SSH_USER_DIR); 3612
3614 if (strstr(identity_file, dotsshdir) != NULL) {
3615 if (stat(dotsshdir, &st) == -1) {
3616 if (errno != ENOENT) {
3617 error("Could not stat %s: %s", dotsshdir,
3618 strerror(errno));
3619 } else if (mkdir(dotsshdir, 0700) == -1) {
3620 error("Could not create directory '%s': %s",
3621 dotsshdir, strerror(errno));
3622 } else if (!quiet)
3623 printf("Created directory '%s'.\n", dotsshdir);
3624 }
3625 }
3626 /* If the file already exists, ask the user to confirm. */ 3613 /* If the file already exists, ask the user to confirm. */
3627 if (!confirm_overwrite(identity_file)) 3614 if (!confirm_overwrite(identity_file))
3628 exit(1); 3615 exit(1);