| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | anyevent-mcp-askpermission - graphical or terminal permission helper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | C<anyevent-mcp-askpermission> asks you whether an MCP tool may perform an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | operation, such as reading a file or running a command. It shows the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | requested operation and privileges, and lets you allow or deny it once, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | or choose a rule for future requests. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | Servers using L<AnyEvent::MCP::Server::Permissions> normally start this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | helper automatically when a permission check needs your decision. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | helper displays a local graphical dialog or asks in a terminal, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | returns your choice to the server. You do not normally run it yourself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | To change saved rules later, use C<anyevent-mcp manage-rules NAME> or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | C<anyevent-mcp edit-rules NAME>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 PERMISSION PROMPTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | The helper tries YAD first, leaving display backend selection to GTK. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | If YAD cannot start, it asks on C</dev/tty>. Closing a working dialog, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | terminal EOF, or having neither interface available means deny once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | Server, tool, action, current dimension values and reason are shown as read-only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | GTK labels when present, including the multibroker alias when available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | The requested sandbox grants appear together on one line. The initial YAD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | form also has a C<Denial reason (optional)> field above four choices: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | C<Deny once>, C<Deny always...>, C<Allow always...>, C<Allow once>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | The persistent rule editor creates a selector for each named permission | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | dimension with multiple offered scopes, using the server's labels and matchers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | Single-choice scopes are applied automatically without a selector. For example, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | the workdir dimension may offer this workdir or any configured workdir. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | The scopes affect saved rule matching, not the current call's sandbox grants. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | One-time decisions are on the outside; C<Deny once> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | uses YAD's default OK response. Closing the dialog also denies once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | The persistent choices open a separate rule editor for grant and scope | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | settings, including exact requested-file scope on deny rules. Rules can last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | indefinitely (the default), 900 seconds or 16 hours. Expired rules disappear | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | when the rules are read and are removed from disk on the next ordinary save. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | The reason | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | is included in a denial result but is ignored on an allowance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | Optional display-only request C<details> maps plain labels to Unicode text, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | for example C<< { "View patch" => $diff } >>. Each entry appears as a size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | summary and a button. YAD adds an ellipsis to the label and opens a separate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | read-only, resizable, monospace text window without dismissing the approval dialog. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | Content is written to a private temporary UTF-8 file, never interpolated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | into a command; control characters are escaped. The helper limits each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | preview to 65536 Unicode characters and identifies incomplete previews. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Terminal and native MCP prompts include the same bounded text inline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | Display-only details never constrain or become part of persistent permission rules; an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | C<allow-always> rule for C<perl -> permits future, different stdin scripts. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | YAD uses GTK, so you can select a dark theme externally by setting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | C<GTK_THEME=Adwaita:dark> in the server's environment before starting it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | The permission helper inherits that setting and passes it to YAD; the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | theme is not changed for unrelated applications. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | In a terminal, the four decisions are single-letter shortcuts and C<m> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | edits the optional denial reason. Closing the dialog, cancelling or an unavailable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | terminal denies once. Rule management remains separate: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | C<anyevent-mcp manage-rules NAME> or C<anyevent-mcp edit-rules NAME>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =head1 HELPER PROTOCOL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | The helper reads one permission request on stdin and writes one JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | decision on stdout. Servers invoke it through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | L<AnyEvent::MCP::Permissions::Ask>, which describes the helper interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | and how to select a replacement helper. YAD's stderr is suppressed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | startup failure is detected from its exit status. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | =item --manage-rules FILE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Open YAD rule list for FILE in evaluation order. Delete or reorder selected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | rules. File lock protects updates; changes fail if list changed elsewhere. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | Cannot combine with C<--edit-rules> or prompt-mode flags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =item --edit-rules FILE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | Edit permission rules in FILE using C<$VISUAL>, C<$EDITOR>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | C<sensible-editor> or C<vi>. Does not validate or overwrite editor output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | Cannot combine with C<--manage-rules> or prompt-mode flags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =item --tty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | Prompt only on C</dev/tty>, without YAD fallback. Unavailable terminal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | denies access. Cannot combine with C<--yad> or rule-management flags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | =item --yad | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | Prompt only with YAD, without terminal fallback. Unavailable YAD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | denies access. Cannot combine with C<--tty> or rule-management flags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =item --help | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | Print short usage synopsis and exit. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Without explicit C<--tty> or C<--yad>, prompts try YAD first, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | C</dev/tty> only if YAD cannot start. Closing or declining a working | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | dialog never triggers fallback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | ▶ | use common::sense; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 16 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 16 | ▶ | use Text::ParseWords (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 16 | ▶ | use File::Temp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 16 | ▶ | use JSON::XS (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 16 | ▶ | use AnyEvent::MCP (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 16 | ▶ | use AnyEvent::MCP::Permissions::Ask (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 16 | ▶ | use AnyEvent::MCP::Server::Permissions (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 16 | ▶ | Getopt::Long::GetOptions ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | "manage-rules=s" => \my $rules_file, "edit-rules=s" => \my $edit_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | "tty" => \my $tty_only, "yad" => \my $yad_only, "help" => \my $help, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | or exit 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 16 | ▶ | die "Unexpected arguments\n" if @ARGV || defined $rules_file && defined $edit_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
@ARGV or defined $rules_file and defined $edit_file
defined $rules_file and defined $edit_file
MC/DC0%0/3
@ARGV or defined $rules_file and defined $edit_file
@ARGV
defined $rules_file
defined $edit_file
Truth table50%2/4
A or B and C
A= @ARGVB= defined $rules_fileC= defined $edit_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | ▶ | die "--tty and --yad are mutually exclusive\n" if $tty_only && $yad_only; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tty_only and $yad_only
MC/DC0%0/2
$tty_only and $yad_only
$tty_only
$yad_only
Truth table33%1/3
A and B
A= $tty_onlyB= $yad_only
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 16 | ▶ | die "--tty/--yad select permission prompts, not rule management\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition22%2/9
$tty_only || $yad_only and defined $rules_file || defined $edit_file
$tty_only or $yad_only
defined $rules_file or defined $edit_file
MC/DC0%0/4
$tty_only || $yad_only and defined $rules_file || defined $edit_file
$tty_only
$yad_only
defined $rules_file
defined $edit_file
Truth table14%1/7
A or B and C or D
A= $tty_onlyB= $yad_onlyC= defined $rules_fileD= defined $edit_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | if ($tty_only || $yad_only) && (defined $rules_file || defined $edit_file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 16 | ▶ | if ($help) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | print "usage: $0 [--tty | --yad | --manage-rules FILE | --edit-rules FILE]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 16 | binmode STDIN; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 16 | binmode STDOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 16 | my $json = JSON::XS->new->canonical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 16 | my $yad_pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $SIG{TERM} = $SIG{INT} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($yad_pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | kill TERM => $yad_pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | waitpid $yad_pid, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 17 | ▶ | sub yad { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
yad: called CC=7 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 17 | my $pid = open my $fh, "-|"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 17 | ▶ | return unless defined $pid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 17 | ▶ | if (!$pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 7 | ▶ | open STDERR, ">", "/dev/null" or exit 127; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | exec "yad", "--no-markup", map AnyEvent::MCP::utf8enc $_, @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | exit 127; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 10 | $yad_pid = $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 10 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 10 | my $output = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | my $status = $?; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | undef $yad_pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # our buttons never use 1: GTK display failure is not user cancellation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | ▶ | return if $status == 1 << 8 || $status == 127 << 8 || $status & 127; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$status == 256 or $status == 32512 or $status & 127
$status == 256 or $status == 32512
MC/DC0%0/3
$status == 256 or $status == 32512 or $status & 127
$status == 256
$status == 32512
$status & 127
Truth table25%1/4
A or B or C
A= $status == 256B= $status == 32512C= $status & 127
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 10 | ($status >> 8, AnyEvent::MCP::utf8dec $output) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 11 | ▶ | sub manage_rules { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
manage_rules: called CC=18 SCAR=32.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 11 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 11 | my $permissions = AnyEvent::MCP::Server::Permissions->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 11 | $permissions->{file} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 11 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 17 | my $rules = $permissions->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | my ($status, $output) = yad ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | "--list", "--title=MCP permission rules", "--width=900", "--height=450", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | "--text=$file\nRules are evaluated from top to bottom; the first match wins.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | "--column=Order:NUM", "--column=Decision", "--column=Action", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | "--column=Dimensions", "--column=Sandbox grants", "--column=Expires", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | "--no-click", "--print-column=1", "--separator=\x1f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | "--button=Close:0", "--button=Move up:4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | "--button=Move down:6", "--button=Delete selected:2", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 17 | my $rule = $rules->[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | $_ + 1, $rule->{decision} || "ask", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | (exists $rule->{action} ? $json->encode ($rule->{action}) : "(any)"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | (join ", ", map { "$_=" . $json->encode ($rule->{$_}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | sort grep /^match\./, keys %$rule) || "(any)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | (exists $rule->{"sandbox-grants"} ? $json->encode ($rule->{"sandbox-grants"}) : "(any)"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 40 | ▶ | (exists $rule->{expires} ? scalar localtime $rule->{expires} : "Indefinite") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$rule->{'decision'} || 'ask'
join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule)))) || '(any)'
MC/DC0%0/1
$rule->{'decision'} || 'ask'
$rule->{'decision'}
MC/DC0%0/1
join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule)))) || '(any)'
join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule))))
Truth table50%1/2
A
A= $rule->{'decision'}
Truth table50%1/2
A
A= join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule))))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } 0 .. $#$rules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | ▶ | die "YAD rule editor unavailable\n" unless defined $status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | ▶ | return unless grep $_ == $status, 2, 4, 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | my ($index) = $output =~ /\A([1-9][0-9]*)\x1f?\s*\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | ▶ | next unless $index && $index <= @$rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index and $index <= @$rules
MC/DC0%0/2
$index and $index <= @$rules
$index
$index <= @$rules
Truth table33%1/3
A and B
A= $indexB= $index <= @$rules
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | next if $status == 4 && $index == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$status == 4 and $index == 1
MC/DC0%0/2
$status == 4 and $index == 1
$status == 4
$index == 1
Truth table66%2/3
A and B
A= $status == 4B= $index == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | ▶ | next if $status == 6 && $index == @$rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$status == 6 and $index == @$rules
MC/DC0%0/2
$status == 6 and $index == @$rules
$status == 6
$index == @$rules
Truth table66%2/3
A and B
A= $status == 6B= $index == @$rules
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | my $expected = $json->encode ($rules); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 6 | my $lock = $permissions->_lock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 6 | my $current = $permissions->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | ▶ | die "Permission rules changed since selection\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | unless $json->encode ($current) eq $expected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | ▶ | if ($status == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | splice @$current, $index - 1, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | ▶ | my $other = $status == 4 ? $index - 2 : $index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | @$current[$index - 1, $other] = @$current[$other, $index - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # deletion does not need the application's capability implications. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | $permissions->{sandbox_grants} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | map { map { $_ => [] } split /,/, $_->{"sandbox-grants"} } @$current | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 6 | $permissions->_write ($current); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 6 | 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | print STDERR $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | yad "--title=MCP permission rules", "--text=$error", "--button=Close:0"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | ▶ | sub edit_rules { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit_rules: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | my $permissions = AnyEvent::MCP::Server::Permissions->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | $permissions->{file} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | my $lock = $permissions->_lock; # ensure the file exists and is private. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 5 | ▶ | close $lock or die "Cannot unlock permission rules: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 5 | ▶ | for my $choice (grep { defined && /\S/ } @ENV{qw(VISUAL EDITOR)}, "sensible-editor", "vi") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && /\S/u
MC/DC0%0/2
defined $_ && /\S/u
defined $_
/\S/u
Truth table33%1/3
A && B
A= defined $_B= /\S/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | my @editor = Text::ParseWords::shellwords ($choice); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 7 | ▶ | next unless @editor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 7 | my $status = system { $editor[0] } @editor, AnyEvent::MCP::utf8enc ($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | ▶ | next if $status == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 5 | ▶ | $status == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | or die "Editor failed or was interrupted (status $status)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | die "No editor found (VISUAL, EDITOR, sensible-editor, vi)\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 16 | ▶ | if (defined $rules_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 11 | ▶ | eval { manage_rules AnyEvent::MCP::utf8dec $rules_file; 1 } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | print STDERR $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 5 | ▶ | if (defined $edit_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 5 | ▶ | eval { edit_rules AnyEvent::MCP::utf8dec $edit_file; 1 } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | print STDERR $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $request = do { local $/; JSON::XS::decode_json (scalar <STDIN>) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | die "Invalid permission request\n" unless $request->{version} == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my $dimensions = $request->{dimensions} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->{'dimensions'} || {}
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
Truth table0%0/2
A
A= $request->{'dimensions'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my @dimensions = sort keys %$dimensions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my @selectable_dimensions = grep @{$dimensions->{$_}{choices}} > 1, @dimensions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my %decisions = (d => "deny-once", n => "deny-always", o => "allow-once", a => "allow-always"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $persistent = !grep !@{$dimensions->{$_}{choices}}, @dimensions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my @deny_paths = grep defined && !ref, @{$request->{paths} || []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
defined $_ && !ref($_)
$request->{'paths'} || []
MC/DC0%0/2
defined $_ && !ref($_)
defined $_
!ref($_)
MC/DC0%0/1
$request->{'paths'} || []
$request->{'paths'}
Truth table0%0/3
A && not(B)
A= defined $_B= !ref($_)
Truth table0%0/2
A
A= $request->{'paths'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | my $unsandboxed = ($request->{sandbox_implementation} || "") =~ /\ANONE/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->{'sandbox_implementation'} || ''
MC/DC0%0/1
$request->{'sandbox_implementation'} || ''
$request->{'sandbox_implementation'}
Truth table0%0/2
A
A= $request->{'sandbox_implementation'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub rule_dialog { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule_dialog: not called CC=32 SCAR=69.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my ($choice, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $allow = $choice eq "allow-always"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my %selected = map { $_ => 1 } @{$request->{sandbox_grants}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | my ($status, $output) = yad ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | "--form", "--title=Create MCP permission rule", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | "--width=650", "--separator=\x1f", "--item-separator=\x1f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | "--num-output", "--always-print-result", "--buttons-layout=edge", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | "--text=Configure which future requests this rule covers." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | . (!$allow ? "\nDenial reason: " . (length $message ? $message : "(none)") : ""), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | "--button=Back:10", "--button=Save rule:8", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ($allow ? (map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $grant = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $description = $request->{sandbox_grant_descriptions}{$grant}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | my $label = $grant . (defined $description && length $description ? " - $description" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $description and length $description
MC/DC0%0/2
defined $description and length $description
defined $description
length $description
Truth table0%0/3
A and B
A= defined $descriptionB= length $description
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $label =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | ("--field=$label:CHK", $selected{$grant} ? "TRUE" : "FALSE") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | } @{$request->{sandbox_grant_choices}}) : ()), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | (map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $dim = $dimensions->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ("--field=$dim->{label} scope:CB", join "\x1f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | map { ($_ == 0 ? "^" : "") . ($_ + 1) . ": " . $json->encode ($dim->{choices}[$_]{label}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | 0 .. $#{$dim->{choices}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $allow and @deny_paths
MC/DC0%0/2
not $allow and @deny_paths
not $allow
@deny_paths
Truth table0%0/3
not(A) and B
A= not $allowB= @deny_paths
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } @selectable_dimensions), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | (!$allow && @deny_paths ? ("--field=Deny file scope:CB", join "\x1f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | (map { ($_ == 0 ? "^" : "") . ($_ + 1) . ": Exact file " . $json->encode ($deny_paths[$_]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 .. $#deny_paths), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | (@deny_paths + 1) . ": All paths") : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | "--field=Rule lifetime:CB", "^Indefinite\x1f900 seconds\x1f16 hours", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | return { decision => "back" } if $status == 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | return { decision => "deny-once" } unless $status == 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my @values = split /\x1f/, $output, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | my %answer = (decision => $choice, (!$allow && length $message ? (message => $message) : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $allow and length $message
MC/DC0%0/2
not $allow and length $message
not $allow
length $message
Truth table0%0/3
not(A) and B
A= not $allowB= length $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if ($allow) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my @grants; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | for (@{$request->{sandbox_grant_choices}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $value = shift @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | die "Invalid YAD sandbox grant selection\n" unless defined $value && $value =~ /\A(?:TRUE|FALSE)\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and $value =~ /\A(?:TRUE|FALSE)\z/iu
MC/DC0%0/2
defined $value and $value =~ /\A(?:TRUE|FALSE)\z/iu
defined $value
$value =~ /\A(?:TRUE|FALSE)\z/iu
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /\A(?:TRUE|FALSE)\z/iu
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | push @grants, $_ if lc $value eq "true"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $answer{sandbox_grants} = \@grants; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | for my $name (@selectable_dimensions) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $index = shift @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | die "Invalid YAD dimension scope\n" unless defined $index && $index =~ /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | && $index <= @{$dimensions->{$name}{choices}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dimensions->{$name}{"choices"};}
defined $index and $index =~ /\A[1-9][0-9]*\z/u
MC/DC0%0/3
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dimensions->{$name}{"choices"};}
defined $index
$index =~ /\A[1-9][0-9]*\z/u
$index <= @{$dimensions->{$name}{"choices"};}
Truth table0%0/4
A and B and C
A= defined $indexB= $index =~ /\A[1-9][0-9]*\z/uC= $index <= @{$dimensions->{$name}{"choices"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $answer{"dim_$name"} = $dimensions->{$name}{choices}[$index - 1]{match}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if (!$allow && @deny_paths) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $allow and @deny_paths
MC/DC0%0/2
not $allow and @deny_paths
not $allow
@deny_paths
Truth table0%0/3
not(A) and B
A= not $allowB= @deny_paths
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $index = shift @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | die "Invalid YAD denial file scope\n" unless defined $index && $index =~ /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
defined $index and $index =~ /\A[1-9][0-9]*\z/u
MC/DC0%0/3
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
defined $index
$index =~ /\A[1-9][0-9]*\z/u
$index <= @deny_paths + 1
Truth table0%0/4
A and B and C
A= defined $indexB= $index =~ /\A[1-9][0-9]*\z/uC= $index <= @deny_paths + 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | && $index <= @deny_paths + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $answer{path} = $deny_paths[$index - 1] if $index <= @deny_paths; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my $lifetime = shift @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | defined $lifetime && $lifetime =~ /\A[123]\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $lifetime and $lifetime =~ /\A[123]\z/u
MC/DC0%0/2
defined $lifetime and $lifetime =~ /\A[123]\z/u
defined $lifetime
$lifetime =~ /\A[123]\z/u
Truth table0%0/3
A and B
A= defined $lifetimeB= $lifetime =~ /\A[123]\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | or die "Invalid YAD rule lifetime\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $answer{lifetime} = ("indefinite", "900", "57600")[$lifetime - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | \%answer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # display-only details are passed by filename, never through shell source text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub shell_quote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shell_quote: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $arg =~ s/'/'\\''/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | "'$arg'" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub display_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display_text: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # render control and bidi characters explicitly, preserving tabs and newlines. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $text =~ s/([\x00-\x08\x0b-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $text | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | sub detail_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detail_fields: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | for my $label (sort keys %{$request->{details} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->{'details'} || {}
MC/DC0%0/1
$request->{'details'} || {}
$request->{'details'}
Truth table0%0/2
A
A= $request->{'details'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $text = $request->{details}{$label}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | defined $text && !ref $text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $text and not ref $text
MC/DC0%0/2
defined $text and not ref $text
defined $text
not ref $text
Truth table0%0/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | or die "Invalid permission detail\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $preview = AnyEvent::MCP::Permissions::Ask::detail_text $label, $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my $chars = length $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $bytes = length AnyEvent::MCP::utf8enc $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my ($fh, $filename) = File::Temp::tempfile ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | "mcp-permission-XXXXXXXX", TMPDIR => 1, UNLINK => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | print {$fh} AnyEvent::MCP::utf8enc ($preview) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | or die "Cannot write permission detail: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | close $fh or die "Cannot close permission detail: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $label = display_text $label; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $label =~ s/[:\t\n]/sprintf "\\u{%X}", ord $&/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $info = "$label: $chars characters, $bytes UTF-8 bytes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | . ($chars > 65536 ? " (incomplete preview)" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $info =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $button = $label; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $button =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | push @fields, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | "--field=$info:LBL", "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | "--field=$button...:FBTN", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | join " ", map shell_quote ($_), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ("yad", "--no-markup", "--text-info", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | "--title=MCP permission: $label", "--width=900", "--height=650", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | "--fontname=Monospace 11", "--filename=$filename", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | "--button=Close:0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | @fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | sub graphical { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
graphical: not called CC=25 SCAR=64.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if (($request->{_permission_stage} || "") eq "rule") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$request->{'_permission_stage'} || ''
MC/DC0%0/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
Truth table0%0/2
A
A= $request->{'_permission_stage'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my $previous = $request->{_permission_selection}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | return rule_dialog ($previous->{decision}, $previous->{message} // ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$previous->{"message"} // ""
MC/DC0%0/1
$previous->{"message"} // ""
$previous->{"message"}
Truth table0%0/2
A
A= $previous->{"message"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | my @details = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my $value = $request->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | $value = $_ eq "reason" ? display_text ($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $value or $value =~ /[\x00-\x1f\x7f]/u
MC/DC0%0/2
ref $value or $value =~ /[\x00-\x1f\x7f]/u
ref $value
$value =~ /[\x00-\x1f\x7f]/u
Truth table0%0/3
A or B
A= ref $valueB= $value =~ /[\x00-\x1f\x7f]/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | : ref $value || $value =~ /[\x00-\x1f\x7f]/ ? $json->encode ($value) : $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $value =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | name => "Server", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | multibroker_alias => "Multibroker alias", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | tool => "Tool", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | action => "Action", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | action_description => "Action description", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | sandbox_implementation => "Sandbox", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | paths => "Paths", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | reason => "Reason", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | }->{$_} || ucfirst $_) . ": $value" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
{'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_} || ucfirst $_
MC/DC0%0/2
{'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_} || ucfirst $_
{'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_}
ucfirst $_
Truth table0%0/3
A || B
A= {'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_}B= ucfirst $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | } grep defined $request->{$_}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | qw(name multibroker_alias tool action action_description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | sandbox_implementation paths reason); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | push @details, map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $dim = $dimensions->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | "$dim->{label}: " . $json->encode ($dim->{value}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | } @dimensions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my @view_fields = detail_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my $message = $request->{_permission_selection}{message} // ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->{"_permission_selection"}{"message"} // ""
MC/DC0%0/1
$request->{"_permission_selection"}{"message"} // ""
$request->{"_permission_selection"}{"message"}
Truth table0%0/2
A
A= $request->{"_permission_selection"}{"message"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | my ($status, $output) = yad ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | "--form", ($unsandboxed ? "--title=UNSANDBOXED MCP permission required" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | : "--title=MCP permission required"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | "--width=650", "--height=400", "--scroll", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | "--text=" . ($unsandboxed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | ? "WARNING: NO SANDBOX. Workers run with all privileges of the host user.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | : "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | . "Required grants: " . (join " ", @{$request->{sandbox_grants}}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | "--separator=\x1f", "--item-separator=\x1f", "--num-output", "--always-print-result", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | "--focus-field=" . (@details + @view_fields / 2 + 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | "--buttons-layout=edge", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | "--button=Deny once:0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | ($persistent ? ("--button=Deny always...:6") : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | ($persistent ? ("--button=Allow always...:8") : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | "--button=Allow once:4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | (map { ("--field=$_:LBL", "") } @details), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | @view_fields, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | "--field=Denial reason (optional)", $message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | return unless defined $status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | return { decision => "deny-once" } unless grep $_ == $status, 0, 4, 6, 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $message = (split /\x1f/, $output, -1)[@details + @view_fields / 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | die "Missing permission message field\n" unless defined $message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $message =~ s/\r?\n\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | my $choice = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 => "deny-once", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 => "allow-once", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 6 => "deny-always", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 8 => "allow-always", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | }->{$status}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | if ($choice =~ /-always\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | return { decision => $choice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | ($choice eq "deny-always" && length $message ? (message => $message) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | } if ($request->{_permission_stage} || "") eq "choice"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/5
$request->{'_permission_stage'} || ''
$choice eq "deny-always" and length $message
MC/DC0%0/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
MC/DC0%0/2
$choice eq "deny-always" and length $message
$choice eq "deny-always"
length $message
Truth table0%0/2
A
A= $request->{'_permission_stage'}
Truth table0%0/3
A and B
A= $choice eq "deny-always"B= length $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my $answer = rule_dialog ($choice, $message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | next if $answer->{decision} eq "back"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | return $answer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | decision => $choice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | ($status == 0 && length $message ? (message => $message) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | ($status == 4 ? (sandbox_grants => [@{$request->{sandbox_grants}}]) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$status == 0 and length $message
MC/DC0%0/2
$status == 0 and length $message
$status == 0
length $message
Truth table0%0/3
A and B
A= $status == 0B= length $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | sub terminal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
terminal: not called CC=23 SCAR=63.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | open my $tty, "+<", "/dev/tty" or return { decision => "deny-once" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | binmode $tty, ":encoding(UTF-8)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | select ((select ($tty), $| = 1)[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | my $ask = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | print {$tty} $_[0] or die "Permission terminal: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my $answer = <$tty>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | $answer =~ s/\s+\z// if defined $answer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $answer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $message = $request->{_permission_selection}{message} // ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->{"_permission_selection"}{"message"} // ""
MC/DC0%0/1
$request->{"_permission_selection"}{"message"} // ""
$request->{"_permission_selection"}{"message"}
Truth table0%0/2
A
A= $request->{"_permission_selection"}{"message"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | my $rule = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=26 SCAR=65.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my ($choice) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | print {$tty} "Denial reason: ", (length $message ? $message : "(none)"), "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | if $choice eq "deny-always"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | return { decision => "back" } if (($ask->("Configure future rule [Enter=continue, b=back]: ") // "b") eq "b"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
&$ask("Configure future rule [Enter=continue, b=back]: ") // "b"
MC/DC0%0/1
&$ask("Configure future rule [Enter=continue, b=back]: ") // "b"
&$ask("Configure future rule [Enter=continue, b=back]: ")
Truth table0%0/2
A
A= &$ask("Configure future rule [Enter=continue, b=back]: ")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | my %answer = (decision => $choice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$choice eq "deny-always" and length $message
MC/DC0%0/2
$choice eq "deny-always" and length $message
$choice eq "deny-always"
length $message
Truth table0%0/3
A and B
A= $choice eq "deny-always"B= length $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | ($choice eq "deny-always" && length $message ? (message => $message) : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | if ($choice eq "allow-always") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | print {$tty} "Available grants: ", join (", ", @{$request->{sandbox_grant_choices}}), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my $caps = $ask->("Allowed grants [" . (join ",", @{$request->{sandbox_grants}}) . "]: "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | return { decision => "deny-once" } unless defined $caps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | $answer{sandbox_grants} = [length $caps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | ? ($caps eq "-" ? () : split /\s*,\s*/, $caps, -1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | : @{$request->{sandbox_grants}}]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | for my $name (@selectable_dimensions) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $dim = $dimensions->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | print {$tty} "$dim->{label} scope:\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | map { ($_ + 1) . ": " . $json->encode ($dim->{choices}[$_]{label}) . "\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | 0 .. $#{$dim->{choices}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | my $index = $ask->("$dim->{label} scope [1]: "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | return { decision => "deny-once" } unless defined $index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | $index = 1 unless length $index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | die "Invalid dimension scope\n" unless $index =~ /\A[1-9][0-9]*\z/ && $index <= @{$dim->{choices}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dim->{"choices"};}
MC/DC0%0/2
$index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dim->{"choices"};}
$index =~ /\A[1-9][0-9]*\z/u
$index <= @{$dim->{"choices"};}
Truth table0%0/3
A and B
A= $index =~ /\A[1-9][0-9]*\z/uB= $index <= @{$dim->{"choices"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $answer{"dim_$name"} = $dim->{choices}[$index - 1]{match}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | if ($choice eq "deny-always" && @deny_paths) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$choice eq "deny-always" and @deny_paths
MC/DC0%0/2
$choice eq "deny-always" and @deny_paths
$choice eq "deny-always"
@deny_paths
Truth table0%0/3
A and B
A= $choice eq "deny-always"B= @deny_paths
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | print {$tty} map { ($_ + 1) . ": " . $json->encode ($deny_paths[$_]) . "\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 .. $#deny_paths; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | print {$tty} (@deny_paths + 1) . ": All paths\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my $index = $ask->("Deny file scope [1]: "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | return { decision => "deny-once" } unless defined $index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | $index = 1 unless length $index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | die "Invalid deny file scope\n" unless $index =~ /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
MC/DC0%0/2
$index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
$index =~ /\A[1-9][0-9]*\z/u
$index <= @deny_paths + 1
Truth table0%0/3
A and B
A= $index =~ /\A[1-9][0-9]*\z/uB= $index <= @deny_paths + 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | && $index <= @deny_paths + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | $answer{path} = $deny_paths[$index - 1] if $index <= @deny_paths; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my $lifetime = $ask->("Rule lifetime [1=indefinite, 2=900 seconds, 3=16 hours; default 1]: "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | return { decision => "deny-once" } unless defined $lifetime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | $lifetime = 1 unless length $lifetime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | $lifetime =~ /\A[123]\z/ or die "Invalid rule lifetime\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $answer{lifetime} = ("indefinite", "900", "57600")[$lifetime - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | \%answer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | if (($request->{_permission_stage} || "") eq "rule") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$request->{'_permission_stage'} || ''
MC/DC0%0/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
Truth table0%0/2
A
A= $request->{'_permission_stage'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | return $rule->($request->{_permission_selection}{decision}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | print {$tty} "\n\n******** MCP PERMISSION REQUIRED ********\n\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | AnyEvent::MCP::Permissions::Ask::message ($request), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | "\n\nThis is an approval prompt. No decision has been made.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | print {$tty} "\nDenial reason: ", (length $message ? $message : "(none)"), "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | " m edit denial reason\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | " o allow once d deny once (default)\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | ($persistent ? " a allow always... n deny always...\n" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $choice = $ask->("Choice [d]: "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | return { decision => "deny-once" } unless defined $choice; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | $choice = "d" unless length $choice; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | if ($choice eq "m") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my $text = $ask->("Denial reason (Enter clears): "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | return { decision => "deny-once" } unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $message = $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | next unless exists $decisions{$choice}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | next if !$persistent && $choice =~ /[na]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $persistent and $choice =~ /[na]/u
MC/DC0%0/2
not $persistent and $choice =~ /[na]/u
not $persistent
$choice =~ /[na]/u
Truth table0%0/3
not(A) and B
A= not $persistentB= $choice =~ /[na]/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my $decision = $decisions{$choice}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | if ($decision =~ /-always\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | return { decision => $decision, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | ($decision eq "deny-always" && length $message ? (message => $message) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | } if ($request->{_permission_stage} || "") eq "choice"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/5
$request->{'_permission_stage'} || ''
$decision eq "deny-always" and length $message
MC/DC0%0/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
MC/DC0%0/2
$decision eq "deny-always" and length $message
$decision eq "deny-always"
length $message
Truth table0%0/2
A
A= $request->{'_permission_stage'}
Truth table0%0/3
A and B
A= $decision eq "deny-always"B= length $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my $answer = $rule->($decision); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | next if $answer->{decision} eq "back"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | return $answer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | decision => $decision, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | ($choice eq "d" && length $message ? (message => $message) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | ($choice eq "o" ? (sandbox_grants => [@{$request->{sandbox_grants}}]) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$choice eq "d" and length $message
MC/DC0%0/2
$choice eq "d" and length $message
$choice eq "d"
length $message
Truth table0%0/3
A and B
A= $choice eq "d"B= length $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my $decision = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | my $answer = $tty_only ? terminal : graphical; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | $answer = $yad_only ? { decision => "deny-once" } : terminal unless $answer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | AnyEvent::MCP::Permissions::Ask::build ($request, $answer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | $request->{_permission_stage}, $request->{_permission_selection}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | print STDERR "Permission prompt failed; denied: $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $decision = { decision => "deny-once" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | print JSON::XS::encode_json ($decision), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||