diff options
author | 2020-06-26 05:02:03 +0000 | |
---|---|---|
committer | 2020-06-26 05:02:03 +0000 | |
commit | 2f0dab9281a8112b1c5413e089c76a516d26a3f5 (patch) | |
tree | c45dad6b700f0e63784f71abba46225026e18667 /usr.bin/ssh/ssh-keygen.c | |
parent | drm/amdkfd: Use correct major in devcgroup check (diff) | |
download | wireguard-openbsd-2f0dab9281a8112b1c5413e089c76a516d26a3f5.tar.xz wireguard-openbsd-2f0dab9281a8112b1c5413e089c76a516d26a3f5.zip |
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@
Diffstat (limited to 'usr.bin/ssh/ssh-keygen.c')
-rw-r--r-- | usr.bin/ssh/ssh-keygen.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c index c1e307566e3..17866937eaf 100644 --- a/usr.bin/ssh/ssh-keygen.c +++ b/usr.bin/ssh/ssh-keygen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keygen.c,v 1.412 2020/05/29 03:11:54 djm Exp $ */ +/* $OpenBSD: ssh-keygen.c,v 1.413 2020/06/26 05:02:03 dtucker Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -3060,11 +3060,10 @@ usage(void) int main(int argc, char **argv) { - char dotsshdir[PATH_MAX], comment[1024], *passphrase; + char comment[1024], *passphrase; char *rr_hostname = NULL, *ep, *fp, *ra; struct sshkey *private, *public; struct passwd *pw; - struct stat st; int r, opt, type; int change_passphrase = 0, change_comment = 0, show_cert = 0; int find_host = 0, delete_host = 0, hash_hosts = 0; @@ -3584,20 +3583,8 @@ main(int argc, char **argv) ask_filename(pw, "Enter file in which to save the key"); /* Create ~/.ssh directory if it doesn't already exist. */ - snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", - pw->pw_dir, _PATH_SSH_USER_DIR); - if (strstr(identity_file, dotsshdir) != NULL) { - if (stat(dotsshdir, &st) == -1) { - if (errno != ENOENT) { - error("Could not stat %s: %s", dotsshdir, - strerror(errno)); - } else if (mkdir(dotsshdir, 0700) == -1) { - error("Could not create directory '%s': %s", - dotsshdir, strerror(errno)); - } else if (!quiet) - printf("Created directory '%s'.\n", dotsshdir); - } - } + hostfile_create_user_ssh_dir(identity_file, !quiet); + /* If the file already exists, ask the user to confirm. */ if (!confirm_overwrite(identity_file)) exit(1); |