Apache-AuthzUnix
view release on metacpan or search on metacpan
lib/Apache/AuthzUnix.pm view on Meta::CPAN
if (!-e $r->filename) { $fn = dirname($fn) }
# Why did we just do that? Because:
# If we're PUTting a file, we want to check if we can write to the directory.
# Otherwise, we're GETting a non-existent or autogenerated file (ie autoindex)
# If it's a directory index, then we use the permissions of the directory.
# If it's non-existent, permissions are an irrelevance!
my $stat = File::stat::stat($fn);
my $access =
_access($user, $stat->mode, $stat->uid, $stat->gid, $r->method);
warn "Access to file: "
. $r->filename
. " (resolved as $fn) : "
. ($access ? "allowed" : "denied")
if $DEBUG;
return $access ? OK() : DECLINED();
}
sub _access {
my ($username, $perms, $uid, $gid, $method) = @_;
my ($u, $g, $o) = ($perms & 0700, $perms & 0070, $perms & 0007);
my $user = getpwnam($username);
my %in_group = map { $_ => 1 } @{ getgrgid($gid)->members };
my $bit = $method =~ /(PUT|DELETE)/ ? 2 : 4;
return 1 if $o & $bit
|| ($uid == $user->uid and $u & ($bit << 6))
|| (($gid == $user->gid or $in_group{$username})
and $g & ($bit << 3));
return 0;
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
( run in 3.153 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )