digest-md5-auth.pl untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 72 CC 1 SCAR 6.9
CC
1
Cov
0%
dbg
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use warnings;
4 use strict;
5  
6 use OpenLDAP;
7 use Authen::DigestMD5;
8  
9 use Getopt::Std;
10 our ($opt_h, $opt_U, $opt_R, $opt_w, $opt_d);
11 getopts("h:U:R:w:d");
12  
13 my $host=$opt_h || 'localhost';
14 my $realm=$opt_R || 'demo';
15 my $user=$opt_U || 'test';
16 my $passwd=$opt_w or die "password missing\n";
17  
18 sub dbg { $opt_d and print STDERR @_, "\n" };
19  
20 my ($ld, $rc, $id, $msg, $req);
21 $ld=OpenLDAP::Client->new($host);
22 ($rc, $id)=$ld->sasl_bind(undef, 'DIGEST-MD5');
23 dbg "sasl_bind: $rc $id";
24  
25 ($rc, $msg)=$ld->result($id);
26 dbg "result: $rc $msg";
27  
28 ($rc, $req)=$ld->parse_sasl_bind_result($msg);
29 dbg "parse_sasl_bind_result: $rc";
30  
31 dbg "IN: |$req|";
32 my $request=Authen::DigestMD5::Request->new($req);
33  
34 my $response=Authen::DigestMD5::Response->new;
35 $response->got_request($request);
36 $response->set(username => $user,
37 realm => $realm,
38 'digest-uri' => "ldap/$host");
39 $response->add_digest(password=>$passwd);
40  
41 my $res=$response->output;
42  
43  
44 dbg "OUT: |$res|";
45  
46 ($rc, $id)=$ld->sasl_bind(undef, 'DIGEST-MD5', $res);
47 dbg "sasl_bind: $rc $id";
48  
49 ($rc, $msg)=$ld->result($id);
50 dbg "result: $rc $msg";
51  
52 ($rc, $req)=$ld->parse_sasl_bind_result($msg);
53 dbg "parse_sasl_bind_result: $rc, $req";
54  
55 $request->input($req);
56  
57  
58 print $request->auth_ok ? "AUTH OK\n" : "AUTH FAILED\n"