Skip to content

Commit

Permalink
Tarsnap 1.0.18
Browse files Browse the repository at this point in the history
Changes since 1.0.17:
* Many portability fixes. Tarsnap should now build and run on
  FreeBSD, Linux (success has been reported on Debian, Ubuntu,
  CentOS, Slackware, Gentoo, and RedHat), OS X, NetBSD, OpenBSD,
  and OpenSolaris. Thanks to "Triskelios" (IRC nick), "WEiRDJE"
  (IRC nick), Thomas Hurst, and Justin Haynes for their help with
  testing and fixing portability issues.
* Minor bugfixes (mostly harmless).
  • Loading branch information
cperciva authored and gperciva committed Dec 25, 2008
1 parent b8dcf6c commit d54e4b0
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 34 deletions.
21 changes: 11 additions & 10 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ tarsnap_SOURCES= \
lib/crypto/crypto_verify_bytes.c \
lib/crypto/crypto_keys_server.c \
lib/crypto/crypto_dh_group14.c \
lib/util/asprintf.c \
lib/util/dirutil.c \
lib/util/entropy.c \
lib/util/hexify.c \
Expand Down Expand Up @@ -231,11 +232,13 @@ tarsnap_keygen_SOURCES= \
lib/crypto/crypto_verify_bytes.c \
lib/crypto/crypto_keys_server.c \
lib/crypto/crypto_dh_group14.c \
lib/util/asprintf.c \
lib/util/entropy.c

tarsnap_keygen_CFLAGS= \
-I$(top_builddir)/tar \
-I${top_builddir}/libarchive \
tarsnap_keygen_LDADD= -lcrypto
tarsnap_keygen_CFLAGS= \
-I$(top_builddir)/tar \
-I${top_builddir}/libarchive \
-I$(top_builddir)/lib/netpacket \
-I$(top_builddir)/lib/netproto \
-I$(top_builddir)/lib/network \
Expand All @@ -244,8 +247,6 @@ tarsnap_keygen_CFLAGS= \
-I$(top_builddir)/lib/util \
-DUSERAGENT=\"tarsnap-keygen-${VERSION}\"

tarsnap_keygen_LDADD= -lcrypto

tarsnap_keygen_dist_man_MANS= keygen/tarsnap-keygen.1

#
Expand All @@ -270,18 +271,18 @@ tarsnap_keymgmt_SOURCES= \
lib/crypto/crypto_verify_bytes.c \
lib/crypto/crypto_keys_server.c \
lib/crypto/crypto_dh_group14.c \
lib/util/asprintf.c \
lib/util/entropy.c

tarsnap_keymgmt_CFLAGS= \
-I$(top_builddir)/tar \
-I${top_builddir}/libarchive \
tarsnap_keymgmt_LDADD= -lcrypto
tarsnap_keymgmt_CFLAGS= \
-I$(top_builddir)/tar \
-I${top_builddir}/libarchive \
-I$(top_builddir)/lib/datastruct \
-I${top_builddir}/lib/crypto \
-I$(top_builddir)/lib/util \
-DUSERAGENT=\"tarsnap-keygen-${VERSION}\"

tarsnap_keymgmt_LDADD= -lcrypto

tarsnap_keymgmt_dist_man_MANS= keymgmt/tarsnap-keymgmt.1

# Tarsnap sample configuration file
Expand Down
14 changes: 14 additions & 0 deletions actarsnap.m4
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@ esac
AC_SUBST([HAVE_EXT2FS_EXT2_FS_H])
])# CHECK_LINUX_EXT2FS

# CHECK_SOLARIS_PATHS
# -------------------
AC_DEFUN([CHECK_SOLARIS_PATHS],
[AC_REQUIRE([AC_CANONICAL_TARGET])
case $target_os in
*solaris* | *sunos*)
CPPFLAGS="${CPPFLAGS} -I/usr/sfw/include"
LDFLAGS="${LDFLAGS} -L/usr/sfw/lib -R/usr/sfw/lib"
LIBS="${LIBS} -lsocket"
;;
esac
])# CHECK_SOLARIS_PATHS
8 changes: 7 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ AC_CHECK_HEADERS([stdint.h stdlib.h string.h sys/acl.h sys/ioctl.h])
AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/select.h sys/time.h sys/utime.h])
AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h])

# If we're on Solaris, we need to add some extra paths to the Makefile.
# This needs to be done *before* we look for OpenSSL; otherwise we won't
# be able to find it...
CHECK_SOLARIS_PATHS

