Import pkg_install-20170419.

This commit is contained in:
joerg 2017-04-20 13:12:46 +00:00
parent c57cca78b1
commit e64dcdc0b6
19 changed files with 183 additions and 488 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.1.1.10 2011/02/18 22:32:27 aymeric Exp $ */
/* $NetBSD: main.c,v 1.1.1.11 2017/04/20 13:12:46 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.10 2011/02/18 22:32:27 aymeric Exp $");
__RCSID("$NetBSD: main.c,v 1.1.1.11 2017/04/20 13:12:46 joerg Exp $");
/*
*
@ -33,20 +33,14 @@ __RCSID("$NetBSD: main.c,v 1.1.1.10 2011/02/18 22:32:27 aymeric Exp $");
#if HAVE_ERR_H
#include <err.h>
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include "lib.h"
#include "add.h"
static char Options[] = "AC:DIK:LP:RVW:fhm:np:t:Uuvw:";
static char Options[] = "AC:DIK:P:RVfhm:np:t:Uuv";
char *Destdir = NULL;
char *OverrideMachine = NULL;
char *Prefix = NULL;
char *View = NULL;
char *Viewbase = NULL;
Boolean NoView = FALSE;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
Boolean Automatic = FALSE;
@ -65,10 +59,9 @@ int ReplaceSame = 0;
static void
usage(void)
{
(void) fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: pkg_add [-AfhILnRuVv] [-C config] [-P destdir] [-K pkg_dbdir]",
" [-m machine] [-p prefix] [-s verification-type",
" [-W viewbase] [-w view]\n",
(void) fprintf(stderr, "%s\n%s\n%s\n",
"usage: pkg_add [-AfhInRuVv] [-C config] [-P destdir] [-K pkg_dbdir]",
" [-m machine] [-p prefix]",
" [[ftp|http]://[user[:password]@]host[:port]][/path/]pkg-name ...");
exit(1);
}
@ -112,10 +105,6 @@ main(int argc, char **argv)
pkgdb_set_dir(optarg, 3);
break;
case 'L':
NoView = TRUE;
break;
case 'R':
NoRecord = TRUE;
break;
@ -150,14 +139,6 @@ main(int argc, char **argv)
Verbose = TRUE;
break;
case 'W':
Viewbase = optarg;
break;
case 'w':
View = optarg;
break;
case 'h':
case '?':
default:
@ -178,7 +159,10 @@ main(int argc, char **argv)
free(pkgdbdir);
}
#ifndef BOOTSTRAP
process_pkg_path();
#endif
TAILQ_INIT(&pkgs);
if (argc == 0) {
@ -187,6 +171,7 @@ main(int argc, char **argv)
usage();
}
#ifndef BOOTSTRAP
if (strcasecmp(do_license_check, "no") == 0)
LicenseCheck = 0;
else if (strcasecmp(do_license_check, "yes") == 0)
@ -199,6 +184,7 @@ main(int argc, char **argv)
if (LicenseCheck)
load_license_lists();
#endif
/* Get all the remaining package names, if any */
for (; argc > 0; --argc, ++argv) {

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_add.1,v 1.1.1.12 2011/02/18 22:32:28 aymeric Exp $
.\" $NetBSD: pkg_add.1,v 1.1.1.13 2017/04/20 13:12:46 joerg Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@ -17,7 +17,7 @@
.\"
.\" @(#)pkg_add.1
.\"
.Dd June 16, 2010
.Dd December 27, 2014
.Dt PKG_ADD 1
.Os
.Sh NAME
@ -25,14 +25,12 @@
.Nd a utility for installing and upgrading software package distributions
.Sh SYNOPSIS
.Nm
.Op Fl AfILnRUuVv
.Op Fl AfInRUuVv
.Op Fl C Ar config
.Op Fl K Ar pkg_dbdir
.Op Fl m Ar machine
.Op Fl P Ar destdir
.Op Fl p Ar prefix
.Op Fl W Ar viewbase
.Op Fl w Ar view
.Ar Oo Oo Li ftp|http Oc Ns Li :// Ns Oo Ar user Oc Ns \
Oo Li \&: Ns Ar password Oc \
Ns Li @ Oc Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns \
@ -142,8 +140,6 @@ Override the value of the
.Dv PKG_DBDIR
configuration option with the value
.Ar pkg_dbdir .
.It Fl L
Don't add the package to any views after installation.
.It Fl m
Override the machine architecture returned by uname with
.Ar machine .
@ -179,14 +175,6 @@ See below for a more detailed description of the process.
Print version number and exit.
.It Fl v
Turn on verbose output.
.It Fl W Ar viewbase
Passed down to
.Xr pkg_view 1
for managed views.
.It Fl w Ar view
Passed down to
.Xr pkg_view 1
for managed views.
.El
.Pp
One or more
@ -337,11 +325,6 @@ Any package dependencies are recorded in the other packages'
.Pa +REQUIRED_BY
file.
.It
If the package is a depoted package, then add it to the registered
by calling
.Xr pkg_view 1
accordingly.
.It
Finally, if we were upgrading a package, any
.Pa +REQUIRED_BY
file that was moved aside before upgrading was started is now moved
@ -386,9 +369,6 @@ are prefixed with
See
.Xr pkg_install.conf 5
for options, that can also be specified using the environment.
Packages using views are also affected by the environment variables
documented for
.Xr pkg_view 1 .
.Sh EXAMPLES
In all cases,
.Nm

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.1.1.15 2010/04/23 20:54:07 joerg Exp $ */
/* $NetBSD: main.c,v 1.1.1.16 2017/04/20 13:12:47 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.15 2010/04/23 20:54:07 joerg Exp $");
__RCSID("$NetBSD: main.c,v 1.1.1.16 2017/04/20 13:12:47 joerg Exp $");
/*-
* Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@ -104,7 +104,6 @@ usage(void)
" rebuild-tree - rebuild +REQUIRED_BY files from forward deps\n"
" check [pkg ...] - check md5 checksum of installed files\n"
" add pkg ... - add pkg files to database\n"
" delete pkg ... - delete file entries for pkg in database\n"
" set variable=value pkg ... - set installation variable for package\n"
" unset variable pkg ... - unset installation variable for package\n"
" lsall /path/to/pkgpattern - list all pkgs matching the pattern\n"
@ -220,15 +219,6 @@ add_pkg(const char *pkgdir, void *vp)
return 0;
}
static void
delete1pkg(const char *pkgdir)
{
if (!pkgdb_open(ReadWrite))
err(EXIT_FAILURE, "cannot open pkgdb");
(void) pkgdb_remove_pkg(pkgdir);
pkgdb_close();
}
static void
rebuild(void)
{
@ -248,7 +238,7 @@ rebuild(void)
iterate_pkg_db(add_pkg, &count);
printf("\n");
printf("Stored %" PRIzu " file%s and %zu explicit director%s"
printf("Stored %" PRIzu " file%s and %" PRIzu " explicit director%s"
" from %"PRIzu " package%s in %s.\n",
count.files, count.files == 1 ? "" : "s",
count.directories, count.directories == 1 ? "y" : "ies",
@ -525,12 +515,6 @@ main(int argc, char *argv[])
for (++argv; *argv != NULL; ++argv)
add_pkg(*argv, &count);
} else if (strcasecmp(argv[0], "delete") == 0) {
argv++; /* "delete" */
while (*argv != NULL) {
delete1pkg(*argv);
argv++;
}
} else if (strcasecmp(argv[0], "set") == 0) {
argv++; /* "set" */
set_unset_variable(argv, FALSE);
@ -624,8 +608,8 @@ main(int argc, char *argv[])
if (pkg_full_signature_check(archive_name, &pkg))
rc = 1;
free(archive_name);
if (!pkg)
archive_read_finish(pkg);
if (pkg != NULL)
archive_read_free(pkg);
}
return rc;
} else if (strcasecmp(argv[0], "x509-sign-package") == 0) {

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_admin.1,v 1.1.1.12 2013/04/20 15:26:52 wiz Exp $
.\" $NetBSD: pkg_admin.1,v 1.1.1.13 2017/04/20 13:12:47 joerg Exp $
.\"
.\" Copyright (c) 1999-2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -34,7 +34,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd December 14, 2012
.Dd December 27, 2014
.Dt PKG_ADMIN 1
.Os
.Sh NAME
@ -106,13 +106,6 @@ Be more verbose.
.Pp
The following commands are supported:
.Bl -tag -width indent
.It Cm add Ar pkg ...
For each listed package, write the absolute pathnames of the files listed in
its
.Pa +CONTENTS
file together with the package they belong to into the package database.
This should be used only by
.Xr pkg_view 1 .
.It Cm audit Oo Fl es Oc Oo Fl t Ar type Oc Oo Ar pkg Oc ...
Check the listed installed packages for vulnerabilities.
If no package is given, check all installed packages.
@ -187,11 +180,6 @@ otherwise it exits with error.
Print the current value of
.Ar variable
as used after parsing the configuration file.
.It Cm delete Ar pkg ...
For each listed package, remove all file entries in the package database that
belong to the package.
This should be used only by
.Xr pkg_view 1 .
.It Cm dump
Dump the contents of the package database, similar to
.Cm pkg_info -F .
@ -310,7 +298,6 @@ for options, that can also be specified using the environment.
.Xr pkg_create 1 ,
.Xr pkg_delete 1 ,
.Xr pkg_info 1 ,
.Xr pkg_view 1 ,
.Xr pkg_install.conf 5 ,
.Xr pkgsrc 7
.Sh HISTORY

View File

@ -1,4 +1,4 @@
/* $NetBSD: build.c,v 1.1.1.8 2010/04/23 20:54:07 joerg Exp $ */
/* $NetBSD: build.c,v 1.1.1.9 2017/04/20 13:12:47 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.8 2010/04/23 20:54:07 joerg Exp $");
__RCSID("$NetBSD: build.c,v 1.1.1.9 2017/04/20 13:12:47 joerg Exp $");
/*-
* Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -93,7 +93,6 @@ static struct memory_file *build_info_file;
static struct memory_file *size_pkg_file;
static struct memory_file *size_all_file;
static struct memory_file *preserve_file;
static struct memory_file *views_file;
static void
write_meta_file(struct memory_file *file, struct archive *archive)
@ -234,6 +233,7 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
archive = archive_write_new();
archive_write_set_format_pax_restricted(archive);
archive_write_set_options(archive, "hdrcharset=BINARY");
if ((resolver = archive_entry_linkresolver_new()) == NULL)
errx(2, "cannot create link resolver");
archive_entry_linkresolver_set_strategy(resolver,
@ -251,20 +251,18 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
}
if (strcmp(CompressionType, "bzip2") == 0)
archive_write_set_compression_bzip2(archive);
archive_write_add_filter_bzip2(archive);
else if (strcmp(CompressionType, "gzip") == 0)
archive_write_set_compression_gzip(archive);
archive_write_add_filter_gzip(archive);
else if (strcmp(CompressionType, "xz") == 0)
archive_write_set_compression_xz(archive);
else if (strcmp(CompressionType, "none") == 0)
archive_write_set_compression_none(archive);
else
archive_write_add_filter_xz(archive);
else if (strcmp(CompressionType, "none") != 0)
errx(1, "Unspported compression type for -F: %s",
CompressionType);
archive_name = xasprintf("%s.%s", pkg, suffix);
if (archive_write_open_file(archive, archive_name))
if (archive_write_open_filename(archive, archive_name))
errx(2, "cannot create archive: %s", archive_error_string(archive));
free(archive_name);
@ -292,8 +290,6 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
write_meta_file(size_all_file, archive);
if (Preserve)
write_meta_file(preserve_file, archive);
if (create_views)
write_meta_file(views_file, archive);
initial_cwd = getcwd(NULL, 0);
@ -327,9 +323,8 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
archive_entry_linkresolver_free(resolver);
if (archive_write_close(archive))
if (archive_write_free(archive))
errx(2, "cannot finish archive: %s", archive_error_string(archive));
archive_write_finish(archive);
free(initial_cwd);
}
@ -407,8 +402,6 @@ pkg_build(const char *pkg, const char *full_pkg, const char *suffix,
preserve_file = load_and_add(plist, Preserve,
PRESERVE_FNAME, 0444);
}
if (create_views)
views_file = make_and_add(plist, VIEWS_FNAME, xstrdup(""), 0444);
/* Finally, write out the packing list */
stringify_plist(plist, &plist_buf, &plist_len, realprefix);

View File

@ -1,4 +1,4 @@
/* $NetBSD: create.h,v 1.1.1.5 2009/11/05 18:39:02 joerg Exp $ */
/* $NetBSD: create.h,v 1.1.1.6 2017/04/20 13:12:47 joerg Exp $ */
/* from FreeBSD Id: create.h,v 1.13 1997/10/08 07:46:19 charnier Exp */
@ -57,8 +57,6 @@ extern char *DefaultGroup;
extern const char *CompressionType;
extern int PlistOnly;
extern int RelativeLinks;
extern int update_pkgdb;
extern int create_views;
void check_list(package_t *, const char *);
void copy_plist(char *, package_t *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.1.1.7 2010/01/30 21:33:31 joerg Exp $ */
/* $NetBSD: main.c,v 1.1.1.8 2017/04/20 13:12:47 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.7 2010/01/30 21:33:31 joerg Exp $");
__RCSID("$NetBSD: main.c,v 1.1.1.8 2017/04/20 13:12:47 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
@ -26,7 +26,8 @@ __RCSID("$NetBSD: main.c,v 1.1.1.7 2010/01/30 21:33:31 joerg Exp $");
#include "lib.h"
#include "create.h"
static const char Options[] = "B:C:D:EF:I:K:L:OP:S:T:UVb:c:d:f:g:i:k:ln:p:r:s:u:v";
/* -U is silently ignored, it used to inhibit pkgdb changes. */
static const char Options[] = "B:C:D:F:I:K:L:OP:S:T:UVb:c:d:f:g:i:k:ln:p:r:s:u:v";
char *Prefix = NULL;
char *Comment = NULL;
@ -47,8 +48,6 @@ char *DefaultOwner = NULL;
char *DefaultGroup = NULL;
char *realprefix = NULL;
const char *CompressionType = NULL;
int update_pkgdb = 1;
int create_views = 0;
int PlistOnly = 0;
int RelativeLinks = 0;
Boolean File2Pkg = FALSE;
@ -57,7 +56,7 @@ static void
usage(void)
{
fprintf(stderr,
"usage: pkg_create [-ElOUVv] [-B build-info-file] [-b build-version-file]\n"
"usage: pkg_create [-lOUVv] [-B build-info-file] [-b build-version-file]\n"
" [-C cpkgs] [-D displayfile] [-F compression] \n"
" [-I realprefix] [-i iscript]\n"
" [-K pkg_dbdir] [-k dscript]\n"
@ -81,10 +80,6 @@ main(int argc, char **argv)
Verbose = TRUE;
break;
case 'E':
create_views = 1;
break;
case 'F':
CompressionType = optarg;
break;
@ -98,7 +93,6 @@ main(int argc, char **argv)
break;
case 'U':
update_pkgdb = 0;
break;
case 'p':
@ -209,7 +203,7 @@ main(int argc, char **argv)
return 0;
if (Verbose) {
if (PlistOnly)
warnx("package registration failed");
warnx("PLIST adjustment failed");
else
warnx("package creation failed");
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.1.1.5 2009/11/05 18:39:02 joerg Exp $ */
/* $NetBSD: perform.c,v 1.1.1.6 2017/04/20 13:12:47 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.5 2009/11/05 18:39:02 joerg Exp $");
__RCSID("$NetBSD: perform.c,v 1.1.1.6 2017/04/20 13:12:47 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
@ -225,12 +225,7 @@ pkg_perform(const char *pkg)
write_plist(&plist, stdout, realprefix);
retval = TRUE;
} else {
#ifdef BOOTSTRAP
warnx("Package building is not supported in bootstrap mode");
retval = FALSE;
#else
retval = pkg_build(pkg, full_pkg, suffix, &plist);
#endif
}
/* Cleanup */

View File

@ -1,4 +1,4 @@
/* $NetBSD: pl.c,v 1.1.1.4 2009/11/05 18:39:03 joerg Exp $ */
/* $NetBSD: pl.c,v 1.1.1.5 2017/04/20 13:12:47 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: pl.c,v 1.1.1.4 2009/11/05 18:39:03 joerg Exp $");
__RCSID("$NetBSD: pl.c,v 1.1.1.5 2017/04/20 13:12:47 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
@ -89,10 +89,6 @@ check_list(package_t *pkg, const char *PkgName)
char *pkgname = NULL;
int cc;
/* Open Package Database for writing */
if (update_pkgdb && !pkgdb_open(ReadWrite))
err(EXIT_FAILURE, "can't open pkgdb");
for (p = pkg->head; p; p = p->next) {
switch (p->type) {
case PLIST_CWD:
@ -109,38 +105,10 @@ check_list(package_t *pkg, const char *PkgName)
errx(2, "@pkgdir without preceding @cwd found");
if (pkgname == NULL)
errx(2, "@pkgdir without preceding @name found");
if (update_pkgdb) {
add_pkgdir(pkgname, cwd, p->name);
/* mkdir_p(cwd, p->name); */
}
break;
case PLIST_FILE:
/*
* pkgdb handling - usually, we enter files
* into the pkgdb as soon as they hit the disk,
* but as they are present before pkg_create
* starts, it's ok to do this somewhere here
*/
if (cwd == NULL)
errx(2, "file without preceding @cwd found");
if (update_pkgdb) {
char *s, t[MaxPathSize];
(void) snprintf(t, sizeof(t), "%s%s%s",
cwd,
(strcmp(cwd, "/") == 0) ? "" : "/",
p->name);
s = pkgdb_retrieve(t);
if (s && PlistOnly)
warnx("Overwriting %s - "
"pkg %s bogus/conflicting?", t, s);
else {
pkgdb_store(t, PkgName);
}
}
/* prepend DESTDIR if set? - HF */
(void) snprintf(name, sizeof(name), "%s%s%s",
cwd,
(strcmp(cwd, "/") == 0) ? "" : "/",
@ -204,8 +172,4 @@ check_list(package_t *pkg, const char *PkgName)
break;
}
}
if (update_pkgdb) {
pkgdb_close();
}
}

View File

@ -39,27 +39,18 @@
#if HAVE_ERR_H
#include <err.h>
#endif
#include <fcntl.h>
#if HAVE_PWD_H
#include <grp.h>
#endif
#include <limits.h>
#if HAVE_PWD_H
#include <pwd.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_TIME_H
#include <time.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include "lib.h"
#include "create.h"

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_delete.1,v 1.1.1.8 2010/04/23 20:54:08 joerg Exp $
.\" $NetBSD: pkg_delete.1,v 1.1.1.9 2017/04/20 13:12:46 joerg Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@ -17,7 +17,7 @@
.\"
.\" from FreeBSD: @(#)pkg_delete.1
.\"
.Dd January 20, 2010
.Dd December 27, 2014
.Dt PKG_DELETE 1
.Os
.Sh NAME
@ -221,12 +221,6 @@ script is called as:
.Bd -filled -offset indent -compact
.Cm deinstall
.Aq Ar pkg-name
.Ar VIEW-DEINSTALL
.Ed
before removing the package from a view, and as:
.Bd -filled -offset indent -compact
.Cm deinstall
.Aq Ar pkg-name
.Ar DEINSTALL
.Ed
before deleting all files and as:
@ -237,8 +231,7 @@ before deleting all files and as:
.Ed
after deleting them.
Passing the keywords
.Ar VIEW-DEINSTALL ,
.Ar DEINSTALL ,
.Ar DEINSTALL
and
.Ar POST-DEINSTALL
lets you potentially write only one program/script that handles all

View File

@ -34,7 +34,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: pkg_delete.c,v 1.1.1.8 2012/02/19 17:46:46 tron Exp $");
__RCSID("$NetBSD: pkg_delete.c,v 1.1.1.9 2017/04/20 13:12:46 joerg Exp $");
#if HAVE_ERR_H
#include <err.h>
@ -397,59 +397,15 @@ find_preserve_pkgs(lpkg_head_t *pkgs)
return 0;
}
/*
* Remove package from view. This is calling pkg_deinstall again.
*/
static int
remove_pkg_from_view(const char *pkg)
{
char line[MaxPathSize], *fname, *eol;
FILE *fp;
fname = pkgdb_pkg_file(pkg, VIEWS_FNAME);
if (isemptyfile(fname)) {
free(fname);
return 0;
}
if ((fp = fopen(fname, "r")) == NULL) {
warn("Unable to open `%s', aborting", fname);
free(fname);
return 1;
}
free(fname);
while (fgets(line, sizeof(line), fp) != NULL) {
if ((eol = strrchr(line, '\n')) != NULL)
*eol = '\0';
if (Verbose || Fake)
printf("Deleting package `%s' instance from `%s' view\n",
pkg, line);
if (Fake)
continue;
if (fexec_skipempty(BINDIR "/pkg_delete", "-K", line,
Fake ? "-n" : "",
(Force > 1) ? "-f" : "",
(Force > 0) ? "-f" : "",
pkg, NULL) != 0) {
warnx("Unable to delete package `%s' from view `%s'",
pkg, line);
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}
/*
* Run the +DEINSTALL script. Depending on whether this is
* a depoted package and whether this pre- or post-deinstall phase,
* different arguments are passed down.
* pre- or post-deinstall phase, different arguments are passed down.
*/
static int
run_deinstall_script(const char *pkg, int do_postdeinstall)
{
const char *target, *text;
char *fname, *fname2, *pkgdir;
char *fname, *pkgdir;
int rv;
fname = pkgdb_pkg_file(pkg, DEINSTALL_FNAME);
@ -458,23 +414,13 @@ run_deinstall_script(const char *pkg, int do_postdeinstall)
return 0;
}
fname2 = pkgdb_pkg_file(pkg, DEPOT_FNAME);
if (fexists(fname2)) {
if (do_postdeinstall) {
free(fname);
free(fname2);
return 0;
}
target = "VIEW-DEINSTALL";
text = "view deinstall";
} else if (do_postdeinstall) {
if (do_postdeinstall) {
target = "POST-DEINSTALL";
text = "post-deinstall";
} else {
target = "DEINSTALL";
text = "deinstall";
}
free(fname2);
if (Fake) {
printf("Would execute %s script with argument %s now\n",
@ -540,57 +486,6 @@ remove_line(const char *fname, const char *fname_tmp, const char *text)
return rv;
}
/*
* Unregister the package from the depot it is registered in.
*/
static int
remove_pkg_from_depot(const char *pkg)
{
FILE *fp;
char line[MaxPathSize], *eol;
char *fname, *fname2;
int rv;
fname = pkgdb_pkg_file(pkg, DEPOT_FNAME);
if (isemptyfile(fname)) {
free(fname);
return 0;
}
if (Verbose)
printf("Attempting to remove the `%s' registration "
"on package `%s'\n", fname, pkg);
if (Fake) {
free(fname);
return 1;
}
if ((fp = fopen(fname, "r")) == NULL) {
warn("Unable to open `%s' file", fname);
free(fname);
return 1;
}
if (fgets(line, sizeof(line), fp) == NULL) {
fclose(fp);
warnx("Empty depot file `%s'", fname);
free(fname);
return 1;
}
if ((eol = strrchr(line, '\n')) != NULL)
*eol = '\0';
fclose(fp);
free(fname);
fname = pkgdb_pkg_file(pkg, VIEWS_FNAME);
fname2 = pkgdb_pkg_file(pkg, VIEWS_FNAME_TMP);
rv = remove_line(fname, fname2, line);
free(fname2);
free(fname);
return rv;
}
/*
* remove_depend is used as iterator function below.
* The passed-in package name should be removed from the
@ -627,7 +522,7 @@ remove_pkg(const char *pkg)
char *fname, *pkgdir;
package_t plist;
plist_t *p;
int is_depoted_pkg, rv, late_error;
int rv, late_error;
if (pkgdb_update_only)
return pkgdb_remove_pkg(pkg) ? 0 : 1;
@ -640,15 +535,6 @@ remove_pkg(const char *pkg)
}
free(fname);
/* +REQUIRED_BY and +PRESERVE already checked */
if (remove_pkg_from_view(pkg))
return 1;
/*
* The views related code has bad error handling, if e.g.
* the deinstall script fails, the package remains unregistered.
*/
fname = pkgdb_pkg_file(pkg, CONTENTS_FNAME);
if ((fp = fopen(fname, "r")) == NULL) {
warnx("Failed to open `%s'", fname);
@ -712,37 +598,23 @@ remove_pkg(const char *pkg)
* processing.
*/
fname = pkgdb_pkg_file(pkg, DEPOT_FNAME);
if (fexists(fname)) {
late_error |= remove_pkg_from_depot(pkg);
/* XXX error checking */
} else {
for (p = plist.head; p; p = p->next) {
if (p->type != PLIST_PKGDEP)
continue;
if (Verbose)
printf("Attempting to remove dependency "
"on package `%s'\n", p->name);
if (Fake)
continue;
match_installed_pkgs(p->name, remove_depend,
__UNCONST(pkg));
}
for (p = plist.head; p; p = p->next) {
if (p->type != PLIST_PKGDEP)
continue;
if (Verbose)
printf("Attempting to remove dependency "
"on package `%s'\n", p->name);
if (Fake)
continue;
match_installed_pkgs(p->name, remove_depend,
__UNCONST(pkg));
}
free(fname);
free_plist(&plist);
if (!no_deinstall && !unregister_only)
late_error |= run_deinstall_script(pkg, 1);
fname = pkgdb_pkg_file(pkg, VIEWS_FNAME);
if (fexists(fname))
is_depoted_pkg = TRUE;
else
is_depoted_pkg = FALSE;
free(fname);
if (Fake)
return 0;
@ -755,8 +627,6 @@ remove_pkg(const char *pkg)
rv = 1;
if (isemptydir(pkgdir)&& rmdir(pkgdir) == 0)
rv = 0;
else if (is_depoted_pkg)
warnx("Depot directory `%s' is not empty", pkgdir);
else if (!Force)
warnx("Couldn't remove package directory in `%s'", pkgdir);
else if (recursive_remove(pkgdir, 1))

View File

@ -1,4 +1,4 @@
/* $NetBSD: info.h,v 1.1.1.5 2009/10/07 13:19:42 joerg Exp $ */
/* $NetBSD: info.h,v 1.1.1.6 2017/04/20 13:12:47 joerg Exp $ */
/* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */
@ -68,7 +68,6 @@ struct pkg_meta {
char *meta_install;
char *meta_deinstall;
char *meta_preserve;
char *meta_views;
char *meta_installed_info;
int is_installed;
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.1.1.13 2010/02/20 04:41:55 joerg Exp $ */
/* $NetBSD: perform.c,v 1.1.1.14 2017/04/20 13:12:47 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,13 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if HAVE_SYS_QUEUE_H
#include <sys/queue.h>
#endif
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
__RCSID("$NetBSD: perform.c,v 1.1.1.13 2010/02/20 04:41:55 joerg Exp $");
__RCSID("$NetBSD: perform.c,v 1.1.1.14 2017/04/20 13:12:47 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -73,6 +67,12 @@ __RCSID("$NetBSD: perform.c,v 1.1.1.13 2010/02/20 04:41:55 joerg Exp $");
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_QUEUE_H
#include <sys/queue.h>
#endif
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifndef BOOTSTRAP
#include <archive.h>
@ -81,22 +81,13 @@ __RCSID("$NetBSD: perform.c,v 1.1.1.13 2010/02/20 04:41:55 joerg Exp $");
#if HAVE_ERR_H
#include <err.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#if HAVE_DIRENT_H
#include <dirent.h>
#endif
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stddef.h>
#include <signal.h>
#define LOAD_CONTENTS (1 << 0)
#define LOAD_COMMENT (1 << 1)
@ -110,9 +101,8 @@ __RCSID("$NetBSD: perform.c,v 1.1.1.13 2010/02/20 04:41:55 joerg Exp $");
#define LOAD_SIZE_PKG (1 << 9)
#define LOAD_SIZE_ALL (1 << 10)
#define LOAD_PRESERVE (1 << 11)
#define LOAD_VIEWS (1 << 12)
#define LOAD_REQUIRED_BY (1 << 13)
#define LOAD_INSTALLED_INFO (1 << 14)
#define LOAD_REQUIRED_BY (1 << 12)
#define LOAD_INSTALLED_INFO (1 << 13)
static const struct pkg_meta_desc {
size_t entry_offset;
@ -144,8 +134,6 @@ static const struct pkg_meta_desc {
LOAD_SIZE_ALL, 0 },
{ offsetof(struct pkg_meta, meta_preserve), PRESERVE_FNAME,
LOAD_PRESERVE, 0 },
{ offsetof(struct pkg_meta, meta_views), VIEWS_FNAME,
LOAD_VIEWS, 0 },
{ offsetof(struct pkg_meta, meta_required_by), REQUIRED_BY_FNAME,
LOAD_REQUIRED_BY, 0 },
{ offsetof(struct pkg_meta, meta_installed_info), INSTALLED_INFO_FNAME,
@ -361,7 +349,7 @@ pkg_do(const char *pkg)
free(pkgname);
meta = read_meta_data_from_archive(archive, entry);
archive_read_finish(archive);
archive_read_free(archive);
if (!IS_URL(pkg))
binpkgfile = pkg;
#endif

View File

@ -15,8 +15,8 @@
/* Define to 1 if you have the <err.h> header file. */
#undef HAVE_ERR_H
/* Define to 1 if you have the <fnctl.h> header file. */
#undef HAVE_FNCTL_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the <fnmatch.h> header file. */
#undef HAVE_FNMATCH_H
@ -72,9 +72,6 @@
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define to 1 if you have the <sys/queue.h> header file. */
#undef HAVE_SYS_QUEUE_H
@ -147,6 +144,17 @@
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
#define below would cause a syntax error. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: file.c,v 1.1.1.6 2011/02/18 22:32:30 aymeric Exp $ */
/* $NetBSD: file.c,v 1.1.1.7 2017/04/20 13:12:47 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -7,13 +7,10 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#if HAVE_SYS_QUEUE_H
#include <sys/queue.h>
#endif
__RCSID("$NetBSD: file.c,v 1.1.1.6 2011/02/18 22:32:30 aymeric Exp $");
__RCSID("$NetBSD: file.c,v 1.1.1.7 2017/04/20 13:12:47 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance

View File

@ -1,4 +1,4 @@
/* $NetBSD: gpgsig.c,v 1.1.1.2 2009/08/06 16:55:27 joerg Exp $ */
/* $NetBSD: gpgsig.c,v 1.1.1.3 2017/04/20 13:12:48 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
@ -7,7 +7,7 @@
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: gpgsig.c,v 1.1.1.2 2009/08/06 16:55:27 joerg Exp $");
__RCSID("$NetBSD: gpgsig.c,v 1.1.1.3 2017/04/20 13:12:48 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -50,106 +50,48 @@ __RCSID("$NetBSD: gpgsig.c,v 1.1.1.2 2009/08/06 16:55:27 joerg Exp $");
#include <stdlib.h>
#endif
#include <netpgp/verify.h>
#include "lib.h"
static void
verify_signature(const char *input, size_t input_len, const char *keyring,
const char *detached_signature)
{
const char *argv[8], **argvp;
pid_t child;
int fd[2], status;
if (pipe(fd) == -1)
err(EXIT_FAILURE, "cannot create input pipes");
child = vfork();
if (child == -1)
err(EXIT_FAILURE, "cannot fork GPG process");
if (child == 0) {
close(fd[1]);
close(STDIN_FILENO);
if (dup2(fd[0], STDIN_FILENO) == -1) {
static const char err_msg[] =
"cannot redirect stdin of GPG process\n";
write(STDERR_FILENO, err_msg, sizeof(err_msg) - 1);
_exit(255);
}
close(fd[0]);
argvp = argv;
*argvp++ = gpg_cmd;
*argvp++ = "--verify";
if (keyring != NULL) {
*argvp++ = "--no-default-keyring";
*argvp++ = "--keyring";
*argvp++ = keyring;
}
if (detached_signature != NULL)
*argvp++ = detached_signature;
*argvp++ = "-";
*argvp = NULL;
execvp(gpg_cmd, __UNCONST(argv));
_exit(255);
}
close(fd[0]);
if (write(fd[1], input, input_len) != (ssize_t)input_len)
errx(EXIT_FAILURE, "Short read from GPG");
close(fd[1]);
waitpid(child, &status, 0);
if (status)
errx(EXIT_FAILURE, "GPG could not verify the signature");
}
int
inline_gpg_verify(const char *content, size_t len, const char *keyring)
gpg_verify(const char *content, size_t len, const char *keyring,
const char *sig, size_t sig_len)
{
verify_signature(content, len, keyring, NULL);
pgpv_t *pgp;
pgpv_cursor_t *cursor;
static const char hdr1[] = "-----BEGIN PGP SIGNED MESSAGE-----\n";
static const char hdr2[] = "Hash: SHA512\n\n";
ssize_t buflen;
char *allocated_buf;
const char *buf;
return 0;
}
int
detached_gpg_verify(const char *content, size_t len,
const char *signature, size_t signature_len, const char *keyring)
{
int fd;
const char *tmpdir;
char *tempsig;
ssize_t ret;
if (gpg_cmd == NULL) {
warnx("GPG variable not set, failing signature check");
return -1;
/*
* If there is a detached signature we need to construct a format that
* netpgp can parse, otherwise use as-is.
*/
if (sig_len) {
buf = allocated_buf = xasprintf("%s%s%s%s", hdr1, hdr2, content, sig);
buflen = strlen(buf);
} else {
buf = content;
allocated_buf = NULL;
buflen = len;
}
if ((tmpdir = getenv("TMPDIR")) == NULL)
tmpdir = "/tmp";
tempsig = xasprintf("%s/pkg_install.XXXXXX", tmpdir);
pgp = pgpv_new();
cursor = pgpv_new_cursor();
fd = mkstemp(tempsig);
if (fd == -1) {
warnx("Creating temporary file for GPG signature failed");
return -1;
}
if (!pgpv_read_pubring(pgp, keyring, -1))
err(EXIT_FAILURE, "cannot read keyring");
while (signature_len) {
ret = write(fd, signature, signature_len);
if (ret == -1)
err(EXIT_FAILURE, "Write to GPG failed");
if (ret == 0)
errx(EXIT_FAILURE, "Short write to GPG");
signature_len -= ret;
signature += ret;
}
if (!pgpv_verify(cursor, pgp, buf, buflen))
errx(EXIT_FAILURE, "unable to verify signature: %s",
pgpv_get_cursor_str(cursor, "why"));
verify_signature(content, len, keyring, tempsig);
pgpv_close(pgp);
unlink(tempsig);
close(fd);
free(tempsig);
free(allocated_buf);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pkg_io.c,v 1.1.1.9 2010/04/23 20:54:11 joerg Exp $ */
/* $NetBSD: pkg_io.c,v 1.1.1.10 2017/04/20 13:12:47 joerg Exp $ */
/*-
* Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
* All rights reserved.
@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: pkg_io.c,v 1.1.1.9 2010/04/23 20:54:11 joerg Exp $");
__RCSID("$NetBSD: pkg_io.c,v 1.1.1.10 2017/04/20 13:12:47 joerg Exp $");
#include <archive.h>
#include <archive_entry.h>
@ -46,9 +46,14 @@ __RCSID("$NetBSD: pkg_io.c,v 1.1.1.9 2010/04/23 20:54:11 joerg Exp $");
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <fetch.h>
#include <stdlib.h>
#ifdef BOOTSTRAP
#define IS_URL(x) 0
#else
#include <fetch.h>
#endif
#include "lib.h"
struct pkg_path {
@ -59,6 +64,7 @@ struct pkg_path {
static char *orig_cwd, *last_toplevel;
static TAILQ_HEAD(, pkg_path) pkg_path = TAILQ_HEAD_INITIALIZER(pkg_path);
#ifndef BOOTSTRAP
struct fetch_archive {
struct url *url;
fetchIO *fetch;
@ -145,19 +151,33 @@ open_archive_by_url(struct url *url, char **archive_name)
*archive_name = fetchStringifyURL(url);
a = archive_read_new();
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
a = prepare_archive();
if (archive_read_open(a, f, fetch_archive_open, fetch_archive_read,
fetch_archive_close)) {
free(*archive_name);
*archive_name = NULL;
archive_read_finish(a);
archive_read_free(a);
return NULL;
}
return a;
}
#endif /* !BOOTSTRAP */
struct archive *
prepare_archive(void)
{
struct archive *a = archive_read_new();
if (a == NULL)
errx(EXIT_FAILURE, "memory allocation failed");
archive_read_support_filter_gzip(a);
archive_read_support_filter_bzip2(a);
archive_read_support_filter_xz(a);
archive_read_support_format_ar(a);
archive_read_support_format_tar(a);
archive_read_set_options(a, "hdrcharset=BINARY");
return a;
}
struct archive *
open_archive(const char *url, char **archive_name)
@ -168,9 +188,7 @@ open_archive(const char *url, char **archive_name)
*archive_name = NULL;
if (!IS_URL(url)) {
a = archive_read_new();
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
a = prepare_archive();
if (archive_read_open_filename(a, url, 1024)) {
archive_read_close(a);
return NULL;
@ -179,6 +197,9 @@ open_archive(const char *url, char **archive_name)
return a;
}
#ifdef BOOTSTRAP
return NULL;
#else
if ((u = fetchParseURL(url)) == NULL)
return NULL;
@ -186,8 +207,10 @@ open_archive(const char *url, char **archive_name)
fetchFreeURL(u);
return a;
#endif
}
#ifndef BOOTSTRAP
static int
strip_suffix(char *filename)
{
@ -333,6 +356,7 @@ find_best_package(const char *toplevel, const char *pattern, int do_path)
return best_match;
}
#endif /* !BOOTSTRAP */
struct archive *
find_archive(const char *fname, int top_level, char **archive_name)
@ -364,7 +388,7 @@ find_archive(const char *fname, int top_level, char **archive_name)
free(full_fname);
return a;
}
#ifndef BOOTSTRAP
fname = last_slash + 1;
*last_slash = '\0';
@ -379,5 +403,6 @@ find_archive(const char *fname, int top_level, char **archive_name)
return NULL;
a = open_archive_by_url(best_match, archive_name);
fetchFreeURL(best_match);
#endif /* !BOOTSTRAP */
return a;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vulnerabilities-file.c,v 1.1.1.5 2010/06/26 00:14:33 joerg Exp $ */
/* $NetBSD: vulnerabilities-file.c,v 1.1.1.6 2017/04/20 13:12:47 joerg Exp $ */
/*-
* Copyright (c) 2008, 2010 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -38,7 +38,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: vulnerabilities-file.c,v 1.1.1.5 2010/06/26 00:14:33 joerg Exp $");
__RCSID("$NetBSD: vulnerabilities-file.c,v 1.1.1.6 2017/04/20 13:12:47 joerg Exp $");
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
@ -77,6 +77,20 @@ static const char pgp_msg_end[] = "-----BEGIN PGP SIGNATURE-----\n";
static const char pkcs7_begin[] = "-----BEGIN PKCS7-----\n";
static const char pkcs7_end[] = "-----END PKCS7-----\n";
static struct archive *
prepare_raw_file(void)
{
struct archive *a = archive_read_new();
if (a == NULL)
errx(EXIT_FAILURE, "memory allocation failed");
archive_read_support_filter_gzip(a);
archive_read_support_filter_bzip2(a);
archive_read_support_filter_xz(a);
archive_read_support_format_raw(a);
return a;
}
static void
verify_signature_pkcs7(const char *input)
{
@ -110,12 +124,7 @@ verify_signature_pkcs7(const char *input)
static void
verify_signature(const char *input, size_t input_len)
{
if (gpg_cmd == NULL && certs_pkg_vulnerabilities == NULL)
errx(EXIT_FAILURE,
"At least GPG or CERTIFICATE_ANCHOR_PKGVULN "
"must be configured");
if (gpg_cmd != NULL)
inline_gpg_verify(input, input_len, gpg_keyring_pkgvuln);
gpg_verify(input, input_len, gpg_keyring_pkgvuln, NULL, 0);
if (certs_pkg_vulnerabilities != NULL)
verify_signature_pkcs7(input);
}
@ -350,12 +359,8 @@ read_pkg_vulnerabilities_memory(void *buf, size_t len, int check_sum)
struct archive *a;
struct pkg_vulnerabilities *pv;
if ((a = archive_read_new()) == NULL)
errx(EXIT_FAILURE, "memory allocation failed");
if (archive_read_support_compression_all(a) != ARCHIVE_OK ||
archive_read_support_format_raw(a) != ARCHIVE_OK ||
archive_read_open_memory(a, buf, len) != ARCHIVE_OK)
a = prepare_raw_file();
if (archive_read_open_memory(a, buf, len) != ARCHIVE_OK)
errx(EXIT_FAILURE, "Cannot open pkg_vulnerabilies buffer: %s",
archive_error_string(a));
@ -381,12 +386,8 @@ read_pkg_vulnerabilities_file(const char *path, int ignore_missing, int check_su
err(EXIT_FAILURE, "Cannot open %s", path);
}
if ((a = archive_read_new()) == NULL)
errx(EXIT_FAILURE, "memory allocation failed");
if (archive_read_support_compression_all(a) != ARCHIVE_OK ||
archive_read_support_format_raw(a) != ARCHIVE_OK ||
archive_read_open_fd(a, fd, 65536) != ARCHIVE_OK)
a = prepare_raw_file();
if (archive_read_open_fd(a, fd, 65536) != ARCHIVE_OK)
errx(EXIT_FAILURE, "Cannot open ``%s'': %s", path,
archive_error_string(a));