-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckhomeownership
52 lines (47 loc) · 1.72 KB
/
checkhomeownership
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/perl
# -*- Perl -*-
# put into the public domain by Russell Nelson <nelson@qmail.org>
# NO GUARANTEE AT ALL; support is available for a fee from the author.
#
# Reports anyone in /etc/passwd whom qmail won't deliver mail to.
# Reports any maildirs that don't exist or are owned by the wrong user.
# Assumes that nothing is trying to modify the mailboxes in /var/spool/mail
# This assumption could be removed by locking the mailboxes and deleting
# the mail after moving it.
# version 0.00 - first release to the public.
# version 0.01 - removed check for "drop" in password field. Changed
# documentation, since it doesn't create maildirs, but instead checks for them.
# version 0.02 - removed 'stat.pl'.
# ==============================================================================
# Modified - Julio Maidanik <julio.maidanik@coasin.com.ar>
# The report format has been changed, including user ok
# ------------------------------------------------------------------------------
while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) =
getpwent()) {
$uids{$uid} = $name;
}
endpwent();
while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) =
getpwent()) {
print "${uid}: $name, $dir, ";
if (!-e $dir) {
print "home dir doesn't exist (passwd: $passwd)\n";
next;
}
$st_uid = (stat($dir))[4];
if ($uid != $st_uid) {
print "home dir is owned by $st_uid, who is $uids{$st_uid}\n";
next;
}
$st_uid = (stat("$dir/Maildir"))[4];
if (!$st_uid) {
print "$dir/Maildir doesn't exist\n";
next;
}
if ($uid != $st_uid) {
print "$dir/Maildir is owned by $st_uid, who is $uids{$st_uid}\n";
next;
}
print "ok\n"
}
endpwent();