diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2020-05-13 09:55:58 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2020-05-13 09:55:58 +0000 |
commit | fe6e13b4cd9f136c11d1e3bcb6d2a841b872b8c3 (patch) | |
tree | 1b8b0cfca65211a847fb89b02d148d2b68d9acc7 /usr.bin | |
parent | c5cdba5d1fcf26c9b44d455dce72885447cc0a03 (diff) |
preserve group/world read permission on known_hosts file across runs of
"ssh-keygen -Rf /path". The old behaviour was to remove all rights for
group/other. bz#3146 ok dtucker@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ssh/ssh-keygen.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c index 02cdd276fc9..53e32bab905 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.409 2020/05/02 07:19:43 djm Exp $ */ +/* $OpenBSD: ssh-keygen.c,v 1.410 2020/05/13 09:55:57 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -1270,6 +1270,7 @@ do_known_hosts(struct passwd *pw, const char *name, int find_host, int r, fd, oerrno, inplace = 0; struct known_hosts_ctx ctx; u_int foreach_options; + struct stat sb; if (!have_identity) { cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid); @@ -1279,6 +1280,8 @@ do_known_hosts(struct passwd *pw, const char *name, int find_host, free(cp); have_identity = 1; } + if (stat(identity_file, &sb) != 0) + fatal("Cannot stat %s: %s", identity_file, strerror(errno)); memset(&ctx, 0, sizeof(ctx)); ctx.out = stdout; @@ -1305,6 +1308,7 @@ do_known_hosts(struct passwd *pw, const char *name, int find_host, unlink(tmp); fatal("fdopen: %s", strerror(oerrno)); } + fchmod(fd, sb.st_mode & 0644); inplace = 1; } /* XXX support identity_file == "-" for stdin */ |