summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install/lib
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/pkg_install/lib
parentc3cebc304b3fb018e0c7bcf0bf799547bdd63b40 (diff)
bye bye old package tools.
ok deraadt@
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-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
9 files changed, 0 insertions, 2179 deletions
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;
-}