diff options
author | Jan Cholasta <jcholast@redhat.com> | 2012-02-27 06:57:06 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-02-27 11:52:34 -0500 |
commit | 26202f8e447b694843d3fb9532673dc280a4c245 (patch) | |
tree | 4d4bf3ab72c826dd0c8ba63d53c382d999232629 | |
parent | 3194ce1c60e766e2a850949427dd99ad09944ddb (diff) | |
download | sssd-26202f8e447b694843d3fb9532673dc280a4c245.tar.gz sssd-26202f8e447b694843d3fb9532673dc280a4c245.tar.bz2 sssd-26202f8e447b694843d3fb9532673dc280a4c245.zip |
SSH: Use fchmod instead of chmod on known_hosts file
-rw-r--r-- | src/responder/ssh/sshsrv_cmd.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/responder/ssh/sshsrv_cmd.c b/src/responder/ssh/sshsrv_cmd.c index 40d9c520..33f042a3 100644 --- a/src/responder/ssh/sshsrv_cmd.c +++ b/src/responder/ssh/sshsrv_cmd.c @@ -476,6 +476,7 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx) fd = mkstemp(filename); if (fd == -1) { + filename = NULL; ret = errno; goto done; } @@ -547,10 +548,7 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx) dom = dom->next; } - close(fd); - fd = -1; - - ret = chmod(filename, 0644); + ret = fchmod(fd, 0644); if (ret == -1) { ret = errno; goto done; @@ -565,10 +563,8 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx) ret = EOK; done: - if (fd != -1) { - close(fd); - unlink(filename); - } + if (fd != -1) close(fd); + if (ret != EOK && filename) unlink(filename); talloc_free(tmp_ctx); return ret; |