source: trunk/debathena/config/msmtp-config/debian/debathena-msmtp @ 24491

Revision 24491, 2.4 KB checked in by broder, 14 years ago (diff)
In msmtp-config: * Rearrange the start of debathena-msmtp slightly to make it clearer that setting $kuser is dependent on having tickets.
  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3use Mail::ExpandAliases;
4use File::Basename;
5use POSIX qw(getgroups);
6
7use strict;
8use warnings;
9
10sub debug {
11  if (defined($ENV{'DEBATHENA_SENDMAIL_DEBUG'}) &&
12      ($ENV{'DEBATHENA_SENDMAIL_DEBUG'} eq 'yes')) {
13    print STDERR "DEBUG: " . join(' ', @_) . "\n";
14  }
15}
16
17my $kuser;
18my $want_auth = $ENV{'DEBATHENA_SENDMAIL_AUTH'} || '';
19
20system(qw(klist -s));
21if (($? == 0) &&
22    (`klist 2>/dev/null` =~ /Default principal: (.*?)\@ATHENA.MIT.EDU/)) {
23    $kuser = $1;
24}
25
26my $parser = Mail::ExpandAliases->new;
27
28if (basename($0) eq 'newaliases') {
29    my $root = join(', ', @{$parser->expand('root')});
30    if ($root !~ /@/) {
31        print STDERR <<EOF
32NOTE: root expands to: $root
33This does not appear to contain a remote address.  Since debathena-msmtp
34does not support local delivery, you may wish to send root's mail
35somewhere useful (e.g. your MIT account).
36EOF
37    }
38    exit 0;
39}
40
41sub from_address {
42  # If we have tickets, use them
43  if ($kuser) {
44    return "--from=" . join('@', $kuser, 'mit.edu');
45  }
46  # Note that ATHENA_USER is explicitly not checked here. We've
47  # already checked to see if you have Kerberos tickets, and
48  # semantically, if you don't have Kerberos tickets, you're not
49  # sending as an Athena user.
50  my $uname = $ENV{'USER'} || $ENV{'LOGNAME'} || getpwuid($<);
51  # Otherwise, assume user@fqdn ...
52  chomp(my $maildomain = `hostname --fqdn`);
53  # ... except that nss-nonlocal-users are @mit.edu
54  if (getgrnam('nss-nonlocal-users')) {
55    my $nssnonlocalgid = (getgrnam('nss-nonlocal-users'))[2];
56    if (grep(/^$nssnonlocalgid$/, getgroups())) {
57      debug("Assuming \@mit.edu for nss-nonlocal-user $uname");
58      $maildomain = 'mit.edu';
59    }
60  }
61  return "--from=" . join('@', $uname, $maildomain);
62}
63
64my @aliases = ();
65foreach my $arg (@ARGV) {
66    push @aliases, $parser->expand($arg);
67}
68
69if ($kuser && (($want_auth eq 'yes') || ($want_auth eq '')) ) {
70    #send auth
71    debug(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
72    exec(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
73}
74elsif ($want_auth eq 'yes') {
75    $! = 1;
76    die "Could not find valid ATHENA.MIT.EDU Kerberos tickets.\n";
77}
78else {
79    #send unauth
80    debug(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
81    exec(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
82}
Note: See TracBrowser for help on using the repository browser.