summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/eg/scan/scan_sudo
blob: 5b143e941c88914d943f72b2b061f5d1120eec82 (plain)
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
52
53
54
#!/usr/bin/perl -P

# $RCSfile: scan_sudo,v $$Revision: 4.1 $$Date: 92/08/07 17:20:42 $

# Analyze the sudo log.

chdir('/usr/adm/private/memories') || die "Can't cd to memories: $!\n";

if (open(Oldsudo,'oldsudo')) {
    $maxpos = <Oldsudo>;
    close Oldsudo;
}
else {
    $maxpos = 0;
    `echo 0 >oldsudo`;
}

unless (open(Sudo, '/usr/adm/sudo.log')) {
    print "Somebody removed sudo.log!!!\n" if $maxpos;
    exit 0;
}

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
   $blksize,$blocks) = stat(Sudo);

if ($size < $maxpos) {
    $maxpos = 0;
    print "Somebody reset sudo.log!!!\n";
}

seek(Sudo,$maxpos,0);

while (<Sudo>) {
    s/^.* :[ \t]+//;
    s/ipcrm.*/ipcrm/;
    s/kill.*/kill/;
    unless ($seen{$_}++) {
	push(@seen,$_);
    }
    $last = $_;
}
$max = tell(Sudo);

open(tmp,'|sort >oldsudo.tmp') || die "Can't create tmp file: $!\n";
while ($_ = pop(@seen)) {
    print tmp $_;
}
close(tmp);
open(tmp,'oldsudo.tmp') || die "Can't reopen tmp file: $!\n";
while (<tmp>) {
    print $seen{$_},":\t",$_;
}

print `(rm -f oldsudo.tmp; echo $max > oldsudo) 2>&1`;
OpenPOWER on IntegriCloud