Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge branch 'master' of github.com:freebsd/pkg
Matthew Seaman committed 11 years ago
commit 23b4ab6e3c920e9976cd26ee1406cae8c6f2cc40
parent 073517d
12 files changed +293 -25
modified compat/gr_util.c
@@ -32,6 +32,7 @@
#include <sys/errno.h>
#include <sys/stat.h>

+
#include <errno.h>
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
modified configure.ac
@@ -100,8 +100,6 @@ AC_CHECK_HEADERS_ONCE([sys/endian.h])
AC_CHECK_HEADERS_ONCE([fcntl.h])
AC_CHECK_HEADERS_ONCE([dlfcn.h])
AC_CHECK_HEADERS_ONCE([memory.h])
-
AC_CHECK_HEADERS_ONCE([sys/types.h])
-
AC_CHECK_HEADERS_ONCE([sys/stat.h])
AC_CHECK_HEADERS_ONCE([stdlib.h])
AC_CHECK_HEADERS_ONCE([string.h])
AC_CHECK_HEADERS_ONCE([memory.h])
@@ -130,11 +128,13 @@ AC_CHECK_HEADERS_ONCE([libgen.h])
AC_CHECK_HEADERS_ONCE([stdio.h])
AC_CHECK_HEADERS_ONCE([float.h])
AC_CHECK_HEADERS_ONCE([math.h])
+
AC_CHECK_HEADERS_ONCE([readpassphrase.h])
AC_CHECK_HEADERS_ONCE([osreldate.h])
AC_CHECK_HEADERS_ONCE([sys/socket.h])
AC_CHECK_HEADERS_ONCE([netinet/in.h])
AC_CHECK_HEADERS_ONCE([netinet/in6.h])
AC_CHECK_HEADERS_ONCE([sys/statfs.h])
+
AC_CHECK_HEADERS_ONCE([sys/statvfs.h])
AC_CHECK_HEADERS_ONCE([dirent.h], [sys/ndir.h], [sys/dir.h], [ndir.h])
AC_CHECK_HEADERS_ONCE([sys/capability.h])
AC_CHECK_HEADERS_ONCE([sys/capsicum.h])
@@ -329,6 +329,20 @@ if test "$ac_cv_func_dirname" = yes ; then
	AC_DEFINE(HAVE_BSD_DIRNAME, 1, [Define 1 if you have 'dirname(const char *)' function.])
fi

