diff options
author | Dan McGee <dan@archlinux.org> | 2011-08-25 16:40:39 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-08-28 19:52:19 -0500 |
commit | dc3336c27728fc16d2f9e68cb818648e7ca88467 (patch) | |
tree | a0d06285caa82e56ea917673868e2080f5f7b1ca /lib/libalpm/be_package.c | |
parent | c7e4005e5ced965db49d73067fe40c516b6c34df (diff) | |
download | pacman-dc3336c27728fc16d2f9e68cb818648e7ca88467.tar.xz |
Refactor some args out of pkg_load_internal
Just pass the entire sync package in if we have it; that way we can do
any necessary operations involving it rather than have a parameter list
growing endlessly.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_package.c')
-rw-r--r-- | lib/libalpm/be_package.c | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index deec0c45..2566574d 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -276,19 +276,17 @@ static alpm_file_t *files_msort(alpm_file_t *files, size_t n) * Load a package and create the corresponding alpm_pkg_t struct. * @param handle the context handle * @param pkgfile path to the package file + * @param syncpkg package object to load verification data from (md5sum, + * sha256sum, and/or base64 signature) * @param full whether to stop the load after metadata is read or continue * through the full archive - * @param md5sum the expected md5sum of the package file if known - * @param sha256sum the expected sha256sum of the package file if known - * @param base64_sig the encoded signature of the package file if known * @param level the required level of signature verification * @return An information filled alpm_pkg_t struct */ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile, - int full, const char *md5sum, const char *sha256sum, const char *base64_sig, - alpm_siglevel_t level) + alpm_pkg_t *syncpkg, int full, alpm_siglevel_t level) { - int ret, skip_checksums, config = 0; + int ret, use_sig, config = 0; struct archive *archive; struct archive_entry *entry; alpm_pkg_t *newpkg = NULL; @@ -314,45 +312,49 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile, } /* can we get away with skipping checksums? */ - skip_checksums = 0; + use_sig = 0; if(level & ALPM_SIG_PACKAGE) { - if(base64_sig) { - skip_checksums = 1; + if(syncpkg && syncpkg->base64_sig) { + use_sig = 1; } else { char *sigpath = _alpm_sigpath(handle, pkgfile); if(sigpath && !_alpm_access(handle, NULL, sigpath, R_OK)) { - skip_checksums = 1; + use_sig = 1; } free(sigpath); } } - _alpm_log(handle, ALPM_LOG_DEBUG, "md5sum: %s\n", md5sum); - if(!skip_checksums && md5sum && !sha256sum) { - _alpm_log(handle, ALPM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile); - if(_alpm_test_checksum(pkgfile, md5sum, ALPM_CSUM_MD5) != 0) { - alpm_pkg_free(newpkg); - RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL); + if(syncpkg && !use_sig) { + if(syncpkg->md5sum && !syncpkg->sha256sum) { + _alpm_log(handle, ALPM_LOG_DEBUG, "md5sum: %s\n", syncpkg->md5sum); + _alpm_log(handle, ALPM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile); + if(_alpm_test_checksum(pkgfile, syncpkg->md5sum, ALPM_CSUM_MD5) != 0) { + alpm_pkg_free(newpkg); + RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL); + } } - } - _alpm_log(handle, ALPM_LOG_DEBUG, "sha256sum: %s\n", sha256sum); - if(!skip_checksums && sha256sum) { - _alpm_log(handle, ALPM_LOG_DEBUG, "checking sha256sum for %s\n", pkgfile); - if(_alpm_test_checksum(pkgfile, sha256sum, ALPM_CSUM_SHA256) != 0) { - alpm_pkg_free(newpkg); - RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL); + if(syncpkg->sha256sum) { + _alpm_log(handle, ALPM_LOG_DEBUG, "sha256sum: %s\n", syncpkg->sha256sum); + _alpm_log(handle, ALPM_LOG_DEBUG, "checking sha256sum for %s\n", pkgfile); + if(_alpm_test_checksum(pkgfile, syncpkg->sha256sum, ALPM_CSUM_SHA256) != 0) { + alpm_pkg_free(newpkg); + RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL); + } } } - _alpm_log(handle, ALPM_LOG_DEBUG, "base64_sig: %s\n", base64_sig); - if(level & ALPM_SIG_PACKAGE && - _alpm_check_pgp_helper(handle, pkgfile, base64_sig, - level & ALPM_SIG_PACKAGE_OPTIONAL, level & ALPM_SIG_PACKAGE_MARGINAL_OK, - level & ALPM_SIG_PACKAGE_UNKNOWN_OK)) { - handle->pm_errno = ALPM_ERR_PKG_INVALID_SIG; - _alpm_pkg_free(newpkg); - return NULL; + if(use_sig) { + const char *sig = syncpkg ? syncpkg->base64_sig : NULL; + _alpm_log(handle, ALPM_LOG_DEBUG, "sig data: %s\n", sig ? sig : "<from .sig>"); + if(_alpm_check_pgp_helper(handle, pkgfile, sig, + level & ALPM_SIG_PACKAGE_OPTIONAL, level & ALPM_SIG_PACKAGE_MARGINAL_OK, + level & ALPM_SIG_PACKAGE_UNKNOWN_OK)) { + handle->pm_errno = ALPM_ERR_PKG_INVALID_SIG; + _alpm_pkg_free(newpkg); + return NULL; + } } /* next- try to create an archive object to read in the package */ @@ -487,7 +489,7 @@ int SYMEXPORT alpm_pkg_load(alpm_handle_t *handle, const char *filename, int ful CHECK_HANDLE(handle, return -1); ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1)); - *pkg = _alpm_pkg_load_internal(handle, filename, full, NULL, NULL, NULL, level); + *pkg = _alpm_pkg_load_internal(handle, filename, NULL, full, level); if(*pkg == NULL) { /* pm_errno is set by pkg_load */ return -1; |