Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Aug 2001 18:19:22 +0900
From:      "Akinori MUSHA" <knu@iDaemons.org>
To:        audit@FreeBSD.org
Cc:        "Brian F. Feldman" <green@FreeBSD.org>, Mike Barcroft <mike@FreeBSD.org>, ports@FreeBSD.org
Subject:   Re: adding -P option to pkg_delete(1) 
Message-ID:  <86k804weed.wl@archon.local.idaemons.org>
In-Reply-To: <200108122310.f7CNAUZ01898@green.bikeshed.org>
References:  <86ofpl0yq8.wl@archon.local.idaemons.org> <200108122310.f7CNAUZ01898@green.bikeshed.org>

next in thread | previous in thread | raw e-mail | index | archive | help
OK, adopting green's suggestion I'd propose the attached patch again.
FWIW, I've confirmed that it works.

Since I've had no objection against it so far, I'm going to commit it
this weekend and do MFC after the 4.4-RELEASE unless someone objects.


FYI, 4.4-RELEASE users can use my pkg_deinstall(1) utility included in
sysutils/portupgrade.  It is a wrapper of pkg_delete(1) with almost
upper compatible syntax, and which already has the -P option.


Mental note:

We'll have to audit the whole pkg_install code to eliminate possible
buffer overflows.

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Freeze this moment a little bit longer, make each impression
  a little bit stronger..  Experience slips away -- Time stand still"

Index: add/perform.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/add/perform.c,v
retrieving revision 1.65
diff -u -r1.65 perform.c
--- add/perform.c	2001/08/15 14:22:01	1.65
+++ add/perform.c	2001/08/15 19:57:59
@@ -480,7 +480,7 @@
  fail:
     /* Nuke the whole (installed) show, XXX but don't clean directories */
     if (!Fake)
-	delete_package(FALSE, FALSE, &Plist);
+	delete_package(FALSE, FALSE, FALSE, &Plist);
 
  success:
     /* delete the packing list contents */
Index: delete/delete.h
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/delete.h,v
retrieving revision 1.6
diff -u -r1.6 delete.h
--- delete/delete.h	2001/02/27 09:00:18	1.6
+++ delete/delete.h	2001/08/05 17:39:55
@@ -28,6 +28,7 @@
 extern Boolean	Interactive;
 extern Boolean	NoDeInstall;
 extern Boolean	Force;
+extern Boolean	PreserveShlib;
 extern char	*Directory;
 extern char	*PkgName;
 extern match_t	MatchType;
Index: delete/main.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/main.c,v
retrieving revision 1.22
diff -u -r1.22 main.c
--- delete/main.c	2001/08/02 13:13:05	1.22
+++ delete/main.c	2001/08/06 06:22:43
@@ -30,12 +30,13 @@
 #include "lib.h"
 #include "delete.h"
 
-static char Options[] = "adDfGhinp:vx";
+static char Options[] = "adDfGhinp:Pvx";
 
 char	*Prefix		= NULL;
 Boolean	CleanDirs	= FALSE;
 Boolean	Interactive	= FALSE;
 Boolean	NoDeInstall	= FALSE;
+Boolean	PreserveShlib	= FALSE;
 match_t	MatchType	= MATCH_GLOB;
 
 static void usage __P((void));
@@ -93,6 +94,10 @@
 	    Interactive = TRUE;
 	    break;
 
+	case 'P':
+	    PreserveShlib = TRUE;
+	    break;
+
 	case 'h':
 	case '?':
 	default:
@@ -148,7 +153,7 @@
 usage()
 {
     fprintf(stderr, "%s\n%s\n",
-	"usage: pkg_delete [-dDfGinvx] [-p prefix] pkg-name ...",
+	"usage: pkg_delete [-dDfGinPvx] [-p prefix] pkg-name ...",
 	"       pkg_delete -a [flags]");
     exit(1);
 }
