diff options
author | joerg <joerg> | 2008-04-04 15:47:01 +0000 |
---|---|---|
committer | joerg <joerg> | 2008-04-04 15:47:01 +0000 |
commit | 034f8dc20ddeec3ba9631515760dbfbc0d351583 (patch) | |
tree | f0ae37369241b26835668278882abc53fa732497 /pkgtools | |
parent | 58c6062d2b3f46f7a57bbbc888ee51d923bd65ba (diff) | |
download | pkgsrc-034f8dc20ddeec3ba9631515760dbfbc0d351583.tar.gz |
Also switch pkg_admin's fetch-vulnerabilities implementation to
libfetch.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkg_install/files/admin/audit.c | 104 |
1 files changed, 26 insertions, 78 deletions
diff --git a/pkgtools/pkg_install/files/admin/audit.c b/pkgtools/pkg_install/files/admin/audit.c index 5d2ddc00745..523de63451a 100644 --- a/pkgtools/pkg_install/files/admin/audit.c +++ b/pkgtools/pkg_install/files/admin/audit.c @@ -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 @@ __RCSID("$NetBSD: audit.c,v 1.4 2008/03/20 20:26:52 joerg Exp $"); #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 @@ __RCSID("$NetBSD: audit.c,v 1.4 2008/03/20 20:26:52 joerg Exp $"); #include <nbcompat/unistd.h> #endif +#include <fetch.h> + #include "admin.h" #include "lib.h" @@ -326,107 +325,56 @@ void 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"); - - 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]); + fprintf(stderr, "Fetching %s\n", pkg_vulnerabilities_url); - cur_len = 0; - buf_len = 32768; - if ((buf = malloc(buf_len + 1)) == NULL) { - error = "malloc failed"; - goto ftp_error; - } + f = fetchXGetURL(pkg_vulnerabilities_url, &st, ""); + if (f == NULL) + err(EXIT_FAILURE, "Could not fetch vulnerability file"); - 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; - } - } - - if (bytes_read == -1) { - error = "read from FTP process failed"; - goto ftp_error; - } - - waitpid(child, &status, 0); - close(fd[0]); + if (st.size > SSIZE_MAX - 1) + err(EXIT_FAILURE, "pkg-vulnerabilities is too large"); - if (status) - errx(EXIT_FAILURE, - "Download of pkg-vulnerabilities from %s failed", - pkg_vulnerabilities_url); + buf_len = st.size; + if ((buf = malloc(buf_len + 1)) == NULL) + err(EXIT_FAILURE, "malloc failed"); - buf[cur_len] = '\0'; + if (fetchIO_read(f, buf, buf_len) != buf_len) + err(EXIT_FAILURE, "Failure during fetch of pkg-vulnerabilities"); + buf[buf_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); } |