1 # vim: set tabstop=4 shiftwidth=4 expandtab syntax=perl:
9 sub local_filter_cancel {
10 unless($hdr{Control} =~ m/^cancel\s+(<[^>]+>)/i) {
11 return "Cancel with broken target ID";
13 return verify_cancel(\%hdr, $1, 'Cancel');
16 sub local_filter_after_emp {
17 if (exists( $hdr{'Supersedes'} )) {
18 #return verify_cancel(\%hdr, $hdr{'Supersedes'}, 'Supersedes');
19 # verify_cancel is called, but not returned, so the
20 # posting is unconditionally accepted
21 # verify_cancel calls INN:cancel() if verification suceeds
22 verify_cancel(\%hdr, $hdr{'Supersedes'}, 'Supersedes');
28 sub verify_cancel($$$) {
29 my $r_hdr = shift || die;
33 my $headers = INN::head($target) || return "$descr of non-existing ID $target";
36 for my $line(split(/\s*\n/, $headers)) {
37 if ($line =~ m/^([[:alnum:]-]+):\s+(.*)/) {
40 } elsif ($line =~ m/^\s+(.*)/ and defined($lastkey)) {
41 $headers{$lastkey} .= ' ' . $1;
44 my $lock = $headers{'Cancel-Lock'};
47 my $key = $r_hdr->{'Cancel-Key'} || return "$descr of $target without Cancel-Key";
48 #return verify_cancel_key($key, $lock, ' target=' . $target);
49 return verify_cancel_key($key, $lock, $target);
52 # no cancel-lock: go ahead and cancel anyway!
59 sub verify_cancel_key($$$) {
60 my $cancel_key = shift;
61 my $cancel_lock = shift;
64 $msg = '' unless(defined($msg));
67 $msg = ' target=' . $msg;
70 for my $l(split(/\s+/, $cancel_lock)) {
71 next unless($l =~ m/^(sha1|md5):(\S+)/);
75 for my $k(split(/\s+/, $cancel_key)) {
76 unless($k =~ m/^(sha1|md5):(\S+)/) {
77 INN::syslog('notice', "Invalid Cancel-Key syntax '$k'.$msg");
83 $key = Digest::SHA::sha1($2); }
85 $key = Digest::MD5::md5($2);
87 $key = MIME::Base64::encode_base64($key, '');
89 if (exists($lock{$key})) {
90 # INN::syslog('notice', "Valid Cancel-Key $key found.$msg");
92 # article is canceled now
93 INN::cancel($target) if ($target);
99 "No Cancel-Key[$cancel_key] matches Cancel-Lock[$cancel_lock]$msg"
101 return "No Cancel-Key matches Cancel-Lock.$msg";