summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-08-12 13:05:32 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-08-17 15:22:15 +0200
commit84493af37d4b57294e94b7bb0596dec51e06b7b0 (patch)
tree869239dcece633edaf6f516cbf4857cfeb943306
parent51ae9cb4ed85b60cfe00eaf6d3a4af39ed409ddc (diff)
downloadsssd-84493af37d4b57294e94b7bb0596dec51e06b7b0.tar.gz
sssd-84493af37d4b57294e94b7bb0596dec51e06b7b0.tar.xz
sssd-84493af37d4b57294e94b7bb0596dec51e06b7b0.zip
SSH: Use sss_unique_file_ex to create the known hosts file
Simplifies the code. Reviewed-by: Pavel Březina <pbrezina@redhat.com>
-rw-r--r--src/responder/ssh/sshsrv_cmd.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/responder/ssh/sshsrv_cmd.c b/src/responder/ssh/sshsrv_cmd.c
index f630e5f03..5f5487035 100644
--- a/src/responder/ssh/sshsrv_cmd.c
+++ b/src/responder/ssh/sshsrv_cmd.c
@@ -538,7 +538,7 @@ static errno_t
ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx)
{
TALLOC_CTX *tmp_ctx;
- errno_t ret, tmp_ret;
+ errno_t ret;
const char *attrs[] = {
SYSDB_NAME,
SYSDB_NAME_ALIAS,
@@ -557,7 +557,6 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx)
char *filename = NULL;
char *entstr;
ssize_t wret;
- mode_t old_mask;
tmp_ctx = talloc_new(NULL);
if (!tmp_ctx) {
@@ -580,12 +579,9 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx)
goto done;
}
- old_mask = umask(0133);
- fd = mkstemp(filename);
- umask(old_mask);
+ fd = sss_unique_file_ex(tmp_ctx, filename, 0133, &ret);
if (fd == -1) {
filename = NULL;
- ret = errno;
goto done;
}
@@ -655,18 +651,9 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx)
ret = EOK;
done:
- if (fd != -1) close(fd);
- if (ret != EOK && filename) {
- tmp_ret = unlink(filename);
- /* non-fatal failure */
- if (tmp_ret != EOK) {
- tmp_ret = errno;
- DEBUG(SSSDBG_MINOR_FAILURE,
- "Failed to remove file: %s - %d : [%s]!\n",
- filename, tmp_ret, sss_strerror(tmp_ret));
- }
+ if (fd != -1) {
+ close(fd);
}
-
talloc_free(tmp_ctx);
return ret;