* Don't create cache dir several times
* Do efreet_init before using efreet_*() functions
* Move lock creation to own function for desktop cache
+ * Set file owner to calling user
snprintf(file, sizeof(file), "%s/efreet/desktop_data.lock", efreet_cache_home_get());
lockfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (lockfd < 0) return -1;
+ efreet_fsetowner(lockfd);
memset(&fl, 0, sizeof(struct flock));
fl.l_type = F_WRLCK;
/* create homedir */
snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
- if (!ecore_file_mkpath(file)) goto efreet_error;
+ if (!ecore_file_exists(file))
+ {
+ if (!ecore_file_mkpath(file)) goto efreet_error;
+ efreet_setowner(file);
+ }
/* lock process, so that we only run one copy of this program */
lockfd = cache_lock_file();
{
dirsfd = open(efreet_desktop_cache_dirs(), O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
if (dirsfd < 0) goto error;
+ efreet_fsetowner(dirsfd);
EINA_LIST_FREE(user_dirs, dir)
{
unsigned int size = strlen(dir) + 1;
}
/* cleanup */
+ eet_sync(util_ef);
eet_close(util_ef);
+ eet_sync(ef);
eet_close(ef);
/* unlink old cache files */
}
/* rename tmp files to real files */
if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error;
+ efreet_setowner(efreet_desktop_util_cache_file());
if (rename(file, efreet_desktop_cache_file()) < 0) goto error;
+ efreet_setowner(efreet_desktop_cache_file());
}
else
{
tmpfd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (tmpfd >= 0)
{
+ efreet_fsetowner(tmpfd);
if (write(tmpfd, "a", 1) != 1) perror("write");
close(tmpfd);
}
snprintf(file, sizeof(file), "%s/efreet/icon_data.lock", efreet_cache_home_get());
lockfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (lockfd < 0) return -1;
+ efreet_fsetowner(lockfd);
memset(&fl, 0, sizeof(struct flock));
fl.l_type = F_WRLCK;
/* create homedir */
snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
- if (!ecore_file_mkpath(file)) goto on_error;
+ if (!ecore_file_exists(file))
+ {
+ if (!ecore_file_mkpath(file)) return -1;
+ efreet_setowner(file);
+ }
/* lock process, so that we only run one copy of this program */
lockfd = cache_lock_file();
}
eet_data_write(icon_ef, efreet_version_edd(), EFREET_CACHE_VERSION, icon_version, 1);
+ eet_sync(icon_ef);
eet_close(icon_ef);
+ efreet_setowner(efreet_icon_cache_file(theme->theme.name.internal));
free(icon_version);
}
eina_iterator_free(it);
icon_theme_free(theme);
eet_data_write(icon_ef, efreet_version_edd(), EFREET_CACHE_VERSION, icon_version, 1);
+ eet_sync(icon_ef);
eet_close(icon_ef);
+ efreet_setowner(efreet_icon_cache_file(EFREET_CACHE_ICON_FALLBACK));
free(icon_version);
eina_hash_free(icon_themes);
/* save data */
eet_data_write(theme_ef, efreet_version_edd(), EFREET_CACHE_VERSION, theme_version, 1);
+ eet_sync(theme_ef);
eet_close(theme_ef);
+ efreet_setowner(efreet_icon_theme_cache_file());
free(theme_version);
/* touch update file */
tmpfd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (tmpfd >= 0)
{
+ efreet_fsetowner(tmpfd);
write(tmpfd, "a", 1);
close(tmpfd);
}
#include <stdio.h>
#include <string.h>
#include <limits.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
#include <Eet.h>
#include <Ecore.h>
static void efreet_parse_locale(void);
static int efreet_parse_locale_setting(const char *env);
+static uid_t ruid;
+static uid_t rgid;
+
/**
* @return Returns > 0 if the initialization was successful, 0 otherwise
* @brief Initializes the Efreet system
EAPI int
efreet_init(void)
{
+ char *tmp;
+
if (++_efreet_init_count != 1)
return _efreet_init_count;
+ /* Find users real uid and gid */
+ tmp = getenv("SUDO_UID");
+ if (tmp)
+ ruid = strtoul(tmp, NULL, 10);
+ else
+ ruid = getuid();
+
+ tmp = getenv("SUDO_GID");
+ if (tmp)
+ rgid = strtoul(tmp, NULL, 10);
+ else
+ rgid = getgid();
+
if (!eina_init())
return --_efreet_init_count;
if (!eet_init())
}
return n;
}
+
+EAPI void
+efreet_fsetowner(int fd)
+{
+ struct stat st;
+
+ if (fd < 0) return;
+ if (fstat(fd, &st) < 0) return;
+ if (st.st_uid == ruid) return;
+
+ fchown(fd, ruid, rgid);
+}
+
+EAPI void
+efreet_setowner(const char *path)
+{
+ int fd;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) return;
+ efreet_fsetowner(fd);
+ close(fd);
+}
fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
snprintf(buf, sizeof(buf), "%s/efreet", efreet_cache_home_get());
- if (!ecore_file_mkpath(buf)) goto error;
+ if (!ecore_file_exists(buf))
+ {
+ if (!ecore_file_mkpath(buf)) goto error;
+ efreet_setowner(buf);
+ }
if (efreet_cache_update)
{
desktop_cache_exe_lock = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (desktop_cache_exe_lock < 0) return;
+ efreet_fsetowner(desktop_cache_exe_lock);
memset(&fl, 0, sizeof(struct flock));
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
icon_cache_exe_lock = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (icon_cache_exe_lock < 0) return;
+ efreet_fsetowner(icon_cache_exe_lock);
memset(&fl, 0, sizeof(struct flock));
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
snprintf(file, sizeof(file), "%s/desktop_data.lock", efreet_cache_home_get());
fd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd < 0) return 0;
+ efreet_fsetowner(fd);
/* TODO: Retry update cache later */
memset(&fl, 0, sizeof(struct flock));
fl.l_type = F_WRLCK;
cachefd = open(efreet_desktop_cache_dirs(), O_CREAT | O_APPEND | O_RDWR, S_IRUSR | S_IWUSR);
if (cachefd < 0) goto error;
+ efreet_fsetowner(cachefd);
if (fstat(cachefd, &st) < 0) goto error;
if (st.st_size > 0)
{
EAPI void efreet_cache_array_string_free(Efreet_Cache_Array_String *array);
EAPI void efreet_hash_free(Eina_Hash *hash, Eina_Free_Cb free_cb);
+EAPI void efreet_setowner(const char *path);
+EAPI void efreet_fsetowner(int fd);
#define NON_EXISTING (void *)-1