X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApache2%2FAuthzCaps.pm;h=281d3d6f6e3b63eaa9874172ea00f5030901bbc5;hb=59f2225d192cda0f843a9d5f99892e60b5a95341;hp=426b6081278e5597c4b3ef0aa4edfca03a17d31a;hpb=2096e2673d405afc7b394e3a09487a19e7bd3788;p=apache2-authzcaps.git diff --git a/lib/Apache2/AuthzCaps.pm b/lib/Apache2/AuthzCaps.pm index 426b608..281d3d6 100644 --- a/lib/Apache2/AuthzCaps.pm +++ b/lib/Apache2/AuthzCaps.pm @@ -21,45 +21,45 @@ our @EXPORT_OK = qw/setcap hascaps/; 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;