From 9b88da873aab5dcca755a4fd1d9e61c5584f885f Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Tue, 10 Jan 2006 23:35:22 +0100 Subject: [PATCH] Use mode_t and mode macros everywhere. --- src/bfu/inphist.c | 2 +- src/bookmarks/backend/common.c | 2 +- src/config/conf.c | 2 +- src/cookies/cookies.c | 2 +- src/formhist/formhist.c | 2 +- src/globhist/globhist.c | 2 +- src/main/interlink.c | 2 +- src/protocol/ftp/parse.c | 6 +++--- src/protocol/ftp/parse.h | 6 +++--- src/util/file.c | 8 ++++---- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/bfu/inphist.c b/src/bfu/inphist.c index 0cc48318b..94ae93166 100644 --- a/src/bfu/inphist.c +++ b/src/bfu/inphist.c @@ -321,7 +321,7 @@ save_input_history(struct input_history *history, unsigned char *filename) history_file = straconcat(elinks_home, filename, NULL); if (!history_file) return -1; - ssi = secure_open(history_file, 0177); + ssi = secure_open(history_file, S_IXUSR | S_IRWXG | S_IRWXO); mem_free(history_file); if (!ssi) return -1; diff --git a/src/bookmarks/backend/common.c b/src/bookmarks/backend/common.c index e9dae3951..8b26e79ff 100644 --- a/src/bookmarks/backend/common.c +++ b/src/bookmarks/backend/common.c @@ -94,7 +94,7 @@ bookmarks_write(struct list_head *bookmarks_list) file_name = straconcat(elinks_home, file_name, NULL); if (!file_name) return; - ssi = secure_open(file_name, 0177); + ssi = secure_open(file_name, S_IXUSR | S_IRWXG | S_IRWXO); mem_free(file_name); if (!ssi) return; diff --git a/src/config/conf.c b/src/config/conf.c index 64a57493f..8e23fa549 100644 --- a/src/config/conf.c +++ b/src/config/conf.c @@ -805,7 +805,7 @@ write_config_file(unsigned char *prefix, unsigned char *name, config_file = straconcat(prefix, slash, name, NULL); if (!config_file) goto free_cfg_str; - ssi = secure_open(config_file, 0177); + ssi = secure_open(config_file, S_IXUSR | S_IRWXG | S_IRWXO); if (ssi) { secure_fputs(ssi, cfg_str); ret = secure_close(ssi); diff --git a/src/cookies/cookies.c b/src/cookies/cookies.c index b96e82c97..ebb93d93c 100644 --- a/src/cookies/cookies.c +++ b/src/cookies/cookies.c @@ -775,7 +775,7 @@ save_cookies(void) { cookfile = straconcat(elinks_home, COOKIES_FILENAME, NULL); if (!cookfile) return; - ssi = secure_open(cookfile, 0177); /* rw for user only */ + ssi = secure_open(cookfile, S_IXUSR | S_IRWXG | S_IRWXO); mem_free(cookfile); if (!ssi) return; diff --git a/src/formhist/formhist.c b/src/formhist/formhist.c index 4213183d2..0e7d6e2f2 100644 --- a/src/formhist/formhist.c +++ b/src/formhist/formhist.c @@ -225,7 +225,7 @@ save_formhist_to_file(void) file = straconcat(elinks_home, FORMS_HISTORY_FILENAME, NULL); if (!file) return 0; - ssi = secure_open(file, 0177); + ssi = secure_open(file, S_IXUSR | S_IRWXG | S_IRWXO); mem_free(file); if (!ssi) return 0; diff --git a/src/globhist/globhist.c b/src/globhist/globhist.c index e91c964ad..3e9898e61 100644 --- a/src/globhist/globhist.c +++ b/src/globhist/globhist.c @@ -369,7 +369,7 @@ write_global_history(void) file_name = straconcat(elinks_home, GLOBAL_HISTORY_FILENAME, NULL); if (!file_name) return; - ssi = secure_open(file_name, 0177); /* rw for user only */ + ssi = secure_open(file_name, S_IXUSR | S_IRWXG | S_IRWXO); mem_free(file_name); if (!ssi) return; diff --git a/src/main/interlink.c b/src/main/interlink.c index 604ea4191..8c0b91c1d 100644 --- a/src/main/interlink.c +++ b/src/main/interlink.c @@ -371,7 +371,7 @@ elinks_usleep(unsigned long useconds) static int bind_to_af_unix(void) { - mode_t saved_mask = umask(0177); + mode_t saved_mask = umask(S_IXUSR | S_IRWXG | S_IRWXO); int attempts = 0; int pf = get_address(&s_info_listen, ADDR_IP_SERVER); diff --git a/src/protocol/ftp/parse.c b/src/protocol/ftp/parse.c index 770dc4cf8..b5caeba7c 100644 --- a/src/protocol/ftp/parse.c +++ b/src/protocol/ftp/parse.c @@ -138,7 +138,7 @@ enum ftp_unix { static int parse_ftp_unix_permissions(const unsigned char *src, int len) { - int perms = 0; + mode_t perms = 0; if (len != 9 && !(len == 10 && src[9] == '+')) /* ACL tag */ @@ -583,12 +583,12 @@ parse_ftp_winnt_response(struct ftp_file_info *info, unsigned char *src, int len if (*src == '<') { info->type = FTP_FILE_DIRECTORY; - info->permissions = 0755; + info->permissions = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; } else if (isdigit(*src)) { info->type = FTP_FILE_PLAINFILE; info->size = parse_ftp_number(&src, end, 0, LONG_MAX); - info->permissions = 0644; + info->permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; } else { info->type = FTP_FILE_UNKNOWN; diff --git a/src/protocol/ftp/parse.h b/src/protocol/ftp/parse.h index 9e44d93ab..e7773987f 100644 --- a/src/protocol/ftp/parse.h +++ b/src/protocol/ftp/parse.h @@ -22,7 +22,7 @@ struct ftp_file_info { long size; /* File size. -1 if unknown. */ time_t mtime; /* Modification time */ unsigned int local_time_zone:1; /* What format the mtime is in */ - int permissions; /* File permissions */ + mode_t permissions; /* File permissions */ }; #define FTP_SIZE_UNKNOWN -1 @@ -30,10 +30,10 @@ struct ftp_file_info { /* File info initializers: */ #define INIT_FTP_FILE_INFO \ - { FTP_FILE_UNKNOWN, INIT_STRING("", 0), INIT_STRING("", 0), FTP_SIZE_UNKNOWN, 0, 0, 0644 } + { FTP_FILE_UNKNOWN, INIT_STRING("", 0), INIT_STRING("", 0), FTP_SIZE_UNKNOWN, 0, 0, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH } #define INIT_FTP_FILE_INFO_ROOT \ - { FTP_FILE_DIRECTORY, INIT_STRING("..", 2), INIT_STRING("", 0), FTP_SIZE_UNKNOWN, 0, 0, 0755 } + { FTP_FILE_DIRECTORY, INIT_STRING("..", 2), INIT_STRING("", 0), FTP_SIZE_UNKNOWN, 0, 0, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH } struct ftp_file_info * parse_ftp_file_info(struct ftp_file_info *info, unsigned char *src, int len); diff --git a/src/util/file.c b/src/util/file.c index 09cfd1e97..e0b186500 100644 --- a/src/util/file.c +++ b/src/util/file.c @@ -272,7 +272,7 @@ file_read_line(unsigned char *line, size_t *size, FILE *file, int *lineno) int safe_mkstemp(unsigned char *template) { - mode_t saved_mask = umask(0177); + mode_t saved_mask = umask(S_IXUSR | S_IRWXG | S_IRWXO); int fd = mkstemp(template); umask(saved_mask); @@ -321,12 +321,12 @@ stat_mode(struct string *string, struct stat *stp) unsigned char rwx[10] = "---------"; if (stp) { - int mode = stp->st_mode; - int shift; + mode_t mode = stp->st_mode; + unsigned int shift; /* Set permissions attributes for user, group and other */ for (shift = 0; shift <= 6; shift += 3) { - int m = mode << shift; + mode_t m = mode << shift; if (m & S_IRUSR) rwx[shift + 0] = 'r'; if (m & S_IWUSR) rwx[shift + 1] = 'w';