summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-08-12 12:45:34 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-09-01 13:01:42 +0200
commit3954cd07dae78bf79136f0854472757d1ed26897 (patch)
tree4e027f68352dc1a9df29a082b3fd02b41b036f57
parent03a4bb0706635ef6dcb238d90e8abce9a3d8e45f (diff)
downloadsssd-master.zip
sssd-master.tar.gz
sssd-master.tar.xz
GPO: Use sss_unique_file and close fd on failureHEADmaster
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). Reviewed-by: Pavel Březina <pbrezina@redhat.com>
-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 6547f9c..1b59971 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);