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 0efeb79..29d60b6 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 == M_SAVE_APPEND)
return fopen (path, "a");
if (flags == M_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 6fefe5b..d273517 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 b5b2886..4b45269 100644
--- a/init.h
+++ b/init.h
@@ -256,6 +256,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 c7d95af..439adf6 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 */
--
1.7.10.4