use ExtUtils::MakeMaker;
WriteMakefile(
- NAME => 'Apache2::AuthzCaps',
- VERSION_FROM => 'lib/Apache2/AuthzCaps.pm',
- ABSTRACT_FROM => 'lib/Apache2/AuthzCaps.pm',
- AUTHOR => 'Marius Gavrilescu <marius@ieval.ro>',
- MIN_PERL_VERSION => '5.14.0',
- LICENSE => 'perl',
- SIGN => 1,
- PREREQ_PM => {
- qw/YAML::Any 0/,
- },
- META_MERGE => {
- dynamic_config => 0,
- recommends => {
- qw/Apache2::Access 0
- Apache2::Const 0
- Apache2::RequestRec 0/,
- }
- }
+ NAME => 'Apache2::AuthzCaps',
+ VERSION_FROM => 'lib/Apache2/AuthzCaps.pm',
+ ABSTRACT_FROM => 'lib/Apache2/AuthzCaps.pm',
+ AUTHOR => 'Marius Gavrilescu <marius@ieval.ro>',
+ MIN_PERL_VERSION => '5.14.0',
+ LICENSE => 'perl',
+ SIGN => 1,
+ PREREQ_PM => {
+ qw/YAML::Any 0/,
+ },
+ META_MERGE => {
+ dynamic_config => 0,
+ recommends => {
+ qw/Apache2::Access 0
+ Apache2::Const 0
+ Apache2::RequestRec 0/,
+ }
+ }
);
our $rootdir;
sub setcap{
- my ($user, $cap, $value) = @_;
- my $config = eval { LoadFile "$rootdir/$user.yml" } // {};
- $config->{caps}//={};
- my $caps=$config->{caps};
-
- delete $caps->{$cap} unless $value;
- $caps->{$cap} = 1 if $value;
- DumpFile "$rootdir/$user.yml", $config
+ my ($user, $cap, $value) = @_;
+ my $config = eval { LoadFile "$rootdir/$user.yml" } // {};
+ $config->{caps}//={};
+ my $caps=$config->{caps};
+
+ delete $caps->{$cap} unless $value;
+ $caps->{$cap} = 1 if $value;
+ DumpFile "$rootdir/$user.yml", $config
}
sub hascaps{
- my ($user, @caps) = @_;
- my $config = LoadFile "$rootdir/$user.yml";
- my $caps = $config->{caps};
- for (@caps) {
- return 0 unless $caps->{$_}
- }
- 1
+ my ($user, @caps) = @_;
+ my $config = LoadFile "$rootdir/$user.yml";
+ my $caps = $config->{caps};
+ for (@caps) {
+ return 0 unless $caps->{$_}
+ }
+ 1
}
sub handler{
- my $r=shift;
- my $user = $r->user;
- local $rootdir = $r->dir_config('AuthzCapsRootdir');
+ my $r=shift;
+ my $user = $r->user;
+ local $rootdir = $r->dir_config('AuthzCapsRootdir');
- if ($user) {
- LOOP: for my $requirement (map { $_->{requirement} } @{$r->requires}) {
- my ($command, @args) = split ' ', $requirement;
+ if ($user) {
+ LOOP: for my $requirement (map { $_->{requirement} } @{$r->requires}) {
+ my ($command, @args) = split ' ', $requirement;
- given ($command){
- when('cap'){
- return OK if hascaps $user, @args
- }
+ given ($command){
+ when('cap'){
+ return OK if hascaps $user, @args
+ }
- }
+ }
+ }
}
- }
- DECLINED
+ DECLINED
}
1;
$Apache2::AuthzCaps::rootdir = tempdir CLEANUP => 1;
sub checkcaps{
- my ($user, $testname, @caps) = @_;
- ok hascaps ($user, @caps), $testname
+ my ($user, $testname, @caps) = @_;
+ ok hascaps ($user, @caps), $testname
}
sub checknocaps{
- my ($user, $testname, @caps) = @_;
- ok !(hascaps $user, @caps), $testname
+ my ($user, $testname, @caps) = @_;
+ ok !(hascaps $user, @caps), $testname
}
setcap marius => dostuff => 1;