1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-01 03:36:26 -04:00

Simplify secure_open() call, make it a wrapper around secure_open_umask().

This commit is contained in:
Laurent MONIN 2006-01-10 23:49:35 +01:00 committed by Jonas Fonseca
parent 5fd2b6228f
commit 1c95d6c2af
8 changed files with 15 additions and 9 deletions

View File

@ -321,7 +321,7 @@ save_input_history(struct input_history *history, unsigned char *filename)
history_file = straconcat(elinks_home, filename, NULL); history_file = straconcat(elinks_home, filename, NULL);
if (!history_file) return -1; if (!history_file) return -1;
ssi = secure_open(history_file, S_IXUSR | S_IRWXG | S_IRWXO); ssi = secure_open(history_file);
mem_free(history_file); mem_free(history_file);
if (!ssi) return -1; if (!ssi) return -1;

View File

@ -94,7 +94,7 @@ bookmarks_write(struct list_head *bookmarks_list)
file_name = straconcat(elinks_home, file_name, NULL); file_name = straconcat(elinks_home, file_name, NULL);
if (!file_name) return; if (!file_name) return;
ssi = secure_open(file_name, S_IXUSR | S_IRWXG | S_IRWXO); ssi = secure_open(file_name);
mem_free(file_name); mem_free(file_name);
if (!ssi) return; if (!ssi) return;

View File

@ -805,7 +805,7 @@ write_config_file(unsigned char *prefix, unsigned char *name,
config_file = straconcat(prefix, slash, name, NULL); config_file = straconcat(prefix, slash, name, NULL);
if (!config_file) goto free_cfg_str; if (!config_file) goto free_cfg_str;
ssi = secure_open(config_file, S_IXUSR | S_IRWXG | S_IRWXO); ssi = secure_open(config_file);
if (ssi) { if (ssi) {
secure_fputs(ssi, cfg_str); secure_fputs(ssi, cfg_str);
ret = secure_close(ssi); ret = secure_close(ssi);

View File

@ -775,7 +775,7 @@ save_cookies(void) {
cookfile = straconcat(elinks_home, COOKIES_FILENAME, NULL); cookfile = straconcat(elinks_home, COOKIES_FILENAME, NULL);
if (!cookfile) return; if (!cookfile) return;
ssi = secure_open(cookfile, S_IXUSR | S_IRWXG | S_IRWXO); ssi = secure_open(cookfile);
mem_free(cookfile); mem_free(cookfile);
if (!ssi) return; if (!ssi) return;

View File

@ -225,7 +225,7 @@ save_formhist_to_file(void)
file = straconcat(elinks_home, FORMS_HISTORY_FILENAME, NULL); file = straconcat(elinks_home, FORMS_HISTORY_FILENAME, NULL);
if (!file) return 0; if (!file) return 0;
ssi = secure_open(file, S_IXUSR | S_IRWXG | S_IRWXO); ssi = secure_open(file);
mem_free(file); mem_free(file);
if (!ssi) return 0; if (!ssi) return 0;

View File

@ -369,7 +369,7 @@ write_global_history(void)
file_name = straconcat(elinks_home, GLOBAL_HISTORY_FILENAME, NULL); file_name = straconcat(elinks_home, GLOBAL_HISTORY_FILENAME, NULL);
if (!file_name) return; if (!file_name) return;
ssi = secure_open(file_name, S_IXUSR | S_IRWXG | S_IRWXO); ssi = secure_open(file_name);
mem_free(file_name); mem_free(file_name);
if (!ssi) return; if (!ssi) return;

View File

@ -68,8 +68,8 @@ enum secsave_errno secsave_errno = SS_ERR_NONE;
/* Open a file for writing in a secure way. It returns a pointer to a structure /* Open a file for writing in a secure way. It returns a pointer to a structure
* secure_save_info on success, or NULL on failure. */ * secure_save_info on success, or NULL on failure. */
struct secure_save_info * static struct secure_save_info *
secure_open(unsigned char *file_name, mode_t mask) secure_open_umask(unsigned char *file_name, mode_t mask)
{ {
mode_t saved_mask; mode_t saved_mask;
struct stat st; struct stat st;
@ -203,6 +203,11 @@ end:
return NULL; return NULL;
} }
struct secure_save_info *
secure_open(unsigned char *file_name)
{
return secure_open_umask(file_name, S_IXUSR | S_IRWXG | S_IRWXO);
}
/* Close a file opened with secure_open, and return 0 on success, errno /* Close a file opened with secure_open, and return 0 on success, errno
* or -1 on failure. */ * or -1 on failure. */

View File

@ -31,7 +31,8 @@ struct secure_save_info {
int secure_save; /* use secure save for this file */ int secure_save; /* use secure save for this file */
}; };
struct secure_save_info *secure_open(unsigned char *, mode_t); struct secure_save_info *secure_open(unsigned char *);
int secure_close(struct secure_save_info *); int secure_close(struct secure_save_info *);
int secure_fputs(struct secure_save_info *, const char *); int secure_fputs(struct secure_save_info *, const char *);