Find group writable home directories

With procmail, vacation and forward files do not work if the user’s home directory is group writable. Here’s a script that will locate all group writable home directories:

#!/usr/bin/perl

my %users;
open(P,"/etc/passwd");
while(

) {
        chomp();
        my ($uname,$pass,$uid,$gid,$gecos,$home,$shell) = split(/\:/,$_);
        $users{$uname} = $home;
};
close P;

LINE: foreach $user (sort keys %users) {
        $home = $users{$user};
        next LINE if ($user eq "dbus");
        next LINE if ($user eq "distcache");
        next LINE if ($user eq "haldaemon");
        next LINE if ($user eq "nobody");
        next LINE if ($user eq "rpc");
        $test = `find $home -maxdepth 0 -perm -g=w -type d 2>&1`;
        chomp($test);
        if ($test ne "") {
                if ($test =~ /No such file or directory/) {
                        $msg = "NOT FOUND";
                } else {
                        print $user . " : " . $home . "\n";
                };
        };
};

blog comments powered by Disqus