On Tue, Jan 28, 2014 at 6:02 PM, Kaarle Ritvanen
<[email protected]> wrote:
> 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 <[email protected]>
> ---
> 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);
> +
There are a number of problems here.
(0) You did not initialize opt_from to NULL. If -f isn't specified,
opt_from contains garbage, not NULL.
(1) You do not need to set G.user if opt_from isn't NULL.
That part of code should be inside "if (!opt_from) {...}".
(2) Please test what sendmail does when -f is not specified,
and document it in a comment. E.g. "sendmail v.1.2.3 does the same",
or "sendmail v.1.2.3 does Y, we do Z because ....".
In particular: is there an environment variable to supply -f SENDER
which is recognized by sendmail? *You as a user* need that for your
use case - "cron+sendmail", no?
(3) Edit -f option in --help text.
I just committed the following change:
http://git.busybox.net/busybox/commit/?id=07f417b6ab92e0429f302ff6783bb9681b60120e
but I'm unsure it is good enough for your use case.
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox