Import pkg_install-20090214:

- pkg_add:
  - doesn't crash on missing +BUILD_INFO
  - for -u skip the package it will update when l oking for conflicts
  - don't fail in libarchive when trying to use directories as packages
- pkg_admin:
  - stricter argument checking for audit family of commands
  - fetch-pkg-vulnerabilities -u will only update if the remove file
    is newer
- pkg_delete:
  - fix PKG_METADATA_DIR passed to deinstall script
  - when using -d, ignore @dirrm
  - fix -d code to unregister the correct pkgdb entry
- pkg_info:
  - fix crashes on incomplete packages
This commit is contained in:
joerg 2009-02-14 17:18:56 +00:00
parent 78a7904557
commit b8b994aea2
20 changed files with 210 additions and 140 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:01 joerg Exp $ */
/* $NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:18:56 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
@ -6,7 +6,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:01 joerg Exp $");
__RCSID("$NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:18:56 joerg Exp $");
/*-
* Copyright (c) 2003 Grant Beattie <grant@NetBSD.org>
@ -45,6 +45,9 @@ __RCSID("$NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:01 joerg Exp $");
#include <err.h>
#endif
#include <errno.h>
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -455,7 +458,7 @@ read_buildinfo(struct pkg_task *pkg)
data = pkg->meta_data.meta_build_info;
for (; *data != '\0'; data = next_line) {
for (; data != NULL && *data != '\0'; data = next_line) {
if ((eol = strchr(data, '\n')) == NULL) {
eol = data + strlen(data);
next_line = eol;
@ -887,9 +890,30 @@ run_install_script(struct pkg_task *pkg, const char *argument)
return ret;
}
struct find_conflict_data {
const char *pkg;
const char *old_pkg;
const char *pattern;
};
static int
check_explicit_conflict_iter(const char *cur_pkg, void *cookie)
{
struct find_conflict_data *data = cookie;
if (strcmp(data->old_pkg, cur_pkg) == 0)
return 0;
warnx("Package `%s' conflicts with `%s', and `%s' is installed.",
data->pkg, data->pattern, cur_pkg);
return 1;
}
static int
check_explicit_conflict(struct pkg_task *pkg)
{
struct find_conflict_data data;
char *installed, *installed_pattern;
plist_t *p;
int status;
@ -900,15 +924,14 @@ check_explicit_conflict(struct pkg_task *pkg)
if (p->type == PLIST_IGNORE) {
p = p->next;
continue;
} else if (p->type != PLIST_PKGCFL)
continue;
installed = find_best_matching_installed_pkg(p->name);
if (installed) {
warnx("Package `%s' conflicts with `%s', and `%s' is installed.",
pkg->pkgname, p->name, installed);
free(installed);
status = -1;
}
if (p->type != PLIST_PKGCFL)
continue;
data.pkg = pkg->pkgname;
data.old_pkg = pkg->other_version;
data.pattern = p->name;
status |= match_installed_pkgs(p->name,
check_explicit_conflict_iter, &data);
}
if (some_installed_package_conflicts_with(pkg->pkgname,
@ -917,7 +940,7 @@ check_explicit_conflict(struct pkg_task *pkg)
installed, installed_pattern, pkg->pkgname);
free(installed);
free(installed_pattern);
status = -1;
status |= -1;
}
return status;
@ -1232,13 +1255,11 @@ pkg_do(const char *pkgpath, int mark_automatic)
goto clean_find_archive;
}
#ifdef HAVE_SSL
invalid_sig = pkg_verify_signature(&pkg->archive, &pkg->entry,
&pkg->pkgname, &signature_cookie);
#else
invalid_sig = 1;
signature_cookie = NULL;
#endif
if (pkg->archive == NULL)
goto clean_memory;
if (read_meta_data(pkg))
goto clean_memory;
@ -1397,9 +1418,7 @@ clean_memory:
}
free(pkg->other_version);
free(pkg->pkgname);
#ifdef HAVE_SSL
pkg_free_signature(signature_cookie);
#endif
clean_find_archive:
free(pkg);
return status;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_add.1,v 1.1.1.2 2009/02/02 20:44:02 joerg Exp $
.\" $NetBSD: pkg_add.1,v 1.1.1.3 2009/02/14 17:19:03 joerg Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@ -172,7 +172,7 @@ you know what you are doing!
If the package that's being installed is already installed,
an update is performed.
It is currently not possible to update to an identical version.
If this is specified twice, then any dependant packages that are
If this is specified twice, then any dependent packages that are
too old will also be updated to fulfill the dependency.
See below for a more detailed description of the process.
.It Fl V
@ -294,7 +294,7 @@ conflicts with the package.
If it is, installation is terminated.
.It
The file list of the package is compared to the file lists of the
installed packeges.
installed packages.
If there is any overlap, the installation is terminated.
.It
All package dependencies (from
@ -311,7 +311,7 @@ If the
option was specified twice, any required packages that are installed,
but which have a version number that is considered to be too old,
are also updated.
The dependant packages are found according to the normal
The dependent packages are found according to the normal
.Ev PKG_PATH
rules.
.It
@ -330,7 +330,7 @@ If the
.Ar install
script exits with a non-zero status code, the installation is terminated.
.It
The files from the file list are extracted to the choosen prefix.
The files from the file list are extracted to the chosen prefix.
.It
If an
.Ar install
@ -490,7 +490,7 @@ If you do this, consider installing and using the
package and running it after every
.Nm .
.Sh CONFIGURATION VARIABLES
The following variables change the behaviour of
The following variables change the behavior of
.Nm
and are described in
.Xr pkg_install.conf 5 :

View File

@ -1,4 +1,4 @@
/* $NetBSD: audit.c,v 1.1.1.3 2009/02/02 20:44:02 joerg Exp $ */
/* $NetBSD: audit.c,v 1.1.1.4 2009/02/14 17:19:08 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: audit.c,v 1.1.1.3 2009/02/02 20:44:02 joerg Exp $");
__RCSID("$NetBSD: audit.c,v 1.1.1.4 2009/02/14 17:19:08 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -76,11 +76,14 @@ __RCSID("$NetBSD: audit.c,v 1.1.1.3 2009/02/02 20:44:02 joerg Exp $");
static int check_eol = 0;
static int check_signature = 0;
static const char *limit_vul_types = NULL;
static int update_pkg_vuln = 0;
static struct pkg_vulnerabilities *pv;
static const char audit_options[] = "est:";
static void
parse_options(int argc, char **argv)
parse_options(int argc, char **argv, const char *options)
{
int ch;
@ -94,7 +97,7 @@ parse_options(int argc, char **argv)
++argc;
--argv;
while ((ch = getopt(argc, argv, "est:")) != -1) {
while ((ch = getopt(argc, argv, options)) != -1) {
switch (ch) {
case 'e':
check_eol = 1;
@ -105,6 +108,9 @@ parse_options(int argc, char **argv)
case 't':
limit_vul_types = optarg;
break;
case 'u':
update_pkg_vuln = 1;
break;
default:
usage();
/* NOTREACHED */
@ -211,7 +217,7 @@ audit_pkgdb(int argc, char **argv)
{
int rv;
parse_options(argc, argv);
parse_options(argc, argv, audit_options);
argv += optind;
check_and_read_pkg_vulnerabilities();
@ -235,7 +241,7 @@ audit_pkg(int argc, char **argv)
{
int rv;
parse_options(argc, argv);
parse_options(argc, argv, audit_options);
argv += optind;
check_and_read_pkg_vulnerabilities();
@ -255,7 +261,7 @@ audit_batch(int argc, char **argv)
{
int rv;
parse_options(argc, argv);
parse_options(argc, argv, audit_options);
argv += optind;
check_and_read_pkg_vulnerabilities();
@ -272,7 +278,7 @@ audit_batch(int argc, char **argv)
void
check_pkg_vulnerabilities(int argc, char **argv)
{
parse_options(argc, argv);
parse_options(argc, argv, "s");
if (argc != optind + 1)
usage();
@ -287,18 +293,50 @@ fetch_pkg_vulnerabilities(int argc, char **argv)
char *buf, *decompressed_input;
size_t buf_len, buf_fetched, decompressed_len;
ssize_t cur_fetched;
struct url *url;
struct url_stat st;
fetchIO *f;
int fd;
struct stat sb;
char my_flags[20];
const char *flags;
parse_options(argc, argv);
parse_options(argc, argv, "su");
if (argc != optind)
usage();
if (verbose >= 2)
fprintf(stderr, "Fetching %s\n", pkg_vulnerabilities_url);
f = fetchXGetURL(pkg_vulnerabilities_url, &st, fetch_flags);
url = fetchParseURL(pkg_vulnerabilities_url);
if (url == NULL)
errx(EXIT_FAILURE,
"Could not parse location of pkg_vulnerabilities: %s",
fetchLastErrString);
flags = fetch_flags;
if (update_pkg_vuln) {
fd = open(pkg_vulnerabilities_file, O_RDONLY);
if (fd != -1 && fstat(fd, &sb) != -1) {
url->last_modified = sb.st_mtime;
snprintf(my_flags, sizeof(my_flags), "%si",
fetch_flags);
flags = my_flags;
} else
update_pkg_vuln = 0;
if (fd != -1)
close(fd);
}
f = fetchXGet(url, &st, flags);
if (f == NULL && update_pkg_vuln &&
fetchLastErrCode == FETCH_UNCHANGED) {
if (verbose >= 1)
fprintf(stderr, "%s is not newer\n",
pkg_vulnerabilities_url);
exit(EXIT_SUCCESS);
}
if (f == NULL)
errx(EXIT_FAILURE, "Could not fetch vulnerability file: %s",
fetchLastErrString);
@ -460,7 +498,7 @@ check_pkg_history(const char *pkg)
void
audit_history(int argc, char **argv)
{
parse_options(argc, argv);
parse_options(argc, argv, "st:");
argv += optind;
check_and_read_pkg_vulnerabilities();

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $ */
/* $NetBSD: main.c,v 1.1.1.3 2009/02/14 17:19:11 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: main.c,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $");
__RCSID("$NetBSD: main.c,v 1.1.1.3 2009/02/14 17:19:11 joerg Exp $");
/*-
* Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
@ -533,7 +533,6 @@ main(int argc, char *argv[])
} else if (strcasecmp(argv[0], "audit-history") == 0) {
audit_history(--argc, ++argv);
} else if (strcasecmp(argv[0], "check-signature") == 0) {
#ifdef HAVE_SSL
struct archive *pkg;
void *cookie;
int rc;
@ -545,14 +544,12 @@ main(int argc, char *argv[])
warnx("%s could not be opened", *argv);
continue;
}
if (pkg_full_signature_check(pkg))
if (pkg_full_signature_check(&pkg))
rc = 1;
if (!pkg)
close_archive(pkg);
}
return rc;
#else
errx(EXIT_FAILURE, "OpenSSL support is not included");
#endif
} else if (strcasecmp(argv[0], "x509-sign-package") == 0) {
#ifdef HAVE_SSL
--argc;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_admin.1,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $
.\" $NetBSD: pkg_admin.1,v 1.1.1.3 2009/02/14 17:19:09 joerg Exp $
.\"
.\" Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -137,7 +137,7 @@ but check only the given package names or patterns.
Like
.Cm audit-pkg ,
but read the package names or patterns one per line from the given files.
.It Cm audit-history Oo Fl t Ar type Oc Oo Ar pkgbase Oc ...
.It Cm audit-history Oo Fl s Oc Oo Fl t Ar type Oc Oo Ar pkgbase Oc ...
Print all vulnerabilities for the given base package names.
.It Cm check Op Ar pkg ...
Use this command to check the files belonging to some or all of the
@ -161,7 +161,7 @@ checksum of the file on disk.
Symbolic links are also checked, ensuring that the targets on disk are
the same as the contents recorded at package installation time.
.It Cm check-pkg-vulnerabilities Oo Fl s Oc Ar file
Check format and hashes in the pkg-vulnerabilties file
Check format and hashes in the pkg-vulnerabilities file
.Ar file .
If
.Fl s
@ -184,7 +184,7 @@ Dump the contents of the package database, similar to
.Cm pkg_info -F .
Columns are printed for the key field used in the pkgdb - the filename -,
and the data field - the package the file belongs to.
.It Cm fetch-pkg-vulnerabilities Op Fl s
.It Cm fetch-pkg-vulnerabilities Oo Fl su Oc
Fetch a new pkg-vulnerabilities file, check the format and if
.Fl s
is given the signature.
@ -294,7 +294,7 @@ The default package database directory is
.Pa /var/db/pkg .
.El
.Sh CONFIGURATION VARIABLES
The following variables change the behaviour of
The following variables change the behavior of
.Nm
and are described in
.Xr pkg_install.conf 5 :

View File

@ -1,4 +1,4 @@
.\" $NetBSD: bpm.1,v 1.1.1.1 2008/09/30 19:00:26 joerg Exp $ */
.\" $NetBSD: bpm.1,v 1.1.1.2 2009/02/14 17:19:13 joerg Exp $ */
.\"
.\"
.\" Copyright (c) 2003 Alistair G. Crooks. All rights reserved.
@ -100,7 +100,7 @@ It is also possible to change the category currently being examined,
and to quit from the utility, simply by selecting the appropriate choices
on the menu.
.Sh ENVIRONMENT
The environment variables which govern the behaviour of
The environment variables which govern the behavior of
.Xr ftp 1
and
.Xr pkg_add 1

View File

@ -1,4 +1,4 @@
/* $NetBSD: build.c,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $ */
/* $NetBSD: build.c,v 1.1.1.3 2009/02/14 17:19:13 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: build.c,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $");
__RCSID("$NetBSD: build.c,v 1.1.1.3 2009/02/14 17:19:13 joerg Exp $");
/*-
* Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -320,7 +320,6 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
errx(2, "cannot finish archive: %s", archive_error_string(archive));
archive_write_finish(archive);
chdir(initial_cwd);
free(initial_cwd);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $ */
/* $NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:19:14 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $");
__RCSID("$NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:19:14 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
@ -35,6 +35,9 @@ __RCSID("$NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:03 joerg Exp $");
#if HAVE_ERR_H
#include <err.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_create.1,v 1.1.1.2 2009/02/02 20:44:04 joerg Exp $
.\" $NetBSD: pkg_create.1,v 1.1.1.3 2009/02/14 17:19:16 joerg Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@ -257,7 +257,7 @@ as the initial directory
to start from in selecting files for
the package.
.It Fl R
Re-order any directories in the pkg/PLIST file into reverse alphabetic
Re-order any directories in the PLIST file into reverse alphabetic
order, so that child directories will automatically be removed before
parent directories.
.It Fl S Ar size-all-file
@ -419,7 +419,7 @@ Set default group ownership for all subsequently extracted files to
Use without an arg to set back to default (extraction)
group ownership.
.It Cm @comment Ar string
Imbed a comment in the packing list.
Embed a comment in the packing list.
Useful in trying to document some particularly hairy sequence that
may trip someone up later.
.It Cm @ignore

View File

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:04 joerg Exp $ */
/* $NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:19:22 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:04 joerg Exp $");
__RCSID("$NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:19:22 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
@ -79,7 +79,6 @@ static int require_delete(int);
static void require_print(void);
static int undepend(const char *, void *);
static char LogDir[MaxPathSize];
static char linebuf[MaxPathSize];
static package_t Plist;
@ -705,7 +704,9 @@ pkg_do(char *pkg)
if (Destdir != NULL)
setenv(PKG_DESTDIR_VNAME, Destdir, 1);
setenv(PKG_PREFIX_VNAME, p->name, 1);
setenv(PKG_METADATA_DIR_VNAME, LogDir, 1);
fname = xasprintf("%s/%s", _pkgdb_getPKGDB_DIR(), pkg);
setenv(PKG_METADATA_DIR_VNAME, fname, 1);
free(fname);
/*
* Ensure that we don't do VIEW-DEINSTALL action for old packages
* or for the package in its depot directory.

View File

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:05 joerg Exp $ */
/* $NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:19:25 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -13,7 +13,7 @@
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
__RCSID("$NetBSD: perform.c,v 1.1.1.2 2009/02/02 20:44:05 joerg Exp $");
__RCSID("$NetBSD: perform.c,v 1.1.1.3 2009/02/14 17:19:25 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -298,9 +298,7 @@ pkg_do(const char *pkg)
#else
struct archive *archive;
void *archive_cookie;
# ifdef HAVE_SSL
void *signature_cookie;
# endif
struct archive_entry *entry;
char *pkgname;
@ -311,17 +309,15 @@ pkg_do(const char *pkg)
}
pkgname = NULL;
entry = NULL;
# ifdef HAVE_SSL
pkg_verify_signature(&archive, &entry, &pkgname,
&signature_cookie);
# endif
if (archive == NULL)
return -1;
free(pkgname);
meta = read_meta_data_from_archive(archive, entry);
close_archive(archive_cookie);
# ifdef HAVE_SSL
pkg_free_signature(signature_cookie);
# endif
if (!IS_URL(pkg))
binpkgfile = pkg;
#endif
@ -363,10 +359,17 @@ pkg_do(const char *pkg)
show_index(meta->meta_comment, tmp);
} else if (Flags & SHOW_BI_VAR) {
if (strcspn(BuildInfoVariable, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
== strlen(BuildInfoVariable))
== strlen(BuildInfoVariable)) {
if (meta->meta_installed_info)
show_var(meta->meta_installed_info, BuildInfoVariable);
else
warnx("Installation information missing");
} else {
if (meta->meta_build_info)
show_var(meta->meta_build_info, BuildInfoVariable);
else
warnx("Build information missing");
}
} else {
package_t plist;

View File

@ -1,4 +1,4 @@
/* $NetBSD: show.c,v 1.1.1.2 2009/02/02 20:44:05 joerg Exp $ */
/* $NetBSD: show.c,v 1.1.1.3 2009/02/14 17:19:26 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: show.c,v 1.1.1.2 2009/02/02 20:44:05 joerg Exp $");
__RCSID("$NetBSD: show.c,v 1.1.1.3 2009/02/14 17:19:26 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
@ -366,7 +366,10 @@ show_summary(struct pkg_meta *meta, package_t *plist, const char *binpkgfile)
print_string_as_var("COMMENT", meta->meta_comment);
print_string_as_var("SIZE_PKG", meta->meta_size_pkg);
if (meta->meta_build_info)
var_copy_list(meta->meta_build_info, bi_vars);
else
warnx("Build information missing");
if (binpkgfile != NULL && stat(binpkgfile, &st) == 0) {
const char *base;

View File

@ -135,9 +135,6 @@
/* Define to 1 if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H
/* Define to 1 if you have the `tgetent' function. */
#undef HAVE_TGETENT
/* Define to 1 if you have the <time.h> header file. */
#undef HAVE_TIME_H

View File

@ -1,4 +1,4 @@
/* $NetBSD: lib.h,v 1.1.1.2 2009/02/02 20:44:06 joerg Exp $ */
/* $NetBSD: lib.h,v 1.1.1.3 2009/02/14 17:19:30 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@ -308,7 +308,7 @@ Boolean isempty(const char *);
int URLlength(const char *);
Boolean make_preserve_name(char *, size_t, char *, char *);
void remove_files(const char *, const char *);
int delete_hierarchy(char *, Boolean, Boolean);
int delete_hierarchy(const char *, Boolean, Boolean);
int format_cmd(char *, size_t, const char *, const char *, const char *);
int recursive_remove(const char *, int);
@ -376,12 +376,12 @@ void pkg_install_config(void);
/* Print configuration variable */
void pkg_install_show_variable(const char *);
#ifdef HAVE_SSL
/* Package signature creation and validation */
int pkg_verify_signature(struct archive **, struct archive_entry **, char **,
void **);
int pkg_full_signature_check(struct archive *);
int pkg_full_signature_check(struct archive **);
void pkg_free_signature(void *);
#ifdef HAVE_SSL
void pkg_sign_x509(const char *, const char *, const char *, const char *);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse-config.c,v 1.1.1.1 2009/02/02 20:44:07 joerg Exp $ */
/* $NetBSD: parse-config.c,v 1.1.1.2 2009/02/14 17:19:30 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: parse-config.c,v 1.1.1.1 2009/02/02 20:44:07 joerg Exp $");
__RCSID("$NetBSD: parse-config.c,v 1.1.1.2 2009/02/14 17:19:30 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -49,7 +49,7 @@ __RCSID("$NetBSD: parse-config.c,v 1.1.1.1 2009/02/02 20:44:07 joerg Exp $");
const char *config_file = SYSCONFDIR"/pkg_install.conf";
char fetch_flags[10];
char fetch_flags[10] = ""; /* Workaround Mac OS X linker issues with BSS */
static const char *active_ftp;
static const char *verbose_netio;
static const char *ignore_proxy;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_install.conf.5,v 1.1.1.1 2009/02/02 20:44:07 joerg Exp $
.\" $NetBSD: pkg_install.conf.5,v 1.1.1.2 2009/02/14 17:19:31 joerg Exp $
.\"
.\" Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -65,7 +65,7 @@ is trusted when a certificate chain ends in one of the certificates
contained in this file.
.It Dv CERTIFICATE_CHAIN
Path to a file containing additional certificates that can be used
for completing certicate chains when validating binary packages or
for completing certificate chains when validating binary packages or
pkg-vulnerabilities files.
.Dv CHECK_VULNERABILITIES
Check for vulnerabilities when installing packages.

View File

@ -1,4 +1,4 @@
/* $NetBSD: pkg_signature.c,v 1.1.1.1 2009/02/02 20:44:07 joerg Exp $ */
/* $NetBSD: pkg_signature.c,v 1.1.1.2 2009/02/14 17:19:32 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: pkg_signature.c,v 1.1.1.1 2009/02/02 20:44:07 joerg Exp $");
__RCSID("$NetBSD: pkg_signature.c,v 1.1.1.2 2009/02/14 17:19:32 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -178,11 +178,13 @@ read_file_from_archive(struct archive *archive, struct archive_entry **entry,
retry:
if (*entry == NULL &&
(r = archive_read_next_header(archive, entry)) != ARCHIVE_OK) {
if (r == ARCHIVE_FATAL)
if (r == ARCHIVE_FATAL) {
warnx("Cannot read from archive: %s",
archive_error_string(archive));
return -1;
}
return 1;
}
if (strcmp(archive_entry_pathname(*entry), "//") == 0) {
archive_read_data_skip(archive);
*entry = NULL;
@ -190,7 +192,7 @@ retry:
}
if (strcmp(fname, archive_entry_pathname(*entry)) != 0)
return -1;
return 1;
if (archive_entry_size(*entry) > SSIZE_MAX - 1) {
warnx("signature too large to process");
@ -329,6 +331,8 @@ pkg_verify_signature(struct archive **archive, struct archive_entry **entry,
r = read_file_from_archive(*archive, entry, HASH_FNAME,
&hash_file, &hash_len);
if (r == -1) {
archive_read_finish(*archive);
*archive = NULL;
free(state);
goto no_valid_signature;
} else if (r == 1) {
@ -341,12 +345,24 @@ pkg_verify_signature(struct archive **archive, struct archive_entry **entry,
r = read_file_from_archive(*archive, entry, SIGNATURE_FNAME,
&signature_file, &signature_len);
if (r != 0) {
if (r == -1) {
archive_read_finish(*archive);
*archive = NULL;
free(state);
free(hash_file);
goto no_valid_signature;
} else if (r != 0) {
if (*entry != NULL)
r = read_file_from_archive(*archive, entry,
GPG_SIGNATURE_FNAME,
&signature_file, &signature_len);
if (r != 0) {
if (r == -1) {
archive_read_finish(*archive);
*archive = NULL;
free(state);
free(hash_file);
goto no_valid_signature;
} else if (r != 0) {
free(hash_file);
free(state);
goto no_valid_signature;
@ -356,10 +372,16 @@ pkg_verify_signature(struct archive **archive, struct archive_entry **entry,
free(signature_file);
} else {
#ifdef HAVE_SSL
has_sig = !easy_pkcs7_verify(hash_file, hash_len, signature_file,
signature_len, certs_packages, 1);
free(signature_file);
#else
warnx("No OpenSSL support compiled in, skipping signature");
has_sig = 0;
free(signature_file);
#endif
}
r = archive_read_next_header(*archive, &my_entry);
@ -398,21 +420,21 @@ no_valid_signature:
}
int
pkg_full_signature_check(struct archive *archive)
pkg_full_signature_check(struct archive **archive)
{
struct archive_entry *entry = NULL;
char *pkgname;
void *cookie;
int r;
if (pkg_verify_signature(&archive, &entry, &pkgname, &cookie))
if (pkg_verify_signature(archive, &entry, &pkgname, &cookie))
return -1;
if (pkgname == NULL)
return 0;
/* XXX read PLIST and compare pkgname */
while ((r = archive_read_next_header(archive, &entry)) == ARCHIVE_OK)
archive_read_data_skip(archive);
while ((r = archive_read_next_header(*archive, &entry)) == ARCHIVE_OK)
archive_read_data_skip(*archive);
pkg_free_signature(cookie);
free(pkgname);
@ -503,6 +525,7 @@ static const char hash_template[] =
static const char hash_trailer[] = "end pkgsrc signature\n";
#ifdef HAVE_SSL
void
pkg_sign_x509(const char *name, const char *output, const char *key_file, const char *cert_file)
{
@ -593,6 +616,7 @@ pkg_sign_x509(const char *name, const char *output, const char *key_file, const
exit(0);
}
#endif
void
pkg_sign_gpg(const char *name, const char *output)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pkgdb.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $ */
/* $NetBSD: pkgdb.c,v 1.1.1.3 2009/02/14 17:19:33 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: pkgdb.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $");
__RCSID("$NetBSD: pkgdb.c,v 1.1.1.3 2009/02/14 17:19:33 joerg Exp $");
/*-
* Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
@ -44,6 +44,8 @@ __RCSID("$NetBSD: pkgdb.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $");
#include <db1/db.h>
#elif HAVE_DB_H
#include <db.h>
#else
#include <nbcompat/db.h>
#endif
#if HAVE_ERR_H
#include <err.h>
@ -63,11 +65,6 @@ __RCSID("$NetBSD: pkgdb.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $");
#if HAVE_STRING_H
#include <string.h>
#endif
#if defined(HAVE_DBOPEN) || (defined(HAVE___DB185_OPEN) && defined(HAVE_DB_185_H))
#define HAVE_DBLIB 1
#else
#define HAVE_DBLIB 0
#endif
#include "lib.h"
@ -83,13 +80,10 @@ __RCSID("$NetBSD: pkgdb.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $");
/* just in case we change the environment variable name */
#define PKG_DBDIR "PKG_DBDIR"
#if HAVE_DBLIB
static DB *pkgdbp;
#endif
static char *pkgdb_dir = NULL;
static char pkgdb_cache[MaxPathSize];
#if HAVE_DBLIB
/*
* Open the pkg-database
* Return value:
@ -270,18 +264,6 @@ pkgdb_remove_pkg(const char *pkg)
return ret;
}
#else /* !HAVE_DBLIB */
int pkgdb_open(int mode) { return 1; }
void pkgdb_close(void) {}
int pkgdb_store(const char *key, const char *val) { return 0; }
char *pkgdb_retrieve(const char *key) { return NULL; }
int pkgdb_dump(void) { return 0; }
int pkgdb_remove(const char *key) { return 0; }
int pkgdb_remove_pkg(const char *pkg) { return 1; }
#endif /* HAVE_DBLIB */
/*
* Return the location of the package reference counts database directory.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: plist.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $ */
/* $NetBSD: plist.c,v 1.1.1.3 2009/02/14 17:19:39 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: plist.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $");
__RCSID("$NetBSD: plist.c,v 1.1.1.3 2009/02/14 17:19:39 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
@ -638,7 +638,7 @@ pkgdb_cleanup:
break;
case PLIST_DIR_RM:
if (NoDeleteFiles)
if (NoDeleteFiles || nukedirs)
break;
(void) snprintf(tmp, sizeof(tmp), "%s%s%s/%s",
@ -675,11 +675,10 @@ pkgdb_cleanup:
* Returns 1 on error, 0 else.
*/
int
delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs)
{
char *cp1, *cp2;
char *cp1, *cp2, *tmp_dir;
cp1 = cp2 = dir;
if (!fexists(dir)) {
if (!ign_err)
warnx("%s `%s' doesn't really exist",
@ -700,21 +699,26 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
if (!nukedirs)
return 0;
cp1 = cp2 = tmp_dir = xstrdup(dir);;
while (cp2) {
if ((cp2 = strrchr(cp1, '/')) != NULL)
*cp2 = '\0';
if (!isemptydir(dir))
return 0;
if (rmdir(dir) && !ign_err) {
if (!fexists(dir))
warnx("directory `%s' doesn't really exist", dir);
else
if (!isemptydir(tmp_dir))
break;
if (rmdir(tmp_dir) && !ign_err) {
if (fexists(tmp_dir)) {
free(tmp_dir);
return 1;
}
warnx("directory `%s' doesn't really exist", tmp_dir);
}
/* back up the pathname one component */
if (cp2) {
cp1 = dir;
cp1 = tmp_dir;
}
}
free(tmp_dir);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.1.1.3 2009/02/02 20:44:08 joerg Exp $ */
/* $NetBSD: version.h,v 1.1.1.4 2009/02/14 17:19:39 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@ -27,6 +27,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
#define PKGTOOLS_VERSION "20090201"
#define PKGTOOLS_VERSION "20090214"
#endif /* _INST_LIB_VERSION_H_ */