# Checks for libraries. While libbz2 is optional (if it is not present,
# support for @archive.bz2 will be lost, but that's all), libz and
# libcrypto are necesasry.
Expand All @@ -110,6 +115,7 @@ CHECK_FREEBSD_PORTRANGE_BUG

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_UID_T
AC_TYPE_MODE_T
# AC_TYPE_OFF_T defaults to "long", which limits us to 4GB files on
Expand Down Expand Up @@ -158,7 +164,7 @@ AC_FUNC_STAT
AC_FUNC_STRERROR_R
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([chflags chown chroot])
AC_CHECK_FUNCS([asprintf chflags chown chroot])
AC_CHECK_FUNCS([fchdir fchflags fchmod fchown fstat])
AC_CHECK_FUNCS([ftruncate futimes geteuid getopt_long getpid])
AC_CHECK_FUNCS([lchflags lchmod lchown])
Expand Down
2 changes: 0 additions & 2 deletions lib/crypto/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ typedef struct HMAC_SHA256Context {
SHA256_CTX octx;
} HMAC_SHA256_CTX;

__BEGIN_DECLS
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX *, const void *, size_t);
void SHA256_Final(unsigned char [32], SHA256_CTX *);
void HMAC_SHA256_Init(HMAC_SHA256_CTX *, const void *, size_t);
void HMAC_SHA256_Update(HMAC_SHA256_CTX *, const void *, size_t);
void HMAC_SHA256_Final(unsigned char [32], HMAC_SHA256_CTX *);
__END_DECLS

#endif /* !_SHA256_H_ */
1 change: 0 additions & 1 deletion lib/datastruct/patricia.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ patricia_insert(PATRICIA * P, const uint8_t * key, size_t keylen, void * rec)
* *recp = NULL;
* but this does not reduce the memory used by the tree as one might expect
* from reducing its size.
*/
void **
patricia_lookup(PATRICIA * P, const uint8_t * key, size_t keylen)
Expand Down
10 changes: 7 additions & 3 deletions lib/netproto/netproto_keyexchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ docallback(struct keyexchange_internal * KC, int status)
* its choice of 2^y mod p).
*/

/* User-agent name must be at least 1 and at most 255 characters. */
CTASSERT(strlen(USERAGENT) >= 1);
CTASSERT(strlen(USERAGENT) <= 255);
/*
* User-agent name must be at least 1 and at most 255 characters, not
* counting the final NUL byte. Some C compilers don't handle strlen of a
* constant string as a constant, so we use sizeof here instead.
*/
CTASSERT(sizeof(USERAGENT) >= 2);
CTASSERT(sizeof(USERAGENT) <= 256);

static uint8_t protovers = 0;
static uint8_t namelen = sizeof(USERAGENT) - 1;
Expand Down
19 changes: 19 additions & 0 deletions lib/network/network_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <sys/socket.h>
#include <sys/time.h>

#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -60,7 +61,11 @@ callback_buf(void * cookie, int status)
ssize_t len;
int rc = -1; /* If not callback or reset, we have an error. */
#ifndef HAVE_MSG_NOSIGNAL
#ifdef SO_NOSIGPIPE
int val;
#else
void (*oldsig)(int);
#endif
#endif

