1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 09:16:16 +02:00

Verify hdrmd5 of packages if specified in the buildinfo

Needed for buildenv builds that want specific packages.
This commit is contained in:
Michael Schroeder 2014-11-17 12:39:58 +01:00
parent 930dfc1999
commit f47c39521d
4 changed files with 54 additions and 6 deletions

View File

@ -179,7 +179,7 @@ class Pac:
self.mp = {}
for i in ['binary', 'package',
'epoch', 'version', 'release',
'epoch', 'version', 'release', 'hdrmd5',
'project', 'repository',
'preinstall', 'vminstall', 'noinstall', 'installonly', 'runscripts',
]:
@ -931,6 +931,17 @@ def main(apiurl, opts, argv):
else:
print('WARNING: unknown packages get not verified, they can compromise your system !')
for i in bi.deps:
if i.hdrmd5:
from .util import packagequery
hdrmd5 = packagequery.PackageQuery.queryhdrmd5(i.fullfilename)
if not hdrmd5:
print("Error: cannot get hdrmd5 for %s" % i.fullfilename)
sys.exit(1)
if hdrmd5 != i.hdrmd5:
print("Error: hdrmd5 mismatch for %s: %s != %s" % (i.fullfilename, hdrmd5, i.hdrmd5))
sys.exit(1)
print('Writing build configuration')
if build_type == 'kiwi':

View File

@ -239,6 +239,12 @@ class Fetcher:
i.makeurls(self.cachedir, self.urllist)
if os.path.exists(i.fullfilename):
cached += 1
if i.hdrmd5:
from .util import packagequery
hdrmd5 = packagequery.PackageQuery.queryhdrmd5(i.fullfilename)
if not hdrmd5 or hdrmd5 != i.hdrmd5:
os.unlink(i.fullfilename)
cached -= 1
miss = 0
needed = all - cached
if all:
@ -254,6 +260,10 @@ class Fetcher:
'--offline not possible.' %
i.fullfilename)
self.dirSetup(i)
if i.hdrmd5 and self.enable_cpio:
self.__add_cpio(i)
done += 1
continue
try:
# if there isn't a progress bar, there is no output at all
if not self.progress_obj:

View File

@ -113,6 +113,17 @@ class PackageQuery:
f.close()
return pkgquery
@staticmethod
def queryhdrmd5(filename):
f = open(filename, 'rb')
magic = f.read(7)
f.seek(0)
if magic[:4] == '\xed\xab\xee\xdb':
from . import rpmquery
f.close()
return rpmquery.RpmQuery.queryhdrmd5(filename)
return None
if __name__ == '__main__':
import sys
try:

View File

@ -69,7 +69,7 @@ class RpmQuery(packagequery.PackageQuery):
self.filename_suffix = 'rpm'
self.header = None
def read(self, all_tags=False, self_provides=True, *extra_tags):
def read(self, all_tags=False, self_provides=True, *extra_tags, **extra_kw):
# self_provides is unused because a rpm always has a self provides
self.__read_lead()
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
@ -80,8 +80,10 @@ class RpmQuery(packagequery.PackageQuery):
size = il * RpmHeaderEntry.ENTRY_SIZE + dl
# data is 8 byte aligned
pad = (size + 7) & ~7
self.__file.read(pad)
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
querysig = extra_kw.get('querysig')
if not querysig:
self.__file.read(pad)
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
hdrmgc, reserved, il, dl = struct.unpack('!I3i', data)
self.header = RpmHeader(pad, dl)
if self.HEADER_MAGIC != hdrmgc:
@ -115,9 +117,10 @@ class RpmQuery(packagequery.PackageQuery):
entry.data = struct.unpack('!%dh' % entry.count, data[off:off + 2 * entry.count])
elif entry.type == 4:
entry.data = struct.unpack('!%di' % entry.count, data[off:off + 4 * entry.count])
elif entry.type == 6 or entry.type == 7:
# XXX: what to do with binary data? for now treat it as a string
elif entry.type == 6:
entry.data = unpack_string(data[off:])
elif entry.type == 7:
entry.data = data[off:off + entry.count]
elif entry.type == 8 or entry.type == 9:
cnt = entry.count
entry.data = []
@ -250,6 +253,17 @@ class RpmQuery(packagequery.PackageQuery):
f.close()
return rpmq
@staticmethod
def queryhdrmd5(filename):
f = open(filename, 'rb')
rpmq = RpmQuery(f)
rpmq.read(1004, querysig=True)
f.close()
entry = rpmq.gettag(1004)
if entry is None:
return None
return ''.join([ "%02x" % x for x in struct.unpack('16B', entry.data) ])
@staticmethod
def rpmvercmp(ver1, ver2):
"""
@ -326,3 +340,5 @@ if __name__ == '__main__':
print('\n'.join(rpmq.provides()))
print('##########')
print('\n'.join(rpmq.requires()))
print('##########')
print(RpmQuery.queryhdrmd5(sys.argv[1]))