source: soft/build_system/build_system/upload/robot/trunk/check_owner_of_rpm.pl @ 1

Last change on this file since 1 was 1, checked in by fasma, 13 years ago

Initial Import from Mandriva's soft revision 224062 and package revision 45733

File size: 1.7 KB
RevLine 
[1]1#!/usr/bin/perl
2## Chmouel Boudjnah <chmouel@mandriva.com>
3## Check if the rpm contains a local user, if fail he send a mail to
4## the maintenner.
5
6my ($quiet, $mail, @bad);
7
8while ($ARGV[0] =~ /^--/ || $ARGV[0] =~ /^-/) {
9  $_ = shift;
10  if (/^-q$/ || /^--quiet$/) { $quiet++ ;}
11  elsif (/^-m$/ || /^--mail$/) { $mail++ ;}
12  else { die "Unrecognized switch: $_\n" };
13}
14
15my $rpm = shift or die "You should give me a rpm\n";
16
17while (my @list=getpwent){
18    push @users, "$list[0] " if $list[2] >= 500 && $list[0] !~ /games|sympa/;
19}
20while (my @list=getgrent){
21    my @F = ":";
22    push @groups, "$list[0] " if $list[2] >= 500 && $list[0] !~ /sympa/;
23}
24
25open FH, "rpm -v -qpl $rpm|" or die "Can't open $rpm\n";
26while (<FH>) {
27    if (m(^(\S+)\W+(\w+)\W+(\w+)\W+(\w+)\W+(\w+ \w+ \w+:\w+)\s*(/[^ ]+))) {
28        my ($user, $group, $file) = ($2, $3, $6);
29        if (grep /$user/, @users) {push @bad , "$user\t$group\t$file"; next}
30        if (grep /$group/, @groups){push @bad ,"$user\t$group\t$file"; next}
31    }
32}
33close FH;
34
35if (@bad) {
36    exit 1 if $quiet;
37    if ($mail) {
38        my $a = `/home/chmou/tmp/bin/ch -m $rpm`;chop $a;
39        (my $brpm = $rpm) =~ s|.*/||;
40        open MAIL, "|/usr/sbin/sendmail -B8BITMIME -n -t -U" or die "can't fork sendmail $!";
41        select MAIL;
42        print "From: Sergent Garcia <kenobi\@mandriva.com>\nTo: $a\n";
43        print "Subject: Bad owner or groups for $brpm\nUser-Agent: Marijuana 1.2\n\n";
44    }
45    print "Tis is the bad files containing bad owner or groups :\n";
46    print "====================\nUSER\tGROUP\tFILE\n====================\n";
47    for (@bad) {print};
48    print "\nplease fix this asap with a defattr(-,root,root)\n";
49    if ($mail) {
50        print "\n-- \nHip Youp\n";
51        close MAIL;
52    }
53    exit 1;
54}
55
56exit 0;
Note: See TracBrowser for help on using the repository browser.