| 1 | package Protocol::DBus::Authn::Mechanism::EXTERNAL; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use parent 'Protocol::DBus::Authn::Mechanism'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | 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 | # On other OSes it doesn’t seem possible to send credentials via a | ||||||||||||||||||||||||||||
| 17 | # UNIX socket in the first place. But let’s still try. | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | 4 | our @OS_NO_MSGHDR_LIST = ( | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Reference server doesn’t need our help: | ||||||||||||||||||||||||||||
| 22 | 'linux', | ||||||||||||||||||||||||||||
| 23 | 'netbsd', # via LOCAL_PEEREID, which dbus calls | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # LOCAL_PEERCRED exists and works, but the reference server | ||||||||||||||||||||||||||||
| 26 | # doesn’t appear to use it. Nonetheless, EXTERNAL authn works | ||||||||||||||||||||||||||||
| 27 | # on these OSes. Maybe getpeereid() calls LOCAL_PEERCRED? | ||||||||||||||||||||||||||||
| 28 | 'freebsd', # NB: doesn’t work w/ socketpair() | ||||||||||||||||||||||||||||
| 29 | 'darwin', | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # 'openbsd', ??? Still trying to test. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # No way to pass credentials via UNIX socket, | ||||||||||||||||||||||||||||
| 34 | # so let’s just send EXTERNAL and see what happens. | ||||||||||||||||||||||||||||
| 35 | # It’ll likely just fail over to DBUS_COOKIE_SHA1. | ||||||||||||||||||||||||||||
| 36 | 'cygwin', | ||||||||||||||||||||||||||||
| 37 | 'mswin32', | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub INITIAL_RESPONSE { unpack 'H*', $> } | ||||||||||||||||||||||||||
|
Subroutine
INITIAL_RESPONSE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # The reference server implementation does a number of things to try to | ||||||||||||||||||||||||||||
| 43 | # fetch the peer credentials. . | ||||||||||||||||||||||||||||
| 44 | sub must_send_initial { | ||||||||||||||||||||||||||||
| 45 | 6 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
must_send_initial: called CC=4 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 6 | ▶ | if (!defined $self->{'_must_send_initial'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 5 | my $can_skip_msghdr = grep { $_ eq $^O } @OS_NO_MSGHDR_LIST; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 5 | ▶ | $can_skip_msghdr ||= eval { my $v = Socket::SO_PEERCRED(); 1 }; | ||||||||||||||||||||||||||
|
Condition33%1/3
$can_skip_msghdr ||= eval {
do {
my $v = 17;
1
}
}
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
}
}
| |||||||||||||||||||||||||||||
| 52 | 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
}
}
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
}
}
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # As of this writing it seems FreeBSD and DragonflyBSD do require | ||||||||||||||||||||||||||||
| 55 | # Socket::MsgHdr, even though they both have LOCAL_PEERCRED which | ||||||||||||||||||||||||||||
| 56 | # should take care of that. | ||||||||||||||||||||||||||||
| 57 | 5 | $self->{'_must_send_initial'} = !$can_skip_msghdr; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 6 | return $self->{'_must_send_initial'}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub send_initial { | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my ($self, $s) = @_; | ||||||||||||||||||||||||||
|
Subroutine
send_initial: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | eval { require Socket::MsgHdr; 1 } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | die "Socket::MsgHdr appears to be needed for EXTERNAL authn (OS=$^O) but failed to load: $@"; | |||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my $msg = Socket::MsgHdr->new( buf => "\0" ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # The kernel should fill in the payload. | ||||||||||||||||||||||||||||
| 73 | 0 | $msg->cmsghdr( Socket::SOL_SOCKET(), Socket::SCM_CREDS(), "\0" x 64 ); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | local $!; | |||||||||||||||||||||||||||
| 76 | 0 | my $ok = Protocol::DBus::Socket::sendmsg_nosignal($s, $msg, 0); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (!$ok && !$!{'EAGAIN'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ok or $!{"EAGAIN"}
MC/DC0%0/2
$ok or $!{"EAGAIN"}
$ok
$!{"EAGAIN"}
Truth table0%0/3
A or B
A= $okB= $!{"EAGAIN"}
| |||||||||||||||||||||||||||||
| 79 | 0 | die "sendmsg($s): $!"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | return $ok; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 4 | 1; | |||||||||||||||||||||||||||