[ACL-Devel] Gacl
Andreas Gruenbacher
a.gruenbacher@bestbits.at
Sun, 02 Apr 2000 22:58:16 +0200
This is a multi-part message in MIME format.
--------------9D577016172AAB96909EC539
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Dear Peter,
Just as an experiment I have hacked together a short script that displays ACLs
in a table-like fashion, similar to what we were talking about a while ago. It's
actually a wrapper around getfacl.
Maybe that helps you find a better layout for Gacl. Maybe somebody even suggests
a better format---who knows :-)
Feel free to use the script as you like.
Here's some sample output:
> $ getfacl d
> # file: d
> # owner: ag
> # group: users
> user::rw-
> user:lisa:r--
> user:franz:rwx #effective:r-x
> group::r-x
> mask:r-x
> other:---
> default:user::rw-
> default:user:joe:---
> default:user:franz:rwx #effective:r-x
> default:group::r-x
> default:mask:r-x
> default:other:---
>
> $ showacl d
> # file: d
> USER ag rw- rw-
> user lisa r--
> user franz rWx rWx
> user joe ---
> GROUP users r-x r-x
> mask r-x r-x
> other --- ---
>
What I dislike is that capitalization is used in column 1 for emphasizing, and
in columns 3, 4 for de-emphasizing. Colors might be a better choice. Otherwise I
think this alternative format adds some clarity, especially since my experience
so far is that ACLs and default ACLs are very often mostly identical. Another
disadvantage of course is that this format is more difficult to parse, so I
don't think it's appropriate for use in scripts.
Cheers,
Andreas
------------------------------------------------------------------------
Andreas Gruenbacher, a.gruenbacher@computer.org
Contact information: http://www.bestbits.at/~ag/
--------------9D577016172AAB96909EC539
Content-Type: text/plain; charset=us-ascii;
name="showacl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="showacl"
#!/usr/bin/perl -w
use FileHandle;
use strict;
#print "getfacl " . join (" ", map { s/(\s)/\\$1/g; $_; } @ARGV) . " |\n";
my $pipe = new FileHandle("getfacl " . join (" ", map { s/\s/\\$&/g; $_; } @ARGV) . " |")
or die ($? >> 8);
file: while (1) {
my ($file, $owner, $owning_group);
my $user = [];
my $group = [];
my $mask = [];
my $other = [];
while (my $line = <$pipe>) {
chomp $line;
if ($line =~ /^# (\w+): (.+)$/) {
$file = $2
if ($1 eq 'file');
$owner = $2
if ($1 eq 'owner');
$owning_group = $2
if ($1 eq 'group');
next;
}
$line =~ s/\s+#effective.*$//;
if ($line) {
my $fields = [ split /:/, $line ];
if ($fields->[0] eq 'user') {
$fields->[0] = 'USER'
if $fields->[1] eq '';
push @$user, $fields;
} elsif ($fields->[0] eq 'group') {
$fields->[0] = 'GROUP'
if $fields->[1] eq '';
push @$group, $fields;
} elsif ($fields->[0] eq 'mask') {
$mask = [ $fields->[0], '', $fields->[1] ];
} elsif ($fields->[0] eq 'other') {
$other = [ $fields->[0], '', $fields->[1] ];
#$other = [ 'OTHER', '', $fields->[1] ];
} elsif ($fields->[0] eq 'default') {
shift @$fields;
if ($fields->[0] eq 'user') {
add_default($user, $fields);
} elsif ($fields->[0] eq 'group') {
add_default($group, $fields);
} elsif ($fields->[0] eq 'mask') {
push @$mask, $fields->[1];
} elsif ($fields->[0] eq 'other') {
push @$other, $fields->[1];
}
}
} else {
$user->[0][1] = $owner;
$group->[0][1] = $owning_group;
for (my $i = 1; $i < @$user; $i++) {
$user->[$i][2] =
mask_perm($user->[$i][2], $mask->[2]);
$user->[$i][3] =
mask_perm($user->[$i][3], $mask->[3])
if $user->[$i][3];
}
for (my $i = 1; $i < @$group; $i++) {
$group->[$i][2] =
mask_perm($group->[$i][2], $mask->[2]);
$group->[$i][3] =
mask_perm($group->[$i][3], $mask->[3])
if $group->[$i][3];
}
my $table = [ @$user, @$group, $mask, $other ];
print "# file: $file\n";
print_table($table, [5, 8, 3, 3]);
print "\n";
next file;
}
}
last;
}
close $pipe;
sub add_default {
my ($list, $fields) = @_;
for (my $i = 0; $i < @$list; $i++) {
if ($list->[$i][1] eq $fields->[1]) {
push @{$list->[$i]}, $fields->[2];
return;
}
}
push @$list, [ $fields->[0], $fields->[1], '', $fields->[2] ];
}
sub print_table {
my ($table, $width) = @_;
#my $width = [ map { 0 } @{$table->[0]} ];
for (my $i = 0; $i < @$table; $i++) {
my $row = $table->[$i];
for (my $j = 0; $j < @$row; $j++) {
$width->[$j] = length $row->[$j]
unless ($width->[$j] &&
$width->[$j] > length $row->[$j]);
}
}
my $fstr = '';
for (my $j = 0; $j < @$width; $j++) {
$fstr .= "%-" . $width->[$j] . "s";
if ($j + 1 < @$width) {
$fstr .= " ";
} else {
$fstr .= "\n";
}
}
for (my $i = 0; $i < @$table; $i++) {
print sprintf $fstr, @{$table->[$i]};
}
}
sub mask_perm {
my ($perm, $mask) = @_;
my @p = split //, $perm;
my @m = split //, $mask;
for (my $i = 0; $i < @p; $i++) {
if ($p[$i] ne $m[$i]) {
$p[$i] = uc $p[$i];
}
}
return join '', @p;
}
--------------9D577016172AAB96909EC539--
-------------------------------------------------------------------------
Linux ACL Developers List --- http://acl.bestbits.at/acl-devel/
To unsubscribe, send a message with `unsubscribe acl-devel'
in the message body to majordomo@bestbits.at.
-------------------------------------------------------------------------