diff options
author | Leonardo Taccari <iamleot@gmail.com> | 2018-10-10 13:03:10 +0200 |
---|---|---|
committer | Daniel Carl <danielcarl@gmx.de> | 2018-10-10 22:31:54 +0200 |
commit | 43a8d1763aec964a8734aad7d688e1a84d02a36a (patch) | |
tree | a06d5cdfb0a3ba91f585d08c700df37ae199c6dd /src | |
parent | 79e0a8cabae152d78ee7179d850269a86daa77f0 (diff) |
Add a mode (in chmod(2) context) argument to util_get_filepath()
Add a mode argument to util_get_filepath() in order to adjust file
permissions when creating file. Adjust all util_get_filepath()
call and file permissions making them readable and writable only
by the user.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | src/util.c | 4 | ||||
-rw-r--r-- | src/util.h | 2 |
3 files changed, 14 insertions, 12 deletions
@@ -1637,19 +1637,19 @@ static void vimb_setup(void) vb.files[FILES_CONFIG] = g_strdup(rp); free(rp); } else { - vb.files[FILES_CONFIG] = util_get_filepath(path, "config", FALSE); + vb.files[FILES_CONFIG] = util_get_filepath(path, "config", FALSE, 0600); } /* Setup those files that are use multiple time during runtime */ - vb.files[FILES_CLOSED] = util_get_filepath(path, "closed", TRUE); - vb.files[FILES_COOKIE] = util_get_filepath(path, "cookies.db", TRUE); - vb.files[FILES_USER_STYLE] = util_get_filepath(path, "style.css", FALSE); - vb.files[FILES_SCRIPT] = util_get_filepath(path, "scripts.js", FALSE); - vb.files[FILES_HISTORY] = util_get_filepath(path, "history", TRUE); - vb.files[FILES_COMMAND] = util_get_filepath(path, "command", TRUE); - vb.files[FILES_BOOKMARK] = util_get_filepath(path, "bookmark", TRUE); - vb.files[FILES_QUEUE] = util_get_filepath(path, "queue", TRUE); - vb.files[FILES_SEARCH] = util_get_filepath(path, "search", TRUE); + vb.files[FILES_CLOSED] = util_get_filepath(path, "closed", TRUE, 0600); + vb.files[FILES_COOKIE] = util_get_filepath(path, "cookies.db", TRUE, 0600); + vb.files[FILES_USER_STYLE] = util_get_filepath(path, "style.css", FALSE, 0600); + vb.files[FILES_SCRIPT] = util_get_filepath(path, "scripts.js", FALSE, 0600); + vb.files[FILES_HISTORY] = util_get_filepath(path, "history", TRUE, 0600); + vb.files[FILES_COMMAND] = util_get_filepath(path, "command", TRUE, 0600); + vb.files[FILES_BOOKMARK] = util_get_filepath(path, "bookmark", TRUE, 0600); + vb.files[FILES_QUEUE] = util_get_filepath(path, "queue", TRUE, 0600); + vb.files[FILES_SEARCH] = util_get_filepath(path, "search", TRUE, 0600); g_free(path); /* Use seperate rendering processed for the webview of the clients in the @@ -362,8 +362,9 @@ char *util_get_file_contents(const char *filename, gsize *length) * @dir: Directory in which the file is searched. * @filename: Filename to built the absolute path with. * @create: If TRUE, the file is created if it does not already exist. + * @mode: Mode (file permission as chmod(2)) used for the file when creating it. */ -char *util_get_filepath(const char *dir, const char *filename, gboolean create) +char *util_get_filepath(const char *dir, const char *filename, gboolean create, int mode) { char *fullpath; @@ -375,6 +376,7 @@ char *util_get_filepath(const char *dir, const char *filename, gboolean create) } else if (create) { /* If create option was given - create the file. */ fclose(fopen(fullpath, "a")); + g_chmod(fullpath, mode); return fullpath; } @@ -42,7 +42,7 @@ void util_file_prepend_line(const char *file, const char *line, char *util_file_pop_line(const char *file, int *item_count); char *util_get_config_dir(void); char *util_get_file_contents(const char *filename, gsize *length); -char *util_get_filepath(const char *dir, const char *filename, gboolean create); +char *util_get_filepath(const char *dir, const char *filename, gboolean create, int mode); char **util_get_lines(const char *filename); GList *util_file_to_unique_list(const char *filename, Util_Content_Func func, guint max_items); |