Your message dated Mon, 25 Jul 2022 14:51:03 +0200
with message-id <yt6rt+k2oaivl...@georges.khaznadar.fr>
and subject line MAILFROM is supported by the last version of cron
has caused the Debian Bug report #929959,
regarding cron: please support /etc/mailname
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact ow...@bugs.debian.org
immediately.)


-- 
929959: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=929959
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Package: cron
Version: 3.0pl1-133
Severity: normal
Tags: patch

Dear Maintainer,

Outgoing mail has the following From: header:
    From: root (Cron Daemon)

This gets rejected by smarthosts as suspicious spam. Rather than manually
rewriting the From: header with the MTA, it would be nice if cron would
use /etc/mailname.

Here is a patch that has been working great for me.

Thanks,

Alex

-- System Information:
Debian Release: 10.0
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.19.0-5-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_FR.utf8, LC_CTYPE=fr_FR.utf8 (charmap=UTF-8), 
LANGUAGE=fr_FR.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages cron depends on:
ii  adduser              3.118
ii  debianutils          4.8.6.1
ii  init-system-helpers  1.56+nmu1
ii  libc6                2.28-10
ii  libpam-runtime       1.3.1-5
ii  libpam0g             1.3.1-5
ii  libselinux1          2.8-1+b1
ii  lsb-base             10.2019051400
ii  sensible-utils       0.0.12

Versions of packages cron recommends:
ii  ssmtp [mail-transport-agent]  2.64-8+b2

Versions of packages cron suggests:
pn  anacron        <none>
pn  checksecurity  <none>
ii  logrotate      3.14.0-4

Versions of packages cron is related to:
pn  libnss-ldap   <none>
pn  libnss-ldapd  <none>
pn  libpam-ldap   <none>
pn  libpam-mount  <none>
pn  nis           <none>
pn  nscd          <none>

-- no debconf information
diff --git a/debian/changelog b/debian/changelog
index a32710e..c506471 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+cron (3.0pl1-133+mailfrom+2) unstable; urgency=medium
+
+  * Add domain name to mail From: header.
+
+ -- Alexandre Rossi <alexandre.ro...@gmail.com>  Sun, 12 May 2019 12:48:18 
+0200
+
 cron (3.0pl1-133) unstable; urgency=medium
 
   * SECURITY: Fix bypass of /etc/cron.{allow,deny} on failure to open
diff --git a/do_command.c b/do_command.c
index 930e910..c958636 100644
--- a/do_command.c
+++ b/do_command.c
@@ -533,17 +533,20 @@ child_process(e, u)
        char            **jobenv = build_env(e->envp);
        auto char       mailcmd[MAX_COMMAND];
        auto char       hostname[MAXHOSTNAMELEN];
-       char            *content_type = env_get("CONTENT_TYPE",jobenv),
+       auto char       domainname[MAXHOSTNAMELEN];
                        *content_transfer_encoding = 
env_get("CONTENT_TRANSFER_ENCODING",jobenv);
 
        (void) gethostname(hostname, MAXHOSTNAMELEN);
+       if (0 != first_line(ETCMAILNAME, domainname, MAXHOSTNAMELEN)) {
+               strncpy(domainname, hostname, MAXHOSTNAMELEN);
+       }
        (void) snprintf(mailcmd, sizeof(mailcmd),
                        MAILARGS, MAILCMD, mailto);
        if (!(mail = cron_popen(mailcmd, "w", e))) {
                perror(MAILCMD);
                (void) _exit(ERROR_EXIT);
        }
-       fprintf(mail, "From: root (Cron Daemon)\n");
+       fprintf(mail, "From: root (Cron Daemon) <root@%s>\n", domainname);
        fprintf(mail, "To: %s\n", mailto);
        fprintf(mail, "Subject: Cron <%s@%s> %s%s\n",
                        usernm,
diff --git a/misc.c b/misc.c
index 77e7091..e98fef5 100644
--- a/misc.c
+++ b/misc.c
@@ -647,6 +647,58 @@ first_word(s, t)
 }
 
 
+char*
+strstrip(char *str)
+{
+    size_t size = strlen(str);
+    char *start = NULL;
+    char *end = NULL;
+
+    if (size) {
+        start = str;
+        end = start + size - 1;
+
+        while (end > start && isspace(*end))
+            end--;
+        *(end + 1) = '\0';
+
+        while (*start && isspace(*start))
+            start++;
+    }
+
+    return start;
+}
+
+
+int
+first_line(char *fpath, char *s, int maxlength)
+{
+    FILE *fp = NULL;
+    char *line = NULL;
+    char *stripped_line = NULL;
+    int ret = 1;
+
+    fp = fopen(fpath, "r");
+    if (!fp) {
+        return 1;
+    }
+
+    line = malloc(sizeof(char) * maxlength);
+    *line = '\0';
+    if (fgets(line, maxlength, fp)) {
+        stripped_line = strstrip(line);
+        if (stripped_line) {
+            strncpy(s, stripped_line, strlen(stripped_line) + 1);
+            ret = 0;
+        }
+    }
+
+    free(line);
+    fclose(fp);
+    return ret;
+}
+
+
 /* warning:
  *     heavily ascii-dependent.
  */
diff --git a/pathnames.h b/pathnames.h
index 669d33f..a9c7880 100644
--- a/pathnames.h
+++ b/pathnames.h
@@ -64,7 +64,7 @@
 #define SYSCRONTAB     "/etc/crontab"
                        /* where package specific crontabs live */
 #define SYSCRONDIR      "/etc/cron.d"
-
+#define ETCMAILNAME "/etc/mailname"
                        /* what editor to use if no EDITOR or VISUAL
                         * environment variable specified.
                         */

--- End Message ---
--- Begin Message ---
Since a few weeks, I patched cron and set up a test, to ensure that the
variable MAILFROM is honored.

So bug #929959 can be closed now.

Best regards,                   Georges.

-- 
Georges KHAZNADAR et Jocelyne FOURNIER
22 rue des mouettes, 59240 Dunkerque France.
Téléphone +33 (0)3 28 29 17 70

Attachment: signature.asc
Description: PGP signature


--- End Message ---

Reply via email to