Subversion Repositories DevTools

Rev

Rev 3410 | Rev 5253 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3410 dpurdie 1
#!/usr/bin/perl -w
2
# nbannon 20050523
3413 dpurdie 3
# chmod 0775 /devl/dpkg_archive/*
4
############################
5
#
6
#   Ensure that package directories in dpkg_archive are:
7
#       chmod 0775      - Not world writable
8
#       chown buildadm  - Owned by buildadm
9
#
10
#   Script should be run as root - so that it can fix file attributes
11
#
3410 dpurdie 12
 
13
use File::stat;
14
 
15
$DIR="/export/devl/dpkg_archive";
16
chdir($DIR) or die "$0: Could not change to \"$DIR\": $!\n";
17
 
18
($name, $passwd, $buildadm, $buildgid) = getpwnam ('buildadm');
19
$name = '';
20
$passwd = '';
21
 
22
die "$0: Could not determine uid of builadadm\n"
23
	unless ($buildadm && $buildgid);
24
 
25
die "$0: Not run as root\n"
26
        if ( $> );
27
 
28
opendir(DPKGARCHIVE, ".") or die "$0: Could not open \"$DIR\": $!\n";
3413 dpurdie 29
while (defined($pkg=readdir(DPKGARCHIVE))) {
30
    next if ( $pkg eq ".." );
31
    next if ( $pkg eq "." );
32
    next if ( $pkg eq "dpkg_archive_list.txt" );
3410 dpurdie 33
 
34
    $sb=lstat($pkg);
35
    $rwx=$sb->mode & 00777;
36
    $uid=$sb->uid;
37
 
38
    # Rather than change everything every day, change it only if it's wrong
39
    if ($rwx != 00775) {
3413 dpurdie 40
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
41
               sprintf("%s/%s: was chmod %04o", $DIR, $pkg, $rwx));
42
        printf STDERR ("%s: %s/%s: was chmod %04o\n", $0, $DIR, $pkg, $rwx);
43
        $rwx=($sb->mode & 07000) | 00775;
44
        unless (chmod($rwx, $pkg) == 1) {
45
            printf STDERR "%s: Could not chmod %04o %s/%s: %s\n", $0, $rwx, $DIR, $pkg, $!;
46
        }
3410 dpurdie 47
    }
48
 
49
    if ($uid != $buildadm ) {
3413 dpurdie 50
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
51
               sprintf("%s/%s: was uid %d", $DIR, $pkg, $uid));
52
        printf STDERR ("%s: %s/%s: was uid %d\n", $0, $DIR, $pkg, $uid);
53
        unless (chown($buildadm, $buildgid, $pkg) == 1) {
54
            printf STDERR "%s: Could not chown buildadm (%d) %s/%s: %s\n", $0,$uid, $DIR, $pkg, $!;
55
        }
3410 dpurdie 56
    }
57
}
58
closedir(DPKGARCHIVE);
59