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

Revision 25714, 2.6 KB checked in by jdreed, 12 years ago (diff)
In msmtp-config: * Man page cleanup * Remind users how to renew 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'} || 'yes';
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 ($ENV{'DEBATHENA_SENDMAIL_FROM'}) {
46    return "--from=" . $ENV{'DEBATHENA_SENDMAIL_FROM'};
47  }
48  if ($kuser) {
49    return "--from=" . join('@', $kuser, 'mit.edu');
50  }
51  # Note that ATHENA_USER is explicitly not checked here. We've
52  # already checked to see if you have Kerberos tickets, and
53  # semantically, if you don't have Kerberos tickets, you're not
54  # sending as an Athena user.
55  my $uname = $ENV{'USER'} || $ENV{'LOGNAME'} || getpwuid($<);
56  # Otherwise, assume user@fqdn ...
57  chomp(my $maildomain = `hostname --fqdn`);
58  # ... except that nss-nonlocal-users are @mit.edu
59  if (getgrnam('nss-nonlocal-users')) {
60    my $nssnonlocalgid = (getgrnam('nss-nonlocal-users'))[2];
61    if (grep(/^$nssnonlocalgid$/, getgroups())) {
62      debug("Assuming \@mit.edu for nss-nonlocal-user $uname");
63      $maildomain = 'mit.edu';
64    }
65  }
66  return "--from=" . join('@', $uname, $maildomain);
67}
68
69my @aliases = ();
70foreach my $arg (@ARGV) {
71    push @aliases, $parser->expand($arg);
72}
73
74if ($kuser) {
75    #send auth
76    debug(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
77    exec(qw{msmtp --host=outgoing.mit.edu --port=587 --auth=gssapi}, "--user=$kuser", from_address(), @aliases);
78}
79elsif ($want_auth ne 'fallback') {
80    $! = 1;
81    die "Could not find valid ATHENA.MIT.EDU Kerberos tickets.\n(Do you need to run 'renew'?)\n";
82}
83else {
84    #send unauth
85    debug(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
86    exec(qw{msmtp --host=outgoing.mit.edu --port=25 --auth=off}, from_address(), @aliases);
87}
Note: See TracBrowser for help on using the repository browser.