summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1996-07-30 10:48:20 +0000
committerjkh <jkh@FreeBSD.org>1996-07-30 10:48:20 +0000
commit84d237928927613ef8052cc504b40894a8f01f4d (patch)
tree88293eee6032bf226b091c9261848f0aae12de17 /usr.sbin/pkg_install
parent7fde0e3b7da9d7033e238dbec5ce1e88946fd069 (diff)
downloadFreeBSD-src-84d237928927613ef8052cc504b40894a8f01f4d.zip
FreeBSD-src-84d237928927613ef8052cc504b40894a8f01f4d.tar.gz
Add MD5 checksums to packing list for all files during pkg_create and use
later at pkg_delete time to verify that you're deleting what you added. This, of course, does NOT cover the case where a file you still need hasn't changed! That's a tougher problem to solve, and this provides only the minimal amount of safety belt. MD5 checksums are stored in comment fields, so packages produced with these tools are backwards compatible with the older ones.
Diffstat (limited to 'usr.sbin/pkg_install')
-rw-r--r--usr.sbin/pkg_install/add/Makefile4
-rw-r--r--usr.sbin/pkg_install/add/main.c3
-rw-r--r--usr.sbin/pkg_install/create/Makefile4
-rw-r--r--usr.sbin/pkg_install/create/perform.c7
-rw-r--r--usr.sbin/pkg_install/create/pl.c22
-rw-r--r--usr.sbin/pkg_install/delete/Makefile4
-rw-r--r--usr.sbin/pkg_install/delete/main.c3
-rw-r--r--usr.sbin/pkg_install/delete/perform.c8
-rw-r--r--usr.sbin/pkg_install/info/Makefile4
-rw-r--r--usr.sbin/pkg_install/lib/global.c3
-rw-r--r--usr.sbin/pkg_install/lib/lib.h25
-rw-r--r--usr.sbin/pkg_install/lib/plist.c92
12 files changed, 105 insertions, 74 deletions
diff --git a/usr.sbin/pkg_install/add/Makefile b/usr.sbin/pkg_install/add/Makefile
index 723ca45..83a022e 100644
--- a/usr.sbin/pkg_install/add/Makefile
+++ b/usr.sbin/pkg_install/add/Makefile
@@ -10,8 +10,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif
-LDADD+= -lftpio
-DPADD+= ${LIBFTPIO}
+LDADD+= -lftpio -lmd
+DPADD+= ${LIBFTPIO} ${LIBMD}
SRCS= main.c perform.c futil.c extract.c
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c
index 4dd9109..1d3099a 100644
--- a/usr.sbin/pkg_install/add/main.c
+++ b/usr.sbin/pkg_install/add/main.c
@@ -1,5 +1,5 @@
#ifndef lint
-static char *rcsid = "$Id: main.c,v 1.9 1995/11/12 04:55:19 jkh Exp $";
+static char *rcsid = "$Id: main.c,v 1.10 1996/03/12 06:12:36 jkh Exp $";
#endif
/*
@@ -32,7 +32,6 @@ static char Options[] = "hvIRfnp:SMt:";
char *Prefix = NULL;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
-Boolean Force = FALSE;
char *Mode = NULL;
char *Owner = NULL;
diff --git a/usr.sbin/pkg_install/create/Makefile b/usr.sbin/pkg_install/create/Makefile
index 26d57e4..01048ac 100644
--- a/usr.sbin/pkg_install/create/Makefile
+++ b/usr.sbin/pkg_install/create/Makefile
@@ -10,8 +10,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif
-LDADD+= -lftpio
-DPADD+= ${LIBFTPIO}
+LDADD+= -lftpio -lmd
+DPADD+= ${LIBFTPIO} ${LIBMD}
SRCS= main.c perform.c pl.c
diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c
index c3004ee..ee89e1a 100644
--- a/usr.sbin/pkg_install/create/perform.c
+++ b/usr.sbin/pkg_install/create/perform.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: perform.c,v 1.30 1996/03/20 19:05:59 jdp Exp $";
+static const char *rcsid = "$Id: perform.c,v 1.31 1996/06/20 18:33:36 jkh Exp $";
#endif
/*
@@ -156,11 +156,6 @@ pkg_perform(char **pkgs)
add_plist(&plist, PLIST_MTREE, MTREE_FNAME);
}
- /* Run through the list again, picking up extra "local" items */
- /* check_list(".", &plist); */
- /* copy_plist(".", &plist); */
- /* mark_plist(&plist); */
-
/* Finally, write out the packing list */
fp = fopen(CONTENTS_FNAME, "w");
if (!fp)
diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c
index 9eb98a3..80d8805 100644
--- a/usr.sbin/pkg_install/create/pl.c
+++ b/usr.sbin/pkg_install/create/pl.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: pl.c,v 1.6 1994/12/06 00:51:38 jkh Exp $";
+static const char *rcsid = "$Id: pl.c,v 1.7 1995/05/30 03:49:56 rgrimes Exp $";
#endif
/*
@@ -25,13 +25,12 @@ static const char *rcsid = "$Id: pl.c,v 1.6 1994/12/06 00:51:38 jkh Exp $";
#include "lib.h"
#include "create.h"
#include <errno.h>
+#include <md5.h>
/* Check a list for files that require preconversion */
void
check_list(char *home, Package *pkg)
{
- char cmd[FILENAME_MAX];
- char name[FILENAME_MAX];
char *where = home;
char *there = NULL;
PackingList p = pkg->head;
@@ -45,15 +44,18 @@ check_list(char *home, Package *pkg)
there = p->name;
}
else if (p->type == PLIST_FILE) {
- cmd[0] = '\0';
+ char *cp, name[FILENAME_MAX], buf[33];
+
sprintf(name, "%s/%s", there ? there : where, p->name);
+ if ((cp = MD5File(name, buf)) != NULL) {
+ PackingList tmp = new_plist_entry();
- if (*cmd) {
- if (Verbose)
- printf("Uncompressing-> %s\n", cmd);
- if (system(cmd))
- barf("%s failed!", cmd);
- nuke_suffix(p->name);
+ tmp->name = copy_string(strconcat("MD5:", cp));
+ tmp->type = PLIST_COMMENT;
+ tmp->next = p->next;
+ tmp->prev = p;
+ p->next = tmp;
+ p = tmp;
}
}
p = p->next;
diff --git a/usr.sbin/pkg_install/delete/Makefile b/usr.sbin/pkg_install/delete/Makefile
index 9fd0980..20a5717 100644
--- a/usr.sbin/pkg_install/delete/Makefile
+++ b/usr.sbin/pkg_install/delete/Makefile
@@ -9,8 +9,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif
-LDADD+= -lftpio
-DPADD+= ${LIBFTPIO}
+LDADD+= -lftpio -lmd
+DPADD+= ${LIBFTPIO} ${LIBMD}
SRCS= main.c perform.c
diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c
index 10d0c18..646c420 100644
--- a/usr.sbin/pkg_install/delete/main.c
+++ b/usr.sbin/pkg_install/delete/main.c
@@ -1,5 +1,5 @@
#ifndef lint
-static char *rcsid = "$Id: main.c,v 1.4 1995/05/30 03:49:57 rgrimes Exp $";
+static char *rcsid = "$Id: main.c,v 1.5 1996/06/20 18:33:43 jkh Exp $";
#endif
/*
@@ -32,7 +32,6 @@ static char Options[] = "hvDdnfp:";
char *Prefix = NULL;
Boolean NoDeInstall = FALSE;
Boolean CleanDirs = FALSE;
-Boolean Force = FALSE;
int
main(int argc, char **argv)
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c
index dd3810a..dd548b2 100644
--- a/usr.sbin/pkg_install/delete/perform.c
+++ b/usr.sbin/pkg_install/delete/perform.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: perform.c,v 1.8 1995/11/12 04:55:30 jkh Exp $";
+static const char *rcsid = "$Id: perform.c,v 1.9 1996/06/20 18:33:44 jkh Exp $";
#endif
/*
@@ -127,15 +127,15 @@ pkg_do(char *pkg)
"incorrectly specified?)\n");
if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
whinge("Couldn't remove log entry in %s, de-install failed.", LogDir);
- return 1;
+ if (!Force)
+ return 1;
}
}
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);
+ printf("Attempting to remove dependency on package `%s'\n", p->name);
if (!Fake)
undepend(p, pkg);
}
diff --git a/usr.sbin/pkg_install/info/Makefile b/usr.sbin/pkg_install/info/Makefile
index 9ab8dc3..29f98d2 100644
--- a/usr.sbin/pkg_install/info/Makefile
+++ b/usr.sbin/pkg_install/info/Makefile
@@ -9,8 +9,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif
-LDADD+= -lftpio
-DPADD+= ${LIBFTPIO}
+LDADD+= -lftpio -lmd
+DPADD+= ${LIBFTPIO} ${LIBMD}
SRCS= main.c perform.c show.c
diff --git a/usr.sbin/pkg_install/lib/global.c b/usr.sbin/pkg_install/lib/global.c
index d411f5e..17d0026 100644
--- a/usr.sbin/pkg_install/lib/global.c
+++ b/usr.sbin/pkg_install/lib/global.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: global.c,v 1.1.1.1 1993/08/26 01:19:55 jkh Exp $";
+static const char *rcsid = "$Id: global.c,v 1.2 1994/04/05 14:08:45 jkh Exp $";
#endif
/*
@@ -28,6 +28,7 @@ static const char *rcsid = "$Id: global.c,v 1.1.1.1 1993/08/26 01:19:55 jkh Exp
/* These are global for all utils */
Boolean Verbose = FALSE;
Boolean Fake = FALSE;
+Boolean Force = FALSE;
int AutoAnswer = FALSE;
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index 95ac9a1..6abf95f 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -1,4 +1,4 @@
-/* $Id: lib.h,v 1.20 1996/06/08 00:46:32 alex Exp $ */
+/* $Id: lib.h,v 1.21 1996/06/20 18:33:53 jkh Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
@@ -62,25 +62,25 @@
#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 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 DISPLAY_FNAME "+DISPLAY"
+#define MTREE_FNAME "+MTREE_DIRS"
-#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
+#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
/* The name of the "prefix" environment variable given to scripts */
#define PKG_PREFIX_VNAME "PKG_PREFIX"
enum _plist_t {
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_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
+ PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST,
PLIST_OPTION
};
@@ -171,6 +171,7 @@ int pkg_perform(char **);
/* Externs */
extern Boolean Verbose;
extern Boolean Fake;
+extern Boolean Force;
extern int AutoAnswer;
#endif /* _INST_LIB_LIB_H_ */
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 2a5c674..b9f3e16 100644
--- a/usr.sbin/pkg_install/lib/plist.c
+++ b/usr.sbin/pkg_install/lib/plist.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: plist.c,v 1.15 1995/11/12 04:55:40 jkh Exp $";
+static const char *rcsid = "$Id: plist.c,v 1.16 1996/06/20 18:33:55 jkh Exp $";
#endif
/*
@@ -23,6 +23,7 @@ static const char *rcsid = "$Id: plist.c,v 1.15 1995/11/12 04:55:40 jkh Exp $";
*/
#include "lib.h"
+#include <md5.h>
/* Add an item to a packing list */
void
@@ -238,11 +239,11 @@ read_plist(Package *pkg, FILE *fp)
int cmd;
while (fgets(pline, FILENAME_MAX, fp)) {
- int len = strlen(pline) - 1;
+ int len = strlen(pline);
- while (isspace(pline[len]))
- pline[len--] = '\0';
- if (len <= 0)
+ while (len && isspace(pline[len - 1]))
+ pline[--len] = '\0';
+ if (!len)
continue;
cp = pline;
if (pline[0] == CMD_CHAR) {
@@ -348,51 +349,84 @@ write_plist(Package *pkg, FILE *fp)
int
delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
{
- PackingList p = pkg->head;
+ PackingList p;
char *Where = ".", *last_file = "";
Boolean fail = SUCCESS;
+ char tmp[FILENAME_MAX];
- if (!p)
- return FAIL;
- while (p) {
- if (p->type == PLIST_CWD) {
+ for (p = pkg->head; p; p = p->next) {
+ switch (p->type) {
+ case PLIST_IGNORE:
+ p = p->next;
+ break;
+
+ case PLIST_CWD:
Where = p->name;
if (Verbose)
printf("Change working directory to %s\n", Where);
- }
- else if (p->type == PLIST_UNEXEC) {
- char cmd[FILENAME_MAX];
+ break;
- format_cmd(cmd, p->name, Where, last_file);
+ case PLIST_UNEXEC:
+ format_cmd(tmp, p->name, Where, last_file);
if (Verbose)
- printf("Execute `%s'\n", cmd);
- if (!Fake && system(cmd)) {
- whinge("unexec command for `%s' failed.", cmd);
+ printf("Execute `%s'\n", tmp);
+ if (!Fake && system(tmp)) {
+ whinge("unexec command for `%s' failed.", tmp);
fail = FAIL;
}
- }
- else if (p->type == PLIST_IGNORE)
- p = p->next;
- else if (p->type == PLIST_FILE || p->type == PLIST_DIR_RM) {
- char full_name[FILENAME_MAX];
+ break;
- sprintf(full_name, "%s/%s", Where, p->name);
- if (isdir(full_name) && p->type == PLIST_FILE) {
+ case PLIST_FILE:
+ sprintf(tmp, "%s/%s", Where, p->name);
+ if (isdir(tmp)) {
whinge("Attempting to delete directory `%s' as a file\n"
- "This packing list is incorrect - ignoring delete request.\n", full_name);
+ "This packing list is incorrect - ignoring delete request.\n", tmp);
}
else {
+ if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
+ char *cp, buf[33];
+
+ if ((cp = MD5File(tmp, buf)) != NULL) {
+ /* Mismatch? */
+ if (strcmp(cp, p->next->name + 4)) {
+ if (Verbose)
+ printf("%s fails original MD5 checksum - %s\n",
+ tmp, Force ? "deleted anyway." : "not deleted.");
+ if (!Force) {
+ fail = FAIL;
+ continue;
+ }
+ }
+ }
+ }
if (Verbose)
- printf("Delete %s %s\n", !isdir(full_name) ? "file" : " directory", full_name);
+ printf("Delete file %s\n", tmp);
+
+ if (!Fake && delete_hierarchy(tmp, ign_err, nukedirs)) {
+ whinge("Unable to completely remove file '%s'", tmp);
+ fail = FAIL;
+ }
+ }
+ last_file = p->name;
+ break;
- if (!Fake && delete_hierarchy(full_name, ign_err, p->type == PLIST_DIR_RM ? FALSE : nukedirs)) {
- whinge("Unable to completely remove file '%s'", full_name);
+ case PLIST_DIR_RM:
+ sprintf(tmp, "%s/%s", Where, p->name);
+ if (!isdir(tmp)) {
+ whinge("Attempting to delete file `%s' as a directory\n"
+ "This packing list is incorrect - ignoring delete request.\n", tmp);
+ }
+ else {
+ if (Verbose)
+ printf("Delete directory %s\n", tmp);
+ if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
+ whinge("Unable to completely remove directory '%s'", tmp);
fail = FAIL;
}
}
last_file = p->name;
+ break;
}
- p = p->next;
}
return fail;
}
OpenPOWER on IntegriCloud