diff options
Diffstat (limited to 'script/testauthenticator.pl')
-rwxr-xr-x | script/testauthenticator.pl | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/script/testauthenticator.pl b/script/testauthenticator.pl new file mode 100755 index 0000000..2e04573 --- /dev/null +++ b/script/testauthenticator.pl @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +use v5.24; +use warnings; +use utf8; +use autodie; + +use constant HMAC_MD5 => eval { require Digest::HMAC_MD5; Digest::HMAC_MD5->import('hmac_md5_hex'); 1 }; + +use constant { + VALID_USER => 'mockmaildir@example.org', + VALID_PW => '12345', +}; + + +sub main { + open my $authfd, '<&=3'; + + my $inp = <$authfd>; + close $authfd; + + my ($u, $p, $c, @r) = split "\0", $inp; + if (@r) { + warn 'too many fields!'; + exit 2; + } + + if ($c) { + if (!HMAC_MD5) { exit 111 } + if ($u eq VALID_USER && $p eq hmac_md5_hex($c, VALID_PW)) { + exec @ARGV; + } + } + else { + if ($u eq VALID_USER && $p eq VALID_PW) { + exec @ARGV; + } + } + + exit 1; +} + +main unless caller; + +1 + +__END__ + +=encoding utf-8 + +=head1 + +testauthenicator.pl |