Handle hostnames with upper-case letters
[webmin.git] / file / irix-getfacl.pl
1 #!/usr/local/bin/perl
2 # irix-getfacl.pl
3 # Wrapper for the ls -D command
4
5 $esc = quotemeta($ARGV[0]);
6 $out = `ls -dDL $esc 2>&1`;
7 if ($?) {
8         print STDERR $out;
9         exit 1;
10         }
11 if ($out !~ /\[([^\]]*)\]/) {
12         print STDERR "Failed to parse ls -D output : $out\n";
13         exit 1;
14         }
15 if ($1) {
16         # Convert to normal ACL form
17         ($acl, $dacl) = split(/\//, $1);
18         foreach (split(/,/, $acl)) {
19                 s/^u:/user:/;
20                 s/^g:/group:/;
21                 s/^o:/other:/;
22                 s/^m:/mask:/;
23                 print $_,"\n";
24                 }
25         foreach (split(/,/, $dacl)) {
26                 s/^u:/user:/;
27                 s/^g:/group:/;
28                 s/^o:/other:/;
29                 s/^m:/mask:/;
30                 print "default:",$_,"\n";
31                 }
32         }
33 else {
34         # Make up ACL from perms
35         local @st = stat($ARGV[0]);
36         local $other = $st[2] & 7;
37         local $group = ($st[2] >> 3) & 7;
38         local $user = ($st[2] >> 6) & 7;
39         print "user::",&octal_to_perms($user),"\n";
40         print "group::",&octal_to_perms($group),"\n";
41         print "other::",&octal_to_perms($other),"\n";
42         print "mask::",&octal_to_perms($user | $group),"\n";
43         }
44
45 sub octal_to_perms
46 {
47 local $rv;
48 $rv .= ($_[0] & 4 ? "r" : "-");
49 $rv .= ($_[0] & 2 ? "w" : "-");
50 $rv .= ($_[0] & 1 ? "x" : "-");
51 return $rv;
52 }
53