summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2004-05-28 20:15:49 +0000
committerBrad Smith <brad@cvs.openbsd.org>2004-05-28 20:15:49 +0000
commitf473943a23d39230500fa5d4bd2e7c0be8904725 (patch)
treeaaf5a2ca769ebe488845669e6ad6c019d568bb05 /usr.sbin
parentc3cebc304b3fb018e0c7bcf0bf799547bdd63b40 (diff)
bye bye old package tools.
ok deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_install/add/Makefile19
-rw-r--r--usr.sbin/pkg_install/add/add.h45
-rw-r--r--usr.sbin/pkg_install/add/extract.c258
-rw-r--r--usr.sbin/pkg_install/add/futil.c90
-rw-r--r--usr.sbin/pkg_install/add/main.c207
-rw-r--r--usr.sbin/pkg_install/add/perform.c618
-rw-r--r--usr.sbin/pkg_install/add/pkg_add.1444
-rw-r--r--usr.sbin/pkg_install/create/Makefile19
-rw-r--r--usr.sbin/pkg_install/create/create.h49
-rw-r--r--usr.sbin/pkg_install/create/main.c168
-rw-r--r--usr.sbin/pkg_install/create/perform.c394
-rw-r--r--usr.sbin/pkg_install/create/pkg_create.1478
-rw-r--r--usr.sbin/pkg_install/create/pl.c250
-rw-r--r--usr.sbin/pkg_install/delete/Makefile17
-rw-r--r--usr.sbin/pkg_install/delete/delete.h35
-rw-r--r--usr.sbin/pkg_install/delete/main.c119
-rw-r--r--usr.sbin/pkg_install/delete/perform.c322
-rw-r--r--usr.sbin/pkg_install/delete/pkg_delete.1198
-rw-r--r--usr.sbin/pkg_install/info/Makefile17
-rw-r--r--usr.sbin/pkg_install/info/info.h56
-rw-r--r--usr.sbin/pkg_install/info/main.c163
-rw-r--r--usr.sbin/pkg_install/info/perform.c314
-rw-r--r--usr.sbin/pkg_install/info/pkg_info.1206
-rw-r--r--usr.sbin/pkg_install/info/show.c198
-rw-r--r--usr.sbin/pkg_install/lib/Makefile11
-rw-r--r--usr.sbin/pkg_install/lib/exec.c68
-rw-r--r--usr.sbin/pkg_install/lib/file.c701
-rw-r--r--usr.sbin/pkg_install/lib/global.c35
-rw-r--r--usr.sbin/pkg_install/lib/lib.h219
-rw-r--r--usr.sbin/pkg_install/lib/pen.c176
-rw-r--r--usr.sbin/pkg_install/lib/plist.c499
-rw-r--r--usr.sbin/pkg_install/lib/pwarnx.c104
-rw-r--r--usr.sbin/pkg_install/lib/str.c366
-rw-r--r--usr.sbin/pkg_install/sign/INSTALL21
-rw-r--r--usr.sbin/pkg_install/sign/MANIFEST14
-rw-r--r--usr.sbin/pkg_install/sign/Makefile19
-rw-r--r--usr.sbin/pkg_install/sign/Makefile.bsd-wrapper20
-rw-r--r--usr.sbin/pkg_install/sign/README36
-rw-r--r--usr.sbin/pkg_install/sign/check.c102
-rw-r--r--usr.sbin/pkg_install/sign/common.c83
-rw-r--r--usr.sbin/pkg_install/sign/extern.h73
-rw-r--r--usr.sbin/pkg_install/sign/gzip.c309
-rw-r--r--usr.sbin/pkg_install/sign/gzip.h85
-rw-r--r--usr.sbin/pkg_install/sign/main.c159
-rw-r--r--usr.sbin/pkg_install/sign/pgp.h23
-rw-r--r--usr.sbin/pkg_install/sign/pgp_check.c189
-rw-r--r--usr.sbin/pkg_install/sign/pgp_sign.c262
-rw-r--r--usr.sbin/pkg_install/sign/pkg_sign.1164
-rw-r--r--usr.sbin/pkg_install/sign/sha1.c207
-rw-r--r--usr.sbin/pkg_install/sign/sign.c132
-rw-r--r--usr.sbin/pkg_install/sign/stand.c54
-rw-r--r--usr.sbin/pkg_install/sign/stand.h19
52 files changed, 0 insertions, 8834 deletions
diff --git a/usr.sbin/pkg_install/add/Makefile b/usr.sbin/pkg_install/add/Makefile
deleted file mode 100644
index 5331c789bd2..00000000000
--- a/usr.sbin/pkg_install/add/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-# $OpenBSD: Makefile,v 1.3 1996/08/26 07:00:30 deraadt Exp $
-PROG= pkg_add
-
-CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
-
-.include <bsd.obj.mk>
-
-.if exists(${.CURDIR}/../lib/${__objdir})
-LDADD+= -L${.CURDIR}/../lib/${__objdir} -linstall
-DPADD+= ${.CURDIR}/../lib/${__objdir}/libinstall.a
-.else
-LDADD+= -L${.CURDIR}/../lib -linstall
-DPADD+= ${.CURDIR}/../lib/libinstall.a
-.endif
-
-
-SRCS= main.c perform.c futil.c extract.c
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/pkg_install/add/add.h b/usr.sbin/pkg_install/add/add.h
deleted file mode 100644
index 9145b95f4a9..00000000000
--- a/usr.sbin/pkg_install/add/add.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* $OpenBSD: add.h,v 1.3 1998/10/13 23:09:49 marc Exp $ */
-/* from FreeBSD Id: add.h,v 1.8 1997/02/22 16:09:15 peter Exp */
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Include and define various things wanted by the add command.
- *
- */
-
-#ifndef _INST_ADD_H_INCLUDE
-#define _INST_ADD_H_INCLUDE
-
-typedef enum { NORMAL, MASTER, SLAVE } add_mode_t;
-
-extern char *Prefix;
-extern Boolean NoInstall;
-extern Boolean NoRecord;
-extern Boolean Force;
-extern char *Mode;
-extern char *Owner;
-extern char *Group;
-extern char *Directory;
-extern char *PkgName;
-extern char FirstPen[];
-extern add_mode_t AddMode;
-
-int make_hierarchy(char *);
-void extract_plist(char *, package_t *);
-void apply_perms(char *, char *);
-
-#endif /* _INST_ADD_H_INCLUDE */
diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c
deleted file mode 100644
index 36254505490..00000000000
--- a/usr.sbin/pkg_install/add/extract.c
+++ /dev/null
@@ -1,258 +0,0 @@
-/* $OpenBSD: extract.c,v 1.16 2003/07/04 17:31:19 avsm Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: extract.c,v 1.16 2003/07/04 17:31:19 avsm Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the package extraction code for the add module.
- *
- */
-
-#include <err.h>
-#include "lib.h"
-#include "add.h"
-
-
-#define STARTSTRING "tar cf - "
-#define TOOBIG(str) ((strlen(str) + FILENAME_MAX + where_count > maxargs) \
- || (strlen(str) + FILENAME_MAX + perm_count > maxargs))
-
-#define PUSHOUT(todir) /* push out string */ \
- if (where_count > sizeof(STARTSTRING)-1) { \
- strlcat(where_args, "|tar xpf - -C ", maxargs); \
- strlcat(where_args, todir, maxargs); \
- if (system(where_args)) { \
- cleanup(0); \
- errx(2, "can not invoke %lu byte tar pipeline: %s", \
- (u_long)strlen(where_args), where_args); \
- } \
- strlcpy(where_args, STARTSTRING, maxargs); \
- where_count = sizeof(STARTSTRING)-1; \
- } \
- if (perm_count) { \
- apply_perms(todir, perm_args); \
- perm_args[0] = 0; \
- perm_count = 0; \
- }
-
-static void
-rollback(char *name, char *home, plist_t *start, plist_t *stop)
-{
- plist_t *q;
- char try[FILENAME_MAX], bup[FILENAME_MAX], *dir;
-
- dir = home;
- for (q = start; q != stop; q = q->next) {
- if (q->type == PLIST_FILE) {
- snprintf(try, sizeof(try), "%s/%s", dir, q->name);
- if (make_preserve_name(bup, sizeof(bup), name, try) && fexists(bup)) {
- (void)chflags(try, 0);
- (void)unlink(try);
- if (rename(bup, try))
- pwarnx("rollback: unable to rename %s back to %s", bup, try);
- }
- }
- else if (q->type == PLIST_CWD) {
- if (strcmp(q->name, "."))
- dir = q->name;
- else
- dir = home;
- }
- }
-}
-
-static int
-preserve(const char *fname)
-{
- char copy[FILENAME_MAX];
- int i;
-
- for (i = 0; i < 50; i++) {
- snprintf(copy, sizeof(copy), "%s-%d", fname, i);
- if (fexists(copy))
- continue;
- if (rename(fname, copy) == 0) {
- pwarnx("conflict: renamed existing %s to %s", fname, copy);
- return 0;
- }
- }
- return -1;
-}
-
-void
-extract_plist(char *home, package_t *pkg)
-{
- plist_t *p = pkg->head;
- char *last_file;
- char *where_args, *perm_args, *last_chdir;
- int maxargs, where_count = 0, perm_count = 0, add_count;
-
- maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
- where_args = alloca(maxargs);
- if (!where_args) {
- cleanup(0);
- errx(2, "can't get argument list space");
- }
- perm_args = alloca(maxargs);
- if (!perm_args) {
- cleanup(0);
- errx(2, "can't get argument list space");
- }
- strlcpy(where_args, STARTSTRING, maxargs);
- where_count = sizeof(STARTSTRING)-1;
- perm_args[0] = 0;
-
- last_chdir = 0;
-
- /* Reset the world */
- Owner = NULL;
- Group = NULL;
- Mode = NULL;
- last_file = NULL;
- Directory = home;
-
- /* Do it */
- while (p) {
- char cmd[FILENAME_MAX];
-
- switch(p->type) {
- case PLIST_NAME:
- PkgName = p->name;
- if (Verbose)
- printf("extract: Package name is %s\n", p->name);
- break;
-
- case PLIST_FILE:
- last_file = p->name;
- if (Verbose)
- printf("extract: %s/%s\n", Directory, p->name);
- if (!Fake) {
- char try[FILENAME_MAX];
-
- if (strrchr(p->name,'\'')) {
- cleanup(0);
- errx(2, "Bogus filename \"%s\"", p->name);
- }
-
- /* first try to rename it into place */
- snprintf(try, sizeof(try), "%s/%s", Directory, p->name);
- if (fexists(try)) {
- if (preserve(try) == -1) {
- pwarnx("unable to back up %s, aborting pkg_add", try);
- rollback(PkgName, home, pkg->head, p);
- return;
- }
- }
- if (rename(p->name, try) == 0) {
- /* try to add to list of perms to be changed and run in bulk. */
- if (p->name[0] == '/' || TOOBIG(p->name)) {
- PUSHOUT(Directory);
- }
- add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
- if (add_count > maxargs - perm_count) {
- cleanup(0);
- errx(2, "oops, miscounted strings!");
- }
- perm_count += add_count;
- } else {
- /* rename failed, try copying with a big tar command */
- if (last_chdir != Directory) {
- PUSHOUT(last_chdir);
- last_chdir = Directory;
- }
- else if (p->name[0] == '/' || TOOBIG(p->name)) {
- PUSHOUT(Directory);
- }
- add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
- if (add_count > maxargs - where_count) {
- cleanup(0);
- errx(2, "oops, miscounted strings!");
- }
- where_count += add_count;
- add_count = snprintf(&perm_args[perm_count],
- maxargs - perm_count,
- "'%s' ", p->name);
- if (add_count > maxargs - perm_count) {
- cleanup(0);
- errx(2, "oops, miscounted strings!");
- }
- perm_count += add_count;
- }
- }
- break;
-
- case PLIST_CWD:
- if (Verbose)
- printf("extract: CWD to %s\n", p->name);
- PUSHOUT(Directory);
- if (strcmp(p->name, ".")) {
- if (!Fake && make_hierarchy(p->name) == FAIL) {
- cleanup(0);
- errx(2, "unable to make directory '%s'", p->name);
- }
- Directory = p->name;
- } else
- Directory = home;
- break;
-
- case PLIST_CMD:
- if (!format_cmd(cmd, sizeof(cmd), p->name, Directory, last_file)) {
- cleanup(0);
- if (last_file == NULL)
- errx(2, "no last file specified for '%s' command", p->name);
- else
- errx(2, "'%s' command could not expand", p->name);
- }
-
- PUSHOUT(Directory);
- if (Verbose)
- printf("extract: execute '%s'\n", cmd);
- if (!Fake && system(cmd))
- pwarnx("command '%s' failed", cmd);
- break;
-
- case PLIST_CHMOD:
- PUSHOUT(Directory);
- Mode = p->name;
- break;
-
- case PLIST_CHOWN:
- PUSHOUT(Directory);
- Owner = p->name;
- break;
-
- case PLIST_CHGRP:
- PUSHOUT(Directory);
- Group = p->name;
- break;
-
- case PLIST_COMMENT:
- break;
-
- case PLIST_IGNORE:
- p = p->next;
- break;
-
- default:
- break;
- }
- p = p->next;
- }
- PUSHOUT(Directory);
-}
diff --git a/usr.sbin/pkg_install/add/futil.c b/usr.sbin/pkg_install/add/futil.c
deleted file mode 100644
index f6cacbc11bf..00000000000
--- a/usr.sbin/pkg_install/add/futil.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* $OpenBSD: futil.c,v 1.7 2003/07/04 17:31:19 avsm Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: futil.c,v 1.7 2003/07/04 17:31:19 avsm Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Miscellaneous file access utilities.
- *
- */
-
-#include <err.h>
-#include "lib.h"
-#include "add.h"
-
-/*
- * Assuming dir is a desired directory name, make it and all intervening
- * directories necessary.
- */
-
-int
-make_hierarchy(char *dir)
-{
- char *cp1, *cp2;
-
- if (dir[0] == '/')
- cp1 = cp2 = dir + 1;
- else
- cp1 = cp2 = dir;
- while (cp2) {
- if ((cp2 = strchr(cp1, '/')) !=NULL )
- *cp2 = '\0';
- if (fexists(dir)) {
- if (!(isdir(dir) || islinktodir(dir)))
- return FAIL;
- }
- else {
- if (vsystem("mkdir %s", dir))
- return FAIL;
- apply_perms(NULL, dir);
- }
- /* Put it back */
- if (cp2) {
- *cp2 = '/';
- cp1 = cp2 + 1;
- }
- }
- return SUCCESS;
-}
-
-/* Using permission defaults, apply them as necessary */
-void
-apply_perms(char *dir, char *arg)
-{
- char *cd_to;
-
- if (!dir || *arg == '/') /* absolute path? */
- cd_to = "/";
- else
- cd_to = dir;
-
- if (Owner || Group) {
- char *real_owner = Owner ? Owner : "";
- char *real_group = Group ? Group : "";
-
- if (vsystem("cd %s && chown -R %s:%s %s", cd_to, real_owner ,
- real_group, arg))
- pwarnx("couldn't change owner/group of '%s' to '%s:%s'",
- arg, real_owner, real_group);
- }
- if (Mode)
- if (vsystem("cd %s && chmod -R %s %s", cd_to, Mode, arg))
- pwarnx("couldn't change modes of '%s' to '%s'", arg, Mode);
-}
-
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c
deleted file mode 100644
index dd4997d1e5d..00000000000
--- a/usr.sbin/pkg_install/add/main.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/* $OpenBSD: main.c,v 1.18 2003/08/06 20:46:36 millert Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: main.c,v 1.18 2003/08/06 20:46:36 millert Exp $";
-#endif
-
-/*
- *
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the add module.
- *
- */
-
-#include <err.h>
-#include <sys/param.h>
-#include "lib.h"
-#include "add.h"
-
-static char Options[] = "hvIRfnp:SMt:";
-
-char *Prefix = NULL;
-Boolean NoInstall = FALSE;
-Boolean NoRecord = FALSE;
-
-char *Mode = NULL;
-char *Owner = NULL;
-char *Group = NULL;
-char *PkgName = NULL;
-char *Directory = NULL;
-char FirstPen[FILENAME_MAX];
-add_mode_t AddMode = NORMAL;
-
-char **pkgs;
-int pkg_count = 0;
-
-static void usage(void);
-
-int
-main(int argc, char **argv)
-{
- int ch, err;
- char **start;
- char *cp;
-
- start = argv;
- while ((ch = getopt(argc, argv, Options)) != -1) {
- switch(ch) {
- case 'v':
- Verbose = TRUE;
- break;
-
- case 'p':
- Prefix = optarg;
- break;
-
- case 'I':
- NoInstall = TRUE;
- break;
-
- case 'R':
- NoRecord = TRUE;
- break;
-
- case 'f':
- Force = TRUE;
- break;
-
- case 'n':
- Fake = TRUE;
- Verbose = TRUE;
- break;
-
- case 't':
- strlcpy(FirstPen, optarg, sizeof(FirstPen));
- break;
-
- case 'S':
- AddMode = SLAVE;
- break;
-
- case 'M':
- AddMode = MASTER;
- break;
-
- case 'h':
- case '?':
- default:
- usage();
- break;
- }
- }
- argc -= optind;
- argv += optind;
-
- pkg_count = argc + 1;
- pkgs = (char **)calloc(pkg_count, sizeof(char **));
- if (pkgs == NULL) {
- fprintf(stderr, "malloc failed - abandoning package add.\n");
- exit(1);
- }
-
- if (AddMode != SLAVE) {
-
- /* Get all the remaining package names, if any */
- for (ch = 0; *argv; ch++, argv++) {
- /* Don't mangle stdin ("-") or URL arguments */
- if ( (strcmp(*argv, "-") == 0)
- || (isURL(*argv))) {
- pkgs[ch] = strdup(*argv);
- if (pkgs[ch] == NULL) {
- fprintf(stderr,
- "malloc failed - abandoning package add.\n");
- exit(1);
- }
- }
- else { /* expand all pathnames to fullnames */
- char *s, *tmp;
-
- s=ensure_tgz(*argv);
-
- if (fexists(s)) { /* refers to a file directly */
- pkgs[ch] = (char *) malloc(MAXPATHLEN * sizeof(char));
- if (pkgs[ch] == NULL) {
- fprintf(stderr,
- "malloc failed - abandoning package add.\n");
- exit(1);
- }
- tmp = realpath(s, pkgs[ch]);
- if (tmp == NULL) {
- perror("realpath failed");
- fprintf(stderr, "failing path was %s\n", pkgs[ch]);
- exit(1);
- }
- }
- else if (ispkgpattern(*argv)
- && (s=findbestmatchingname(dirname_of(*argv),
- basename_of(*argv)))
- != NULL) {
- if (Verbose)
- printf("Using %s for %s\n",s, *argv);
- pkgs[ch] = (char *) malloc(MAXPATHLEN * sizeof(char));
- if (pkgs[ch] == NULL) {
- fprintf(stderr,
- "malloc failed - abandoning package add.\n");
- exit(1);
- }
- tmp = realpath(s, pkgs[ch]);
- if (tmp == NULL) {
- perror("realpath failed");
- fprintf(stderr, "failing path was %s\n", pkgs[ch]);
- exit(1);
- }
- free(s);
- } else {
- /* look for the file(pattern) in the expected places */
- if (!(cp = fileFindByPath(NULL, *argv))) {
- fprintf(stderr, "can't find package '%s'\n", *argv);
- exit(1);
- }
- else {
- pkgs[ch] = strdup(cp);
- if (pkgs[ch] == NULL) {
- fprintf(stderr,
- "malloc failed - abandoning package add.\n");
- exit(1);
- }
- }
- }
- }
- }
- /* If no packages, yelp */
- if (!ch)
- pwarnx("missing package name(s)"), usage();
- else if (ch > 1 && AddMode == MASTER)
- pwarnx("only one package name may be specified with master mode"),
- usage();
- }
- if ((err = pkg_perform(pkgs)) != 0) {
- if (Verbose)
- pwarnx("%d package addition(s) failed", err);
- return err;
- }
- else
- return 0;
-}
-
-static void
-usage()
-{
- fprintf(stderr, "%s\n",
- "usage: pkg_add [-vInfRMS] [-t template] [-p prefix] pkg-name ...");
- exit(1);
-}
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c
deleted file mode 100644
index 4970cc91545..00000000000
--- a/usr.sbin/pkg_install/add/perform.c
+++ /dev/null
@@ -1,618 +0,0 @@
-/* $OpenBSD: perform.c,v 1.32 2003/08/21 20:24:56 espie Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: perform.c,v 1.32 2003/08/21 20:24:56 espie Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the main body of the add module.
- *
- */
-
-#include <err.h>
-#include "lib.h"
-#include "add.h"
-
-#include <sys/wait.h>
-#include <ctype.h>
-#include <signal.h>
-#include <errno.h>
-
-static int pkg_do(char *);
-static int sanity_check(char *);
-static char LogDir[FILENAME_MAX];
-static int zapLogDir; /* Should we delete LogDir? */
-
-int
-pkg_perform(char **pkgs)
-{
- int i, err_cnt = 0;
-
- signal(SIGINT, cleanup);
- signal(SIGHUP, cleanup);
-
- if (AddMode == SLAVE)
- err_cnt = pkg_do(NULL);
- else {
- for (i = 0; pkgs[i]; i++)
- err_cnt += pkg_do(pkgs[i]);
- }
- return err_cnt;
-}
-
-static package_t Plist;
-static char *Home;
-
-/* called to see if pkg is already installed as some other version */
-/* note found version in "note" */
-static int
-check_if_installed(const char *found, char *note, int len)
-{
- strlcpy(note, found, len);
- return 0;
-}
-
-/*
- * This is seriously ugly code following. Written very fast!
- * [And subsequently made even worse.. Sigh! This code was just born
- * to be hacked, I guess.. :) -jkh]
- */
-static int
-pkg_do(char *pkg)
-{
- char pkg_fullname[FILENAME_MAX];
- char playpen[FILENAME_MAX];
- char extract_contents[FILENAME_MAX];
- char solve_deps[FILENAME_MAX+50];
- char *where_to, *tmp, *extract;
- char *dbdir;
- FILE *cfile;
- int code;
- plist_t *p;
- struct stat sb;
-
- set_pkg(pkg);
- code = 0;
- zapLogDir = 0;
- LogDir[0] = '\0';
- strlcpy(playpen, FirstPen, sizeof(playpen));
- dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR;
-
- snprintf(solve_deps, sizeof solve_deps, "pkg%s dependencies solve %s",
- Verbose ? " -v": "", CONTENTS_FNAME);
- if (Prefix)
- setenv("PKG_PREFIX", Prefix, 1);
- else
- unsetenv("PKG_PREFIX");
- /* Are we coming in for a second pass, everything already extracted? */
- /* (Slave mode) */
- if (!pkg) {
- fgets(playpen, FILENAME_MAX, stdin);
- playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */
- if (chdir(playpen) == FAIL) {
- pwarnx("add in SLAVE mode can't chdir to `%s'", playpen);
- return 1;
- }
- read_plist(&Plist, stdin);
- where_to = playpen;
- }
- /* Nope - do it now */
- else {
- /* Is it an ftp://foo.bar.baz/file.tgz specification? */
- if (isURL(pkg)) {
- if (ispkgpattern(pkg)) {
- pwarnx("patterns not allowed in URLs, "
- "please install manually!");
- /* ... until we come up with a better solution :-/ - HF */
- goto bomb;
- }
-
- if (!(Home = fileGetURL(NULL, pkg))) {
- pwarnx("unable to fetch `%s' by URL", pkg);
- return 1;
- }
- where_to = Home;
- strlcpy(pkg_fullname, pkg, sizeof(pkg_fullname));
- system(solve_deps);
- cfile = fopen(CONTENTS_FNAME, "r");
- if (!cfile) {
- pwarnx(
- "unable to open table of contents file `%s' - not a package?",
- CONTENTS_FNAME);
- goto bomb;
- }
- read_plist(&Plist, cfile);
- fclose(cfile);
- } else {
- strlcpy(pkg_fullname, ensure_tgz(pkg), sizeof(pkg_fullname));
- if (strcmp(pkg, "-")) {
- if (!ispkgpattern(pkg_fullname)
- && stat(pkg_fullname, &sb) == FAIL) {
- pwarnx("can't stat package file '%s'", pkg_fullname);
- goto bomb;
- }
- snprintf(extract_contents, sizeof( extract_contents ),
- "%s", CONTENTS_FNAME);
- extract = extract_contents;
- }
- else {
- extract = NULL;
- sb.st_size = 100000; /* Make up a plausible average size */
- }
- Home = make_playpen(playpen, sizeof(playpen), sb.st_size * 4);
- if (!Home)
- pwarnx("unable to make playpen for %ld bytes",
- (long)(sb.st_size * 4));
- where_to = Home;
- if (unpack(pkg_fullname, extract)) {
- pwarnx(
- "unable to extract table of contents from `%s'\n"
- "Is this a Package, or a simple .tgz archive ? See tar(1).",
- pkg_fullname);
- goto bomb;
- }
- system(solve_deps);
- cfile = fopen(CONTENTS_FNAME, "r");
- if (!cfile) {
- pwarnx(
- "unable to open table of contents file `%s'\n"
- "Is this a Package, or a simple .tgz archive ? See tar(1).",
- CONTENTS_FNAME);
- goto bomb;
- }
- read_plist(&Plist, cfile);
- fclose(cfile);
-
- /*
- * Apply a crude heuristic to see how much space the package will
- * take up once it's unpacked. I've noticed that most packages
- * compress an average of 75%, so multiply by 4 for good
- * measure. Ignore if extract is null as we've already
- * extracted the full file, anyway.
- */
-
- if (!extract && min_free(playpen) < sb.st_size * 4) {
- pwarnx("projected size of %ld exceeds available free space\n"
- "Please set your PKG_TMPDIR variable to point to a"
- "location with more\n"
- "free space and try again", (long)(sb.st_size * 4));
- pwarnx("not extracting `%s'\ninto `%s', sorry!", pkg_fullname,
- where_to);
- goto bomb;
- }
-
- /* Finally unpack the whole mess. If extract is null we already
- did so so don't bother doing it again. */
- if (extract && unpack(pkg_fullname, NULL)) {
- pwarnx("unable to extract `%s'!", pkg_fullname);
- goto bomb;
- }
- } /* isURL(pkg) */
-
- /* Check for sanity and dependencies */
- if (sanity_check(pkg))
- goto bomb;
-
- /* If we're running in MASTER mode, just output the plist and return */
- if (AddMode == MASTER) {
- printf("%s\n", where_playpen());
- write_plist(&Plist, stdout);
- return 0;
- }
- }
-
- /*
- * If we have a prefix, delete the first one we see and add this
- * one in place of it.
- */
- if (Prefix) {
- delete_plist(&Plist, FALSE, PLIST_CWD, NULL);
- add_plist_top(&Plist, PLIST_CWD, Prefix);
- }
-
- setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1);
- /* Protect against old packages with bogus @name fields */
- PkgName = (p = find_plist(&Plist, PLIST_NAME)) ? p->name : NULL;
- if (PkgName == NULL) {
- pwarnx("package name not set in package file");
- goto bomb;
- }
-
- /* See if we're already registered */
- (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", dbdir, PkgName);
- if ((isdir(LogDir) || islinktodir(LogDir)) && !Force) {
- pwarnx("package already recorded as installed");
- code = 1;
- goto success; /* close enough for government work */
- }
-
- /* See if some other version of us is already installed */
- {
- char buf[FILENAME_MAX];
- char installed[FILENAME_MAX];
- char *s;
-
- if ((s=strrchr(PkgName, '-')) != NULL){
- strlcpy(buf, PkgName, sizeof(buf));
- /* try to find a better version number */
- if (!isdigit(s[1])) {
- char *t;
- for (t = s-1; t >= PkgName; t--)
- if (*t == '-' && isdigit(t[1])) {
- s = t;
- break;
- }
- }
- strlcpy(buf+(s-PkgName+1), isdigit(s[1]) ? "[0-9]*" : "*", sizeof(buf)-(s-PkgName+1));
-
- if (findmatchingname(dbdir, buf, check_if_installed, installed, sizeof(installed))) {
- pwarnx("other version '%s' already installed", installed);
- if (find_plist_option(&Plist, "no-default-conflict") != NULL) {
- pwarnx("proceeding with installation anyway");
- } else {
- code = 1;
- goto success; /* close enough for government work */
- }
- }
- }
- }
-
- /* See if there are conflicting packages installed */
- for (p = Plist.head; p ; p = p->next) {
- char installed[FILENAME_MAX];
-
- if (p->type != PLIST_PKGCFL)
- continue;
- if (Verbose)
- printf("Package `%s' conflicts with `%s'\n", PkgName, p->name);
-
- /* was: */
- /* if (!vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) {*/
- if(findmatchingname(dbdir, p->name, check_if_installed, installed, sizeof(installed))){
- pwarnx("Conflicting package installed, please use\n\t\"pkg_delete %s\" first to remove it!", installed);
- ++code;
- }
- }
-
- /* Now check the packing list for dependencies */
- for (p = Plist.head; p ; p = p->next) {
- char installed [FILENAME_MAX];
-
- if (p->type != PLIST_PKGDEP)
- continue;
- if (Verbose)
- printf("Package `%s' depends on `%s'\n", PkgName, p->name);
- /* if (vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
- if (!findmatchingname(dbdir, p->name, check_if_installed, installed, sizeof(installed))) {
- char path[FILENAME_MAX], *cp = NULL;
-
- if (!Fake) {
- if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) {
- /* install depending pkg from local disk */
-
- snprintf(path, sizeof(path), "%s/%s", Home, ensure_tgz(p->name));
- if (fexists(path))
- cp = path;
- else
- cp = fileFindByPath(pkg, p->name);
- if (cp) {
- if (Verbose)
- printf("Loading it from `%s'\n", cp);
- if (vsystem("/usr/sbin/pkg_add %s%s %s%s",
- Prefix ? "-p " : "",
- Prefix ? Prefix : "",
- Verbose ? "-v " : "", cp)) {
- pwarnx("autoload of dependency `%s' failed%s",
- cp, Force ? " (proceeding anyway)" : "!");
- if (!Force)
- ++code;
- }
- }
- else {
- pwarnx("add of dependency `%s' failed%s",
- p->name, Force ? " (proceeding anyway)" : "!");
- if (!Force)
- ++code;
- }
- } else {
- /* install depending pkg via FTP */
-
- if (ispkgpattern(p->name)){
- pwarnx("can't install dependent pkg '%s' via FTP, "
- "please install manually!", p->name);
- /* ... until we come up with a better solution - HF */
- goto bomb;
- }else{
- char *saved_Current; /* allocated/set by save_dirs(), */
- char *saved_Previous; /* freed by restore_dirs() */
-
- save_dirs(&saved_Current, &saved_Previous);
-
- if ((cp = fileGetURL(pkg, p->name)) != NULL) {
- if (Verbose)
- printf("Finished loading `%s' over FTP\n", p->name);
- system(solve_deps);
- if (!fexists(CONTENTS_FNAME)) {
- pwarnx("autoloaded package `%s' has no %s file?",
- p->name, CONTENTS_FNAME);
- if (!Force)
- ++code;
- }
- else if (vsystem("(pwd; cat %s) | pkg_add %s%s %s-S",
- CONTENTS_FNAME,
- Prefix ? "-p " : "",
- Prefix ? Prefix : "",
- Verbose ? "-v " : "")) {
- pwarnx("add of dependency `%s' failed%s",
- p->name, Force ? " (proceeding anyway)" : "!");
- if (!Force)
- ++code;
- }
- else if (Verbose)
- printf("\t`%s' loaded successfully\n", p->name);
- /* Nuke the temporary playpen */
- leave_playpen(cp);
- free(cp);
-
- restore_dirs(saved_Current, saved_Previous);
- }
- }
- }
- } else {
- if (Verbose)
- printf("and was not found%s\n", Force ? " (proceeding anyway)" : "");
- else
- printf("Package dependency `%s' for `%s' not found%s\n", p->name, pkg,
- Force ? " (proceeding anyway)" : "!");
- if (!Force)
- ++code;
- }
- }
- else if (Verbose)
- printf(" - `%s' already installed\n", installed);
- }
-
- if (code != 0)
- goto bomb;
-
- /* Look for the requirements file */
- if (fexists(REQUIRE_FNAME)) {
- vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */
- if (Verbose)
- printf("Running requirements file first for `%s'\n", PkgName);
- if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, PkgName)) {
- pwarnx("package `%s' fails requirements %s", pkg_fullname,
- Force ? "installing anyway" : "- not installed");
- if (!Force) {
- code = 1;
- goto success; /* close enough for government work */
- }
- }
- }
-
- /* If we're really installing, and have an installation file, run it */
- if (!NoInstall && fexists(INSTALL_FNAME)) {
- vsystem("chmod +x %s", INSTALL_FNAME); /* make sure */
- if (Verbose)
- printf("Running install with PRE-INSTALL for `%s'\n", PkgName);
- if (!Fake && vsystem("./%s %s PRE-INSTALL", INSTALL_FNAME, PkgName)) {
- pwarnx("install script returned error status");
- unlink(INSTALL_FNAME);
- code = 1;
- goto success; /* nothing to uninstall yet */
- }
- }
-
- extract_plist(".", &Plist);
-
- if (!Fake && fexists(MTREE_FNAME)) {
- if (Verbose)
- printf("Running mtree for `%s'\n", PkgName);
- p = find_plist(&Plist, PLIST_CWD);
- if (Verbose)
- printf("mtree -q -U -f %s -d -e -p %s\n", MTREE_FNAME,
- p ? p->name : "/");
- if (!Fake) {
-
- if (vsystem("/usr/sbin/mtree -q -U -f %s -d -e -p %s", MTREE_FNAME,
- p ? p->name : "/"))
- pwarnx("mtree returned a non-zero status - continuing");
- }
- unlink(MTREE_FNAME);
- }
-
- /* Run the installation script one last time? */
- if (!NoInstall && fexists(INSTALL_FNAME)) {
- if (Verbose)
- printf("Running install with POST-INSTALL for `%s'\n", PkgName);
- if (!Fake && vsystem("./%s %s POST-INSTALL", INSTALL_FNAME, PkgName)) {
- pwarnx("install script returned error status");
- unlink(INSTALL_FNAME);
- code = 1;
- goto fail;
- }
- unlink(INSTALL_FNAME);
- }
-
- /* Time to record the deed? */
- if (!NoRecord && !Fake) {
- char contents[FILENAME_MAX];
- FILE *cfile;
-
- umask(022);
- if (getuid() != 0)
- pwarnx("not running as root - trying to record install anyway");
- if (!PkgName) {
- pwarnx("no package name! can't record package, sorry");
- code = 1;
- goto success; /* well, partial anyway */
- }
- (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", dbdir, PkgName);
- zapLogDir = 1;
- if (Verbose)
- printf("Attempting to record package into `%s'\n", LogDir);
- if (make_hierarchy(LogDir)) {
- pwarnx("can't record package into '%s', you're on your own!",
- LogDir);
- memset(LogDir, 0, FILENAME_MAX);
- code = 1;
- goto success; /* close enough for government work */
- }
- /* Make sure pkg_info can read the entry */
- vsystem("chmod a+rx %s", LogDir);
- if (fexists(DEINSTALL_FNAME))
- move_file(".", DEINSTALL_FNAME, LogDir);
- if (fexists(REQUIRE_FNAME))
- move_file(".", REQUIRE_FNAME, LogDir);
- (void) snprintf(contents, sizeof(contents), "%s/%s", LogDir, CONTENTS_FNAME);
- cfile = fopen(contents, "w");
- if (!cfile) {
- pwarnx("can't open new contents file '%s'! can't register pkg",
- contents);
- goto success; /* can't log, but still keep pkg */
- }
- write_plist(&Plist, cfile);
- fclose(cfile);
- move_file(".", DESC_FNAME, LogDir);
- move_file(".", COMMENT_FNAME, LogDir);
- if (fexists(DISPLAY_FNAME))
- move_file(".", DISPLAY_FNAME, LogDir);
-
- /* register dependencies */
- /* we could save some cycles here if we remembered what we installed
- * above (in case we got a wildcard dependency) */
- /* XXX remembering in p->name would NOT be good! */
- for (p = Plist.head; p ; p = p->next) {
- if (p->type != PLIST_PKGDEP)
- continue;
- if (Verbose)
- printf("Attempting to record dependency on package `%s'\n", p->name);
- (void) snprintf(contents, sizeof(contents), "%s/%s", dbdir,
- basename_of(p->name));
- if (ispkgpattern(p->name)) {
- char *s;
- s=findbestmatchingname(dirname_of(contents),
- basename_of(contents));
- if (s != NULL) {
- char *t;
- t=strrchr(contents, '/');
- strlcpy(t+1, s, contents + sizeof(contents) - (t+1));
- free(s);
- }else{
- errx(1,"Where did our dependency go?!");
- /* this shouldn't happen... X-) */
- }
- }
- strlcat(contents, "/", sizeof(contents));
- strlcat(contents, REQUIRED_BY_FNAME, sizeof(contents));
-
- cfile = fopen(contents, "a");
- if (!cfile)
- pwarnx("can't open dependency file '%s'!\n"
- "dependency registration is incomplete", contents);
- else {
- fprintf(cfile, "%s\n", PkgName);
- if (fclose(cfile) == EOF)
- pwarnx("cannot properly close file `%s'", contents);
- }
- }
- if (Verbose)
- printf("Package `%s' registered in `%s'\n", PkgName, LogDir);
- }
-
- if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) {
- char *Pager;
- char buf[BUFSIZ];
- struct stat sbuf;
-
- Pager = getenv("PAGER");
- if (!Pager)
- Pager = "/usr/bin/more";
-
- snprintf(buf, sizeof buf, "%s/%s", LogDir, p->name);
- if (stat(buf,&sbuf) == -1 || vsystem("%s %s", Pager, buf))
- pwarnx("cannot open `%s' as display file", buf);
- }
-
- goto success;
-
- bomb:
- code = 1;
- goto success;
-
- fail:
- /* Nuke the whole (installed) show, XXX but don't clean directories */
- if (!Fake)
- delete_package(FALSE, FALSE, FALSE, FALSE, &Plist);
-
- success:
- /* delete the packing list contents */
- free_plist(&Plist);
- leave_playpen(Home);
- return code;
-}
-
-static int
-sanity_check(char *pkg)
-{
- int code = 0;
-
- if (!fexists(CONTENTS_FNAME)) {
- pwarnx("package `%s' has no CONTENTS file!", pkg);
- code = 1;
- }
- else if (!fexists(COMMENT_FNAME)) {
- pwarnx("package `%s' has no COMMENT file!", pkg);
- code = 1;
- }
- else if (!fexists(DESC_FNAME)) {
- pwarnx("package `%s' has no DESC file!", pkg);
- code = 1;
- }
- return code;
-}
-
-void
-cleanup(int signo)
-{
- int save_errno = errno;
- static int alreadyCleaning;
- void (*oldint)(int);
- void (*oldhup)(int);
- char buf[1024];
- oldint = signal(SIGINT, SIG_IGN);
- oldhup = signal(SIGHUP, SIG_IGN);
-
- /* XXX big signal race, nearly all of it! */
- if (!alreadyCleaning) {
- alreadyCleaning = 1;
- if (signo) {
- snprintf(buf, sizeof buf,
- "Signal %d received, cleaning up\n", signo);
- write(STDOUT_FILENO, buf, strlen(buf));
- }
- if (!Fake && zapLogDir && LogDir[0])
- vsystem("%s -rf %s", REMOVE_CMD, LogDir); /* XXX */
- leave_playpen(Home); /* XXX */
- if (signo)
- _exit(1);
- }
- signal(SIGINT, oldint);
- signal(SIGHUP, oldhup);
- errno = save_errno;
-}
diff --git a/usr.sbin/pkg_install/add/pkg_add.1 b/usr.sbin/pkg_install/add/pkg_add.1
deleted file mode 100644
index 6cd9ffe52ec..00000000000
--- a/usr.sbin/pkg_install/add/pkg_add.1
+++ /dev/null
@@ -1,444 +0,0 @@
-.\" $OpenBSD: pkg_add.1,v 1.32 2003/07/14 13:38:24 jmc Exp $
-.\"
-.\" FreeBSD install - a package for the installation and maintenance
-.\" of non-core utilities.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" Jordan K. Hubbard
-.\"
-.\"
-.\" @(#)pkg_add.1
-.\"
-.Dd November 25, 1994
-.Dt PKG_ADD 1
-.Os
-.Sh NAME
-.Nm pkg_add
-.Nd install software package distributions
-.Sh SYNOPSIS
-.Nm pkg_add
-.Op Fl vInfRMS
-.Op Fl t Ar template
-.Op Fl p Ar prefix
-.Ar pkg-name Op Ar ...
-.Sh DESCRIPTION
-The
-.Nm
-command is used to extract packages that have been previously created
-with the
-.Xr pkg_create 1
-command.
-Selected packages containing pre-compiled applications from the
-.Pa /usr/ports
-tree can be found on the
-.Ox
-FTP site or on the official
-.Ox
-CD.
-These packages are provided as a convenience for quickly installing software
-that would otherwise need to be built manually.
-.Bd -filled -offset indent
-.Em Note :
-System distribution files, e.g. base28.tgz, comp28.tgz, etc., are
-.Em not
-packages and may not be installed using
-.Nm pkg_add .
-.Ed
-.Pp
-Package names may be specified as filenames (which normally consist of the
-package name itself plus the
-.Dq .tgz ,
-.Dq .tar.gz ,
-or
-.Dq .tar
-suffix) or an FTP location in the form of an URL.
-For example, the following is valid:
-.Pp
-.Ic pkg_add -v ftp://ftp.openbsd.org/pub/OpenBSD/2.7/packages/i386/m4-1.4.tgz
-.Pp
-If the given package names are not found in the current working directory,
-.Nm
-will search for them in each directory named by the
-.Ev PKG_PATH
-environment variable.
-Specifying
-.Ql -
-as a package name causes
-.Nm
-to read from the standard input.
-.Pp
-Alternatively, it is possible to add packages interactively from within
-the ftp client.
-For example, the following works:
-.Bd -literal
- $ ftp ftp://ftp.openbsd.org/pub/OpenBSD/2.7/packages/i386/
- 250 CWD command successful
- ftp> ls m*
- 227 Entering Passive Mode (129,128,5,191,164,73)
- 150 Opening ASCII mode data connection for m*.
- m4-1.4.tgz
- metamail-2.7.tgz
- mh-6.8.4.tgz
- mm-1.0.12.tgz
- mpeg_lib-1.2.1.tgz
- mpeg_play-2.4.tgz
- mpg123-0.59q.tgz
- mutt-0.95.7i.tgz
- 226 Transfer complete.
- ftp> get m4-1.4.tgz "|pkg_add -v -"
-.Ed
-.Pp
-.Sy Warning:
-Since the
-.Nm
-command may execute scripts or programs contained within a package file,
-your system may be susceptible to
-.Dq trojan horses
-or other subtle attacks from miscreants who create dangerous packages.
-Be sure the specified package(s) are from trusted sources.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl v
-Turn on verbose output.
-.It Fl I
-If an installation script exists for a given package, do not execute it.
-.It Fl n
-Don't actually install a package, just report the steps that
-would be taken if it was.
-.It Fl R
-Do not record the installation of a package.
-This means that you cannot deinstall it later, so only use this option if
-you know what you are doing!
-.It Fl f
-Force installation to proceed even if prerequisite packages are not
-installed or the requirements script fails.
-Although
-.Nm
-will still try to find and auto-install missing prerequisite packages,
-a failure to find one will not be fatal.
-.It Fl p Ar prefix
-Set
-.Ar prefix
-as the directory in which to extract files from a package.
-If a package has set its default directory, it will be overridden
-by this flag.
-Note that only the first
-.Cm @cwd
-directive will be replaced, since
-.Nm
-has no way of knowing which directory settings are relative and
-which are absolute.
-It is rare in any case to see more than one
-directory transition made, but when such does happen and you wish
-to have control over
-.Em all
-directory transitions, then you may then wish to look into the use of
-.Cm MASTER
-and
-.Cm SLAVE
-modes (see the
-.Fl M
-and
-.Fl S
-options).
-.It Fl t Ar template
-Use
-.Ar template
-as the input to
-.Xr mkdtemp 3
-when creating a
-.Dq staging area .
-By default, this is the string
-.Pa /var/tmp/instmp.XXXXXX ,
-but it may be necessary to override it (see CAVEATS).
-Be sure to leave some number of
-.Dq X
-characters for
-.Xr mkdtemp 3
-to fill in with a unique ID.
-.Pp
-You can get a performance boost by setting the staging area
-.Ar template
-to reside on the same disk partition as target directories for package
-file installation; often this is
-.Pa /usr .
-.It Fl M
-Run in
-.Cm MASTER
-mode.
-This is a very specialized mode for running
-.Nm
-and is meant to be run in conjunction with
-.Cm SLAVE
-mode.
-When run in this mode,
-.Nm
-does no work beyond extracting the package into a temporary staging
-area (see the
-.Fl t
-option), reading in the packing list, and then dumping it (prefaced by
-the current staging area) to the standard output where it may be filtered by a
-program such as
-.Xr sed 1 .
-When used in conjunction with
-.Cm SLAVE
-mode, it allows you to make radical changes to the package structure
-before acting on its contents.
-.It Fl S
-Run in
-.Cm SLAVE
-mode.
-This is a very specialized mode for running
-.Nm
-and is meant to be run in conjunction with
-.Cm MASTER
-mode.
-When run in this mode,
-.Nm
-expects the release contents to be already extracted and waiting
-in the staging area, the location of which is read as a string
-from the standard input.
-The complete packing list is also read from stdin,
-and the contents then acted on as normal.
-.El
-.Pp
-By default, when adding packages via FTP, the
-.Xr ftp 1
-program operates in
-.Dq passive
-mode.
-If you wish to use active mode instead, set the
-.Ev FTPMODE
-environment variable to
-.Qq active .
-If
-.Nm
-consistently fails to fetch a package from a site known to work,
-it may be because the site does not support
-passive mode ftp correctly.
-This is very rare since
-.Nm
-will try active mode ftp if the server refuses a passive mode
-connection.
-.Ss Technical details
-.Nm
-extracts each package's
-.Dq packing list
-into a special staging directory in
-.Pa /var/tmp
-(or
-.Ev PKG_TMPDIR
-if set - see CAVEATS section)
-and then runs through the following sequence to fully extract the contents
-of the package:
-.Bl -enum
-.It
-A check is made to determine if the package is already recorded as installed.
-If it is,
-installation is terminated.
-.It
-A check is made to determine if the package conflicts (from
-.Cm @pkgcfl
-directives, see
-.Xr pkg_create 1 )
-with an already recorded as installed package.
-If it is, installation is terminated.
-.It
-All package dependencies (from
-.Cm @pkgdep
-directives, see
-.Xr pkg_create 1 )
-are read from the packing list.
-If any of these required packages are not currently installed,
-an attempt is made to find and install it;
-if the missing package cannot be found or installed,
-the installation is terminated.
-.It
-A staging area is created under
-.Pa /var/tmp ,
-and the package is extracted into the staging area.
-.It
-If the package contains a
-.Ar require
-script (see
-.Xr pkg_create 1 ) ,
-it is executed with the following arguments:
-.Bl -tag -width indentindent
-.It Ar pkg-name
-The name of the package being installed
-.It Cm INSTALL
-Keyword denoting to the script that it is to run an installation requirements
-check
-(the keyword is useful only to scripts which serve multiple functions).
-.El
-.Pp
-If the
-.Ar require
-script exits with a non-zero status code, the installation is terminated.
-.It
-If the package contains an
-.Ar install
-script, it is executed with the following arguments:
-.Bl -tag -width indentindent
-.It Ar pkg-name
-The name of the package being installed.
-.It Cm PRE-INSTALL
-Keyword denoting that the script is to perform any actions needed before
-the package is installed.
-.El
-.Pp
-If the
-.Ar install
-script exits with a non-zero status code, the installation is terminated.
-.It
-The packing list is used as a guide for moving (or copying, as necessary)
-files from the staging area into their final locations.
-.It
-If the package contains an
-.Ar mtreefile
-file (see
-.Xr pkg_create 1 ) ,
-then mtree is invoked as:
-.Pp
-.Bd -filled -offset indent -compact
-.Cm mtree
-.Fl u
-.Fl f
-.Ar mtreefile
-.Fl d
-.Fl e
-.Fl p
-.Pa prefix
-.Ed
-.Pp
-where
-.Pa prefix
-is either the prefix specified with the
-.Fl p
-flag or, if no
-.Fl p
-flag was specified, the name of the first directory named by a
-.Cm @cwd
-directive within this package.
-.It
-If an
-.Ar install
-script exists for the package, it is executed with the following arguments:
-.Bl -tag -width indentindent
-.It Ar pkg_name
-The name of the package being installed.
-.It Cm POST-INSTALL
-Keyword denoting that the script is to perform any actions needed
-after the package has been installed.
-.El
-.It
-After installation is complete, a copy of the packing list,
-.Ar deinstall
-script, description, and display files are copied into
-.Pa /var/db/pkg/<pkg-name>
-for subsequent possible use by
-.Xr pkg_delete 1 .
-Any package dependencies are recorded in the other packages'
-.Pa /var/db/pkg/<other-pkg>/+REQUIRED_BY
-file
-(if the environment variable
-.Ev PKG_DBDIR
-is set, this overrides the
-.Pa /var/db/pkg/
-path shown above).
-.It
-Finally, the staging area is deleted and the program terminates.
-.El
-.Pp
-The
-.Ar install
-and
-.Ar require
-scripts are called with the environment variable
-.Ev PKG_PREFIX
-set to the installation prefix (see the
-.Fl p
-option above).
-This allows a package author to write a script
-that reliably performs some action on the directory where the package
-is installed, even if the user might change it with the
-.Fl p
-flag to
-.Cm pkg_add .
-.Sh ENVIRONMENT
-.Bl -tag -width PKG_TMPDIR
-.It Ev PKG_PATH
-If a given package name cannot be found,
-the directories named by
-.Ev PKG_PATH
-are searched.
-It should contain a series of entries separated by colons.
-Each entry consists of a directory name.
-The current directory may be indicated
-implicitly by an empty directory name, or explicitly by a single
-period
-.Pq Ql \&. .
-.It Ev PKG_DBDIR
-Where to register packages instead of
-.Pa /var/db/pkg .
-.It Ev PKG_TMPDIR
-Temporary area where packages will be extracted, instead of
-.Pa /var/tmp .
-.El
-.Sh SEE ALSO
-.Xr pkg_create 1 ,
-.Xr pkg_delete 1 ,
-.Xr pkg_info 1 ,
-.Xr mkdtemp 3 ,
-.Xr sysconf 3 ,
-.Xr mtree 8
-.Sh AUTHORS
-.Bl -tag -width indent -compact
-.It "Jordan Hubbard"
-Initial work and ongoing development.
-.It "John Kohl"
-.Nx
-refinements.
-.El
-.Sh CAVEATS
-Package extraction does need a temporary area that
-.Bl -bullet -compact
-.It
-is big enough to hold the complete extracted package,
-.It
-can hold executable scripts.
-.El
-.Pp
-.Nm
-looks through ${PKG_TMPDIR}, ${TMPDIR}, /var/tmp, /tmp, /usr/tmp
-for such an area, in sequence.
-.Pp
-If ${TMPDIR} and /var/tmp are mounted noexec, you must set PKG_TMPDIR
-to a suitable area, as
-.Nm
-has no way to check for noexec status except by failing to run installation
-scripts.
-.Sh BUGS
-Hard links between files in a distribution are only preserved if either
-(1) the staging area is on the same file system as the target directory of
-all the links to the file, or (2) all the links to the file are bracketed by
-.Cm @cwd
-directives in the contents file,
-.Em and
-the link names are extracted with a single
-.Xr tar 1
-command (not split between
-invocations due to exec argument-space limitations; this depends on the
-value returned by
-.Fn sysconf _SC_ARG_MAX ) .
-.Pp
-Sure to be others.
diff --git a/usr.sbin/pkg_install/create/Makefile b/usr.sbin/pkg_install/create/Makefile
deleted file mode 100644
index 39a9ccdad47..00000000000
--- a/usr.sbin/pkg_install/create/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-# $OpenBSD: Makefile,v 1.3 1996/08/26 07:00:31 deraadt Exp $
-PROG= pkg_create
-
-CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
-
-.include <bsd.obj.mk>
-
-.if exists(${.CURDIR}/../lib/${__objdir})
-LDADD+= -L${.CURDIR}/../lib/${__objdir} -linstall
-DPADD+= ${.CURDIR}/../lib/${__objdir}/libinstall.a
-.else
-LDADD+= -L${.CURDIR}/../lib -linstall
-DPADD+= ${.CURDIR}/../lib/libinstall.a
-.endif
-
-
-SRCS= main.c perform.c pl.c
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h
deleted file mode 100644
index df48334bae7..00000000000
--- a/usr.sbin/pkg_install/create/create.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* $OpenBSD: create.h,v 1.4 2003/08/15 00:03:22 espie Exp $ */
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Include and define various things wanted by the create command.
- *
- */
-
-#ifndef _INST_CREATE_H_INCLUDE
-#define _INST_CREATE_H_INCLUDE
-
-extern char *Prefix;
-extern char *Comment;
-extern char *Desc;
-extern char *Display;
-extern char *Install;
-extern char *DeInstall;
-extern char *Contents;
-extern char *Require;
-extern char *SrcDir;
-extern char *ExcludeFrom;
-extern char *Mtree;
-extern char *Pkgdeps;
-extern char *Pkgcfl;
-extern char *BaseDir;
-extern char PlayPen[];
-extern size_t PlayPenSize;
-extern int Dereference;
-extern int PlistOnly;
-
-void check_list(char *, package_t *);
-int pkg_perform(char **);
-void copy_plist(char *, package_t *);
-
-#endif /* _INST_CREATE_H_INCLUDE */
diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c
deleted file mode 100644
index 7d943066380..00000000000
--- a/usr.sbin/pkg_install/create/main.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/* $OpenBSD: main.c,v 1.13 2003/08/15 00:03:22 espie Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: main.c,v 1.13 2003/08/15 00:03:22 espie Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the create module.
- *
- */
-
-#include <err.h>
-#include "lib.h"
-#include "create.h"
-
-static char Options[] = "Ohvf:p:P:C:c:d:i:k:r:t:X:D:m:s:S:";
-
-char *Prefix = NULL;
-char *Comment = NULL;
-char *Desc = NULL;
-char *SrcDir = NULL;
-char *Display = NULL;
-char *Install = NULL;
-char *DeInstall = NULL;
-char *Contents = NULL;
-char *Require = NULL;
-char *ExcludeFrom = NULL;
-char *Mtree = NULL;
-char *Pkgdeps = NULL;
-char *Pkgcfl = NULL;
-char *BaseDir = NULL;
-char PlayPen[FILENAME_MAX];
-size_t PlayPenSize = sizeof(PlayPen);
-int Dereference = 0;
-int PlistOnly = 0;
-
-static void usage(void);
-
-int
-main(int argc, char **argv)
-{
- int ch;
- char **pkgs, **start;
-
- pkgs = start = argv;
- while ((ch = getopt(argc, argv, Options)) != -1)
- switch(ch) {
- case 'v':
- Verbose = TRUE;
- break;
-
- case 'O':
- PlistOnly = YES;
- break;
-
- case 'p':
- Prefix = optarg;
- break;
-
- case 's':
- SrcDir = optarg;
- break;
-
- case 'S':
- BaseDir = optarg;
- break;
-
- case 'f':
- Contents = optarg;
- break;
-
- case 'c':
- Comment = optarg;
- break;
-
- case 'd':
- Desc = optarg;
- break;
-
- case 'i':
- Install = optarg;
- break;
-
- case 'k':
- DeInstall = optarg;
- break;
-
- case 'r':
- Require = optarg;
- break;
-
- case 't':
- strlcpy(PlayPen, optarg, PlayPenSize);
- break;
-
- case 'X':
- /* XXX this won't work until someone adds the gtar -X option
- (--exclude-from-file) to paxtar - so long it is disabled
- in perform.c */
- printf("WARNING: the -X option is not supported in OpenBSD\n");
- ExcludeFrom = optarg;
- break;
-
- case 'h':
- Dereference = 1;
- break;
-
- case 'D':
- Display = optarg;
- break;
-
- case 'm':
- Mtree = optarg;
- break;
-
- case 'P':
- Pkgdeps = optarg;
- break;
-
- case 'C':
- Pkgcfl = optarg;
- break;
-
- case '?':
- default:
- usage();
- break;
- }
-
- argc -= optind;
- argv += optind;
-
- /* Get all the remaining package names, if any */
- while (*argv)
- *pkgs++ = *argv++;
-
- /* If no packages, yelp */
- if (pkgs == start)
- pwarnx("missing package name"), usage();
- *pkgs = NULL;
- if (start[1])
- pwarnx("only one package name allowed ('%s' extraneous)", start[1]),
- usage();
- if (!pkg_perform(start)) {
- if (Verbose)
- pwarnx("package creation failed");
- return 1;
- }
- else
- return 0;
-}
-
-static void
-usage()
-{
- fprintf(stderr, "%s\n%s\n%s\n%s\n",
-"usage: pkg_create [-Ohv] [-P dpkgs] [-C cpkgs] [-p prefix] [-f contents]",
-" [-i iscript] [-k dscript] [-r rscript] [-t template]",
-" [-X excludefile] [-D displayfile] [-m mtreefile]",
-" -c comment -d description -f packlist -S basedir pkg-name");
- exit(1);
-}
diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c
deleted file mode 100644
index 83c2ddb3694..00000000000
--- a/usr.sbin/pkg_install/create/perform.c
+++ /dev/null
@@ -1,394 +0,0 @@
-/* $OpenBSD: perform.c,v 1.17 2003/08/27 06:51:26 jolan Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: perform.c,v 1.17 2003/08/27 06:51:26 jolan Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the main body of the create module.
- *
- */
-
-#include "lib.h"
-#include "create.h"
-
-#include <sys/syslimits.h>
-#include <sys/wait.h>
-
-#include <err.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-
-static void sanity_check(void);
-static void make_dist(char *, char *, char *, package_t *);
-
-static char *home;
-
-int
-pkg_perform(char **pkgs)
-{
- char *pkg = *pkgs; /* Only one arg to create */
- char *cp;
- FILE *pkg_in, *fp;
- package_t plist;
- char *suffix; /* What we tack on to the end of the finished package */
-
- /* Preliminary setup */
- sanity_check();
- if (Verbose && !PlistOnly)
- printf("Creating package %s\n", pkg);
- get_dash_string(&Comment);
- if (strlen(Comment) > MAXINDEXSIZE && !PlistOnly) {
- errx(2,"Comment string is over %d characters long:\n%s",
- MAXINDEXSIZE, Comment);
- }
- get_dash_string(&Desc);
- if (!strcmp(Contents, "-"))
- pkg_in = stdin;
- else {
- pkg_in = fopen(Contents, "r");
- if (!pkg_in) {
- cleanup(0);
- errx(2, "unable to open contents file '%s' for input", Contents);
- }
- }
- plist.head = plist.tail = NULL;
-
- /* Break the package name into base and desired suffix (if any) */
- if ((cp = strrchr(pkg, '.')) != NULL) {
- suffix = cp + 1;
- *cp = '\0';
- }
- else
- suffix = "tgz";
-
- if (Prefix)
- add_plist(&plist, PLIST_CWD, Prefix);
- /* If a SrcDir override is set, add it now */
- if (SrcDir) {
- if (Verbose && !PlistOnly)
- printf("Using SrcDir value of %s\n", SrcDir);
- add_plist(&plist, PLIST_SRC, SrcDir);
- }
-
- /* Stick the dependencies, if any, at the top */
- if (Pkgdeps) {
- if (Verbose && !PlistOnly)
- printf("Registering depends:");
- while (Pkgdeps) {
- cp = strsep(&Pkgdeps, " \t\n");
- if (*cp) {
- add_plist(&plist, PLIST_PKGDEP, cp);
- if (Verbose && !PlistOnly)
- printf(" %s", cp);
- }
- }
- if (Verbose && !PlistOnly)
- printf(".\n");
- }
-
- /* Put the conflicts directly after the dependencies, if any */
- if (Pkgcfl) {
- if (Verbose && !PlistOnly)
- printf("Registering conflicts:");
- while (Pkgcfl) {
- cp = strsep(&Pkgcfl, " \t\n");
- if (*cp) {
- add_plist(&plist, PLIST_PKGCFL, cp);
- if (Verbose && !PlistOnly)
- printf(" %s", cp);
- }
- }
- if (Verbose && !PlistOnly)
- printf(".\n");
- }
-
- /* Slurp in the packing list */
- read_plist(&plist, pkg_in);
-
- /*
- * Run down the list and see if we've named it, if not stick in a name
- * at the top.
- */
- if (find_plist(&plist, PLIST_NAME) == NULL)
- add_plist_top(&plist, PLIST_NAME, basename_of(pkg));
-
- /*
- * We're just here for to dump out a revised plist for the FreeBSD ports
- * hack. It's not a real create in progress.
- */
- if (PlistOnly) {
- check_list(home, &plist);
- write_plist(&plist, stdout);
- exit(0);
- }
-
- /* Make a directory to stomp around in */
- home = make_playpen(PlayPen, PlayPenSize, 0);
- signal(SIGINT, cleanup);
- signal(SIGHUP, cleanup);
-
- /* Make first "real contents" pass over it */
- check_list(home, &plist);
- (void) umask(022); /* make sure gen'ed directories, files don't have
- group or other write bits. */
- /* copy_plist(home, &plist); */
- /* mark_plist(&plist); */
-
- /* Now put the release specific items in */
- add_plist(&plist, PLIST_CWD, ".");
- write_file(COMMENT_FNAME, Comment);
- add_plist(&plist, PLIST_IGNORE, NULL);
- add_plist(&plist, PLIST_FILE, COMMENT_FNAME);
- write_file(DESC_FNAME, Desc);
- add_plist(&plist, PLIST_IGNORE, NULL);
- add_plist(&plist, PLIST_FILE, DESC_FNAME);
-
- if (Install) {
- copy_file(home, Install, INSTALL_FNAME);
- add_plist(&plist, PLIST_IGNORE, NULL);
- add_plist(&plist, PLIST_FILE, INSTALL_FNAME);
- }
- if (DeInstall) {
- copy_file(home, DeInstall, DEINSTALL_FNAME);
- add_plist(&plist, PLIST_IGNORE, NULL);
- add_plist(&plist, PLIST_FILE, DEINSTALL_FNAME);
- }
- if (Require) {
- copy_file(home, Require, REQUIRE_FNAME);
- add_plist(&plist, PLIST_IGNORE, NULL);
- add_plist(&plist, PLIST_FILE, REQUIRE_FNAME);
- }
- if (Display) {
- copy_file(home, Display, DISPLAY_FNAME);
- add_plist(&plist, PLIST_IGNORE, NULL);
- add_plist(&plist, PLIST_FILE, DISPLAY_FNAME);
- add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME);
- }
- if (Mtree) {
- copy_file(home, Mtree, MTREE_FNAME);
- add_plist(&plist, PLIST_IGNORE, NULL);
- add_plist(&plist, PLIST_FILE, MTREE_FNAME);
- add_plist(&plist, PLIST_MTREE, MTREE_FNAME);
- }
-
- /* Finally, write out the packing list */
- fp = fopen(CONTENTS_FNAME, "w");
- if (!fp) {
- cleanup(0);
- errx(2, "can't open file %s for writing", CONTENTS_FNAME);
- }
- write_plist(&plist, fp);
- if (fclose(fp)) {
- cleanup(0);
- errx(2, "error while closing %s", CONTENTS_FNAME);
- }
-
- /* And stick it into a tar ball */
- make_dist(home, pkg, suffix, &plist);
-
- /* Cleanup */
- free(Comment);
- free(Desc);
- free_plist(&plist);
- leave_playpen(home);
- return TRUE; /* Success */
-}
-
-static void
-make_dist(char *home, char *pkg, char *suffix, package_t *plist)
-{
- char tball[FILENAME_MAX];
- plist_t *p;
- int ret;
-#define DIST_MAX_ARGS 4096
- char *args[DIST_MAX_ARGS];
- char *tempfile[DIST_MAX_ARGS/2];
- int current = 0;
- FILE *flist = 0;
- int nargs = 0;
- int i;
- pid_t pid;
-
- args[nargs++] = "tar"; /* argv[0] */
-
- if (*pkg == '/')
- snprintf(tball, FILENAME_MAX, "%s.%s", pkg, suffix);
- else
- snprintf(tball, FILENAME_MAX, "%s/%s.%s", home, pkg, suffix);
-
- args[nargs++] = "-c";
- args[nargs++] = "-f";
- args[nargs++] = tball;
- if (strchr(suffix, 'z')) /* Compress/gzip? */
- args[nargs++] = "-z";
- if (Dereference)
- args[nargs++] = "-h";
- if (ExcludeFrom) {
- /* XXX this won't work until someone adds the gtar -X option
- (--exclude-from-file) to paxtar - so long it is disabled
- here and a warning is printed in main.c
- args[nargs++] = "-X";
- args[nargs++] = ExcludeFrom;
- */
- }
-
- if (Verbose) {
- if (strchr(suffix, 'z'))
- printf("Creating gzip'd tar ball in '%s'\n", tball);
- else
- printf("Creating tar ball in '%s'\n", tball);
- }
- args[nargs++] = CONTENTS_FNAME;
- args[nargs++] = COMMENT_FNAME;
- args[nargs++] = DESC_FNAME;
- if (Install)
- args[nargs++] = INSTALL_FNAME;
- if (DeInstall)
- args[nargs++] = DEINSTALL_FNAME;
- if (Require)
- args[nargs++] = REQUIRE_FNAME;
- if (Display)
- args[nargs++] = DISPLAY_FNAME;
- if (Mtree)
- args[nargs++] = MTREE_FNAME;
-
- for (p = plist->head; p; p = p->next) {
- if (nargs > (DIST_MAX_ARGS - 2))
- errx(2, "too many args for tar command");
- if (p->type == PLIST_FILE) {
- if (!flist) {
- int fd;
- tempfile[current] = strdup("/tmp/tpkg.XXXXXXXXXX");
- if ((fd = mkstemp(tempfile[current])) == -1)
- errx(2, "can't make temp file");
- if (! (flist = fdopen(fd, "w")))
- errx(2, "can't write to temp file");
- if (strcmp(args[nargs], "-C") == 0)
- nargs+= 2;
- args[nargs++] = "-I";
- args[nargs++] = tempfile[current++];
- }
- fprintf(flist, "%s\n", p->name);
- }
- else if (p->type == PLIST_CWD || p->type == PLIST_SRC) {
- /* XXX let PLIST_SRC override PLIST_CWD */
- if (p->type == PLIST_CWD && p->next != NULL &&
- p->next->type == PLIST_SRC)
- continue;
- if (flist)
- fclose(flist);
- flist = 0;
- args[nargs] = "-C";
- if (BaseDir) {
- size_t size = strlen(BaseDir)+2+strlen(p->name);
- args[nargs+1] = malloc(size);
- if (args[nargs+1] == NULL) {
- cleanup(0);
- errx(2, "can't get Cwd space");
- }
- snprintf(args[nargs+1], size, "%s/%s", BaseDir, p->name);
- } else
- args[nargs+1] = p->name;
- }
- else if (p->type == PLIST_IGNORE)
- p = p->next;
- }
- if (flist)
- fclose(flist);
- args[nargs] = NULL;
-
- /* fork/exec tar to create the package */
-
- if (Verbose) {
- printf("Running \"");
- for (i = 0; i < nargs; i++) {
- printf("%s ", args[i]);
- }
- printf("\"\n");
- }
- pid = fork();
- if ( pid < 0 )
- err(2, "failed to fork");
- else if ( pid == 0 ) {
- execv("/bin/tar", args);
- for (i = 0; i < current; i++)
- unlink(tempfile[i]);
- err(2, "failed to execute tar command");
- }
- wait(&ret);
- for (i = 0; i < current; i++)
- unlink(tempfile[i]);
- if (BaseDir) {
- for (i = 0; i < nargs-1; i++) {
- if (!strcmp(args[i], "-C"))
- free(args[++i]);
- }
- }
- /* assume either signal or bad exit is enough for us */
- if (ret) {
- cleanup(0);
- errx(2, "tar command failed with code %d", ret);
- }
-}
-
-static void
-sanity_check()
-{
- if (!Comment) {
- cleanup(0);
- errx(2, "required package comment string is missing (-c comment)");
- }
- if (!Desc) {
- cleanup(0);
- errx(2, "required package description string is missing (-d desc)");
- }
- if (!Contents) {
- cleanup(0);
- errx(2, "required package contents list is missing (-f [-]file)");
- }
-}
-
-
-/* Clean up those things that would otherwise hang around */
-void
-cleanup(int sig)
-{
- int save_errno = errno;
- static int alreadyCleaning;
- void (*oldint)(int);
- void (*oldhup)(int);
- char buf[1024];
- oldint = signal(SIGINT, SIG_IGN);
- oldhup = signal(SIGHUP, SIG_IGN);
-
- if (!alreadyCleaning) {
- alreadyCleaning = 1;
- if (sig) {
- snprintf(buf, sizeof buf, "Signal %d received, cleaning up.\n", sig);
- write(STDOUT_FILENO, buf, strlen(buf));
- }
- leave_playpen(home);
- if (sig)
- _exit(1);
- }
- signal(SIGINT, oldint);
- signal(SIGHUP, oldhup);
- errno = save_errno;
-}
diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1
deleted file mode 100644
index 09a3c768a49..00000000000
--- a/usr.sbin/pkg_install/create/pkg_create.1
+++ /dev/null
@@ -1,478 +0,0 @@
-.\" $OpenBSD: pkg_create.1,v 1.28 2003/08/21 20:24:56 espie Exp $
-.\"
-.\" FreeBSD install - a package for the installation and maintenance
-.\" of non-core utilities.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" Jordan K. Hubbard
-.\"
-.\"
-.\" @(#)pkg_create.1
-.\" from FreeBSD Id: pkg_create.1,v 1.19 1997/05/02 22:00:05 max Exp
-.\"
-.\" hacked up by John Kohl for NetBSD--fixed a few bugs, extended keywords,
-.\" added dependency tracking, etc.
-.\"
-.\" [jkh] Took John's changes back and made some additional extensions for
-.\" better integration with FreeBSD's new ports collection.
-.\"
-.Dd April 21, 1995
-.Dt PKG_CREATE 1
-.Os
-.Sh NAME
-.Nm pkg_create
-.Nd a utility for creating software package distributions
-.Sh SYNOPSIS
-.Nm pkg_create
-.Bk -words
-.Op Fl Ohv
-.Op Fl P Ar dpkgs
-.Op Fl C Ar cpkgs
-.Op Fl p Ar prefix
-.Op Fl i Ar iscript
-.Op Fl k Ar dscript
-.Op Fl r Ar rscript
-.Op Fl s Ar fake-prefix
-.Op Fl S Ar fake-base
-.Op Fl t Ar template
-.Op Fl X Ar excludefile
-.Op Fl D Ar displayfile
-.Op Fl m Ar mtreefile
-.Fl c Ar comment
-.Fl d Ar description
-.Fl f Ar packlist
-.Ar pkg-name
-.Ek
-.Sh DESCRIPTION
-The
-.Nm
-command is used to create packages that will subsequently be fed to
-one of the package extraction/info utilities.
-The input description
-and command line arguments for the creation of a package are not
-really meant to be human-generated, though it is easy enough to
-do so.
-It is more expected that you will use a front-end tool for
-the job rather than muddling through it yourself.
-Nonetheless, a short
-description of the input syntax is included in this document.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl f Ar packinglist
-Fetch
-.Dq packing list
-for package from the file
-.Ar packinglist
-or stdin if
-.Ar packinglist
-is a dash
-.Dq \&- .
-.It Fl c [ Ar \&- ] Ns Ar desc
-Fetch package
-.Dq one line description
-from file
-.Ar desc
-or, if preceded by
-.Dq \&- ,
-the argument itself.
-This string should also
-give some idea of which version of the product (if any) the package
-represents.
-.It Fl d [ Ar \&- ] Ns Ar desc
-Fetch long description for package from file
-.Ar desc
-or, if preceded by
-.Dq \&- ,
-the argument itself.
-.It Fl Y
-Assume a default answer of
-.Dq Yes
-for any questions asked.
-.It Fl N
-Assume a default answer of
-.Dq \&No
-for any questions asked.
-.It Fl O
-Go into a
-.Dq packing list only
-mode.
-This is used to do
-.Dq fake pkg_add
-operations when a package is installed.
-In such cases, it is necessary to know what the final, adjusted packing
-list will look like.
-.It Fl v
-Turn on verbose output.
-.It Fl h
-Force
-.Xr tar
-to follow symbolic links, so that the files they point to
-are dumped, rather than the links themselves.
-.It Fl i Ar iscript
-Set
-.Ar iscript
-to be the install procedure for the package.
-This can be any executable program (or shell script).
-It will be invoked automatically
-when the package is later installed.
-.It Fl P Ar dpkgs
-Set the initial package dependency list to
-.Ar dpkgs .
-This is assumed to be a whitespace separated list of package names
-and is meant as a convenient shorthand for specifying multiple
-.Cm @pkgdep
-directives in the packing list (see
-.Sx PACKING LIST DETAILS
-section below).
-.It Fl C Ar cpkgs
-Set the initial package conflict list to
-.Ar cpkgs .
-This is assumed to be a whitespace separated list of package names
-and is meant as a convenient shorthand for specifying multiple
-.Cm @pkgcfl
-directives in the packing list (see
-.Sx PACKING LIST DETAILS
-section below).
-.It Fl p Ar prefix
-Set
-.Ar prefix
-as the initial directory
-.Dq base
-to start from in selecting files for
-the package, and to record as the base for installing the package.
-.It Fl s Ar fake-prefix
-Set
-.Ar fake-prefix
-as the real initial directory
-to start from in selecting files for the package.
-.It Fl S Ar fake-base
-Set
-.Ar fake-base
-as the prefix to prepend to any file to select for the package.
-.It Fl k Ar dscript
-Set
-.Ar dscript
-to be the de-install procedure for the package.
-This can be any executable program (or shell script).
-It will be invoked automatically
-when the package is later (if ever) de-installed.
-.It Fl r Ar rscript
-Set
-.Ar rscript
-to be the
-.Dq requirements
-procedure for the package.
-This can be any executable program (or shell script).
-It will be invoked automatically
-at installation/deinstallation time to determine whether or not
-installation/deinstallation should proceed.
-.It Fl t Ar template
-Use
-.Ar template
-as the input to
-.Xr mkstemp 3 .
-By default, this is the string
-.Pa /tmp/instmp.XXXXXX ,
-but it may be necessary to override it in the situation where
-space in your
-.Pa /tmp
-directory is limited.
-Be sure to leave some number of
-.Dq X
-characters for
-.Xr mkstemp 3
- to fill in with a unique ID.
-.It Fl X Ar excludefile
-Pass
-.Ar excludefile
-as a
-.Fl exclude-from
-argument to
-.Xr tar
-when creating final package.
-See
-.Xr tar
-man page (or run
-.Xr tar
-with
-.Fl -help
-flag) for further information on using this flag.
-.It Fl D Ar displayfile
-Display the file (using
-.Xr more 1 )
-after installing the package.
-Useful for things like
-legal notices on almost-free software, etc.
-.It Fl m Ar mtreefile
-Run
-.Xr mtree 8
-with input from mtreefile before the package is installed.
-.Xr mtree
-is invoked as
-.Cm mtree
-.Fl u
-.Fl f
-.Ar mtreefile
-.Fl d
-.Fl e
-.Fl p
-.Pa prefix ,
-where
-.Pa prefix
-is the name of the first directory named by a
-.Cm @cwd
-directive.
-.El
-.Sh PACKING LIST DETAILS
-The
-.Dq packing list
-format (see
-.Fl f )
-is fairly simple, being
-nothing more than a single column of filenames to include in the
-package.
-However, since absolute pathnames are generally a bad idea
-for a package that could be installed potentially anywhere, there is
-another method of specifying where things are supposed to go
-and, optionally, what ownership and mode information they should be
-installed with.
-This is done by imbedding specialized command sequences
-in the packing list.
-Briefly described, these sequences are:
-.Bl -tag -width indent
-.It Cm @cwd Ar directory
-Set the internal directory pointer to point to
-.Ar directory .
-All subsequent filenames will be assumed relative to this directory.
-Note:
-.Cm @cd
-is also an alias for this command.
-.It Cm @src Ar directory
-Set the internal directory pointer for creation
-.Em only
-to
-.Ar directory .
-That is to say that it overrides
-.Cm @cwd
-for package creation but not extraction.
-.It Cm @exec Ar command
-Execute
-.Ar command
-as part of the unpacking process.
-If
-.Ar command
-contains any of the following sequences somewhere in it, they will
-be expanded inline.
-For the following examples, assume that
-.Cm @cwd
-is set to
-.Pa /usr/local
-and the last extracted file was
-.Pa bin/emacs .
-.Bl -tag -width indent
-.It Cm "\&%F"
-Expands to the last filename extracted (as specified); in the example case,
-.Pa bin/emacs .
-.It Cm "\&%D"
-Expands to the current directory prefix, as set with
-.Cm @cwd ;
-in the example case
-.Pa /usr/local .
-.It Cm "\&%B"
-Expands to the
-.Dq basename
-of the fully qualified filename, that
-is the current directory prefix, plus the last filespec, minus
-the trailing filename.
-In the example case, that would be
-.Pa /usr/local/bin .
-.It Cm "\&%f"
-Expands to the
-.Dq filename
-part of the fully qualified name, or
-the converse of
-.Cm \&%B ;
-in the example case,
-.Pa emacs .
-.El
-.It Cm @unexec Ar command
-Execute
-.Ar command
-as part of the deinstallation process.
-Expansion of special
-.Cm \&%
-sequences is the same as for
-.Cm @exec .
-This command is not executed during the package add, as
-.Cm @exec
-is, but rather when the package is deleted.
-This is useful
-for deleting links and other ancillary files that were created
-as a result of adding the package, but not directly known to
-the package's table of contents (and hence not automatically
-removable).
-The advantage of using
-.Cm @unexec
-over a deinstallation script is that you can use the
-.Dq special sequence expansion
-to get at files regardless of where they've
-been potentially redirected (see
-.Fl p ) .
-.It Cm @mode Ar mode
-Set default permission for all subsequently extracted files to
-.Ar mode .
-Format is the same as that used by the
-.Cm chmod
-command (well, considering that it's later handed off to it, that's
-no surprise).
-Use without an arg to set back to default (extraction) permissions.
-.It Cm @owner Ar user
-Set default ownership for all subsequently extracted files to
-.Ar user .
-Use without an arg to set back to default (extraction)
-ownership.
-.It Cm @group Ar group
-Set default group ownership for all subsequently extracted files to
-.Ar group .
-Use without an arg to set back to default (extraction)
-group ownership.
-.It Cm @comment Ar string
-Imbed a comment in the packing list.
-Useful in trying to document some particularly hairy sequence that
-may trip someone up later.
-.It Cm @ignore
-Used internally to tell extraction to ignore the next file (don't
-copy it anywhere), as it's used for some special purpose.
-.It Cm @name Ar name
-Set the name of the package.
-This is mandatory and is usually put at the top.
-This name is potentially different than the name of
-the file it came in, and is used when keeping track of the package
-for later deinstallation.
-Note that
-.Nm
-will derive this field from the package name and add it automatically
-if none is given.
-.It Cm @dirrm Ar name
-Declare directory
-.Pa name
-to be deleted at deinstall time.
-By default, directories created by a
-package installation are not deleted when the package is deinstalled;
-this provides an explicit directory cleanup method.
-This directive should appear at the end of the package list.
-If more than one
-.Cm @dirrm
-directive is used, the directories are removed in the order specified.
-The
-.Pa name
-directory will not be removed unless it is empty.
-.It Cm @extra Ar file
-Declare extra file
-.Pa file
-to be deleted at deinstall time, if user sets
-.Fl c
-option.
-Those files are extra configuration files that are normally not deleted.
-If
-.Pa file
-ends with a slash, it is a directory.
-.It Cm @extraunexec Ar command
-Extra
-.Ar command
-to execute when removing extra files.
-.It Cm @mtree Ar name
-Declare
-.Pa name
-as an
-.Xr mtree 8
-input file to be used at install time (see
-.Fl m
-above).
-Only the first
-.Cm @mtree
-directive is honored.
-.It Cm @display Ar name
-Declare
-.Pa name
-as the file to be displayed at install time (see
-.Fl D
-above).
-.It Cm @pkgdep Ar pkgname
-Declare a dependency on the
-.Ar pkgname
-package.
-The
-.Ar pkgname
-package must be installed before this package may be
-installed, and this package must be deinstalled before the
-.Ar pkgname
-package is deinstalled.
-Multiple
-.Cm @pkgdep
-directives may be used if the package depends on multiple other packages.
-.It Cm @pkgcfl Ar pkgcflname
-Declare a conflict to the
-.Ar pkgcflname
-package.
-The
-.Ar pkgcflname
-package must
-.Em not
-be installed if
-.Ar pkgname
-package gets installed because they install the same files and thus conflict.
-.Ar pkgcflname
-may use
-.Xr fnmatch 3
-wildcards.
-.It Cm @option Ar name
-Effects vary depending on
-.Ar name .
-Some options are not documented yet.
-.Bl -tag -width indent
-.It Ar no-default-conflict
-By default, a package conflicts with other versions of the same package.
-With this option, the older package version will still be noticed, but the
-installation will proceed anyway.
-.El
-.El
-.Sh SEE ALSO
-.Xr pkg_add 1 ,
-.Xr pkg_delete 1 ,
-.Xr pkg_info 1 ,
-.Xr sysconf 3
-.Sh HISTORY
-The
-.Nm
-command first appeared in
-.Fx .
-.Sh AUTHORS
-.Bl -tag -width indent -compact
-.It "Jordan Hubbard"
-most of the work
-.It "John Kohl"
-refined it for
-.Nx
-.El
-.Sh BUGS
-Hard links between files in a distribution must be bracketed by
-.Cm @cwd
-directives in order to be preserved as hard links when the package is
-extracted.
-They additionally must not end up being split between
-.Xr tar
-invocations due to exec argument-space limitations (this depends on the
-value returned by
-.Fn sysconf _SC_ARG_MAX ) .
-.Pp
-Sure to be others.
diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c
deleted file mode 100644
index dceede79efb..00000000000
--- a/usr.sbin/pkg_install/create/pl.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/* $OpenBSD: pl.c,v 1.11 2003/08/15 00:03:22 espie Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: pl.c,v 1.11 2003/08/15 00:03:22 espie Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Routines for dealing with the packing list.
- *
- */
-
-#include "lib.h"
-#include "create.h"
-#include <errno.h>
-#include <err.h>
-#include <md5.h>
-
-/* Check a list for files that require preconversion */
-void
-check_list(char *home, package_t *pkg)
-{
- plist_t *tmp;
- plist_t *p;
- char *cwd = home;
- char *there = NULL;
- char *cp;
- char name[FILENAME_MAX];
- char buf[LegibleChecksumLen];
-
- for (p = pkg->head ; p ; p = p->next) {
- switch (p->type) {
- case PLIST_CWD:
- cwd = p->name;
- break;
- case PLIST_IGNORE:
- p = p->next;
- break;
- case PLIST_SRC:
- there = p->name;
- break;
- case PLIST_COMMENT:
- if (p->name != NULL &&
- strcmp(p->name, "no checksum") == 0)
- p = p->next;
- break;
- case PLIST_FILE:
- if (BaseDir)
- (void) snprintf(name, sizeof(name),
- "%s/%s/%s", BaseDir, there ? there : cwd,
- p->name);
- else
- (void) snprintf(name, sizeof(name),
- "%s/%s", there ? there : cwd, p->name);
- if ((cp = MD5File(name, buf)) != NULL) {
- tmp = new_plist_entry();
- tmp->name = copy_string(strconcat("MD5:", cp));
- tmp->type = PLIST_COMMENT;
- tmp->next = p->next;
- tmp->prev = p;
- p->next = tmp;
- if (pkg->tail == p)
- pkg->tail = tmp;
- p = tmp;
- }
- break;
- default:
- break;
- }
- }
-}
-
-static int
-trylink(const char *from, const char *to)
-{
- char *cp;
-
- if (link(from, to) == 0) {
- return 0;
- }
- if (errno == ENOENT) {
- /* try making the container directory */
- if ((cp = strrchr(to, '/')) != (char *) NULL) {
- vsystem("mkdir -p %.*s", (size_t)(cp - to), to);
- }
- return link(from, to);
- }
- return -1;
-}
-
-#define STARTSTRING "tar cf -"
-#define TOOBIG(str) strlen(str) + 6 + strlen(home) + where_count > maxargs
-#define PUSHOUT() /* push out string */ \
- if (where_count > sizeof(STARTSTRING)-1) { \
- strlcat(where_args, "|tar xpf -", maxargs); \
- if (system(where_args)) { \
- cleanup(0); \
- errx(2, "can't invoke tar pipeline"); \
- } \
- memset(where_args, 0, maxargs); \
- last_chdir = NULL; \
- strlcpy(where_args, STARTSTRING, maxargs); \
- where_count = sizeof(STARTSTRING)-1; \
- }
-
-/*
- * Copy unmarked files in packing list to playpen - marked files
- * have already been copied in an earlier pass through the list.
- */
-void
-copy_plist(char *home, package_t *plist)
-{
- plist_t *p = plist->head;
- char *where = home;
- char *there = NULL, *mythere;
- char *where_args, *last_chdir, *root = "/";
- int maxargs, where_count = 0, add_count;
- struct stat stb;
- dev_t curdir;
-
- maxargs = sysconf(_SC_ARG_MAX);
- maxargs -= 64; /* some slop for the tar cmd text,
- and sh -c */
- where_args = malloc(maxargs);
- if (!where_args) {
- cleanup(0);
- errx(2, "can't get argument list space");
- }
-
- memset(where_args, 0, maxargs);
- strlcpy(where_args, STARTSTRING, maxargs);
- where_count = sizeof(STARTSTRING)-1;
- last_chdir = 0;
-
- if (stat(".", &stb) == 0)
- curdir = stb.st_dev;
- else
- curdir = (dev_t) -1; /* It's ok if this is a valid dev_t;
- this is just a hint for an
- optimization. */
-
- while (p) {
- if (p->type == PLIST_CWD)
- where = p->name;
- else if (p->type == PLIST_SRC)
- there = p->name;
- else if (p->type == PLIST_IGNORE)
- p = p->next;
- else if (p->type == PLIST_FILE && !p->marked) {
- char fn[FILENAME_MAX];
-
-
- /* First, look for it in the "home" dir */
- (void) snprintf(fn, sizeof(fn), "%s/%s", home, p->name);
- if (fexists(fn)) {
- if (lstat(fn, &stb) == 0 && stb.st_dev == curdir &&
- S_ISREG(stb.st_mode)) {
- /* if we can link it to the playpen, that avoids a copy
- and saves time. */
- if (p->name[0] != '/') {
- /* don't link abspn stuff--it doesn't come from
- local dir! */
- if (trylink(fn, p->name) == 0) {
- p = p->next;
- continue;
- }
- }
- }
- if (TOOBIG(fn)) {
- PUSHOUT();
- }
- if (p->name[0] == '/') {
- add_count = snprintf(&where_args[where_count],
- maxargs - where_count,
- " %s %s",
- last_chdir == root ? "" : "-C /",
- p->name);
- last_chdir = root;
- } else {
- add_count = snprintf(&where_args[where_count],
- maxargs - where_count,
- " %s%s %s",
- last_chdir == home ? "" : "-C ",
- last_chdir == home ? "" : home,
- p->name);
- last_chdir = home;
- }
- if (add_count > maxargs - where_count) {
- cleanup(0);
- errx(2, "oops, miscounted strings!");
- }
- where_count += add_count;
- }
- /*
- * Otherwise, try along the actual extraction path..
- */
- else {
- if (p->name[0] == '/')
- mythere = root;
- else mythere = there;
- (void) snprintf(fn, sizeof(fn), "%s/%s", mythere ? mythere : where, p->name);
- if (lstat(fn, &stb) == 0 && stb.st_dev == curdir &&
- S_ISREG(stb.st_mode)) {
- /* if we can link it to the playpen, that avoids a copy
- and saves time. */
- if (trylink(fn, p->name) == 0) {
- p = p->next;
- continue;
- }
- }
- if (TOOBIG(p->name)) {
- PUSHOUT();
- }
- if (last_chdir == (mythere ? mythere : where))
- add_count = snprintf(&where_args[where_count],
- maxargs - where_count,
- " %s", p->name);
- else
- add_count = snprintf(&where_args[where_count],
- maxargs - where_count,
- " -C %s %s",
- mythere ? mythere : where,
- p->name);
- if (add_count > maxargs - where_count) {
- cleanup(0);
- errx(2, "oops, miscounted strings!");
- }
- where_count += add_count;
- last_chdir = (mythere ? mythere : where);
- }
- }
- p = p->next;
- }
- PUSHOUT();
- free(where_args);
-}
diff --git a/usr.sbin/pkg_install/delete/Makefile b/usr.sbin/pkg_install/delete/Makefile
deleted file mode 100644
index cf092ec560e..00000000000
--- a/usr.sbin/pkg_install/delete/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# $OpenBSD: Makefile,v 1.3 1996/08/26 07:00:32 deraadt Exp $
-PROG= pkg_delete
-CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
-
-.include <bsd.obj.mk>
-
-.if exists(${.CURDIR}/../lib/${__objdir})
-LDADD+= -L${.CURDIR}/../lib/${__objdir} -linstall
-DPADD+= ${.CURDIR}/../lib/${__objdir}/libinstall.a
-.else
-LDADD+= -L${.CURDIR}/../lib -linstall
-DPADD+= ${.CURDIR}/../lib/libinstall.a
-.endif
-
-SRCS= main.c perform.c
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/pkg_install/delete/delete.h b/usr.sbin/pkg_install/delete/delete.h
deleted file mode 100644
index f6d9231c4aa..00000000000
--- a/usr.sbin/pkg_install/delete/delete.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* $OpenBSD: delete.h,v 1.3 2003/08/21 20:24:56 espie Exp $ */
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Include and define various things wanted by the delete command.
- *
- */
-
-#ifndef _INST_DELETE_H_INCLUDE
-#define _INST_DELETE_H_INCLUDE
-
-extern char *Prefix;
-extern Boolean NoDeInstall;
-extern Boolean CleanDirs;
-extern Boolean CleanConf;
-extern Boolean CheckMD5;
-extern Boolean Force;
-extern char *Directory;
-extern char *PkgName;
-
-#endif /* _INST_DELETE_H_INCLUDE */
diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c
deleted file mode 100644
index fa45b5dfa3e..00000000000
--- a/usr.sbin/pkg_install/delete/main.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/* $OpenBSD: main.c,v 1.12 2003/08/21 20:24:56 espie Exp $ */
-
-#include <sys/cdefs.h>
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: main.c,v 1.12 2003/08/21 20:24:56 espie Exp $";
-#endif
-
-/*
- *
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the delete module.
- *
- */
-
-#include <err.h>
-#include "lib.h"
-#include "delete.h"
-
-static char Options[] = "chvDdnfp:q";
-
-char *Prefix = NULL;
-Boolean NoDeInstall = FALSE;
-Boolean CleanDirs = FALSE;
-Boolean CleanConf = FALSE;
-Boolean CheckMD5 = TRUE;
-
-static void usage(void);
-
-int
-main(int argc, char **argv)
-{
- int ch, error;
- char **pkgs, **start;
-
- pkgs = start = argv;
- while ((ch = getopt(argc, argv, Options)) != -1)
- switch(ch) {
- case 'v':
- Verbose = TRUE;
- break;
-
- case 'f':
- Force = TRUE;
- break;
-
- case 'p':
- Prefix = optarg;
- break;
-
- case 'D':
- NoDeInstall = TRUE;
- break;
-
- case 'd':
- CleanDirs = TRUE;
- break;
-
- case 'n':
- Fake = TRUE;
- Verbose = TRUE;
- break;
-
- case 'q':
- CheckMD5 = FALSE;
- break;
-
- case 'c':
- CleanConf = TRUE;
- break;
- case 'h':
- case '?':
- default:
- usage();
- break;
- }
-
- argc -= optind;
- argv += optind;
-
- /* Get all the remaining package names, if any */
- /* Get all the remaining package names, if any */
- while (*argv)
- *pkgs++ = *argv++;
-
- /* If no packages, yelp */
- if (pkgs == start)
- pwarnx("missing package name(s)"), usage();
- *pkgs = NULL;
- if (!Fake && getuid() != 0)
- errx(1, "you must be root to delete packages");
- if ((error = pkg_perform(start)) != 0) {
- if (Verbose)
- pwarnx("%d package deletion(s) failed", error);
- return error;
- }
- else
- return 0;
-}
-
-static void
-usage()
-{
- fprintf(stderr, "usage: pkg_delete [-cvDdhnfq] [-p prefix] pkg-name ...\n");
- exit(1);
-}
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c
deleted file mode 100644
index 2cf4716bf8e..00000000000
--- a/usr.sbin/pkg_install/delete/perform.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/* $OpenBSD: perform.c,v 1.16 2003/08/21 20:24:56 espie Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: perform.c,v 1.16 2003/08/21 20:24:56 espie Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the main body of the delete module.
- *
- */
-
-#include <sys/param.h>
-#include <sys/mount.h>
-#include <err.h>
-#include "lib.h"
-#include "delete.h"
-
-static int pkg_do(char *);
-static void sanity_check(char *);
-static int undepend(const char *, char *, int);
-static char LogDir[FILENAME_MAX];
-extern Boolean CleanConf;
-
-
-int
-pkg_perform(char **pkgs)
-{
- int i, err_cnt = 0;
-
- for (i = 0; pkgs[i]; i++)
- err_cnt += pkg_do(pkgs[i]);
- return err_cnt;
-}
-
-static package_t Plist;
-
-static int
-trim_end(char *name)
-{
- size_t n, m;
- n = strlen(name);
- m = strlen(".tgz");
- if (n > m && strcmp(name+n-m, ".tgz") == 0) {
- name[n-m] = 0;
- return 1;
- }
- m = strlen(".tar.gz");
- if (n > m && strcmp(name+n-m, ".tar.gz") == 0) {
- name[n-m] = 0;
- return 1;
- }
- m = strlen(".tar");
- if (n > m && strcmp(name+n-m, ".tar") == 0) {
- name[n-m] = 0;
- return 1;
- }
- return 0;
-}
-
-/* remove all links to the package as well */
-static void
-delete_pkg_links(const char *dir, const char *pkg)
-{
- int base;
- int len;
- DIR *d;
- struct dirent *dp;
- struct stat sb;
- char name[FILENAME_MAX+1];
-
- base = open(".", O_RDONLY);
- if (base == -1)
- return;
- if (chdir(dir) == -1) {
- close(base);
- return;
- }
- d = opendir(".");
- if (d == NULL) {
- fchdir(base);
- close(base);
- return;
- }
- while ((dp = readdir(d)) != NULL) {
- if (lstat(dp->d_name, &sb) == -1 || !S_ISLNK(sb.st_mode))
- continue;
- len = readlink(dp->d_name, name, FILENAME_MAX);
- if (len == -1)
- continue;
- name[len] = 0;
- if (strcmp(name, pkg))
- continue;
- unlink(dp->d_name);
- }
- closedir(d);
- fchdir(base);
- close(base);
-}
-
-/* This is seriously ugly code following. Written very fast! */
-static int
-pkg_do(char *pkg)
-{
- FILE *cfile;
- char home[FILENAME_MAX];
- plist_t *p;
- char *dbdir;
-
- set_pkg(pkg);
- /* Reset some state */
- if (Plist.head)
- free_plist(&Plist);
-
- dbdir = getenv(PKG_DBDIR);
- if (!dbdir)
- dbdir = DEF_LOG_DIR;
-try_again:
- (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", dbdir, pkg);
- if (!fexists(LogDir)) {
- if (trim_end(pkg))
- goto try_again;
- else {
- pwarnx("no such package installed");
- return 1;
- }
- }
- if (!getcwd(home, FILENAME_MAX)) {
- cleanup(0);
- errx(2, "unable to get current working directory!");
- }
- if (chdir(LogDir) == FAIL) {
- pwarnx("unable to change directory to %s! deinstall failed", LogDir);
- return 1;
- }
- if (!isemptyfile(REQUIRED_BY_FNAME)) {
- char buf[512];
- pwarnx("package `%s' is required by these other packages\n"
- "and may not be deinstalled%s:",
- pkg, Force ? " (but I'll delete it anyway)" : "" );
- cfile = fopen(REQUIRED_BY_FNAME, "r");
- if (cfile) {
- while (fgets(buf, sizeof(buf), cfile))
- fprintf(stderr, "%s", buf);
- fclose(cfile);
- } else
- pwarnx("cannot open requirements file `%s'", REQUIRED_BY_FNAME);
- if (!Force)
- return 1;
- }
- sanity_check(LogDir);
- cfile = fopen(CONTENTS_FNAME, "r");
- if (!cfile) {
- pwarnx("unable to open '%s' file", CONTENTS_FNAME);
- return 1;
- }
- /* If we have a prefix, add it now */
- if (Prefix)
- add_plist(&Plist, PLIST_CWD, Prefix);
- read_plist(&Plist, cfile);
- fclose(cfile);
- p = find_plist(&Plist, PLIST_CWD);
- if (!p) {
- pwarnx("package '%s' doesn't have a prefix", pkg);
- return 1;
- }
- {
- struct statfs buffer;
-
- if (statfs(p->name, &buffer) == -1) {
- pwarnx("package '%s' prefix (%s) does not exist", pkg, p->name);
- return 1;
- }
- if (buffer.f_flags & MNT_RDONLY) {
- pwarnx("package'%s' mount point %s is read-only", pkg,
- buffer.f_mntonname);
- return 1;
- }
- }
-
- setenv(PKG_PREFIX_VNAME, p->name, 1);
- setenv("PKG_DELETE_EXTRA", (CleanConf ? "Yes" : "No"), 1);
- if (fexists(REQUIRE_FNAME)) {
- if (Verbose)
- printf("Executing 'require' script.\n");
- vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */
- if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
- pwarnx("package %s fails requirements %s", pkg,
- Force ? "" : "- not deleted");
- if (!Force)
- return 1;
- }
- }
- if (!NoDeInstall && fexists(DEINSTALL_FNAME)) {
- if (Fake)
- printf("Would execute de-install script at this point.\n");
- else {
- vsystem("chmod +x %s", DEINSTALL_FNAME); /* make sure */
- if (vsystem("./%s %s DEINSTALL", DEINSTALL_FNAME, pkg)) {
- pwarnx("deinstall script returned error status");
- if (!Force)
- return 1;
- }
- }
- }
- if (chdir(home) == FAIL) {
- cleanup(0);
- errx(2, "Toto! This doesn't look like Kansas anymore!");
- }
- if (!Fake) {
- /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */
- if (delete_package(FALSE, CleanDirs, CleanConf, CheckMD5, &Plist) == FAIL)
- pwarnx(
- "couldn't entirely delete package (perhaps the packing list is\n"
- "incorrectly specified?)");
- if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
- pwarnx("couldn't remove log entry in %s, deinstall failed", LogDir);
- if (!Force)
- return 1;
- }
- delete_pkg_links(dbdir, 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)
- findmatchingname(dbdir, p->name, undepend, pkg, 0);
- }
- return 0;
-}
-
-static void
-sanity_check(char *pkg)
-{
- if (!fexists(CONTENTS_FNAME)) {
- cleanup(0);
- errx(2, "installed package %s has no %s file!", pkg, CONTENTS_FNAME);
- }
-}
-
-void
-cleanup(int sig)
-{
- exit(1);
-}
-
-/* deppkgname is the pkg from which's +REQUIRED_BY file we are
- * about to remove pkg2delname. This function is called from
- * findmatchingname(), deppkgname is expanded from a (possible) pattern.
- */
-int
-undepend(const char *deppkgname, char *pkg2delname, int unused)
-{
- char fname[FILENAME_MAX], ftmp[FILENAME_MAX];
- char fbuf[FILENAME_MAX];
- FILE *fp, *fpwr;
- char *tmp;
- int s;
-
- (void) snprintf(fname, sizeof(fname), "%s/%s/%s",
- (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
- deppkgname, REQUIRED_BY_FNAME);
- fp = fopen(fname, "r");
- if (fp == NULL) {
- pwarnx("couldn't open dependency file `%s'", fname);
- return 0;
- }
- (void) snprintf(ftmp, sizeof(ftmp), "%s.XXXXXXXXXX", fname);
- s = mkstemp(ftmp);
- if (s == -1) {
- fclose(fp);
- pwarnx("couldn't open temp file `%s'", ftmp);
- return 0;
- }
- fpwr = fdopen(s, "w");
- if (fpwr == NULL) {
- close(s);
- fclose(fp);
- pwarnx("couldn't fdopen temp file `%s'", ftmp);
- remove(ftmp);
- return 0;
- }
- while (fgets(fbuf, sizeof(fbuf), fp) != NULL) {
- if (fbuf[strlen(fbuf)-1] == '\n')
- fbuf[strlen(fbuf)-1] = '\0';
- if (strcmp(fbuf, pkg2delname)) /* no match */
- fputs(fbuf, fpwr), putc('\n', fpwr);
- }
- (void) fclose(fp);
- if (fchmod(s, 0644) == FAIL) {
- pwarnx("error changing permission of temp file `%s'", ftmp);
- fclose(fpwr);
- remove(ftmp);
- return 0;
- }
- if (fclose(fpwr) == EOF) {
- pwarnx("error closing temp file `%s'", ftmp);
- remove(ftmp);
- return 0;
- }
- if (rename(ftmp, fname) == -1)
- pwarnx("error renaming `%s' to `%s'", ftmp, fname);
- remove(ftmp); /* just in case */
-
- return 0;
-}
diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1
deleted file mode 100644
index 89431bdbeb3..00000000000
--- a/usr.sbin/pkg_install/delete/pkg_delete.1
+++ /dev/null
@@ -1,198 +0,0 @@
-.\" $OpenBSD: pkg_delete.1,v 1.17 2003/08/21 20:24:56 espie Exp $
-.\"
-.\" FreeBSD install - a package for the installation and maintenance
-.\" of non-core utilities.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" Jordan K. Hubbard
-.\"
-.\"
-.\" from FreeBSD: @(#)pkg_delete.1
-.\"
-.Dd November 25, 1994
-.Dt PKG_DELETE 1
-.Os
-.Sh NAME
-.Nm pkg_delete
-.Nd a utility for deleting previously installed software package distributions
-.Sh SYNOPSIS
-.Nm pkg_delete
-.Op Fl cvDdnfq
-.Op Fl p Ar prefix
-.Ar pkg-name Op Ar ...
-.Sh DESCRIPTION
-The
-.Nm
-command is used to delete packages that have been previously installed
-with the
-.Xr pkg_add 1
-command.
-.Pp
-Package names may be specified either as the package name itself, or as filenames which consist of the package name plus the
-.Dq .tgz
-,
-.Dq .tar.gz
-, or the
-.Dq .tar
-suffix.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Ar pkg-name Op Ar ...
-The named packages are deinstalled.
-.It Fl v
-Turn on verbose output.
-.It Fl D
-If a deinstallation script exists for a given package, do not execute it.
-.It Fl n
-Don't actually deinstall a package, just report the steps that
-would be taken if it were.
-.It Fl p Ar prefix
-Set
-.Ar prefix
-as the directory in which to delete files from any installed packages
-which do not explicitly set theirs.
-For most packages, the prefix will
-be set automatically to the installed location by
-.Xr pkg_add 1 .
-.It Fl d
-Remove empty directories created by file cleanup.
-By default, only
-files/directories explicitly listed in a package's contents (either as
-normal files/directories or with the
-.Cm @dirrm
-directive) will be removed at deinstallation time.
-This option tells
-.Nm
-to also remove any directories that were emptied as a result of removing
-the package.
-.It Fl f
-Force removal of the package, even if a dependency is recorded or the
-deinstall or require script fails.
-.It Fl c
-Delete extra configuration file, mentioned as
-.Bd -literal
-@extra file
-.Ed
-in the packing-list.
-.It Fl q
-Delete package quickly, do not bother checking md5s before removing files.
-.El
-.Sh TECHNICAL DETAILS
-.Nm
-does pretty much what it says.
-It examines installed package records in
-.Pa /var/db/pkg/<pkg-name> ,
-deletes the package contents, and finally removes the package records.
-.Pp
-If a package is required by other installed packages,
-.Nm
-will list those dependent packages and refuse to delete the package
-(unless the
-.Fl f
-option is given).
-.Pp
-If the package contains a
-.Ar require
-file (see
-.Xr pkg_create 1 ) ,
-then this is executed first as
-.Bd -filled -offset indent
-.Cm require
-.Ar <pkg-name>
-.Ar DEINSTALL
-.Ed
-.Pp
-(where
-.Ar pkg-name
-is the name of the package in question and
-.Ar DEINSTALL
-is a keyword denoting that this is a deinstallation)
-to see whether or not deinstallation should continue.
-A non-zero exit status means no, unless the
-.Fl f
-option is specified.
-.Pp
-If a
-.Cm deinstall
-script exists for the package, it is executed before any files are removed.
-It is this script's responsibility to clean up any additional messy details
-around the package's installation, since all
-.Nm
-knows how to do is delete the files created in the original distribution.
-The
-.Nm deinstall
-script is called as:
-.Bd -filled -offset indent
-.Cm deinstall
-.Ar <pkg-name>
-.Ar DEINSTALL
-.Ed
-.Pp
-Passing the keyword
-.Ar DEINSTALL
-lets you potentially write only one program/script that handles all
-aspects of installation and deletion.
-.Pp
-All scripts are called with the environment variable
-.Ev PKG_PREFIX
-set to the installation prefix (see the
-.Fl p
-option above).
-This allows a package author to write a script
-that reliably performs some action on the directory where the package
-is installed, even if the user might have changed it by specifying the
-.Fl p
-option when running
-.Nm
-or
-.Cm pkg_add .
-.Sh SEE ALSO
-.Xr pkg_add 1 ,
-.Xr pkg_create 1 ,
-.Xr pkg_info 1 ,
-.Xr mkstemp 3 ,
-.Xr mtree 8
-.Sh AUTHORS
-.Bl -tag -width indent -compact
-.It "Jordan Hubbard"
-most of the work
-.It "John Kohl"
-refined it for
-.Nx
-.El
-.Sh WARNING
-.Bf -emphasis
-Since the
-.Nm
-command may execute scripts or programs provided by a package file,
-your system may be susceptible to ``trojan horses'' or other subtle
-attacks from miscreants who create dangerous package files.
-.Pp
-You are advised to verify the competence and identity of those who
-provide installable package files.
-For extra protection, examine all
-the package control files in the package record directory
-.Pq Pa /var/db/pkg/<pkg-name>/ .
-Pay particular
-attention to any +INSTALL, +DEINSTALL, +REQUIRE or +MTREE_DIRS files,
-and inspect the +CONTENTS file for
-.Cm @cwd ,
-.Cm @mode
-(check for setuid),
-.Cm @dirrm ,
-.Cm @exec ,
-and
-.Cm @unexec
-directives, and/or use the
-.Xr pkg_info 1
-command to examine the installed package control files.
-.Ef
diff --git a/usr.sbin/pkg_install/info/Makefile b/usr.sbin/pkg_install/info/Makefile
deleted file mode 100644
index 516382a8bc1..00000000000
--- a/usr.sbin/pkg_install/info/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# $OpenBSD: Makefile,v 1.3 1996/08/26 07:00:33 deraadt Exp $
-PROG= pkg_info
-CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
-
-.include <bsd.obj.mk>
-
-.if exists(${.CURDIR}/../lib/${__objdir})
-LDADD+= -L${.CURDIR}/../lib/${__objdir} -linstall
-DPADD+= ${.CURDIR}/../lib/${__objdir}/libinstall.a
-.else
-LDADD+= -L${.CURDIR}/../lib -linstall
-DPADD+= ${.CURDIR}/../lib/libinstall.a
-.endif
-
-SRCS= main.c perform.c show.c
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/pkg_install/info/info.h b/usr.sbin/pkg_install/info/info.h
deleted file mode 100644
index 6e7623b52c5..00000000000
--- a/usr.sbin/pkg_install/info/info.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* $OpenBSD: info.h,v 1.3 1998/11/19 04:12:55 espie Exp $ */
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 23 August 1993
- *
- * Include and define various things wanted by the info command.
- *
- */
-
-#ifndef _INST_INFO_H_INCLUDE
-#define _INST_INFO_H_INCLUDE
-
-#ifndef MAXNAMESIZE
-#define MAXNAMESIZE 20
-#endif
-
-#define SHOW_COMMENT 0x0001
-#define SHOW_DESC 0x0002
-#define SHOW_PLIST 0x0004
-#define SHOW_INSTALL 0x0008
-#define SHOW_DEINSTALL 0x0010
-#define SHOW_REQUIRE 0x0020
-#define SHOW_PREFIX 0x0040
-#define SHOW_INDEX 0x0080
-#define SHOW_FILES 0x0100
-#define SHOW_DISPLAY 0x0200
-#define SHOW_REQBY 0x0400
-#define SHOW_MTREE 0x0800
-
-extern int Flags;
-extern Boolean AllInstalled;
-extern Boolean Quiet;
-extern char *InfoPrefix;
-extern char PlayPen[];
-extern size_t PlayPenSize;
-extern char *CheckPkg;
-
-extern void show_file(char *, char *);
-extern void show_plist(char *, package_t *, pl_ent_t);
-extern void show_files(char *, package_t *);
-extern void show_index(char *, char *);
-
-#endif /* _INST_INFO_H_INCLUDE */
diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c
deleted file mode 100644
index cf248d0b26f..00000000000
--- a/usr.sbin/pkg_install/info/main.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/* $OpenBSD: main.c,v 1.15 2003/07/04 17:31:19 avsm Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: main.c,v 1.15 2003/07/04 17:31:19 avsm Exp $";
-#endif
-
-/*
- *
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * This is the add module.
- *
- */
-
-#include <err.h>
-#include "lib.h"
-#include "info.h"
-
-static char Options[] = "acDde:fIikLl:mpqRrvh";
-
-int Flags = 0;
-Boolean AllInstalled = FALSE;
-Boolean Quiet = FALSE;
-char *InfoPrefix = "";
-char PlayPen[FILENAME_MAX];
-size_t PlayPenSize = sizeof(PlayPen);
-char *CheckPkg = NULL;
-
-static void usage(void);
-
-int
-main(int argc, char **argv)
-{
- int ch;
- char **pkgs, **start;
-
- pkgs = start = argv;
- while ((ch = getopt(argc, argv, Options)) != -1)
- switch(ch) {
- case 'a':
- AllInstalled = TRUE;
- break;
-
- case 'c':
- Flags |= SHOW_COMMENT;
- break;
-
- case 'D':
- Flags |= SHOW_DISPLAY;
- break;
-
- case 'd':
- Flags |= SHOW_DESC;
- break;
-
- case 'e':
- CheckPkg = optarg;
- break;
-
- case 'f':
- Flags |= SHOW_PLIST;
- break;
-
- case 'I':
- Flags |= SHOW_INDEX;
- break;
-
- case 'i':
- Flags |= SHOW_INSTALL;
- break;
-
- case 'k':
- Flags |= SHOW_DEINSTALL;
- break;
-
- case 'L':
- Flags |= SHOW_FILES;
- break;
-
- case 'l':
- InfoPrefix = optarg;
- break;
-
- case 'm':
- Flags |= SHOW_MTREE;
- break;
-
- case 'p':
- Flags |= SHOW_PREFIX;
- break;
-
- case 'q':
- Quiet = TRUE;
- break;
-
- case 'R':
- Flags |= SHOW_REQBY;
- break;
-
- case 'r':
- Flags |= SHOW_REQUIRE;
- break;
-
- case 'v':
- Verbose = TRUE;
- /* Reasonable definition of 'everything' */
- Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
- SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE |
- SHOW_REQBY;
- break;
-
- case 'h':
- case '?':
- default:
- usage();
- /* NOTREACHED */
- }
-
- argc -= optind;
- argv += optind;
-
- if (argc == 0 && !Flags) {
- /* No argument or flags specified - assume -Ia */
- Flags = SHOW_INDEX;
- AllInstalled = TRUE;
- }
-
- /* Set some reasonable defaults */
- if (!Flags)
- Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY;
-
- /* Get all the remaining package names, if any */
- while (*argv)
- *pkgs++ = *argv++;
-
- /* If no packages, yelp */
- if (pkgs == start && !AllInstalled && !CheckPkg)
- pwarnx("missing package name(s)"), usage();
- *pkgs = NULL;
- return pkg_perform(start);
-}
-
-static void
-usage()
-{
- fprintf(stderr, "usage: %s\nusage: %s\n",
- "pkg_info [-cDdfIikLmpqRrvh] [-e package] [-l prefix] pkg-name ...",
- "pkg_info -a [flags]");
- exit(1);
-}
diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c
deleted file mode 100644
index 5a96258a779..00000000000
--- a/usr.sbin/pkg_install/info/perform.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/* $OpenBSD: perform.c,v 1.16 2003/08/23 09:14:43 tedu Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: perform.c,v 1.16 2003/08/23 09:14:43 tedu Exp $";
-#endif
-
-/* This is OpenBSD pkg_install, based on:
- *
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 23 Aug 1993
- *
- * This is the main body of the info module.
- *
- */
-
-#include "lib.h"
-#include "info.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <err.h>
-#include <signal.h>
-#include <dirent.h>
-#include <ctype.h>
-
-static char *Home;
-
-/* retrieve info on installed packages from the base name:
- * find a full name of the form pkg-xxx.
- */
-static char *
-find_prefix(char *buffer, int bufsize, char *base, char *pkg)
-{
- DIR *dirp;
- struct dirent *dp;
- char *res;
- int pkg_length = strlen(pkg);
-
-
- if (! (dirp = opendir(base)) )
- return 0;
- while ( (dp = readdir(dirp)) ) {
- if (strncmp(dp->d_name, pkg, pkg_length) == 0
- && dp->d_name[pkg_length] == '-') {
- snprintf(buffer, bufsize, "%s/%s", base, dp->d_name);
- /* pedantic: need to dup res before closedir() */
- res = strdup(dp->d_name);
- (void)closedir(dirp);
- return res;
- }
- }
- (void)closedir(dirp);
- return 0;
-}
-
-static int
-pkg_do(char *pkg)
-{
- Boolean installed = FALSE, isTMP = FALSE;
- char log_dir[FILENAME_MAX];
- char fname[FILENAME_MAX];
- package_t plist;
- FILE *fp;
- struct stat sb;
- char *cp = NULL;
- int code = 0;
- char *pkg2 = 0; /* hold full name of package, storage to free */
- int len;
- int isurl = 0;
-
- set_pkg(pkg);
-
- if (AllInstalled)
- goto installed;
-
- if (isURL(pkg)) {
- if ((cp = fileGetURL(NULL, pkg)) != NULL) {
- strlcpy(fname, cp, sizeof(fname));
- isTMP = TRUE;
- }
- isurl = 1;
- } else if (fexists(pkg) && isfile(pkg)) {
-
- if (*pkg != '/') {
- if (!getcwd(fname, sizeof(fname))) {
- cleanup(0);
- err(1, "fatal error during execution: getcwd");
- }
- len = strlen(fname);
- snprintf(&fname[len], sizeof(fname) - len, "/%s", pkg);
- } else
- strlcpy(fname, pkg, sizeof(fname));
- cp = fname;
- } else {
- if ((cp = fileFindByPath(NULL, pkg)) != NULL) {
- strlcpy(fname, cp, sizeof(fname));
- if (isURL(fname) && (cp = fileGetURL(NULL, fname))
- != NULL) {
- strlcpy(fname, cp, sizeof(fname));
- isTMP = TRUE;
- isurl = 1;
- } else if (*cp != '/') {
- if (!getcwd(fname, sizeof(fname))) {
- cleanup(0);
- err(1, "fatal error during execution: "
- "getcwd");
- }
- len = strlen(fname);
- snprintf(&fname[len], sizeof(fname) - len,
- "/%s", cp);
- }
- }
- }
- if (cp) {
- if (isurl) {
- /* file is already unpacked by fileGetURL() */
- strlcpy(PlayPen, cp, PlayPenSize);
- } else {
- /*
- * Apply a crude heuristic to see how much space the package will
- * take up once it's unpacked. I've noticed that most packages
- * compress an average of 75%, but we're only unpacking the + files so
- * be very optimistic.
- */
- if (stat(fname, &sb) == FAIL) {
- pwarnx("can't stat package file '%s'", fname);
- code = 1;
- goto bail;
- }
- Home = make_playpen(PlayPen, PlayPenSize, sb.st_size / 2);
- if (unpack(fname, "+*")) {
- pwarnx("error during unpacking, no info for '%s' available", pkg);
- code = 1;
- goto bail;
- }
- }
- }
- /*
- * It's not an uninstalled package, try and find it among the
- * installed
- */
- else
-installed:
- {
- char *tmp;
-
- if (!(tmp = getenv(PKG_DBDIR)))
- tmp = DEF_LOG_DIR;
-
- (void) snprintf(log_dir, sizeof(log_dir), "%s/%s", tmp,
- pkg);
- if (!fexists(log_dir) &&
- ! (pkg2 = find_prefix(log_dir, sizeof(log_dir), tmp, pkg))) {
- pwarnx("can't find package `%s' installed or in a file!", pkg);
- return 1;
- }
- if (pkg2)
- pkg = pkg2;
- if (chdir(log_dir) == FAIL) {
- pwarnx("can't change directory to '%s'!", log_dir);
- free(pkg2);
- return 1;
- }
- installed = TRUE;
- }
-
- /*
- * Index is special info type that has to override all others to make
- * any sense.
- */
- if (Flags & SHOW_INDEX) {
- show_index(pkg, COMMENT_FNAME);
- } else {
- /* Suck in the contents list */
- plist.head = plist.tail = NULL;
- fp = fopen(CONTENTS_FNAME, "r");
- if (!fp) {
- pwarnx("unable to open %s file", CONTENTS_FNAME);
- if (isurl) /* file not on server, check installed */
- goto installed;
- code = 1;
- goto bail;
- }
- /* If we have a prefix, add it now */
- read_plist(&plist, fp);
- fclose(fp);
-
- /* Start showing the package contents */
- if (!Quiet)
- printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
- if (Flags & SHOW_COMMENT)
- show_file("Comment:\n", COMMENT_FNAME);
- if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME))
- show_file("Required by:\n", REQUIRED_BY_FNAME);
- if (Flags & SHOW_DESC)
- show_file("Description:\n", DESC_FNAME);
- if ((Flags & SHOW_DISPLAY) && fexists(DISPLAY_FNAME))
- show_file("Install notice:\n", DISPLAY_FNAME);
- if (Flags & SHOW_PLIST)
- show_plist("Packing list:\n", &plist, PLIST_SHOW_ALL);
- if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME))
- show_file("Install script:\n", INSTALL_FNAME);
- if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME))
- show_file("De-Install script:\n", DEINSTALL_FNAME);
- if ((Flags & SHOW_MTREE) && fexists(MTREE_FNAME))
- show_file("mtree file:\n", MTREE_FNAME);
- if (Flags & SHOW_PREFIX)
- show_plist("Prefix(s):\n", &plist, PLIST_CWD);
- if (Flags & SHOW_FILES)
- show_files("Files:\n", &plist);
- if (!Quiet)
- puts(InfoPrefix);
- free_plist(&plist);
- }
-bail:
- free(pkg2);
- leave_playpen(Home);
- if (isTMP)
- unlink(fname);
- return code;
-}
-
-/* fn to be called for pkgs found */
-static int
-foundpkg(const char *found, char *data, int unused)
-{
- if(!Quiet)
- printf("%s\n", found);
- return 0;
-}
-
-/* check if a package "pkgspec" (which can be a pattern) is installed */
-/* return 0 if found, 1 otherwise (indicating an error). */
-static int
-check4pkg(char *pkgspec, char *dbdir)
-{
- if (strpbrk(pkgspec, "<>[]?*{")) {
- /* expensive (pattern) match */
- int found;
-
- found=findmatchingname(dbdir, pkgspec, foundpkg, NULL, 0);
- return !found;
- } else {
- /* simple match */
- char buf[FILENAME_MAX];
- int error;
- struct stat st;
-
- snprintf(buf, sizeof(buf), "%s/%s", dbdir, pkgspec);
- error = (stat(buf, &st) < 0);
- if (!error && !Quiet)
- printf("%s\n", pkgspec);
-
- return error;
- }
-}
-
-void
-cleanup(int sig)
-{
- leave_playpen(Home); /* XXX signal race */
- _exit(1);
-}
-
-int
-pkg_perform(char **pkgs)
-{
- int i, err_cnt = 0;
- char *tmp;
-
- signal(SIGINT, cleanup);
-
- tmp = getenv(PKG_DBDIR);
- if (!tmp)
- tmp = DEF_LOG_DIR;
- /* Overriding action? */
- if (CheckPkg) {
- err_cnt += check4pkg(CheckPkg, tmp);
- } else if (AllInstalled) {
- struct dirent *dp;
- DIR *dirp;
-
- if (!(isdir(tmp) || islinktodir(tmp)))
- return 1;
- if (chdir(tmp) != 0)
- return 1;
- if ((dirp = opendir(".")) != (DIR *) NULL) {
- while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
- if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
- err_cnt += pkg_do(dp->d_name);
- }
- }
- (void) closedir(dirp);
- }
- } else {
- for (i = 0; pkgs[i]; i++) {
- err_cnt += pkg_do(pkgs[i]);
- }
- }
- return err_cnt;
-}
diff --git a/usr.sbin/pkg_install/info/pkg_info.1 b/usr.sbin/pkg_install/info/pkg_info.1
deleted file mode 100644
index 4b5a1ef94cc..00000000000
--- a/usr.sbin/pkg_install/info/pkg_info.1
+++ /dev/null
@@ -1,206 +0,0 @@
-.\" $OpenBSD: pkg_info.1,v 1.12 2003/06/12 12:59:52 jmc Exp $
-.\"
-.\" FreeBSD install - a package for the installation and maintenance
-.\" of non-core utilities.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" Jordan K. Hubbard
-.\"
-.\"
-.\" @(#)pkg_info.1
-.\"
-.Dd August 22, 1998
-.Dt PKG_INFO 1
-.Os
-.Sh NAME
-.Nm pkg_info
-.Nd a utility for displaying information on software packages
-.Sh SYNOPSIS
-.Nm pkg_info
-.Op Fl cDdfIikLmpqRrvh
-.Op Fl e Ar package
-.Op Fl l Ar prefix
-.Ar pkg-name Op Ar ...
-.Nm pkg_info
-.Op Fl a Ar flags
-.Sh DESCRIPTION
-The
-.Nm
-command is used to dump out information for packages, which may be either
-packed up in files or already installed on the system with the
-.Xr pkg_create 1
-command.
-.Pp
-The
-.Ar pkg-name
-may be the name of an installed package, the pathname to a package
-distribution file, or a URL to an ftp-available package.
-.Nm
-will try to complete
-.Ar pkg-name
-with a version number while looking through installed packages.
-.Pp
-The following command-line options are supported:
-.Bl -tag -width indent
-.It Fl a
-Show information for all currently installed packages.
-.It Fl c
-Show the one-line comment field for each package.
-.It Fl D
-Show the install-message file (if any) for each package.
-.It Fl d
-Show the long-description field for each package.
-.It Fl e Ar pkg-name
-This option
-allows you to test for the presence of another (perhaps
-prerequisite) package from a script.
-If the package identified by
-.Ar pkg-name
-is currently installed, return 0, otherwise return 1.
-In addition, the names of any package(s) found installed are printed to
-stdout unless turned off using the
-.Fl q
-option.
-.Pp
-If the given
-.Ar pkg-name
-contains a
-shell meta-character, it will be matched against all installed
-packages using
-.Xr fnmatch 3 .
-.Xr csh 1
-style
-.Dq {,}
-alternates have also been implemented in addition to this.
-Package version numbers can also be matched in a relational manner
-using the
-.Dq >= ,
-.Dq <= ,
-.Dq > ,
-and
-.Dq <
-operators.
-For example,
-.Ic pkg_info -e 'name>=1.3'
-will match versions 1.3 and later of the
-.Pa name
-package.
-.It Fl f
-Show the packing list instructions for each package.
-.It Fl I
-Show the index entry for each package.
-.It Fl i
-Show the install script (if any) for each package.
-.It Fl k
-Show the de-install script (if any) for each package.
-.It Fl L
-Show the files within each package.
-This is different from just
-viewing the packing list, since full pathnames for everything
-are generated.
-.It Fl l Ar str
-Prefix each information category header (see
-.Fl q )
-shown with
-.Ar str .
-This is primarily of use to front-end programs that want to request a
-lot of different information fields at once for a package, but don't
-necessary want the output intermingled in such a way that they can't
-organize it.
-This lets you add a special token to the start of each field.
-.It Fl m
-Show the mtree file (if any) for each package.
-.It Fl p
-Show the installation prefix for each package.
-.It Fl q
-Be
-.Dq quiet
-in emitting report headers and such, just dump the
-raw info (basically, assume a non-human reading).
-.It Fl R
-Show which packages require a given package.
-.It Fl r
-Show the requirements script (if any) for each package.
-.It Fl v
-Turn on verbose output.
-.El
-.Sh ENVIRONMENT
-.Bl -tag -width PKG_DBDIR
-.It Ev PKG_DBDIR
-The standard package database directory,
-.Pa /var/db/pkg ,
-can be overridden by specifying an alternative directory in the
-.Ev PKG_DBDIR
-environment variable.
-.It Ev PKG_PATH
-This can be used to specify a colon-separated list of paths to search for
-package files.
-The current directory is always searched first, even if
-.Ev PKG_PATH
-is set.
-If
-.Ev PKG_PATH
-is used, the suffix
-.Dq .tgz
-is automatically appended to the
-.Ar pkg-name ,
-whereas searching in the current directory uses
-.Ar pkg-name
-literally.
-.It Ev PKG_TMPDIR , Ev TMPDIR
-These are tried in turn (if set) as candidate directories in which
-to create a
-.Dq staging area
-for any files extracted by
-.Nm
-from package files.
-If neither
-.Ev PKG_TMPDIR
-nor
-.Ev TMPDIR
-yields a suitable scratch directory,
-.Pa /var/tmp ,
-.Pa /tmp ,
-and
-.Pa /usr/tmp
-are tried in turn.
-Note that
-.Pa /usr/tmp
-may be created, if it doesn't already exist.
-.Pp
-Since
-.Nm
-requires very little information to be extracted from any package
-files examined, it is unlikely that these environment variables would
-ever need to be used to work around limited available space in the
-default locations.
-.El
-.Sh TECHNICAL DETAILS
-Package info is either extracted from package files named on the
-command line, or from already installed package information
-in
-.Pa /var/db/pkg/<pkg-name> .
-.Sh SEE ALSO
-.Xr pkg_add 1 ,
-.Xr pkg_create 1 ,
-.Xr pkg_delete 1 ,
-.Xr mkstemp 3 ,
-.Xr mtree 8
-.Sh AUTHORS
-.Bl -tag -width indent -compact
-.It "Jordan Hubbard"
-most of the work
-.It "John Kohl"
-refined it for
-.Nx
-.El
-.Sh BUGS
-Sure to be some.
diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c
deleted file mode 100644
index 6e5fdd3f5e7..00000000000
--- a/usr.sbin/pkg_install/info/show.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/* $OpenBSD: show.c,v 1.13 2003/08/21 20:24:56 espie Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: show.c,v 1.13 2003/08/21 20:24:56 espie Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 23 Aug 1993
- *
- * Various display routines for the info module.
- *
- */
-
-#include <err.h>
-
-#include "lib.h"
-#include "info.h"
-
-/* structure to define entries for the "show table" */
-typedef struct show_t {
- pl_ent_t sh_type; /* type of entry */
- char *sh_quiet; /* message when quiet */
- char *sh_verbose; /* message when verbose */
-} show_t;
-
-/* the entries in this table must be ordered the same as pl_ent_t constants */
-static show_t showv[] = {
- { PLIST_FILE, "%s", "File: %s" },
- { PLIST_CWD, "@cwd %s", "\tCWD to: %s" },
- { PLIST_CMD, "@exec %s", "\tEXEC '%s'" },
- { PLIST_CHMOD, "@chmod %s", "\tCHMOD to %s" },
- { PLIST_CHOWN, "@chown %s", "\tCHOWN to %s" },
- { PLIST_CHGRP, "@chgrp %s", "\tCHGRP to %s" },
- { PLIST_COMMENT, "@comment %s", "\tComment: %s" },
- { PLIST_IGNORE, NULL, NULL },
- { PLIST_NAME, "@name %s", "\tPackage name: %s" },
- { PLIST_UNEXEC, "@unexec %s", "\tUNEXEC '%s'" },
- { PLIST_SRC, "@srcdir: %s", "\tSRCDIR to: %s" },
- { PLIST_DISPLAY, "@display %s", "\tInstall message file: %s" },
- { PLIST_PKGDEP, "@pkgdep %s", "\tPackage depends on: %s" },
- { PLIST_MTREE, "@mtree %s", "\tPackage mtree file: %s" },
- { PLIST_DIR_RM, "@dirrm %s", "\tDeinstall directory remove: %s" },
- { PLIST_OPTION, "@option %s", "\tPackage has option: %s" },
- { PLIST_PKGCFL, "@pkgcfl %s", "\tPackage conflicts with: %s" },
- { PLIST_EXTRA, "@extra %s", "\tExtra files: %s" },
- { PLIST_EXTRAUNEXEC,
- "@extraunexec %s",
- "\tExtra UNEXEC: %s" },
- { -1, NULL, NULL }
-};
-
-void
-show_file(char *title, char *fname)
-{
- FILE *fp;
- char line[1024];
- int n;
-
- if (!Quiet) {
- printf("%s%s", InfoPrefix, title);
- }
- if ((fp = fopen(fname, "r")) == (FILE *) NULL) {
- printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
- } else {
- while ((n = fread(line, 1, 1024, fp)) != 0) {
- fwrite(line, 1, n, stdout);
- }
- (void) fclose(fp);
- }
- printf("\n"); /* just in case */
-}
-
-void
-show_index(char *title, char *fname)
-{
- FILE *fp;
- char line[MAXINDEXSIZE+2];
-
- strlcpy(line, "???\n", sizeof(line));
-
- if (!Quiet) {
- printf("%s%-18s ", InfoPrefix, title);
- }
- if ((fp = fopen(fname, "r")) == (FILE *) NULL) {
- pwarnx("show_file (%s): can't open '%s' for reading", title, fname);
- }
- else {
- if (fgets(line, MAXINDEXSIZE+1, fp)) {
- int line_length = strlen(line);
-
- if (line[line_length-1] != '\n') {
- line[line_length] = '\n';
- line[line_length+1] = 0;
- }
- }
- (void) fclose(fp);
- }
- (void) fputs(line, stdout);
-}
-
-/* Show a packing list item type. If type is PLIST_SHOW_ALL, show all */
-void
-show_plist(char *title, package_t *plist, pl_ent_t type)
-{
- plist_t *p;
- Boolean ign;
-
- if (!Quiet) {
- printf("%s%s", InfoPrefix, title);
- }
- for (ign = FALSE, p = plist->head; p ; p = p->next) {
- if (p->type == type || type == PLIST_SHOW_ALL) {
- switch(p->type) {
- case PLIST_FILE:
- printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
- if (ign) {
- if (!Quiet) {
- printf(" (ignored)");
- }
- ign = FALSE;
- }
- break;
- case PLIST_CHMOD:
- case PLIST_CHOWN:
- case PLIST_CHGRP:
- printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose,
- p->name ? p->name : "(clear default)");
- break;
- case PLIST_IGNORE:
- ign = TRUE;
- break;
- case PLIST_CWD:
- case PLIST_CMD:
- case PLIST_SRC:
- case PLIST_UNEXEC:
- case PLIST_COMMENT:
- case PLIST_NAME:
- case PLIST_DISPLAY:
- case PLIST_PKGDEP:
- case PLIST_MTREE:
- case PLIST_DIR_RM:
- case PLIST_OPTION:
- case PLIST_PKGCFL:
- case PLIST_EXTRA:
- case PLIST_EXTRAUNEXEC:
- printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
- break;
- default:
- pwarnx("unknown command type %d (%s)", p->type, p->name);
- }
- (void) fputc('\n', stdout);
- }
- }
-}
-
-/* Show all files in the packing list (except ignored ones) */
-void
-show_files(char *title, package_t *plist)
-{
- plist_t *p;
- Boolean ign;
- char *dir = ".";
-
- if (!Quiet) {
- printf("%s%s", InfoPrefix, title);
- }
- for (ign = FALSE, p = plist->head; p ; p = p->next) {
- switch(p->type) {
- case PLIST_FILE:
- if (!ign) {
- printf("%s/%s\n", dir, p->name);
- }
- ign = FALSE;
- break;
- case PLIST_CWD:
- dir = p->name;
- break;
- case PLIST_IGNORE:
- ign = TRUE;
- break;
- default:
- break;
- }
- }
-}
diff --git a/usr.sbin/pkg_install/lib/Makefile b/usr.sbin/pkg_install/lib/Makefile
deleted file mode 100644
index e1f0b4efbfa..00000000000
--- a/usr.sbin/pkg_install/lib/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-# $OpenBSD: Makefile,v 1.5 2001/04/08 16:45:47 espie Exp $
-LIB= install
-SRCS= file.c plist.c str.c exec.c global.c pen.c pwarnx.c
-CFLAGS+= ${DEBUG}
-NOPROFILE= yes
-NOPIC= yes
-
-install:
- @echo -n
-
-.include <bsd.lib.mk>
diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c
deleted file mode 100644
index f912eba46a5..00000000000
--- a/usr.sbin/pkg_install/lib/exec.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/* $OpenBSD: exec.c,v 1.8 2003/09/05 19:40:42 tedu Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: exec.c,v 1.8 2003/09/05 19:40:42 tedu Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Miscellaneous system routines.
- *
- */
-
-#include <err.h>
-#include "lib.h"
-
-/*
- * Unusual system() substitute. Accepts format string and args,
- * builds and executes command. Returns exit code.
- */
-
-int
-vsystem(const char *fmt, ...)
-{
- va_list args;
- char *cmd;
- size_t maxargs;
- int ret;
-
- maxargs = (size_t) sysconf(_SC_ARG_MAX);
- if ((long)maxargs == -1) {
- pwarnx("vsystem can't retrieve max args");
- return 1;
- }
- maxargs -= 32; /* some slop for the sh -c */
- if ((cmd = (char *) malloc(maxargs)) == (char *) NULL) {
- pwarnx("vsystem can't alloc arg space");
- return 1;
- }
-
- va_start(args, fmt);
- if (vsnprintf(cmd, maxargs, fmt, args) >= maxargs) {
- pwarnx("vsystem args are too long");
- free(cmd);
- return 1;
- }
-#ifdef DEBUG
- printf("Executing %s\n", cmd);
-#endif
- ret = system(cmd);
- va_end(args);
- free(cmd);
- return ret;
-}
-
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
deleted file mode 100644
index ffed6a427c8..00000000000
--- a/usr.sbin/pkg_install/lib/file.c
+++ /dev/null
@@ -1,701 +0,0 @@
-/* $OpenBSD: file.c,v 1.26 2003/08/21 20:24:57 espie Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: file.c,v 1.26 2003/08/21 20:24:57 espie Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Miscellaneous file access utilities.
- *
- */
-
-#include "lib.h"
-
-#include <sys/wait.h>
-
-#include <assert.h>
-#include <err.h>
-#include <netdb.h>
-#include <pwd.h>
-#include <time.h>
-
-/* This fixes errant package names so they end up in .tgz.
- XXX returns static storage, so beware ! Consume the result
- before reusing the function.
- */
-#define TGZ ".tgz"
-char *
-ensure_tgz(char *name)
-{
- static char buffer[FILENAME_MAX];
- size_t len;
-
- len = strlen(name);
- if ( (strcmp (name, "-") == 0 )
- || (len >= strlen(TGZ) && strcmp(name+len-strlen(TGZ), TGZ) == 0)
- || (len >= strlen(".tar.gz") &&
- strcmp(name+len-strlen(".tar.gz"), ".tar.gz") == 0)
- || (len >= strlen(".tar") &&
- strcmp(name+len-strlen(".tar"), ".tar") == 0))
- return name;
- else {
- snprintf(buffer, sizeof(buffer), "%s%s", name, TGZ);
- return buffer;
- }
-}
-
-/* This is as ftpGetURL from FreeBSD's ftpio.c, except that it uses
- * OpenBSD's ftp command to do all FTP.
- */
-static FILE *
-ftpGetURL(char *url, int *retcode)
-{
- FILE *ftp;
- pid_t pid_ftp;
- int p[2];
-
- *retcode=0;
-
- if (pipe(p) < 0) {
- *retcode = 1;
- return NULL;
- }
-
- pid_ftp = fork();
- if (pid_ftp < 0) {
- *retcode = 1;
- return NULL;
- }
- if (pid_ftp == 0) {
- /* child */
- dup2(p[1],1);
- close(p[1]);
-
- fprintf(stderr, ">>> ftp -o - %s\n",url);
- execl("/usr/bin/ftp","ftp","-V","-o","-",url,(char *)NULL);
- exit(1);
- } else {
- /* parent */
- ftp = fdopen(p[0],"r");
-
- close(p[1]);
-
- if (ftp == (FILE *) NULL) {
- *retcode = 1;
- return NULL;
- }
- }
- return ftp;
-}
-
-/* Quick check to see if a file exists */
-Boolean
-fexists(const char *fname)
-{
- struct stat dummy;
- if (!lstat(fname, &dummy))
- return TRUE;
- return FALSE;
-}
-
-/* Quick check to see if something is a directory */
-Boolean
-isdir(const char *fname)
-{
- struct stat sb;
-
- if (lstat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
- return TRUE;
- else
- return FALSE;
-}
-
-/* Check if something is a link to a directory */
-Boolean
-islinktodir(const char *fname)
-{
- struct stat sb;
-
- if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode))
- if (stat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
- return TRUE; /* link to dir! */
- else
- return FALSE; /* link to non-dir */
- else
- return FALSE; /* non-link */
-}
-
-/* Check to see if file is a dir, and is empty */
-Boolean
-isemptydir(const char *fname)
-{
- if (isdir(fname) || islinktodir(fname)) {
- DIR *dirp;
- struct dirent *dp;
-
- dirp = opendir(fname);
- if (!dirp)
- return FALSE; /* no perms, leave it alone */
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
- if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
- closedir(dirp);
- return FALSE;
- }
- }
- (void)closedir(dirp);
- return TRUE;
- }
- return FALSE;
-}
-
-Boolean
-isfile(const char *fname)
-{
- struct stat sb;
- if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode))
- return TRUE;
- return FALSE;
-}
-
-/* Check to see if file is a file and is empty. If nonexistent or not
- a file, say "it's empty", otherwise return TRUE if zero sized. */
-Boolean
-isemptyfile(const char *fname)
-{
- struct stat sb;
- if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) {
- if (sb.st_size != 0)
- return FALSE;
- }
- return TRUE;
-}
-
-/* Returns TRUE if file is a URL specification */
-Boolean
-isURL(const char *fname)
-{
- /*
- * Hardcode url types... not perfect, but working.
- */
- if (!fname)
- return FALSE;
- while (isspace(*fname))
- ++fname;
- if (!strncmp(fname, "ftp://", 6))
- return TRUE;
- if (!strncmp(fname, "http://", 7))
- return TRUE;
- return FALSE;
-}
-
-/* Returns the host part of a URL */
-char *
-fileURLHost(char *fname, char *where, int max)
-{
- char *ret;
-
- while (isspace(*fname))
- ++fname;
- /* Don't ever call this on a bad URL! */
- fname = strchr(fname, ':');
- if (fname)
- fname+=3;
- else
- return NULL;
- /* Do we have a place to stick our work? */
- if ((ret = where) != NULL) {
- while (*fname && *fname != '/' && max--)
- *where++ = *fname++;
- *where = '\0';
- return ret;
- }
- /* If not, they must really want us to stomp the original string */
- ret = fname;
- while (*fname && *fname != '/')
- ++fname;
- *fname = '\0';
- return ret;
-}
-
-/* Returns the filename part of a URL */
-char *
-fileURLFilename(char *fname, char *where, int max)
-{
- char *ret;
-
- while (isspace(*fname))
- ++fname;
- /* Don't ever call this on a bad URL! */
- fname = strchr(fname, ':');
- if (fname)
- fname+=3;
- else
- return NULL;
- /* Do we have a place to stick our work? */
- if ((ret = where) != NULL) {
- while (*fname && *fname != '/')
- ++fname;
- if (*fname == '/') {
- while (*fname && max--)
- *where++ = *fname++;
- }
- *where = '\0';
- return ret;
- }
- /* If not, they must really want us to stomp the original string */
- while (*fname && *fname != '/')
- ++fname;
- return fname;
-}
-
-/*
- * Try and fetch a file by URL, returning the directory name for where
- * it's unpacked, if successful.
- */
-char *
-fileGetURL(char *base, char *spec)
-{
- char host[MAXHOSTNAMELEN], file[FILENAME_MAX];
- char *cp, *rp;
- char fname[FILENAME_MAX];
- char pen[FILENAME_MAX];
- FILE *ftp;
- pid_t tpid;
- int i, status;
- char *hint;
-
- rp = NULL;
- /* Special tip that sysinstall left for us */
- hint = getenv("PKG_ADD_BASE");
- if (!isURL(spec)) {
- if (!base && !hint)
- return NULL;
- /* We've been given an existing URL (that's known-good) and now we need
- to construct a composite one out of that and the basename we were
- handed as a dependency. */
- if (base) {
- strlcpy(fname, base, sizeof(fname));
- /* OpenBSD packages are currently stored in a flat space, so
- we don't yet need to backup the category and switch to all.
- */
- cp = strrchr(fname, '/');
- if (cp) {
- *(cp + 1) = '\0';
- strlcat(fname, ensure_tgz(spec), sizeof(fname));
- }
- else
- return NULL;
- }
- else {
- /* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
- snprintf(fname, sizeof(fname), "%s%s", hint, spec);
- }
- }
- else
- strlcpy(fname, spec, sizeof(fname));
- cp = fileURLHost(fname, host, sizeof(host));
- if (!*cp) {
- pwarnx("URL `%s' has bad host part!", fname);
- return NULL;
- }
-
- cp = fileURLFilename(fname, file, sizeof(fname));
- if (!*cp) {
- pwarnx("URL `%s' has bad filename part!", fname);
- return NULL;
- }
-
- if (Verbose)
- printf("Trying to fetch %s.\n", fname);
- ftp = ftpGetURL(fname, &status);
- if (ftp) {
- pen[0] = '\0';
- if ((rp = make_playpen(pen, sizeof(pen), 0)) != NULL) {
- rp=strdup(pen); /* be safe for nested calls */
- if (Verbose)
- printf("Extracting from FTP connection into %s\n", pen);
- tpid = fork();
- if (!tpid) {
- dup2(fileno(ftp), 0);
- i = execl("/bin/tar", "tar", Verbose ? "-xpzvf" : "-xpzf", "-", (char *)NULL);
- exit(i);
- }
- else {
- int pstat;
-
- fclose(ftp);
- tpid = waitpid(tpid, &pstat, 0);
- if (Verbose)
- printf("tar command returns %d status\n", WEXITSTATUS(pstat));
- }
- }
- else
- printf("Error: Unable to construct a new playpen for FTP!\n");
- fclose(ftp);
- }
- else
- printf("Error: FTP Unable to get %s: %s\n",
- fname,
- status ? "Error while performing FTP" :
- hstrerror(h_errno));
- return rp;
-}
-
-char *
-fileFindByPath(char *base, char *fname)
-{
- static char tmp[FILENAME_MAX];
- char *cp;
-
- if (ispkgpattern(fname)) {
- if ((cp=findbestmatchingname(".",fname)) != NULL) {
- strlcpy(tmp, cp, sizeof(tmp));
- free(cp);
- return tmp;
- }
- } else {
- strlcpy(tmp, ensure_tgz(fname), sizeof(tmp));
- if (fexists(tmp) && isfile(tmp)) {
- return tmp;
- }
- }
-
- if (base) {
- strlcpy(tmp, base, sizeof(tmp));
-
- cp = strrchr(tmp, '/');
- if (cp) {
- *(cp + 1) = '\0';
- strlcat(tmp, ensure_tgz(fname), sizeof(tmp));
- if (ispkgpattern(tmp)) {
- cp=findbestmatchingname(dirname_of(tmp),
- basename_of(tmp));
- if (cp) {
- char *s;
- s=strrchr(tmp,'/');
- assert(s != NULL);
- strlcpy(s+1, cp,
- tmp + sizeof(tmp) - (s+1));
- free(cp);
- return tmp;
- }
- } else {
- if (fexists(tmp)) {
- return tmp;
- }
- }
- }
- }
-
- cp = getenv("PKG_PATH");
- /* Check for ftp://... paths */
- if (isURL(cp)) {
- snprintf(tmp, sizeof(tmp), "%s/%s", cp, ensure_tgz(fname));
- return tmp;
- }
- while (cp) {
- char *cp2 = strsep(&cp, ":");
-
- snprintf(tmp, sizeof(tmp), "%s/%s", cp2, ensure_tgz(fname));
- if (ispkgpattern(tmp)) {
- char *s;
- s = findbestmatchingname(dirname_of(tmp),
- basename_of(tmp));
- if (s){
- char *t;
- t=strrchr(tmp, '/');
- strlcpy(t+1, s, tmp + sizeof(tmp) - (t+1));
- free(s);
- return tmp;
- }
- } else {
- if (fexists(tmp) && isfile(tmp)) {
- return tmp;
- }
- }
- }
-
- return NULL;
-}
-
-char *
-fileGetContents(char *fname)
-{
- char *contents;
- struct stat sb;
- int fd;
-
- if (stat(fname, &sb) == FAIL) {
- cleanup(0);
- errx(2, "can't stat '%s'", fname);
- }
-
- contents = (char *)malloc((size_t)(sb.st_size) + 1);
- fd = open(fname, O_RDONLY, 0);
- if (fd == FAIL) {
- cleanup(0);
- errx(2, "unable to open '%s' for reading", fname);
- }
- if (read(fd, contents, (size_t) sb.st_size) != (size_t) sb.st_size) {
- cleanup(0);
- errx(2, "short read on '%s' - did not get %qd bytes",
- fname, (long long)sb.st_size);
- }
- close(fd);
- contents[(size_t)sb.st_size] = '\0';
- return contents;
-}
-
-/* Takes a filename and package name, returning (in "try") the canonical "preserve"
- * name for it.
- */
-Boolean
-make_preserve_name(char *try, size_t max, char *name, char *file)
-{
- char *p;
- int i;
-
- i = strlcpy(try, file, max);
- if (i == 0 || i >= max)
- return FALSE;
-
- /* Catch trailing slash early */
- i--;
- if (try[i] == '/')
- try[i] = '\0';
-
- p = strrchr(try, '/');
- if (p == NULL)
- p = try;
- else
- p++;
-
- i = p - try;
- if (snprintf(p, max - i, ".%s.%s.backup", file + i, name) >= (max - i))
- return FALSE;
-
- return TRUE;
-}
-
-/* Write the contents of "str" to a file */
-void
-write_file(char *name, char *str)
-{
- FILE *fp;
- size_t len;
-
- if ((fp = fopen(name, "w")) == (FILE *) NULL) {
- cleanup(0);
- errx(2, "cannot fopen '%s' for writing", name);
- }
- len = strlen(str);
- if (fwrite(str, 1, len, fp) != len) {
- cleanup(0);
- errx(2, "short fwrite on '%s', tried to write %d bytes",
- name, len);
- }
- if (fclose(fp)) {
- cleanup(0);
- errx(2, "failure to fclose '%s'", name);
- }
-}
-
-void
-copy_file(char *dir, char *fname, char *to)
-{
- char cmd[FILENAME_MAX];
-
- if (fname[0] == '/')
- snprintf(cmd, sizeof(cmd), "cp -p -r %s %s", fname, to);
- else
- snprintf(cmd, sizeof(cmd), "cp -p -r %s/%s %s", dir, fname, to);
- if (vsystem("%s", cmd)) {
- cleanup(0);
- errx(2, "could not perform '%s'", cmd);
- }
-}
-
-void
-move_file(char *dir, char *fname, char *to)
-{
- char cmd[FILENAME_MAX];
-
- if (fname[0] == '/')
- snprintf(cmd, sizeof(cmd), "mv %s %s", fname, to);
- else
- snprintf(cmd, sizeof(cmd), "mv %s/%s %s", dir, fname, to);
- if (vsystem("%s", cmd)) {
- cleanup(0);
- errx(2, "could not perform '%s'", cmd);
- }
-}
-
-/*
- * Copy a hierarchy (possibly from dir) to the current directory, or
- * if "to" is TRUE, from the current directory to a location someplace
- * else.
- *
- * Though slower, using tar to copy preserves symlinks and everything
- * without me having to write some big hairy routine to do it.
- */
-void
-copy_hierarchy(char *dir, char *fname, Boolean to)
-{
- char cmd[FILENAME_MAX * 3];
-
- if (!to) {
- /* If absolute path, use it */
- if (*fname == '/')
- dir = "/";
- snprintf(cmd, sizeof(cmd), "tar cf - -C %s %s | tar xpf -",
- dir, fname);
- }
- else
- snprintf(cmd, sizeof(cmd), "tar cf - %s | tar xpf - -C %s",
- fname, dir);
-#ifdef DEBUG
- printf("Using '%s' to copy trees.\n", cmd);
-#endif
- if (system(cmd)) {
- cleanup(0);
- errx(2, "copy_file: could not perform '%s'", cmd);
- }
-}
-
-/* Unpack a tar file */
-int
-unpack(char *pkg, char *flist)
-{
- char args[10], suff[80], *cp;
-
- args[0] = '\0';
- /*
- * Figure out by a crude heuristic whether this or not this is probably
- * compressed.
- */
- if (strcmp(pkg, "-")) {
- cp = strrchr(pkg, '.');
- if (cp) {
- strlcpy(suff, cp + 1, sizeof(suff));
- if (strchr(suff, 'z') || strchr(suff, 'Z'))
- strlcpy(args, "-z", sizeof(args));
- }
- }
- else
- strlcpy(args, "z", sizeof(args));
- strlcat(args, "xpf", sizeof(args));
- if (vsystem("tar %s %s %s", args, pkg, flist ? flist : "")) {
- pwarnx("tar extract of %s failed!", pkg);
- return 1;
- }
- return 0;
-}
-
-/*
- * Using fmt, replace all instances of:
- *
- * %F With the parameter "name"
- * %D With the parameter "dir"
- * %B Return the directory part ("base") of %D/%F
- * %f Return the filename part of %D/%F
- *
- */
-int
-format_cmd(char *buf, size_t size, const char *fmt,
- const char *dir, const char *name)
-{
- char *pos;
- size_t len;
-
- while (*fmt != 0 && size != 0) {
- if (*fmt == '%') {
- switch(fmt[1]) {
- case 'f':
- if (name == NULL)
- return 0;
- pos = strrchr(name, '/');
- if (pos != NULL) {
- pos++;
- len = strlen(name) - (pos-name);
- if (len >= size)
- return 0;
- memcpy(buf, pos, len);
- buf += len;
- size -= len;
- fmt += 2;
- continue;
- }
- /* FALLTHRU */
- case 'F':
- if (name == NULL)
- return 0;
- len = strlen(name);
- if (len >= size)
- return 0;
- memcpy(buf, name, len);
- buf += len;
- size -= len;
- fmt += 2;
- continue;
- case 'D':
- if (dir == NULL)
- return 0;
- len = strlen(dir);
- if (len >= size)
- return 0;
- memcpy(buf, dir, len);
- buf += len;
- size -= len;
- fmt += 2;
- continue;
- case 'B':
- if (dir == NULL || name == NULL)
- return 0;
- len = strlen(dir);
- if (len >= size)
- return 0;
- memcpy(buf, dir, len);
- buf += len;
- size -= len;
- if ((pos = strrchr(name, '/')) != NULL) {
- *buf++ = '/';
- size--;
- if (pos - name >= size)
- return 0;
- memcpy(buf, name, pos-name);
- buf += pos-name;
- size -= pos-name;
- }
- fmt += 2;
- continue;
- case '%':
- fmt++;
- default:
- break;
-
- }
- }
- *buf++ = *fmt++;
- size--;
- }
- if (size == 0)
- return 0;
- else
- *buf = '\0';
- return 1;
-}
diff --git a/usr.sbin/pkg_install/lib/global.c b/usr.sbin/pkg_install/lib/global.c
deleted file mode 100644
index 06162e21416..00000000000
--- a/usr.sbin/pkg_install/lib/global.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* $OpenBSD: global.c,v 1.5 2003/07/04 17:31:19 avsm Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: global.c,v 1.5 2003/07/04 17:31:19 avsm Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
-
- * 18 July 1993
- *
- * Semi-convenient place to stick some needed globals.
- *
- */
-
-#include "lib.h"
-
-/* These are global for all utils */
-Boolean Verbose = FALSE;
-Boolean Fake = FALSE;
-Boolean Force = FALSE;
-
-
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
deleted file mode 100644
index 67ebf7f442b..00000000000
--- a/usr.sbin/pkg_install/lib/lib.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/* $OpenBSD: lib.h,v 1.14 2003/08/21 20:24:57 espie Exp $ */
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Include and define various things wanted by the library routines.
- *
- */
-
-#ifndef _INST_LIB_LIB_H_
-#define _INST_LIB_LIB_H_
-
-/* Includes */
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-
-#include <ctype.h>
-#include <dirent.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-
-/* Macros */
-#define SUCCESS (0)
-#define FAIL (-1)
-
-#ifndef TRUE
-#define TRUE (1)
-#endif
-
-#ifndef FALSE
-#define FALSE (0)
-#endif
-
-#define YES 2
-#define NO 1
-
-/* Usually "rm", but often "echo" during debugging! */
-#define REMOVE_CMD "rm"
-
-/* Usually "rm", but often "echo" during debugging! */
-#define RMDIR_CMD "rmdir"
-
-/* Where we put logging information by default, else ${PKG_DBDIR} if set */
-#define DEF_LOG_DIR "/var/db/pkg"
-/* just in case we change the environment variable name */
-#define PKG_DBDIR "PKG_DBDIR"
-
-/* The names of our "special" files */
-#define CONTENTS_FNAME "+CONTENTS"
-#define COMMENT_FNAME "+COMMENT"
-#define DESC_FNAME "+DESC"
-#define INSTALL_FNAME "+INSTALL"
-#define DEINSTALL_FNAME "+DEINSTALL"
-#define REQUIRE_FNAME "+REQUIRE"
-#define REQUIRED_BY_FNAME "+REQUIRED_BY"
-#define DISPLAY_FNAME "+DISPLAY"
-#define MTREE_FNAME "+MTREE_DIRS"
-
-#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
-
-/* The name of the "prefix" environment variable given to scripts */
-#define PKG_PREFIX_VNAME "PKG_PREFIX"
-
-/* maximum size of comment that will fit on one line */
-#ifndef MAXINDEXSIZE
-#define MAXINDEXSIZE 60
-#endif
-
-/* enumerated constants for plist entry types */
-typedef enum pl_ent_t {
- PLIST_SHOW_ALL = -1,
- PLIST_FILE,
- PLIST_CWD,
- PLIST_CMD,
- PLIST_CHMOD,
- PLIST_CHOWN,
- PLIST_CHGRP,
- PLIST_COMMENT,
- PLIST_IGNORE,
- PLIST_NAME,
- PLIST_UNEXEC,
- PLIST_SRC,
- PLIST_DISPLAY,
- PLIST_PKGDEP,
- PLIST_MTREE,
- PLIST_DIR_RM,
- PLIST_OPTION,
- PLIST_PKGCFL,
- PLIST_EXTRA,
- PLIST_EXTRAUNEXEC,
- PLIST_NEWDEP,
- PLIST_LIBDEP
-} pl_ent_t;
-
-/* Types */
-typedef unsigned int Boolean;
-
-/* this structure describes a packing list entry */
-typedef struct plist_t {
- struct plist_t *prev; /* previous entry */
- struct plist_t *next; /* next entry */
- char *name; /* name of entry */
- Boolean marked; /* whether entry has been marked */
- pl_ent_t type; /* type of entry */
-} plist_t;
-
-/* this structure describes a package's complete packing list */
-typedef struct package_t {
- plist_t *head; /* head of list */
- plist_t *tail; /* tail of list */
-} package_t;
-
-enum {
- ChecksumLen = 16,
- LegibleChecksumLen = 33
-};
-
-/* type of function to be handed to findmatchingname; return value of this
- * is currently ignored */
-typedef int (*matchfn)(const char *found, char *data, int len);
-
-/* Prototypes */
-/* Misc */
-int vsystem(const char *, ...);
-void cleanup(int);
-char *make_playpen(char *, size_t, size_t);
-char *where_playpen(void);
-void leave_playpen(char *);
-off_t min_free(char *);
-void save_dirs(char **c, char **p);
-void restore_dirs(char *c, char *p);
-
-/* String */
-char *get_dash_string(char **);
-char *copy_string(char *);
-Boolean suffix(char *, char *);
-void nuke_suffix(char *);
-void str_lowercase(char *);
-char *basename_of(char *);
-char *dirname_of(const char *);
-char *strconcat(char *, char *);
-int pmatch(const char *, const char *);
-int findmatchingname(const char *, const char *, matchfn, char *, int); /* doesn't really belong here */
-char *findbestmatchingname(const char *, const char *); /* neither */
-int ispkgpattern(const char *);
-char *strnncpy(char *to, size_t tosize, char *from, size_t cc);
-
-/* File */
-Boolean fexists(const char *);
-Boolean isdir(const char *);
-Boolean islinktodir(const char *);
-Boolean isemptydir(const char *fname);
-Boolean isemptyfile(const char *fname);
-Boolean isfile(const char *);
-Boolean isURL(const char *);
-char *ensure_tgz(char *);
-char *fileGetURL(char *, char *);
-char *fileURLFilename(char *, char *, int);
-char *fileURLHost(char *, char *, int);
-char *fileFindByPath(char *, char *);
-char *fileGetContents(char *);
-Boolean make_preserve_name(char *, size_t, char *, char *);
-void write_file(char *, char *);
-void copy_file(char *, char *, char *);
-void move_file(char *, char *, char *);
-void copy_hierarchy(char *, char *, Boolean);
-int delete_hierarchy(char *, Boolean, Boolean);
-int unpack(char *, char *);
-int format_cmd(char *, size_t , const char *, const char *,
- const char *);
-
-/* Packing list */
-plist_t *new_plist_entry(void);
-plist_t *last_plist(package_t *);
-plist_t *find_plist(package_t *, pl_ent_t);
-char *find_plist_option(package_t *, char *name);
-void plist_delete(package_t *, Boolean, pl_ent_t, char *);
-void free_plist(package_t *);
-void mark_plist(package_t *);
-void csum_plist_entry(char *, plist_t *);
-void add_plist(package_t *, pl_ent_t, char *);
-void add_plist_top(package_t *, pl_ent_t, char *);
-void delete_plist(package_t *pkg, Boolean all, pl_ent_t type, char *name);
-void write_plist(package_t *, FILE *);
-void read_plist(package_t *, FILE *);
-int plist_cmd(char *, char **);
-int delete_package(Boolean, Boolean, Boolean, Boolean, package_t *);
-
-/* For all */
-int pkg_perform(char **);
-
-
-void set_pkg(char *);
-void pwarnx(const char *, ...);
-void pwarn(const char *, ...);
-
-/* Externs */
-extern Boolean Verbose;
-extern Boolean Fake;
-extern Boolean Force;
-
-#endif /* _INST_LIB_LIB_H_ */
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
deleted file mode 100644
index 86f8657e9f6..00000000000
--- a/usr.sbin/pkg_install/lib/pen.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/* $OpenBSD: pen.c,v 1.13 2003/07/04 17:31:19 avsm Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: pen.c,v 1.13 2003/07/04 17:31:19 avsm Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Routines for managing the "play pen".
- *
- */
-
-#include <err.h>
-#include "lib.h"
-#include <sys/signal.h>
-#include <sys/param.h>
-#include <sys/mount.h>
-#include <errno.h>
-
-/* For keeping track of where we are */
-static char Current[FILENAME_MAX];
-static char Previous[FILENAME_MAX];
-
-/* Backup Current and Previous into temp. strings that are later
- * restored & freed by restore_dirs
- * This is to make nested calls to makeplaypen/leave_playpen work
- */
-void
-save_dirs(char **c, char **p)
-{
- *c=strdup(Current);
- *p=strdup(Previous);
-}
-
-/* Restore Current and Previous from temp strings that were created
- * by safe_dirs.
- * This is to make nested calls to makeplaypen/leave_playpen work
- */
-void
-restore_dirs(char *c, char *p)
-{
- strlcpy(Current, c, sizeof(Current)); free(c);
- strlcpy(Previous, p, sizeof(Previous)); free(p);
-}
-
-char *
-where_playpen(void)
-{
- return Current;
-}
-
-/* Find a good place to play. */
-static char *
-find_play_pen(char *pen, size_t pensize, size_t sz)
-{
- char *cp;
- struct stat sb;
-
- if (pen[0] && stat(pen, &sb) != FAIL && (min_free(pen) >= sz))
- return pen;
- else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
- (void) snprintf(pen, pensize, "%s/instmp.XXXXXXXXXX", cp);
- else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
- (void) snprintf(pen, pensize, "%s/instmp.XXXXXXXXXX", cp);
- else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz)
- strlcpy(pen, "/var/tmp/instmp.XXXXXXXXXX", pensize);
- else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz)
- strlcpy(pen, "/tmp/instmp.XXXXXXXXXX", pensize);
- else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
- strlcpy(pen, "/usr/tmp/instmp.XXXXXXXXXX", pensize);
- else {
- cleanup(0);
- errx(2,
-"can't find enough temporary space to extract the files, please set your\n"
-"PKG_TMPDIR environment variable to a location with at least %lu bytes\n"
-"free", (u_long)sz);
- return NULL;
- }
- return pen;
-}
-
-/*
- * Make a temporary directory to play in and chdir() to it, returning
- * pathname of previous working directory.
- */
-char *
-make_playpen(char *pen, size_t pensize, size_t sz)
-{
- if (!find_play_pen(pen, pensize, sz))
- return NULL;
-
- if (!mkdtemp(pen)) {
- cleanup(0);
- errx(2, "can't mkdtemp '%s'", pen);
- }
- if (Verbose) {
- if (sz)
- fprintf(stderr, "Requested space: %lu bytes, free space: %qd bytes in %s\n", (u_long)sz, (long long)min_free(pen), pen);
- }
- if (min_free(pen) < sz) {
- rmdir(pen);
- cleanup(0);
- errx(2, "not enough free space to create '%s'.\n"
- "Please set your PKG_TMPDIR environment variable to a location\n"
- "with more space and\ntry the command again", pen);
- }
- if (Current[0])
- strlcpy(Previous, Current, sizeof(Previous));
- else if (!getcwd(Previous, FILENAME_MAX)) {
- cleanup(0);
- err(1, "fatal error during execution: getcwd");
- }
- if (chdir(pen) == FAIL) {
- cleanup(0);
- errx(2, "can't chdir to '%s'", pen);
- }
- strlcpy(Current, pen, sizeof(Current));
- return Previous;
-}
-
-/* Convenience routine for getting out of playpen */
-void
-leave_playpen(char *save)
-{
- int save_errno = errno;
- void (*oldsig)(int);
-
- /* XXX big signal race! */
- /* Don't interrupt while we're cleaning up */
- oldsig = signal(SIGINT, SIG_IGN);
- if (Previous[0] && chdir(Previous) == FAIL) {
- cleanup(0); /* XXX */
- warnx("can't chdir back to '%s'", Previous);
- _exit(2);
- } else if (Current[0] && strcmp(Current, Previous)) {
- if (strcmp(Current,"/")==0) {
- fprintf(stderr,"PANIC: About to rm -rf / (not doing so, aborting)\n");
- abort(); /* XXX is abort safe? */
- }
- if (vsystem("rm -rf %s", Current))
- pwarnx("couldn't remove temporary dir '%s'", Current);
- strlcpy(Current, Previous, sizeof(Current)); /* XXX */
- }
- if (save)
- strlcpy(Previous, save, sizeof(Previous)); /* XXX */
- else
- Previous[0] = '\0';
- signal(SIGINT, oldsig);
- errno = save_errno;
-}
-
-off_t
-min_free(char *tmpdir)
-{
- struct statfs buf;
-
- if (statfs(tmpdir, &buf) != 0) {
- warn("statfs");
- return -1;
- }
- return (off_t)buf.f_bavail * (off_t)buf.f_bsize;
-}
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
deleted file mode 100644
index 0098aeecc10..00000000000
--- a/usr.sbin/pkg_install/lib/plist.c
+++ /dev/null
@@ -1,499 +0,0 @@
-/* $OpenBSD: plist.c,v 1.17 2003/08/21 20:24:57 espie Exp $ */
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: plist.c,v 1.17 2003/08/21 20:24:57 espie Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * General packing list routines.
- *
- */
-
-#include "lib.h"
-#include <err.h>
-#include <md5.h>
-
-/* this struct defines a plist command type */
-typedef struct cmd_t {
- char *c_s; /* string to recognise */
- pl_ent_t c_type; /* type of command */
- int c_argc; /* # of arguments */
-} cmd_t;
-
-/* commands to recognise */
-static cmd_t cmdv[] = {
- { "cwd", PLIST_CWD, 1 },
- { "src", PLIST_SRC, 1 },
- { "cd", PLIST_CWD, 1 },
- { "exec", PLIST_CMD, 1 },
- { "unexec", PLIST_UNEXEC, 1 },
- { "mode", PLIST_CHMOD, 1 },
- { "owner", PLIST_CHOWN, 1 },
- { "group", PLIST_CHGRP, 1 },
- { "comment", PLIST_COMMENT, 1 },
- { "ignore", PLIST_IGNORE, 0 },
- { "name", PLIST_NAME, 1 },
- { "display", PLIST_DISPLAY, 1 },
- { "pkgdep", PLIST_PKGDEP, 1 },
- { "pkgcfl", PLIST_PKGCFL, 1 },
- { "mtree", PLIST_MTREE, 1 },
- { "dirrm", PLIST_DIR_RM, 1 },
- { "option", PLIST_OPTION, 1 },
- { "newdepend", PLIST_NEWDEP, 1 },
- { "libdepend", PLIST_LIBDEP, 1 },
- { "extra", PLIST_EXTRA, 1 },
- { "extraunexec", PLIST_EXTRAUNEXEC, 1 },
- { NULL, FAIL, 0 }
-};
-
-static void delete_files(const char *);
-
-/* Add an item to the end of a packing list */
-void
-add_plist(package_t *p, pl_ent_t type, char *arg)
-{
- plist_t *tmp;
-
- tmp = new_plist_entry();
- tmp->name = copy_string(arg);
- tmp->type = type;
- if (!p->head) {
- p->head = p->tail = tmp;
- } else {
- tmp->prev = p->tail;
- p->tail->next = tmp;
- p->tail = tmp;
- }
-}
-
-/* add an item to the start of a packing list */
-void
-add_plist_top(package_t *p, pl_ent_t type, char *arg)
-{
- plist_t *tmp;
-
- tmp = new_plist_entry();
- tmp->name = copy_string(arg);
- tmp->type = type;
- if (!p->head) {
- p->head = p->tail = tmp;
- } else {
- tmp->next = p->head;
- p->head->prev = tmp;
- p->head = tmp;
- }
-}
-
-/* Return the last (most recent) entry in a packing list */
-plist_t *
-last_plist(package_t *p)
-{
- return p->tail;
-}
-
-/* Mark all items in a packing list to prevent iteration over them */
-void
-mark_plist(package_t *pkg)
-{
- plist_t *pp;
-
- for (pp = pkg->head ; pp ; pp = pp->next) {
- pp->marked = TRUE;
- }
-}
-
-/* Find a given item in a packing list and, if so, return it (else NULL) */
-plist_t *
-find_plist(package_t *pkg, pl_ent_t type)
-{
- plist_t *pp;
-
- for (pp = pkg->head ; pp && pp->type != type ; pp = pp->next) {
- }
- return pp;
-}
-
-/* Look for a specific boolean option argument in the list */
-char *
-find_plist_option(package_t *pkg, char *name)
-{
- plist_t *p;
-
- for (p = pkg->head ; p ; p = p->next) {
- if (p->type == PLIST_OPTION && strcmp(p->name, name) == 0) {
- return p->name;
- }
- }
- return (char *) NULL;
-}
-
-/*
- * Delete plist item 'type' in the list (if 'name' is non-null, match it
- * too.) If 'all' is set, delete all items, not just the first occurance.
- */
-void
-delete_plist(package_t *pkg, Boolean all, pl_ent_t type, char *name)
-{
- plist_t *p = pkg->head;
-
- while (p) {
- plist_t *pnext = p->next;
-
- if (p->type == type && (!name || !strcmp(name, p->name))) {
- free(p->name);
- if (p->prev)
- p->prev->next = pnext;
- else
- pkg->head = pnext;
- if (pnext)
- pnext->prev = p->prev;
- else
- pkg->tail = p->prev;
- free(p);
- if (!all)
- return;
- p = pnext;
- }
- else
- p = p->next;
- }
-}
-
-/* Allocate a new packing list entry */
-plist_t *
-new_plist_entry(void)
-{
- plist_t *ret;
-
- if ((ret = (plist_t *)malloc(sizeof(plist_t))) == (plist_t *) NULL) {
- err(1, "can't allocate %d bytes", sizeof(plist_t));
- }
- memset(ret, 0, sizeof(plist_t));
- return ret;
-}
-
-/* Free an entire packing list */
-void
-free_plist(package_t *pkg)
-{
- plist_t *p = pkg->head;
-
- while (p) {
- plist_t *p1 = p->next;
-
- free(p->name);
- free(p);
- p = p1;
- }
- pkg->head = pkg->tail = NULL;
-}
-
-/*
- * For an ascii string denoting a plist command, return its code and
- * optionally its argument(s)
- */
-int
-plist_cmd(char *s, char **arg)
-{
- cmd_t *cmdp;
- char cmd[FILENAME_MAX + 20]; /* 20 == fudge for max cmd len */
- char *cp;
- char *sp;
-
- (void) strlcpy(cmd, s, sizeof(cmd));
- str_lowercase(cmd);
- for (cp = cmd, sp = s ; *cp ; cp++, sp++) {
- if (isspace(*cp)) {
- for (*cp = '\0'; isspace(*sp) ; sp++) {
- }
- break;
- }
- }
- if (arg) {
- *arg = sp;
- }
- for (cmdp = cmdv ; cmdp->c_s && strcmp(cmdp->c_s, cmd) != 0 ; cmdp++) {
- }
- return cmdp->c_type;
-}
-
-/* Read a packing list from a file */
-void
-read_plist(package_t *pkg, FILE *fp)
-{
- char *cp, pline[FILENAME_MAX];
- int cmd;
-
- while (fgets(pline, FILENAME_MAX, fp)) {
- int len = strlen(pline);
-
- while (len && isspace(pline[len - 1]))
- pline[--len] = '\0';
- if (!len)
- continue;
- cp = pline;
- if (pline[0] == CMD_CHAR) {
- cmd = plist_cmd(pline + 1, &cp);
- if (cmd == FAIL) {
- pwarnx("Unrecognised PLIST command `%s'", pline);
- continue;
- }
- if (*cp == '\0')
- cp = NULL;
- }
- else
- cmd = PLIST_FILE;
- add_plist(pkg, cmd, cp);
- }
-}
-
-/* Write a packing list to a file, converting commands to ascii equivs */
-void
-write_plist(package_t *pkg, FILE *fp)
-{
- plist_t *p;
- cmd_t *cmdp;
-
- for (p = pkg->head ; p ; p = p->next) {
- if (p->type == PLIST_FILE) {
- /* Fast-track files - these are the most common */
- (void) fprintf(fp, "%s\n", p->name);
- continue;
- }
- for (cmdp = cmdv ; cmdp->c_type != FAIL && cmdp->c_type != p->type ; cmdp++) {
- }
- if (cmdp->c_type == FAIL) {
- pwarnx("Unknown PLIST command type %d (%s)", p->type, p->name);
- } else if (cmdp->c_argc == 0) {
- (void) fprintf(fp, "%c%s\n", CMD_CHAR, cmdp->c_s);
- } else {
- (void) fprintf(fp, "%c%s %s\n", CMD_CHAR, cmdp->c_s,
- (p->name) ? p->name : "");
- }
- }
-}
-
-/*
- * Delete the results of a package installation.
- *
- * This is here rather than in the pkg_delete code because pkg_add needs to
- * run it too in cases of failure.
- */
-int
-delete_package(Boolean ign_err, Boolean nukedirs, Boolean remove_config,
- Boolean check_md5, package_t *pkg)
-{
- plist_t *p;
- char *Where = ".", *last_file = "";
- int fail = SUCCESS;
- char tmp[FILENAME_MAX], *name = NULL;
-
- for (p = pkg->head; p; p = p->next) {
- switch (p->type) {
- case PLIST_NAME:
- name = p->name;
- break;
-
- case PLIST_IGNORE:
- p = p->next;
- break;
-
- case PLIST_CWD:
- Where = p->name;
- if (Verbose)
- printf("Change working directory to %s\n", Where);
- break;
-
- case PLIST_EXTRAUNEXEC:
- if (!remove_config)
- break;
- /*FALLTHRU*/
- case PLIST_UNEXEC:
- if (!format_cmd(tmp, sizeof(tmp), p->name, Where, last_file)) {
- pwarnx("unexec command `%s' could not expand", p->name);
- fail = FAIL;
- } else {
- if (Verbose)
- printf("Execute `%s'\n", tmp);
- if (!Fake && system(tmp)) {
- pwarnx("unexec command for `%s' failed", tmp);
- fail = FAIL;
- }
- }
- break;
-
- case PLIST_FILE:
- last_file = p->name;
- (void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
- if (isdir(tmp)) {
- pwarnx("attempting to delete directory `%s' as a file\n"
- "this packing list is incorrect - ignoring delete request", tmp);
- }
- else {
- if (check_md5 && p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
- char *cp, buf[LegibleChecksumLen];
-
- if ((cp = MD5File(tmp, buf)) != NULL) {
- /* Mismatch? */
- if (strcmp(cp, p->next->name + 4)) {
- printf("%s fails original MD5 checksum - %s\n",
- tmp, Force ? "deleted anyway." : "not deleted.");
- if (!Force) {
- fail = FAIL;
- continue;
- }
- }
- }
- }
- if (Verbose)
- printf("Delete file %s\n", tmp);
- if (!Fake) {
- if (delete_hierarchy(tmp, ign_err, nukedirs))
- fail = FAIL;
- }
- }
- break;
-
- case PLIST_EXTRA:
- if (!remove_config)
- break;
- if (!p->name)
- break;
- if (p->name[0] == '/')
- delete_files(p->name);
- else {
- (void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
- delete_files(tmp);
- }
- break;
- case PLIST_DIR_RM:
- (void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
- if (!isdir(tmp)) {
- if (fexists(tmp)) {
- pwarnx("attempting to delete file `%s' as a directory\n"
- "this packing list is incorrect - ignoring delete request", tmp);
- } else {
- pwarnx("attempting to delete non-existent directory `%s'\n"
- "this packing list is incorrect - ignoring delete request", tmp);
- }
- }
- else {
- if (Verbose)
- printf("Delete directory %s\n", tmp);
- if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
- pwarnx("unable to completely remove directory '%s'", tmp);
- fail = FAIL;
- }
- }
- last_file = p->name;
- break;
- default:
- break;
- }
- }
- return fail;
-}
-
-#ifdef DEBUG
-#define RMDIR(dir) vsystem("%s %s", RMDIR_CMD, dir)
-#define REMOVE(dir,ie) vsystem("%s %s%s", REMOVE_CMD, (ie ? "-f " : ""), dir)
-#else
-#define RMDIR rmdir
-#define REMOVE(file,ie) (remove(file) && !(ie))
-#endif
-
-/* Selectively delete a hierarchy */
-int
-delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
-{
- char *cp1, *cp2;
-
- cp1 = cp2 = dir;
- if (!fexists(dir)) {
- if (!ign_err)
- pwarnx("%s `%s' doesn't really exist",
- isdir(dir) ? "directory" : "file", dir);
- return !ign_err;
- }
- else if (nukedirs) {
- if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
- return 1;
- }
- else if (isdir(dir)) {
- if (RMDIR(dir) && !ign_err)
- return 1;
- }
- else {
- if (REMOVE(dir, ign_err))
- return 1;
- }
-
- if (!nukedirs)
- return 0;
- while (cp2) {
- if ((cp2 = strrchr(cp1, '/')) != NULL)
- *cp2 = '\0';
- if (!isemptydir(dir))
- return 0;
- if (RMDIR(dir) && !ign_err) {
- if (!fexists(dir))
- pwarnx("directory `%s' doesn't really exist", dir);
- else
- return 1;
- }
- /* back up the pathname one component */
- if (cp2) {
- cp1 = dir;
- }
- }
- return 0;
-}
-
-static void
-delete_files(const char *fname)
-{
- size_t len;
- Boolean b;
-
- len = strlen(fname);
- if (len == 0) {
- pwarnx("empty extra file");
- return;
- }
- /* don't warn if stuff does not exist */
- if (!fexists(fname))
- return;
-
- b = isdir(fname);
- if (fname[len-1] == '/') {
- if (b) {
- if (rmdir(fname) == -1)
- pwarn("problem removing directory %s",
- fname);
- } else {
- pwarnx("extra directory %s is not a directory",
- fname);
- }
- } else {
- if (b) {
- pwarnx("extra file %s is a directory", fname);
- } else {
- if (unlink(fname) == -1)
- pwarn("problem removing %s", fname);
- }
- }
-}
diff --git a/usr.sbin/pkg_install/lib/pwarnx.c b/usr.sbin/pkg_install/lib/pwarnx.c
deleted file mode 100644
index 439fa2b195b..00000000000
--- a/usr.sbin/pkg_install/lib/pwarnx.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/* $OpenBSD: pwarnx.c,v 1.4 2003/08/21 20:24:57 espie Exp $ */
-
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include "lib.h"
-
-static char pkgname[60];
-
-void
-set_pkg(name)
- char *name;
-{
-
- char *name2;
-
- if (name != NULL) {
- size_t len;
-
- len = strlen(name);
- while (len != 0 && name[len-1] == '/')
- name[--len] = '\0';
-
- name2 = strrchr(name, '/');
- if (name2 != NULL)
- name = name2+1;
- strlcpy(pkgname, name, sizeof pkgname);
- name2 = strstr(pkgname, ".tgz");
- if (name2 != NULL && name2[4] == '\0')
- *name2 = '\0';
- } else
- pkgname[0] = '\0';
-}
-
-
-extern char *__progname;
-
-void
-pwarnx(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
-
- if (pkgname[0] == '\0')
- (void)fprintf(stderr, "%s: ", __progname);
- else
- (void)fprintf(stderr, "%s(%s): ", __progname, pkgname);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
- va_end(ap);
-}
-
-void
-pwarn(const char *fmt, ...)
-{
- va_list ap;
- int sverrno;
-
- sverrno = errno;
- va_start(ap, fmt);
-
- if (pkgname[0] == '\0')
- (void)fprintf(stderr, "%s: ", __progname);
- else
- (void)fprintf(stderr, "%s(%s): ", __progname, pkgname);
- if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
- (void)fprintf(stderr, "\n");
- va_end(ap);
-}
diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c
deleted file mode 100644
index d3a264819de..00000000000
--- a/usr.sbin/pkg_install/lib/str.c
+++ /dev/null
@@ -1,366 +0,0 @@
-/* $OpenBSD: str.c,v 1.11 2003/07/04 17:31:19 avsm Exp $ */
-
-#ifndef lint
-static const char rcsid[] = "$OpenBSD: str.c,v 1.11 2003/07/04 17:31:19 avsm Exp $";
-#endif
-
-/*
- * FreeBSD install - a package for the installation and maintainance
- * of non-core utilities.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Jordan K. Hubbard
- * 18 July 1993
- *
- * Miscellaneous string utilities.
- *
- */
-
-#include <err.h>
-#include <fnmatch.h>
-#include "lib.h"
-
-/* Return the filename portion of a path */
-char *
-basename_of(char *str)
-{
- char *slash;
-
- return ((slash = strrchr(str, '/')) == (char *) NULL) ? str : slash + 1;
-}
-
-/* Return the dirname portion of a path */
-char *
-dirname_of(const char *path)
-{
- size_t cc;
- char *s;
- char *t;
-
- if ((s = strrchr(path, '/')) == (char *) NULL) {
- return ".";
- }
- if (s == path) {
- /* "/foo" -> return "/" */
- return "/";
- }
- cc = (size_t)(s - path) + 1;
- if ((t = (char *) malloc(cc)) == (char *) NULL) {
- errx(1, "out of memory in dirname_of");
- }
- (void) memcpy(t, path, cc);
- t[cc] = 0;
- return t;
-}
-
-char *
-strconcat(char *s1, char *s2)
-{
- static char tmp[FILENAME_MAX];
-
- strlcpy(tmp, s1 ? s1 : s2, sizeof(tmp));
- if (s1 && s2)
- strlcat(tmp, s2, sizeof(tmp));
- return tmp;
-}
-
-/* Get a string parameter as a file spec or as a "contents follow -" spec */
-char *
-get_dash_string(char **str)
-{
- char *s = *str;
-
- if (*s == '-')
- *str = copy_string(s + 1);
- else
- *str = fileGetContents(s);
- return *str;
-}
-
-/* Rather Obvious */
-char *
-copy_string(char *str)
-{
- char *ret;
-
- if (!str)
- ret = NULL;
- else {
- ret = strdup(str);
- }
- return ret;
-}
-
-/* Return TRUE if 'str' ends in suffix 'suff' */
-Boolean
-suffix(char *str, char *suff)
-{
- char *idx;
- Boolean ret = FALSE;
-
- idx = strrchr(str, '.');
- if (idx && !strcmp(idx + 1, suff))
- ret = TRUE;
- return ret;
-}
-
-/* Assuming str has a suffix, brutally murder it! */
-void
-nuke_suffix(char *str)
-{
- char *idx;
-
- idx = strrchr(str, '.');
- if (idx)
- *idx = '\0'; /* Yow! Don't try this on a const! */
-}
-
-/* Lowercase a whole string */
-void
-str_lowercase(char *str)
-{
- while (*str) {
- *str = tolower(*str);
- ++str;
- }
-}
-
-
-enum deweycmp_ops {
- GT,
- GE,
- LT,
- LE
-};
-
-/* compare two dewey decimal numbers */
-static int
-deweycmp(char *a, enum deweycmp_ops op, char *b)
-{
- int ad;
- int bd;
- int cmp;
-
- for (;;) {
- if (*a == 0 && *b == 0) {
- cmp = 0;
- break;
- }
- ad = bd = 0;
- for (; *a && *a != '.'; a++) {
- ad = (ad * 10) + (*a - '0');
- }
- for (; *b && *b != '.'; b++) {
- bd = (bd * 10) + (*b - '0');
- }
- if ((cmp = ad - bd) != 0) {
- break;
- }
- if (*a == '.') {
- a++;
- }
- if (*b == '.') {
- b++;
- }
- }
- return (op == GE) ? cmp >= 0 : (op == GT) ? cmp > 0 : (op == LE) ? cmp <= 0 : cmp < 0;
-}
-
-/* perform alternate match on "pkg" against "pattern", */
-/* calling pmatch (recursively) to resolve any other patterns */
-/* return 1 on match, 0 otherwise */
-static int
-alternate_match(const char *pattern, const char *pkg)
-{
- char *sep;
- char buf[FILENAME_MAX];
- char *last;
- char *alt;
- char *cp;
- int cnt;
- int found;
-
- if ((sep = strchr(pattern, '{')) == (char *) NULL) {
- errx(1, "alternate_match(): '{' expected in \"%s\"", pattern);
- }
- (void) strncpy(buf, pattern, (size_t)(sep - pattern));
- alt = &buf[sep - pattern];
- last = (char *) NULL;
- for (cnt = 0, cp = sep; *cp && last == (char *) NULL ; cp++) {
- if (*cp == '{') {
- cnt++;
- } else if (*cp == '}' && --cnt == 0 && last == (char *) NULL) {
- last = cp + 1;
- }
- }
- if (cnt != 0) {
- pwarnx("Malformed alternate `%s'", pattern);
- return 1;
- }
- for (found = 0, cp = sep + 1; *sep != '}'; cp = sep + 1) {
- for (cnt = 0, sep = cp; cnt > 0 || (cnt == 0 && *sep != '}' && *sep != ','); sep++) {
- if (*sep == '{') {
- cnt++;
- } else if (*sep == '}') {
- cnt--;
- }
- }
- (void) snprintf(alt, sizeof(buf) - (alt - buf), "%.*s%s", (int) (sep - cp), cp, last);
- if (pmatch(buf, pkg) == 1) {
- found = 1;
- }
- }
- return found;
-}
-
-/* perform dewey match on "pkg" against "pattern" */
-/* return 1 on match, 0 otherwise */
-static int
-dewey_match(const char *pattern, const char *pkg)
-{
- char *cp;
- char *sep;
- char *ver;
- int found;
- enum deweycmp_ops op;
- int n;
- char name[FILENAME_MAX];
-
- found = 0;
- if ((sep = strpbrk(pattern, "<>")) == NULL)
- errx(1, "dewey_match(): '<' or '>' expexted in \"%s\"", pattern);
-
- /* next three lines are static in loops, too (-> cache!) */
- snprintf(name, sizeof(name), "%.*s", (int) (sep - pattern), pattern);
- op = (*sep == '>') ? (*(sep + 1) == '=') ? GE : GT : (*(sep + 1) == '=') ? LE : LT;
- ver = (op == GE || op == LE) ? sep + 2 : sep + 1;
- n = (int)(sep - pattern);
- if ((cp = strrchr(pkg, '-')) != (char *) NULL) {
- if (strncmp(pkg, name, (size_t)(cp - pkg)) == 0 && n == cp - pkg) {
- if (deweycmp(cp + 1, op, ver)) {
- found = 1;
- }
- }
- }
- return found;
-}
-
-/* perform glob match on "pkg" against "pattern" */
-/* return 1 on match, 0 otherwise */
-static int
-glob_match(const char *pattern, const char *pkg)
-{
- return fnmatch(pattern, pkg, FNM_PERIOD) == 0;
-}
-
-/* perform simple match on "pkg" against "pattern" */
-/* return 1 on match, 0 otherwise */
-static int
-simple_match(const char *pattern, const char *pkg)
-{
- return !strcmp(pattern, pkg);
-}
-
-/* match pkg against pattern, return 1 if matching, 0 else */
-/*
- * Optimize: this is called many times in readdir()-loops, where the
- * pattern doesn't change, so the {,} alternates may be unrolles/cached.
- */
-int
-pmatch(const char *pattern, const char *pkg)
-{
- if (strchr(pattern, '{')) {
- /* emulate csh-type alternates */
- return alternate_match(pattern, pkg);
- }
- if (strpbrk(pattern, "<>")) {
- /* perform relational dewey match on version number */
- return dewey_match(pattern, pkg);
- }
- if (strpbrk(pattern, "*?[]")) {
- /* glob match */
- return glob_match(pattern, pkg);
- }
- /* no alternate, dewey or glob match -> simple compare */
- return simple_match(pattern, pkg);
-}
-
-
-/* search dir for pattern, writing the found match in buf */
-/* let's hope there's only one ... - HF */
-/* returns -1 on error, 1 if found, 0 otherwise. */
-int
-findmatchingname(const char *dir, const char *pattern, matchfn f, char *data, int len)
-{
- struct dirent *dp;
- DIR *dirp;
- int found;
-
- found = 0;
- if ((dirp = opendir(dir)) == NULL) {
- /* pwarnx("can't opendir dir '%s'", dir); */
- return -1;
- }
- while ((dp = readdir(dirp)) != NULL) {
- if (strcmp(dp->d_name, ".") == 0 ||
- strcmp(dp->d_name, "..") == 0) {
- continue;
- }
- if (pmatch(pattern, dp->d_name)) {
- if(f)
- f(dp->d_name, data, len);
- found=1;
- }
- }
- closedir(dirp);
-
- return found;
-}
-
-/* does the pkgname contain any of the special chars ("{[]?*<>")? */
-/* if so, return 1, else 0 */
-int
-ispkgpattern(const char *pkg)
-{
- return strpbrk(pkg, "<>[]?*{") != NULL;
-}
-
-/* auxiliary function called by findbestmatchingname() */
-static int
-findbestmatchingname_fn(const char *pkg, char *data, int len)
-{
- /* if pkg > data */
- char *s1, *s2;
-
- s1=strrchr(pkg, '-')+1;
- s2=strrchr(data, '-')+1;
-
- if(data[0] == '\0' || deweycmp(s1, GT, s2))
- strlcpy(data, pkg, len);
-
- return 0;
-}
-
-/* find best matching filename, i.e. the pkg with the highest
- * matching(!) version */
-/* returns pointer to pkg name (which can be free(3)ed),
- * or NULL if no match is available. */
-char *
-findbestmatchingname(const char *dir, const char *pattern)
-{
- char buf[FILENAME_MAX];
-
- buf[0]='\0';
- if (findmatchingname(dir, pattern, findbestmatchingname_fn, buf, sizeof(buf)) > 0 && buf[0] != '\0') {
- return strdup(buf);
- }
- return NULL;
-}
diff --git a/usr.sbin/pkg_install/sign/INSTALL b/usr.sbin/pkg_install/sign/INSTALL
deleted file mode 100644
index bc0a530fcee..00000000000
--- a/usr.sbin/pkg_install/sign/INSTALL
+++ /dev/null
@@ -1,21 +0,0 @@
-These are just bare bones installation instructions.
-
-Normally, `make' should be enough to build these tools.
-A simpler version can be built by using `make check_sign'
-(does not depend on the existence of getpass())
-
-You should define PGP in the Makefile if the default
-(/usr/local/bin/pgp) doesn't apply.
-
-There is no install target, just copy pkg_sign and/or check_sign where
-you want, along with the manpage.
-
-You need to install pgp by yourself. This should be pgp 2.63,
-as these tools won't work with pgp5.
-
-A standard Unix environment is assumed. Common functions such
-as getopt() or strdup() should be obtained from another free software
-package such as libiberty if not available on your platform.
-
-These tools won't work on Unix-lookalike that don't provide fork()
-or popen() without some extensive modifications.
diff --git a/usr.sbin/pkg_install/sign/MANIFEST b/usr.sbin/pkg_install/sign/MANIFEST
deleted file mode 100644
index a02d940c0d6..00000000000
--- a/usr.sbin/pkg_install/sign/MANIFEST
+++ /dev/null
@@ -1,14 +0,0 @@
-INSTALL
-Makefile
-MANIFEST
-README
-check.c
-common.c
-extern.h
-gzip.c
-gzip.h
-main.c
-pgp.h
-pkg_sign.1
-sign.c
-stand.h
diff --git a/usr.sbin/pkg_install/sign/Makefile b/usr.sbin/pkg_install/sign/Makefile
deleted file mode 100644
index 72b2e5c506c..00000000000
--- a/usr.sbin/pkg_install/sign/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-# define PGP to be the path to pgp (default: /usr/local/bin/pgp)
-
-# Use the check_sign target if your system can't handle pipes or getpass
-all: pkg_sign
-
-OBJS=main.o sign.o check.o gzip.o common.o
-OBJS2=varmain.o check.o gzip.o common.o
-
-pkg_sign: $(OBJS)
- ${CC} ${CFLAGS} -o $@ $(OBJS)
-
-check_sign: $(OBJS2)
- ${CC} ${CFLAGS} -o $@ $(OBJS2)
-
-varmain.o: main.c
- ${CC} ${CFLAGS} -DCHECKER_ONLY -o varmain.o -c main.c
-
-clean:
- rm *.o
diff --git a/usr.sbin/pkg_install/sign/Makefile.bsd-wrapper b/usr.sbin/pkg_install/sign/Makefile.bsd-wrapper
deleted file mode 100644
index 5f55dc27dd4..00000000000
--- a/usr.sbin/pkg_install/sign/Makefile.bsd-wrapper
+++ /dev/null
@@ -1,20 +0,0 @@
-# $OpenBSD: Makefile.bsd-wrapper,v 1.2 1999/10/07 16:30:32 espie Exp $
-
-PROG= pkg_sign
-SRCS= main.c sign.c pgp_sign.c
-
-.if exists(${.CURDIR}/../lib/${__objdir})
-LDADD+= -L${.CURDIR}/../lib/${__objdir} -linstall
-DPADD+= ${.CURDIR}/../lib/${__objdir}/libinstall.a
-.else
-LDADD+= -L${.CURDIR}/../lib -linstall
-DPADD+= ${.CURDIR}/../lib/libinstall.a
-.endif
-
-LINKS= ${BINDIR}/pkg_sign ${BINDIR}/check_sign
-MANLINKS=pkg_sign.1 check_sign.1
-
-CLEANFILES=varmain.o
-
-.include <bsd.prog.mk>
-
diff --git a/usr.sbin/pkg_install/sign/README b/usr.sbin/pkg_install/sign/README
deleted file mode 100644
index 952dec5a40a..00000000000
--- a/usr.sbin/pkg_install/sign/README
+++ /dev/null
@@ -1,36 +0,0 @@
-To sign packages in a transparent way:
-gzip files can handle an extra field at the beginning that
-stores anything we wish.
-
-So it's just a question to choose a format for the signature, and to
-embed it there.
-
-We use the extra field to store signatures. Each signature consists
-of a 6 bytes type marker, a 2 bytes length, followed by the signature
-itself. We can potentially stack signatures: resign a signed archive
-by just prepending the new signature to the extra field.
-
-To check the first signature, the checker just needs to extract it, pass it
-off to the checking protocol (e.g. PGP), followed by the unsigned archive
-(e.g., regenerate the gzip header without the first signature, then put
-the gzip data).
-
-* Signed archives just look like normal .tar.gz files, except for programs
-that use the extra field for their own purpose,
-* Possibility to grab the files off the net and extract stuff/verify
-signatures on the fly (just need to wedge the checker as an intermediate
-pipe)
-* Pretty simple, small portable code to be able to check signatures
-everywhere (the signer itself needs getpass and corresponding functionality)
-
-The scheme should be extensible to any compressed format which allows for
-extended headers.
-
-
-Thanks to Angelos D. Keromytis for pointing out I did not need to
-uncompress the archive to sign it, and to other members of the OpenBSD
-project for various reasons.
-
---
- Marc Espie, 1999
- $OpenBSD: README,v 1.2 1999/10/04 21:46:27 espie Exp $
diff --git a/usr.sbin/pkg_install/sign/check.c b/usr.sbin/pkg_install/sign/check.c
deleted file mode 100644
index ba2cf1c89a7..00000000000
--- a/usr.sbin/pkg_install/sign/check.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* $OpenBSD: check.c,v 1.3 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* Simple code for a stand-alone package checker */
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include "stand.h"
-#include "pgp.h"
-#include "gzip.h"
-#include "extern.h"
-
-struct checker {
- void *context;
- void (*add)(void *, const char *, size_t);
- int (*get)(void *);
- int status;
-};
-
-#define MAX_CHECKERS 20
-
-int
-check_signature(file, userid, envp, filename)
- /*@dependent@*/FILE *file;
- const char *userid;
- char *envp[];
- /*@observer@*/const char *filename;
-{
- struct signature *sign;
- struct mygzip_header h;
- int status;
- char buffer[1024];
- size_t length;
- struct checker checker[MAX_CHECKERS];
- struct signature *sweep;
- int i, j;
-
- status = read_header_and_diagnose(file, &h, &sign, filename);
- if (status != 1)
- return PKG_UNSIGNED;
-
- for (sweep = sign, i = 0;
- sweep != NULL && i < MAX_CHECKERS;
- sweep=sweep->next, i++) {
- switch(sweep->type) {
- case TAG_OLD:
- fprintf(stderr, "File %s uses old signatures, no longer supported\n",
- filename);
- checker[i].context = NULL;
- break;
- case TAG_SHA1:
- checker[i].context = new_sha1_checker(&h, sweep, userid, envp, filename);
- checker[i].add = sha1_add;
- checker[i].get = sha1_sign_ok;
- break;
- case TAG_PGP:
- checker[i].context = new_pgp_checker(&h, sweep, userid, envp, filename);
- checker[i].add = pgp_add;
- checker[i].get = pgp_sign_ok;
- break;
- default:
- abort();
- }
- }
- while ((length = fread(buffer, 1, sizeof buffer, file)) > 0)
- for (j = 0; j < i; j++)
- if (checker[j].context)
- (*checker[j].add)(checker[j].context, buffer, length);
-// for (j = i-1; j >= 0; j--)
- for (j = 0; j < i; j++)
- if (checker[j].context)
- checker[j].status = (*checker[j].get)(checker[j].context);
- else
- checker[j].status = PKG_SIGERROR;
- free_signature(sign);
- return checker[0].status;
-}
-
diff --git a/usr.sbin/pkg_install/sign/common.c b/usr.sbin/pkg_install/sign/common.c
deleted file mode 100644
index 4e8cf4fdc80..00000000000
--- a/usr.sbin/pkg_install/sign/common.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/* $OpenBSD: common.c,v 1.4 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "stand.h"
-#include "gzip.h"
-#include "pgp.h"
-#include "extern.h"
-
-/* Ensure consistent diagnostics */
-int
-read_header_and_diagnose(file, h, sign, filename)
- FILE *file;
- struct mygzip_header *h;
- struct signature **sign;
- const char *filename;
-{
- switch(gzip_read_header(file, h, sign)) {
- case GZIP_SIGNED:
- if (sign == NULL) {
- fprintf(stderr, "File %s is already signed\n", filename);
- return 0;
- } else
- return 1;
- case GZIP_UNSIGNED:
- if (sign != NULL) {
- fprintf(stderr, "File %s is not a signed gzip file\n", filename);
- return 0;
- } else
- return 1;
- case GZIP_NOT_GZIP:
- fprintf(stderr, "File %s is not a gzip file\n", filename);
- return 0;
- case GZIP_NOT_PGPSIGNED:
- fprintf(stderr, "File %s contains an unknown extension\n", filename);
- return 0;
- default:
- /* this should not happen */
- abort();
- }
-}
-
-int
-reap(pid)
- pid_t pid;
-{
- int pstat;
- pid_t result;
-
- do {
- result = waitpid(pid, &pstat, 0);
- } while (result == -1 && errno == EINTR);
- return result == -1 ? -1 : pstat;
-}
-
diff --git a/usr.sbin/pkg_install/sign/extern.h b/usr.sbin/pkg_install/sign/extern.h
deleted file mode 100644
index 5c93d2cac17..00000000000
--- a/usr.sbin/pkg_install/sign/extern.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* $OpenBSD: extern.h,v 1.6 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* Convention: all functions that operate on a FILE * also take a filename
- for diagnostic purposes. The file can be connected to a pipe, so
- - don't rewind
- - don't reopen from filename.
- */
-
-struct mygzip_header;
-struct signature;
-
-/* common.c */
-extern int read_header_and_diagnose(FILE *file, \
- /*@out@*/struct mygzip_header *h, /*@null@*/struct signature **sign, \
- const char *filename);
-extern int reap(pid_t pid);
-
-/* sign.c */
-extern int sign(/*@observer@*/const char *filename, int type, \
- /*@null@*/const char *userid, char *envp[]);
-
-/* check.c */
-extern int check_signature(/*@dependent@*/FILE *file, \
- /*@null@*/const char *userid, char *envp[], \
- /*@observer@*/const char *filename);
-
-#define PKG_BADSIG 0
-#define PKG_GOODSIG 1
-#define PKG_UNSIGNED 2
-#define PKG_SIGNED 4
-#define PKG_SIGERROR 8
-#define PKG_SIGUNKNOWN 16
-
-typedef /*@observer@*/char *pchar;
-
-#define MAXID 512
-/* sha1.c */
-#define SHA1_DB_NAME "/var/db/pkg/SHA1"
-
-extern void *new_sha1_checker(struct mygzip_header *h, \
- struct signature *sign, const char *userid, char *envp[], \
- const char *filename);
-
-extern void sha1_add(void *arg, const char *buffer, size_t length);
-
-extern int sha1_sign_ok(void *arg);
-
-extern int retrieve_sha1_marker(const char *filename, \
- struct signature **sign, const char *userid);
diff --git a/usr.sbin/pkg_install/sign/gzip.c b/usr.sbin/pkg_install/sign/gzip.c
deleted file mode 100644
index b230d504a57..00000000000
--- a/usr.sbin/pkg_install/sign/gzip.c
+++ /dev/null
@@ -1,309 +0,0 @@
-/* $OpenBSD: gzip.c,v 1.4 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include "stand.h"
-#include "gzip.h"
-#include "pgp.h"
-
-/* Signatures follow a simple format
- (endianess was chosen to conform to gzip header format)
- */
-
-SIGNTAG known_tags[KNOWN_TAGS] = {
- {'S', 'I', 'G', 'P', 'G', 'P', 0, 0 },
- {'C', 'K', 'S', 'H', 'A', '1', 0, 0 },
- {'S', 'i', 'g', 'P', 'G', 'P', 0, 0 } /* old format */
-};
-
-void
-sign_fill_tag(sign)
- struct signature *sign;
-{
- sign->tag[6] = sign->length % 256;
- sign->tag[7] = sign->length / 256;
-}
-
-void
-sign_fill_length(sign)
- struct signature *sign;
-{
- sign->length = sign->tag[6] + 256 * sign->tag[7];
-}
-
-static size_t
-stack_sign(match, t, f, sign)
- SIGNTAG match;
- int t;
- FILE *f;
- struct signature **sign;
-{
- struct signature *new_sign;
- size_t length;
-
- new_sign = malloc(sizeof *new_sign);
- if (new_sign == NULL)
- return 0;
- new_sign->type = t;
- new_sign->next = NULL;
- memcpy(new_sign->tag, match, sizeof(SIGNTAG));
- sign_fill_length(new_sign);
- new_sign->data = malloc(new_sign->length);
- if (new_sign->data == NULL ||
- fread(new_sign->data, 1, new_sign->length, f) != new_sign->length) {
- free_signature(new_sign);
- return 0;
- }
- length = new_sign->length;
- if (sign != NULL) {
- if (!*sign)
- *sign = new_sign;
- else {
- while ((*sign)->next != NULL)
- sign = &((*sign)->next);
- (*sign)->next = new_sign;
- }
- } else
- free_signature(new_sign);
- return length;
-}
-
-
-static int
-add_sign(f, sign)
- FILE *f;
- struct signature **sign;
-{
- SIGNTAG match;
- int i;
-
- if (fread(match, 1, sizeof(SIGNTAG), f) != sizeof(SIGNTAG))
- return -1;
- for (i = 0; i < KNOWN_TAGS; i++) {
- if (memcmp(match, known_tags[i], TAGCHECK) == 0) {
- unsigned int sign_length = stack_sign(match, i, f, sign);
- if (sign_length > 0)
- return sign_length + sizeof(SIGNTAG);
- else
- return -1;
- }
- }
- return 0;
-}
-
-static int
-gzip_magic(f)
- FILE *f;
-{
- int c, d;
-
- c = fgetc(f);
- d = fgetc(f);
- if ((unsigned char)c != (unsigned char)GZIP_MAGIC0
- || (unsigned char)d != (unsigned char)GZIP_MAGIC1)
- return 0;
- else
- return 1;
-}
-
-static int
-fill_gzip_fields(f, h)
- FILE *f;
- struct mygzip_header *h;
-{
- int method, flags;
-
- method = fgetc(f);
- flags = fgetc(f);
-
- if (method == EOF || flags == EOF || fread(h->stamp, 1, 6, f) != 6)
- return 0;
- h->method = (char)method;
- h->flags = (char)flags;
- if ((h->flags & CONTINUATION) != 0)
- if (fread(h->part, 1, 2, f) != 2)
- return 0;
- return 1;
-}
-
-/* retrieve a gzip header, including signatures */
-int
-gzip_read_header(f, h, sign)
- FILE *f;
- struct mygzip_header *h;
- struct signature **sign;
-{
- if (sign != NULL)
- *sign = NULL;
- if (!gzip_magic(f) || !fill_gzip_fields(f, h))
- return GZIP_NOT_GZIP;
-
- if ((h->flags & EXTRA_FIELD) == 0) {
- h->remaining = 0;
- return GZIP_UNSIGNED;
- }
- else {
- int c;
-
- c = fgetc(f);
- if (c == EOF)
- return GZIP_NOT_GZIP;
- h->remaining = (unsigned)c;
- c = fgetc(f);
- if (c == EOF)
- return GZIP_NOT_PGPSIGNED;
- h->remaining += ((unsigned) c) << 8;
- while (h->remaining >= sizeof(SIGNTAG)) {
- int sign_length = add_sign(f, sign);
- if (sign_length > 0)
- h->remaining -= sign_length;
- if (sign_length < 0)
- return GZIP_NOT_GZIP;
- if (sign_length == 0)
- return GZIP_SIGNED;
- }
- return GZIP_SIGNED;
- }
-}
-
-static unsigned
-sign_length(sign)
- struct signature *sign;
-{
- unsigned total = 0;
-
- while (sign != NULL) {
- total += sizeof(SIGNTAG) + sign->length;
- sign = sign->next;
- }
- return total;
-}
-
-struct mydata {
- FILE *file;
- int ok;
-};
-
-static void myadd(arg, buffer, size)
- void *arg;
- const char *buffer;
- size_t size;
-{
- struct mydata *d = arg;
-
- if (fwrite(buffer, 1, size, d->file) == size)
- d->ok = 1;
- else
- d->ok = 0;
-}
-
-/* write a gzip header, including signatures */
-int
-gzip_write_header(f, h, sign)
- FILE *f;
- const struct mygzip_header *h;
- struct signature *sign;
-{
- struct mydata d;
- d.file = f;
- if (gzip_copy_header(h, sign, myadd, &d) == 0)
- return 0;
- return d.ok;
-}
-
-int
-gzip_copy_header(h, sign, add, data)
- const struct mygzip_header *h;
- struct signature *sign;
- void (*add)(void *, const char *, size_t);
- void *data;
-{
- char flags;
- size_t length;
- size_t buflength;
- size_t i;
- char *buffer;
-
- length = h->remaining + sign_length(sign);
- if (length) {
- buflength = length + 2;
- flags = h->flags | EXTRA_FIELD;
- } else {
- flags = h->flags & ~EXTRA_FIELD;
- buflength = 0;
- }
- buflength += 10;
- if ((h->flags & CONTINUATION) != 0)
- buflength += 2;
-
- buffer = malloc(buflength);
- if (buffer == NULL)
- return 0;
-
- i = 0;
- buffer[i++] = GZIP_MAGIC0;
- buffer[i++] = GZIP_MAGIC1;
- buffer[i++] = h->method;
- buffer[i++] = flags;
- memcpy(buffer+i, h->stamp, 6);
- i += 6;
- if ((flags & CONTINUATION) != 0) {
- memcpy(buffer+i, h->part, 2);
- i += 2;
- }
- if (length) {
- buffer[i++] = (char)(length % 256);
- buffer[i++] = (char)(length / 256);
- while (sign != NULL) {
- memcpy(buffer+i, sign->tag, sizeof(SIGNTAG));
- i += sizeof(SIGNTAG);
- memcpy(buffer+i, sign->data, sign->length);
- i += sign->length;
- sign = sign->next;
- }
- }
- (*add)(data, buffer, buflength);
- free(buffer);
- return 1;
-}
-
-void
-free_signature(sign)
- struct signature *sign;
-{
- struct signature *next;
-
- while (sign != NULL) {
- next = sign->next;
- free(sign->data);
- free(sign);
- sign = next;
- }
-}
diff --git a/usr.sbin/pkg_install/sign/gzip.h b/usr.sbin/pkg_install/sign/gzip.h
deleted file mode 100644
index ed0680fe8e4..00000000000
--- a/usr.sbin/pkg_install/sign/gzip.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* $OpenBSD: gzip.h,v 1.5 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#define GZIP_MAGIC0 '\037'
-#define GZIP_MAGIC1 '\213'
-/* flags values */
-#define CONTINUATION 0x02
-#define EXTRA_FIELD 0x04
-
-/* meaningful fields in a gzip header, see gzip proper for details.
- This structure should not be fiddled with outside of gzip_read_header
- and gzip_write_header
- */
-struct mygzip_header {
- char method;
- char flags;
- char stamp[6];
- char part[2];
- /* remaining extra, after know signs have been read */
- unsigned int remaining;
-};
-
-#define TAGSIZE 8
-#define TAGCHECK 6
-
-typedef unsigned char SIGNTAG[8];
-
-/* stack of signatures */
-struct signature {
- SIGNTAG tag;
- int type;
- int length;
- char *data;
- struct signature *next;
-};
-
-/* returns from gzip_read_header */
-#define GZIP_UNSIGNED 0 /* gzip file, no signature */
-#define GZIP_SIGNED 1 /* gzip file, signature parsed ok */
-#define GZIP_NOT_GZIP 2 /* not a proper gzip file */
-#define GZIP_NOT_PGPSIGNED 3 /* gzip file, unknown extension */
-extern int gzip_read_header(FILE *f, /*@out@*/struct mygzip_header *h, \
- /*@null@*/struct signature **sign);
-/* gzip_write_header returns 1 for success */
-extern int gzip_write_header(FILE *f, const struct mygzip_header *h, \
- /*@null@*/struct signature *sign);
-/* writing header to memory. Returns size needed, or 0 if buffer too small
- buffer must be at least 14 characters */
-extern int gzip_copy_header(const struct mygzip_header *h, \
- /*@null@*/struct signature *sign, \
- void (*add)(void *, const char *, size_t), void *data);
-
-extern void free_signature(/*@null@*/struct signature *sign);
-extern void sign_fill_tag(struct signature *sign);
-#define KNOWN_TAGS 3
-#define TAG_PGP 0
-#define TAG_SHA1 1
-#define TAG_OLD 2
-#define TAG_ANY -1
-#define pgptag (known_tags[TAG_PGP])
-#define sha1tag (known_tags[TAG_SHA1])
-extern SIGNTAG known_tags[KNOWN_TAGS];
diff --git a/usr.sbin/pkg_install/sign/main.c b/usr.sbin/pkg_install/sign/main.c
deleted file mode 100644
index 1deb09d2124..00000000000
--- a/usr.sbin/pkg_install/sign/main.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* $OpenBSD: main.c,v 1.3 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include "stand.h"
-#include "gzip.h"
-#include "pgp.h"
-#include "extern.h"
-
-#ifdef __OpenBSD__
-extern char *__progname;
-#define argv0 __progname
-#else
-static char *argv0;
-#endif
-
-#define NM_SIGN "pkg_sign"
-
-static void
-usage()
-{
- fprintf(stderr, "usage: %s [-sc] [-u userid] pkg1 ...\n", argv0);
- exit(EXIT_FAILURE);
-}
-
-#define SIGN 0
-#define CHECK 1
-
-/* wrapper for the check_signature function (open file if needed) */
-static int
-check(filename, type, userid, envp)
- /*@observer@*/const char *filename;
- int type;
- /*@null@*/const char *userid;
- char *envp[];
-{
- int result;
- FILE *file;
-
- if (strcmp(filename, "-") == 0)
- return check_signature(stdin, userid, envp, "stdin");
- file = fopen(filename, "r");
- if (file == NULL) {
- fprintf(stderr, "Can't open %s\n", filename);
- return 0;
- }
- result = check_signature(file, userid, envp, filename);
- if (fclose(file) == 0) {
- if (result == PKG_BADSIG || result == PKG_SIGERROR)
- return 0;
- else
- return 1;
- } else
- return 0;
-}
-
-int
-main(argc, argv, envp)
- int argc;
- char *argv[];
- char *envp[];
-{
- int success = 1;
- int ch;
- char *userid = NULL;
- int mode;
- int i;
- int type = TAG_ANY;
-
-#ifndef BSD4_4
- set_program_name(argv[0]);
-#endif
-#ifdef CHECKER_ONLY
- mode = CHECK;
-#else
-#ifndef __OpenBSD__
- if ((argv0 = strrchr(argv[0], '/')) != NULL)
- argv0++;
- else
- argv0 = argv[0];
-#endif
- if (strcmp(argv0, NM_SIGN) == 0)
- mode = SIGN;
- else
- mode = CHECK;
-#endif
-
- while ((ch = getopt(argc, argv, "u:t:sc")) != -1) {
- switch(ch) {
- case 't':
- if (strcmp(optarg, "pgp") == 0)
- type = TAG_PGP;
- else if (strcmp(optarg, "sha1") == 0)
- type = TAG_SHA1;
- else
- usage();
- break;
- case 'u':
- userid = strdup(optarg);
- break;
-#ifndef CHECKER_ONLY
- case 's':
- mode = SIGN;
- break;
-#endif
- case 'c':
- mode = CHECK;
- break;
- default:
- usage();
- }
- }
- argc -= optind;
- argv += optind;
- if (argc == 0) {
- if (mode == CHECK)
- success &= check("-", userid, envp);
- else
- usage();
- }
-
-#ifndef CHECKER_ONLY
- if (mode == SIGN && type == TAG_ANY)
- type = TAG_PGP;
- if (mode == SIGN && type == TAG_PGP)
- handle_pgp_passphrase();
-#endif
- for (i = 0; i < argc; i++)
- success &= (mode == SIGN ? sign : check)(argv[i], type, userid, envp);
- exit(success == 1 ? EXIT_SUCCESS : EXIT_FAILURE);
-}
diff --git a/usr.sbin/pkg_install/sign/pgp.h b/usr.sbin/pkg_install/sign/pgp.h
deleted file mode 100644
index e179a26afa5..00000000000
--- a/usr.sbin/pkg_install/sign/pgp.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* $OpenBSD: pgp.h,v 1.4 2002/02/17 19:42:38 millert Exp $ */
-/* Estimate size of pgp signature */
-#define MAXPGPSIGNSIZE 1024
-
-#ifndef PGP
-#define PGP "/usr/local/bin/pgp"
-#endif
-
-struct mygzip_header;
-struct signature;
-
-extern void *new_pgp_checker(struct mygzip_header *h, \
- struct signature *sign, const char *userid, char *envp[], \
- const char *filename);
-
-extern void pgp_add(void *arg, const char *buffer, size_t length);
-
-extern int pgp_sign_ok(void *arg);
-
-extern void handle_pgp_passphrase(void);
-
-extern int retrieve_pgp_signature(const char *filename, \
- struct signature **sign, const char *userid, char *envp[]);
diff --git a/usr.sbin/pkg_install/sign/pgp_check.c b/usr.sbin/pkg_install/sign/pgp_check.c
deleted file mode 100644
index 0a73b9f1d74..00000000000
--- a/usr.sbin/pkg_install/sign/pgp_check.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* $OpenBSD: pgp_check.c,v 1.4 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <assert.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include "stand.h"
-#include "pgp.h"
-#include "gzip.h"
-#include "extern.h"
-
-#ifndef _PATH_DEVNULL
-#define _PATH_DEVNULL "/dev/null"
-#endif
-
-/* transform current process into pgp signature checker -u userid <fd */
-static void
-pgpcheck(fd, userid, envp)
- int fd;
- const char *userid;
- char *envp[];
-{
- int fdnull;
- pchar argv[6];
- int argc = 0;
-
- argv[argc++] = PGP;
- argv[argc++] = "+batchmode";
- argv[argc++] = "-f";
-
- if (userid) {
- argv[argc++] = "-u";
- argv[argc++] = (char *)userid;
- }
- argv[argc++] = NULL;
-
- assert(argc <= sizeof argv / sizeof(pchar));
-
- fdnull = open(_PATH_DEVNULL, O_RDWR);
- if (fdnull == -1 ||
- dup2(fd, fileno(stdin)) == -1 ||
- dup2(fdnull, fileno(stdout)) == -1 ||
- close(fdnull) == -1 || close(fd) == -1 ||
- execve(PGP, argv, envp) == -1)
- perror("launching pgp");
- exit(errno);
-}
-
-struct pgp_checker {
- pid_t id;
- int fdout;
- int status;
-#ifdef DEBUG_DUMP
- FILE *out;
-#endif
-};
-
-void *
-new_pgp_checker(h, sign, userid, envp, filename)
- struct mygzip_header *h;
- struct signature *sign;
- const char *userid;
- char *envp[];
- /*@observer@*/const char *filename;
-{
- struct pgp_checker *n;
- int topgpcheck[2];
-
- assert(sign->type == TAG_PGP);
- n = malloc(sizeof *n);
-
- {
- struct stat sbuf;
-
- if (stat(PGP, &sbuf) == -1) {
- pwarnx("%s does not exist", PGP);
- return NULL;
- }
- }
- if (n == NULL) {
- pwarnx("Can't allocate pgp_checker");
- return NULL;
- }
-
- if (pipe(topgpcheck) == -1) {
- warn("Pgp checker pipe");
- free(n);
- return NULL;
- }
- switch(n->id = fork()) {
- case -1:
- warn("Pgp checker process");
- free(n);
- return NULL;
- case 0:
- if (close(topgpcheck[1]) == -1)
- exit(errno);
- pgpcheck(topgpcheck[0], userid, envp);
- /*@notreached@*/
- break;
- default:
- (void)close(topgpcheck[0]);
- break;
- }
- n->fdout = topgpcheck[1];
- /* so that subsequent fork() won't duplicate it inadvertently */
- (void)fcntl(n->fdout, F_SETFD, FD_CLOEXEC);
-#ifdef DEBUG_DUMP
- n->out = fopen("compare", "w");
-#endif
- n->status = PKG_GOODSIG;
-
- pgp_add(n, sign->data, sign->length);
- if (gzip_copy_header(h, sign->next, pgp_add, n) == 0) {
- pwarnx("Unexpected header in %s", filename);
- n->status = PKG_SIGERROR;
- }
- return n;
-}
-
-void
-pgp_add(arg, buffer, length)
- void *arg;
- const char *buffer;
- size_t length;
-{
- struct pgp_checker *n = arg;
-
- if (n->status == PKG_GOODSIG) {
-#ifdef DEBUG_DUMP
- fwrite(buffer, 1, length, n->out);
-#endif
- while (length > 0) {
- ssize_t l = write(n->fdout, buffer, length);
- if (l == -1) {
- n->status = PKG_SIGERROR;
- break;
- }
- length -= l;
- buffer += l;
- }
- }
-}
-
-int
-pgp_sign_ok(arg)
- void *arg;
-{
- struct pgp_checker *n = arg;
- int status = n->status;
-
-#ifdef DEBUG_DUMP
- fclose(n->out);
-#endif
- if (close(n->fdout) != 0)
- status = PKG_SIGERROR;
- if (reap(n->id) != 0)
- status = PKG_BADSIG;
- free(n);
- return status;
-}
diff --git a/usr.sbin/pkg_install/sign/pgp_sign.c b/usr.sbin/pkg_install/sign/pgp_sign.c
deleted file mode 100644
index b3aef749d43..00000000000
--- a/usr.sbin/pkg_install/sign/pgp_sign.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/* $OpenBSD: pgp_sign.c,v 1.5 2003/08/16 17:31:56 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <signal.h>
-#include <pwd.h>
-#include <assert.h>
-#include "stand.h"
-#include "pgp.h"
-#include "gzip.h"
-#include "extern.h"
-
-static void
-pgpsign(fdin, fdout, userid, envp)
- int fdin, fdout;
- const char *userid;
- char *envp[];
-{
- pchar argv[10];
- int argc = 0;
-
- argv[argc++] = PGP;
- argv[argc++] = "+batchmode";
- argv[argc++] = "+compress=off";
- argv[argc++] = "-f";
- argv[argc++] = "-s";
-
- if (userid) {
- argv[argc++] = "-u";
- argv[argc++] = (char *)userid;
- }
- argv[argc++] = NULL;
- assert(argc <= sizeof argv / sizeof(pchar));
-
- if (dup2(fdin, fileno(stdin)) == -1 ||
- dup2(fdout, fileno(stdout)) == -1 ||
- execve(PGP, argv, envp) == -1)
- exit(errno);
-}
-
-static struct signature *
-new_pgpsignature(old)
- struct signature *old;
-{
- struct signature *n;
-
- n = malloc(sizeof(*n));
- if (n != NULL) {
- n->data = malloc(MAXPGPSIGNSIZE);
- if (n->data == NULL) {
- free(n);
- return NULL;
- }
- n->length = 0;
- n->next = old;
- n->type = TAG_PGP;
- memcpy(n->tag, pgptag, sizeof pgptag);
- }
- return n;
-}
-
-int
-retrieve_pgp_signature(filename, sign, userid, envp)
- const char *filename;
- struct signature **sign;
- const char *userid;
- char *envp[];
-{
- int topgp[2], frompgp[2];
- pid_t pgpid;
- struct mygzip_header h;
- int success;
-
- FILE *orig, *dest, *signin;
- struct signature *old;
-
- orig = fopen(filename, "r");
- if (orig == NULL)
- return 0;
- if (gzip_read_header(orig, &h, &old) == GZIP_NOT_GZIP) {
- pwarnx("File %s is not a gzip file", filename);
- fclose(orig);
- return 0;
- }
-
- if (pipe(topgp) == -1) {
- fclose(orig);
- return 0;
- }
- if (pipe(frompgp) == -1) {
- fclose(orig);
- (void)close(topgp[0]);
- (void)close(topgp[1]);
- return 0;
- }
- switch(pgpid = fork()) {
- case 0:
- (void)close(topgp[1]);
- (void)close(frompgp[0]);
- pgpsign(topgp[0], frompgp[1], userid, envp);
- /*NOT REACHED */
- case -1:
- (void)close(topgp[0]);
- (void)close(topgp[1]);
- (void)close(frompgp[0]);
- (void)close(frompgp[1]);
- fclose(orig);
- return 0;
- default:
- (void)close(topgp[0]);
- (void)close(frompgp[1]);
- }
-
- dest = fdopen(topgp[1], "w");
- if (dest == NULL) {
- (void)close(topgp[1]);
- (void)close(frompgp[0]);
- (void)reap(pgpid);
- return 0;
- }
-
- success = 1;
- if (gzip_write_header(dest, &h, old) == 0)
- success = 0;
- else {
- int c;
-
- while ((c = fgetc(orig)) != EOF && fputc(c, dest) != EOF)
- ;
- if (ferror(dest))
- success = 0;
- }
- if (fclose(dest) != 0)
- success = 0;
-
- if (fclose(orig) != 0)
- success = 0;
-
- signin = fdopen(frompgp[0], "r");
- if (signin == NULL) {
- (void)close(frompgp[0]);
- } else {
- enum { NONE, FIRST, DONE, COPY} magic = NONE;
- int c;
-#ifdef DEBUG_DUMP
- FILE *out = fopen("dump", "w");
-#endif
-
- if ((*sign = new_pgpsignature(old)) == NULL)
- success = 0;
- else {
- while ((c = fgetc(signin)) != EOF && magic != DONE &&
- (*sign)->length < MAXPGPSIGNSIZE) {
- switch(magic) {
- case NONE:
- (*sign)->data[(*sign)->length++] = c;
- if ((unsigned char)c == (unsigned char)GZIP_MAGIC0)
- magic = FIRST;
- break;
- case FIRST:
- (*sign)->data[(*sign)->length++] = c;
- if ((unsigned char)c == (unsigned char)GZIP_MAGIC1)
-#ifdef DEBUG_DUMP
- magic = COPY;
-#else
- magic = DONE;
-#endif
- else if ((unsigned char)c != (unsigned char)GZIP_MAGIC0)
- magic = NONE;
- break;
- case DONE:
- case COPY:
- break;
- }
-#ifdef DEBUG_DUMP
- fputc(c, out);
-#endif
- }
- if ((*sign)->length == MAXPGPSIGNSIZE)
- success = 0;
- (*sign)->length -= 2;
- sign_fill_tag(*sign);
- }
- fclose(signin);
-#ifdef DEBUG_DUMP
- fclose(out);
-#endif
- reap(pgpid);
- }
- return success;
-}
-
-void
-handle_pgp_passphrase()
-{
- pid_t pid;
- int fd[2];
- char *p;
-
- /* Retrieve the pgp passphrase */
- p = getpass("Enter passphrase:");
-
- /* somewhat kludgy code to get the passphrase to pgp, see
- pgp documentation for the gore
- */
- if (pipe(fd) != 0) {
- perror("pkg_sign");
- exit(EXIT_FAILURE);
- }
- switch(pid = fork()) {
- case -1:
- perror("pkg_sign");
- exit(EXIT_FAILURE);
- case 0:
- {
- (void)close(fd[0]);
- /* the child fills the pipe with copies of the passphrase.
- Expect violent death when father exits.
- */
- for(;;) {
- char c = '\n';
- (void)write(fd[1], p, strlen(p));
- (void)write(fd[1], &c, 1);
- }
- }
- default:
- {
- char buf[12];
-
- (void)close(fd[1]);
- (void)snprintf(buf, sizeof(buf), "%d", fd[0]);
- (void)setenv("PGPPASSFD", buf, 1);
- }
- }
-}
-
diff --git a/usr.sbin/pkg_install/sign/pkg_sign.1 b/usr.sbin/pkg_install/sign/pkg_sign.1
deleted file mode 100644
index e62ce5c21c2..00000000000
--- a/usr.sbin/pkg_install/sign/pkg_sign.1
+++ /dev/null
@@ -1,164 +0,0 @@
-.\" $OpenBSD: pkg_sign.1,v 1.9 2003/06/12 12:59:52 jmc Exp $
-.\"
-.\" Copyright (c) 1999 Marc Espie.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
-.\" PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-.Dd September 24, 1999
-.Dt PKG_SIGN 1
-.Os
-.Sh NAME
-.Nm pkg_sign ,
-.Nm check_sign
-.Nd handle package signatures
-.Sh SYNOPSIS
-.Nm pkg_sign
-.Op Fl sc
-.Op Fl t Ar type
-.Op Fl u Ar id
-.Op Ar
-.Nm pkg_check
-.Op Fl sc
-.Op Fl u Ar id
-.Op Ar
-.Sh DESCRIPTION
-.Nm pkg_sign
-embeds a cryptographic signature within a gzip file
-.Ar file .
-.Ar type
-can be
-.Li pgp
-(default) or
-.Li sha1 .
-If
-.Ar type
-is
-.Li pgp ,
-it will always prompt you for a passphrase to unlock your private
-pgp key, even if you don't use a passphrase (which is a bad idea, anyway).
-If
-.Ar type
-is
-.Li sha1 ,
-you must supply an
-.Ar id ,
-which will be recorded as the name of the package, and printed as the
-SHA1 checksum.
-.Pp
-.Nm pkg_check
-checks that cryptographic signature.
-It currently disregards
-.Ar type
-and checks only the topmost signature.
-For sha1, it checksums the file
-and verifies that the result matches the list of checksums recorded in
-.Pa /var/db/pkg/SHA1 .
-.Pp
-Options
-.Fl s
-and
-.Fl c
-can be used to force package signing or signature checking mode.
-.Pp
-For pgp, the
-.Ar id
-to use to sign the package or verify the signature can be forced with
-.Fl u .
-.Pp
-If
-.Ar file
-is a single dash
-.Pq Sq \&-
-or absent,
-.Nm check_sign
-reads from the standard input.
-.Pp
-Package signing uses a feature of the gzip format, namely that one can
-set a flag
-.Dv EXTRA_FIELD
-in the gzip header and store extra data between the gzip header and the
-compressed file proper.
-The
-.Ox
-signing scheme uses eight bytes markers such `SIGPGP' \+ length
-or `CKSHA1' \+ length for its signatures (those markers are conveniently
-eight bytes long).
-.Sh RESULTS
-.Nm pkg_sign
-and
-.Nm pkg_check
-return with an exit code > 0 if anything went wrong for any
-.Ar file .
-For
-.Nm pkg_check ,
-this usually indicates that the package is not signed, or that the
-signature is forged.
-.Sh FILES
-.Bl -tag -width "/usr/local/bin/pgp" -compact
-.It Pa file.sign
-Temporary file built by
-.Nm pkg_sign
-from
-.Ar file .
-.It Pa /usr/local/bin/pgp
-Default path to
-.Xr pgp 1 .
-.It Pa /var/db/pkgs/SHA1
-Recorded checksums.
-.El
-.Sh DIAGNOSTICS
-.Bl -diag
-.It "File %s is already signed"
-There is a signature embedded within the gzip file already.
-.Nm pkg_sign
-currently does not handle multiple signatures.
-.It "File %s is not a signed gzip file"
-This is an unsigned package.
-.It "File %s is not a gzip file"
-The program couldn't find a proper gzip header.
-.It "File %s contains an unknown extension"
-The extended area of the gzip file has been used for an unknown purpose.
-.It "File %s uses old signatures, no longer supported"
-The gzip file uses a very early version of package signing that was
-substantially slower.
-.El
-.Sh SEE ALSO
-.Xr gzip 1 ,
-.Xr pgp 1 ,
-.Xr pkg_add 1 ,
-.Xr sha1 1
-.Sh BUGS
-.Xr pgp 1
-is an ill-designed program, which is hard to interface with.
-For instance, the `separate signing scheme' it pretends to offer is
-useless, as it can't be used with pipes, so that
-.Nm pgp_sign
-needs to kludge it by knowing the length of a pgp signature, and invoking
-pgp in `seamless' signature mode, without compression of the main file,
-and just retrieving the signature.
-.Pp
-The checking scheme is little less convoluted, namely we rebuild the file
-that pgp expects on the fly.
-.Pp
-Paths to
-.Nm pgp
-and
-the checksum file are hard-coded to avoid tampering and hinder flexibility.
diff --git a/usr.sbin/pkg_install/sign/sha1.c b/usr.sbin/pkg_install/sign/sha1.c
deleted file mode 100644
index 0da8e055eff..00000000000
--- a/usr.sbin/pkg_install/sign/sha1.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/* $OpenBSD: sha1.c,v 1.6 2003/08/16 17:31:56 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include <sha1.h>
-#include "stand.h"
-#include "gzip.h"
-#include "extern.h"
-
-/* private context for sha1 signature checker */
-struct sha1_checker {
- SHA1_CTX context;
- const char *id;
- const char *filename;
-};
-
-#define SHA1_TEMPLATE "SHA1 (%s) = "
-#define BUFSIZE (MAXID+sizeof(SHA1_TEMPLATE)+2*SHA1_DIGESTSIZE+1)
-
-/* Finalize SHA1 checksum for our sha1_context into result
- (size at least bufsize). Returns the length of the checksum
- marker, e.g., SHA1 (id) = xxxxxxxxx
- ^here
- Return 0 for errors.
- */
-size_t
-sha1_build_checksum(result, n, bufsize)
- char *result;
- struct sha1_checker *n;
- size_t bufsize;
-{
- size_t length;
-
- snprintf(result, bufsize, "SHA1 (%s) = ", n->id);
- length = strlen(result);
- SHA1End(&n->context, result + length);
- strlcat(result, "\n", bufsize);
- free(n);
- return length;
-}
-
-void *
-new_sha1_checker(h, sign, userid, envp, filename)
- struct mygzip_header *h;
- struct signature *sign;
- const char *userid;
- char *envp[];
- /*@observer@*/const char *filename;
-{
- struct sha1_checker *n;
-
- assert(sign->type == TAG_SHA1);
- /* make sure data conforms to what we can handle */
- if (sign->length > MAXID || sign->data[sign->length-1] != '\0') {
- pwarnx("Corrupted SHA1 header in %s", filename);
- return 0;
- }
-
- n = malloc(sizeof *n);
- if (n == NULL) {
- pwarnx("Can't allocate sha1_checker");
- return NULL;
- }
- SHA1Init(&n->context);
- n->id = sign->data;
- n->filename = filename;
-
- /* copy header, as this is a checksum, we don't strip our own marker */
- if (gzip_copy_header(h, sign, sha1_add, n) == 0) {
- pwarnx("Unexpected header in %s", filename);
- free(n);
- return 0;
- }
- return n;
-}
-
-void
-sha1_add(arg, buffer, length)
- void *arg;
- const char *buffer;
- size_t length;
-{
- struct sha1_checker *n = arg;
- SHA1Update(&n->context, buffer, length);
-}
-
-int
-sha1_sign_ok(arg)
- void *arg;
-{
- struct sha1_checker *n = arg;
- char buffer[BUFSIZE];
- char scan[BUFSIZE];
- size_t length;
- FILE *f;
- int tag_found;
-
- length = sha1_build_checksum(buffer, n, sizeof(buffer));
- f= fopen(SHA1_DB_NAME, "r");
- tag_found = 0;
-
- if (f == NULL) {
- warn("Can't access checksum file %s", SHA1_DB_NAME);
- return PKG_BADSIG;
- }
- while (fgets(scan, sizeof(scan), f) != NULL) {
- if (strcmp(scan, buffer) == 0) {
- fprintf(stderr, "Checksum ok\n");
- return PKG_GOODSIG;
- }
- if (strncmp(scan, buffer, length) == 0)
- tag_found = 1;
- }
-
- if (tag_found) {
- pwarnx("Checksum incorrect for %s (%s)", n->filename, n->id);
- return PKG_BADSIG;
- } else {
- pwarnx("No checksum found for %s (%s)", n->filename, n->id);
- return PKG_SIGUNKNOWN;
- }
-}
-
-int
-retrieve_sha1_marker(filename, sign, userid)
- const char *filename;
- struct signature **sign;
- const char *userid;
-{
- struct signature *n;
- struct mygzip_header h;
- FILE *f;
- char buffer[1024];
- char result[BUFSIZE];
- ssize_t length;
- struct sha1_checker *checker;
- struct signature *old;
-
- *sign = NULL;
- if (userid == NULL)
- return 0;
-
- n = malloc(sizeof *n);
- if (n == NULL)
- return 0;
- n->data = (char *)userid;
- n->length = strlen(n->data)+1;
- n->type = TAG_SHA1;
- memcpy(n->tag, sha1tag, sizeof sha1tag);
- sign_fill_tag(n);
-
- f = fopen(filename, "r");
- if (f == NULL) {
- free(n);
- return 0;
- }
- if (gzip_read_header(f, &h, sign) == GZIP_NOT_GZIP) {
- pwarnx("File %s is not a gzip file", filename);
- fclose(f);
- free(n);
- return 0;
- }
- n->next = *sign;
- *sign = n;
-
- checker = new_sha1_checker(&h, *sign, NULL, NULL, filename);
- while ((length = fread(buffer, 1, sizeof buffer, f)) > 0)
- sha1_add(checker, buffer, length);
- if (fclose(f) != 0 || length == -1) {
- warn("Problem checksumming %s", filename);
- *sign = n->next;
- free(n);
- return 0;
- }
-
- (void)sha1_build_checksum(result, checker, sizeof(result));
- fputs(result, stderr);
- return 1;
-}
-
diff --git a/usr.sbin/pkg_install/sign/sign.c b/usr.sbin/pkg_install/sign/sign.c
deleted file mode 100644
index d746a35d23e..00000000000
--- a/usr.sbin/pkg_install/sign/sign.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/* $OpenBSD: sign.c,v 1.5 2003/06/04 04:29:03 deraadt Exp $ */
-/*-
- * Copyright (c) 1999 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <signal.h>
-#include <pwd.h>
-#include <assert.h>
-#include "stand.h"
-#include "pgp.h"
-#include "gzip.h"
-#include "extern.h"
-
-#define COPY_TEMPLATE "%s.sign"
-
-static int
-embed_signature_FILE(orig, dest, sign, filename)
- /*@temp@*/FILE *orig;
- /*@temp@*/FILE *dest;
- struct signature *sign;
- const char *filename;
-{
- struct mygzip_header h;
- int c;
-
- if (gzip_read_header(orig, &h, NULL) == GZIP_NOT_GZIP)
- return 0;
-
- if (gzip_write_header(dest, &h, sign) == 0)
- return 0;
- while ((c = fgetc(orig)) != EOF && fputc(c, dest) != EOF)
- ;
- if (ferror(dest) != 0)
- return 0;
- return 1;
-}
-
-static int
-embed_signature(filename, copy, sign)
- const char *filename;
- const char *copy;
- struct signature *sign;
-{
- FILE *orig, *dest;
- int success;
-
- success = 0;
- orig= fopen(filename, "r");
- if (orig) {
- dest = fopen(copy, "w");
- if (dest) {
- success = embed_signature_FILE(orig, dest, sign, filename);
- if (fclose(dest) != 0)
- success = 0;
- }
- if (fclose(orig) != 0)
- success = 0;
- }
- return success;
-}
-
-int
-sign(filename, type, userid, envp)
- const char *filename;
- const char *userid;
- int type;
- char *envp[];
-{
- char *copy;
- int result;
- struct signature *sign;
- int success;
-
- switch(type) {
- case TAG_PGP:
- success = retrieve_pgp_signature(filename, &sign, userid, envp);
- break;
- case TAG_SHA1:
- success =retrieve_sha1_marker(filename, &sign, userid);
- break;
- }
-
- if (!success) {
- fprintf(stderr, "Problem signing %s\n", filename);
- free_signature(sign);
- return 0;
- }
- if (asprintf(&copy, COPY_TEMPLATE, filename) == -1) {
- fprintf(stderr, "Can't allocate memory\n");
- free_signature(sign);
- return 0;
- }
- result = embed_signature(filename, copy, sign);
- if (result == 0) {
- fprintf(stderr, "Can't embed signature in %s\n", filename);
- } else if (unlink(filename) != 0) {
- fprintf(stderr, "Can't unlink original %s\n", filename);
- result = 0;
- } else if (rename(copy, filename) != 0) {
- fprintf(stderr, "Can't rename new file %s\n", copy);
- result = 0;
- }
- free(copy);
- free_signature(sign);
- return result;
-}
-
diff --git a/usr.sbin/pkg_install/sign/stand.c b/usr.sbin/pkg_install/sign/stand.c
deleted file mode 100644
index 4788a79ced3..00000000000
--- a/usr.sbin/pkg_install/sign/stand.c
+++ /dev/null
@@ -1,54 +0,0 @@
-#include "stand.h"
-
-#ifdef BSD4_4
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdarg.h>
-
-/* shortened version of warn */
-static const char *program_name;
-
-void
-set_program_name(n)
- const char *n;
-{
- if ((program_name = strrchr(n, '/')) != NULL)
- program_name++;
- else
- program_name = n;
-}
-
-void
-warn(const char *fmt, ...)
-{
- va_list ap;
- int interrno;
-
- va_start(ap, fmt);
-
- interrno = errno;
- (void)fprintf(stderr, "%s", program_name);
- if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(interrno));
-
- va_end(ap);
-}
-
-void
-warnx(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- (void)fprintf(stderr, "%s", program_name);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
- va_end(ap);
-}
-
-#endif
diff --git a/usr.sbin/pkg_install/sign/stand.h b/usr.sbin/pkg_install/sign/stand.h
deleted file mode 100644
index af61be3dff9..00000000000
--- a/usr.sbin/pkg_install/sign/stand.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* $OpenBSD: stand.h,v 1.4 2002/02/17 19:42:38 millert Exp $ */
-
-/* provided to cater for BSD idiosyncrasies */
-
-#if (defined(__unix__) || defined(unix)) && !defined(USG)
-#include <sys/param.h>
-#endif
-
-#if defined(BSD4_4)
-#include <err.h>
-#else
-extern void set_program_name(const char * name);
-extern void warn(const char *fmt, ...);
-extern void warnx(const char *fmt, ...);
-#endif
-
-#ifndef __GNUC__
-#define __attribute__(x)
-#endif