#!/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