Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pkgviews]: src/usr.sbin/pkg_install Teach pkg_delete(1) and pkg_view(1) ...



details:   https://anonhg.NetBSD.org/src/rev/05ff4d22e984
branches:  pkgviews
changeset: 534234:05ff4d22e984
user:      jlam <jlam%NetBSD.org@localhost>
date:      Thu Jul 24 23:14:51 2003 +0000

description:
Teach pkg_delete(1) and pkg_view(1) about using VIEW-INSTALL and
VIEW-DEINSTALL actions for the INSTALL/DEINSTALL scripts.  The
VIEW-INSTALL action is run after a package is added to a view, and the
VIEW-DEINSTALL action is run before a package is removed from a view.

Be backwards compatible with using pkg_delete(1) to remove existing
non-depoted packages by not executing the VIEW-DEINSTALL action.

Also, test for +DEPOT in pkg_view(1) to check whether a package is part
of a view or not since +DEPOT is only present for "viewed" packages.

diffstat:

 usr.sbin/pkg_install/delete/perform.c    |  25 ++++++++-
 usr.sbin/pkg_install/delete/pkg_delete.1 |   9 +++-
 usr.sbin/pkg_install/lib/version.h       |   4 +-
 usr.sbin/pkg_install/view/pkg_view.1     |  78 +++++++++++++++++++++++++++++++-
 usr.sbin/pkg_install/view/pkg_view.sh    |  24 ++++++++-
 5 files changed, 128 insertions(+), 12 deletions(-)

diffs (270 lines):

diff -r 4ef2342b18b9 -r 05ff4d22e984 usr.sbin/pkg_install/delete/perform.c
--- a/usr.sbin/pkg_install/delete/perform.c     Wed Jul 23 23:03:00 2003 +0000
+++ b/usr.sbin/pkg_install/delete/perform.c     Thu Jul 24 23:14:51 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.36.2.4 2003/07/23 23:03:00 jlam Exp $    */
+/*     $NetBSD: perform.c,v 1.36.2.5 2003/07/24 23:14:51 jlam Exp $    */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
 #else
-__RCSID("$NetBSD: perform.c,v 1.36.2.4 2003/07/23 23:03:00 jlam Exp $");
+__RCSID("$NetBSD: perform.c,v 1.36.2.5 2003/07/24 23:14:51 jlam Exp $");
 #endif
 #endif
 
@@ -715,7 +715,24 @@
                                return 1;
                }
        }
