diff options
author | djm@openbsd.org <djm@openbsd.org> | 2020-05-13 09:55:57 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2020-05-27 10:09:19 +1000 |
commit | f2d84f1b3fa68d77c99238d4c645d0266fae2a74 (patch) | |
tree | 8085ec5a2a634b35f4a7aa307b56e05cb3c86eb2 /ssh-keygen.c | |
parent | 05a651400da6fbe12296c34e3d3bcf09f034fbbf (diff) |
upstream: 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@
OpenBSD-Commit-ID: dc369d0e0b5dd826430c63fd5f4b269953448a8a
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r-- | ssh-keygen.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c index 8c23a54cf..bcf1ece39 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-keygen.c,v 1.409 2020/05/02 07:19:43 djm Exp $ */ | 1 | /* $OpenBSD: ssh-keygen.c,v 1.410 2020/05/13 09:55:57 djm 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 |
@@ -1292,6 +1292,7 @@ do_known_hosts(struct passwd *pw, const char *name, int find_host, | |||
1292 | int r, fd, oerrno, inplace = 0; | 1292 | int r, fd, oerrno, inplace = 0; |
1293 | struct known_hosts_ctx ctx; | 1293 | struct known_hosts_ctx ctx; |
1294 | u_int foreach_options; | 1294 | u_int foreach_options; |
1295 | struct stat sb; | ||
1295 | 1296 | ||
1296 | if (!have_identity) { | 1297 | if (!have_identity) { |
1297 | cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid); | 1298 | cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid); |
@@ -1301,6 +1302,8 @@ do_known_hosts(struct passwd *pw, const char *name, int find_host, | |||
1301 | free(cp); | 1302 | free(cp); |
1302 | have_identity = 1; | 1303 | have_identity = 1; |
1303 | } | 1304 | } |
1305 | if (stat(identity_file, &sb) != 0) | ||
1306 | fatal("Cannot stat %s: %s", identity_file, strerror(errno)); | ||
1304 | 1307 | ||
1305 | memset(&ctx, 0, sizeof(ctx)); | 1308 | memset(&ctx, 0, sizeof(ctx)); |
1306 | ctx.out = stdout; | 1309 | ctx.out = stdout; |
@@ -1327,6 +1330,7 @@ do_known_hosts(struct passwd *pw, const char *name, int find_host, | |||
1327 | unlink(tmp); | 1330 | unlink(tmp); |
1328 | fatal("fdopen: %s", strerror(oerrno)); | 1331 | fatal("fdopen: %s", strerror(oerrno)); |
1329 | } | 1332 | } |
1333 | fchmod(fd, sb.st_mode & 0644); | ||
1330 | inplace = 1; | 1334 | inplace = 1; |
1331 | } | 1335 | } |
1332 | /* XXX support identity_file == "-" for stdin */ | 1336 | /* XXX support identity_file == "-" for stdin */ |