18 October 2010

Package File Ownership

Once a system is built and begins to be used, undoubtedly, more files
are added to the system.  These files may be logs, user / application
created files, files that are part of a package, or those compiled
from source.  When poking around a system, one may stumble across a file
that was installed by a package though either the package is unknown to
the individual or is not readily identifiable.  Solaris, FreeBSD, and
Linux provide a means of tying together a file to a package (should it
belong to one).  To relate /usr/bin/ksh back to a package in Solaris,
pkgchk can be used:

        sunhost [0] /usr/sbin/pkgchk -l -p /usr/bin/ksh
        Type: regular file
        Expected mode: 0555
        Expected owner: root
        Expected group: bin
        Expected file size (bytes): 201076
        Expected sum(1) of contents: 46306
        Expected last modification: Apr 20 04:41:16 PM 2005
        Referenced by the following packages:
                SUNWcsu
        Current status: installed

The -p option tells pkgchk to check the path of the file specified while
-l effectively tells pkgchk to display that information.  In the above
example, aside from just getting the packages that reference this file
(SUNWcsu), the output also contains other file information including size,
ownership, etc.

While producing effectively the same output in FreeBSD is slightly more
involved, it can be easily accomplished via both pkg_info and stat:

        bsdhost [0] /usr/sbin/pkg_info -W /usr/local/bin/ksh
        /usr/local/bin/ksh was installed by package pdksh-5.2.14p2
        bsdhost [0] /usr/bin/stat -x /usr/local/bin/ksh
          File: "/usr/local/bin/ksh"
          Size: 594272       FileType: Regular File
          Mode: (0555/-r-xr-xr-x)   Uid: (  0/  root)  Gid: (  0/  wheel)
        Device: 4,17   Inode: 405874    Links: 1
        Access: Wed Dec 31 19:00:00 1969
        Modify: Sun Apr  3 18:54:04 2005
        Change: Fri Jan 13 17:04:45 2006

The -W option to pkg_info only identifies which package, if any, the file
belongs to.  Following this up with stat -x allows one to determine the
rest of the output listed within pkgchk from Solaris.  The -x to stat
simply states Linux-like output verbosity.

Similar to FreeBSD, determining this information on Linux is a multistep
process.  On a host that uses Red Hat Package Manager (rpm), both rpm
and stat can be used to retrieve the same information as that above:

        linhost [0] /bin/rpm -qf /bin/ksh
        pdksh-5.2.14-21
        linhost [0] /usr/bin/stat /bin/ksh
          File: `/bin/ksh'
          Size: 180884      Blocks: 368    IO Block: 4096   Regular File
        Device: 801h/2049d  Inode: 304397  Links: 1
        Access: (0755/-rwxr-xr-x)   Uid: (  0/  root)  Gid: (  0/  root)
        Access: 2006-09-01 17:00:10.000000000 -0400
        Modify: 2003-11-19 01:11:27.000000000 -0500
        Change: 2005-07-13 15:08:08.000000000 -0400

rpm's -q option sets rpm in query mode with option f specifying the file
in question to query an installed package for.  Of note, unlike FreeBSD,
stat does not require any further parameters besides the filename to
provide the above listing.

see also:
    Notes on Packages in Solaris 11