Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Uses has to figure out manifest keys.
Baptiste Daroussin committed 13 years ago
commit 37e975b4267958e2279fac1b23f19b9ebea38c42
parent 04a79c9
14 files changed +143 -51
modified libpkg/pkg.c
@@ -1040,13 +1040,13 @@ pkg_list_free(struct pkg *pkg, pkg_list list) {
}

int
-
pkg_open(struct pkg **pkg_p, const char *path)
+
pkg_open(struct pkg **pkg_p, const char *path, struct pkg_manifest_key *keys)
{
	struct archive *a;
	struct archive_entry *ae;
	int ret;

-
	ret = pkg_open2(pkg_p, &a, &ae, path);
+
	ret = pkg_open2(pkg_p, &a, &ae, path, keys);

	if (ret != EPKG_OK && ret != EPKG_END)
		return (EPKG_FATAL);
@@ -1057,7 +1057,7 @@ pkg_open(struct pkg **pkg_p, const char *path)
}

int
-
pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, const char *path)
+
pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, const char *path, struct pkg_manifest_key *keys)
{
	struct pkg *pkg;
	pkg_error_t retcode = EPKG_OK;
@@ -1135,7 +1135,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con

			sbuf_finish(manifest);

-
			ret = pkg_parse_manifest(pkg, sbuf_get(manifest));
+
			ret = pkg_parse_manifest(pkg, sbuf_get(manifest), keys);
			if (ret != EPKG_OK) {
				retcode = EPKG_FATAL;
				goto cleanup;
modified libpkg/pkg.h.in
@@ -82,6 +82,8 @@ struct pkg_config_value;

struct pkg_plugin;

+
struct pkg_manifest_key;
+

/**
 * The system-wide pkg(1) status: ie. is it a) installed or otherwise
 * available on the sysem, b) database (local.sqlite) initialised and
@@ -484,7 +486,7 @@ int pkg_is_valid(struct pkg *);
 * NULL pointer, the function allocate a new pkg using pkg_new().
 * @param path The path to the local package archive.
 */
-
int pkg_open(struct pkg **p, const char *path);
+
int pkg_open(struct pkg **p, const char *path, struct pkg_manifest_key *keys);

/**
 * @return the type of the package.
@@ -777,9 +779,11 @@ int pkg_delannotation(struct pkg *pkg, const char *tag);
 * @param buf An NULL-terminated buffer containing the manifest data.
 * @return An error code.
 */
-
int pkg_parse_manifest(struct pkg *pkg, char *buf);
-
int pkg_parse_manifest_file(struct pkg *pkg, FILE *f);
-
int pkg_load_manifest_file(struct pkg *pkg, const char *fpath);
+
int pkg_parse_manifest(struct pkg *pkg, char *buf, struct pkg_manifest_key *key);
+
int pkg_parse_manifest_file(struct pkg *pkg, FILE *f, struct pkg_manifest_key *key);
+
int pkg_load_manifest_file(struct pkg *pkg, const char *fpath, struct pkg_manifest_key *key);
+
int pkg_manifest_keys_new(struct pkg_manifest_key **k);
+
void pkg_manifest_keys_free(struct pkg_manifest_key *k);

/**
 * Emit a manifest according to the attributes of pkg.
@@ -1020,7 +1024,7 @@ int pkgdb_compact(struct pkgdb *db);
 * @param path The path to the package archive file on the local disk
 * @return An error code.
 */
-
int pkg_add(struct pkgdb *db, const char *path, unsigned flags);
+
int pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_key *keys);

#define PKG_ADD_UPGRADE			(1U << 0)
#define PKG_ADD_USE_UPGRADE_SCRIPTS	(1U << 1)
modified libpkg/pkg_add.c
@@ -149,7 +149,7 @@ cleanup:
}

int
-
pkg_add(struct pkgdb *db, const char *path, unsigned flags)
+
pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_key *keys)
{
	const char	*arch;
	const char	*myarch;
@@ -177,7 +177,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	 * current archive_entry to the first non-meta file.
	 * If there is no non-meta files, EPKG_END is returned.
	 */
-
	ret = pkg_open2(&pkg, &a, &ae, path);
+
	ret = pkg_open2(&pkg, &a, &ae, path, keys);
	if (ret == EPKG_END)
		extract = false;
	else if (ret != EPKG_OK) {
@@ -254,7 +254,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)

			if ((flags & PKG_ADD_UPGRADE) == 0 &&
			    access(dpath, F_OK) == 0) {
-
				ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC);
+
				ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC, keys);
				if (ret != EPKG_OK) {
					retcode = EPKG_FATAL;
					goto cleanup;
modified libpkg/pkg_create.c
@@ -218,6 +218,7 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
	regmatch_t	 pmatch[2];
	size_t		 size;
	char		*www = NULL;
+
	struct pkg_manifest_key *keys = NULL;

	/* Load the manifest from the metadata directory */
	if (snprintf(path, sizeof(path), "%s/+MANIFEST", md_dir) == -1)
@@ -228,7 +229,8 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
		goto cleanup;
	}

-
	if ((ret = pkg_load_manifest_file(pkg, path)) != EPKG_OK) {
+
	pkg_manifest_keys_new(&keys);
+
	if ((ret = pkg_load_manifest_file(pkg, path, keys)) != EPKG_OK) {
		ret = EPKG_FATAL;
		goto cleanup;
	}
@@ -330,6 +332,7 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
cleanup:
	free(pkg);
	free(manifest);
+
	pkg_manifest_keys_free(keys);
	if (ret == EPKG_OK)
		ret = packing_finish(pkg_archive);
	return ret;
modified libpkg/pkg_jobs.c
@@ -366,6 +366,7 @@ pkg_jobs_install(struct pkg_jobs *j)
	struct pkg *pkg_temp = NULL;
	struct pkgdb_it *it = NULL;
	struct pkg *pkg_queue = NULL;
+
	struct pkg_manifest_key *keys = NULL;
	char path[MAXPATHLEN + 1];
	const char *cachedir = NULL;
	int flags = 0;
@@ -387,6 +388,7 @@ pkg_jobs_install(struct pkg_jobs *j)
	pkg_config_bool(PKG_CONFIG_HANDLE_RC_SCRIPTS, &handle_rc);

	p = NULL;
+
	pkg_manifest_keys_new(&keys);
	/* Install */
	pkgdb_transaction_begin(j->db->sqlite, "upgrade");

@@ -466,7 +468,7 @@ pkg_jobs_install(struct pkg_jobs *j)
		}
		snprintf(path, sizeof(path), "%s/%s", cachedir, pkgrepopath);

-
		pkg_open(&newpkg, path);
