DBus/Authn/Mechanism/EXTERNAL.pm

filter: Statementstmt 55.1% 27 / 49 Branchbran 30.0% 3 / 10 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 4 totaltotal 44.8% 39 / 87 CC 9 SCAR 20.0
CC
9
Cov
47%
send_initial
12.0
must_send_initial
11.9
on_rejected
6.0
CRAP 7.4
« DBus/Client/Mojo.pm ↑ Summary DBus/Client/IOAsync.pm »
1 package Protocol::DBus::Authn::Mechanism::EXTERNAL;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use parent 'Protocol::DBus::Authn::Mechanism';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Protocol::DBus::Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶use constant SOCKET_MSGHDR_MINIMUM_VERSION => 0.05;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # The methods of user credential retrieval that the reference D-Bus
13 # server relies on prefer “out-of-band” methods like SO_PEERCRED
14 # on Linux rather than SCM_CREDS. (See See dbus/dbus-sysdeps-unix.c.)
15 # So for some OSes it’s just not necessary to do anything special to
16 # send credentials.
17 #
18 # This list is exposed for the sake of tests.
19 #
20 12 our @_OS_NO_MSGHDR_LIST = (
21  
22 # Reference server doesn’t need our help:
23 'linux',
24 'netbsd', # via LOCAL_PEEREID, which dbus calls
25  
26 # MacOS works, though … ??
27 'darwin',
28  
29 # 'openbsd', ??? Still trying to test.
30  
31 # No way to pass credentials via UNIX socket,
32 # so let’s just send EXTERNAL and see what happens.
33 # It’ll likely just fail over to DBUS_COOKIE_SHA1.
34 'cygwin',
35 'mswin32',
36 );
37  
38 3 ▶sub INITIAL_RESPONSE { unpack 'H*', $> }
Subroutine INITIAL_RESPONSE: called CC=1 SCAR=0.0
Pod undocumented
39  
40 # The reference server implementation does a number of things to try to
41 # fetch the peer credentials. .
42 10 ▶sub must_send_initial {
Subroutine must_send_initial: called CC=6 SCAR=24.8
Pod undocumented
43 10 my ($self) = @_;
44  
45 10 ▶ if (!defined $self->{'_must_send_initial'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_must_send_initial"}) 8 2 10
46  
47 8 my $can_skip_msghdr = grep { $_ eq $^O } @_OS_NO_MSGHDR_LIST;
48  
49 0 ▶ $can_skip_msghdr ||= eval { my $v = Socket::SO_PEERCRED(); 1 };
Condition33%1/3
$can_skip_msghdr ||= eval { do { my $v = 17; 1 } }
l!l&&r!l&&!r
800
MC/DC0%0/2
$can_skip_msghdr ||= eval { do { my $v = 17; 1 } }
$can_skip_msghdr eval { do { my $v = 17; 1 } }
Truth table33%1/3
A ||= B
A= $can_skip_msghdrB= eval { do { my $v = 17; 1 } }
ABresult
1X1
011
000
50 0 ▶ $can_skip_msghdr ||= eval { my $v = Socket::LOCAL_PEEREID(); 1 };
Condition33%1/3
$can_skip_msghdr ||= eval { do { my $v = &Socket::LOCAL_PEEREID(); 1 } }
l!l&&r!l&&!r
800
MC/DC0%0/2
$can_skip_msghdr ||= eval { do { my $v = &Socket::LOCAL_PEEREID(); 1 } }
$can_skip_msghdr eval { do { my $v = &Socket::LOCAL_PEEREID(); 1 } }
Truth table33%1/3
A ||= B
A= $can_skip_msghdrB= eval { do { my $v = &Socket::LOCAL_PEEREID(); 1 } }
ABresult
1X1
011
000
51  
52 8 ▶ if (!$can_skip_msghdr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($can_skip_msghdr) 0 8 8
53 0 my $ok = eval {
54 0 require Socket::MsgHdr;
55 0 Socket::MsgHdr->VERSION(SOCKET_MSGHDR_MINIMUM_VERSION);
56 };
57  
58 0 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
59 0 $self->{'_failed_socket_msghdr'} = $@;
60 0 $can_skip_msghdr = 1;
61 }
62 }
63  
64 # As of this writing it seems FreeBSD and DragonflyBSD do require
65 # Socket::MsgHdr, even though they both have LOCAL_PEERCRED which
66 # should take care of that.
67 8 $self->{'_must_send_initial'} = !$can_skip_msghdr;
68 }
69  
70 10 return $self->{'_must_send_initial'};
71 }
72  
73 0 ▶sub on_rejected {
Subroutine on_rejected: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my ($self) = @_;
75  
76 0 ▶ if ($self->{'_failed_socket_msghdr'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_failed_socket_msghdr"}) 0 0 0
77 0 warn "EXTERNAL authentication failed. Socket::MsgHdr failed to load earlier; maybe making it available would fix this? (Load failure was: $self->{'_failed_socket_msghdr'})";
78 }
79  
80 0 return;
81 }
82  
83 0 ▶sub send_initial {
Subroutine send_initial: not called CC=3 SCAR=24.8
Pod undocumented
84 0 my ($self, $s) = @_;
85  
86 0 my $msg = Socket::MsgHdr->new( buf => "\0" );
87  
88 # The kernel should fill in the payload.
89 0 $msg->cmsghdr( Socket::SOL_SOCKET(), Socket::SCM_CREDS(), "\0" x 64 );
90  
91 0 local $!;
92 0 my $ok = Protocol::DBus::Socket::sendmsg_nosignal($s, $msg, 0);
93  
94 0 ▶ if (!$ok && !$!{'EAGAIN'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok or $!{"EAGAIN"}) 0 0 0
Condition0%0/3
$ok or $!{"EAGAIN"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ok or $!{"EAGAIN"}
$ok $!{"EAGAIN"}
Truth table0%0/3
A or B
A= $okB= $!{"EAGAIN"}
ABresult
1X1
011
000
95 0 die "sendmsg($s): $!";
96 }
97  
98 0 return $ok;
99 }
100  
101 12 1;
« DBus/Client/Mojo.pm ↑ Summary DBus/Client/IOAsync.pm »