[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH v2] sendmail: automatically determine sender if not specified
From:       Kaarle Ritvanen <kaarle.ritvanen () datakunkku ! fi>
Date:       2014-01-28 17:02:44
Message-ID: 1390928564-24387-1-git-send-email-kaarle.ritvanen () datakunkku ! fi
[Download RAW message or body]

Make the -f option optional. If not given, construct the sender
address from the username and fully qualified hostname.

This is required to interoperate with the cron applet.

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
---
Changes since v1:
 Added missing sign-off

 mailutils/sendmail.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c
index b5aa1d1..b99c42f 100644
--- a/mailutils/sendmail.c
+++ b/mailutils/sendmail.c
@@ -199,8 +199,8 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
 	G.fp0 = xfdopen_for_read(3);
 
 	// parse options
-	// -v is a counter, -f is required. -H and -S are mutually exclusive, -a is a list
-	opt_complementary = "vv:f:w+:H--S:S--H:a::";
+	// -v is a counter, -H and -S are mutually exclusive, -a is a list
+	opt_complementary = "vv:w+:H--S:S--H:a::";
 	// N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect
 	// -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility,
 	// it is still under development.
@@ -279,7 +279,6 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
 	// we should start with modern EHLO
 	if (250 != smtp_checkp("EHLO %s", host, -1))
 		smtp_checkp("HELO %s", host, 250);
-	free(host);
 
 	// perform authentication
 	if (opts & OPT_a) {
@@ -305,12 +304,11 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
 	//	file descriptor (e.g. 4), or again from a secured file.
 
 	// got no sender address? -> use system username as a resort
-	// N.B. we marked -f as required option!
-	//if (!G.user) {
-	//	// N.B. IMHO getenv("USER") can be way easily spoofed!
-	//	G.user = xuid2uname(getuid());
-	//	opt_from = xasprintf("%s@%s", G.user, domain);
-	//}
+	if (!G.user) G.user = xuid2uname(getuid());
+	if (!opt_from)
+		opt_from = xasprintf("%s@%s", G.user, xgethostbyname(host)->h_name);
+	free(host);
+
 	smtp_checkp("MAIL FROM:<%s>", opt_from, 250);
 
 	// process message
-- 
1.8.3.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic