[yum-commits] Branch 'yum-3_2_X' - yum/constants.py yum/packages.py
skvidal at osuosl.org
skvidal at osuosl.org
Mon Feb 23 19:25:25 UTC 2009
yum/constants.py | 3 +++
yum/packages.py | 24 +++++++++++++++++-------
2 files changed, 20 insertions(+), 7 deletions(-)
New commits:
commit efc3d08d5ae8b4c6e7cb7991f44c595ea13e51b6
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Mon Feb 23 14:23:55 2009 -0500
fix up yum's package object verify() to work with non md5 filedigests.
diff --git a/yum/constants.py b/yum/constants.py
index e4dd184..3711fc0 100644
--- a/yum/constants.py
+++ b/yum/constants.py
@@ -108,3 +108,6 @@ PATTERNS_MAX = 8
# We have another value here because name is indexed and sqlite is _much_
# faster even at large numbers of patterns.
PATTERNS_INDEXED_MAX = 128
+
+RPM_CHECKSUM_TYPES = { 1:'md5', 2:'sha1', 8:'sha256', 9:'sha384', 10:'sha512',
+ 11:'sha224' } # from RFC 4880
diff --git a/yum/packages.py b/yum/packages.py
index bc3d6d5..7a84990 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -34,6 +34,7 @@ from rpmUtils.miscutils import flagToString, stringToVersion
import Errors
import errno
import struct
+from constants import *
import urlparse
urlparse.uses_fragment.append("media")
@@ -1221,7 +1222,7 @@ class _PkgVerifyProb:
return ret
# From: lib/rpmvf.h ... not in rpm *sigh*
-_RPMVERIFY_MD5 = (1 << 0)
+_RPMVERIFY_DIGEST = (1 << 0)
_RPMVERIFY_FILESIZE = (1 << 1)
_RPMVERIFY_LINKTO = (1 << 2)
_RPMVERIFY_USER = (1 << 3)
@@ -1265,9 +1266,18 @@ class YumInstalledPackage(YumHeaderPackage):
prelink_cmd = "/usr/sbin/prelink"
have_prelink = os.path.exists(prelink_cmd)
+ # determine what checksum algo to use:
+ csum_type = 'md5' # default for legacy
+ if hasattr(rpm, 'RPMTAG_FILEDIGESTALGO'):
+ csum_num = self.hdr[rpm.RPMTAG_FILEDIGESTALGO]
+ if csum_num:
+ if RPM_CHECKSUM_TYPES.has_key(csum_num):
+ csum_type = RPM_CHECKSUM_TYPES[csum_num]
+ # maybe an else with an error code here? or even a verify issue?
+
for filetuple in fi:
#tuple is: (filename, fsize, mode, mtime, flags, frdev?, inode, link,
- # state, vflags?, user, group, md5sum(or none for dirs)
+ # state, vflags?, user, group, checksum(or none for dirs)
(fn, size, mode, mtime, flags, dev, inode, link, state, vflags,
user, group, csum) = filetuple
if patterns:
@@ -1407,15 +1417,15 @@ class YumInstalledPackage(YumHeaderPackage):
# just so we get the size correct.
if (check_content and
((have_prelink and vflags & _RPMVERIFY_FILESIZE) or
- (csum and vflags & _RPMVERIFY_MD5))):
+ (csum and vflags & _RPMVERIFY_DIGEST))):
try:
- my_csum = misc.checksum('md5', fn)
+ my_csum = misc.checksum(csum_type, fn)
gen_csum = True
except Errors.MiscError:
# Don't have permission?
gen_csum = False
- if csum and vflags & _RPMVERIFY_MD5 and not gen_csum:
+ if csum and vflags & _RPMVERIFY_DIGEST and not gen_csum:
prob = _PkgVerifyProb('genchecksum',
'checksum not available', ftypes)
prob.database_value = csum
@@ -1428,10 +1438,10 @@ class YumInstalledPackage(YumHeaderPackage):
(ig, fp,er) = os.popen3([prelink_cmd, "-y", fn])
# er.read(1024 * 1024) # Try and get most of the stderr
fp = _CountedReadFile(fp)
- my_csum = misc.checksum('md5', fp)
+ my_csum = misc.checksum(csum_type, fp)
my_st_size = fp.read_size
- if (csum and vflags & _RPMVERIFY_MD5 and gen_csum and
+ if (csum and vflags & _RPMVERIFY_DIGEST and gen_csum and
my_csum != csum):
prob = _PkgVerifyProb('checksum',
'checksum does not match', ftypes)
More information about the Yum-commits
mailing list