summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/providers/ad/ad_gpo_child.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/providers/ad/ad_gpo_child.c b/src/providers/ad/ad_gpo_child.c
index 6547f9c05..1b5997164 100644
--- a/src/providers/ad/ad_gpo_child.c
+++ b/src/providers/ad/ad_gpo_child.c
@@ -273,10 +273,10 @@ static errno_t gpo_cache_store_file(const char *smb_path,
int buflen)
{
int ret;
+ int fret;
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 +318,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;
}
@@ -353,14 +350,6 @@ static errno_t gpo_cache_store_file(const char *smb_path,
goto done;
}
- ret = close(fd);
- if (ret == -1) {
- ret = errno;
- DEBUG(SSSDBG_CRIT_FAILURE,
- "close failed [%d][%s].\n", ret, strerror(ret));
- goto done;
- }
-
ret = rename(tmp_name, filename);
if (ret == -1) {
ret = errno;
@@ -369,10 +358,19 @@ 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);
+ DEBUG(SSSDBG_CRIT_FAILURE, "Error encountered: %d.\n", ret);
+ }
+
+ if (fd != -1) {
+ fret = close(fd);
+ if (fret == -1) {
+ fret = errno;
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "close failed [%d][%s].\n", fret, strerror(fret));
+ }
}
talloc_free(tmp_ctx);