>From 729bf7ce633fa8065e82e7e985a776f949bdd87d Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 12 Aug 2015 12:45:34 +0200 Subject: [PATCH] GPO: Use sss_unique_file and close fd on failure The GPO child didn't remove temporary file on failure and didn't close the fd on failure (the latter was not much of a problem for a short-lived child process). --- src/providers/ad/ad_gpo_child.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/providers/ad/ad_gpo_child.c b/src/providers/ad/ad_gpo_child.c index 03951af041463000d51695fe1a86609ed6c7c1c2..b4c6aa5a3535377dc8aefae4bd959e8bbc959b26 100644 --- a/src/providers/ad/ad_gpo_child.c +++ b/src/providers/ad/ad_gpo_child.c @@ -276,7 +276,6 @@ static errno_t gpo_cache_store_file(const char *smb_path, int fd = -1; char *tmp_name = NULL; ssize_t written; - mode_t old_umask; char *filename = NULL; char *smb_path_with_suffix = NULL; TALLOC_CTX *tmp_ctx = NULL; @@ -318,13 +317,10 @@ static errno_t gpo_cache_store_file(const char *smb_path, goto done; } - old_umask = umask(077); - fd = mkstemp(tmp_name); - umask(old_umask); + fd = sss_unique_file(tmp_ctx, tmp_name, &ret); if (fd == -1) { - ret = errno; DEBUG(SSSDBG_CRIT_FAILURE, - "mkstemp failed [%d][%s].\n", ret, strerror(ret)); + "sss_unique_file failed [%d][%s].\n", ret, strerror(ret)); goto done; } @@ -354,6 +350,7 @@ static errno_t gpo_cache_store_file(const char *smb_path, } ret = close(fd); + fd = -1; if (ret == -1) { ret = errno; DEBUG(SSSDBG_CRIT_FAILURE, @@ -369,12 +366,16 @@ static errno_t gpo_cache_store_file(const char *smb_path, goto done; } + ret = EOK; done: - if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Error encountered: %d.\n", ret); } + if (fd != -1) { + close(fd); + } + talloc_free(tmp_ctx); return ret; } -- 2.4.3