Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
check abi on pkg update
Baptiste Daroussin committed 13 years ago
commit 42a9122beec28eace435b78824aadeca589d1093
parent e2cdcbf51c904dd7c703b879cf49d98fa47506b5
4 files changed +45 -4
modified libpkg/pkg_add.c
@@ -167,7 +167,7 @@ pkg_add(struct pkgdb *db, const char *path, int flags)
	pkg_config_string(PKG_CONFIG_ABI, &myarch);
	pkg_get(pkg, PKG_ARCH, &arch, PKG_ORIGIN, &origin);

-
	if (fnmatch(myarch, arch, FNM_CASEFOLD) == FNM_NOMATCH) {
+
	if (fnmatch(arch, myarch, FNM_CASEFOLD) == FNM_NOMATCH) {
		pkg_emit_error("wrong architecture: %s instead of %s",
		    arch, myarch);
		if ((flags & PKG_ADD_FORCE) == 0) {
modified libpkg/pkgdb.c
@@ -66,7 +66,6 @@ static void pkgdb_pkglt(sqlite3_context *, int, sqlite3_value **);
static void pkgdb_pkggt(sqlite3_context *, int, sqlite3_value **);
static void pkgdb_pkgle(sqlite3_context *, int, sqlite3_value **);
static void pkgdb_pkgge(sqlite3_context *, int, sqlite3_value **);
-
static int get_pragma(sqlite3 *, const char *, int64_t *);
static int pkgdb_upgrade(struct pkgdb *);
static void populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg);
static int create_temporary_pkgjobs(sqlite3 *);
@@ -2340,7 +2339,7 @@ pkgdb_detach_remotes(sqlite3 *s)
	sbuf_delete(sql);
}

-
static int
+
int
get_pragma(sqlite3 *s, const char *sql, int64_t *res)
{
	sqlite3_stmt *stmt;
modified libpkg/private/pkg.h
@@ -255,6 +255,7 @@ int pkg_check_repo_version(struct pkgdb *db, const char *database);

/* pkgdb commands */
int sql_exec(sqlite3 *, const char *, ...);
+
int get_pragma(sqlite3 *, const char *sql, int64_t *res);

int pkgdb_load_deps(struct pkgdb *db, struct pkg *pkg);
int pkgdb_load_rdeps(struct pkgdb *db, struct pkg *pkg);
modified libpkg/update.c
@@ -38,8 +38,9 @@
#include "pkg.h"
#include "private/event.h"
#include "private/utils.h"
+
#include "private/pkgdb.h"

-
#define EXTRACT_ARCHIVE_FLAGS  (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM)
+
//#define EXTRACT_ARCHIVE_FLAGS  (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM)

/* Add indexes to the repo */
static int
@@ -79,6 +80,10 @@ pkg_update(const char *name, const char *packagesite, bool force)
	int rc = EPKG_FATAL, ret;
	struct stat st;
	time_t t = 0;
+
	sqlite3 *sqlite;
+
	char *archreq = NULL;
+
	const char *myarch;
+
	int64_t res;

	snprintf(url, MAXPATHLEN, "%s/repo.txz", packagesite);

@@ -168,8 +173,44 @@ pkg_update(const char *name, const char *packagesite, bool force)
		}
	}

+
	/* check is the repository is for valid architecture */
+
	sqlite3_initialize();
+

+
	if (sqlite3_open(repofile_unchecked, &sqlite) != SQLITE_OK) {
+
		unlink(repofile_unchecked);
+
		pkg_emit_error("Corrupted repository");
+
		rc = EPKG_FATAL;
+
		goto cleanup;
+
	}
+

+
	pkg_config_string(PKG_CONFIG_ABI, &myarch);
+

+
	archreq = sqlite3_mprintf("select count(arch) from packages "
+
	    "where arch not GLOB '%q'", myarch);
+
	if (get_pragma(sqlite, archreq, &res) != EPKG_OK) {
+
		sqlite3_free(archreq);
+
		pkg_emit_error("Unable to query repository");
+
		rc = EPKG_FATAL;
+
		sqlite3_close(sqlite);
+
		goto cleanup;
+
	}
+

+
	if (res > 0) {
+
		pkg_emit_error("At least one of the packages provided by"
+
		    "the repository is not compatible with your abi: %s",
+
		    myarch);
+
		rc = EPKG_FATAL;
+
		sqlite3_close(sqlite);
+
		goto cleanup;
+
	}
+

+
	sqlite3_close(sqlite);
+
	sqlite3_shutdown();
+

+

	if (rename(repofile_unchecked, repofile) != 0) {
		pkg_emit_errno("rename", "");
+
		rc = EPKG_FATAL;
		goto cleanup;
	}