aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-10-16 04:48:20 +0200
committerSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-10-16 04:48:20 +0200
commitbd5a5e7fce3931476bbc68a156be28e58f5d7ef8 (patch)
treea945a5be5185ed83b71bd871eeccf56e0f211472 /src/bin/efreet
parentSet secure file permissions for temporary file (diff)
downloadefl-bd5a5e7fce3931476bbc68a156be28e58f5d7ef8.tar.gz
efreet: Use eina_file_mkstemp
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreet_desktop_cache_create.c30
-rw-r--r--src/bin/efreet/efreetd.c28
2 files changed, 24 insertions, 34 deletions
diff --git a/src/bin/efreet/efreet_desktop_cache_create.c b/src/bin/efreet/efreet_desktop_cache_create.c
index 2fc6e917d7..fe67da1fb4 100644
--- a/src/bin/efreet/efreet_desktop_cache_create.c
+++ b/src/bin/efreet/efreet_desktop_cache_create.c
@@ -223,9 +223,9 @@ main(int argc, char **argv)
int lockfd = -1, tmpfd;
int changed = 0;
int i;
- char file[PATH_MAX] = { '\0' };
- char util_file[PATH_MAX] = { '\0' };
- mode_t um;
+ char path_name[PATH_MAX] = { '\0' };
+ Eina_Tmpstr *file = NULL;
+ Eina_Tmpstr *util_file = NULL;
if (!eina_init()) goto eina_error;
_efreet_desktop_cache_log_dom =
@@ -273,11 +273,11 @@ main(int argc, char **argv)
if (!efreet_init()) goto efreet_error;
/* create homedir */
- snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
- if (!ecore_file_exists(file))
+ snprintf(path_name, sizeof(path_name), "%s/efreet", efreet_cache_home_get());
+ if (!ecore_file_exists(path_name))
{
- if (!ecore_file_mkpath(file)) goto efreet_error;
- efreet_setowner(file);
+ if (!ecore_file_mkpath(path_name)) goto efreet_error;
+ efreet_setowner(path_name);
}
/* lock process, so that we only run one copy of this program */
@@ -296,21 +296,13 @@ main(int argc, char **argv)
}
/* create cache */
- snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file());
- /* set secure umask for temporary files */
- um = umask(0077);
- tmpfd = mkstemp(file);
- umask(um);
+ tmpfd = eina_file_mkstemp("efreet_desktop_cache_XXXXXX", &file);
if (tmpfd < 0) goto error;
close(tmpfd);
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) goto error;
- snprintf(util_file, sizeof(util_file), "%s.XXXXXX", efreet_desktop_util_cache_file());
- /* set secure umask for temporary files */
- um = umask(0077);
- tmpfd = mkstemp(util_file);
- umask(um);
+ tmpfd = eina_file_mkstemp("efreet_desktop_util_cache_XXXXXX", &util_file);
if (tmpfd < 0) goto error;
close(tmpfd);
util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
@@ -450,6 +442,8 @@ main(int argc, char **argv)
printf("%c\n", c);
}
+ eina_tmpstr_del(file);
+ eina_tmpstr_del(util_file);
EINA_LIST_FREE(systemdirs, dir)
eina_stringshare_del(dir);
eina_list_free(extra_dirs);
@@ -461,6 +455,8 @@ main(int argc, char **argv)
close(lockfd);
return 0;
error:
+ eina_tmpstr_del(file);
+ eina_tmpstr_del(util_file);
IF_FREE(dir);
edd_error:
if (old_file_ids)
diff --git a/src/bin/efreet/efreetd.c b/src/bin/efreet/efreetd.c
index 18fc500db1..414bb2cbf4 100644
--- a/src/bin/efreet/efreetd.c
+++ b/src/bin/efreet/efreetd.c
@@ -26,29 +26,22 @@ quit(void)
int
main(int argc, char *argv[])
{
- char path[PATH_MAX];
FILE *log;
- mode_t um;
+ int fd;
- strcpy(path, "/tmp/efreetd_XXXXXX");
- um = umask(0077);
- if (mkstemp(path) < 0)
- {
- perror("mkstemp");
- umask(um);
- return 1;
- }
- umask(um);
- if (chmod(path, 0700) < 0)
+ if (!eina_init()) return 1;
+
+ fd = eina_file_mkstemp("efreetd_XXXXXX", NULL);
+ if (fd < 0)
{
- perror("chmod");
- return 1;
+ EINA_LOG_ERR("mkstemp");
+ goto eina_error;
}
- log = fopen(path, "wb");
- if (!log) return 1;
+ log = fdopen(fd, "wb");
+ if (!log)
+ goto eina_error;
- if (!eina_init()) return 1;
eina_log_print_cb_set(eina_log_print_cb_file, log);
efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR);
@@ -91,6 +84,7 @@ ecore_error:
if (efreetd_log_dom >= 0)
eina_log_domain_unregister(efreetd_log_dom);
efreetd_log_dom = -1;
+eina_error:
eina_shutdown();
return 1;
}