118
print STDERR "-Info- $_[0]\n" if $debug;
119
}
120
121
-sub parse_config ($$) {
122
- my ($data, $fn) = @_;
123
- info "Loading $fn";
124
- open(I,'-|','git',"--git-dir=$acl_git",'cat-file','blob',$fn);
121
+sub git_value (@) {
122
+ open(T,'-|','git',@_); local $_ = <T>; chop; close T; $_;
123
+}
124
+
125
+sub parse_config ($$$$) {
126
+ my $data = shift;
127
+ local $ENV{GIT_DIR} = shift;
128
+ my $br = shift;
129
+ my $fn = shift;
130
+ info "Loading $br:$fn";
131
+ open(I,'-|','git','cat-file','blob',"$br:$fn");
132
my $section = '';
133
while (<I>) {
134
chomp;
135
if (/^\s*$/ || /^\s*#/) {
136
} elsif (/^\[([a-z]+)\]$/i) {
130
- $section = $1;
137
+ $section = lc $1;
138
} elsif (/^\[([a-z]+)\s+"(.*)"\]$/i) {
132
- $section = "$1.$2";
139
+ $section = join('.',lc $1,$2);
140
} elsif (/^\s*([a-z][a-z0-9]+)\s*=\s*(.*?)\s*$/i) {
134
- push @{$data->{"$section.$1"}}, $2;
141
+ push @{$data->{join('.',$section,lc $1)}}, $2;
142
} else {
136
- deny "bad config file line $. in $fn";
143
+ deny "bad config file line $. in $br:$fn";
144
}
145
}
146
close I;
209
}
210
}
211
205
-sub git_value (@) {
206
- open(T,'-|','git',@_); local $_ = <T>; chop; close T;
207
- $_;
208
-}
209
-
212
deny "No GIT_DIR inherited from caller" unless $git_dir;
213
deny "Need a ref name" unless $ref;
214
deny "Refusing funny ref $ref" unless $ref =~ s,^refs/,,;
233
&& $ref =~ m,^heads/,
234
&& $old eq git_value('merge-base',$old,$new));
235
234
-# Load the user's ACL file.
236
+# Load the user's ACL file. Expand groups (user.memberof) one level.
237
{
238
my %data = ('user.committer' => []);
237
- parse_config(\%data, "$acl_branch:users/$this_user.acl");
239
+ parse_config(\%data,$acl_git,$acl_branch,"external/$repository_name.acl");
240
+
241
+ %data = (
242
+ 'user.committer' => $data{'user.committer'},
243
+ 'user.memberof' => [],
244
+ );
245
+ parse_config(\%data,$acl_git,$acl_branch,"users/$this_user.acl");
246
+
247
%user_committer = map {$_ => $_} @{$data{'user.committer'}};
239
- my $rules = $data{"repository.$repository_name.allow"} || [];
248
+ my $rule_key = "repository.$repository_name.allow";
249
+ my $rules = $data{$rule_key} || [];
250
+
251
+ foreach my $group (@{$data{'user.memberof'}}) {
252
+ my %g;
253
+ parse_config(\%g,$acl_git,$acl_branch,"groups/$group.acl");
254
+ my $group_rules = $g{$rule_key};
255
+ push @$rules, @$group_rules if $group_rules;
256
+ }
257
+
258
+RULE:
259
foreach (@$rules) {
260
+ while (/\${user\.([a-z][a-zA-Z0-9]+)}/) {
261
+ my $k = lc $1;
262
+ my $v = $data{"user.$k"};
263
+ next RULE unless defined $v;
264
+ next RULE if @$v != 1;
265
+ next RULE unless defined $v->[0];
266
+ s/\${user\.$k}/$v->[0]/g;
267
+ }
268
+
269
if (/^([CDRU ]+)\s+for\s+([^\s]+)$/) {
270
my $ops = $1;
271
my $ref = $2;