MAIL environment variable set wrong

David Banks david.banks at proporta.com
Thu Jul 30 08:39:14 UTC 2009


Hi,

[This was previously posted on the forums, I didn't get a response 
there; apologies if you've seen it before.]

I am using Ubuntu Hardy x86_64. The problem I have is that whenever I 
log in, the MAIL environment variable is set to '/var/mail/david' (where 
my username is 'david'). This isn't right, since I don't keep my mail in 
Mbox under /var/mail. In fact, on this machine I don't get mail for my 
local username, and I'd like MAIL to be unset when I log in.

   david at scatha $ echo $MAIL
   /var/mail/david

I've tried to find out where this gets set, and I've found that it's set 
by PAM.  The PAM module responsible for setting the variable seems to be 
'pam_mail'. There are a few lines in various files under /etc/pam.d that 
seem to enable this module:

   david at scatha $ grep -r pam_mail /etc/pam.d
   /etc/pam.d/login:session    optional   pam_mail.so standard
   /etc/pam.d/sshd:session    optional     pam_mail.so standard noenv # [1]
   /etc/pam.d/su:session    optional   pam_mail.so nopen

However, commenting out all these lines doesn't seem to solve the 
problem. (Since I log in by ssh, I restarted sshd to apply the changes.) 
"man pam_mail" says that appending "noenv" to the module lines should 
work - I tried adding it to all of these files, but it didn't work. MAIL 
is still set in all circumstances - this includes non-SSH physical logins.

There's also some related things in /etc/login.defs, with the following 
note:

   # NOTE: This is no more used for setting up users MAIL environment 
variable
   #       which is, starting from shadow 4.0.12-1 in Debian, entirely the
   #       job of the pam_mail PAM modules
   #       See default PAM configuration files provided for
   #       login, su, etc.

Why do I care? Because zsh automatically checks for mail when MAIL is 
defined:

   MAIL: If this parameter is set and mailpath is not set, the shell
   looks for mail in the specified file.

There's no way to disable this check except by unsetting MAIL, so (since 
/var/mail is forbidden to my user), every five minutes I get a message 
"/var/mail/david: permission denied". There are quite a few workarounds 
for this: unset MAIL in my zshrc, profile, /etc/profile; change the 
permissions on /var/mail. But none of these do exactly what I want, 
which is to avoid setting MAIL in the first place. Ideally the 'noenv' 
option should do this perfectly, but it doesn't seem to work.

Any idea where I'm going wrong?

Cheers
David




More information about the ubuntu-users mailing list