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

Revision 25065, 2.5 KB checked in by jdreed, 13 years ago (diff)
In msmtp-config: * Strip off the instance of any principal in the tickets (Trac #806)
  • 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    # Remove any instances
25    $kuser =~ s|/.*||g;
26}
27
28my $parser = Mail::ExpandAliases->new;
29
30if (basename($0) eq 'newaliases') {
31    my $root = join(', ', @{$parser->expand('root')});
32    if ($root !~ /@/) {
33        print STDERR <<EOF
34NOTE: root expands to: $root
35This does not appear to contain a remote address.  Since debathena-msmtp
36does not support local delivery, you may wish to send root's mail
37somewhere useful (e.g. your MIT account).
38EOF
39    }
40    exit 0;
41}
42
43sub from_address {
44  # If we have tickets, use them
45  if ($kuser) {
46    return "--from=" . join('@', $kuser, 'mit.edu');
47  }
48  # Note that ATHENA_USER is explicitly not checked here. We've
49  # already checked to see if you have Kerberos tickets, and
50  # semantically, if you don't have Kerberos tickets, you're not
51  # sending as an Athena user.
52  my $uname = $ENV{'USER'} || $ENV{'LOGNAME'} || getpwuid($<);
53  # Otherwise, assume user@fqdn ...
54  chomp(my $maildomain = `hostname --fqdn`);
55  # ... except that nss-nonlocal-users are @mit.edu
56  if (getgrnam('nss-nonlocal-users')) {
57    my $nssnonlocalgid = (getgrnam('nss-nonlocal-users'))[2];
58    if (grep(/^$nssnonlocalgid$/, getgroups())) {
59      debug("Assuming \@mit.edu for nss-nonlocal-user $uname");
60      $maildomain = 'mit.edu';
61    }
62  }
63  return "--from=" . join('@', $uname, $maildomain);
64}
65
66my @aliases = ();
67foreach my $arg (@ARGV) {
68    push @aliases, $parser->expand($arg);
69}
70
71if ($kuser && (($want_auth eq 'yes') || ($want_auth eq '')) ) {
72    #send auth
73    debug(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
74    exec(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
75}
76elsif ($want_auth eq 'yes') {
77    $! = 1;
78    die "Could not find valid ATHENA.MIT.EDU Kerberos tickets.\n";
79}
80else {
81    #send unauth
82    debug(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
83    exec(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
84}
Note: See TracBrowser for help on using the repository browser.