Skip to content

Add support for RPM-based distros for docker and rootfs images scanpipe #6

Description

@pombredanne

There is no easy way to access the RPM database but through librpm and the rpm executable.
The installed RPMs database comes in three formats:

  1. bdb: a legacy Berkeley DB hash used as a key/value where the value is a binary blob that contains all the RPM data. The format of this blob should be the same as the RPM header format and scancode-toolkit can parse the headers. This is the format that was/is used in older RH, CentOS, Fedora and most every RPM distros.
  2. sqlite: a SQLite database where one table is used as a key/value store where the value is a binary blob that contains all the RPM data in the same binary format as in 1. and the RPM header. This is the format that is used in newer RH, CentOS and Fedora versions.
  3. ndb: a new key/value store that is built-in librpm. This is the format used by newer openSUSE distros

librpm provides support for each of these formats and also contains a built-in read-only handler for the 1. bdb format such that librpm can be built without Berkeley DB and still can read an older RPM db (for instance to convert it to a newer format).

It needs to be built with specific flags to enable all these formats (typically a given build of a distro does not nee to support all the formats).

The installed DBs locations are:

Distro Path Format
CentOS 8 /var/lib/rpm/Packages Berkeley DB (Hash, version 9, native byte-order)
CentOS 5 /var/lib/rpm/Packages Berkeley DB (Hash, version 8, native byte-order)
Fedora 30 /var/lib/rpm/rpmdb.sqlite SQLite 3.x database
Fedora 20 /var/lib/rpm/Packages Berkeley DB (Hash, version 9, native byte-order)
openMandriva /var/lib/rpm/Packages Berkeley DB (Hash, version 10, native byte-order)
RHEL 8 /var/lib/rpm/Packages Berkeley DB (Hash, version 9, native byte-order)
openSUSE 20200528 /usr/lib/sysimage/rpm/Packages.db data, but this is the ndb format

In addition on Fedora distros there are files under /etc/yum.repos.d/* that contains base and mirror URLs for the repo used to install RPMs. Each file is in .ini format. On openSUSE and SLES, these are under /etc/zypp/repos.d

The licenses (when not deleted as in some CentOS Docker images) are found in /usr/share/licenses/<package name>/<license files> or /usr/share/doc/<package name>/<license files>

If using the rpm cli, this can create an XML like output:
./rpm --query --all --qf '[%{*:xml}\n]' --rcfile=./rpmrc --dbpath=<path to>/var/lib/rpm > somefile.xml
The .rcfile option may not be needed, but when using a fresh RPM build this is needed.

The RPM db may need to be rebuilt first when this is a bdb format from an older version than the bdb with which librpm was built.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions