| 1 | package SVN::Access; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use SVN::Access::Group; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use SVN::Access::Resource; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use open ':encoding(utf8)'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use 5.006001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||
| 15 | 9 | ▶ | my ($class, %attr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 9 | my $self = bless(\%attr, $class); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # it's important that we have this. | ||||||||||||||||||||||||||||
| 19 | 9 | ▶ | die "No ACL file specified!" unless $attr{acl_file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | if (-e $attr{acl_file}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | # parse the file in. | ||||||||||||||||||||||||||||
| 23 | 8 | $self->parse_acl; | |||||||||||||||||||||||||||
| 24 | } else { | ||||||||||||||||||||||||||||
| 25 | # empty acl. | ||||||||||||||||||||||||||||
| 26 | 1 | $attr{acl} = {}; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | 9 | return $self; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub parse_acl { | ||||||||||||||||||||||||||||
| 32 | 8 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_acl: called CC=17 SCAR=28.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 8 | ▶ | open(ACL, '<', $self->{acl_file}) or die "Can't open SVN Access file " . $self->{acl_file} . ": $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 8 | my $current_resource; | |||||||||||||||||||||||||||
| 35 | my $statement; | ||||||||||||||||||||||||||||
| 36 | 8 | ▶ | while (my $line = <ACL>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | # ignore comments (properly defined) | ||||||||||||||||||||||||||||
| 38 | 129 | ▶ | next if $line =~ /^#/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 125 | ▶ | $line =~ s/\s*#.*$// unless $self->{pedantic}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # get rid of trailing whitespace. | ||||||||||||||||||||||||||||
| 42 | 125 | $line =~ s/[\s\r\n]+$//; | |||||||||||||||||||||||||||
| 43 | 125 | ▶ | next unless $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # handle line continuations | ||||||||||||||||||||||||||||
| 46 | 94 | ▶ | if ($line =~ /^\s+(.+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 4 | $statement .= " $1"; | |||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 90 | $statement = $line; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # lookahead and see if the next line is a line continuation | ||||||||||||||||||||||||||||
| 53 | 94 | my $pos = tell(ACL); | |||||||||||||||||||||||||||
| 54 | 94 | my $nextline = <ACL>; | |||||||||||||||||||||||||||
| 55 | 94 | seek(ACL, $pos, 0); # rewind the filehandle to where we were. | |||||||||||||||||||||||||||
| 56 | 94 | ▶ | if ($nextline && $nextline =~ /^[ \t]+\S/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$nextline and $nextline =~ /^[ \t]+\S/
MC/DC100%2/2
$nextline and $nextline =~ /^[ \t]+\S/
$nextline
$nextline =~ /^[ \t]+\S/
Truth table100%3/3
A and B
A= $nextlineB= $nextline =~ /^[ \t]+\S/
| |||||||||||||||||||||||||||||
| 57 | 4 | next; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 90 | ▶ | next unless $statement; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 90 | ▶ | if ($statement =~ /^\[\s*(.+?)\s*\]$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | # this statement is defining a new resource. | ||||||||||||||||||||||||||||
| 64 | 31 | $current_resource = $1; | |||||||||||||||||||||||||||
| 65 | 31 | ▶ | unless ($current_resource =~ /^(?:groups|aliases)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 20 | $self->add_resource($current_resource); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||
| 69 | # both groups and resources need this parsed. | ||||||||||||||||||||||||||||
| 70 | 59 | my ($k, $v) = $statement =~ /^(.+?)\s*=\s*(.*?)$/; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # if the previous split didn't work, there's a syntax error | ||||||||||||||||||||||||||||
| 73 | 59 | ▶ | unless ($k) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 2 | warn "Unrecognized line $statement\n"; | |||||||||||||||||||||||||||
| 75 | 2 | next; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 57 | ▶ | if ($current_resource eq "groups") { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 79 | # this is a group | ||||||||||||||||||||||||||||
| 80 | 17 | $self->add_group($k, split(/\s*,\s*/, $v)); | |||||||||||||||||||||||||||
| 81 | } elsif ($current_resource eq "aliases") { | ||||||||||||||||||||||||||||
| 82 | # aliases are simple k=v, so let's just store them in ourselves. | ||||||||||||||||||||||||||||
| 83 | 4 | $self->add_alias($k, $v); | |||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||
| 85 | # this is a generic resource | ||||||||||||||||||||||||||||
| 86 | 36 | ▶ | if (my $resource = $self->resource($current_resource)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 36 | $resource->authorize($k => $v); | |||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 0 | $self->add_resource($current_resource, $k, $v); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 88 | $statement = undef; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # make sure this isn't empty. | ||||||||||||||||||||||||||||
| 98 | 8 | ▶ | unless (ref($self->{acl}->{aliases}) eq "HASH") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 4 | $self->{acl}->{aliases} = {}; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 8 | close (ACL); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub verify_acl { | ||||||||||||||||||||||||||||
| 106 | 6 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
verify_acl: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Check for references to undefined groups (Thanks Jesse!) | ||||||||||||||||||||||||||||
| 109 | 6 | my (%groups, @errors); | |||||||||||||||||||||||||||
| 110 | 6 | ▶ | if ($self->groups) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 3 | foreach my $group ($self->groups) { | |||||||||||||||||||||||||||
| 112 | 3 | $groups{$group->name}++; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 6 | foreach my $resource ($self->resources) { | |||||||||||||||||||||||||||
| 117 | 20 | ▶ | if (defined($resource) && $resource->authorized) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $resource and $resource->authorized
MC/DC50%1/2
defined $resource and $resource->authorized
defined $resource
$resource->authorized
Truth table66%2/3
A and B
A= defined $resourceB= $resource->authorized
| |||||||||||||||||||||||||||||
| 118 | 19 | foreach my $k (keys %{$resource->authorized}) { | |||||||||||||||||||||||||||
| 119 | 35 | ▶ | if ( $k =~ /^@(.*)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 5 | ▶ | unless ( $groups{$1} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 2 | push(@errors, "[error] An authz rule (" . $resource->name . ") refers to group '\@$1', which is undefined"); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 6 | ▶ | return scalar(@errors) ? join("\n", @errors) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub write_acl { | ||||||||||||||||||||||||||||
| 132 | 6 | ▶ | my ($self, $out) = @_; | ||||||||||||||||||||||||||
|
Subroutine
write_acl: called CC=14 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # verify the ACL has no errors before writing it out | ||||||||||||||||||||||||||||
| 135 | 6 | ▶ | if (my $error = $self->verify_acl) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | die "Error found in ACL:\n$error\n"; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 5 | ▶ | if (ref \$out eq "GLOB" or ref $out) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref \$out eq "GLOB" or ref $out
MC/DC0%0/2
ref \$out eq "GLOB" or ref $out
ref \$out eq "GLOB"
ref $out
Truth table33%1/3
A or B
A= ref \$out eq "GLOB"B= ref $out
| |||||||||||||||||||||||||||||
| 140 | 0 | *ACL = $out; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||
| 143 | 5 | ▶ | $out = $self->{acl_file} unless $out; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 5 | ▶ | open (ACL, '>', $out) or warn "Can't open ACL file " . $out . " for writing: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # aliases now supported! | ||||||||||||||||||||||||||||
| 148 | 5 | ▶ | if (scalar(keys %{$self->aliases})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 2 | print ACL "[aliases]\n"; | |||||||||||||||||||||||||||
| 150 | 2 | foreach my $alias (keys %{$self->aliases}) { | |||||||||||||||||||||||||||
| 151 | 2 | print ACL $alias . " = " . $self->aliases->{$alias} . "\n"; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 2 | print ACL "\n"; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # groups now second to aliases | ||||||||||||||||||||||||||||
| 157 | 5 | ▶ | if ($self->groups) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 3 | print ACL "[groups]\n"; | |||||||||||||||||||||||||||
| 159 | 3 | foreach my $group ($self->groups) { | |||||||||||||||||||||||||||
| 160 | 3 | print ACL $group->name . " = " . join(', ', $group->members) . "\n"; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | 3 | print ACL "\n"; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 5 | foreach my $resource ($self->resources) { | |||||||||||||||||||||||||||
| 166 | 14 | ▶ | if (defined($resource) && $resource->authorized) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $resource and $resource->authorized
MC/DC50%1/2
defined $resource and $resource->authorized
defined $resource
$resource->authorized
Truth table66%2/3
A and B
A= defined $resourceB= $resource->authorized
| |||||||||||||||||||||||||||||
| 167 | 13 | print ACL "[" . $resource->name . "]\n"; | |||||||||||||||||||||||||||
| 168 | 13 | ▶ | while (my ($k, $v) = (each %{$resource->authorized})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 23 | print ACL "$k = $v\n"; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 13 | print ACL "\n"; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 5 | close(ACL); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | sub write_pretty { | ||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
write_pretty: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # verify the ACL has no errors before writing it out | ||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (my $error = $self->verify_acl) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | die "Error found in ACL:\n$error\n"; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | my $max_len = 0; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # Compile a list of names that will appear on the left side | ||||||||||||||||||||||||||||
| 189 | 0 | my @names; | |||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (scalar(keys %{$self->aliases})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 0 | foreach my $alias (keys %{$self->aliases}) { | |||||||||||||||||||||||||||
| 192 | 0 | push(@names, $alias); | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($self->groups) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | for ($self->groups) { | |||||||||||||||||||||||||||
| 198 | 0 | push(@names, $_->name); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ($self->resources) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | for ($self->resources) { | |||||||||||||||||||||||||||
| 203 | 0 | push(@names, keys(%{$_->authorized})); | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | # Go through that list looking for the longest name | ||||||||||||||||||||||||||||
| 208 | 0 | for (@names) { | |||||||||||||||||||||||||||
| 209 | 0 | ▶ | $max_len = length($_) >= $max_len ? length($_) : $max_len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | open (ACL, '>', $self->{acl_file}) or warn "Can't open ACL file " . $self->{acl_file} . " for writing: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # aliases now fully supported! | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if (scalar(keys %{$self->aliases})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | print ACL "[aliases]\n"; | |||||||||||||||||||||||||||
| 217 | 0 | foreach my $alias (keys %{$self->aliases}) { | |||||||||||||||||||||||||||
| 218 | 0 | print ACL $alias . " " x ($max_len - length($alias)) . " = " . $self->aliases->{$alias} . "\n"; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # groups now second? | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($self->groups) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | print ACL "[groups]\n"; | |||||||||||||||||||||||||||
| 226 | 0 | foreach my $group ($self->groups) { | |||||||||||||||||||||||||||
| 227 | 0 | print ACL $group->name . " " x ($max_len - length($group->name)) . " = " . join(', ', $group->members) . "\n"; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | foreach my $resource ($self->resources) { | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | if (defined($resource) && $resource->authorized) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $resource and $resource->authorized
MC/DC0%0/2
defined $resource and $resource->authorized
defined $resource
$resource->authorized
Truth table0%0/3
A and B
A= defined $resourceB= $resource->authorized
| |||||||||||||||||||||||||||||
| 234 | 0 | print ACL "[" . $resource->name . "]\n"; | |||||||||||||||||||||||||||
| 235 | 0 | ▶ | while (my ($k, $v) = (each %{$resource->authorized})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | print ACL "$k" . " " x ($max_len - length($k)) . " = $v\n"; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | 0 | print ACL "\n"; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | 0 | close(ACL); | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | sub add_alias { | ||||||||||||||||||||||||||||
| 245 | 6 | ▶ | my ($self, $alias_name, $aliased) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 246 | 6 | $self->{acl}->{aliases}->{$alias_name} = $aliased; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | sub remove_alias { | ||||||||||||||||||||||||||||
| 250 | 2 | ▶ | my ($self, $alias_name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
remove_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 251 | 2 | delete $self->{acl}->{aliases}->{$alias_name}; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | sub alias { | ||||||||||||||||||||||||||||
| 255 | 4 | ▶ | my ($self, $alias_name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
alias: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 256 | 4 | ▶ | if (exists ($self->{acl}->{aliases}->{$alias_name})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 3 | return $self->{acl}->{aliases}->{$alias_name}; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | 1 | return undef; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | sub aliases { | ||||||||||||||||||||||||||||
| 263 | 10 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
aliases: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 264 | # give em something if we got nothing! | ||||||||||||||||||||||||||||
| 265 | 10 | ▶ | unless (ref($self->{acl}->{aliases}) eq "HASH") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 1 | $self->{acl}->{aliases} = {}; | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | 10 | return $self->{acl}->{aliases}; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub add_resource { | ||||||||||||||||||||||||||||
| 272 | 28 | ▶ | my ($self, $resource_name, @access) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add_resource: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 273 | 28 | ▶ | if ($resource_name eq "name") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 1 | $resource_name = shift(@access); | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 28 | ▶ | if ($self->resource($resource_name)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 278 | 0 | die "Can't add new resource $resource_name: resource already exists!\n"; | |||||||||||||||||||||||||||
| 279 | } elsif ($resource_name !~ /^(?:\S+\:)?\/.*$/) { # Thanks Matt | ||||||||||||||||||||||||||||
| 280 | 0 | die "Invalid resource format in $resource_name! (format 'repo:/path')!\n"; | |||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||
| 282 | 28 | my $resource = SVN::Access::Resource->new( | |||||||||||||||||||||||||||
| 283 | name => $resource_name, | ||||||||||||||||||||||||||||
| 284 | authorized => \@access, | ||||||||||||||||||||||||||||
| 285 | ); | ||||||||||||||||||||||||||||
| 286 | 28 | push(@{$self->{acl}->{resources}}, $resource); | |||||||||||||||||||||||||||
| 287 | 28 | return $resource; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | sub remove_resource { | ||||||||||||||||||||||||||||
| 292 | 8 | ▶ | my ($self, $resource_name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
remove_resource: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 293 | 8 | my @resources; | |||||||||||||||||||||||||||
| 294 | 8 | foreach my $resource ($self->resources) { | |||||||||||||||||||||||||||
| 295 | 33 | ▶ | push(@resources, $resource) unless $resource->name eq $resource_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | 8 | ▶ | $self->{acl}->{resources} = scalar(@resources) ? \@resources : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | sub resources { | ||||||||||||||||||||||||||||
| 301 | 91 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
resources: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 302 | 91 | ▶ | if (ref($self->{acl}->{resources}) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | 79 | return (@{$self->{acl}->{resources}}); | |||||||||||||||||||||||||||
| 304 | } else { | ||||||||||||||||||||||||||||
| 305 | 12 | return (undef); | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | sub resource { | ||||||||||||||||||||||||||||
| 310 | 71 | ▶ | my ($self, $resource_name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
resource: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 311 | 71 | foreach my $resource ($self->resources) { | |||||||||||||||||||||||||||
| 312 | 197 | ▶ | return $resource if defined($resource) && $resource->name eq $resource_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $resource and $resource->name eq $resource_name
MC/DC100%2/2
defined $resource and $resource->name eq $resource_name
defined $resource
$resource->name eq $resource_name
Truth table100%3/3
A and B
A= defined $resourceB= $resource->name eq $resource_name
| |||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | 28 | return undef; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | sub add_group { | ||||||||||||||||||||||||||||
| 318 | 18 | ▶ | my ($self, $group_name, @initial_members) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add_group: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # get rid of the @ symbol. | ||||||||||||||||||||||||||||
| 321 | 18 | ▶ | $group_name =~ s/\@//g unless $self->{pedantic}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 18 | ▶ | if ($self->group($group_name)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | 0 | die "Can't add new group $group_name: group already exists!\n"; | |||||||||||||||||||||||||||
| 325 | } else { | ||||||||||||||||||||||||||||
| 326 | 18 | my $group = SVN::Access::Group->new( | |||||||||||||||||||||||||||
| 327 | name => $group_name, | ||||||||||||||||||||||||||||
| 328 | members => \@initial_members, | ||||||||||||||||||||||||||||
| 329 | ); | ||||||||||||||||||||||||||||
| 330 | 18 | push(@{$self->{acl}->{groups}}, $group); | |||||||||||||||||||||||||||
| 331 | 18 | return $group; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | sub remove_group { | ||||||||||||||||||||||||||||
| 336 | 1 | ▶ | my ($self, $group_name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
remove_group: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 337 | 1 | my @groups; | |||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | # get rid of the @ symbol. | ||||||||||||||||||||||||||||
| 340 | 1 | $group_name =~ s/\@//g; | |||||||||||||||||||||||||||
| 341 | 1 | foreach my $group ($self->groups) { | |||||||||||||||||||||||||||
| 342 | 1 | ▶ | push(@groups, $group) unless $group->name eq $group_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 1 | ▶ | $self->{acl}->{groups} = scalar(@groups) ? \@groups : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | sub groups { | ||||||||||||||||||||||||||||
| 349 | 55 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
groups: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 350 | 55 | ▶ | if (ref($self->{acl}->{groups}) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 41 | return (@{$self->{acl}->{groups}}); | |||||||||||||||||||||||||||
| 352 | } else { | ||||||||||||||||||||||||||||
| 353 | 14 | return (undef); | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | sub group { | ||||||||||||||||||||||||||||
| 358 | 36 | ▶ | my ($self, $group_name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
group: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 359 | 36 | foreach my $group ($self->groups) { | |||||||||||||||||||||||||||
| 360 | 71 | ▶ | return $group if defined($group) && $group->name eq $group_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $group and $group->name eq $group_name
MC/DC100%2/2
defined $group and $group->name eq $group_name
defined $group
$group->name eq $group_name
Truth table100%3/3
A and B
A= defined $groupB= $group->name eq $group_name
| |||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | 18 | return undef; | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | sub resolve { | ||||||||||||||||||||||||||||
| 366 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 367 | 8 | my @res; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 8 | foreach my $e (@_) { | |||||||||||||||||||||||||||
| 370 | 8 | ▶ | if ($e =~ /^\@(.+)/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 371 | 4 | ▶ | push @res, map $self->resolve($_), $self->group($1)->members() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | if $self->group($1); | ||||||||||||||||||||||||||||
| 373 | } elsif ($e =~ /^\&(.+)/) { | ||||||||||||||||||||||||||||
| 374 | 1 | ▶ | push @res, map $self->resolve($_), $self->alias($1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | if $self->alias($1); | ||||||||||||||||||||||||||||
| 376 | } else { | ||||||||||||||||||||||||||||
| 377 | 3 | push @res, $e; | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 8 | return @res; | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 1 | 1; | |||||||||||||||||||||||||||
| 385 | __END__ | ||||||||||||||||||||||||||||