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 *
RevLine 
[24016]1#!/usr/bin/perl
2
3use Mail::ExpandAliases;
[24401]4use File::Basename;
5use POSIX qw(getgroups);
[24016]6
[24415]7use strict;
[24416]8use warnings;
[24016]9
[24458]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
[24491]17my $kuser;
18my $want_auth = $ENV{'DEBATHENA_SENDMAIL_AUTH'} || '';
19
20system(qw(klist -s));
[24415]21if (($? == 0) &&
22    (`klist 2>/dev/null` =~ /Default principal: (.*?)\@ATHENA.MIT.EDU/)) {
23    $kuser = $1;
[25065]24    # Remove any instances
25    $kuser =~ s|/.*||g;
[24415]26}
[24401]27
[24415]28my $parser = Mail::ExpandAliases->new;
29
[24401]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  }
[24490]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.
[24489]52  my $uname = $ENV{'USER'} || $ENV{'LOGNAME'} || getpwuid($<);
[24456]53  # Otherwise, assume user@fqdn ...
54  chomp(my $maildomain = `hostname --fqdn`);
55  # ... except that nss-nonlocal-users are @mit.edu
[24416]56  if (getgrnam('nss-nonlocal-users')) {
57    my $nssnonlocalgid = (getgrnam('nss-nonlocal-users'))[2];
58    if (grep(/^$nssnonlocalgid$/, getgroups())) {
[24458]59      debug("Assuming \@mit.edu for nss-nonlocal-user $uname");
[24456]60      $maildomain = 'mit.edu';
[24416]61    }
[24401]62  }
[24456]63  return "--from=" . join('@', $uname, $maildomain);
[24401]64}
65
[24415]66my @aliases = ();
67foreach my $arg (@ARGV) {
[24016]68    push @aliases, $parser->expand($arg);
69}
70
[24416]71if ($kuser && (($want_auth eq 'yes') || ($want_auth eq '')) ) {
[24016]72    #send auth
[24458]73    debug(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
[24401]74    exec(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
[24016]75}
[24416]76elsif ($want_auth eq 'yes') {
[24016]77    $! = 1;
78    die "Could not find valid ATHENA.MIT.EDU Kerberos tickets.\n";
79}
80else {
81    #send unauth
[24458]82    debug(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
[24401]83    exec(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
[24016]84}
Note: See TracBrowser for help on using the repository browser.