Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Nov 2009 10:18:45 GMT
From:      Dennis Yusupoff <dyr@smartspb.net>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   www/140304: Patch for adding MAILFROM ability to cron
Message-ID:  <200911051018.nA5AIjIo045257@www.freebsd.org>
Resent-Message-ID: <200911051020.nA5AK580041076@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         140304
>Category:       www
>Synopsis:       Patch for adding MAILFROM ability to cron
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-www
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 05 10:20:05 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Dennis Yusupoff
>Release:        7.2-release
>Organization:
Smart-Telecom ISP
>Environment:
FreeBSD Gingema.smartspb.net 7.2-PRERELEASE FreeBSD 7.2-PRERELEASE #1: Mon Oct  5 14:03:54 MSD 2009     root@Gingema.smartspb.net:/usr/obj/usr/src/sys/ROUTER_HOME_NETS  i386

>Description:
After some looking for ability to change sender mail address of cron daemon I decided to add this feature right in the cron daemon as it already done with MAILTO since I found nowhere in mailing list reasons to not do it. :)
I think that it could be useful for many people. 
I'm a newbie in C so any corrections are welcome.
>How-To-Repeat:
Make a patch also :)
>Fix:
Use environment "MAILFOM" in your file crontab for change sender e-mail or will be used default (username@hostname).

Patch attached with submission follows:

--- do_command.c.orig	2008-08-01 12:13:01.000000000 +0400
+++ do_command.c	2009-11-05 12:57:56.000000000 +0300
@@ -83,7 +83,7 @@
 {
 	int		stdin_pipe[2], stdout_pipe[2];
 	register char	*input_data;
-	char		*usernm, *mailto;
+	char		*usernm, *mailto, *mailfrom;
 	int		children = 0;
 # if defined(LOGIN_CAP)
 	struct passwd	*pwd;
@@ -101,6 +101,7 @@
 	 */
 	usernm = env_get("LOGNAME", e->envp);
 	mailto = env_get("MAILTO", e->envp);
+	mailfrom = env_get("MAILFROM", e->envp);
 
 #ifdef PAM
 	/* use PAM to see if the user's account is available,
@@ -468,6 +469,17 @@
 				else
 					mailto = usernm;
 			}
+			/* get name of sender.  this is MAILFROM if set to a
+			 * valid local username; USER otherwise.
+			 */
+			if (mailfrom == NULL) 
+				/* MAILFROM not present, set to USER
+				 */
+				mailfrom = usernm;
+
+			if (mailfrom && *mailfrom == '\0')
+				mailfrom = NULL;
+
 			if (mailto && *mailto == '\0')
 				mailto = NULL;
 
@@ -488,7 +500,7 @@
 					warn("%s", MAILCMD);
 					(void) _exit(ERROR_EXIT);
 				}
-				fprintf(mail, "From: %s (Cron Daemon)\n", usernm);
+				fprintf(mail, "From: %s (Cron Daemon)\n", mailfrom);
 				fprintf(mail, "To: %s\n", mailto);
 				fprintf(mail, "Subject: Cron <%s@%s> %s\n",
 					usernm, first_word(hostname, "."),


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200911051018.nA5AIjIo045257>