Subversion Repositories DevTools

Rev

Rev 5608 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5608 Rev 5813
Line 1... Line 1...
1
#!/usr/bin/perl -w
1
#!/usr/bin/perl -w
2
# nbannon 20050523
-
 
3
# chmod 0775 /devl/dpkg_archive/*
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
4
############################
3
###############################################################################
5
#
4
#
6
#   Ensure that package directories in dpkg_archive are:
5
#   Ensure that package directories in dpkg_archive are:
7
#       chmod 0775      - Not world writable
6
#       chmod 0775      - Not world writable
8
#       chown buildadm  - Owned by buildadm
7
#       chown buildadm  - Owned by buildadm
9
#
8
#
Line 23... Line 22...
23
    unless ($buildadm && $buildgid);
22
    unless ($buildadm && $buildgid);
24
 
23
 
25
die "$0: Not run as root\n"
24
die "$0: Not run as root\n"
26
        if ( $> );
25
        if ( $> );
27
 
26
 
-
 
27
#   Proccess all directories in dpkg_archive
-
 
28
#   Are only expecting directories at the top level
-
 
29
#   
28
opendir(DPKGARCHIVE, ".") or die "$0: Could not open \"$DIR\": $!\n";
30
opendir(DPKGARCHIVE, ".") or die "$0: Could not open \"$DIR\": $!\n";
29
while (defined($pkg=readdir(DPKGARCHIVE))) {
31
while (defined($pkg=readdir(DPKGARCHIVE))) {
30
    next if ( $pkg eq ".." );
32
    next if ( $pkg eq ".." );
31
    next if ( $pkg eq "." );
33
    next if ( $pkg eq "." );
-
 
34
 
-
 
35
    # Ignore special (symlinks) to files
32
    next if ( $pkg eq "dpkg_archive_list.txt" );
36
    next if ( $pkg eq "dpkg_archive_list.txt" );
-
 
37
    next if ( $pkg eq "dpkg_archive_pkg.txt" );
33
 
38
 
34
    $sb=lstat($pkg);
39
    $sb=lstat($pkg);
35
    $rwx=$sb->mode & 00777;
40
    $rwx=$sb->mode & 00777;
36
    $uid=$sb->uid;
41
    $uid=$sb->uid;
37
 
42
 
-
 
43
    # Delete empty subdirs (packages)
38
    if ( -d $pkg && isEmptyDir($pkg) == 1 )
44
    if ( -d $pkg && isEmptyDir($pkg) == 1 )
39
    {
45
    {
40
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
46
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
41
               sprintf("%s/%s: is empty", $DIR, $pkg, $rwx));
47
               sprintf("%s/%s: is empty", $DIR, $pkg, $rwx));
42
        printf STDERR ("%s: %s/%s: is empty\n", $0, $DIR, $pkg, $rwx);
48
        printf STDERR ("%s: %s/%s: is empty\n", $0, $DIR, $pkg, $rwx);
Line 44... Line 50...
44
            printf STDERR "%s: Could not delete empty directiry %s/%s: %s\n", $0, $rwx, $DIR, $pkg, $!;
50
            printf STDERR "%s: Could not delete empty directiry %s/%s: %s\n", $0, $rwx, $DIR, $pkg, $!;
45
        }
51
        }
46
        next;
52
        next;
47
    }
53
    }
48
 
54
 
-
 
55
    # Check that (directory) is NOT world writable, but is writable by user/group
49
    # Rather than change everything every day, change it only if it's wrong
56
    #   Change it only if it's wrong
50
    if ($rwx != 00775) {
57
    if ($rwx != 00775) {
51
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
58
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
52
               sprintf("%s/%s: was chmod %04o", $DIR, $pkg, $rwx));
59
               sprintf("%s/%s: was chmod %04o", $DIR, $pkg, $rwx));
53
        printf STDERR ("%s: %s/%s: was chmod %04o\n", $0, $DIR, $pkg, $rwx);
60
        printf STDERR ("%s: %s/%s: was chmod %04o\n", $0, $DIR, $pkg, $rwx);
54
        $rwx=($sb->mode & 07000) | 00775;
61
        $rwx=($sb->mode & 07000) | 00775;
55
        unless (chmod($rwx, $pkg) == 1) {
62
        unless (chmod($rwx, $pkg) == 1) {
56
            printf STDERR "%s: Could not chmod %04o %s/%s: %s\n", $0, $rwx, $DIR, $pkg, $!;
63
            printf STDERR "%s: Could not chmod %04o %s/%s: %s\n", $0, $rwx, $DIR, $pkg, $!;
57
        }
64
        }
58
    }
65
    }
59
 
66
 
-
 
67
    # Check that (directory) is owned by buildamd
-
 
68
    #   Chnage if wrong
60
    if ($uid != $buildadm ) {
69
    if ($uid != $buildadm ) {
61
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
70
        system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
62
               sprintf("%s/%s: was uid %d", $DIR, $pkg, $uid));
71
               sprintf("%s/%s: was uid %d", $DIR, $pkg, $uid));
63
        printf STDERR ("%s: %s/%s: was uid %d\n", $0, $DIR, $pkg, $uid);
72
        printf STDERR ("%s: %s/%s: was uid %d\n", $0, $DIR, $pkg, $uid);
64
        unless (chown($buildadm, $buildgid, $pkg) == 1) {
73
        unless (chown($buildadm, $buildgid, $pkg) == 1) {