2008-01-21 22:23:54 -05:00
|
|
|
/*
|
2011-06-19 00:24:06 -04:00
|
|
|
* be_package.c : backend for packages
|
2008-01-21 22:23:54 -05:00
|
|
|
*
|
2014-01-01 05:24:48 -05:00
|
|
|
* Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2008-01-21 22:23:54 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-05-11 17:49:01 -04:00
|
|
|
#include <errno.h>
|
2011-10-26 16:51:46 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2008-01-21 22:23:54 -05:00
|
|
|
|
|
|
|
/* libarchive */
|
|
|
|
#include <archive.h>
|
|
|
|
#include <archive_entry.h>
|
|
|
|
|
|
|
|
/* libalpm */
|
|
|
|
#include "alpm_list.h"
|
2011-06-07 14:46:11 -04:00
|
|
|
#include "alpm.h"
|
2013-01-28 20:23:25 -05:00
|
|
|
#include "libarchive-compat.h"
|
2008-01-21 22:23:54 -05:00
|
|
|
#include "util.h"
|
|
|
|
#include "log.h"
|
2011-06-03 13:13:22 -04:00
|
|
|
#include "handle.h"
|
2008-01-21 22:23:54 -05:00
|
|
|
#include "package.h"
|
2011-07-17 19:54:06 -04:00
|
|
|
#include "deps.h"
|
2012-07-12 16:29:59 -04:00
|
|
|
#include "filelist.h"
|
2008-01-21 22:23:54 -05:00
|
|
|
|
2011-11-14 00:45:55 -05:00
|
|
|
struct package_changelog {
|
|
|
|
struct archive *archive;
|
|
|
|
int fd;
|
|
|
|
};
|
|
|
|
|
2008-05-11 17:49:01 -04:00
|
|
|
/**
|
|
|
|
* Open a package changelog for reading. Similar to fopen in functionality,
|
|
|
|
* except that the returned 'file stream' is from an archive.
|
|
|
|
* @param pkg the package (file) to read the changelog
|
|
|
|
* @return a 'file stream' to the package changelog
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
static void *_package_changelog_open(alpm_pkg_t *pkg)
|
2008-05-11 17:49:01 -04:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2008-05-11 17:49:01 -04:00
|
|
|
|
2011-11-14 00:45:55 -05:00
|
|
|
struct package_changelog *changelog;
|
|
|
|
struct archive *archive;
|
2008-05-11 17:49:01 -04:00
|
|
|
struct archive_entry *entry;
|
|
|
|
const char *pkgfile = pkg->origin_data.file;
|
2011-11-14 00:45:55 -05:00
|
|
|
struct stat buf;
|
|
|
|
int fd;
|
2008-05-11 17:49:01 -04:00
|
|
|
|
2011-11-14 00:45:55 -05:00
|
|
|
fd = _alpm_open_archive(pkg->handle, pkgfile, &buf,
|
|
|
|
&archive, ALPM_ERR_PKG_OPEN);
|
|
|
|
if(fd < 0) {
|
|
|
|
return NULL;
|
2008-05-11 17:49:01 -04:00
|
|
|
}
|
|
|
|
|
2010-10-31 16:39:31 -04:00
|
|
|
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
|
2008-05-11 17:49:01 -04:00
|
|
|
const char *entry_name = archive_entry_pathname(entry);
|
|
|
|
|
|
|
|
if(strcmp(entry_name, ".CHANGELOG") == 0) {
|
2011-11-14 00:45:55 -05:00
|
|
|
changelog = malloc(sizeof(struct package_changelog));
|
|
|
|
if(!changelog) {
|
|
|
|
pkg->handle->pm_errno = ALPM_ERR_MEMORY;
|
2013-01-28 20:23:25 -05:00
|
|
|
_alpm_archive_read_free(archive);
|
2013-07-03 20:33:19 -04:00
|
|
|
close(fd);
|
2011-11-14 00:45:55 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
changelog->archive = archive;
|
|
|
|
changelog->fd = fd;
|
|
|
|
return changelog;
|
2008-05-11 17:49:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* we didn't find a changelog */
|
2013-01-28 20:23:25 -05:00
|
|
|
_alpm_archive_read_free(archive);
|
2013-07-03 20:33:19 -04:00
|
|
|
close(fd);
|
2008-05-11 17:49:01 -04:00
|
|
|
errno = ENOENT;
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2008-05-11 17:49:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read data from an open changelog 'file stream'. Similar to fread in
|
|
|
|
* functionality, this function takes a buffer and amount of data to read.
|
|
|
|
* @param ptr a buffer to fill with raw changelog data
|
|
|
|
* @param size the size of the buffer
|
|
|
|
* @param pkg the package that the changelog is being read from
|
|
|
|
* @param fp a 'file stream' to the package changelog
|
|
|
|
* @return the number of characters read, or 0 if there is no more data
|
|
|
|
*/
|
2010-12-18 09:15:05 -05:00
|
|
|
static size_t _package_changelog_read(void *ptr, size_t size,
|
2011-09-18 18:07:05 -04:00
|
|
|
const alpm_pkg_t UNUSED *pkg, void *fp)
|
2008-05-11 17:49:01 -04:00
|
|
|
{
|
2011-11-14 00:45:55 -05:00
|
|
|
struct package_changelog *changelog = fp;
|
|
|
|
ssize_t sret = archive_read_data(changelog->archive, ptr, size);
|
2008-05-11 17:49:01 -04:00
|
|
|
/* Report error (negative values) */
|
|
|
|
if(sret < 0) {
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(pkg->handle, ALPM_ERR_LIBARCHIVE, 0);
|
2008-05-11 17:49:01 -04:00
|
|
|
} else {
|
2011-03-20 20:45:57 -04:00
|
|
|
return (size_t)sret;
|
2008-05-11 17:49:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close a package changelog for reading. Similar to fclose in functionality,
|
|
|
|
* except that the 'file stream' is from an archive.
|
|
|
|
* @param pkg the package (file) that the changelog was read from
|
|
|
|
* @param fp a 'file stream' to the package changelog
|
|
|
|
* @return whether closing the package changelog stream was successful
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
static int _package_changelog_close(const alpm_pkg_t UNUSED *pkg, void *fp)
|
2008-05-11 17:49:01 -04:00
|
|
|
{
|
2011-11-14 00:45:55 -05:00
|
|
|
int ret;
|
|
|
|
struct package_changelog *changelog = fp;
|
2013-01-28 20:23:25 -05:00
|
|
|
ret = _alpm_archive_read_free(changelog->archive);
|
2013-07-03 20:33:19 -04:00
|
|
|
close(changelog->fd);
|
2011-11-14 00:45:55 -05:00
|
|
|
free(changelog);
|
|
|
|
return ret;
|
2008-05-11 17:49:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Package file operations struct accessor. We implement this as a method
|
|
|
|
* rather than a static struct as in be_files because we want to reuse the
|
|
|
|
* majority of the default_pkg_ops struct and add only a few operations of
|
2010-10-17 05:47:59 -04:00
|
|
|
* our own on top.
|
2008-05-11 17:49:01 -04:00
|
|
|
*/
|
2010-12-18 07:26:04 -05:00
|
|
|
static struct pkg_operations *get_file_pkg_ops(void)
|
2008-05-11 17:49:01 -04:00
|
|
|
{
|
2010-10-17 05:47:59 -04:00
|
|
|
static struct pkg_operations file_pkg_ops;
|
|
|
|
static int file_pkg_ops_initialized = 0;
|
|
|
|
if(!file_pkg_ops_initialized) {
|
|
|
|
file_pkg_ops = default_pkg_ops;
|
|
|
|
file_pkg_ops.changelog_open = _package_changelog_open;
|
|
|
|
file_pkg_ops.changelog_read = _package_changelog_read;
|
|
|
|
file_pkg_ops.changelog_close = _package_changelog_close;
|
|
|
|
file_pkg_ops_initialized = 1;
|
2008-05-11 17:49:01 -04:00
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return &file_pkg_ops;
|
2008-05-11 17:49:01 -04:00
|
|
|
}
|
|
|
|
|
2008-01-21 22:23:54 -05:00
|
|
|
/**
|
2011-06-28 09:26:39 -04:00
|
|
|
* Parses the package description file for a package into a alpm_pkg_t struct.
|
2008-01-21 22:23:54 -05:00
|
|
|
* @param archive the archive to read from, pointed at the .PKGINFO entry
|
2011-06-28 09:26:39 -04:00
|
|
|
* @param newpkg an empty alpm_pkg_t struct to fill with package info
|
2008-01-21 22:23:54 -05:00
|
|
|
*
|
2011-06-03 15:37:51 -04:00
|
|
|
* @return 0 on success, -1 on error
|
2008-01-21 22:23:54 -05:00
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *newpkg)
|
2008-01-21 22:23:54 -05:00
|
|
|
{
|
|
|
|
char *ptr = NULL;
|
|
|
|
char *key = NULL;
|
2011-06-03 15:37:51 -04:00
|
|
|
int ret, linenum = 0;
|
2010-12-14 23:26:23 -05:00
|
|
|
struct archive_read_buffer buf;
|
2008-01-21 22:23:54 -05:00
|
|
|
|
2010-12-14 23:26:23 -05:00
|
|
|
memset(&buf, 0, sizeof(buf));
|
|
|
|
/* 512K for a line length seems reasonable */
|
|
|
|
buf.max_line_size = 512 * 1024;
|
|
|
|
|
|
|
|
/* loop until we reach EOF or other error */
|
2011-06-03 15:37:51 -04:00
|
|
|
while((ret = _alpm_archive_fgets(a, &buf)) == ARCHIVE_OK) {
|
2012-05-28 17:32:11 -04:00
|
|
|
size_t len = _alpm_strip_newline(buf.line, buf.real_line_size);
|
2010-12-14 23:26:23 -05:00
|
|
|
|
2008-01-21 22:23:54 -05:00
|
|
|
linenum++;
|
2011-12-23 15:32:01 -05:00
|
|
|
key = buf.line;
|
|
|
|
if(len == 0 || key[0] == '#') {
|
2008-01-21 22:23:54 -05:00
|
|
|
continue;
|
|
|
|
}
|
2011-12-23 15:32:01 -05:00
|
|
|
/* line is always in this format: "key = value"
|
|
|
|
* we can be sure the " = " exists, so look for that */
|
|
|
|
ptr = memchr(key, ' ', len);
|
2012-01-01 23:31:46 -05:00
|
|
|
if(!ptr || (size_t)(ptr - key + 2) > len || memcmp(ptr, " = ", 3) != 0) {
|
2011-12-23 15:32:01 -05:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"%s: syntax error in description file line %d\n",
|
|
|
|
newpkg->name ? newpkg->name : "error", linenum);
|
2008-01-21 22:23:54 -05:00
|
|
|
} else {
|
2011-12-23 15:32:01 -05:00
|
|
|
/* NULL the end of the key portion, move ptr to start of value */
|
|
|
|
*ptr = '\0';
|
|
|
|
ptr += 3;
|
2010-06-19 04:55:08 -04:00
|
|
|
if(strcmp(key, "pkgname") == 0) {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->name, ptr, return -1);
|
2010-12-14 13:06:31 -05:00
|
|
|
newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);
|
2011-01-28 18:34:06 -05:00
|
|
|
} else if(strcmp(key, "pkgbase") == 0) {
|
|
|
|
/* not used atm */
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "pkgver") == 0) {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->version, ptr, return -1);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "pkgdesc") == 0) {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->desc, ptr, return -1);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "group") == 0) {
|
2008-01-21 22:23:54 -05:00
|
|
|
newpkg->groups = alpm_list_add(newpkg->groups, strdup(ptr));
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "url") == 0) {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->url, ptr, return -1);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "license") == 0) {
|
2008-01-21 22:23:54 -05:00
|
|
|
newpkg->licenses = alpm_list_add(newpkg->licenses, strdup(ptr));
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "builddate") == 0) {
|
2011-01-07 21:35:43 -05:00
|
|
|
newpkg->builddate = _alpm_parsedate(ptr);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "packager") == 0) {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->packager, ptr, return -1);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "arch") == 0) {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->arch, ptr, return -1);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "size") == 0) {
|
2008-01-21 22:23:54 -05:00
|
|
|
/* size in the raw package is uncompressed (installed) size */
|
2011-08-29 13:12:54 -04:00
|
|
|
newpkg->isize = _alpm_strtoofft(ptr);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "depend") == 0) {
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *dep = _alpm_splitdep(ptr);
|
2008-01-21 22:23:54 -05:00
|
|
|
newpkg->depends = alpm_list_add(newpkg->depends, dep);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "optdepend") == 0) {
|
2011-07-17 19:54:06 -04:00
|
|
|
alpm_depend_t *optdep = _alpm_splitdep(ptr);
|
|
|
|
newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
|
2013-11-01 08:13:46 -04:00
|
|
|
} else if(strcmp(key, "makedepend") == 0) {
|
|
|
|
/* not used atm */
|
|
|
|
} else if(strcmp(key, "checkdepend") == 0) {
|
|
|
|
/* not used atm */
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "conflict") == 0) {
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_depend_t *conflict = _alpm_splitdep(ptr);
|
|
|
|
newpkg->conflicts = alpm_list_add(newpkg->conflicts, conflict);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "replaces") == 0) {
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_depend_t *replace = _alpm_splitdep(ptr);
|
|
|
|
newpkg->replaces = alpm_list_add(newpkg->replaces, replace);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "provides") == 0) {
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_depend_t *provide = _alpm_splitdep(ptr);
|
|
|
|
newpkg->provides = alpm_list_add(newpkg->provides, provide);
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "backup") == 0) {
|
2011-06-28 00:39:43 -04:00
|
|
|
alpm_backup_t *backup;
|
|
|
|
CALLOC(backup, 1, sizeof(alpm_backup_t), return -1);
|
2011-06-16 14:15:11 -04:00
|
|
|
STRDUP(backup->name, ptr, return -1);
|
|
|
|
newpkg->backup = alpm_list_add(newpkg->backup, backup);
|
2011-01-28 18:34:06 -05:00
|
|
|
} else if(strcmp(key, "force") == 0) {
|
|
|
|
/* deprecated, skip it */
|
2010-06-19 04:55:08 -04:00
|
|
|
} else if(strcmp(key, "makepkgopt") == 0) {
|
2009-09-12 16:47:27 -04:00
|
|
|
/* not used atm */
|
2008-01-21 22:23:54 -05:00
|
|
|
} else {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "%s: unknown key '%s' in description file line %d\n",
|
2011-01-28 18:34:06 -05:00
|
|
|
newpkg->name ? newpkg->name : "error", key, linenum);
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-03 15:37:51 -04:00
|
|
|
if(ret != ARCHIVE_EOF) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "error parsing package descfile\n");
|
2011-06-03 15:37:51 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2008-01-21 22:23:54 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-19 21:40:32 -04:00
|
|
|
* Validate a package.
|
2011-06-07 14:46:11 -04:00
|
|
|
* @param handle the context handle
|
2008-01-21 22:23:54 -05:00
|
|
|
* @param pkgfile path to the package file
|
2011-08-25 17:40:39 -04:00
|
|
|
* @param syncpkg package object to load verification data from (md5sum,
|
|
|
|
* sha256sum, and/or base64 signature)
|
2011-08-11 21:16:42 -04:00
|
|
|
* @param level the required level of signature verification
|
2011-09-20 00:28:05 -04:00
|
|
|
* @param sigdata signature data from the package to pass back
|
2012-02-18 01:31:37 -05:00
|
|
|
* @param validation successful validations performed on the package file
|
2011-09-19 21:40:32 -04:00
|
|
|
* @return 0 if package is fully valid, -1 and pm_errno otherwise
|
2008-01-21 22:23:54 -05:00
|
|
|
*/
|
2011-09-19 21:40:32 -04:00
|
|
|
int _alpm_pkg_validate_internal(alpm_handle_t *handle,
|
2011-09-20 00:28:05 -04:00
|
|
|
const char *pkgfile, alpm_pkg_t *syncpkg, alpm_siglevel_t level,
|
2012-02-18 01:31:37 -05:00
|
|
|
alpm_siglist_t **sigdata, alpm_pkgvalidation_t *validation)
|
2008-01-21 22:23:54 -05:00
|
|
|
{
|
2011-09-19 21:40:32 -04:00
|
|
|
int has_sig;
|
2011-09-20 17:52:18 -04:00
|
|
|
handle->pm_errno = 0;
|
2008-01-21 22:23:54 -05:00
|
|
|
|
|
|
|
if(pkgfile == NULL || strlen(pkgfile) == 0) {
|
2011-09-19 21:40:32 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1);
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
|
2011-09-19 21:40:32 -04:00
|
|
|
/* attempt to access the package file, ensure it exists */
|
2012-02-07 12:43:59 -05:00
|
|
|
if(_alpm_access(handle, NULL, pkgfile, R_OK) != 0) {
|
2012-04-07 12:29:11 -04:00
|
|
|
if(errno == ENOENT) {
|
|
|
|
handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
|
|
|
|
} else if(errno == EACCES) {
|
|
|
|
handle->pm_errno = ALPM_ERR_BADPERMS;
|
|
|
|
} else {
|
|
|
|
handle->pm_errno = ALPM_ERR_PKG_OPEN;
|
|
|
|
}
|
|
|
|
return -1;
|
2008-05-28 17:25:40 -04:00
|
|
|
}
|
|
|
|
|
2011-08-15 09:56:58 -04:00
|
|
|
/* can we get away with skipping checksums? */
|
2011-09-07 16:02:52 -04:00
|
|
|
has_sig = 0;
|
2011-08-15 09:56:58 -04:00
|
|
|
if(level & ALPM_SIG_PACKAGE) {
|
2011-08-25 17:40:39 -04:00
|
|
|
if(syncpkg && syncpkg->base64_sig) {
|
2011-09-07 16:02:52 -04:00
|
|
|
has_sig = 1;
|
2011-08-15 09:56:58 -04:00
|
|
|
} else {
|
|
|
|
char *sigpath = _alpm_sigpath(handle, pkgfile);
|
|
|
|
if(sigpath && !_alpm_access(handle, NULL, sigpath, R_OK)) {
|
2011-09-07 16:02:52 -04:00
|
|
|
has_sig = 1;
|
2011-08-15 09:56:58 -04:00
|
|
|
}
|
|
|
|
free(sigpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-07 16:02:52 -04:00
|
|
|
if(syncpkg && !has_sig) {
|
2011-08-25 17:40:39 -04:00
|
|
|
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);
|
2012-02-19 23:24:35 -05:00
|
|
|
if(_alpm_test_checksum(pkgfile, syncpkg->md5sum, ALPM_PKG_VALIDATION_MD5SUM) != 0) {
|
2011-09-19 21:40:32 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, -1);
|
2011-08-25 17:40:39 -04:00
|
|
|
}
|
2012-02-18 01:31:37 -05:00
|
|
|
if(validation) {
|
|
|
|
*validation |= ALPM_PKG_VALIDATION_MD5SUM;
|
|
|
|
}
|
2011-08-11 21:16:42 -04:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:40:39 -04:00
|
|
|
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);
|
2012-02-19 23:24:35 -05:00
|
|
|
if(_alpm_test_checksum(pkgfile, syncpkg->sha256sum, ALPM_PKG_VALIDATION_SHA256SUM) != 0) {
|
2011-09-19 21:40:32 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, -1);
|
2011-08-25 17:40:39 -04:00
|
|
|
}
|
2012-02-18 01:31:37 -05:00
|
|
|
if(validation) {
|
|
|
|
*validation |= ALPM_PKG_VALIDATION_SHA256SUM;
|
|
|
|
}
|
2011-04-22 00:39:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-07 16:02:52 -04:00
|
|
|
/* even if we don't have a sig, run the check code if level tells us to */
|
2013-05-19 08:41:01 -04:00
|
|
|
if(level & ALPM_SIG_PACKAGE) {
|
2011-08-25 17:40:39 -04:00
|
|
|
const char *sig = syncpkg ? syncpkg->base64_sig : NULL;
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "sig data: %s\n", sig ? sig : "<from .sig>");
|
2013-05-19 08:41:01 -04:00
|
|
|
if(!has_sig && !(level & ALPM_SIG_PACKAGE_OPTIONAL)) {
|
|
|
|
handle->pm_errno = ALPM_ERR_PKG_MISSING_SIG;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-25 17:40:39 -04:00
|
|
|
if(_alpm_check_pgp_helper(handle, pkgfile, sig,
|
|
|
|
level & ALPM_SIG_PACKAGE_OPTIONAL, level & ALPM_SIG_PACKAGE_MARGINAL_OK,
|
2011-09-20 00:28:05 -04:00
|
|
|
level & ALPM_SIG_PACKAGE_UNKNOWN_OK, sigdata)) {
|
2011-08-25 17:40:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_PKG_INVALID_SIG;
|
2011-09-19 21:40:32 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2012-02-18 01:31:37 -05:00
|
|
|
if(validation && has_sig) {
|
|
|
|
*validation |= ALPM_PKG_VALIDATION_SIGNATURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 16:48:53 -05:00
|
|
|
if(validation && !*validation) {
|
2012-02-18 01:31:37 -05:00
|
|
|
*validation = ALPM_PKG_VALIDATION_NONE;
|
2011-09-19 21:40:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a package and create the corresponding alpm_pkg_t struct.
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param pkgfile path to the package file
|
|
|
|
* @param full whether to stop the load after metadata is read or continue
|
|
|
|
* through the full archive
|
|
|
|
*/
|
|
|
|
alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
|
|
|
|
const char *pkgfile, int full)
|
|
|
|
{
|
2011-10-26 16:51:46 -04:00
|
|
|
int ret, fd, config = 0;
|
2011-09-19 21:40:32 -04:00
|
|
|
struct archive *archive;
|
|
|
|
struct archive_entry *entry;
|
2012-01-08 12:53:22 -05:00
|
|
|
alpm_pkg_t *newpkg;
|
2011-09-19 21:40:32 -04:00
|
|
|
struct stat st;
|
2012-02-29 17:47:39 -05:00
|
|
|
size_t files_size = 0;
|
2011-09-19 21:40:32 -04:00
|
|
|
|
|
|
|
if(pkgfile == NULL || strlen(pkgfile) == 0) {
|
|
|
|
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL);
|
|
|
|
}
|
|
|
|
|
2011-11-14 00:45:55 -05:00
|
|
|
fd = _alpm_open_archive(handle, pkgfile, &st, &archive, ALPM_ERR_PKG_OPEN);
|
|
|
|
if(fd < 0) {
|
|
|
|
if(errno == ENOENT) {
|
2011-10-26 16:51:46 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
|
2012-04-07 12:29:11 -04:00
|
|
|
} else if(errno == EACCES) {
|
|
|
|
handle->pm_errno = ALPM_ERR_BADPERMS;
|
|
|
|
} else {
|
|
|
|
handle->pm_errno = ALPM_ERR_PKG_OPEN;
|
2011-10-26 16:51:46 -04:00
|
|
|
}
|
2012-01-08 12:53:22 -05:00
|
|
|
return NULL;
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
|
2011-10-26 16:51:46 -04:00
|
|
|
newpkg = _alpm_pkg_new();
|
|
|
|
if(newpkg == NULL) {
|
|
|
|
handle->pm_errno = ALPM_ERR_MEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
STRDUP(newpkg->filename, pkgfile,
|
|
|
|
handle->pm_errno = ALPM_ERR_MEMORY; goto error);
|
|
|
|
newpkg->size = st.st_size;
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
|
2011-01-11 21:16:54 -05:00
|
|
|
|
2008-01-21 22:23:54 -05:00
|
|
|
/* If full is false, only read through the archive until we find our needed
|
|
|
|
* metadata. If it is true, read through the entire archive, which serves
|
2013-04-14 22:33:46 -04:00
|
|
|
* as a verification of integrity and allows us to create the filelist. */
|
2008-01-21 22:23:54 -05:00
|
|
|
while((ret = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) {
|
|
|
|
const char *entry_name = archive_entry_pathname(entry);
|
|
|
|
|
|
|
|
if(strcmp(entry_name, ".PKGINFO") == 0) {
|
|
|
|
/* parse the info file */
|
2011-06-07 17:13:58 -04:00
|
|
|
if(parse_descfile(handle, archive, newpkg) != 0) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("could not parse package description file in %s\n"),
|
2008-01-21 22:23:54 -05:00
|
|
|
pkgfile);
|
|
|
|
goto pkg_invalid;
|
|
|
|
}
|
|
|
|
if(newpkg->name == NULL || strlen(newpkg->name) == 0) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("missing package name in %s\n"), pkgfile);
|
2008-01-21 22:23:54 -05:00
|
|
|
goto pkg_invalid;
|
|
|
|
}
|
|
|
|
if(newpkg->version == NULL || strlen(newpkg->version) == 0) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("missing package version in %s\n"), pkgfile);
|
2008-01-21 22:23:54 -05:00
|
|
|
goto pkg_invalid;
|
|
|
|
}
|
2013-10-14 07:04:22 -04:00
|
|
|
if(strchr(newpkg->version, '-') == NULL) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("invalid package version in %s\n"), pkgfile);
|
|
|
|
goto pkg_invalid;
|
|
|
|
}
|
2008-01-21 22:23:54 -05:00
|
|
|
config = 1;
|
|
|
|
continue;
|
2013-11-08 00:44:40 -05:00
|
|
|
} else if(strcmp(entry_name, ".INSTALL") == 0) {
|
2008-01-21 22:23:54 -05:00
|
|
|
newpkg->scriptlet = 1;
|
|
|
|
} else if(*entry_name == '.') {
|
|
|
|
/* for now, ignore all files starting with '.' that haven't
|
|
|
|
* already been handled (for future possibilities) */
|
2011-02-16 21:56:32 -05:00
|
|
|
} else if(full) {
|
2012-02-29 17:47:39 -05:00
|
|
|
const size_t files_count = newpkg->files.count;
|
|
|
|
alpm_file_t *current_file;
|
2008-01-21 22:23:54 -05:00
|
|
|
/* Keep track of all files for filelist generation */
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
if(files_count >= files_size) {
|
|
|
|
size_t old_size = files_size;
|
2012-02-29 17:47:39 -05:00
|
|
|
alpm_file_t *newfiles;
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
if(files_size == 0) {
|
|
|
|
files_size = 4;
|
|
|
|
} else {
|
|
|
|
files_size *= 2;
|
|
|
|
}
|
2012-02-29 17:47:39 -05:00
|
|
|
newfiles = realloc(newpkg->files.files,
|
|
|
|
sizeof(alpm_file_t) * files_size);
|
|
|
|
if(!newfiles) {
|
2012-04-30 00:40:06 -04:00
|
|
|
_alpm_alloc_fail(sizeof(alpm_file_t) * files_size);
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* ensure all new memory is zeroed out, in both the initial
|
|
|
|
* allocation and later reallocs */
|
2012-02-29 17:47:39 -05:00
|
|
|
memset(newfiles + old_size, 0,
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
sizeof(alpm_file_t) * (files_size - old_size));
|
2012-02-29 17:47:39 -05:00
|
|
|
newpkg->files.files = newfiles;
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
}
|
2012-02-29 17:47:39 -05:00
|
|
|
current_file = newpkg->files.files + files_count;
|
|
|
|
STRDUP(current_file->name, entry_name, goto error);
|
|
|
|
current_file->size = archive_entry_size(entry);
|
|
|
|
current_file->mode = archive_entry_mode(entry);
|
|
|
|
newpkg->files.count++;
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(archive_read_data_skip(archive)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"),
|
2008-01-21 22:23:54 -05:00
|
|
|
pkgfile, archive_error_string(archive));
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_LIBARCHIVE;
|
2008-01-21 22:23:54 -05:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we are not doing a full read, see if we have all we need */
|
|
|
|
if(!full && config) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-14 22:33:46 -04:00
|
|
|
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occurred */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"),
|
2008-01-21 22:23:54 -05:00
|
|
|
pkgfile, archive_error_string(archive));
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_LIBARCHIVE;
|
2008-01-21 22:23:54 -05:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!config) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("missing package metadata in %s\n"), pkgfile);
|
2008-01-21 22:23:54 -05:00
|
|
|
goto pkg_invalid;
|
|
|
|
}
|
|
|
|
|
2013-01-28 20:23:25 -05:00
|
|
|
_alpm_archive_read_free(archive);
|
2013-07-03 20:33:19 -04:00
|
|
|
close(fd);
|
2008-01-21 22:23:54 -05:00
|
|
|
|
|
|
|
/* internal fields for package struct */
|
2012-04-01 01:37:19 -04:00
|
|
|
newpkg->origin = ALPM_PKG_FROM_FILE;
|
2008-01-21 22:23:54 -05:00
|
|
|
newpkg->origin_data.file = strdup(pkgfile);
|
2008-05-11 17:49:01 -04:00
|
|
|
newpkg->ops = get_file_pkg_ops();
|
2011-06-03 13:13:22 -04:00
|
|
|
newpkg->handle = handle;
|
2011-10-26 16:44:55 -04:00
|
|
|
newpkg->infolevel = INFRQ_BASE | INFRQ_DESC | INFRQ_SCRIPTLET;
|
2012-02-18 01:31:37 -05:00
|
|
|
newpkg->validation = ALPM_PKG_VALIDATION_NONE;
|
2008-01-21 22:23:54 -05:00
|
|
|
|
|
|
|
if(full) {
|
2012-02-29 17:47:39 -05:00
|
|
|
if(newpkg->files.files) {
|
2011-10-26 16:44:55 -04:00
|
|
|
/* attempt to hand back any memory we don't need */
|
2012-02-29 17:47:39 -05:00
|
|
|
newpkg->files.files = realloc(newpkg->files.files,
|
|
|
|
sizeof(alpm_file_t) * newpkg->files.count);
|
2011-10-26 16:44:55 -04:00
|
|
|
/* "checking for conflicts" requires a sorted list, ensure that here */
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"sorting package filelist for %s\n", pkgfile);
|
2012-07-11 09:59:49 -04:00
|
|
|
|
|
|
|
qsort(newpkg->files.files, newpkg->files.count,
|
|
|
|
sizeof(alpm_file_t), _alpm_files_cmp);
|
2011-10-26 16:44:55 -04:00
|
|
|
}
|
|
|
|
newpkg->infolevel |= INFRQ_FILES;
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return newpkg;
|
2008-01-21 22:23:54 -05:00
|
|
|
|
|
|
|
pkg_invalid:
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_PKG_INVALID;
|
2008-01-21 22:23:54 -05:00
|
|
|
error:
|
|
|
|
_alpm_pkg_free(newpkg);
|
2013-01-28 20:23:25 -05:00
|
|
|
_alpm_archive_read_free(archive);
|
2011-10-26 16:51:46 -04:00
|
|
|
if(fd >= 0) {
|
2013-07-03 20:33:19 -04:00
|
|
|
close(fd);
|
2011-10-26 16:51:46 -04:00
|
|
|
}
|
2008-01-21 22:23:54 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
|
2012-11-02 11:16:32 -04:00
|
|
|
static int read_sigfile(const char *sigpath, unsigned char **sig)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if(stat(sigpath, &st) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
MALLOC(*sig, st.st_size, return -1);
|
|
|
|
|
|
|
|
if((fp = fopen(sigpath, "rb")) == NULL) {
|
|
|
|
free(*sig);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fread(*sig, st.st_size, 1, fp) != 1) {
|
|
|
|
free(*sig);
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return st.st_size;
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:04:00 -04:00
|
|
|
int SYMEXPORT alpm_pkg_load(alpm_handle_t *handle, const char *filename, int full,
|
2011-06-27 17:29:49 -04:00
|
|
|
alpm_siglevel_t level, alpm_pkg_t **pkg)
|
2008-01-21 22:23:54 -05:00
|
|
|
{
|
2012-02-18 01:31:37 -05:00
|
|
|
alpm_pkgvalidation_t validation = 0;
|
2013-02-13 18:54:28 -05:00
|
|
|
char *sigpath;
|
2012-02-18 01:31:37 -05:00
|
|
|
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return -1);
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
2008-01-21 22:23:54 -05:00
|
|
|
|
2013-02-13 18:54:28 -05:00
|
|
|
sigpath = _alpm_sigpath(handle, filename);
|
2012-11-02 11:16:32 -04:00
|
|
|
if(sigpath && !_alpm_access(handle, NULL, sigpath, R_OK)) {
|
|
|
|
if(level & ALPM_SIG_PACKAGE) {
|
|
|
|
alpm_list_t *keys = NULL;
|
|
|
|
int fail = 0;
|
|
|
|
unsigned char *sig = NULL;
|
|
|
|
int len = read_sigfile(sigpath, &sig);
|
2013-02-13 18:54:28 -05:00
|
|
|
|
2012-11-02 11:16:32 -04:00
|
|
|
if(len == -1) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR,
|
|
|
|
_("failed to read signature file: %s\n"), sigpath);
|
|
|
|
free(sigpath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-15 01:53:51 -04:00
|
|
|
if(alpm_extract_keyid(handle, filename, sig, len, &keys) == 0) {
|
2012-11-02 11:16:32 -04:00
|
|
|
alpm_list_t *k;
|
|
|
|
for(k = keys; k; k = k->next) {
|
|
|
|
char *key = k->data;
|
|
|
|
if(_alpm_key_in_keychain(handle, key) == 0) {
|
|
|
|
if(_alpm_key_import(handle, key) == -1) {
|
|
|
|
fail = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FREELIST(keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(sig);
|
|
|
|
|
|
|
|
if(fail) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("required key missing from keyring\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(sigpath);
|
|
|
|
|
2012-02-18 01:31:37 -05:00
|
|
|
if(_alpm_pkg_validate_internal(handle, filename, NULL, level, NULL,
|
|
|
|
&validation) == -1) {
|
2011-09-19 21:40:32 -04:00
|
|
|
/* pm_errno is set by pkg_validate */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*pkg = _alpm_pkg_load_internal(handle, filename, full);
|
2008-01-21 22:23:54 -05:00
|
|
|
if(*pkg == NULL) {
|
|
|
|
/* pm_errno is set by pkg_load */
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
2012-02-18 01:31:37 -05:00
|
|
|
(*pkg)->validation = validation;
|
2008-01-21 22:23:54 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2008-01-21 22:23:54 -05:00
|
|
|
}
|
|
|
|
|
2014-01-22 18:06:11 -05:00
|
|
|
/* vim: set noet: */
|