DBus/Authn/Mechanism/EXTERNAL.pm

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