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/admin Also switch pkg_admin...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c1674f7bf4eb
branches:  trunk
changeset: 540586:c1674f7bf4eb
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Fri Apr 04 15:47:01 2008 +0000

description:
Also switch pkg_admin's fetch-vulnerabilities implementation to
libfetch.

diffstat:

 pkgtools/pkg_install/files/admin/audit.c |  104 +++++++-----------------------
 1 files changed, 26 insertions(+), 78 deletions(-)

diffs (167 lines):

diff -r ba952b0c5b67 -r c1674f7bf4eb pkgtools/pkg_install/files/admin/audit.c
--- a/pkgtools/pkg_install/files/admin/audit.c  Fri Apr 04 15:36:20 2008 +0000
+++ b/pkgtools/pkg_install/files/admin/audit.c  Fri Apr 04 15:47:01 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audit.c,v 1.4 2008/03/20 20:26:52 joerg Exp $  */
+/*     $NetBSD: audit.c,v 1.5 2008/04/04 15:47:01 joerg Exp $  */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -8,7 +8,7 @@
 #include <sys/cdefs.h>
 #endif
 #ifndef lint
-__RCSID("$NetBSD: audit.c,v 1.4 2008/03/20 20:26:52 joerg Exp $");
+__RCSID("$NetBSD: audit.c,v 1.5 2008/04/04 15:47:01 joerg Exp $");
 #endif
 
 /*-
@@ -46,9 +46,6 @@
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#if HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
 #if HAVE_ERR_H
 #include <err.h>
 #endif
@@ -73,6 +70,8 @@
 #include <nbcompat/unistd.h>
 #endif
 
+#include <fetch.h>
+
 #include "admin.h"
 #include "lib.h"
 
@@ -326,107 +325,56 @@
 fetch_pkg_vulnerabilities(int argc, char **argv)
 {
        struct pkg_vulnerabilities *pv_check;
-       const char *error;
-       pid_t child;
        char *buf, *decompressed_input;
-       size_t buf_len, cur_len, decompressed_len;
-       ssize_t bytes_read;
-       int fd[2], status;
+       size_t buf_len, decompressed_len;
+       struct url_stat st;
+       fetchIO *f;
+       int fd;
 
        parse_options(argc, argv);
        if (argc != optind)
                usage();
 
        if (verbose >= 2)
-               fprintf(stderr, "ftp -o - %s\n", pkg_vulnerabilities_url);
-
-       if (pipe(fd) == -1)
-               err(EXIT_FAILURE, "cannot create FTP data pipe");
+               fprintf(stderr, "Fetching %s\n", pkg_vulnerabilities_url);
 
-       child = vfork();
-       if (child == -1)
-               err(EXIT_FAILURE, "cannot fork FTP process");
-       if (child == 0) {
-               close(fd[0]);
-               close(STDOUT_FILENO);
-               if (dup2(fd[1], STDOUT_FILENO) == -1) {
-                       static const char err_msg[] =
-                           "cannot redirect stdout of FTP process\n";
-                       write(STDERR_FILENO, err_msg, sizeof(err_msg) - 1);
-                       _exit(255);
-               }
-               close(fd[1]);
-               execlp(fetch_cmd, fetch_cmd, "-o", "-",
-                   pkg_vulnerabilities_url, (char *)NULL);
-               _exit(255);
-       }
-       close(fd[1]);
+       f = fetchXGetURL(pkg_vulnerabilities_url, &st, "");
+       if (f == NULL)
+               err(EXIT_FAILURE, "Could not fetch vulnerability file");
 
-       cur_len = 0;
-       buf_len = 32768;
-       if ((buf = malloc(buf_len + 1)) == NULL) {
-               error = "malloc failed";
-               goto ftp_error;
-       }
+       if (st.size > SSIZE_MAX - 1)
+               err(EXIT_FAILURE, "pkg-vulnerabilities is too large");
 
-       while ((bytes_read = read(fd[0], buf + cur_len, buf_len - cur_len)) > 0) {
-               cur_len += bytes_read;
-               if (cur_len * 2 < buf_len)
-                       continue;
-               if (cur_len >= SSIZE_MAX / 2) {
-                       error = "pkg-vulnerabilies too large";
-                       goto ftp_error;
-               }
-               buf_len *= 2;
-               if ((buf = realloc(buf, buf_len + 1)) == NULL) {
-                       error = "realloc failed";
-                       goto ftp_error;
-               }
-       }
+       buf_len = st.size;
+       if ((buf = malloc(buf_len + 1)) == NULL)
+               err(EXIT_FAILURE, "malloc failed");
 
-       if (bytes_read == -1) {
-               error = "read from FTP process failed";
-               goto ftp_error;
-       }
-
-       waitpid(child, &status, 0);
-       close(fd[0]);
+       if (fetchIO_read(f, buf, buf_len) != buf_len)
+               err(EXIT_FAILURE, "Failure during fetch of pkg-vulnerabilities");
+       buf[buf_len] = '\0';
 
-       if (status)
-               errx(EXIT_FAILURE,
-                   "Download of pkg-vulnerabilities from %s failed",
-                   pkg_vulnerabilities_url);
-
-       buf[cur_len] = '\0';
-
-       if (decompress_buffer(buf, cur_len, &decompressed_input,
+       if (decompress_buffer(buf, buf_len, &decompressed_input,
            &decompressed_len)) {
                pv_check = parse_pkg_vulnerabilities(decompressed_input,
                    decompressed_len, check_signature);
                free(decompressed_input);
        } else {
-               pv_check = parse_pkg_vulnerabilities(buf, cur_len,
+               pv_check = parse_pkg_vulnerabilities(buf, buf_len,
                    check_signature);
        }
        free_pkg_vulnerabilities(pv_check);
 
-       fd[0] = open(pkg_vulnerabilities_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
-       if (fd[0] == -1)
+       fd = open(pkg_vulnerabilities_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+       if (fd == -1)
                err(EXIT_FAILURE, "Cannot create pkg-vulnerability file %s",
                    pkg_vulnerabilities_file);
 
-       if (write(fd[0], buf, cur_len) != cur_len)
+       if (write(fd, buf, buf_len) != buf_len)
                err(EXIT_FAILURE, "Cannot write pkg-vulnerability file");
-       if (close(fd[0]) == -1)
+       if (close(fd) == -1)
                err(EXIT_FAILURE, "Cannot close pkg-vulnerability file after write");
 
        free(buf);
 
        exit(EXIT_SUCCESS);
-
- ftp_error:
-       (void)kill(child, SIGTERM);
-       (void)close(fd[0]);
-       (void)waitpid(child, &status, 0);
-       err(EXIT_FAILURE, error);
 }



Home | Main Index | Thread Index | Old Index