pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files Replace note_whats_installe...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/105d459c4bbd
branches:  trunk
changeset: 531950:105d459c4bbd
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Wed Aug 08 22:33:38 2007 +0000

description:
Replace note_whats_installed, add_to_list_fn and generally most
users of findbestmatchingname and findmatching name with more
descriptive and easier to use iterator functions. This functions
are a first step to abstract away pkgdb layout from most parts of
the code. It also helps to reduce side effects and point out potential
bugs in this code.

Fix a potential, but practically irrelevant buffer overflow.

No longer allow symbolic links directly in pkgdb to store the meta
data of individual packages outside. E.g. /var/db/pkg/atk-1.18.0
must be a directory and not point to it. This is not yet enforced in
all parts of the code, more changes will follow.

Bump version to 20070808.

diffstat:

 pkgtools/pkg_install/files/add/perform.c                   |   74 +-
 pkgtools/pkg_install/files/admin/main.c                    |  135 ++--
 pkgtools/pkg_install/files/audit-packages/audit-packages.c |   77 +--
 pkgtools/pkg_install/files/create/perform.c                |   76 +-
 pkgtools/pkg_install/files/delete/main.c                   |    6 +-
 pkgtools/pkg_install/files/delete/perform.c                |   58 +-
 pkgtools/pkg_install/files/info/main.c                     |   10 +-
 pkgtools/pkg_install/files/info/perform.c                  |   98 +--
 pkgtools/pkg_install/files/lib/Makefile.in                 |    7 +-
 pkgtools/pkg_install/files/lib/iterate.c                   |  328 +++++++++++++
 pkgtools/pkg_install/files/lib/lib.h                       |   15 +-
 pkgtools/pkg_install/files/lib/str.c                       |   36 +-
 pkgtools/pkg_install/files/lib/version.h                   |    4 +-
 13 files changed, 585 insertions(+), 339 deletions(-)

diffs (truncated from 1479 to 300 lines):

diff -r 3af991d12448 -r 105d459c4bbd pkgtools/pkg_install/files/add/perform.c
--- a/pkgtools/pkg_install/files/add/perform.c  Wed Aug 08 22:20:44 2007 +0000
+++ b/pkgtools/pkg_install/files/add/perform.c  Wed Aug 08 22:33:38 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: perform.c,v 1.51 2007/07/30 08:09:14 joerg Exp $       */
+/*     $NetBSD: perform.c,v 1.52 2007/08/08 22:33:38 joerg Exp $       */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -14,7 +14,7 @@
 #if 0
 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
 #else
-__RCSID("$NetBSD: perform.c,v 1.51 2007/07/30 08:09:14 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.52 2007/08/08 22:33:38 joerg Exp $");
 #endif
 #endif
 