+
AC_CACHE_CHECK(for BSD statfs(const char *path, struct statfs *buf),
+
               ac_cv_func_dirname,
+
               [ac_save_CFLAGS="$CFLAGS"
+
		CFLAGS="-Werror $CFLAGS"
+
		AC_TRY_COMPILE([#include <sys/param.h>
+
     					#include <sys/mount.h>],
+
                               [static int *(*ac_test_statfs)(const char *path, struct statfs *buf) = statfs; ac_test_statfs("");],
+
                               [ac_cv_func_statfs=yes],
+
                               [ac_cv_func_statfs=no])
+
		CFLAGS="$ac_save_CFLAGS"])
+
if test "$ac_cv_func_statfs" = yes ; then
+
	AC_DEFINE(HAVE_STATFS, 1, [Define 1 if you have 'statfs(const char *path, struct statfs *buf)' function.])
+
fi
+

AC_CHECK_FUNCS(chflags chflagsat)

AC_CHECK_FUNCS(basename_r)
modified libpkg/pkg_delete.c
@@ -157,7 +157,7 @@ pkg_add_dir_to_del(struct pkg *pkg, const char *file, const char *dir)

	if (pkg->dir_to_del_len + 1 > pkg->dir_to_del_cap) {
		pkg->dir_to_del_cap += 64;
-
		pkg->dir_to_del = reallocf(pkg->dir_to_del,
+
		pkg->dir_to_del = realloc(pkg->dir_to_del,
		    pkg->dir_to_del_cap * sizeof(char *));
	}

@@ -379,7 +379,7 @@ pkg_delete_dir(struct pkg *pkg, struct pkg_dir *dir)
	} else {
		if (pkg->dir_to_del_len + 1 > pkg->dir_to_del_cap) {
			pkg->dir_to_del_cap += 64;
-
			pkg->dir_to_del = reallocf(pkg->dir_to_del,
+
			pkg->dir_to_del = realloc(pkg->dir_to_del,
			    pkg->dir_to_del_cap * sizeof(char *));
		}
		pkg->dir_to_del[pkg->dir_to_del_len++] = strdup(path);
modified libpkg/pkg_jobs.c
@@ -53,6 +53,8 @@

#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
+
#elif defined(HAVE_SYS_STATVFS_H)
+
#include <sys/statvfs.h>
#endif

#include "utarray.h"
@@ -2008,9 +2010,8 @@ pkg_jobs_fetch(struct pkg_jobs *j)
{
	struct pkg *p = NULL;
	struct pkg_solved *ps;
-
	struct statfs fs;
	struct stat st;
-
	int64_t dlsize = 0;
+
	int64_t dlsize = 0, fs_avail = -1;
	const char *cachedir = NULL;
	char cachedpath[MAXPATHLEN];
	bool mirror = (j->flags & PKG_FLAG_FETCH_MIRROR) ? true : false;
@@ -2045,6 +2046,8 @@ pkg_jobs_fetch(struct pkg_jobs *j)
	if (dlsize == 0)
		return (EPKG_OK);

+
#ifdef HAVE_STATFS
+
	struct statfs fs;
	while (statfs(cachedir, &fs) == -1) {
		if (errno == ENOENT) {
			if (mkdirs(cachedir) != EPKG_OK)
@@ -2054,14 +2057,27 @@ pkg_jobs_fetch(struct pkg_jobs *j)
			return (EPKG_FATAL);
		}
	}
+
	fs_avail = fs.f_bsize * (int64_t)fs.f_bavail;
+
#elif defined(HAVE_SYS_STATVFS_H)
+
	struct statvfs fs;
+
	while (statvfs(cachedir, &fs) == -1) {
+
		if (errno == ENOENT) {
+
			if (mkdirs(cachedir) != EPKG_OK)
+
				return (EPKG_FATAL);
+
		} else {
+
			pkg_emit_errno("statvfs", cachedir);
+
			return (EPKG_FATAL);
+
		}
+
	}
+
	fs_avail = fs.f_bsize * (int64_t)fs.f_bavail;
+
#endif

-
	if (dlsize > ((int64_t)fs.f_bsize * (int64_t)fs.f_bavail)) {
-
		int64_t fsize = (int64_t)fs.f_bsize * (int64_t)fs.f_bavail;
+
	if (fs_avail != -1 && dlsize > fs_avail) {
		char dlsz[9], fsz[9];

		humanize_number(dlsz, sizeof(dlsz), dlsize, "B",
		    HN_AUTOSCALE, HN_IEC_PREFIXES);
-
		humanize_number(fsz, sizeof(fsz), fsize, "B",
+
		humanize_number(fsz, sizeof(fsz), fs_avail, "B",
		    HN_AUTOSCALE, HN_IEC_PREFIXES);
		pkg_emit_error("Not enough space in %s, needed %s available %s",
		    cachedir, dlsz, fsz);
modified libpkg/pkg_ports.c
@@ -546,7 +546,7 @@ parse_post(struct plist *p)
			continue;
		if (p->post_patterns.len >= p->post_patterns.cap) {
			p->post_patterns.cap += 10;
-
			p->post_patterns.patterns = reallocf(p->post_patterns.patterns, p->post_patterns.cap * sizeof (char *));
+
			p->post_patterns.patterns = realloc(p->post_patterns.patterns, p->post_patterns.cap * sizeof (char *));
		}
		p->post_patterns.patterns[p->post_patterns.len++] = token;
	}
modified libpkg/pkgdb.c
@@ -59,6 +59,8 @@

#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
+
#elif defined(HAVE_SYS_STATVFS_H)
+
#include <sys/statvfs.h>
#endif

#include "pkg.h"
@@ -898,7 +900,6 @@ int
pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
{
	struct pkgdb	*db = NULL;
-
	struct statfs	 stfs;
	bool		 reopen = false;
	bool		 profile = false;
	char		 localpath[MAXPATHLEN];
@@ -954,15 +955,25 @@ pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)

		sqlite3_initialize();

-
#ifdef MNT_LOCAL
		/*
		 * Fall back on unix-dotfile locking strategy if on a network filesystem
		 */
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
		struct statvfs stfs;
+

+
		if (statvfs(dbdir, &stfs) == 0) {
+
			if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
+
				sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
		}
+
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
+
		struct statfs stfs;
+

		if (statfs(dbdir, &stfs) == 0) {
			if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
				sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
		}
#endif
+

		if (sqlite3_open(localpath, &db->sqlite) != SQLITE_OK) {
			ERROR_SQLITE(db->sqlite, "sqlite open");
			pkgdb_close(db);
modified libpkg/private/pkg.h
@@ -76,6 +76,17 @@
#define archive_write_add_filter_none(a) archive_write_set_compression_none(a)
#define archive_read_support_filter_all(a) archive_read_support_compression_all(a)
#define archive_read_support_filter_none(a) archive_read_support_compression_none(a)
+
#define archive_read_free archive_read_finish
+
#define archive_write_free archive_write_finish
+

+
#ifndef UF_NOUNLINK
+
#define UF_NOUNLINK 0
+
#endif
+

+
#ifndef SF_NOUNLINK
+
#define SF_NOUNLINK 0
+
#endif
+

#endif

#define EXTRACT_ARCHIVE_FLAGS  (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM | \
modified libpkg/repo/binary/init.c
@@ -41,6 +41,8 @@

#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
+
#elif defined(HAVE_SYS_STATVFS_H)
+
#include <sys/statvfs.h>
#endif

#include "pkg.h"
@@ -310,11 +312,19 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
	sqlite3_initialize();
	dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));

-
#ifdef MNT_LOCAL
-
	struct statfs stfs;
	/*
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
	struct statvfs stfs;
+

+
	if (statvfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
+
	struct statfs stfs;
+

	if (statfs(dbdir, &stfs) == 0) {
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
@@ -420,11 +430,19 @@ pkg_repo_binary_create(struct pkg_repo *repo)
	if (access(filepath, R_OK) == 0)
		return (EPKG_CONFLICT);

-
#ifdef MNT_LOCAL
-
	struct statfs stfs;
	/*
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
	struct statvfs stfs;
+

+
	if (statvfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
+
	struct statfs stfs;
+

	if (statfs(dbdir, &stfs) == 0) {
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
added src/readpassphrase_compat.h
@@ -0,0 +1,192 @@
+
/*	$OpenBSD: readpassphrase.c,v 1.24 2013/11/24 23:51:29 deraadt Exp $	*/
+

+
/*
+
 * Copyright (c) 2000-2002, 2007, 2010
+
 *	Todd C. Miller <Todd.Miller@courtesan.com>
+
 *
+
 * Permission to use, copy, modify, and distribute this software for any
+
 * purpose with or without fee is hereby granted, provided that the above
+
 * copyright notice and this permission notice appear in all copies.
+
 *
+
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
 *
+
 * Sponsored in part by the Defense Advanced Research Projects
+
 * Agency (DARPA) and Air Force Research Laboratory, Air Force
+
 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+
 */
+

+
#ifndef READPASSPHRASE_COMPAT_H
+
#define READPASSPHRASE_COMPAT_H
+

+
#include <ctype.h>
+
#include <errno.h>
+
#include <fcntl.h>
+
#include <paths.h>
+
#include <pwd.h>
+
#include <signal.h>
+
#include <string.h>
+
#include <termios.h>
+
#include <unistd.h>
+

+
#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */
+
#define RPP_ECHO_ON 0x01 /* Leave echo on. */
+
#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */
+
#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
+
#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
+
#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
+
#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
+

+
#ifndef _NSIG
+
#define _NSIG 32
+
#endif
+

+
static volatile sig_atomic_t signo[_NSIG];
+
static void handler(int);
+

+
static char *
+
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
+
{
+
	ssize_t nr;
+
	int input, output, save_errno, i, need_restart;
+
	char ch, *p, *end;
+
	struct termios term, oterm;
+
	struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
+
	struct sigaction savetstp, savettin, savettou, savepipe;
+

+
	/* I suppose we could alloc on demand in this case (XXX). */
+
	if (bufsiz == 0) {
+
		errno = EINVAL;
+
		return(NULL);
+
	}
+

+
restart:
+
	for (i = 0; i < _NSIG; i++)
+
		signo[i] = 0;
+
	nr = -1;
+
	save_errno = 0;
+
	need_restart = 0;
+
	/*
+
	 * Read and write to /dev/tty if available.  If not, read from
+
	 * stdin and write to stderr unless a tty is required.
+
	 */
+
	if ((flags & RPP_STDIN) ||
+
	    (input = output = open("/dev/tty", O_RDWR)) == -1) {
+
		if (flags & RPP_REQUIRE_TTY) {
+
			errno = ENOTTY;
+
			return(NULL);
+
		}
+
		input = STDIN_FILENO;
+
		output = STDERR_FILENO;
+
	}
+

+
	/*
+
	 * Turn off echo if possible.
+
	 * If we are using a tty but are not the foreground pgrp this will
+
	 * generate SIGTTOU, so do it *before* installing the signal handlers.
+
	 */
+
	if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
+
		memcpy(&term, &oterm, sizeof(term));
+
		if (!(flags & RPP_ECHO_ON))
+
			term.c_lflag &= ~(ECHO | ECHONL);
+
		(void)tcsetattr(input, TCSAFLUSH, &term);
+
	} else {
+
		memset(&term, 0, sizeof(term));
+
		term.c_lflag |= ECHO;
+
		memset(&oterm, 0, sizeof(oterm));
+
		oterm.c_lflag |= ECHO;
+
	}
+

+
	/*
+
	 * Catch signals that would otherwise cause the user to end
+
	 * up with echo turned off in the shell.  Don't worry about
+
	 * things like SIGXCPU and SIGVTALRM for now.
+
	 */
+
	sigemptyset(&sa.sa_mask);
+
	sa.sa_flags = 0;		/* don't restart system calls */
+
	sa.sa_handler = handler;
+
	(void)sigaction(SIGALRM, &sa, &savealrm);
+
	(void)sigaction(SIGHUP, &sa, &savehup);
+
	(void)sigaction(SIGINT, &sa, &saveint);
+
	(void)sigaction(SIGPIPE, &sa, &savepipe);
+
	(void)sigaction(SIGQUIT, &sa, &savequit);
+
	(void)sigaction(SIGTERM, &sa, &saveterm);
+
	(void)sigaction(SIGTSTP, &sa, &savetstp);
+
	(void)sigaction(SIGTTIN, &sa, &savettin);
+
	(void)sigaction(SIGTTOU, &sa, &savettou);
+

+
	if (!(flags & RPP_STDIN))
+
		(void)write(output, prompt, strlen(prompt));
+
	end = buf + bufsiz - 1;
+
	p = buf;
+
	while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
+
		if (p < end) {
+
			if ((flags & RPP_SEVENBIT))
+
				ch &= 0x7f;
+
			if (isalpha((unsigned char)ch)) {
+
				if ((flags & RPP_FORCELOWER))
+
					ch = (char)tolower((unsigned char)ch);
+
				if ((flags & RPP_FORCEUPPER))
+
					ch = (char)toupper((unsigned char)ch);
+
			}
+
			*p++ = ch;
+
		}
+
	}
+
	*p = '\0';
+
	save_errno = errno;
+
	if (!(term.c_lflag & ECHO))
+
		(void)write(output, "\n", 1);
+

+
	/* Restore old terminal settings and signals. */
+
	if (memcmp(&term, &oterm, sizeof(term)) != 0) {
+
		while (tcsetattr(input, TCSAFLUSH, &oterm) == -1 &&
+
		    errno == EINTR && !signo[SIGTTOU])
+
			continue;
+
	}
+
	(void)sigaction(SIGALRM, &savealrm, NULL);
+
	(void)sigaction(SIGHUP, &savehup, NULL);
+
	(void)sigaction(SIGINT, &saveint, NULL);
+
	(void)sigaction(SIGQUIT, &savequit, NULL);
+
	(void)sigaction(SIGPIPE, &savepipe, NULL);
+
	(void)sigaction(SIGTERM, &saveterm, NULL);
+
	(void)sigaction(SIGTSTP, &savetstp, NULL);
+
	(void)sigaction(SIGTTIN, &savettin, NULL);
+
	(void)sigaction(SIGTTOU, &savettou, NULL);
+
	if (input != STDIN_FILENO)
+
		(void)close(input);
+

+
	/*
+
	 * If we were interrupted by a signal, resend it to ourselves
+
	 * now that we have restored the signal handlers.
+
	 */
+
	for (i = 0; i < _NSIG; i++) {
+
		if (signo[i]) {
+
			kill(getpid(), i);
+
			switch (i) {
+
			case SIGTSTP:
+
			case SIGTTIN:
+
			case SIGTTOU:
+
				need_restart = 1;
+
			}
+
		}
+
	}
+
	if (need_restart)
+
		goto restart;
+

+
	if (save_errno)
+
		errno = save_errno;
+
	return(nr == -1 ? NULL : buf);
+
}
+

+
static void handler(int s)
+
{
+

+
	signo[s] = 1;
+
}
+

+
#endif
modified src/repo.c
@@ -24,6 +24,10 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#ifdef HAVE_CONFIG_H
+
#include "pkg_config.h"
+
#endif
+

#include <bsd_compat.h>
#include <getopt.h>
#include <signal.h>
@@ -31,10 +35,12 @@
#include <stdio.h>
#include <string.h>

-
#ifdef HAVE_BSD_READPASSPHRASE_H
+
#ifdef HAVE_READPASSPHRASE_H
+
#include <readpassphrase.h>
+
#elif defined(HAVE_BSD_READPASSPHRASE_H)
#include <bsd/readpassphrase.h>
#else
-
#include <readpassphrase.h>
+
#include "readpassphrase_compat.h"
#endif

#include <unistd.h>
modified src/set.c
@@ -96,7 +96,6 @@ exec_set(int argc, char **argv)
	int64_t		 newautomatic = -1;
	bool		 automatic = false;
	bool		 rc = false;
-
	const char	*errstr;
	const char	*changed = NULL;
	char		*newvalue = NULL;
	char		*oldvalue = NULL;
@@ -122,11 +121,11 @@ exec_set(int argc, char **argv)
		switch (ch) {
		case 'A':
			sets |= AUTOMATIC;
-
			newautomatic = strtonum(optarg, 0, 1, &errstr);
-
			if (errstr)
+
			newautomatic = optarg[0] - '0';
+
			if (newautomatic != 0 & newautomatic != 1)
				errx(EX_USAGE, "Wrong value for -A. "
-
				    "Expecting 0 or 1, got: %s (%s)",
-
				    optarg, errstr);
+
				    "Expecting 0 or 1, got: %s",
+
				    optarg);
			break;
		case 'a':
			match = MATCH_ALL;
modified src/version.c
@@ -565,7 +565,7 @@ exec_buf(struct sbuf *res, char **argv) {
	}

	if ((spawn_err = posix_spawn_file_actions_init(&actions)) != 0) {
-
		warnc(spawn_err, "%s", argv[0]);
+
		warnx("%s:%s", argv[0], strerror(spawn_err));
		return (0);
	}

@@ -578,7 +578,7 @@ exec_buf(struct sbuf *res, char **argv) {
	    (spawn_err = posix_spawnp(&pid, argv[0], &actions, NULL,
	    argv, environ)) != 0) {
		posix_spawn_file_actions_destroy(&actions);
-
		warnc(spawn_err, "%s", argv[0]);
+
		warnx("%s:%s", argv[0], strerror(spawn_err));
		return (0);
	}
	posix_spawn_file_actions_destroy(&actions);