Index: delete/perform.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/perform.c,v
retrieving revision 1.32
diff -u -r1.32 perform.c
--- delete/perform.c	2001/08/02 13:13:05	1.32
+++ delete/perform.c	2001/08/05 17:40:22
@@ -217,7 +217,7 @@
      * Some packages aren't packed right, so we need to just ignore
      * delete_package()'s status.  Ugh! :-(
      */
-    if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
+    if (delete_package(FALSE, CleanDirs, PreserveShlib, &Plist) == FAIL)
 	warnx(
 	"couldn't entirely delete package (perhaps the packing list is\n"
 	"incorrectly specified?)");
Index: delete/pkg_delete.1
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/pkg_delete.1,v
retrieving revision 1.26
diff -u -r1.26 pkg_delete.1
--- delete/pkg_delete.1	2001/07/15 08:02:37	1.26
+++ delete/pkg_delete.1	2001/08/06 06:20:53
@@ -25,7 +25,7 @@
 .Nd a utility for deleting previously installed software package distributions
 .Sh SYNOPSIS
 .Nm
-.Op Fl dDfGinvx
+.Op Fl dDfGinPvx
 .Op Fl p Ar prefix
 .Ar pkg-name ...
 .Nm
@@ -91,6 +91,14 @@
 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 P
+Preserve (possible) shared library files that end with the
+.Dq .so ,
+.Dq .so.X ,
+or
+.Dq .so.X.Y
+suffix.  This is useful when you suspect that you still have some
+binaries that depend on the shared library being deleted.
 .It Fl d
 Remove empty directories created by file cleanup.  By default, only
 files/directories explicitly listed in a package's contents (either as
Index: lib/lib.h
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/lib/lib.h,v
retrieving revision 1.37
diff -u -r1.37 lib.h
--- lib/lib.h	2001/08/13 04:18:30	1.37
+++ lib/lib.h	2001/08/13 15:21:51
@@ -171,7 +171,7 @@
 void		write_plist(Package *, FILE *);
 void		read_plist(Package *, FILE *);
 int		plist_cmd(char *, char **);
-int		delete_package(Boolean, Boolean, Package *);
+int		delete_package(Boolean, Boolean, Boolean, Package *);
 Boolean 	make_preserve_name(char *, int, char *, char *);
 
 /* For all */
Index: lib/plist.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/lib/plist.c,v
retrieving revision 1.34
diff -u -r1.34 plist.c
--- lib/plist.c	2001/08/02 12:38:29	1.34
+++ lib/plist.c	2001/08/16 09:06:09
@@ -26,6 +26,7 @@
 #include "lib.h"
 #include <err.h>
 #include <md5.h>
+#include <regex.h>
 
 /* Add an item to a packing list */
 void
@@ -346,13 +347,28 @@
 }
 
 /*
+ * Check if the given filename looks like a shared library.
+ */
+static Boolean
+is_shlib(const char *filename) {
+	regex_t reg;
+	Boolean ret;
+
+	if (regcomp(&reg, "[^/]\\.so(\\.[[:digit:]]+)*$", REG_EXTENDED) != 0)
+		return (FALSE);
+	ret = regexec(&reg, filename, 0, NULL, 0) == 0;
+	regfree(&reg);
+	return (ret);
+}
+
+/*
  * 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, Package *pkg)
+delete_package(Boolean ign_err, Boolean nukedirs, Boolean preserve_shlib, Package *pkg)
 {
     PackingList p;
     char *Where = ".", *last_file = "";
@@ -389,7 +405,12 @@
 
 	case PLIST_FILE:
 	    last_file = p->name;
-	    sprintf(tmp, "%s/%s", Where, p->name);
+	    sprintf(tmp, "%s/%s", Where, last_file);
+	    if (preserve_shlib && is_shlib(last_file)) {
+		if (Verbose)
+		    printf("Preserve shared library file %s\n", tmp);
+		continue;
+	    }
 	    if (isdir(tmp) && fexists(tmp) && !issymlink(tmp)) {
 		warnx("cannot delete specified file '%s' - it is a directory!\n"
 	   "this packing list is incorrect - ignoring delete request", tmp);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86k804weed.wl>