Example: perms
#! /usr/bin/perl -w
#
# perms - complain about files that students can inappropriately read.
#
# We take the "all is forbidden unless permitted" approach.
# Complain about any publically readable or writable file unless
# it's in a directory with a ".public" flag file.
use strict;
use File::Find;
find {wanted => \&wanted, no_chdir => 1},
glob("~applin"),
glob("~cs155"),
glob("~cs156"),
glob("~cs157"),
glob("~cs253");
sub wanted {
my @statbuf = stat($_);
my $mode = $statbuf[2] || 0;
my $r = $mode & 044;
my $w = $mode & 022;
my $x = $mode & 011;
if (-d) {
$File::Find::prune = 1 # Give up on this directory
unless -r && -x; # if we can't search it.
$File::Find::prune = 1 # Give up on this directory
unless $r && $x; # if nobody can search it.
$File::Find::prune = 1 # We don't care about this dir
if -e "$_/.public"; # if it's marked as public.
return;
}
return if m!/\.[^/]+$!; # We don't care about .files
ls($_) # Show permissions and filename
if $r || $w; # if publically accessible
}
# Emulate the ls -l command
sub ls {
my ($file) = @_;
my $cmdout = `/bin/ls -l "$file"`; # for the -rwxr-xr-x part
printf "%.10s %s\n", $cmdout, $file; # Show permissions and filename
}