@@ -524,7 +524,7 @@
 
                if ((s = strrchr(PkgName, '-')) != NULL) {
                        char    buf[MaxPathSize];
-                       char    installed[MaxPathSize];
+                       char *best_installed;
 
                        /*
                         * See if the pkg is already installed. If so, we might
@@ -532,18 +532,19 @@
                         */
                        (void) snprintf(buf, sizeof(buf), "%.*s[0-9]*",
                                (int)(s - PkgName) + 1, PkgName);
-                       if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0) {
+                       best_installed = find_best_matching_installed_pkg(buf);
+                       if (best_installed) {
                                if (Replace && !Fake) {
                                        /* XXX Should list the steps in Fake mode */
                                        snprintf(replace_from, sizeof(replace_from), "%s/%s/" REQUIRED_BY_FNAME,
-                                                dbdir, installed);
+                                                dbdir, best_installed);
                                        snprintf(replace_via, sizeof(replace_via), "%s/.%s." REQUIRED_BY_FNAME,
-                                                dbdir, installed);
+                                                dbdir, best_installed);
                                        snprintf(replace_to, sizeof(replace_to), "%s/%s/" REQUIRED_BY_FNAME,
                                                 dbdir, PkgName);
 
                                        if (Verbose)
-                                               printf("Upgrading %s to %s.\n", installed, PkgName);
+                                               printf("Upgrading %s to %s.\n", best_installed, PkgName);
 
                                        if (fexists(replace_from)) {  /* Are there any dependencies? */
                                                /*
@@ -658,30 +659,34 @@
                                                printf("%s/pkg_delete -K %s '%s'\n",
                                                        BINDIR,
                                                        dbdir,
-                                                       installed);
+                                                       best_installed);
                                        }
-                                       fexec(BINDIR "/pkg_delete", "-K", dbdir, installed, NULL);
+                                       fexec(BINDIR "/pkg_delete", "-K", dbdir, best_installed, NULL);
                                } else if (!is_depoted_pkg) {
-                                       warnx("other version '%s' already installed", installed);
+                                       warnx("other version '%s' already installed", best_installed);
 
                                        errc = 1;
                                        goto success;   /* close enough for government work */
                                }
+                               free(best_installed);
                        }
                }
        }
 
        /* See if there are conflicting packages installed */
        for (p = Plist.head; p; p = p->next) {
-               char    installed[MaxPathSize];
+               char *best_installed;
 
                if (p->type != PLIST_PKGCFL)
                        continue;
                if (Verbose)
                        printf("Package `%s' conflicts with `%s'.\n", PkgName, p->name);
-               if (findmatchingname(dbdir, p->name, note_whats_installed, installed) > 0) {
+               best_installed = find_best_matching_installed_pkg(p->name);
+               if (best_installed) {
                        warnx("Conflicting package `%s'installed, please use\n"
-                             "\t\"pkg_delete %s\" first to remove it!", installed, installed);
+                             "\t\"pkg_delete %s\" first to remove it!",
+                             best_installed, best_installed);
+                       free(best_installed);
                        ++errc;
                }
        }
@@ -691,13 +696,14 @@
         */
        err_prescan=0;
        for (p = Plist.head; p; p = p->next) {
-               char installed[MaxPathSize];
+               char *best_installed;
                
                if (p->type != PLIST_PKGDEP)
                        continue;
                if (Verbose)
                        printf("Depends pre-scan: `%s' required.\n", p->name);
-               if (findmatchingname(dbdir, p->name, note_whats_installed, installed) <= 0) {
+               best_installed = find_best_matching_installed_pkg(p->name);
+               if (best_installed == NULL) {
                        /* 
                         * required pkg not found. look if it's available with a more liberal
                         * pattern. If so, this will lead to problems later (check on "some
@@ -729,8 +735,8 @@
                                (void) snprintf(buf, sizeof(buf),
                                    skip ? "%.*s[0-9]*" : "%.*s-[0-9]*",
                                    (int)(s - p->name) + skip, p->name);
-                               if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0)
-                               {
+                               best_installed = find_best_matching_installed_pkg(buf);
+                               if (best_installed) {
                                        int done = 0;
 
                                        if (Replace > 1)
@@ -752,15 +758,18 @@
                                        if (!done)
                                        {
                                                warnx("pkg `%s' required, but `%s' found installed.",
-                                                         p->name, installed);
+                                                         p->name, best_installed);
                                                if (Force) {
                                                        warnx("Proceeding anyway.");
                                                } else {
                                                        err_prescan++;
                                                }
                                        }
+                                       free(best_installed);
                                }
                        }
+               } else {
+                       free(best_installed);
                }
        }
        if (err_prescan > 0) {
@@ -772,7 +781,7 @@
 
        /* Now check the packing list for dependencies */
        for (exact = NULL, p = Plist.head; p; p = p->next) {
-               char    installed[MaxPathSize];
+               char *best_installed;
 
                if (p->type == PLIST_BLDDEP) {
                        exact = p->name;
@@ -785,7 +794,9 @@
                if (Verbose)
                        printf("Package `%s' depends on `%s'.\n", PkgName, p->name);
 
-               if (findmatchingname(dbdir, p->name, note_whats_installed, installed) != 1) {
+               best_installed = find_best_matching_installed_pkg(p->name);
+
+               if (best_installed == NULL) {
                        /* required pkg not found - need to pull in */
 
                        if (Fake) {
@@ -808,8 +819,10 @@
                                        errc += errc0;
                                }
                        }
-               } else if (Verbose) {
-                       printf(" - %s already installed.\n", installed);
+               } else {
+                       if (Verbose)
+                               printf(" - %s already installed.\n", best_installed);
+                       free(best_installed);
                }
        }
 
@@ -910,17 +923,14 @@
                            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, '/');
-                                       strcpy(t + 1, s);
-                                       free(s);
-                               } else {
+
+                               s = find_best_matching_installed_pkg(p->name);
+
+                               if (s == NULL)
                                        errx(EXIT_FAILURE, "Where did our dependency go?!");
-                                       /* this shouldn't happen... X-) */
-                               }
+
+                               (void) snprintf(contents, sizeof(contents), "%s/%s", dbdir, s);
+                               free(s);
                        }
                        strlcat(contents, "/", sizeof(contents));
                        strlcat(contents, REQUIRED_BY_FNAME, sizeof(contents));
diff -r 3af991d12448 -r 105d459c4bbd pkgtools/pkg_install/files/admin/main.c
--- a/pkgtools/pkg_install/files/admin/main.c   Wed Aug 08 22:20:44 2007 +0000
+++ b/pkgtools/pkg_install/files/admin/main.c   Wed Aug 08 22:33:38 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.21 2007/07/20 22:22:52 joerg Exp $  */
+/*     $NetBSD: main.c,v 1.22 2007/08/08 22:33:38 joerg Exp $  */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -8,7 +8,7 @@
 #include <sys/cdefs.h>
 #endif
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.21 2007/07/20 22:22:52 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.22 2007/08/08 22:33:38 joerg Exp $");
 #endif
 
 /*
@@ -83,7 +83,7 @@
 
 static int     quiet;
 
-static int checkpattern_fn(const char *, const char *, void *);
+static int checkpattern_fn(const char *, void *);
 static void set_unset_variable(char **, Boolean);
 
 /* print usage message and exit */
@@ -414,9 +414,9 @@
 }
 
 static int
