From 668502204b7297903c29b3bd023eae0d81a80483 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 21 Aug 2016 10:12:49 +0200 Subject: [PATCH 5/5] Introduce attach_umask to specify the umask that is used to save attachements This patch introduces a new parameter attach_umask which allows to specify the umask that is being used to save attachments. It defaults to 0077. It changes the file creation mode of safe_open from 0600 to 0644 which is not a problem because mutt sets the umask to 0700 when starting in main() in main.c The umask is honored by open. Example: set attach_umask=0022 --- attach.c | 14 ++++++++++++-- globals.h | 1 + init.h | 5 +++++ lib.c | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/attach.c b/attach.c index 84cdf6d..7a098b8 100644 --- a/attach.c +++ b/attach.c @@ -691,12 +691,22 @@ bail: static FILE * mutt_save_attachment_open (char *path, int flags) { + mode_t omask, nmask; + FILE *ret; + if (flags == MUTT_SAVE_APPEND) return fopen (path, "a"); if (flags == MUTT_SAVE_OVERWRITE) return fopen (path, "w"); /* __FOPEN_CHECKED__ */ - - return safe_fopen (path, "w"); + + if (sscanf(AttachUmask, "%o", &nmask) == 1) { + omask = umask(nmask); + ret = safe_fopen (path, "w"); + umask(omask); + } else + ret = safe_fopen (path, "w"); + + return ret; } /* returns 0 on success, -1 on error */ diff --git a/globals.h b/globals.h index 95a6869..5e35e07 100644 --- a/globals.h +++ b/globals.h @@ -35,6 +35,7 @@ WHERE char *AliasFile; WHERE char *AliasFmt; WHERE char *AssumedCharset; WHERE char *AttachSep; +WHERE char *AttachUmask; WHERE char *Attribution; WHERE char *AttachCharset; WHERE char *AttachFormat; diff --git a/init.h b/init.h index babc574..8ebc621 100644 --- a/init.h +++ b/init.h @@ -259,6 +259,11 @@ struct option_t MuttVars[] = { ** $$attach_sep separator is added after each attachment. When \fIset\fP, ** Mutt will operate on the attachments one by one. */ + { "attach_umask", DT_STR, R_NONE, UL &AttachUmask, UL "0077" }, + /* + ** .pp + ** The umask which is used while saving attachments. Defaults to 0077. + */ { "attribution", DT_STR, R_NONE, UL &Attribution, UL "On %d, %n wrote:" }, /* ** .pp diff --git a/lib.c b/lib.c index 224232b..aa401df 100644 --- a/lib.c +++ b/lib.c @@ -642,7 +642,7 @@ int safe_open (const char *path, int flags) safe_dir, sizeof (safe_dir)) == -1) return -1; - if ((fd = open (safe_file, flags, 0600)) < 0) + if ((fd = open (safe_file, flags, 0644)) < 0) { rmdir (safe_dir); return fd; @@ -654,7 +654,7 @@ int safe_open (const char *path, int flags) return -1; } - if ((fd = open (path, flags & ~O_EXCL, 0600)) < 0) + if ((fd = open (path, flags & ~O_EXCL, 0644)) < 0) return fd; /* make sure the file is not symlink */ -- 2.1.4