summaryrefslogtreecommitdiff
path: root/script/testauthenticator.pl
blob: 2e045735b396345a30d76e623233ef0df81e58f9 (plain)
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
#!/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