-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspf-forward
executable file
·74 lines (62 loc) · 2.09 KB
/
spf-forward
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl -T
#
# Copyright (C) 2015-2021 Christian Jaeger (ch at christianjaeger ch)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use strict; use warnings; use warnings FATAL => 'uninitialized';
# find modules
use Cwd 'abs_path';
our ($mydir, $myname); BEGIN {
my $location= (-l $0) ? abs_path ($0) : $0;
$location=~ /(.*?)([^\/]+?)_?\z/s or die "?";
($mydir, $myname)=($1,$2);
}
use lib "$mydir/chj-perllib";
use lib "$mydir/functional-perl/lib";
use lib "$mydir/lib";
@ARGV >= 3
or die "usage: $0 newsender_pre newsender_post address(es)";
my ($newsender_pre, $newsender_post, @address)= @ARGV;
# use safe PATH setting: XX make configurable?
$ENV{PATH}=
join(":",
qw(/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin));
use FP::Untainted qw(untainted);
my $sender= $ENV{SENDER}
// die "missing SENDER env variable";
$sender=~ s/\@/=/g;
my $newsender= do {
# XXX which characters exactly are all ok?
if (my ($ok)= $sender=~ /^([a-zA-Z=0-9.+-]+)\z/s) {
untainted($newsender_pre) . $ok . untainted($newsender_post)
} else {
warn "rewritefailure with sender='$sender'";
untainted($newsender_pre) . "rewritefailure" . untainted($newsender_post)
}
};
$ENV{NEWSENDER}= $newsender;
if ($ENV{DRY_RUN}) {
print "NEWSENDER=$ENV{NEWSENDER} ";
print join(" ", "forward", (map { untainted $_ } @address)),"\n";
} else {
exec "forward", (map { untainted $_ } @address)
or exit 127;
}