mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-24 13:56:13 +01:00
Verify hdrmd5 of packages if specified in the buildinfo
Needed for buildenv builds that want specific packages.
This commit is contained in:
parent
930dfc1999
commit
f47c39521d
13
osc/build.py
13
osc/build.py
@ -179,7 +179,7 @@ class Pac:
|
|||||||
|
|
||||||
self.mp = {}
|
self.mp = {}
|
||||||
for i in ['binary', 'package',
|
for i in ['binary', 'package',
|
||||||
'epoch', 'version', 'release',
|
'epoch', 'version', 'release', 'hdrmd5',
|
||||||
'project', 'repository',
|
'project', 'repository',
|
||||||
'preinstall', 'vminstall', 'noinstall', 'installonly', 'runscripts',
|
'preinstall', 'vminstall', 'noinstall', 'installonly', 'runscripts',
|
||||||
]:
|
]:
|
||||||
@ -931,6 +931,17 @@ def main(apiurl, opts, argv):
|
|||||||
else:
|
else:
|
||||||
print('WARNING: unknown packages get not verified, they can compromise your system !')
|
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')
|
print('Writing build configuration')
|
||||||
|
|
||||||
if build_type == 'kiwi':
|
if build_type == 'kiwi':
|
||||||
|
10
osc/fetch.py
10
osc/fetch.py
@ -239,6 +239,12 @@ class Fetcher:
|
|||||||
i.makeurls(self.cachedir, self.urllist)
|
i.makeurls(self.cachedir, self.urllist)
|
||||||
if os.path.exists(i.fullfilename):
|
if os.path.exists(i.fullfilename):
|
||||||
cached += 1
|
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
|
miss = 0
|
||||||
needed = all - cached
|
needed = all - cached
|
||||||
if all:
|
if all:
|
||||||
@ -254,6 +260,10 @@ class Fetcher:
|
|||||||
'--offline not possible.' %
|
'--offline not possible.' %
|
||||||
i.fullfilename)
|
i.fullfilename)
|
||||||
self.dirSetup(i)
|
self.dirSetup(i)
|
||||||
|
if i.hdrmd5 and self.enable_cpio:
|
||||||
|
self.__add_cpio(i)
|
||||||
|
done += 1
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
# if there isn't a progress bar, there is no output at all
|
# if there isn't a progress bar, there is no output at all
|
||||||
if not self.progress_obj:
|
if not self.progress_obj:
|
||||||
|
@ -113,6 +113,17 @@ class PackageQuery:
|
|||||||
f.close()
|
f.close()
|
||||||
return pkgquery
|
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__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
try:
|
try:
|
||||||
|
@ -69,7 +69,7 @@ class RpmQuery(packagequery.PackageQuery):
|
|||||||
self.filename_suffix = 'rpm'
|
self.filename_suffix = 'rpm'
|
||||||
self.header = None
|
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_provides is unused because a rpm always has a self provides
|
||||||
self.__read_lead()
|
self.__read_lead()
|
||||||
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
|
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
|
||||||
@ -80,8 +80,10 @@ class RpmQuery(packagequery.PackageQuery):
|
|||||||
size = il * RpmHeaderEntry.ENTRY_SIZE + dl
|
size = il * RpmHeaderEntry.ENTRY_SIZE + dl
|
||||||
# data is 8 byte aligned
|
# data is 8 byte aligned
|
||||||
pad = (size + 7) & ~7
|
pad = (size + 7) & ~7
|
||||||
self.__file.read(pad)
|
querysig = extra_kw.get('querysig')
|
||||||
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
|
if not querysig:
|
||||||
|
self.__file.read(pad)
|
||||||
|
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
|
||||||
hdrmgc, reserved, il, dl = struct.unpack('!I3i', data)
|
hdrmgc, reserved, il, dl = struct.unpack('!I3i', data)
|
||||||
self.header = RpmHeader(pad, dl)
|
self.header = RpmHeader(pad, dl)
|
||||||
if self.HEADER_MAGIC != hdrmgc:
|
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])
|
entry.data = struct.unpack('!%dh' % entry.count, data[off:off + 2 * entry.count])
|
||||||
elif entry.type == 4:
|
elif entry.type == 4:
|
||||||
entry.data = struct.unpack('!%di' % entry.count, data[off:off + 4 * entry.count])
|
entry.data = struct.unpack('!%di' % entry.count, data[off:off + 4 * entry.count])
|
||||||
elif entry.type == 6 or entry.type == 7:
|
elif entry.type == 6:
|
||||||
# XXX: what to do with binary data? for now treat it as a string
|
|
||||||
entry.data = unpack_string(data[off:])
|
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:
|
elif entry.type == 8 or entry.type == 9:
|
||||||
cnt = entry.count
|
cnt = entry.count
|
||||||
entry.data = []
|
entry.data = []
|
||||||
@ -250,6 +253,17 @@ class RpmQuery(packagequery.PackageQuery):
|
|||||||
f.close()
|
f.close()
|
||||||
return rpmq
|
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
|
@staticmethod
|
||||||
def rpmvercmp(ver1, ver2):
|
def rpmvercmp(ver1, ver2):
|
||||||
"""
|
"""
|
||||||
@ -326,3 +340,5 @@ if __name__ == '__main__':
|
|||||||
print('\n'.join(rpmq.provides()))
|
print('\n'.join(rpmq.provides()))
|
||||||
print('##########')
|
print('##########')
|
||||||
print('\n'.join(rpmq.requires()))
|
print('\n'.join(rpmq.requires()))
|
||||||
|
print('##########')
|
||||||
|
print(RpmQuery.queryhdrmd5(sys.argv[1]))
|
||||||
|
Loading…
Reference in New Issue
Block a user