-checkpattern_fn(const char *pattern, const char *pkg, void *vp)
+checkpattern_fn(const char *pkg, void *vp)
 {
-       int     rc;
+       int *got_match, rc;
 
        rc = chdir(pkg);
        if (rc == -1)
@@ -429,6 +429,9 @@
 
        chdir("..");
 
+       got_match = vp;
+       *got_match = 1;
+
        return 0;
 }
 
@@ -551,32 +554,26 @@
                                err(EXIT_FAILURE, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR());
 
                        while (*argv != NULL) {
-                               if (ispkgpattern(*argv)) {
-                                       if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) <= 0)
-                                               errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
-                               } else {
-                                       rc = chdir(*argv);
-                                       if (rc == -1) {
-                                               /* found nothing - try 'pkg-[0-9]*' */
-                                               char try[MaxPathSize];
-                                       
-                                               snprintf(try, sizeof(try), "%s-[0-9]*", *argv);
-                                               if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
-                                                                    checkpattern_fn, NULL) <= 0) {
+                               int got_match;
+
+                               got_match = 0;
+                               if (match_installed_pkgs(*argv, checkpattern_fn, &got_match) == -1)
+                                       errx(EXIT_FAILURE, "Cannot process pkdbdb");
+                               if (got_match == 0) {
+                                       char *pattern;
 
-                                                       errx(EXIT_FAILURE, "cannot find package %s", *argv);
-                                               } else {
-                                                       /* nothing to do - all the work is/was
-                                                        * done in checkpattern_fn() */
-                                               }
-                                       } else {
-                                               check1pkg(*argv);
-                                               if (!quiet) {
-                                                       printf(".");
-                                               }
+                                       if (ispkgpattern(*argv))
+                                               errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
+
+                                       if (asprintf(&pattern, "%s-[0-9]*", *argv) == -1)
+                                               errx(EXIT_FAILURE, "asprintf failed");
 
-                                               chdir("..");
-                                       }
+                                       if (match_installed_pkgs(*argv, checkpattern_fn, &got_match) == -1)
+                                               errx(EXIT_FAILURE, "Cannot process pkdbdb");
+
+                                       if (got_match == 0)
+                                               errx(EXIT_FAILURE, "cannot find package %s", *argv);
+                                       free(pattern);
                                }
 
                                argv++;
@@ -751,32 +748,36 @@
        return 0;



Home | Main Index | Thread Index | Old Index