This little script will find out about a lot of packaging issues.

Specifically, you invoke it on a set of packages, and it will report
most instances of funny owner/mode in the tarball that's not matched
by a proper @owner/@group/@mode annotation in the packing-list.

It's actually limited to 5 entries per package, as it's normally
not any use to go any further.

For instance, it's very good at catching setuid games that don't say
they're setuid upfront in the packing-list...


Cleaning these errors up now would be a good idea. Sooner or later,
pkg_create is going to become really picky about this. Better sooner
than later, in fact...



#!/usr/bin/perl

# $OpenBSD$
# Copyright (c) 2005 Marc Espie <[EMAIL PROTECTED]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# check all packages in the current directory, and report mode issues

use strict;
use warnings;

use OpenBSD::PackageLocator;
use OpenBSD::PackageInfo;
use OpenBSD::PackingList;
use Getopt::Std;

package OpenBSD::PackingElement;
sub check_modes
{
}

package OpenBSD::PackingElement::FileBase;
use POSIX;

sub check_modes
{
        my ($item, $pkgname, $max, $handle) = @_;
        return if $$max >= 5;
        my $entry = $handle->next();
        if (defined $item->{owner}) {
                #if ($item->{owner} ne $entry->{uname}) {
                #       print "Problem in $pkgname: ", $item->fullname(),
                #       ", [EMAIL PROTECTED] mismatch (", $item->{owner}, 
                #       " vs ", $entry->{uname}, ")\n";
                #       $$max++;
                #}
        } else {
                if ($entry->{uname} ne 'root' && $entry->{uname} ne 'bin') {
                        print "Problem in $pkgname: no [EMAIL PROTECTED] for ",
                        $item->fullname(), " (", $entry->{uname}, ")\n";
                        $$max++;
                }
        }
        if (defined $item->{group}) {
                #if ($item->{group} ne $entry->{gname}) {
                #       print "Problem in $pkgname: ", $item->fullname(),
                #       ", [EMAIL PROTECTED] mismatch (", $item->{group}, 
                #       " vs ", $entry->{gname}, ")\n";
                #       $$max++;
                #}
        } else {
                if ($entry->{gname} ne 'bin' && $entry->{gname} ne 'wheel') {
                        print "Problem in $pkgname: no [EMAIL PROTECTED] for ",
                        $item->fullname(), " (", $entry->{gname}, ")\n";
                        $$max++;
                }
        }
        if (!defined $item->{mode} && $entry->isFile()) {
                if (($entry->{mode} & (S_ISUID | S_ISGID | S_IWOTH)) != 0) {
                        print "Weird mode in $pkgname for ", $item->fullname(),
                        ": ", sprintf("%4o", $entry->{mode}), "\n";
                }
        }
}

package main;

my $db = {};
sub do_pkg
{
        my $pkgname = shift;

        print STDERR "$pkgname:\n";
        my $true_package = OpenBSD::PackageLocator->find($pkgname);
        return 0 unless $true_package;
        my $dir = $true_package->info();
        # twice read
        return 0 unless -d $dir;
        my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS);
        my $max = 0;
        $plist->visit('check_modes', $plist->pkgname(), \$max, $true_package);
        $true_package->close();
        $true_package->wipe_info();
        $plist->forget();
        return 1;
}


for my $pkgname (@ARGV) {
        do_pkg($pkgname);
}

exit(0);

Reply via email to