mail from: field question
Ian Smith
smithi at nimnet.asn.au
Thu Jan 10 20:15:41 PST 2008
On Thu, 10 Jan 2008 13:22:47 +0000 Jim Bow <jimbow at darq.net> wrote:
> Mike Bristow wrote:
> > On Thu, Jan 10, 2008 at 10:46:30AM +0000, Jim Bow wrote:
> >> If I run the script (or just send a mail) on the command line using sudo,
> >> then it's sent as me and not root. Same happens if I su to root first.
> >
> > use 'su -'. It means you get a login shell (which sets up the enviroment
> > in the same way that login does).
>
> That makes perfect sense, but doesn't seem to work. Here's the output of
> my terminal session:
>
> host% whoami
> jim
> host% sudo su - (tried doing "su -" also, with same results)
> Password:
> host# whoami
> root
> host# env
> USER=root
> HOME=/root
> SHELL=/bin/csh
> PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
> MAIL=/var/mail/root
> BLOCKSIZE=K
> FTP_PASSIVE_MODE=YES
> TERM=screen
> HOSTTYPE=FreeBSD
> VENDOR=intel
> OSTYPE=FreeBSD
> MACHTYPE=i386
> SHLVL=1
> PWD=/root
> LOGNAME=root
> GROUP=wheel
> HOST=host.example.com
> EDITOR=vi
> PAGER=more
> host# cat /etc/motd | mail -s "hello" test at example.com
>
> This results in the mail from: header of jim at host.example.com. I've
> tried this on two different hosts with the same result.
I can confirm this behaviour, also using csh and sendmail, and 'su -'
from originally having logged in as myself, since freebsd 2.2 ..
I use this csh alias whenever not entirely sure who or where I am ..
paqi# alias um
tty;id -p;who am i
paqi# um
/dev/ttyp3
login smithi
uid root
groups wheel operator network
root ttyp3 Jan 11 14:09
Note 'id -p' showing 'login smithi'; see id(1) .. I gather that sendmail
must also use getlogin(2) - which value does not appear in `env` - when
sending mail from an su'd session, as opposed to an original root login,
and don't know whether or how this may be configurable in sendmail.
paqi# mail smithi
Subject: boo
hoo
.
EOT
Return-Path: <smithi at paqi.nimnet.asn.au>
Received: from paqi.nimnet.asn.au (localhost.nimnet.asn.au [127.0.0.1])
by paqi.nimnet.asn.au (8.13.8/8.13.8) with ESMTP id m0B2gGpU059565
for <smithi at paqi.nimnet.asn.au>; Fri, 11 Jan 2008 13:42:16 +1100 (EST)
(envelope-from smithi at paqi.nimnet.asn.au)
Received: (from root at localhost)
by paqi.nimnet.asn.au (8.13.8/8.13.8/Submit) id m0B2gFPr059564
for smithi; Fri, 11 Jan 2008 13:42:15 +1100 (EST)
(envelope-from smithi)
Date: Fri, 11 Jan 2008 13:42:15 +1100 (EST)
From: Ian Smith <smithi at paqi.nimnet.asn.au>
Message-Id: <200801110242.m0B2gFPr059564 at paqi.nimnet.asn.au>
To: smithi at paqi.nimnet.asn.au
Subject: boo
hoo
Note 'received from root at localhost' but 'envelope-from smithi'. Also
note I'm not using domain masquerading here, as I don't actually mail
out from this box currently.
> The actual thing Im trying to do is to email something from a script
> that runs as root from devd, but I run into the same problem of the
> email arriving from somebody other than root, hence trying this manually
> on the command line.
Hmm .. I know mail sent from cron scripts properly comes 'from root',
and don't know why scripts run as root from devd would be any different.
Is 'somebody other than root' consistent, and someone who's logged in,
perhaps before su'ing and then starting the session that invokes devd?
> There is definitely something that I am overlooking, but what is it? I'm
> extremely curious to work-out why I'm seeing such behavior as its
> defeating all my expectations so far.
I noticed later that Paul gets a different result .. maybe postfix as
mentioned, if Paul was starting from an su'd session, not a root login?
cheers, Ian
More information about the freebsd-questions
mailing list