Monday, April 04, 2005

Perl script to identify incorrect ownership

Was feeling inclined the other day to look through a bunch of home directories on a unix login server at work to make sure that everyone had correct ownership on their home directories.

The result of the question produced the following script:

#!/usr/bin/perl
use File::stat
open(FH,"/etc/passwd");
while($line = ) {
chomp($line);
($user,undef,$uid,$gid,$fullName,$homedir,$shell)= split(/:/,$line);
#print "Now on line: $line\n";
if( -d "$homedir") {
$homedirUID = stat($homedir)->uid();
$homedirGID = stat($homedir)->gid();
print "Permission Error: [Bad UID] ${user}'s home directory not owned by $user\n" if($uid != $homedirUID);
print "Permission Error: [Bad GID] ${user}'s home directory not owned by $user\n" if($gid != $homedirGID);
}else{
print "Homedir: $homedir doesn't exist\n";
}
}
close(FH);

0 Comments:

Post a Comment

<< Home