+
		pkg_open(&newpkg, path, keys);
		if (newversion != NULL) {
			pkg_emit_upgrade_begin(p);
		} else {
@@ -497,7 +499,7 @@ pkg_jobs_install(struct pkg_jobs *j)
		if (automatic)
			flags |= PKG_ADD_AUTOMATIC;

-
		if (pkg_add(j->db, path, flags) != EPKG_OK) {
+
		if (pkg_add(j->db, path, flags, keys) != EPKG_OK) {
			pkgdb_transaction_rollback(j->db->sqlite, "upgrade");
			goto cleanup;
		}
@@ -518,6 +520,7 @@ pkg_jobs_install(struct pkg_jobs *j)
	cleanup:
	pkgdb_transaction_commit(j->db->sqlite, "upgrade");
	pkg_free(newpkg);
+
	pkg_manifest_keys_free(keys);

	return (retcode);
}
@@ -605,6 +608,7 @@ pkg_jobs_fetch(struct pkg_jobs *j)
	const char *repopath = NULL;
	char cachedpath[MAXPATHLEN];
	int ret = EPKG_OK;
+
	struct pkg_manifest_key *keys = NULL;
	
	if (pkg_config_string(PKG_CONFIG_CACHEDIR, &cachedir) != EPKG_OK)
		return (EPKG_FATAL);
@@ -655,19 +659,21 @@ pkg_jobs_fetch(struct pkg_jobs *j)
	/* integrity checking */
	pkg_emit_integritycheck_begin();

+
	pkg_manifest_keys_new(&keys);
	while (pkg_jobs(j, &p) == EPKG_OK) {
		const char *pkgrepopath;

		pkg_get(p, PKG_REPOPATH, &pkgrepopath);
		snprintf(path, sizeof(path), "%s/%s", cachedir,
		    pkgrepopath);
-
		if (pkg_open(&pkg, path) != EPKG_OK) {
+
		if (pkg_open(&pkg, path, keys) != EPKG_OK) {
			return (EPKG_FATAL);
		}

		if (pkgdb_integrity_append(j->db, pkg) != EPKG_OK)
			ret = EPKG_FATAL;
	}
+
	pkg_manifest_keys_free(keys);

	pkg_free(pkg);

modified libpkg/pkg_manifest.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
+
 * Copyright (c) 2011-2013 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * All rights reserved.
 * 
@@ -114,6 +114,65 @@ static struct manifest_key {
	{ NULL, -99, -99, NULL}
};

+
struct dataparser {
+
	yaml_node_type_t type;
+
	int (*parse_data)(struct pkg *, yaml_node_t *, yaml_document_t *, int);
+
	UT_hash_handle hh;
+
};
+

+
struct pkg_manifest_key {
+
	const char *key;
+
	int type;
+
	struct dataparser *parser;
+
	UT_hash_handle hh;
+
};
+

+
int
+
pkg_manifest_keys_new(struct pkg_manifest_key **key)
+
{
+
	int i;
+
	struct pkg_manifest_key *k;
+
	struct dataparser *dp;
+

+
	if (*key != NULL)
+
		return (EPKG_OK);
+

+
	for (i = 0; manifest_keys[i].key != NULL; i++) {
+
		HASH_FIND_STR(*key, manifest_keys[i].key, k);
+
		if (k == NULL) {
+
			k = calloc(1, sizeof(struct pkg_manifest_key));
+
			k->key = manifest_keys[i].key;
+
			k->type = manifest_keys[i].type;
+
			HASH_ADD_KEYPTR(hh, *key, k->key, strlen(k->key), k);
+
		}
+
		HASH_FIND_YAMLT(k->parser, &manifest_keys[i].valid_type, dp);
+
		if (dp != NULL)
+
			continue;
+
		dp = calloc(1, sizeof(struct dataparser));
+
		dp->type = manifest_keys[i].valid_type;
+
		dp->parse_data = manifest_keys[i].parse_data;
+
		HASH_ADD_YAMLT(k->parser, type, dp);
+
	}
+

+
	return (EPKG_OK);
+
}
+

+
static void
+
pmk_free(struct pkg_manifest_key *key) {
+
	HASH_FREE(key->parser, dataparser, free);
+

+
	free(key);
+
}
+

+
void
+
pkg_manifest_keys_free(struct pkg_manifest_key *key)
+
{
+
	if (key == NULL)
+
		return;
+

+
	HASH_FREE(key, pkg_manifest_key, pmk_free);
+
}
+

static int
is_valid_yaml_scalar(yaml_node_t *val)
{
@@ -182,7 +241,7 @@ urldecode(const char *src, struct sbuf **dest)
}

int
-
pkg_load_manifest_file(struct pkg *pkg, const char *fpath)
+
pkg_load_manifest_file(struct pkg *pkg, const char *fpath, struct pkg_manifest_key *keys)
{
	FILE *f;
	int ret;
@@ -193,7 +252,7 @@ pkg_load_manifest_file(struct pkg *pkg, const char *fpath)
		return (EPKG_FATAL);
	}

-
	ret = pkg_parse_manifest_file(pkg, f);
+
	ret = pkg_parse_manifest_file(pkg, f, keys);
	fclose(f);

	return (ret);
@@ -628,22 +687,13 @@ pkg_set_deps_from_node(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc,
}

static int
-
manifest_key_cmp(const void *pkey, const void *pmanifest_key)
-
{
-
	const struct manifest_key *mkey =
-
			(const struct manifest_key*)pmanifest_key;
-
	const char *key = (const char *)pkey;
-

-
	return strcasecmp(key, mkey->key);
-
}
-

-
static int
-
parse_root_node(struct pkg *pkg, yaml_node_t *node, yaml_document_t *doc) {
+
parse_root_node(struct pkg *pkg, struct pkg_manifest_key *keys,  yaml_node_t *node, yaml_document_t *doc) {
	yaml_node_pair_t *pair;
	yaml_node_t *key;
	yaml_node_t *val;
	int retcode = EPKG_OK;
-
	struct manifest_key *selected_key;
+
	struct pkg_manifest_key *selected_key;
+
	struct dataparser *dp;

	pair = node->data.mapping.pairs.start;
	while (pair < node->data.mapping.pairs.top) {
@@ -666,12 +716,12 @@ parse_root_node(struct pkg *pkg, yaml_node_t *node, yaml_document_t *doc) {
			continue;
		}

-
		selected_key = bsearch(key->data.scalar.value, manifest_keys,
-
				sizeof(manifest_keys) / sizeof(manifest_keys[0]) - 1,
-
				sizeof(manifest_keys[0]), manifest_key_cmp);
-
		if (selected_key != NULL && val->type == selected_key->valid_type) {
-
			retcode = selected_key->parse_data(pkg, val, doc,
-
					selected_key->type);
+
		HASH_FIND_STR(keys, key->data.scalar.value, selected_key);
+
		if (selected_key != NULL) {
+
			HASH_FIND_YAMLT(selected_key->parser, &val->type, dp);
+
			if (dp != NULL) {
+
				dp->parse_data(pkg, val, doc, selected_key->type);
+
			}
		}
		++pair;
	}
@@ -680,7 +730,7 @@ parse_root_node(struct pkg *pkg, yaml_node_t *node, yaml_document_t *doc) {
}

int
-
pkg_parse_manifest(struct pkg *pkg, char *buf)
+
pkg_parse_manifest(struct pkg *pkg, char *buf, struct pkg_manifest_key *keys)
{
	yaml_parser_t parser;
	yaml_document_t doc;
@@ -699,7 +749,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
		if (node->type != YAML_MAPPING_NODE) {
			pkg_emit_error("Invalid manifest format");
		} else {
-
			retcode = parse_root_node(pkg, node, &doc);
+
			retcode = parse_root_node(pkg, keys, node, &doc);
		}
	} else {
		pkg_emit_error("Invalid manifest format");
@@ -712,7 +762,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
}

int
-
pkg_parse_manifest_file(struct pkg *pkg, FILE *f)
+
pkg_parse_manifest_file(struct pkg *pkg, FILE *f, struct pkg_manifest_key *keys)
{
	yaml_parser_t parser;
	yaml_document_t doc;
@@ -731,7 +781,7 @@ pkg_parse_manifest_file(struct pkg *pkg, FILE *f)
		if (node->type != YAML_MAPPING_NODE) {
			pkg_emit_error("Invalid manifest format");
		} else {
-
			retcode = parse_root_node(pkg, node, &doc);
+
			retcode = parse_root_node(pkg, keys, node, &doc);
		}
	} else {
		pkg_emit_error("Invalid manifest format");
modified libpkg/pkg_repo.c
@@ -398,6 +398,7 @@ read_pkg_file(void *data)
{
	struct thd_data *d = (struct thd_data*) data;
	struct pkg_result *r;
+
	struct pkg_manifest_key *keys = NULL;

	FTSENT *fts_ent = NULL;
	char fts_accpath[MAXPATHLEN + 1];
@@ -409,6 +410,8 @@ read_pkg_file(void *data)
	char *ext = NULL;
	char *pkg_path;

+
	pkg_manifest_keys_new(&keys);
+

	for (;;) {
		fts_ent = NULL;

@@ -464,7 +467,7 @@ read_pkg_file(void *data)

		r = calloc(1, sizeof(struct pkg_result));

-
		if (pkg_open(&r->pkg, fts_accpath) != EPKG_OK) {
+
		if (pkg_open(&r->pkg, fts_accpath, keys) != EPKG_OK) {
			r->retcode = EPKG_WARN;
		} else {
			sha256_file(fts_accpath, r->cksum);
@@ -493,6 +496,7 @@ read_pkg_file(void *data)
	d->thd_finished++;
	pthread_cond_signal(&d->has_result);
	pthread_mutex_unlock(&d->results_m);
+
	pkg_manifest_keys_free(keys);
}

static int
modified libpkg/private/pkg.h
@@ -95,6 +95,11 @@
			return (EPKG_OK);     \
	} while (0)

+
#define HASH_FIND_YAMLT(head,type,out)                                   \
+
	HASH_FIND(hh,head,type,sizeof(yaml_node_type_t),out)
+
#define HASH_ADD_YAMLT(head,type,add)                                    \
+
	HASH_ADD(hh,head,type,sizeof(yaml_node_type_t),add)
+

extern int eventpipe;

struct pkg {
@@ -305,7 +310,7 @@ int pkg_add_user_group(struct pkg *pkg);
int pkg_delete_user_group(struct pkgdb *db, struct pkg *pkg);

int pkg_open2(struct pkg **p, struct archive **a, struct archive_entry **ae,
-
	      const char *path);
+
	      const char *path, struct pkg_manifest_key *keys);

void pkg_list_free(struct pkg *, pkg_list);

modified libpkg/update.c
@@ -361,7 +361,8 @@ pkg_update_full(const char *repofile, const char *name, const char *packagesite,

static int
pkg_add_from_manifest(FILE *f, const char *origin, long offset,
-
		const char *manifest_digest, const char *local_arch, sqlite3 *sqlite)
+
		const char *manifest_digest, const char *local_arch, sqlite3 *sqlite,
+
		struct pkg_manifest_key *keys)
{
	int rc = EPKG_OK;
	struct pkg *pkg;
@@ -376,7 +377,7 @@ pkg_add_from_manifest(FILE *f, const char *origin, long offset,
	if (rc != EPKG_OK)
		return (EPKG_FATAL);

-
	rc = pkg_parse_manifest_file(pkg, f);
+
	rc = pkg_parse_manifest_file(pkg, f, keys);
	if (rc != EPKG_OK) {
		goto cleanup;
	}
@@ -445,6 +446,7 @@ pkg_update_incremental(const char *name, const char *packagesite, time_t *mtime)
	struct pkg_increment_task_item *ldel = NULL, *ladd = NULL,
			*item, *tmp_item;
	const char *myarch;
+
	struct pkg_manifest_key *keys = NULL;

	if ((rc = pkgdb_repo_open(name, false, &sqlite)) != EPKG_OK) {
		return (EPKG_FATAL);
@@ -486,6 +488,7 @@ pkg_update_incremental(const char *name, const char *packagesite, time_t *mtime)
		goto cleanup;
	*mtime = local_t;

+
	pkg_manifest_keys_new(&keys);
	do {
		pkg_get(local_pkg, PKG_ORIGIN, &local_origin, PKG_DIGEST, &local_digest);
		/* Read a line from digests file */
@@ -576,7 +579,7 @@ pkg_update_incremental(const char *name, const char *packagesite, time_t *mtime)
	LL_FOREACH_SAFE(ladd, item, tmp_item) {
		if (rc == EPKG_OK) {
			rc = pkg_add_from_manifest(fmanifest, item->origin,
-
						item->offset, item->digest, myarch, sqlite);
+
			        item->offset, item->digest, myarch, sqlite, keys);
			added ++;
		}
		free(item->origin);
@@ -595,6 +598,7 @@ cleanup:
		fclose(fmanifest);
	if (fdigests)
		fclose(fdigests);
+
	pkg_manifest_keys_free(keys);

	return (rc);
}
modified pkg/add.c
@@ -71,6 +71,7 @@ exec_add(int argc, char **argv)
	int i;
	int failedpkgcount = 0;
	pkg_flags f = PKG_FLAG_NONE;
+
	struct pkg_manifest_key *keys;

	while ((ch = getopt(argc, argv, "IAfq")) != -1) {
		switch (ch) {
@@ -113,6 +114,7 @@ exec_add(int argc, char **argv)
		return (EX_IOERR);

	failedpkgs = sbuf_new_auto();
+
	pkg_manifest_keys_new(&keys);
	for (i = 0; i < argc; i++) {
		if (is_url(argv[i]) == EPKG_OK) {
			snprintf(path, sizeof(path), "./%s", basename(argv[i]));
@@ -135,7 +137,7 @@ exec_add(int argc, char **argv)

		}

-
		if ((retcode = pkg_add(db, file, f)) != EPKG_OK) {
+
		if ((retcode = pkg_add(db, file, f, keys)) != EPKG_OK) {
			sbuf_cat(failedpkgs, argv[i]);
			if (i != argc - 1)
				sbuf_printf(failedpkgs, ", ");
@@ -143,6 +145,7 @@ exec_add(int argc, char **argv)
		}

	}
+
	pkg_manifest_keys_free(keys);

	pkgdb_close(db);
	
modified pkg/clean.c
@@ -227,6 +227,7 @@ exec_clean(__unused int argc, __unused char **argv)
	int		 retcode;
	int		 ret;
	int		 ch;
+
	struct pkg_manifest_key *keys = NULL;

	pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);

@@ -286,6 +287,7 @@ exec_clean(__unused int argc, __unused char **argv)

	/* Build the list of out-of-date or obsolete packages */

+
	pkg_manifest_keys_new(&keys);
	while ((ent = fts_read(fts)) != NULL) {
		const char *origin, *pkgrepopath;

@@ -296,7 +298,7 @@ exec_clean(__unused int argc, __unused char **argv)
		if (repopath[0] == '/')
			repopath++;

-
		if (pkg_open(&pkg, ent->fts_path) != EPKG_OK) {
+
		if (pkg_open(&pkg, ent->fts_path, keys) != EPKG_OK) {
			if (!quiet)
				warnx("skipping %s", ent->fts_path);
			continue;
@@ -388,6 +390,7 @@ exec_clean(__unused int argc, __unused char **argv)
		retcode = EX_OK;

cleanup:
+
	pkg_manifest_keys_free(keys);
	free_dellist(&dl);

	pkg_free(pkg);
modified pkg/info.c
@@ -81,6 +81,7 @@ exec_info(int argc, char **argv)
	int sign2 = 0;
	bool pkg_exists = false;
	bool origin_search = false;
+
	struct pkg_manifest_key *keys = NULL;

	/* TODO: exclusive opts ? */
	while ((ch = getopt(argc, argv, "aADegixEIdrklbBsqopOfF:R")) != -1) {
@@ -194,9 +195,11 @@ exec_info(int argc, char **argv)
		quiet = false;

	if (file != NULL) {
-
		if (pkg_open(&pkg, file) != EPKG_OK) {
+
		pkg_manifest_keys_new(&keys);
+
		if (pkg_open(&pkg, file, keys) != EPKG_OK) {
			return (1);
		}
+
		pkg_manifest_keys_free(keys);
		print_info(pkg, opt);
		pkg_free(pkg);
		return (0);
modified pkg/query.c
@@ -866,6 +866,7 @@ exec_query(int argc, char **argv)
	struct pkgdb *db = NULL;
	struct pkgdb_it *it = NULL;
	struct pkg *pkg = NULL;
+
	struct pkg_manifest_key *keys = NULL;
	char *pkgname = NULL;
	int query_flags = PKG_LOAD_BASIC;
	match_t match = MATCH_EXACT;
@@ -925,10 +926,12 @@ exec_query(int argc, char **argv)
		return (EX_USAGE);

	if (pkgname != NULL) {
-
		if (pkg_open(&pkg, pkgname) != EPKG_OK) {
+
		pkg_manifest_keys_new(&keys);
+
		if (pkg_open(&pkg, pkgname, keys) != EPKG_OK) {
			return (EX_IOERR);
		}

+
		pkg_manifest_keys_free(keys);
		print_query(pkg, argv[0], multiline);
		pkg_free(pkg);
		return (EX_OK);
modified pkg/register.c
@@ -77,6 +77,8 @@ exec_register(int argc, char **argv)
	struct pkg *pkg = NULL;
	struct pkgdb *db = NULL;

+
	struct pkg_manifest_key *keys = NULL;
+

	regex_t preg;
	regmatch_t pmatch[2];

@@ -156,10 +158,12 @@ exec_register(int argc, char **argv)
	if (mdir == NULL)
		errx(EX_USAGE, "missing -m flag");

+
	pkg_manifest_keys_new(&keys);
	snprintf(fpath, sizeof(fpath), "%s/+MANIFEST", mdir);
-
	if ((ret = pkg_load_manifest_file(pkg, fpath)) != EPKG_OK) {
+
	if ((ret = pkg_load_manifest_file(pkg, fpath, keys)) != EPKG_OK) {
		return (EX_IOERR);
	}
+
	pkg_manifest_keys_free(keys);

	snprintf(fpath, sizeof(fpath), "%s/+DESC", mdir);
	pkg_set_from_file(pkg, PKG_DESC, fpath, false);