if (status != NETWORK_STATUS_OK) {
Expand All @@ -72,24 +77,38 @@ callback_buf(void * cookie, int status)

/* Try to read/write data to/from the buffer. */
#ifndef HAVE_MSG_NOSIGNAL
#ifdef SO_NOSIGPIPE
val = 1;

if (setsockopt(C->fd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(int))) {
status = NETWORK_STATUS_ERR;
goto docallback;
}
#else
if ((oldsig = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) {
warnp("signal(SIGPIPE)");
goto docallback;
}
#endif
#endif
oplen = C->buflen - C->bufpos;
if (oplen > *(C->bwlimit))
oplen = *(C->bwlimit);
len = (C->sendrecv)(C->fd, C->buf + C->bufpos, oplen, C->flags);
#ifndef HAVE_MSG_NOSIGNAL
#ifdef SO_NOSIGPIPE
val = 0;

if (setsockopt(C->fd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(int))) {
status = NETWORK_STATUS_ERR;
goto docallback;
}
#else
if (signal(SIGPIPE, oldsig) == SIG_ERR) {
warnp("signal(SIGPIPE)");
goto docallback;
}
#endif
#endif

/* Failure, closed, or success? */
Expand Down
53 changes: 53 additions & 0 deletions lib/util/asprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "bsdtar_platform.h"

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#ifndef HAVE_ASPRINTF

/**
* asprintf(ret, format, ...):
* Do asprintf(3) like GNU and BSD do.
*/
int
asprintf(char **ret, const char *format, ...)
{
va_list ap;
int len;
size_t buflen;

/* Figure out how long the string needs to be. */
va_start(ap, format);
len = vsnprintf(NULL, 0, format, ap);
va_end(ap);

/* Did we fail? */
if (len < 0)
goto err0;
buflen = (size_t)(len) + 1;

/* Allocate memory. */
if ((*ret = malloc(buflen)) == NULL)
goto err0;

/* Actually generate the string. */
va_start(ap, format);
len = vsnprintf(*ret, buflen, format, ap);
va_end(ap);

/* Did we fail? */
if (len < 0)
goto err1;

/* Success! */
return (len);

err1:
free(*ret);
err0:
/* Failure! */
return (-1);
}

#endif /* !HAVE_ASPRINTF */
6 changes: 6 additions & 0 deletions lib/util/asprintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _ASPRINTF_H_
#define _ASPRINTF_H_

int asprintf(char **, const char *, ...);

#endif /* !_ASPRINTF_H_ */
1 change: 0 additions & 1 deletion lib/util/dirutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <sys/types.h>

#include <errno.h>
#include <ftw.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/util/sigquit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ termios_restore(void)
static int
tcsetattr_nostop(int fd, int action, const struct termios *t)
{
sig_t oldsig;
void (*oldsig)(int);
int rc;

if ((oldsig = signal(SIGTTOU, SIG_IGN)) == SIG_ERR)
Expand Down
16 changes: 8 additions & 8 deletions lib/util/sysendian.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <stdint.h>

static __inline uint32_t
static inline uint32_t
be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
Expand All @@ -20,7 +20,7 @@ be32dec(const void *pp)
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}

static __inline void
static inline void
be32enc(void *pp, uint32_t x)
{
uint8_t * p = (uint8_t *)pp;
Expand All @@ -31,7 +31,7 @@ be32enc(void *pp, uint32_t x)
p[0] = (x >> 24) & 0xff;
}

static __inline uint64_t
static inline uint64_t
be64dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
Expand All @@ -42,7 +42,7 @@ be64dec(const void *pp)
((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
}

static __inline void
static inline void
be64enc(void *pp, uint64_t x)
{
uint8_t * p = (uint8_t *)pp;
Expand All @@ -57,7 +57,7 @@ be64enc(void *pp, uint64_t x)
p[0] = (x >> 56) & 0xff;
}

static __inline uint32_t
static inline uint32_t
le32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
Expand All @@ -66,7 +66,7 @@ le32dec(const void *pp)
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
}

static __inline void
static inline void
le32enc(void *pp, uint32_t x)
{
uint8_t * p = (uint8_t *)pp;
Expand All @@ -77,7 +77,7 @@ le32enc(void *pp, uint32_t x)
p[3] = (x >> 24) & 0xff;
}

static __inline uint64_t
static inline uint64_t
le64dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
Expand All @@ -88,7 +88,7 @@ le64dec(const void *pp)
((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
}

static __inline void
static inline void
le64enc(void *pp, uint64_t x)
{
uint8_t * p = (uint8_t *)pp;
Expand Down
10 changes: 5 additions & 5 deletions lib/util/warnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
* Call warn(3) or warnx(3) depending upon whether errno == 0; and clear
* errno (so that the standard error message isn't repeated later).
*/
#define warnp(format, ...) do { \
#define warnp(...) do { \
warnline; \
if (errno != 0) { \
warn(format, ## __VA_ARGS__); \
warn(__VA_ARGS__); \
errno = 0; \
} else \
warnx(format, ## __VA_ARGS__); \
warnx(__VA_ARGS__); \
} while (0)

/*
* Call warnx(3) and set errno == 0. Unlike warnp, this should be used
* in cases where we're reporting a problem which we discover ourselves
* rather than one which is reported to us from a library or the kernel.
*/
#define warn0(format, ...) do { \
#define warn0(...) do { \
warnline; \
warnx(format, ## __VA_ARGS__); \
warnx(__VA_ARGS__); \
errno = 0; \
} while (0)

Expand Down
3 changes: 2 additions & 1 deletion libarchive/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ __LA_DECL int archive_read_data_block(struct archive *a,
__LA_DECL int archive_read_data_block(struct archive *a,
const void **buff, size_t *size,
__LA_INT64_T *offset);
#endif

/*
* Return the amount of buffered data (data read from the client which has
* not yet been passed back via archive_read_data_*), or -1 if unknown.
Expand All @@ -380,7 +382,6 @@ __LA_DECL off_t archive_read_get_entryleft(struct archive *a);
* Advance the position within the archive entry.
*/
__LA_DECL int archive_read_advance(struct archive *a, off_t offset);
#endif

/*-
* Some convenience functions that are built on archive_read_data:
Expand Down

0 comments on commit d54e4b0

Please sign in to comment.