-       if (!NoDeInstall && fexists(DEINSTALL_FNAME)) {
+       /*
+        * Ensure that we don't do VIEW-DEINSTALL action for old packages
+        * or for the package in its depot directory.
+        */
+       if (!NoDeInstall && fexists(DEINSTALL_FNAME) && fexists(DEPOT_FNAME)) {
+               if (Fake) {
+                       printf("Would execute view de-install script at this point (arg: VIEW-DEINSTALL).\n");
+               } else {
+                       vsystem("%s +x %s", CHMOD_CMD, DEINSTALL_FNAME);        /* make sure */
+                       if (vsystem("./%s %s VIEW-DEINSTALL", DEINSTALL_FNAME, pkg)) {
+                               warnx("view deinstall script returned error status");
+                               if (!Force) {
+                                       return 1;
+                               }
+                       }
+               }
+       }
+       if (!NoDeInstall && fexists(DEINSTALL_FNAME) && !fexists(DEPOT_FNAME)) {
                if (Fake)
                        printf("Would execute de-install script at this point (arg: DEINSTALL).\n");
                else {
@@ -757,7 +774,7 @@
 
                require_delete(home, 1);
        }
-       if (!NoDeInstall && fexists(DEINSTALL_FNAME)) {
+       if (!NoDeInstall && fexists(DEINSTALL_FNAME) && !fexists(DEPOT_FNAME)) {
                if (Fake)
                        printf("Would execute post-de-install script at this point (arg: POST-DEINSTALL).\n");
                else {
diff -r 4ef2342b18b9 -r 05ff4d22e984 usr.sbin/pkg_install/delete/pkg_delete.1
--- a/usr.sbin/pkg_install/delete/pkg_delete.1  Wed Jul 23 23:03:00 2003 +0000
+++ b/usr.sbin/pkg_install/delete/pkg_delete.1  Thu Jul 24 23:14:51 2003 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_delete.1,v 1.24.4.1 2003/07/13 09:45:24 jlam Exp $
+.\" $NetBSD: pkg_delete.1,v 1.24.4.2 2003/07/24 23:14:52 jlam Exp $
 .\"
 .\" FreeBSD install - a package for the installation and maintenance
 .\" of non-core utilities.
@@ -197,6 +197,12 @@
 .Bd -filled -offset indent -compact
 .Cm deinstall
 .Ar \*[Lt]pkg-name\*[Gt]
+.Ar VIEW-DEINSTALL
+.Ed
+before removing the package from a view, and as:
+.Bd -filled -offset indent -compact
+.Cm deinstall
+.Ar \*[Lt]pkg-name\*[Gt]
 .Ar DEINSTALL
 .Ed
 before deleting all files and as:
@@ -207,6 +213,7 @@
 .Ed
 after deleting them.
 Passing the keywords
+.Ar VIEW-DEINSTALL ,
 .Ar DEINSTALL
 and
 .Ar POST-DEINSTALL
diff -r 4ef2342b18b9 -r 05ff4d22e984 usr.sbin/pkg_install/lib/version.h
--- a/usr.sbin/pkg_install/lib/version.h        Wed Jul 23 23:03:00 2003 +0000
+++ b/usr.sbin/pkg_install/lib/version.h        Thu Jul 24 23:14:51 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.13.4.2 2003/07/13 09:45:29 jlam Exp $    */
+/*     $NetBSD: version.h,v 1.13.4.3 2003/07/24 23:14:52 jlam Exp $    */
 
 /*
  * Copyright (c) 2001 Thomas Klausner.  All rights reserved.
@@ -33,6 +33,6 @@
 #ifndef _INST_LIB_VERSION_H_
 #define _INST_LIB_VERSION_H_
 
-#define PKGTOOLS_VERSION "20030713"
+#define PKGTOOLS_VERSION "20030724"
 
 #endif /* _INST_LIB_VERSION_H_ */
diff -r 4ef2342b18b9 -r 05ff4d22e984 usr.sbin/pkg_install/view/pkg_view.1
--- a/usr.sbin/pkg_install/view/pkg_view.1      Wed Jul 23 23:03:00 2003 +0000
+++ b/usr.sbin/pkg_install/view/pkg_view.1      Thu Jul 24 23:14:51 2003 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pkg_view.1,v 1.1.2.4 2003/07/14 22:54:51 jlam Exp $
+.\"    $NetBSD: pkg_view.1,v 1.1.2.5 2003/07/24 23:14:53 jlam Exp $
 .\"
 .\" Copyright (c) 2003 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -52,7 +52,34 @@
 in the
 .Ar prefix
 directory.
+.Sh WARNING
+.Bf -emphasis
+Since the
+.Nm
+command may execute scripts or programs contained within 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, use the
+.Fl M
+flag to extract the package file, and inspect its contents and scripts
+to ensure it poses no danger to your system's integrity.
+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 package file.
+.Ef
+.Sh OPTIONS
 The following command-line options are supported:
 .Bl -tag -width indent
 .It Fl d Ar stowdir
@@ -140,6 +167,55 @@
 .Ev PREFIX
 environment variable.
 .El
+.Sh FILES
+.Bl -tag -width indent
+.It Pa <pkg-dbdir>/<package>/+INSTALL
+If the package contains an
+.Ar install
+script (see
+.Xr pkg_create 1 ) ,
+then after the package is added into a view, the script is executed
+with the following arguments:
+.Bl -tag -width package
+.It Ar package
+The name of the package being installed.
+.It Cm VIEW-INSTALL
+Keyword denoting that the script is to perform any actions needed after
+the package is added to a view.
+.El
+.Pp
+If the
+.Ar install
+script exits with a non-zero status code, the installation is terminated.
+.It Pa <pkg-dbdir>/<package>/+DEINSTALL
+If the package contains an
+.Ar deinstall
+script (see
+.Xr pkg_create 1 ) ,
+then before the package is removed from a view, the script is executed
+with the following arguments:
+.Bl -tag -width package
+.It Ar package
+The name of the package being installed.
+.It Cm VIEW-DEINSTALL
+Keyword denoting that the script is to perform any actions needed before
+the package is removed from a view.
+.El
+.Pp
+If the
+.Ar deinstall
+script exits with a non-zero status code, the de-installation is terminated.
+.El
+.Pp
+The
+.Ar install
+and
+.Ar deinstall
+scripts are called with the environment variable
+.Ev PKG_PREFIX
+set to the path to the
+.Ar view
+directory.
 .Sh SEE ALSO
 .Xr pkg_delete 1 ,
 .Xr linkfarm 1
diff -r 4ef2342b18b9 -r 05ff4d22e984 usr.sbin/pkg_install/view/pkg_view.sh
--- a/usr.sbin/pkg_install/view/pkg_view.sh     Wed Jul 23 23:03:00 2003 +0000
+++ b/usr.sbin/pkg_install/view/pkg_view.sh     Thu Jul 24 23:14:51 2003 +0000
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# $NetBSD: pkg_view.sh,v 1.1.2.12 2003/07/23 22:58:24 jlam Exp $
+# $NetBSD: pkg_view.sh,v 1.1.2.13 2003/07/24 23:14:53 jlam Exp $
 
 #
 # Copyright (c) 2001 Alistair G. Crooks.  All rights reserved.
@@ -35,7 +35,9 @@
 # set -x
 
 # set up program definitions
+chmodprog=/bin/chmod
 cpprog=/bin/cp
+envprog=/usr/bin/env
 findprog=/usr/bin/find
 grepprog=/usr/bin/grep
 linkfarmprog=/usr/sbin/linkfarm
@@ -53,7 +55,7 @@
 }
 
 version() {
-       echo "20030713"
+       echo "20030724"
        exit 0
 }
 
@@ -119,7 +121,7 @@
 while [ $# -gt 0 ]; do
        case $action in
        add)
-               if [ -f ${pkg_dbdir}/$1/+CONTENTS ]; then
+               if [ -f ${pkg_dbdir}/$1/+DEPOT]; then
                        echo "Package $1 already exists in $viewstr."
                else
                        dbs=`(cd ${depot_pkg_dbdir}/$1; echo +*)`
@@ -134,6 +136,11 @@
                        (cd ${depot_pkg_dbdir}/$1; $paxprog -rwpe '-s|\./\+VIEWS$||' ./+* ${pkg_dbdir}/$1)
                        $sedprog -e 's|'${depot_pkg_dbdir}/$1'|'${targetdir}'|g' < ${depot_pkg_dbdir}/$1/+CONTENTS > ${pkg_dbdir}/$1/+CONTENTS
                        echo "${depot_pkg_dbdir}/$1" > ${pkg_dbdir}/$1/+DEPOT
+                       if [ -f ${pkg_dbdir}/$1/+INSTALL ]; then
+                               $chmodprog +x ${pkg_dbdir}/$1/+INSTALL
+                               $envprog -i PKG_PREFIX=${targetdir} ${pkg_dbdir}/$1/+INSTALL $1 VIEW-INSTALL
+                               exit $?
+                       fi
                fi
                ;;
        check)
@@ -141,9 +148,18 @@
                exit $?
                ;;
        delete)
-               if [ ! -f ${pkg_dbdir}/$1/+CONTENTS ]; then
+               if [ ! -f ${pkg_dbdir}/$1/+DEPOT ]; then
                        echo "Package $1 does not exist in $viewstr."
                else
+                       if [ -f ${pkg_dbdir}/$1/+DEINSTALL ]; then
+                               $chmodprog +x ${pkg_dbdir}/$1/+DEINSTALL
+                               $envprog -i PKG_PREFIX=${targetdir} ${pkg_dbdir}/$1/+DEINSTALL $1 VIEW-DEINSTALL
+                               ec=$?
+                               if [ $ec != 0 ]; then
+                                       echo "De-install script returned an error."
+                                       exit $ec
+                               fi
+                       fi
                        dbs=`(cd ${depot_pkg_dbdir}/$1; echo +*)`
                        env PLIST_IGNORE_FILES="${ignorefiles} $dbs" $linkfarmprog -D --target=${targetdir} --dir=${depot_pkg_dbdir} $1
                        temp=${depot_pkg_dbdir}/$1/+VIEWS.$$



Home | Main Index | Thread Index | Old Index