#!/usr/local/bin/perl -w use strict; # Grab a list of directories in /home. my (@users) = ; foreach (@users) { $_ =~ s/\/home\/(.*)$/$1/; } # Print a header. print STDERR "\n Generating report (this may take a while)...\n\n"; printf " %-60s %5s %s\n", 'Offending file', 'UID', 'User owned by'; print "-"x86 . "\n"; # Run through each directory (/home/$usr), checking that all files are # owned by the correct owner ($usr). foreach my $usr (@users) { my @files = ; foreach my $fil (@files) { if ((-d $fil) && !(-l $fil)) { push @files, <$fil/*>; } my $fuid = (stat($fil))[4]; if ((defined $fuid) && (getpwnam($usr)) && ($fuid ne getpwnam($usr))) { if (-l $fil) { last; } # Skip symlinks. printf " %-60s %6s %s\n", $fil, $fuid, getpwuid($fuid); } } } print "\n"; # Perldoc. =head1 NAME B - Homedir ownership security report =head1 DESCRIPTION B scours the /home filesystem, checks that each file in /home/$user is owned by $user, and generates a report based on security policy violations. =head1 AUTHOR/CVS $Id: hosr,v 1.1 2003/01/27 21:42:22 schnesa Exp $ =cut