From nikonovandrey1994 at gmail.com Tue Nov 29 05:05:02 2022 From: nikonovandrey1994 at gmail.com (Andrei Nikonov) Date: Tue, 29 Nov 2022 10:05:02 +0500 Subject: Help RPM database content direct reading and decoding In-Reply-To: References: Message-ID: Dear maintainers, I am writing to you asking for help or advice. I have to get a list of installed packages from /var/lib/rpm/Packages database file directly, without using such commands as 'rpm -qa' or 'yum list' or something else, because I might have no access to those commands and rpm at all. Actually, my case is to get the list of installed packages from the docker container with rpm-based OS, while the host OS can be different. I am using Python and all I have reached for the moment is an opened Berkeley DB file with output of tuples of binary data. But I have no idea how to decode this binary output to get human readable information. Maybe I am using the wrong approach from the beginning - please refer me the right way. Maybe there is a python library that I could use? Unfortunately I did not find any similar questions, so decided to write here. Thank you in advance. -- With regards, Andrey Nikonov. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmatilai at redhat.com Tue Nov 29 07:42:22 2022 From: pmatilai at redhat.com (Panu Matilainen) Date: Tue, 29 Nov 2022 09:42:22 +0200 Subject: Help RPM database content direct reading and decoding In-Reply-To: References: Message-ID: <031dba3b-18f8-fc11-1879-f3ebad36b055@redhat.com> On 11/29/22 07:05, Andrei Nikonov wrote: > Dear maintainers, > I am writing to you asking for help or advice. > I have to get a list of installed packages from /var/lib/rpm/Packages > database file directly, without using such commands as 'rpm -qa' or 'yum > list' or something else,?because I might have no access to those > commands and rpm at all. Actually, my case is to get the list of > installed packages from the docker container with rpm-based OS,?while > the host OS can be different. > I am using Python and all I have reached for the moment is an opened > Berkeley DB file with output of tuples of binary data. But I have no > idea how to decode this binary output to get human readable information. Berkeley DB is one of the possible rpmdb formats, but that's no longer even supported upstream, the current formats are sqlite and an rpm-specific format. > Maybe I am?using the wrong approach from the beginning?- please refer me > the right way. Maybe there is a python library that I could use? > Unfortunately I did not find any similar questions, so decided to write > here. The rpmdb main data is nothing but a pile of rpm headers keyed by a number, and the format is considered private to rpm. To make sense of it, you need to extract and parse the headers, and for that you'll want the rpm python bindings. As in, the only supported means doing this all is through librpm. Of course it's *possible* to do this in pure python, look for "pyrpm" for an example. I don't know how up to date or complete that work is, probably neither. The basic rpm header format is documented in LSB, though outdated it's enough to get an idea. - Panu - > Thank you in?advance. > > -- > With regards, > Andrey Nikonov. > > > _______________________________________________ > Rpm-list mailing list > Rpm-list at lists.rpm.org > http://lists.rpm.org/mailman/listinfo/rpm-list