From ba7a48a2b88b33c6c49511fd4422d255264fac98 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 25 Apr 2014 13:07:46 +0300 Subject: Change default rule to "deny". The old behavior can be restored by setting 'hooks.acldefault = allow' in Git configuration. * gitaclhook: Document hooks.acldefault. * lib/GitACL.pm (default_rule): New sub. * lib/GitACL/File.pm (check_acl): Use default_rule. Fix incorrect reference to project_name. * lib/GitACL/LDAP.pm (check_acl): Use default_rule. --- lib/GitACL.pm | 15 ++++++++++++++- lib/GitACL/File.pm | 6 +++--- lib/GitACL/LDAP.pm | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/GitACL.pm b/lib/GitACL.pm index f1f792a..9cd381d 100644 --- a/lib/GitACL.pm +++ b/lib/GitACL.pm @@ -71,6 +71,20 @@ sub allow($$) { exit 0; } +sub default_rule($) { + my $self = shift; + my $def = GitACL::git_value('config', 'hooks.acldefault'); + my $msg = "default rule"; + if (defined($def)) { + if ($def eq "allow") { + $self->allow($msg); + } elsif ($def ne "deny") { + $msg .= " (warning: hooks.acldefault has invalid value)"; + } + } + $self->deny($msg); +} + sub info($$) { my ($self, $msg) = @_; $self->logmsg("INFO", $msg); @@ -209,7 +223,6 @@ sub new { } $obj->{project_name} = get_project_name($obj->{git_dir}); - $obj->deny("need a ref name") unless defined($args{ref}); $obj->deny("bogus ref $args{ref}") unless $args{ref} =~ s,^refs/,,; $obj->{ref} = $args{ref}; diff --git a/lib/GitACL/File.pm b/lib/GitACL/File.pm index 8842ffd..efabfd4 100644 --- a/lib/GitACL/File.pm +++ b/lib/GitACL/File.pm @@ -1,5 +1,5 @@ # This file is part of gitaclhook -*- perl -*- -# Copyright (C) 2013 Sergey Poznyakoff +# Copyright (C) 2013, 2014 Sergey Poznyakoff # # Gitaclhook is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ sub check_acl { my @ret; my $filename = GitACL::git_value('config', 'hooks.aclfile'); - $self->allow("no ACL configured for ".$self->project_name) + $self->allow("no ACL configured for ".$self->{project_name}) unless defined($filename); open($fd, "<", $filename) @@ -52,7 +52,7 @@ sub check_acl { exit(127); } close($fd); - $self->allow("default rule"); + $self->default_rule; } 1; diff --git a/lib/GitACL/LDAP.pm b/lib/GitACL/LDAP.pm index d8d5489..22bfd8d 100644 --- a/lib/GitACL/LDAP.pm +++ b/lib/GitACL/LDAP.pm @@ -1,5 +1,5 @@ # This file is part of gitaclhook -*- perl -*- -# Copyright (C) 2013 Sergey Poznyakoff +# Copyright (C) 2013, 2014 Sergey Poznyakoff # # Gitaclhook is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -108,7 +108,7 @@ sub check_acl($) { exit(127); } $ldap->unbind; - $self->allow("default rule"); + $self->default_rule; } 1; -- cgit v1.2.1